Skip to content

Commit

Permalink
fix(editor): Fix Cannot read properties of undefined (reading 'finish…
Browse files Browse the repository at this point in the history
…ed') (#11367)
  • Loading branch information
r00gm authored Oct 24, 2024
1 parent e61a853 commit 475d72e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
52 changes: 51 additions & 1 deletion packages/editor-ui/src/stores/workflows.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import {
WAIT_NODE_TYPE,
} from '@/constants';
import { useWorkflowsStore } from '@/stores/workflows.store';
import type { IExecutionResponse, INodeUi, IWorkflowDb, IWorkflowSettings } from '@/Interface';
import type {
IExecutionResponse,
IExecutionsCurrentSummaryExtended,
INodeUi,
IWorkflowDb,
IWorkflowSettings,
} from '@/Interface';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';

import {
Expand Down Expand Up @@ -594,6 +600,50 @@ describe('useWorkflowsStore', () => {
);
});
});

describe('finishActiveExecution', () => {
it('should update execution', async () => {
const cursor = 1;
const ids = ['0', '1', '2'];
workflowsStore.setActiveExecutions(
ids.map((id) => ({ id })) as IExecutionsCurrentSummaryExtended[],
);

const stoppedAt = new Date();

workflowsStore.finishActiveExecution({
executionId: ids[cursor],
data: {
finished: true,
stoppedAt,
},
} as PushPayload<'executionFinished'>);

expect(workflowsStore.activeExecutions[cursor]).toStrictEqual({
id: ids[cursor],
finished: true,
stoppedAt,
});
});

it('should handle parameter casting', async () => {
const cursor = 1;
const ids = ['0', '1', '2'];
workflowsStore.setActiveExecutions(
ids.map((id) => ({ id })) as IExecutionsCurrentSummaryExtended[],
);

workflowsStore.finishActiveExecution({
executionId: ids[cursor],
} as PushPayload<'executionFinished'>);

expect(workflowsStore.activeExecutions[cursor]).toStrictEqual({
id: ids[cursor],
finished: undefined,
stoppedAt: undefined,
});
});
});
});

function getMockEditFieldsNode() {
Expand Down
26 changes: 9 additions & 17 deletions packages/editor-ui/src/stores/workflows.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import type {
INodeParameters,
INodeTypes,
IPinData,
IRun,
IRunData,
IRunExecutionData,
ITaskData,
Expand Down Expand Up @@ -1344,23 +1343,16 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, () => {
return;
}

const activeExecution = activeExecutions.value[activeExecutionIndex];

activeExecutions.value = [
...activeExecutions.value.slice(0, activeExecutionIndex),
{
...activeExecution,
...(finishedActiveExecution.executionId !== undefined
? { id: finishedActiveExecution.executionId }
: {}),
finished: finishedActiveExecution.data.finished,
stoppedAt: finishedActiveExecution.data.stoppedAt,
},
...activeExecutions.value.slice(activeExecutionIndex + 1),
];
Object.assign(activeExecutions.value[activeExecutionIndex], {
...(finishedActiveExecution.executionId !== undefined
? { id: finishedActiveExecution.executionId }
: {}),
finished: finishedActiveExecution.data?.finished,
stoppedAt: finishedActiveExecution.data?.stoppedAt,
});

if (finishedActiveExecution.data && (finishedActiveExecution.data as IRun).data) {
setWorkflowExecutionRunData((finishedActiveExecution.data as IRun).data);
if (finishedActiveExecution.data?.data) {
setWorkflowExecutionRunData(finishedActiveExecution.data.data);
}
}

Expand Down

0 comments on commit 475d72e

Please sign in to comment.