Skip to content

Commit 0291802

Browse files
authored
tasklist link on summary and history (#690)
1 parent 27fdf36 commit 0291802

18 files changed

+250
-161
lines changed

src/utils/data-formatters/__tests__/format-workflow-history-event-type.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('formatWorkflowHistoryEventType', () => {
2424
it('should handle null input correctly', () => {
2525
const input = null;
2626
const expectedOutput = null;
27+
// @ts-expect-error Testing with wrong attribute null
2728
expect(formatWorkflowHistoryEventType(input)).toEqual(expectedOutput);
2829
});
2930

src/utils/data-formatters/__tests__/format-workflow-history.test.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ describe('formatWorkflowHistory', () => {
3434
history: {
3535
events: [completeActivityTaskEvent],
3636
},
37-
rawHistory: ['raw event data'],
38-
otherData: 'some other data',
37+
rawHistory: [],
38+
nextPageToken: '',
3939
};
4040

4141
const expectedOutput = {
@@ -47,8 +47,8 @@ describe('formatWorkflowHistory', () => {
4747
},
4848
],
4949
},
50-
rawHistory: ['raw event data'],
51-
otherData: 'some other data',
50+
rawHistory: null,
51+
nextPageToken: '',
5252
};
5353

5454
expect(formatWorkflowHistory(input)).toEqual(expectedOutput);
@@ -60,6 +60,7 @@ describe('formatWorkflowHistory', () => {
6060
events: [],
6161
},
6262
rawHistory: [],
63+
nextPageToken: '',
6364
};
6465

6566
const expectedOutput = {
@@ -68,8 +69,9 @@ describe('formatWorkflowHistory', () => {
6869
events: [],
6970
},
7071
rawHistory: null,
72+
nextPageToken: '',
7173
};
72-
74+
//@ts-expect-error testing missing archived field
7375
expect(formatWorkflowHistory(input)).toEqual(expectedOutput);
7476
});
7577

@@ -79,6 +81,8 @@ describe('formatWorkflowHistory', () => {
7981
events: [],
8082
},
8183
rawHistory: [],
84+
nextPageToken: '',
85+
archived: false,
8286
};
8387

8488
const expectedOutput = {
@@ -87,6 +91,7 @@ describe('formatWorkflowHistory', () => {
8791
events: [],
8892
},
8993
rawHistory: null,
94+
nextPageToken: '',
9095
};
9196

9297
expect(formatWorkflowHistory(input)).toEqual(expectedOutput);
@@ -98,15 +103,17 @@ describe('formatWorkflowHistory', () => {
98103
history: {
99104
events: [],
100105
},
101-
rawHistory: ['raw event data'],
106+
rawHistory: [],
107+
nextPageToken: '',
102108
};
103109

104110
const expectedOutput = {
105111
archived: true,
106112
history: {
107113
events: [],
108114
},
109-
rawHistory: ['raw event data'],
115+
rawHistory: null,
116+
nextPageToken: '',
110117
};
111118

112119
expect(formatWorkflowHistory(input)).toEqual(expectedOutput);
@@ -119,6 +126,7 @@ describe('formatWorkflowHistory', () => {
119126
events: [],
120127
},
121128
rawHistory: null,
129+
nextPageToken: '',
122130
};
123131

124132
const expectedOutput = {
@@ -127,8 +135,9 @@ describe('formatWorkflowHistory', () => {
127135
events: [],
128136
},
129137
rawHistory: null,
138+
nextPageToken: '',
130139
};
131-
140+
//@ts-expect-error testing null raw history
132141
expect(formatWorkflowHistory(input)).toEqual(expectedOutput);
133142
});
134143
});

src/utils/data-formatters/format-workflow-history-event-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type TransformEventType<T extends string> = CapitalizeFirstLetter<
3535
>;
3636

3737
const formatWorkflowHistoryEventType = <T extends HistoryEvent['attributes']>(
38-
attributes: T | null
38+
attributes: T
3939
) => {
4040
if (!attributes) return attributes;
4141

src/utils/data-formatters/format-workflow-history-event/format-workflow-execution-started-event.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ const formatWorkflowExecutionStartedEvent = ({
6060
...eventFields
6161
}: WorkflowExecutionStartedEvent) => {
6262
return {
63-
...formatWorkflowCommonEventFields(eventFields),
63+
...formatWorkflowCommonEventFields<'workflowExecutionStartedEventAttributes'>(
64+
eventFields
65+
),
6466
...eventAttributes,
6567
taskList: {
6668
kind: formatEnum(taskList?.kind, 'TASK_LIST_KIND'),

src/utils/data-formatters/format-workflow-history.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22+
import { type GetWorkflowHistoryResponse } from '@/route-handlers/get-workflow-history/get-workflow-history.types';
23+
2224
import formatWorkflowHistoryEvent from './format-workflow-history-event';
2325

2426
const formatWorkflowHistory = ({
2527
archived,
26-
history: { events },
28+
history,
2729
rawHistory,
2830
...response
29-
}: any) => ({
31+
}: GetWorkflowHistoryResponse) => ({
3032
...response,
3133
archived: archived || null,
3234
history: {
33-
events: events.map(formatWorkflowHistoryEvent),
35+
events: (history?.events || []).map(formatWorkflowHistoryEvent),
3436
},
3537
rawHistory: rawHistory?.length ? rawHistory : null,
3638
});

src/utils/data-formatters/schema/format-history-event-schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,7 @@ export type FormattedHistoryEvent =
551551
| FormattedStartChildWorkflowExecutionFailedEvent
552552
| FormattedStartChildWorkflowExecutionInitiatedEvent
553553
| FormattedUpsertWorkflowSearchAttributesEvent;
554+
555+
export type FormattedHistoryEventForType<
556+
T extends FormattedHistoryEvent['eventType'],
557+
> = Extract<FormattedHistoryEvent, { eventType: T }>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react';
2+
3+
import { render } from '@/test-utils/rtl';
4+
5+
import WorkflowHistoryEventDetailsTaskListLink from '../workflow-history-event-details-task-list-link';
6+
import { type Props } from '../workflow-history-event-details-task-list-link.types';
7+
8+
describe('WorkflowHistoryEventDetailsTaskListLink', () => {
9+
const props = {
10+
cluster: 'testCluster',
11+
domain: 'testDomain',
12+
taskList: {
13+
name: 'testTaskListName',
14+
kind: 'NORMAL',
15+
},
16+
} as const satisfies Props;
17+
18+
it('should render the link with correct href', () => {
19+
const { getByText } = render(
20+
<WorkflowHistoryEventDetailsTaskListLink {...props} />
21+
);
22+
23+
const linkElement = getByText(props.taskList.name).closest('a');
24+
expect(linkElement).toHaveAttribute(
25+
'href',
26+
`/domains/${props.domain}/${props.cluster}/task-lists/${props.taskList.name}`
27+
);
28+
});
29+
30+
it('should render sticky task list as text', () => {
31+
const stickyTasklistProps = {
32+
...props,
33+
taskList: {
34+
name: 'testTaskListName',
35+
kind: 'STICKY',
36+
},
37+
} as const satisfies Props;
38+
const { getByText, queryByText } = render(
39+
<WorkflowHistoryEventDetailsTaskListLink {...stickyTasklistProps} />
40+
);
41+
expect(getByText(props.taskList.name)).toBeInTheDocument();
42+
43+
expect(
44+
queryByText(props.taskList.name)?.closest('a')
45+
).not.toBeInTheDocument();
46+
});
47+
48+
it('should not render link if taskList name is empty', () => {
49+
const emptyTasklistProps = {
50+
...props,
51+
taskList: {
52+
name: '',
53+
kind: 'STICKY',
54+
},
55+
} as const satisfies Props;
56+
const { queryByRole } = render(
57+
<WorkflowHistoryEventDetailsTaskListLink {...emptyTasklistProps} />
58+
);
59+
expect(queryByRole('link')).not.toBeInTheDocument();
60+
});
61+
});

src/views/workflow-history/workflow-history-event-details-task-list-link/workflow-history-event-details-task-list-link.tsx renamed to src/views/shared/workflow-history-event-details-task-list-link/workflow-history-event-details-task-list-link.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ import { type Props } from './workflow-history-event-details-task-list-link.type
99
export default function WorkflowHistoryEventDetailsTaskListLink({
1010
cluster,
1111
domain,
12-
entryValue,
12+
taskList,
1313
}: Props) {
14+
if (!taskList?.name) return null;
15+
if (taskList.kind === 'STICKY' || !cluster || !domain) return taskList.name;
1416
return (
1517
<StyledLink
1618
$as={Link}
17-
href={`/domains/${encodeURIComponent(domain)}/${encodeURIComponent(cluster)}/task-lists/${encodeURIComponent(entryValue.name)}`}
19+
href={`/domains/${encodeURIComponent(domain)}/${encodeURIComponent(cluster)}/task-lists/${encodeURIComponent(taskList.name)}`}
1820
style={{ fontWeight: 'inherit' }}
1921
>
20-
{entryValue.name}
22+
{taskList?.name}
2123
</StyledLink>
2224
);
2325
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type Props = {
2+
cluster: string;
3+
domain: string;
4+
taskList: { name: string | null; kind: 'NORMAL' | 'STICKY' | null } | null;
5+
};

src/views/workflow-history/config/workflow-history-event-details.config.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { createElement } from 'react';
2+
13
import formatDate from '@/utils/data-formatters/format-date';
24

5+
import WorkflowHistoryEventDetailsTaskListLink from '../../shared/workflow-history-event-details-task-list-link/workflow-history-event-details-task-list-link';
36
import { type WorkflowHistoryEventDetailsConfig } from '../workflow-history-event-details/workflow-history-event-details.types';
47
import WorkflowHistoryEventDetailsJson from '../workflow-history-event-details-json/workflow-history-event-details-json';
5-
import WorkflowHistoryEventDetailsTaskListLink from '../workflow-history-event-details-task-list-link/workflow-history-event-details-task-list-link';
68

79
const workflowHistoryEventDetailsConfig = [
810
{
@@ -18,7 +20,13 @@ const workflowHistoryEventDetailsConfig = [
1820
{
1921
name: 'Tasklists as links',
2022
key: 'taskList',
21-
valueComponent: WorkflowHistoryEventDetailsTaskListLink,
23+
valueComponent: ({ entryValue, domain, cluster }) => {
24+
return createElement(WorkflowHistoryEventDetailsTaskListLink, {
25+
domain: domain,
26+
cluster: cluster,
27+
taskList: entryValue,
28+
});
29+
},
2230
},
2331
{
2432
name: 'Json as PrettyJson',

0 commit comments

Comments
 (0)