From d583f7639b3d8e9507a36f2db89ab9800a86ae2c Mon Sep 17 00:00:00 2001 From: Alexandre Amalric <119614409+aamalric-talend@users.noreply.github.com> Date: Tue, 19 Sep 2023 14:04:59 +0200 Subject: [PATCH] fix(TFD-15974): Fix calculate port position with portId action (#4897) --- .changeset/silver-feet-exercise.md | 5 +++++ .../src/reducers/flow.reducer.test.ts | 14 ++++++++++++++ .../flow-designer/src/reducers/flow.reducer.ts | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .changeset/silver-feet-exercise.md diff --git a/.changeset/silver-feet-exercise.md b/.changeset/silver-feet-exercise.md new file mode 100644 index 00000000000..39ddf987227 --- /dev/null +++ b/.changeset/silver-feet-exercise.md @@ -0,0 +1,5 @@ +--- +'@talend/react-flow-designer': minor +--- + +fix(TFD-15974): Fix calculate port position with portId action diff --git a/packages/flow-designer/src/reducers/flow.reducer.test.ts b/packages/flow-designer/src/reducers/flow.reducer.test.ts index b7be353ed53..784cda1531b 100644 --- a/packages/flow-designer/src/reducers/flow.reducer.test.ts +++ b/packages/flow-designer/src/reducers/flow.reducer.test.ts @@ -184,4 +184,18 @@ describe('calculatePortsPosition behavior', () => { }); expect(calculatePortPosition.mock.calls.length).toEqual(0); }); + + it('should trigger using action with port id', () => { + const calculatePortPosition = jest.fn(); + const givenState = state.setIn(['nodeTypes', '42', 'component'], { calculatePortPosition }); + const action = { + type: 'FLOWDESIGNER_PORT_SET_DATA', + portId: '42', + data: { + flowType: '__default__', + }, + }; + calculatePortsPosition(givenState, action); + expect(calculatePortPosition.mock.calls.length).toEqual(1); + }); }); diff --git a/packages/flow-designer/src/reducers/flow.reducer.ts b/packages/flow-designer/src/reducers/flow.reducer.ts index ef63897deff..7da71b56926 100644 --- a/packages/flow-designer/src/reducers/flow.reducer.ts +++ b/packages/flow-designer/src/reducers/flow.reducer.ts @@ -166,7 +166,7 @@ export function calculatePortsPosition(state: State, action: any) { if (action.nodeId) { nodes.push(state.getIn(['nodes', action.nodeId])); } else if (action.portId) { - nodes.push(state.getIn(['nodes'], state.getIn(['ports', action.portId]).nodeId)); + nodes.push(state.getIn(['nodes', state.getIn(['ports', action.portId]).nodeId])); } else { nodes = state.get('nodes'); }