You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "mcgilman (via GitHub)" <gi...@apache.org> on 2026/04/14 13:06:42 UTC
[PR] NIFI-15818: Implementing route-backed component selection so selecting a processor/connection/etc on the canvas updates the URL, and vice versa. [nifi]
mcgilman opened a new pull request, #11138:
URL: https://github.com/apache/nifi/pull/11138
**Title:** NIFI-15818: Route-backed component selection for the connector canvas
**Body:**
## Summary
- Implements route-backed component selection for the connector canvas so that selecting a component on the canvas updates the URL and deep-linking to a component URL centers the viewport on it
- Adds `selectComponents`, `deselectAllComponents`, and `navigateWithoutTransform` actions with corresponding effects, reducer handlers, and component wiring
- Fixes a corner case where dispatching `selectComponents` with an empty components array would navigate to an invalid route; it now correctly delegates to `deselectAllComponents`
## Details
**Selection routing:** Clicking a single component routes to `/connectors/:id/canvas/:processGroupId/:type/:componentId`. Selecting multiple components routes to `.../bulk/:id1,:id2,...`. Clicking the canvas background deselects all and returns to the base canvas route. All selection-initiated navigations use `replaceUrl: true` to avoid polluting browser history.
**`skipTransform` mechanism:** When the user selects a component on the canvas, `navigateWithoutTransform` sets `skipTransform: true` in the reducer so the resulting route change does not auto-center the viewport. When a deep link is opened directly, `skipTransform` is false, so `onCanvasInitialized` calls `centerOnSelection()` to center the viewport on the selected component(s).
**`leaveProcessGroup$` update:** Refactored to use the `navigateWithoutTransform` action (instead of direct `router.navigate` + `setSkipTransform`) after navigating to the parent process group and waiting for the flow to load. This auto-selects the child process group in the parent view, giving the user a visual reference of where they came from.
**Test cleanup:** Converted all effects tests from the `new Promise<void>((resolve) => { setup().then(...) })` anti-pattern to `async/await` with `firstValueFrom` from RxJS.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-15818: Implementing route-backed component selection so selecting a processor/connection/etc on the canvas updates the URL, and vice versa. [nifi]
Posted by "rfellows (via GitHub)" <gi...@apache.org>.
rfellows commented on code in PR #11138:
URL: https://github.com/apache/nifi/pull/11138#discussion_r3079950526
##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/connectors/ui/connector-canvas/connector-canvas.component.ts:
##########
@@ -33,6 +33,7 @@ import { Navigation } from '../../../../ui/common/navigation/navigation.componen
import * as ConnectorCanvasActions from '../../state/connector-canvas/connector-canvas.actions';
import * as ConnectorCanvasSelectors from '../../state/connector-canvas/connector-canvas.selectors';
import * as ConnectorCanvasEntityActions from '../../state/connector-canvas-entity/connector-canvas-entity.actions';
+import { selectRouteParams } from '../../state/connector-canvas/connector-canvas.selectors';
Review Comment:
This is already imported and available through `ConnectorCanvasSelectors` on line 34. However, looking at it a bit more closely... it looks like it can probably be imported from `@nifi/shared`. The import and re-export in the canvas selectors isn't needed.
##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/connectors/state/connector-canvas/connector-canvas.effects.spec.ts:
##########
@@ -111,264 +118,307 @@ describe('ConnectorCanvasEffects', () => {
});
describe('loadConnectorFlow$', () => {
- it('should call getConnectorFlow and dispatch loadConnectorFlowSuccess', () =>
- new Promise<void>((resolve) => {
- setup().then(({ effects, actions$, mockConnectorService }) => {
- const flowResponse = {
- processGroupFlow: {
- id: 'pg-123',
- parentGroupId: 'parent-456',
- breadcrumb: null,
- flow: {
- labels: [{ id: 'l1' }],
- funnels: [],
- inputPorts: [],
- outputPorts: [],
- remoteProcessGroups: [],
- processGroups: [],
- processors: [],
- connections: []
- }
- }
- };
- (mockConnectorService.getConnectorFlow as Mock).mockReturnValue(of(flowResponse));
- actions$(
- of(
- loadConnectorFlow({
- connectorId: 'conn-a',
- processGroupId: 'pg-in'
- })
- )
- );
-
- effects.loadConnectorFlow$.subscribe((action) => {
- expect(mockConnectorService.getConnectorFlow).toHaveBeenCalledWith('conn-a', 'pg-in');
- expect(action).toEqual(
- loadConnectorFlowSuccess({
- connectorId: 'conn-a',
- processGroupId: 'pg-123',
- parentProcessGroupId: 'parent-456',
- breadcrumb: null,
- labels: [{ id: 'l1' }],
- funnels: [],
- inputPorts: [],
- outputPorts: [],
- remoteProcessGroups: [],
- processGroups: [],
- processors: [],
- connections: []
- })
- );
- resolve();
- });
- });
- }));
-
- it('should default flow collections when processGroupFlow.flow is missing', () =>
- new Promise<void>((resolve) => {
- setup().then(({ effects, actions$, mockConnectorService }) => {
- const flowResponse = {
- processGroupFlow: {
- id: 'pg-123',
- parentGroupId: null,
- breadcrumb: null
- }
- };
- (mockConnectorService.getConnectorFlow as Mock).mockReturnValue(of(flowResponse));
- actions$(
- of(
- loadConnectorFlow({
- connectorId: 'conn-a',
- processGroupId: 'pg-in'
- })
- )
- );
-
- effects.loadConnectorFlow$.subscribe((action) => {
- expect(action).toEqual(
- loadConnectorFlowSuccess({
- connectorId: 'conn-a',
- processGroupId: 'pg-123',
- parentProcessGroupId: null,
- breadcrumb: null,
- labels: [],
- funnels: [],
- inputPorts: [],
- outputPorts: [],
- remoteProcessGroups: [],
- processGroups: [],
- processors: [],
- connections: []
- })
- );
- resolve();
- });
- });
- }));
-
- it('should dispatch loadConnectorFlowFailure when getConnectorFlow errors', () =>
- new Promise<void>((resolve) => {
- setup().then(({ effects, actions$, mockConnectorService, mockErrorHelper }) => {
- const errorResponse = new HttpErrorResponse({ error: 'Failed', status: 500, statusText: 'ISE' });
- (mockConnectorService.getConnectorFlow as Mock).mockReturnValue(throwError(() => errorResponse));
- actions$(
- of(
- loadConnectorFlow({
- connectorId: 'conn-a',
- processGroupId: 'pg-in'
- })
- )
- );
-
- effects.loadConnectorFlow$.subscribe((action) => {
- expect(mockErrorHelper.getErrorString).toHaveBeenCalledWith(errorResponse);
- expect(action).toEqual(
- loadConnectorFlowFailure({
- errorContext: {
- errors: ['Error message'],
- context: ErrorContextKey.CONNECTORS
- }
- })
- );
- resolve();
- });
- });
- }));
+ it('should call getConnectorFlow and dispatch loadConnectorFlowSuccess', async () => {
+ const { effects, actions$, mockConnectorService } = await setup();
+ const flowResponse = {
+ processGroupFlow: {
+ id: 'pg-123',
+ parentGroupId: 'parent-456',
+ breadcrumb: null,
+ flow: {
+ labels: [{ id: 'l1' }],
+ funnels: [],
+ inputPorts: [],
+ outputPorts: [],
+ remoteProcessGroups: [],
+ processGroups: [],
+ processors: [],
+ connections: []
+ }
+ }
+ };
+ (mockConnectorService.getConnectorFlow as Mock).mockReturnValue(of(flowResponse));
+ actions$(
+ of(
+ loadConnectorFlow({
+ connectorId: 'conn-a',
+ processGroupId: 'pg-in'
+ })
+ )
+ );
+
+ const action = await firstValueFrom(effects.loadConnectorFlow$);
+ expect(mockConnectorService.getConnectorFlow).toHaveBeenCalledWith('conn-a', 'pg-in');
+ expect(action).toEqual(
+ loadConnectorFlowSuccess({
+ connectorId: 'conn-a',
+ processGroupId: 'pg-123',
+ parentProcessGroupId: 'parent-456',
+ breadcrumb: null,
+ labels: [{ id: 'l1' }],
+ funnels: [],
+ inputPorts: [],
+ outputPorts: [],
+ remoteProcessGroups: [],
+ processGroups: [],
+ processors: [],
+ connections: []
+ })
+ );
+ });
+
+ it('should default flow collections when processGroupFlow.flow is missing', async () => {
+ const { effects, actions$, mockConnectorService } = await setup();
+ const flowResponse = {
+ processGroupFlow: {
+ id: 'pg-123',
+ parentGroupId: null,
+ breadcrumb: null
+ }
+ };
+ (mockConnectorService.getConnectorFlow as Mock).mockReturnValue(of(flowResponse));
+ actions$(
+ of(
+ loadConnectorFlow({
+ connectorId: 'conn-a',
+ processGroupId: 'pg-in'
+ })
+ )
+ );
+
+ const action = await firstValueFrom(effects.loadConnectorFlow$);
+ expect(action).toEqual(
+ loadConnectorFlowSuccess({
+ connectorId: 'conn-a',
+ processGroupId: 'pg-123',
+ parentProcessGroupId: null,
+ breadcrumb: null,
+ labels: [],
+ funnels: [],
+ inputPorts: [],
+ outputPorts: [],
+ remoteProcessGroups: [],
+ processGroups: [],
+ processors: [],
+ connections: []
+ })
+ );
+ });
+
+ it('should dispatch loadConnectorFlowFailure when getConnectorFlow errors', async () => {
+ const { effects, actions$, mockConnectorService, mockErrorHelper } = await setup();
+ const errorResponse = new HttpErrorResponse({ error: 'Failed', status: 500, statusText: 'ISE' });
+ (mockConnectorService.getConnectorFlow as Mock).mockReturnValue(throwError(() => errorResponse));
+ actions$(
+ of(
+ loadConnectorFlow({
+ connectorId: 'conn-a',
+ processGroupId: 'pg-in'
+ })
+ )
+ );
+
+ const action = await firstValueFrom(effects.loadConnectorFlow$);
+ expect(mockErrorHelper.getErrorString).toHaveBeenCalledWith(errorResponse);
+ expect(action).toEqual(
+ loadConnectorFlowFailure({
+ errorContext: {
+ errors: ['Error message'],
+ context: ErrorContextKey.CONNECTORS
+ }
+ })
+ );
+ });
});
describe('loadConnectorFlowComplete$', () => {
- it('should dispatch loadConnectorFlowComplete on loadConnectorFlowSuccess', () =>
- new Promise<void>((resolve) => {
- setup().then(({ effects, actions$ }) => {
- actions$(
- of(
- loadConnectorFlowSuccess({
- connectorId: 'c1',
- processGroupId: 'pg1',
- parentProcessGroupId: null,
- breadcrumb: null,
- labels: [],
- funnels: [],
- inputPorts: [],
- outputPorts: [],
- remoteProcessGroups: [],
- processGroups: [],
- processors: [],
- connections: []
- })
- )
- );
-
- effects.loadConnectorFlowComplete$.subscribe((action) => {
- expect(action).toEqual(loadConnectorFlowComplete());
- resolve();
- });
- });
- }));
+ it('should dispatch loadConnectorFlowComplete on loadConnectorFlowSuccess', async () => {
+ const { effects, actions$ } = await setup();
+ actions$(
+ of(
+ loadConnectorFlowSuccess({
+ connectorId: 'c1',
+ processGroupId: 'pg1',
+ parentProcessGroupId: null,
+ breadcrumb: null,
+ labels: [],
+ funnels: [],
+ inputPorts: [],
+ outputPorts: [],
+ remoteProcessGroups: [],
+ processGroups: [],
+ processors: [],
+ connections: []
+ })
+ )
+ );
+
+ const action = await firstValueFrom(effects.loadConnectorFlowComplete$);
+ expect(action).toEqual(loadConnectorFlowComplete());
+ });
});
describe('enterProcessGroup$', () => {
- it('should navigate to the child process group canvas URL', () =>
- new Promise<void>((resolve) => {
- setup({ connectorId: 'my-connector' }).then(({ effects, actions$, mockRouter }) => {
- actions$(
- of(
- enterProcessGroup({
- request: { id: 'child-pg-99' }
- })
- )
- );
-
- effects.enterProcessGroup$.subscribe(() => {
- expect(mockRouter.navigate).toHaveBeenCalledWith([
- '/connectors',
- 'my-connector',
- 'canvas',
- 'child-pg-99'
- ]);
- resolve();
- });
- });
- }));
+ it('should navigate to the child process group canvas URL', async () => {
+ const { effects, actions$, mockRouter } = await setup({ connectorId: 'my-connector' });
+ actions$(
+ of(
+ enterProcessGroup({
+ request: { id: 'child-pg-99' }
+ })
+ )
+ );
+
+ await firstValueFrom(effects.enterProcessGroup$);
+ expect(mockRouter.navigate).toHaveBeenCalledWith(['/connectors', 'my-connector', 'canvas', 'child-pg-99']);
+ });
});
describe('leaveProcessGroup$', () => {
- it('should navigate to parent, then after loadConnectorFlowComplete dispatch setSkipTransform and replaceUrl navigate', () =>
- new Promise<void>((resolve) => {
- setup({
- connectorId: 'conn-x',
- parentProcessGroupId: 'parent-pg',
- processGroupId: 'child-pg'
- }).then(({ effects, actions$, mockRouter, store }) => {
- const dispatchSpy = vi.spyOn(store, 'dispatch');
- const actionSubject = new Subject<Action>();
- actions$(actionSubject.asObservable());
-
- effects.leaveProcessGroup$.subscribe({
- complete: () => {
- expect(mockRouter.navigate).toHaveBeenNthCalledWith(1, [
- '/connectors',
- 'conn-x',
- 'canvas',
- 'parent-pg'
- ]);
- expect(dispatchSpy).toHaveBeenCalledWith(setSkipTransform({ skipTransform: true }));
- expect(mockRouter.navigate).toHaveBeenNthCalledWith(
- 2,
- [
- '/connectors',
- 'conn-x',
- 'canvas',
- 'parent-pg',
- ComponentType.ProcessGroup,
- 'child-pg'
- ],
- { replaceUrl: true }
- );
- resolve();
+ it('should navigate to parent, then after loadConnectorFlowComplete dispatch navigateWithoutTransform', async () => {
+ const { effects, actions$, mockRouter } = await setup({
+ connectorId: 'conn-x',
+ parentProcessGroupId: 'parent-pg',
+ processGroupId: 'child-pg'
+ });
+ const actionSubject = new Subject<Action>();
+ actions$(actionSubject.asObservable());
+
+ const resultPromise = firstValueFrom(effects.leaveProcessGroup$);
+
+ actionSubject.next(leaveProcessGroup());
+ actionSubject.next(loadConnectorFlowComplete());
+ actionSubject.complete();
+
+ const action = await resultPromise;
+ expect(mockRouter.navigate).toHaveBeenCalledWith(['/connectors', 'conn-x', 'canvas', 'parent-pg']);
+ expect(action).toEqual(
+ navigateWithoutTransform({
+ url: ['/connectors', 'conn-x', 'canvas', 'parent-pg', ComponentType.ProcessGroup, 'child-pg']
+ })
+ );
+ });
+
+ it('should not navigate when parent process group id is null', async () => {
+ const { effects, actions$, mockRouter } = await setup({
+ connectorId: 'conn-x',
+ parentProcessGroupId: null,
+ processGroupId: 'child-pg'
+ });
+ actions$(of(leaveProcessGroup()));
+
+ await firstValueFrom(effects.leaveProcessGroup$.pipe(() => of(undefined)));
+ expect(mockRouter.navigate).not.toHaveBeenCalled();
+ });
+
+ it('should not navigate when current process group id is null', async () => {
+ const { effects, actions$, mockRouter } = await setup({
+ connectorId: 'conn-x',
+ parentProcessGroupId: 'parent-pg',
+ processGroupId: null
+ });
+ actions$(of(leaveProcessGroup()));
+
+ await firstValueFrom(effects.leaveProcessGroup$.pipe(() => of(undefined)));
+ expect(mockRouter.navigate).not.toHaveBeenCalled();
+ });
Review Comment:
In RxJS, `.pipe()` expects **operator functions** -- functions that take a source observable and return a new observable using RxJS operators like `map`, `filter`, `switchMap`, etc. But `() => of(undefined)` is a plain function that **ignores its source argument entirely** and just returns `of(undefined)`.
So what actually happens:
1. `effects.leaveProcessGroup$` is created (the effect pipeline)
2. `.pipe(() => of(undefined))` wraps it, but the wrapper throws away the source and returns `of(undefined)`
3. `firstValueFrom` subscribes and immediately gets `undefined` from `of(undefined)`
4. The test then asserts `mockRouter.navigate` was not called -- which passes, but only because the effect was never actually driven
The `filter` at line 202-204 of the effects file is the logic being "tested" here:
```202:204:nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/connectors/state/connector-canvas/connector-canvas.effects.ts
filter(
([, , parentProcessGroupId, currentProcessGroupId]) =>
parentProcessGroupId != null && currentProcessGroupId != null
),
```
These tests are supposed to prove that when `parentProcessGroupId` or `processGroupId` is `null`, the filter blocks navigation. But the tests pass regardless of whether that filter exists.
**Recommendation:**
The tricky part is that when the `filter` blocks, `leaveProcessGroup$` simply never emits. Testing "nothing happened" is inherently awkward. Two reasonable approaches:
**Option A** -- Subscribe, flush, then assert (simplest):
```typescript
it('should not navigate when parent process group id is null', async () => {
const { effects, actions$, mockRouter } = await setup({
connectorId: 'conn-x',
parentProcessGroupId: null,
processGroupId: 'child-pg'
});
actions$(of(leaveProcessGroup()));
// Subscribe to drive the pipeline, then check nothing happened
const results: any[] = [];
effects.leaveProcessGroup$.subscribe((action) => results.push(action));
expect(results).toEqual([]);
expect(mockRouter.navigate).not.toHaveBeenCalled();
});
```
**Option B** -- Use `firstValueFrom` with a timeout that rejects (more explicit):
```typescript
it('should not navigate when parent process group id is null', async () => {
const { effects, actions$, mockRouter } = await setup({
connectorId: 'conn-x',
parentProcessGroupId: null,
processGroupId: 'child-pg'
});
actions$(of(leaveProcessGroup()));
await expect(
firstValueFrom(effects.leaveProcessGroup$.pipe(timeout(50)))
).rejects.toThrow();
expect(mockRouter.navigate).not.toHaveBeenCalled();
});
```
Option A is simpler because the source observable (`of(leaveProcessGroup())`) is synchronous, so the effect pipeline runs synchronously through the filter. By the time the next line executes, the filter has already blocked (or not). No async timing issues.
##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/connectors/state/connector-canvas/connector-canvas.selectors.ts:
##########
@@ -19,7 +19,7 @@ import { createFeatureSelector, createSelector } from '@ngrx/store';
import { getRouterSelectors } from '@ngrx/router-store';
import { ConnectorCanvasState, connectorCanvasFeatureKey } from './index';
-const { selectRouteParams } = getRouterSelectors();
+export const { selectRouteParams } = getRouterSelectors();
Review Comment:
I don't think we need export this here. In fact, it can be imported from `@nifi/shared` and not needed from router-store.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-15818: Implementing route-backed component selection so selecting a processor/connection/etc on the canvas updates the URL, and vice versa. [nifi]
Posted by "rfellows (via GitHub)" <gi...@apache.org>.
rfellows merged PR #11138:
URL: https://github.com/apache/nifi/pull/11138
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org