fix(editor): Fix Cannot read properties of undefined (reading 'finished') (#11367)

This commit is contained in:
Raúl Gómez Morales 2024-10-24 08:57:32 +02:00 committed by GitHub
parent e61a8535aa
commit 475d72e0bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 60 additions and 18 deletions

View file

@ -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() {

View file

@ -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];
Object.assign(activeExecutions.value[activeExecutionIndex], {
...(finishedActiveExecution.executionId !== undefined
? { id: finishedActiveExecution.executionId }
: {}),
finished: finishedActiveExecution.data?.finished,
stoppedAt: finishedActiveExecution.data?.stoppedAt,
});
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),
];
if (finishedActiveExecution.data && (finishedActiveExecution.data as IRun).data) {
setWorkflowExecutionRunData((finishedActiveExecution.data as IRun).data);
if (finishedActiveExecution.data?.data) {
setWorkflowExecutionRunData(finishedActiveExecution.data.data);
}
}