fix(editor): Fix executions sorting (#11808)

This commit is contained in:
Raúl Gómez Morales 2024-11-20 15:33:16 +01:00 committed by GitHub
parent 187edf28aa
commit cd5ad65e90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 52 additions and 4 deletions

View file

@ -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 //
}

View file

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

View file

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

View file

@ -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,

View file

@ -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: [],
@ -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: [],
@ -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: [],
@ -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 () => {
@ -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' }));
});
});

View file

@ -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;

View file

@ -656,6 +656,7 @@ function generateMockExecutionEvents() {
finished: false,
mode: 'cli',
startedAt: new Date(),
createdAt: new Date(),
status: 'new',
data: {
resultData: {

View file

@ -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;