From 05c92e45d8c48a1a2eef9fc49b31a4c9a5e15624 Mon Sep 17 00:00:00 2001 From: Matt Gilman Date: Tue, 6 Aug 2024 13:46:10 -0400 Subject: [PATCH] NIFI-13636: Fixing back navigation when navigating to manage access policies. (#9153) This closes #9153 --- .../service/canvas-actions.service.ts | 103 ++++++++++-------- .../flow-designer/state/flow/flow.effects.ts | 19 ++-- .../pages/flow-designer/state/flow/index.ts | 2 +- .../ui/canvas/canvas.component.ts | 5 +- 4 files changed, 71 insertions(+), 58 deletions(-) diff --git a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/service/canvas-actions.service.ts b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/service/canvas-actions.service.ts index 0071e82823a0..16e5d0ffff72 100644 --- a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/service/canvas-actions.service.ts +++ b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/service/canvas-actions.service.ts @@ -223,60 +223,75 @@ export class CanvasActionsService { return this.canvasUtils.canManagePolicies(selection); }, action: (selection: d3.Selection, extraArgs?) => { - if (selection.empty()) { - if (extraArgs?.processGroupId) { + const routeBoundary: string[] = ['/access-policies']; + + if (extraArgs?.processGroupId) { + if (selection.empty()) { this.store.dispatch( navigateToManageComponentPolicies({ request: { resource: 'process-groups', id: extraArgs.processGroupId, - backNavigationContext: 'Process Group' + backNavigation: { + route: ['/process-groups', extraArgs.processGroupId], + routeBoundary, + context: 'Process Group' + } } }) ); - } - } else { - const selectionData = selection.datum(); - const componentType: ComponentType = selectionData.type; + } else { + const selectionData = selection.datum(); + const componentType: ComponentType = selectionData.type; - let resource = 'process-groups'; - let backNavigationContext = 'Process Group'; - switch (componentType) { - case ComponentType.Processor: - resource = 'processors'; - backNavigationContext = 'Processor'; - break; - case ComponentType.InputPort: - resource = 'input-ports'; - backNavigationContext = 'Input Port'; - break; - case ComponentType.OutputPort: - resource = 'output-ports'; - backNavigationContext = 'Output Port'; - break; - case ComponentType.Funnel: - resource = 'funnels'; - backNavigationContext = 'Funnel'; - break; - case ComponentType.Label: - resource = 'labels'; - backNavigationContext = 'Label'; - break; - case ComponentType.RemoteProcessGroup: - resource = 'remote-process-groups'; - backNavigationContext = 'Remote Process Group'; - break; - } + let resource = 'process-groups'; + let context = 'Process Group'; + switch (componentType) { + case ComponentType.Processor: + resource = 'processors'; + context = 'Processor'; + break; + case ComponentType.InputPort: + resource = 'input-ports'; + context = 'Input Port'; + break; + case ComponentType.OutputPort: + resource = 'output-ports'; + context = 'Output Port'; + break; + case ComponentType.Funnel: + resource = 'funnels'; + context = 'Funnel'; + break; + case ComponentType.Label: + resource = 'labels'; + context = 'Label'; + break; + case ComponentType.RemoteProcessGroup: + resource = 'remote-process-groups'; + context = 'Remote Process Group'; + break; + } - this.store.dispatch( - navigateToManageComponentPolicies({ - request: { - resource, - id: selectionData.id, - backNavigationContext - } - }) - ); + this.store.dispatch( + navigateToManageComponentPolicies({ + request: { + resource, + id: selectionData.id, + backNavigation: { + route: [ + '/process-groups', + extraArgs.processGroupId, + componentType, + selectionData.id + ], + routeBoundary, + context + } + } + }) + ); + } } } }, diff --git a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/flow.effects.ts b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/flow.effects.ts index 77754bbd609b..fba867dc01a5 100644 --- a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/flow.effects.ts +++ b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/flow.effects.ts @@ -1065,18 +1065,15 @@ export class FlowEffects { this.actions$.pipe( ofType(FlowActions.navigateToManageComponentPolicies), map((action) => action.request), - concatLatestFrom(() => this.store.select(selectCurrentProcessGroupId)), - tap(([request, processGroupId]) => { - const routeBoundary: string[] = ['/access-policies']; - this.router.navigate([...routeBoundary, 'read', 'component', request.resource, request.id], { - state: { - backNavigation: { - route: ['/process-groups', processGroupId, request.resource, request.id], - routeBoundary, - context: request.backNavigationContext - } as BackNavigation + tap((request) => { + this.router.navigate( + [...request.backNavigation.routeBoundary, 'read', 'component', request.resource, request.id], + { + state: { + backNavigation: request.backNavigation + } } - }); + ); }) ), { dispatch: false } diff --git a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/index.ts b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/index.ts index 023a9e0435bf..2f586351d469 100644 --- a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/index.ts +++ b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/state/flow/index.ts @@ -346,7 +346,7 @@ export interface OpenComponentDialogRequest { export interface NavigateToManageComponentPoliciesRequest { resource: string; id: string; - backNavigationContext: string; + backNavigation: BackNavigation; } export interface EditComponentDialogRequest { diff --git a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/canvas.component.ts b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/canvas.component.ts index 2e6a12a0613c..0eeef0f8d5e7 100644 --- a/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/canvas.component.ts +++ b/nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/canvas.component.ts @@ -57,7 +57,7 @@ import { selectSkipTransform, selectViewStatusHistoryComponent } from '../../state/flow/flow.selectors'; -import { filter, map, switchMap, take } from 'rxjs'; +import { filter, map, NEVER, switchMap, take } from 'rxjs'; import { restoreViewport } from '../../state/transform/transform.actions'; import { initialState } from '../../state/flow/flow.reducer'; import { CanvasContextMenu } from '../../service/canvas-context-menu.service'; @@ -218,7 +218,8 @@ export class Canvas implements OnInit, OnDestroy { component$ = this.store.select(selectLabel(selectedComponent.id)); break; default: - throw 'Unrecognized Component Type'; + component$ = NEVER; + break; } // combine the original selection with the component