Skip to content

Commit

Permalink
fix(editor): Fix executions sorting (#11808)
Browse files Browse the repository at this point in the history
  • Loading branch information
r00gm authored Nov 20, 2024
1 parent 187edf2 commit cd5ad65
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export interface IExecutionBase {
retryOf?: string;
retrySuccessId?: string;
startedAt: Date;
createdAt: Date;
stoppedAt?: Date;
workflowId?: string; // To be able to filter executions easily //
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const executionDataFactory = (): ExecutionSummary => ({
id: faker.string.uuid(),
finished: faker.datatype.boolean(),
mode: faker.helpers.arrayElement(['manual', 'trigger']),
createdAt: faker.date.past(),
startedAt: faker.date.past(),
stoppedAt: faker.date.past(),
workflowId: faker.number.int().toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const executionDataFactory = (): ExecutionSummaryWithScopes => ({
id: faker.string.uuid(),
finished: faker.datatype.boolean(),
mode: faker.helpers.arrayElement(['manual', 'trigger']),
createdAt: faker.date.past(),
startedAt: faker.date.past(),
stoppedAt: faker.date.past(),
workflowId: faker.number.int().toString(),
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/composables/useRunWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
finished: false,
mode: 'manual',
status: 'running',
createdAt: new Date(),
startedAt: new Date(),
stoppedAt: undefined,
workflowId: workflow.id,
Expand Down
47 changes: 45 additions & 2 deletions packages/editor-ui/src/stores/executions.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('executions.store', () => {
id: '3',
mode: 'manual',
status: 'success',
createdAt: new Date('2021-01-01T00:00:00Z'),
startedAt: new Date('2021-01-03T00:00:00Z'),
workflowId: '1',
scopes: [],
Expand All @@ -30,6 +31,7 @@ describe('executions.store', () => {
id: '2',
mode: 'manual',
status: 'success',
createdAt: new Date('2021-01-02T00:00:00Z'),
startedAt: new Date('2021-01-02T00:00:00Z'),
workflowId: '1',
scopes: [],
Expand All @@ -38,6 +40,7 @@ describe('executions.store', () => {
id: '1',
mode: 'manual',
status: 'success',
createdAt: new Date('2021-01-03T00:00:00Z'),
startedAt: new Date('2021-01-01T00:00:00Z'),
workflowId: '1',
scopes: [],
Expand All @@ -55,9 +58,13 @@ describe('executions.store', () => {
});

it('should delete executions started before given date', async () => {
await executionsStore.deleteExecutions({ deleteBefore: mockExecutions[1].startedAt });
const deleteBefore = mockExecutions[1].startedAt;
await executionsStore.deleteExecutions({ deleteBefore });

expect(executionsStore.executions).toEqual([mockExecutions[0], mockExecutions[1]]);
expect(executionsStore.executions.length).toBe(2);
executionsStore.executions.forEach(({ startedAt }) =>
expect(startedAt.getTime()).toBeGreaterThanOrEqual(deleteBefore.getTime()),
);
});

it('should delete all executions if given date is now', async () => {
Expand All @@ -66,4 +73,40 @@ describe('executions.store', () => {
expect(executionsStore.executions).toEqual([]);
});
});

it('should sort execution by createdAt', () => {
const mockExecutions: ExecutionSummaryWithScopes[] = [
{
id: '1',
mode: 'manual',
status: 'success',
createdAt: new Date('2021-01-01T00:00:00Z'),
startedAt: new Date('2021-02-03T00:00:00Z'),
workflowId: '1',
scopes: [],
},
{
id: '2',
mode: 'manual',
status: 'success',
createdAt: new Date('2021-01-02T00:00:00Z'),
startedAt: new Date('2021-02-02T00:00:00Z'),
workflowId: '1',
scopes: [],
},
{
id: '3',
mode: 'manual',
status: 'success',
createdAt: new Date('2021-01-03T00:00:00Z'),
startedAt: new Date('2021-02-01T00:00:00Z'),
workflowId: '1',
scopes: [],
},
];

mockExecutions.forEach(executionsStore.addExecution);

expect(executionsStore.executions.at(-1)).toEqual(expect.objectContaining({ id: '1' }));
});
});
2 changes: 1 addition & 1 deletion packages/editor-ui/src/stores/executions.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const useExecutionsStore = defineStore('executions', () => {
const data = Object.values(executionsById.value);

data.sort((a, b) => {
return new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime();
return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
});

return data;
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/stores/workflows.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ function generateMockExecutionEvents() {
finished: false,
mode: 'cli',
startedAt: new Date(),
createdAt: new Date(),
status: 'new',
data: {
resultData: {
Expand Down
2 changes: 1 addition & 1 deletion packages/workflow/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,7 @@ export interface ExecutionSummary {
retryOf?: string | null;
retrySuccessId?: string | null;
waitTill?: Date;
createdAt?: Date;
createdAt: Date;
startedAt: Date;
stoppedAt?: Date;
workflowId: string;
Expand Down

0 comments on commit cd5ad65

Please sign in to comment.