Skip to content

Commit d9d63bc

Browse files
feat: Workflow History V2 - show Remaining Duration for relevant events (#1115)
Display Remaining Duration badge (implemented in #1036) in Duration column in the Grouped History table Signed-off-by: Adhitya Mamallan <[email protected]>
1 parent e252d82 commit d9d63bc

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

src/views/workflow-history-v2/workflow-history-event-group-duration/__tests__/workflow-history-event-group-duration.test.tsx

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ jest.mock('../helpers/get-formatted-events-duration', () =>
1616
)
1717
);
1818

19+
jest.mock(
20+
'@/views/workflow-history/workflow-history-remaining-duration-badge/workflow-history-remaining-duration-badge',
21+
() => {
22+
return function MockWorkflowHistoryRemainingDurationBadge({
23+
prefix,
24+
expectedEndTime,
25+
}: {
26+
prefix: string;
27+
expectedEndTime: number;
28+
}) {
29+
return (
30+
<div data-testid="end-time-badge">{`${prefix} ${expectedEndTime}`}</div>
31+
);
32+
};
33+
}
34+
);
35+
1936
const mockStartTime = new Date('2024-01-01T10:00:00Z').getTime();
2037
const mockCloseTime = new Date('2024-01-01T10:01:00Z').getTime();
2138
const mockNow = new Date('2024-01-01T10:02:00Z').getTime();
@@ -111,15 +128,6 @@ describe('WorkflowHistoryEventGroupDuration', () => {
111128
expect(getFormattedEventsDuration).toHaveBeenCalledTimes(2);
112129
});
113130

114-
it('cleans up interval when component unmounts', () => {
115-
const { unmount } = setup();
116-
117-
const clearIntervalSpy = jest.spyOn(global, 'clearInterval');
118-
unmount();
119-
120-
expect(clearIntervalSpy).toHaveBeenCalled();
121-
});
122-
123131
it('uses workflow close time when close time is not provided', () => {
124132
setup({
125133
closeTime: null,
@@ -133,6 +141,28 @@ describe('WorkflowHistoryEventGroupDuration', () => {
133141
);
134142
expect(screen.getByText('60')).toBeInTheDocument();
135143
});
144+
145+
it('renders end time badge when expectedEndTimeInfo is provided', () => {
146+
const expectedEndTime = new Date('2024-01-01T10:05:00Z').getTime();
147+
setup({
148+
expectedEndTimeInfo: {
149+
timeMs: expectedEndTime,
150+
prefix: 'Fires in',
151+
},
152+
});
153+
154+
expect(screen.getByTestId('end-time-badge')).toBeInTheDocument();
155+
expect(screen.getByText(`Fires in ${expectedEndTime}`)).toBeInTheDocument();
156+
});
157+
158+
it('cleans up interval when component unmounts', () => {
159+
const { unmount } = setup();
160+
161+
const clearIntervalSpy = jest.spyOn(global, 'clearInterval');
162+
unmount();
163+
164+
expect(clearIntervalSpy).toHaveBeenCalled();
165+
});
136166
});
137167

138168
function setup({
@@ -144,6 +174,7 @@ function setup({
144174
workflowIsArchived = false,
145175
workflowCloseStatus = WorkflowExecutionCloseStatus.WORKFLOW_EXECUTION_CLOSE_STATUS_INVALID,
146176
workflowCloseTime = null,
177+
expectedEndTimeInfo,
147178
}: Partial<Props> = {}) {
148179
return render(
149180
<WorkflowHistoryEventGroupDuration
@@ -155,6 +186,7 @@ function setup({
155186
workflowIsArchived={workflowIsArchived}
156187
workflowCloseStatus={workflowCloseStatus}
157188
workflowCloseTime={workflowCloseTime}
189+
expectedEndTimeInfo={expectedEndTimeInfo}
158190
/>
159191
);
160192
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { styled as createStyled, type Theme } from 'baseui';
2+
3+
export const styled = {
4+
DurationContainer: createStyled('div', ({ $theme }: { $theme: Theme }) => ({
5+
display: 'flex',
6+
alignItems: 'baseline',
7+
gap: $theme.sizing.scale200,
8+
})),
9+
};

src/views/workflow-history-v2/workflow-history-event-group-duration/workflow-history-event-group-duration.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import React, { useEffect, useState } from 'react';
22

3+
import WorkflowHistoryRemainingDurationBadge from '@/views/workflow-history/workflow-history-remaining-duration-badge/workflow-history-remaining-duration-badge';
4+
35
import getFormattedEventsDuration from './helpers/get-formatted-events-duration';
6+
import { styled } from './workflow-history-event-group-duration.styles';
47
import { type Props } from './workflow-history-event-group-duration.types';
58

69
export default function WorkflowHistoryEventGroupDuration({
710
startTime,
811
closeTime,
12+
expectedEndTimeInfo,
913
workflowIsArchived,
1014
workflowCloseStatus,
1115
eventsCount,
@@ -42,9 +46,23 @@ export default function WorkflowHistoryEventGroupDuration({
4246
}
4347
}, [startTime, endTime, isOngoing]);
4448

45-
if (!startTime || hideDuration) {
49+
if (!startTime) {
4650
return null;
4751
}
4852

49-
return <>{duration}</>;
53+
return (
54+
<styled.DurationContainer>
55+
{!hideDuration && duration}
56+
{expectedEndTimeInfo ? (
57+
<WorkflowHistoryRemainingDurationBadge
58+
startTime={startTime}
59+
expectedEndTime={expectedEndTimeInfo.timeMs}
60+
prefix={expectedEndTimeInfo.prefix}
61+
workflowIsArchived={workflowIsArchived}
62+
workflowCloseStatus={workflowCloseStatus}
63+
loadingMoreEvents={loadingMoreEvents}
64+
/>
65+
) : null}
66+
</styled.DurationContainer>
67+
);
5068
}

src/views/workflow-history-v2/workflow-history-event-group-duration/workflow-history-event-group-duration.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { type WorkflowExecutionCloseStatus } from '@/__generated__/proto-ts/uber/cadence/api/v1/WorkflowExecutionCloseStatus';
2+
import { type HistoryEventsGroup } from '@/views/workflow-history/workflow-history.types';
23

34
export type Props = {
45
startTime: number | null | undefined;
56
closeTime: number | null | undefined;
7+
expectedEndTimeInfo?: HistoryEventsGroup['expectedEndTimeInfo'];
68
workflowIsArchived: boolean;
79
workflowCloseStatus: WorkflowExecutionCloseStatus | null | undefined;
810
eventsCount: number;

src/views/workflow-history-v2/workflow-history-event-group/workflow-history-event-group.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ export default function WorkflowHistoryEventGroup({
3636
}: Props) {
3737
const {
3838
status,
39+
firstEventId,
3940
label,
4041
shortLabel,
4142
timeMs,
4243
startTimeMs,
4344
closeTimeMs,
44-
// expectedEndTimeInfo,
45+
expectedEndTimeInfo,
4546
events,
4647
eventsMetadata,
4748
hasMissingEvents,
@@ -86,14 +87,14 @@ export default function WorkflowHistoryEventGroup({
8687
...(groupSummaryDetails.length > 0 && groupDetailsEntries.length > 1
8788
? [
8889
getSummaryTabContentEntry({
89-
groupId: eventGroup.firstEventId ?? 'unknown',
90+
groupId: firstEventId ?? 'unknown',
9091
summaryDetails: groupSummaryDetails,
9192
}),
9293
]
9394
: []),
9495
...groupDetailsEntries,
9596
],
96-
[eventGroup.firstEventId, groupDetailsEntries, groupSummaryDetails]
97+
[firstEventId, groupDetailsEntries, groupSummaryDetails]
9798
);
9899

99100
return (
@@ -128,6 +129,7 @@ export default function WorkflowHistoryEventGroup({
128129
loadingMoreEvents={showLoadingMoreEvents}
129130
hasMissingEvents={hasMissingEvents}
130131
workflowCloseTime={workflowCloseTimeMs}
132+
expectedEndTimeInfo={expectedEndTimeInfo}
131133
/>
132134
</div>
133135
<styled.SummarizedDetailsContainer>

0 commit comments

Comments
 (0)