Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Fix executions sorting #11808

Merged
merged 10 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -240,6 +240,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()),
);
Comment on lines +61 to +67
Copy link
Contributor Author

@r00gm r00gm Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this test so it doesn't depend on how the array is sorted

});

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
Loading