Skip to content

Commit 86f5c00

Browse files
committed
Add missing fields to results (#820)
* add missing fields to results * add unit tests * fix typecheck and add identity * lint fix * fix test case
1 parent 16bf79b commit 86f5c00

File tree

4 files changed

+102
-13
lines changed

4 files changed

+102
-13
lines changed

src/components/pretty-json/pretty-json.types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type PrettyJsonValue =
77
| number
88
| boolean
99
| null
10+
| undefined
1011
| JsonObject
1112
| JsonArray
1213
| bigint;

src/views/workflow-summary-tab/helpers/__tests__/get-workflow-result-json.test.ts

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
type FormattedWorkflowExecutionFailedEvent,
55
type FormattedWorkflowExecutionTerminatedEvent,
66
type FormattedWorkflowExecutionTimedOutEvent,
7+
type FormattedWorkflowExecutionContinuedAsNewEvent,
8+
type FormattedTimerFiredEvent,
79
} from '@/utils/data-formatters/schema/format-history-event-schema';
810

911
import getWorkflowResultJson from '../get-workflow-result-json';
@@ -20,7 +22,7 @@ describe('getWorkflowResultJson', () => {
2022
expect(getWorkflowResultJson(formattedEvent)).toBe('canceled details');
2123
});
2224

23-
it('should return details for WorkflowExecutionFailed event', () => {
25+
it('should return details and reason for WorkflowExecutionFailed event', () => {
2426
const formattedEvent: FormattedWorkflowExecutionFailedEvent = {
2527
eventType: 'WorkflowExecutionFailed',
2628
reason: 'cadenceInternal:Generic',
@@ -29,7 +31,10 @@ describe('getWorkflowResultJson', () => {
2931
timestamp: null,
3032
decisionTaskCompletedEventId: '1',
3133
};
32-
expect(getWorkflowResultJson(formattedEvent)).toBe('failed details');
34+
expect(getWorkflowResultJson(formattedEvent)).toEqual({
35+
reason: 'cadenceInternal:Generic',
36+
details: 'failed details',
37+
});
3338
});
3439

3540
it('should return details for WorkflowExecutionTerminated event', () => {
@@ -41,7 +46,11 @@ describe('getWorkflowResultJson', () => {
4146
timestamp: null,
4247
identity: '1111',
4348
};
44-
expect(getWorkflowResultJson(formattedEvent)).toBe('terminated details');
49+
expect(getWorkflowResultJson(formattedEvent)).toEqual({
50+
reason: 'cadenceInternal:Generic',
51+
details: 'terminated details',
52+
identity: '1111',
53+
});
4554
});
4655

4756
it('should return result for WorkflowExecutionCompleted event', () => {
@@ -55,13 +64,55 @@ describe('getWorkflowResultJson', () => {
5564
expect(getWorkflowResultJson(formattedEvent)).toBe('completed result');
5665
});
5766

58-
it('should return undefined for other eventType', () => {
67+
it('should return timeoutType for WorkflowExecutionTimedOut event', () => {
5968
const formattedEvent: FormattedWorkflowExecutionTimedOutEvent = {
6069
eventType: 'WorkflowExecutionTimedOut',
6170
eventId: 1,
6271
timeoutType: 'TIMEOUT_TYPE_HEARTBEAT',
6372
timestamp: null,
6473
};
74+
expect(getWorkflowResultJson(formattedEvent)).toEqual({
75+
timeoutType: 'TIMEOUT_TYPE_HEARTBEAT',
76+
});
77+
});
78+
79+
it('should return correct fields for WorkflowExecutionContinuedAsNew event', () => {
80+
const formattedEvent: FormattedWorkflowExecutionContinuedAsNewEvent = {
81+
backoffStartIntervalInSeconds: 0,
82+
decisionTaskCompletedEventId: '',
83+
eventId: 1,
84+
eventType: 'WorkflowExecutionContinuedAsNew',
85+
executionStartToCloseTimeoutSeconds: 0,
86+
workflowType: null,
87+
timestamp: null,
88+
header: { fields: {} },
89+
input: [],
90+
memo: { fields: {} },
91+
searchAttributes: { indexedFields: '' },
92+
taskList: { kind: 'NORMAL', name: '' },
93+
taskStartToCloseTimeoutSeconds: 0,
94+
newExecutionRunId: '',
95+
initiator: 'CRON_SCHEDULE',
96+
failureDetails: 'Failure Details',
97+
failureReason: 'Failure Reason',
98+
lastCompletionResult: null,
99+
};
100+
expect(getWorkflowResultJson(formattedEvent)).toEqual({
101+
initiator: 'CRON_SCHEDULE',
102+
failureDetails: 'Failure Details',
103+
failureReason: 'Failure Reason',
104+
lastCompletionResult: null,
105+
});
106+
});
107+
108+
it('should return undefined for other eventType', () => {
109+
const formattedEvent: FormattedTimerFiredEvent = {
110+
eventType: 'TimerFired',
111+
eventId: 3,
112+
timestamp: null,
113+
startedEventId: 2,
114+
timerId: '1',
115+
};
65116
expect(getWorkflowResultJson(formattedEvent)).toBeUndefined();
66117
});
67118

src/views/workflow-summary-tab/helpers/get-workflow-result-json.ts

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,52 @@
1-
import { type FormattedHistoryEvent } from '@/utils/data-formatters/schema/format-history-event-schema';
1+
import {
2+
type FormattedHistoryEventForType,
3+
type FormattedHistoryEvent,
4+
} from '@/utils/data-formatters/schema/format-history-event-schema';
25

36
export default function getWorkflowResultJson(
47
formattedEvent: FormattedHistoryEvent
58
) {
69
const eventType = formattedEvent.eventType;
7-
if (
8-
eventType === 'WorkflowExecutionCanceled' ||
9-
eventType === 'WorkflowExecutionFailed' ||
10-
eventType === 'WorkflowExecutionTerminated'
11-
)
10+
if (eventType === 'WorkflowExecutionFailed') {
11+
const { reason, details } = formattedEvent;
12+
return { reason, details };
13+
}
14+
if (eventType === 'WorkflowExecutionTerminated') {
15+
const { details, reason, identity } = formattedEvent;
16+
return { reason, details, identity };
17+
}
18+
19+
if (eventType === 'WorkflowExecutionContinuedAsNew') {
20+
const { initiator, failureDetails, failureReason, lastCompletionResult } =
21+
formattedEvent;
22+
const result: Partial<
23+
Pick<
24+
FormattedHistoryEventForType<'WorkflowExecutionContinuedAsNew'>,
25+
| 'initiator'
26+
| 'lastCompletionResult'
27+
| 'failureDetails'
28+
| 'failureReason'
29+
>
30+
> = {
31+
initiator,
32+
lastCompletionResult,
33+
};
34+
// only add failure fields if it was failed not to confuse user
35+
if (failureDetails || failureReason) {
36+
result.failureDetails = failureDetails;
37+
result.failureReason = failureReason;
38+
}
39+
return result;
40+
}
41+
42+
if (eventType === 'WorkflowExecutionTimedOut') {
43+
const { timeoutType } = formattedEvent;
44+
return { timeoutType };
45+
}
46+
47+
if (eventType === 'WorkflowExecutionCanceled') {
1248
return formattedEvent.details;
49+
}
1350

1451
if (eventType === 'WorkflowExecutionCompleted') return formattedEvent.result;
1552

src/views/workflow-summary-tab/workflow-summary-tab.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ export default function WorkflowSummaryTab({
6060
? formatWorkflowHistoryEvent(closeEvent)
6161
: null;
6262

63-
const resultJson = formattedCloseEvent
64-
? getWorkflowResultJson(formattedCloseEvent)
65-
: undefined;
63+
const resultJson = (
64+
formattedCloseEvent ? getWorkflowResultJson(formattedCloseEvent) : undefined
65+
) as PrettyJsonValue;
6666

6767
const isWorkflowRunning =
6868
!closeEvent ||

0 commit comments

Comments
 (0)