diff --git a/packages/editor-ui/src/stores/workflows.store.spec.ts b/packages/editor-ui/src/stores/workflows.store.spec.ts index 1c3fbf9e8fd9f..acf86d0744497 100644 --- a/packages/editor-ui/src/stores/workflows.store.spec.ts +++ b/packages/editor-ui/src/stores/workflows.store.spec.ts @@ -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 { @@ -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() { diff --git a/packages/editor-ui/src/stores/workflows.store.ts b/packages/editor-ui/src/stores/workflows.store.ts index b93b00106ad1c..08bee0d448efc 100644 --- a/packages/editor-ui/src/stores/workflows.store.ts +++ b/packages/editor-ui/src/stores/workflows.store.ts @@ -47,7 +47,6 @@ import type { INodeParameters, INodeTypes, IPinData, - IRun, IRunData, IRunExecutionData, ITaskData, @@ -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); } }