Skip to content

Commit a01c3d7

Browse files
show workflow execution with no runid (#846)
* match only complete execution objects * lint * render workflowId as link * add more test cases * rename component and support basic visibility * Update src/views/shared/workflow-event-details-execution-link/workflow-event-details-execution-link.tsx --------- Co-authored-by: Adhitya Mamallan <[email protected]>
1 parent 5a518cd commit a01c3d7

File tree

7 files changed

+132
-79
lines changed

7 files changed

+132
-79
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import React from 'react';
2+
3+
import omit from 'lodash/omit';
4+
import pick from 'lodash/pick';
5+
6+
import { screen, render } from '@/test-utils/rtl';
7+
8+
import WorkflowEventDetailsExecutionLink from '../workflow-event-details-execution-link';
9+
10+
describe('WorkflowEventDetailsExecutionLink', () => {
11+
const props = {
12+
runId: 'testRunId',
13+
workflowId: 'testWorkflowId',
14+
cluster: 'testCluster',
15+
domain: 'testDomain',
16+
};
17+
18+
it('should render the link with correct workflow run link', () => {
19+
render(<WorkflowEventDetailsExecutionLink {...props} />);
20+
21+
const linkElement = screen.getByRole('link');
22+
expect(linkElement).toHaveAttribute(
23+
'href',
24+
`/domains/${props.domain}/${props.cluster}/workflows/${props.workflowId}/${props.runId}`
25+
);
26+
});
27+
28+
it('should render runId as a the link text for workflow run link', () => {
29+
render(<WorkflowEventDetailsExecutionLink {...props} />);
30+
31+
const linkElement = screen.getByRole('link', { name: props.runId });
32+
expect(linkElement).toBeInTheDocument();
33+
});
34+
35+
it('should render the link with correct workflow search link', () => {
36+
render(
37+
<WorkflowEventDetailsExecutionLink
38+
domain={props.domain}
39+
cluster={props.cluster}
40+
workflowId={props.workflowId}
41+
runId=""
42+
/>
43+
);
44+
45+
const linkElement = screen.getByRole('link');
46+
expect(linkElement).toHaveAttribute(
47+
'href',
48+
`/domains/${props.domain}/${props.cluster}/workflows?search=${props.workflowId}&workflowId=${props.workflowId}`
49+
);
50+
});
51+
52+
it('should render workflowId as a the link text for workflow search link', () => {
53+
render(
54+
<WorkflowEventDetailsExecutionLink
55+
domain={props.domain}
56+
cluster={props.cluster}
57+
workflowId={props.workflowId}
58+
runId=""
59+
/>
60+
);
61+
62+
const linkElement = screen.getByRole('link', { name: props.workflowId });
63+
expect(linkElement).toBeInTheDocument();
64+
});
65+
66+
it('should not render link if runId and workflowId is missing', () => {
67+
render(
68+
<WorkflowEventDetailsExecutionLink
69+
domain={props.domain}
70+
cluster={props.cluster}
71+
workflowId=""
72+
runId=""
73+
/>
74+
);
75+
76+
expect(screen.queryByRole('link')).not.toBeInTheDocument();
77+
});
78+
79+
it('should render disabled link with empty href if domain, cluster or workflowId is missing', () => {
80+
const propKeys = Object.keys(
81+
pick(props, ['domain', 'cluster', 'workflowId'])
82+
);
83+
84+
propKeys.forEach((key) => {
85+
const { container } = render(
86+
// @ts-expect-error testing missing props
87+
<WorkflowEventDetailsExecutionLink {...omit(props, key)} />
88+
);
89+
const linkElement = container.querySelector('a');
90+
expect(linkElement).toHaveAttribute('href', '/');
91+
});
92+
});
93+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use client';
2+
import React from 'react';
3+
4+
import queryString from 'query-string';
5+
6+
import Link from '@/components/link/link';
7+
8+
import { type Props } from './workflow-event-details-execution-link.types';
9+
10+
export default function WorkflowEventDetailsExecutionLink({
11+
runId,
12+
workflowId,
13+
cluster,
14+
domain,
15+
}: Props) {
16+
const linkText = runId || workflowId;
17+
if (!linkText) return null;
18+
19+
let href = '';
20+
if (domain && cluster && workflowId) {
21+
href = runId
22+
? `/domains/${encodeURIComponent(domain)}/${encodeURIComponent(cluster)}/workflows/${encodeURIComponent(workflowId)}/${encodeURIComponent(runId)}`
23+
: // TODO: @assem.hafez make query params type safe
24+
// NOTE: workflowId is passed to both search and workflowId to support basic/advanced/visibility
25+
`/domains/${encodeURIComponent(domain)}/${encodeURIComponent(cluster)}/workflows?${queryString.stringify({ search: workflowId, workflowId })}`;
26+
}
27+
28+
return (
29+
<Link href={href} style={{ fontWeight: 'inherit' }}>
30+
{linkText}
31+
</Link>
32+
);
33+
}

src/views/shared/workflow-history-event-details-wf-execution-link/__tests__/workflow-summary-tab-details-wf-execution-link.test.tsx

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/views/shared/workflow-history-event-details-wf-execution-link/workflow-history-event-details-wf-execution-link.tsx

Lines changed: 0 additions & 24 deletions
This file was deleted.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createElement } from 'react';
22

33
import formatDate from '@/utils/data-formatters/format-date';
44
import formatDuration from '@/utils/data-formatters/format-duration';
5-
import WorkflowHistoryEventDetailsExecutionLink from '@/views/shared/workflow-history-event-details-wf-execution-link/workflow-history-event-details-wf-execution-link';
5+
import WorkflowEventDetailsExecutionLink from '@/views/shared/workflow-event-details-execution-link/workflow-event-details-execution-link';
66

77
import WorkflowHistoryEventDetailsTaskListLink from '../../shared/workflow-history-event-details-task-list-link/workflow-history-event-details-task-list-link';
88
import { type WorkflowHistoryEventDetailsConfig } from '../workflow-history-event-details/workflow-history-event-details.types';
@@ -62,7 +62,7 @@ const workflowHistoryEventDetailsConfig = [
6262
pathRegex:
6363
'(parentWorkflowExecution|externalWorkflowExecution|workflowExecution)$',
6464
valueComponent: ({ entryValue, domain, cluster }) => {
65-
return createElement(WorkflowHistoryEventDetailsExecutionLink, {
65+
return createElement(WorkflowEventDetailsExecutionLink, {
6666
domain,
6767
cluster,
6868
workflowId: entryValue?.workflowId,
@@ -75,7 +75,7 @@ const workflowHistoryEventDetailsConfig = [
7575
pathRegex:
7676
'(firstExecutionRunId|originalExecutionRunId|newExecutionRunId)$',
7777
valueComponent: ({ entryValue, domain, cluster, workflowId }) => {
78-
return createElement(WorkflowHistoryEventDetailsExecutionLink, {
78+
return createElement(WorkflowEventDetailsExecutionLink, {
7979
domain,
8080
cluster,
8181
workflowId,

src/views/workflow-summary-tab/config/workflow-summary-tab-details.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import WorkflowHistoryEventDetailsTaskListLink from '@/views/shared/workflow-his
55
import WorkflowStatusTag from '@/views/shared/workflow-status-tag/workflow-status-tag';
66
import getWorkflowStatusTagProps from '@/views/workflow-page/helpers/get-workflow-status-tag-props';
77

8-
import WorkflowHistoryEventDetailsExecutionLink from '../../shared/workflow-history-event-details-wf-execution-link/workflow-history-event-details-wf-execution-link';
8+
import WorkflowEventDetailsExecutionLink from '../../shared/workflow-event-details-execution-link/workflow-event-details-execution-link';
99
import { type WorkflowSummaryTabDetailsConfig } from '../workflow-summary-tab-details/workflow-summary-tab-details.types';
1010

1111
const workflowSummaryTabDetailsConfig: WorkflowSummaryTabDetailsConfig[] = [
@@ -34,7 +34,7 @@ const workflowSummaryTabDetailsConfig: WorkflowSummaryTabDetailsConfig[] = [
3434
firstEvent?.workflowExecutionStartedEventAttributes
3535
?.continuedExecutionRunId;
3636
if (runId) {
37-
return createElement(WorkflowHistoryEventDetailsExecutionLink, {
37+
return createElement(WorkflowEventDetailsExecutionLink, {
3838
...decodedPageUrlParams,
3939
runId,
4040
});
@@ -129,7 +129,7 @@ const workflowSummaryTabDetailsConfig: WorkflowSummaryTabDetailsConfig[] = [
129129
formattedFirstEvent?.parentWorkflowExecution || {};
130130
const domain = formattedFirstEvent?.parentWorkflowDomain;
131131
if (runId && workflowId && domain && decodedPageUrlParams.cluster) {
132-
return createElement(WorkflowHistoryEventDetailsExecutionLink, {
132+
return createElement(WorkflowEventDetailsExecutionLink, {
133133
domain,
134134
cluster: decodedPageUrlParams.cluster,
135135
workflowId,

0 commit comments

Comments
 (0)