Skip to content

Commit c5e14fd

Browse files
authored
fix(orchestrator): set default workflow runs table size to 20 (#1127)
fix(orchestrator): increase default workflow runs table size from 5 to 10
1 parent eaff621 commit c5e14fd

File tree

4 files changed

+86
-9
lines changed

4 files changed

+86
-9
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {
2+
ProcessInstance,
3+
ProcessInstanceState,
4+
WorkflowCategory,
5+
} from '@janus-idp/backstage-plugin-orchestrator-common';
6+
7+
import { fakeWorkflowOverviewList } from './fakeWorkflowOverviewList';
8+
9+
const createValuesGenerator = (counter: number, size: number) => {
10+
const baseDate = new Date('2024-02-01');
11+
const DAY = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
12+
const startDate = new Date(baseDate.getTime() - 30 * DAY); // 30 days ago
13+
const endDate = new Date();
14+
15+
const getNextEnumValue = (enumerator: object) => {
16+
const values = Object.values(enumerator);
17+
const index = counter % values.length;
18+
return values[index];
19+
};
20+
21+
const getNextDate = (): Date => {
22+
const startMillis = startDate.getTime();
23+
const endMillis = endDate.getTime();
24+
const millis =
25+
startMillis + ((endMillis - startMillis) / size) * (counter % size); // Assuming 5 states
26+
return new Date(millis);
27+
};
28+
29+
return {
30+
getNextEnumValue,
31+
getNextDate,
32+
};
33+
};
34+
35+
export const generateFakeProcessInstances = (
36+
listSize: number,
37+
): ProcessInstance[] => {
38+
const instances: ProcessInstance[] = [];
39+
40+
for (let i = 0; i < listSize; i++) {
41+
const valuesGenerator = createValuesGenerator(i, listSize);
42+
43+
const randomState = valuesGenerator.getNextEnumValue(ProcessInstanceState);
44+
const randomCategory = valuesGenerator.getNextEnumValue(WorkflowCategory);
45+
46+
instances.push({
47+
id: `12f767c1-9002-43af-9515-62a72d0eaf${i}`,
48+
processId:
49+
fakeWorkflowOverviewList[i % fakeWorkflowOverviewList.length]
50+
.workflowId,
51+
state: randomState,
52+
endpoint: 'enpoint/foo',
53+
start: valuesGenerator.getNextDate(),
54+
lastUpdate: valuesGenerator.getNextDate(),
55+
nodes: [],
56+
variables: {},
57+
isOpen: false,
58+
isSelected: false,
59+
category: randomCategory,
60+
description: `test description ${i}`,
61+
});
62+
}
63+
64+
return instances;
65+
};

plugins/orchestrator/src/components/WorkflowRunsTabContent.stories.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { TestApiProvider, wrapInTestApp } from '@backstage/test-utils';
44

55
import { Meta, StoryObj } from '@storybook/react';
66

7-
import { WorkflowOverview } from '@janus-idp/backstage-plugin-orchestrator-common';
8-
9-
import { fakeProcessInstances } from '../__fixtures__/fakeProcessInstance';
7+
import { generateFakeProcessInstances } from '../__fixtures__/fakeLongProcessInstanceList';
108
import { fakeWorkflowOverviewList } from '../__fixtures__/fakeWorkflowOverviewList';
119
import { orchestratorApiRef } from '../api';
1210
import { MockOrchestratorClient } from '../api/MockOrchestratorClient';
@@ -19,12 +17,16 @@ const meta = {
1917
decorators: [
2018
(Story, context) => {
2119
const api = new MockOrchestratorClient({
22-
getInstancesResponse: Promise.resolve(fakeProcessInstances),
20+
getInstancesResponse: Promise.resolve(
21+
generateFakeProcessInstances(
22+
(context.args as { length: number }).length,
23+
),
24+
),
2325
listWorkflowsOverviewResponse: Promise.resolve({
2426
limit: 0,
2527
offset: 0,
2628
totalCount: 1,
27-
items: (context.args as { items: WorkflowOverview[] }).items,
29+
items: fakeWorkflowOverviewList,
2830
}),
2931
});
3032

@@ -48,9 +50,16 @@ const meta = {
4850
type Story = StoryObj<typeof meta>;
4951

5052
export const WorkflowRunsTabContentStory: Story = {
51-
name: 'Sample 1',
53+
name: 'Short list',
54+
args: {
55+
length: 3,
56+
},
57+
};
58+
59+
export const WorkflowRunsTabContentLongListStory: Story = {
60+
name: 'Long list',
5261
args: {
53-
items: fakeWorkflowOverviewList,
62+
length: 100,
5463
},
5564
};
5665

plugins/orchestrator/src/components/WorkflowRunsTabContent.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '@janus-idp/backstage-plugin-orchestrator-common';
1919

2020
import { orchestratorApiRef } from '../api';
21-
import { VALUE_UNAVAILABLE } from '../constants';
21+
import { DEFAULT_TABLE_PAGE_SIZE, VALUE_UNAVAILABLE } from '../constants';
2222
import usePolling from '../hooks/usePolling';
2323
import { workflowInstanceRouteRef } from '../routes';
2424
import { capitalize, ellipsis } from '../utils/StringUtils';
@@ -116,6 +116,7 @@ export const WorkflowRunsTabContent = () => {
116116
),
117117
[statusSelectorValue, statuses],
118118
);
119+
const paging = (value?.length || 0) > DEFAULT_TABLE_PAGE_SIZE; // this behavior fits the backstage catalog table behavior https://github.com/backstage/backstage/blob/v1.14.0/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx#L228
119120

120121
return error ? (
121122
<ErrorPanel error={error} />
@@ -124,8 +125,9 @@ export const WorkflowRunsTabContent = () => {
124125
<Table
125126
title="Workflow Runs"
126127
options={{
128+
paging,
127129
search: true,
128-
paging: true,
130+
pageSize: DEFAULT_TABLE_PAGE_SIZE,
129131
}}
130132
isLoading={loading}
131133
columns={columns}

plugins/orchestrator/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const VALUE_UNAVAILABLE = '---' as const;
22
export const SHORT_REFRESH_INTERVAL = 5000;
33
export const LONG_REFRESH_INTERVAL = 15000;
4+
export const DEFAULT_TABLE_PAGE_SIZE = 20;

0 commit comments

Comments
 (0)