rfellows commented on code in PR #11946:
URL: https://github.com/apache/nifi/pull/11946#discussion_r4741508832


##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/drain-process-group-dialog/drain-process-group-dialog.html:
##########
@@ -0,0 +1,101 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~    http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<h2 mat-dialog-title>Drain Process Group</h2>
+@if (drainState$ | async; as drainState) {
+    @if (getFailureMessages(drainState.drainRequest?.failureReason); as 
failureMessages) {
+        @if (failureMessages.length > 0) {
+            <error-banner [messages]="failureMessages" [showErrorIcon]="true" 
[allowDismiss]="false"></error-banner>
+        }
+    }
+    <div class="drain-process-group">
+        <mat-dialog-content>
+            <div class="flex flex-col gap-y-4">
+                <div class="tertiary-color font-medium" 
data-qa="drain-status-message">
+                    {{ getStatusMessage(drainState) }}
+                </div>
+                @if (drainState.drainRequest; as drainRequest) {
+                    <div class="w-full flex flex-col items-center">
+                        <mat-progress-bar
+                            [mode]="isProgressIndeterminate(drainRequest) ? 
'indeterminate' : 'determinate'"
+                            
[value]="getPercentCompleted(drainRequest)"></mat-progress-bar>
+                        <div class="tertiary-color font-medium" 
data-qa="drain-remaining">
+                            {{ getRemainingText(drainRequest) }}
+                        </div>
+                    </div>
+                    @if (drainRequest.blockingComponents.length > 0) {
+                        <div class="flex flex-col gap-y-2">
+                            <status-banner variant="caution" 
[allowDismiss]="false" data-qa="drain-blocking-banner">
+                                <div statusBannerTitle>{{ 
getBlockingBannerTitle(drainState) }}</div>
+                                <div statusBannerDescription>
+                                    Queued data cannot leave until the 
components below are fixed.
+                                </div>
+                            </status-banner>
+                            @for (component of 
drainRequest.blockingComponents; track component.id) {
+                                <div class="flex items-center gap-x-2" 
data-qa="drain-blocking-component">
+                                    @if 
(getBlockingTooltipComponent(component); as tooltipComponent) {
+                                        <div
+                                            class="fa fa-warning caution-color"
+                                            
data-qa="drain-blocking-component-warning"
+                                            nifiTooltip
+                                            
[tooltipComponentType]="tooltipComponent"
+                                            
[tooltipInputData]="getBlockingTooltipData(component)"
+                                            [delayClose]="true"></div>
+                                    } @else {
+                                        <div
+                                            class="fa fa-warning caution-color"
+                                            
data-qa="drain-blocking-component-warning"></div>
+                                    }
+                                    <div class="flex-1">
+                                        @if (drainState.status === 'ended') {
+                                            <a
+                                                class="pointer primary-color"
+                                                data-qa="drain-go-to"
+                                                
(click)="goToComponent.next(component)"
+                                                >{{ 
getBlockingComponentLabel(component) }}</a
+                                            >
+                                        } @else {
+                                            <span 
data-qa="drain-blocking-component-label">{{
+                                                
getBlockingComponentLabel(component)
+                                            }}</span>
+                                        }
+                                        <span 
data-qa="drain-blocking-component-detail">{{
+                                            
getBlockingComponentDetail(component)
+                                        }}</span>
+                                    </div>
+                                </div>
+                            }
+                        </div>
+                    }
+                }
+            </div>
+        </mat-dialog-content>
+        <mat-dialog-actions align="end">
+            @if (drainState.status === 'ended') {
+                <button mat-flat-button mat-dialog-close 
data-qa="drain-close">Close</button>
+            } @else {
+                <button
+                    mat-button
+                    data-qa="drain-cancel"
+                    [disabled]="drainState.status !== 'draining'"
+                    (click)="cancelDrain.next()">
+                    Cancel Drain
+                </button>

Review Comment:
   Done. View Drain now passes whether the user can modify the group, and 
Cancel Drain is only rendered when they can. Close is always shown. Covered in 
the dialog, reducer, selectors and context-menu specs (selected group and 
current group).



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/process-group-drain/process-group-drain.effects.ts:
##########
@@ -0,0 +1,356 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Injectable, inject } from '@angular/core';
+import { Actions, createEffect, ofType } from '@ngrx/effects';
+import { concatLatestFrom } from '@ngrx/operators';
+import { Action, Store } from '@ngrx/store';
+import { HttpErrorResponse } from '@angular/common/http';
+import { MatDialog, MatDialogRef } from '@angular/material/dialog';
+import { NavigationStart, Router } from '@angular/router';
+import {
+    asyncScheduler,
+    catchError,
+    exhaustMap,
+    filter,
+    from,
+    interval,
+    map,
+    of,
+    switchMap,
+    take,
+    takeUntil,
+    tap
+} from 'rxjs';
+import {
+    ComponentType,
+    DrainBlockingComponentType,
+    isDefinedAndNotNull,
+    MEDIUM_DIALOG,
+    SMALL_DIALOG,
+    YesNoDialog
+} from '@nifi/shared';
+import * as ProcessGroupDrainActions from './process-group-drain.actions';
+import * as FlowActions from '../flow/flow.actions';
+import * as ErrorActions from '../../../../state/error/error.actions';
+import {
+    selectDrainDialogState,
+    selectDrainProcessGroupId,
+    selectDrainRequestId
+} from './process-group-drain.selectors';
+import { selectCurrentProcessGroupId } from '../flow/flow.selectors';
+import { ProcessGroupDrainService } from 
'../../../../service/process-group-drain.service';
+import { ErrorHelper } from '../../../../service/error-helper.service';
+import { DrainProcessGroupDialog } from 
'../../../../ui/common/drain-process-group-dialog/drain-process-group-dialog';
+import { NiFiState } from '../../../../state';
+
+const COMPONENT_TYPES: Record<DrainBlockingComponentType, ComponentType> = {
+    PROCESSOR: ComponentType.Processor,
+    INPUT_PORT: ComponentType.InputPort,
+    OUTPUT_PORT: ComponentType.OutputPort,
+    REMOTE_INPUT_PORT: ComponentType.RemoteProcessGroup
+};
+
+const POLLING_STOP_ACTIONS = [
+    ProcessGroupDrainActions.drainEnded,
+    ProcessGroupDrainActions.cancelDrain,
+    ProcessGroupDrainActions.resetDrainState,
+    ProcessGroupDrainActions.drainApiError
+] as const;
+
+@Injectable()
+export class ProcessGroupDrainEffects {
+    private actions$ = inject(Actions);
+    private store = inject<Store<NiFiState>>(Store);
+    private processGroupDrainService = inject(ProcessGroupDrainService);
+    private errorHelper = inject(ErrorHelper);
+    private dialog = inject(MatDialog);
+    private router = inject(Router);
+
+    private drainDialogRef: MatDialogRef<DrainProcessGroupDialog> | undefined;
+    private lastPrepared = false;
+
+    promptDrain$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.promptDrain),
+                map((action) => action.request),
+                tap((request) => {
+                    const dialogReference = this.dialog.open(YesNoDialog, {
+                        ...SMALL_DIALOG,
+                        data: {
+                            title: 'Drain Process Group',
+                            message:
+                                'Drain stops the components that bring data 
into this Process Group, enables the Controller Services its components 
reference, and starts the other components so the queued data can flow out. The 
drain ends when the group is empty or when you cancel it. Components keep their 
run state afterwards, so sources remain stopped. Are you sure you want to drain 
this Process Group?'
+                        }
+                    });
+
+                    
dialogReference.componentInstance.yes.pipe(take(1)).subscribe(() => {
+                        
this.store.dispatch(ProcessGroupDrainActions.beginDrain({ request }));
+                    });
+                })
+            ),
+        { dispatch: false }
+    );
+
+    beginDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrain),
+            map((action) => action.request),
+            switchMap((request) =>
+                
this.processGroupDrainService.beginDrain(request.processGroupId).pipe(
+                    map((response) =>
+                        ProcessGroupDrainActions.beginDrainSuccess({
+                            response: { drainRequestEntity: response }
+                        })
+                    ),
+                    catchError((errorResponse: HttpErrorResponse) => 
this.handleDrainApiError(errorResponse))
+                )
+            )
+        )
+    );
+
+    beginDrainSuccess$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrainSuccess),
+            concatLatestFrom(() => [
+                this.store.select(selectDrainProcessGroupId),
+                this.store.select(selectCurrentProcessGroupId)
+            ]),
+            switchMap(([action, processGroupId, currentProcessGroupId]) => {
+                this.lastPrepared = 
action.response.drainRequestEntity.drainRequest?.prepared === true;
+                const drainRequest = 
action.response.drainRequestEntity.drainRequest;
+                // drainEnded$ performs the reload when the drain has already 
ended, so the group is reloaded once
+                if (!drainRequest || drainRequest.state !== 'DRAINING') {
+                    return of(ProcessGroupDrainActions.drainEnded());
+                }
+                return from([
+                    this.reloadProcessGroupAction(processGroupId, 
currentProcessGroupId),
+                    ProcessGroupDrainActions.startPollingDrain()
+                ]);
+            })
+        )
+    );
+
+    openDrainDialog$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.beginDrainSuccess, 
ProcessGroupDrainActions.viewDrain),
+                tap(() => {
+                    if (this.drainDialogRef) {
+                        return;
+                    }
+
+                    const dialogReference = 
this.dialog.open(DrainProcessGroupDialog, {
+                        ...MEDIUM_DIALOG,
+                        disableClose: true,

Review Comment:
   Done. The dialog keeps `disableClose` (it comes from `MEDIUM_DIALOG`), and 
there is now a Close button next to Cancel Drain while the drain runs. Closing 
doesn't cancel the drain; the effects spec checks that `cancelDrain` isn't 
dispatched. Go To links are shown whenever the status isn't `ending`.



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/canvas/utils/canvas-tooltip-overlay.ts:
##########
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ComponentRef, Type } from '@angular/core';
+import { Overlay, OverlayRef, PositionStrategy } from '@angular/cdk/overlay';
+import { ComponentPortal } from '@angular/cdk/portal';
+import * as d3 from 'd3';
+import { NiFiCommon } from '@nifi/shared';
+
+export interface CanvasTooltipSession {
+    type: Type<unknown>;
+    data: unknown;
+    overlayRef: OverlayRef | null;
+    positionStrategy: PositionStrategy | null;
+    tooltipReference: ComponentRef<unknown> | null;
+    closeTimer: number;
+    openTimer: number;
+}
+
+export type CanvasTooltipSessionMap = WeakMap<Element, CanvasTooltipSession>;
+
+const TOOLTIP_POSITIONS = [
+    {
+        originX: 'end' as const,
+        originY: 'bottom' as const,
+        overlayX: 'start' as const,
+        overlayY: 'top' as const,
+        offsetX: 8,
+        offsetY: 8
+    }
+];
+
+function clearOpenTimer(session: CanvasTooltipSession): void {
+    if (session.openTimer > 0) {
+        window.clearTimeout(session.openTimer);
+        session.openTimer = -1;
+    }
+}
+
+function clearCloseTimer(session: CanvasTooltipSession): void {
+    if (session.closeTimer > 0) {
+        window.clearTimeout(session.closeTimer);
+        session.closeTimer = -1;
+    }
+}
+
+function disposeSession(session: CanvasTooltipSession): void {
+    clearOpenTimer(session);
+    clearCloseTimer(session);
+    session.overlayRef?.detach();
+    session.overlayRef?.dispose();
+    session.overlayRef = null;
+    session.tooltipReference = null;
+    session.positionStrategy?.detach?.();
+    session.positionStrategy?.dispose();
+    session.positionStrategy = null;
+}
+
+function refreshOpenTooltip(session: CanvasTooltipSession): void {
+    if (session.overlayRef?.hasAttached() && session.tooltipReference) {
+        session.tooltipReference.setInput('data', session.data);
+        session.tooltipReference.changeDetectorRef.detectChanges();
+        session.overlayRef.updatePosition();
+    }
+}
+
+function openTooltip(overlay: Overlay, element: Element, session: 
CanvasTooltipSession): void {
+    session.positionStrategy = overlay
+        .position()
+        .flexibleConnectedTo(element)
+        .withPositions(TOOLTIP_POSITIONS)
+        .withPush(true);
+    session.overlayRef = overlay.create({ positionStrategy: 
session.positionStrategy });
+    session.tooltipReference = session.overlayRef.attach(new 
ComponentPortal(session.type));
+    session.tooltipReference.setInput('data', session.data);
+    session.tooltipReference.changeDetectorRef.detectChanges();
+
+    const tooltipElement: HTMLElement = 
session.tooltipReference.location.nativeElement;
+    tooltipElement.addEventListener('mouseenter', () => 
clearCloseTimer(session));
+    tooltipElement.addEventListener('mouseleave', () => 
disposeSession(session));
+}
+
+/**
+ * Binds hover listeners that open a canvas overlay tooltip. If the tooltip is 
already open,
+ * the next bind (for example from a poll) updates its `data` input in place. 
A tooltip that is
+ * waiting to open uses the data from the latest bind.
+ */
+export function bindCanvasTooltip<C>(
+    overlay: Overlay,
+    sessions: CanvasTooltipSessionMap,
+    type: Type<C>,
+    selection: d3.Selection<any, any, any, any>,

Review Comment:
   Done. `bindCanvasTooltip` and `unbindCanvasTooltip` are now generic over the 
d3 selection type, and the spec's `openTip` is typed. `npx eslint 
src/app/ui/common/canvas/utils/` from `apps/nifi` is clean.
   
   Running it across all of `ui/common/canvas/` still reports `no-explicit-any` 
errors in the renderer files under `layers/`. Those predate this PR and are 
hidden by the same root `nx lint` gap you pointed out, so I've left them alone 
here.



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/process-group-drain/process-group-drain.effects.ts:
##########
@@ -0,0 +1,356 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Injectable, inject } from '@angular/core';
+import { Actions, createEffect, ofType } from '@ngrx/effects';
+import { concatLatestFrom } from '@ngrx/operators';
+import { Action, Store } from '@ngrx/store';
+import { HttpErrorResponse } from '@angular/common/http';
+import { MatDialog, MatDialogRef } from '@angular/material/dialog';
+import { NavigationStart, Router } from '@angular/router';
+import {
+    asyncScheduler,
+    catchError,
+    exhaustMap,
+    filter,
+    from,
+    interval,
+    map,
+    of,
+    switchMap,
+    take,
+    takeUntil,
+    tap
+} from 'rxjs';
+import {
+    ComponentType,
+    DrainBlockingComponentType,
+    isDefinedAndNotNull,
+    MEDIUM_DIALOG,
+    SMALL_DIALOG,
+    YesNoDialog
+} from '@nifi/shared';
+import * as ProcessGroupDrainActions from './process-group-drain.actions';
+import * as FlowActions from '../flow/flow.actions';
+import * as ErrorActions from '../../../../state/error/error.actions';
+import {
+    selectDrainDialogState,
+    selectDrainProcessGroupId,
+    selectDrainRequestId
+} from './process-group-drain.selectors';
+import { selectCurrentProcessGroupId } from '../flow/flow.selectors';
+import { ProcessGroupDrainService } from 
'../../../../service/process-group-drain.service';
+import { ErrorHelper } from '../../../../service/error-helper.service';
+import { DrainProcessGroupDialog } from 
'../../../../ui/common/drain-process-group-dialog/drain-process-group-dialog';
+import { NiFiState } from '../../../../state';
+
+const COMPONENT_TYPES: Record<DrainBlockingComponentType, ComponentType> = {
+    PROCESSOR: ComponentType.Processor,
+    INPUT_PORT: ComponentType.InputPort,
+    OUTPUT_PORT: ComponentType.OutputPort,
+    REMOTE_INPUT_PORT: ComponentType.RemoteProcessGroup
+};
+
+const POLLING_STOP_ACTIONS = [
+    ProcessGroupDrainActions.drainEnded,
+    ProcessGroupDrainActions.cancelDrain,
+    ProcessGroupDrainActions.resetDrainState,
+    ProcessGroupDrainActions.drainApiError
+] as const;
+
+@Injectable()
+export class ProcessGroupDrainEffects {
+    private actions$ = inject(Actions);
+    private store = inject<Store<NiFiState>>(Store);
+    private processGroupDrainService = inject(ProcessGroupDrainService);
+    private errorHelper = inject(ErrorHelper);
+    private dialog = inject(MatDialog);
+    private router = inject(Router);
+
+    private drainDialogRef: MatDialogRef<DrainProcessGroupDialog> | undefined;
+    private lastPrepared = false;
+
+    promptDrain$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.promptDrain),
+                map((action) => action.request),
+                tap((request) => {
+                    const dialogReference = this.dialog.open(YesNoDialog, {
+                        ...SMALL_DIALOG,
+                        data: {
+                            title: 'Drain Process Group',
+                            message:
+                                'Drain stops the components that bring data 
into this Process Group, enables the Controller Services its components 
reference, and starts the other components so the queued data can flow out. The 
drain ends when the group is empty or when you cancel it. Components keep their 
run state afterwards, so sources remain stopped. Are you sure you want to drain 
this Process Group?'
+                        }
+                    });
+
+                    
dialogReference.componentInstance.yes.pipe(take(1)).subscribe(() => {
+                        
this.store.dispatch(ProcessGroupDrainActions.beginDrain({ request }));
+                    });
+                })
+            ),
+        { dispatch: false }
+    );
+
+    beginDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrain),
+            map((action) => action.request),
+            switchMap((request) =>
+                
this.processGroupDrainService.beginDrain(request.processGroupId).pipe(
+                    map((response) =>
+                        ProcessGroupDrainActions.beginDrainSuccess({
+                            response: { drainRequestEntity: response }
+                        })
+                    ),
+                    catchError((errorResponse: HttpErrorResponse) => 
this.handleDrainApiError(errorResponse))
+                )
+            )
+        )
+    );
+
+    beginDrainSuccess$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.beginDrainSuccess),
+            concatLatestFrom(() => [
+                this.store.select(selectDrainProcessGroupId),
+                this.store.select(selectCurrentProcessGroupId)
+            ]),
+            switchMap(([action, processGroupId, currentProcessGroupId]) => {
+                this.lastPrepared = 
action.response.drainRequestEntity.drainRequest?.prepared === true;
+                const drainRequest = 
action.response.drainRequestEntity.drainRequest;
+                // drainEnded$ performs the reload when the drain has already 
ended, so the group is reloaded once
+                if (!drainRequest || drainRequest.state !== 'DRAINING') {
+                    return of(ProcessGroupDrainActions.drainEnded());
+                }
+                return from([
+                    this.reloadProcessGroupAction(processGroupId, 
currentProcessGroupId),
+                    ProcessGroupDrainActions.startPollingDrain()
+                ]);
+            })
+        )
+    );
+
+    openDrainDialog$ = createEffect(
+        () =>
+            this.actions$.pipe(
+                ofType(ProcessGroupDrainActions.beginDrainSuccess, 
ProcessGroupDrainActions.viewDrain),
+                tap(() => {
+                    if (this.drainDialogRef) {
+                        return;
+                    }
+
+                    const dialogReference = 
this.dialog.open(DrainProcessGroupDialog, {
+                        ...MEDIUM_DIALOG,
+                        disableClose: true,
+                        autoFocus: false
+                    });
+                    this.drainDialogRef = dialogReference;
+
+                    dialogReference.componentInstance.drainState$ = 
this.store.select(selectDrainDialogState);
+
+                    dialogReference.componentInstance.cancelDrain
+                        .pipe(takeUntil(dialogReference.afterClosed()))
+                        .subscribe(() => {
+                            
this.store.dispatch(ProcessGroupDrainActions.cancelDrain());
+                        });
+
+                    dialogReference.componentInstance.goToComponent
+                        .pipe(takeUntil(dialogReference.afterClosed()))
+                        .subscribe((component) => {
+                            
this.store.dispatch(ProcessGroupDrainActions.goToBlockingComponent({ component 
}));
+                        });
+
+                    dialogReference.afterClosed().subscribe(() => {
+                        this.drainDialogRef = undefined;
+                        this.lastPrepared = false;
+                        
this.store.dispatch(ProcessGroupDrainActions.resetDrainState());
+                    });
+                })
+            ),
+        { dispatch: false }
+    );
+
+    viewDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.viewDrain),
+            map(() => ProcessGroupDrainActions.startPollingDrain())
+        )
+    );
+
+    // viewDrain reaches this effect through viewDrain$, which dispatches 
startPollingDrain. Listening
+    // for both would still be a single interval because switchMap replaces 
the previous one, but it
+    // would restart the timer on every View.
+    startPollingDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.startPollingDrain),
+            switchMap(() =>
+                interval(2000, 
asyncScheduler).pipe(takeUntil(this.actions$.pipe(ofType(...POLLING_STOP_ACTIONS))))
+            ),
+            map(() => ProcessGroupDrainActions.pollDrain())
+        )
+    );
+
+    pollDrain$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.pollDrain, 
ProcessGroupDrainActions.viewDrain),
+            concatLatestFrom(() => [
+                
this.store.select(selectDrainProcessGroupId).pipe(isDefinedAndNotNull()),
+                
this.store.select(selectDrainRequestId).pipe(isDefinedAndNotNull())
+            ]),
+            exhaustMap(([, processGroupId, drainRequestId]) =>
+                this.processGroupDrainService.getDrain(processGroupId, 
drainRequestId).pipe(
+                    map((response) =>
+                        ProcessGroupDrainActions.pollDrainSuccess({
+                            response: { drainRequestEntity: response }
+                        })
+                    ),
+                    catchError((errorResponse: HttpErrorResponse) => 
this.handleDrainApiError(errorResponse)),
+                    
takeUntil(this.actions$.pipe(ofType(...POLLING_STOP_ACTIONS)))
+                )
+            )
+        )
+    );
+
+    pollDrainSuccess$ = createEffect(() =>
+        this.actions$.pipe(
+            ofType(ProcessGroupDrainActions.pollDrainSuccess),
+            concatLatestFrom(() => [
+                this.store.select(selectDrainProcessGroupId),
+                this.store.select(selectCurrentProcessGroupId)
+            ]),
+            switchMap(([action, processGroupId, currentProcessGroupId]) => {
+                const drainRequest = 
action.response.drainRequestEntity.drainRequest;
+                const actions: Action[] = [];
+                const isDraining = drainRequest?.state === 'DRAINING';
+                const prepared = drainRequest?.prepared === true;
+                // An ended drain is reloaded by drainEnded$, so the prepared 
flip only reloads while draining
+                if (isDraining && prepared && !this.lastPrepared) {

Review Comment:
   Done. `lastPrepared` starts as `null`, the reload only happens when the 
previous value was explicitly `false`, and it's reset to `null` on close and on 
API errors. Added specs for a drain that's already prepared on the first poll 
(no reload) and one that flips from `false` to `true` (one reload).



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/canvas/utils/draining-badge.utils.ts:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import * as d3 from 'd3';
+import { CanvasConstants } from '../canvas.constants';
+
+/**
+ * Space between the Draining label and the edge of its background.
+ */
+export const DRAINING_BADGE_HORIZONTAL_PADDING = 5;
+
+/**
+ * Appends a hidden Draining badge inside a process group's Queued stats row. 
The badge is shorter
+ * than the row so it never changes the row height. Its horizontal layout is 
applied by
+ * `updateDrainingBadge`, once the label's font is rendered and can be 
measured accurately.
+ */
+export function appendDrainingBadge<PElement extends d3.BaseType, PDatum>(

Review Comment:
   Done. Added the `fa-info-circle` icon and laid the badge out as padding 4, 
label, gap 4, icon, padding 4, ending where the "5 min" text ends. Height is 
16, radius 3, label 9px / 600, with `text-rendering: geometricPrecision` on the 
label and icon in both canvas stylesheets. The spec checks the icon, the 
vertical centring in the stats row and the layout.



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/process-group-drain/process-group-drain.effects.spec.ts:
##########
@@ -0,0 +1,523 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { TestBed } from '@angular/core/testing';
+import { provideMockActions } from '@ngrx/effects/testing';
+import { MockStore, provideMockStore } from '@ngrx/store/testing';
+import { Action } from '@ngrx/store';
+import { HttpErrorResponse } from '@angular/common/http';
+import { MatDialog } from '@angular/material/dialog';
+import { NavigationStart, Router } from '@angular/router';
+import { filter, firstValueFrom, Observable, of, Subject, throwError } from 
'rxjs';
+import { ProcessGroupDrainEffects } from './process-group-drain.effects';
+import * as ProcessGroupDrainActions from './process-group-drain.actions';
+import * as FlowActions from '../flow/flow.actions';
+import * as ErrorActions from '../../../../state/error/error.actions';
+import { selectCurrentProcessGroupId } from '../flow/flow.selectors';
+import { selectDrainProcessGroupId, selectDrainRequestId } from 
'./process-group-drain.selectors';
+import { ProcessGroupDrainService } from 
'../../../../service/process-group-drain.service';
+import { ErrorHelper } from '../../../../service/error-helper.service';
+import {
+    createDrainBlockingComponent,
+    createProcessGroupDrainRequestEntity
+} from '../../../../testing/process-group-drain-fixture';
+import { ComponentType } from '@nifi/shared';
+
+describe('ProcessGroupDrainEffects', () => {
+    async function setup(
+        options: {
+            processGroupId?: string | null;
+            drainRequestId?: string | null;
+            currentProcessGroupId?: string;
+            processGroupDrainService?: Partial<ProcessGroupDrainService>;
+        } = {}
+    ) {
+        let actions$: Observable<Action>;
+        const yes$ = new Subject<void>();
+        const cancelDrain$ = new Subject<void>();
+        const goToComponent$ = new Subject<unknown>();
+        const afterClosed$ = new Subject<void>();
+        const routerEvents$ = new Subject<unknown>();
+        const mockDialog = {
+            open: vi.fn().mockReturnValue({
+                componentInstance: {
+                    yes: yes$,
+                    cancelDrain: cancelDrain$,
+                    goToComponent: goToComponent$,
+                    drainState$: undefined
+                },
+                close: vi.fn(),
+                afterClosed: () => afterClosed$
+            })
+        };
+
+        await TestBed.configureTestingModule({
+            providers: [
+                ProcessGroupDrainEffects,
+                provideMockActions(() => actions$),
+                provideMockStore({
+                    selectors: [
+                        {
+                            selector: selectDrainProcessGroupId,
+                            value: options.processGroupId !== undefined ? 
options.processGroupId : 'pg-1'
+                        },
+                        {
+                            selector: selectDrainRequestId,
+                            value: options.drainRequestId !== undefined ? 
options.drainRequestId : 'drain-1'
+                        },
+                        {
+                            selector: selectCurrentProcessGroupId,
+                            value: options.currentProcessGroupId ?? 'pg-1'
+                        }
+                    ]
+                }),
+                { provide: MatDialog, useValue: mockDialog },
+                { provide: Router, useValue: { events: routerEvents$ } },
+                {
+                    provide: ProcessGroupDrainService,
+                    useValue: {
+                        beginDrain: vi.fn(),
+                        getDrain: vi.fn(),
+                        endDrain: vi.fn(),
+                        ...options.processGroupDrainService
+                    }
+                },
+                {
+                    provide: ErrorHelper,
+                    useValue: {
+                        getErrorString: (error: HttpErrorResponse) => 
error.message,
+                        showErrorInContext: (status: number) => [400, 403, 
404, 409, 413, 503].includes(status),
+                        fullScreenError: vi
+                            .fn()
+                            .mockReturnValue(
+                                ErrorActions.fullScreenError({ errorDetail: { 
title: 'Error', message: 'boom' } })
+                            )
+                    }
+                }
+            ]
+        }).compileComponents();
+
+        const effects = TestBed.inject(ProcessGroupDrainEffects);
+        const store = TestBed.inject(MockStore);
+        const processGroupDrainService = 
TestBed.inject(ProcessGroupDrainService);
+        const dispatchSpy = vi.spyOn(store, 'dispatch');
+
+        return {
+            effects,
+            setActions: (source: Observable<Action>) => {
+                actions$ = source;
+            },
+            mockDialog,
+            yes$,
+            cancelDrain$,
+            goToComponent$,
+            afterClosed$,
+            routerEvents$,
+            processGroupDrainService,
+            dispatchSpy
+        };
+    }
+
+    it('dispatches beginDrain only when the prompt is confirmed', async () => {
+        const { effects, setActions, mockDialog, yes$, dispatchSpy } = await 
setup();
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        effects.promptDrain$.subscribe();
+        actions$.next(ProcessGroupDrainActions.promptDrain({ request: { 
processGroupId: 'pg-1' } }));
+
+        expect(mockDialog.open).toHaveBeenCalled();
+        expect(dispatchSpy).not.toHaveBeenCalled();
+
+        yes$.next();
+
+        expect(dispatchSpy).toHaveBeenCalledWith(
+            ProcessGroupDrainActions.beginDrain({ request: { processGroupId: 
'pg-1' } })
+        );
+    });
+
+    it('opens the dialog, starts polling, and reloads the current group after 
a successful POST', async () => {
+        const entity = createProcessGroupDrainRequestEntity();
+        const { effects, setActions, mockDialog } = await setup({
+            processGroupDrainService: {
+                beginDrain: vi.fn().mockReturnValue(of(entity))
+            }
+        });
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        const beginResult = firstValueFrom(effects.beginDrain$);
+        actions$.next(ProcessGroupDrainActions.beginDrain({ request: { 
processGroupId: 'pg-1' } }));
+        expect(await beginResult).toEqual(
+            ProcessGroupDrainActions.beginDrainSuccess({ response: { 
drainRequestEntity: entity } })
+        );
+
+        const successResults = 
firstValueFrom(effects.beginDrainSuccess$.pipe());
+        const openPromise = firstValueFrom(effects.openDrainDialog$);
+        actions$.next(ProcessGroupDrainActions.beginDrainSuccess({ response: { 
drainRequestEntity: entity } }));
+        await openPromise;
+        const success = await successResults;
+
+        expect(mockDialog.open).toHaveBeenCalled();
+        expect(success).toEqual(FlowActions.reloadFlow());
+    });
+
+    it('reloads a child process group after a successful POST when it is not 
the current group', async () => {
+        const entity = createProcessGroupDrainRequestEntity();
+        const { effects, setActions } = await setup({
+            currentProcessGroupId: 'current-pg',
+            processGroupId: 'pg-1'
+        });
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        const result = firstValueFrom(effects.beginDrainSuccess$);
+        actions$.next(ProcessGroupDrainActions.beginDrainSuccess({ response: { 
drainRequestEntity: entity } }));
+
+        expect(await result).toEqual(FlowActions.loadChildProcessGroup({ 
request: { id: 'pg-1' } }));
+    });
+
+    it('ends the drain without reloading in beginDrainSuccess$ when the POST 
returns an ended drain', async () => {
+        const ended = createProcessGroupDrainRequestEntity({ state: 'ENDED', 
currentCount: 0 });
+        const { effects, setActions } = await setup({ currentProcessGroupId: 
'pg-1', processGroupId: 'pg-1' });
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        const emitted: Action[] = [];
+        const subscription = effects.beginDrainSuccess$.subscribe((action) => 
emitted.push(action));
+        actions$.next(ProcessGroupDrainActions.beginDrainSuccess({ response: { 
drainRequestEntity: ended } }));
+        subscription.unsubscribe();
+
+        expect(emitted).toEqual([ProcessGroupDrainActions.drainEnded()]);
+    });
+
+    it('shows a snackbar and does not open the dialog when the POST fails', 
async () => {
+        const errorResponse = new HttpErrorResponse({ status: 409, statusText: 
'Conflict', error: 'already draining' });
+        Object.defineProperty(errorResponse, 'message', { value: 'already 
draining' });
+        const { effects, setActions, mockDialog, processGroupDrainService } = 
await setup({
+            processGroupDrainService: {
+                beginDrain: vi.fn().mockReturnValue(throwError(() => 
errorResponse))
+            }
+        });
+        vi.spyOn(processGroupDrainService, 
'beginDrain').mockReturnValue(throwError(() => errorResponse));
+        const actions$ = new Subject<Action>();
+        setActions(actions$);
+
+        const result = firstValueFrom(effects.beginDrain$);
+        actions$.next(ProcessGroupDrainActions.beginDrain({ request: { 
processGroupId: 'pg-1' } }));
+
+        expect(await result).toEqual(ProcessGroupDrainActions.drainApiError({ 
error: 'already draining' }));
+        expect(mockDialog.open).not.toHaveBeenCalled();
+    });
+
+    it('stops polling and reloads when a poll returns an ended drain', async 
() => {

Review Comment:
   Extended it rather than renaming. With fake timers it now runs through 
`startPollingDrain$`, `pollDrain$`, `pollDrainSuccess$` and `drainEnded$`, and 
asserts that `getDrain` is called only once and that a reload is dispatched. 
The reload is now `loadProcessGroup` instead of `reloadFlow`; see the throttle 
thread.



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/ui/common/tooltips/drain-summary-tip/drain-summary-tip.component.html:
##########
@@ -0,0 +1,28 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<div class="tooltip">
+    @if (data) {
+        <div class="flex flex-col gap-y-2">
+            <div>{{ title }}</div>
+            <mat-progress-bar
+                [mode]="isProgressIndeterminate() ? 'indeterminate' : 
'determinate'"
+                [value]="getPercentCompleted()"></mat-progress-bar>
+            <div class="tertiary-color font-medium">{{ getStatusDetail() 
}}</div>

Review Comment:
   Done, the bar and caption now sit in the same `w-full flex flex-col 
items-center` wrapper as the dialog.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to