Skip to content

Commit e005574

Browse files
authored
Change pending event label based on state (#965)
1 parent ae04b27 commit e005574

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

src/views/workflow-history/helpers/get-history-group-from-events/__tests__/get-activity-group-from-events.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@/views/workflow-history/__fixtures__/workflow-history-activity-events';
99
import {
1010
pendingActivityTaskStartEvent,
11+
pendingActivityTaskStartEventWithCancelRequestedState,
1112
pendingActivityTaskStartEventWithStartedState,
1213
} from '@/views/workflow-history/__fixtures__/workflow-history-pending-events';
1314
import * as shortenGroupLabelsConfigModule from '@/views/workflow-history/config/workflow-history-should-shorten-group-labels.config';
@@ -120,6 +121,34 @@ describe('getActivityGroupFromEvents', () => {
120121
expect(group.groupType).toBe('Activity');
121122
});
122123

124+
it('should return a group with correct label for pending activity event', () => {
125+
const events: ExtendedActivityHistoryEvent[] = [
126+
scheduleActivityTaskEvent,
127+
pendingActivityTaskStartEvent,
128+
];
129+
const group = getActivityGroupFromEvents(events);
130+
expect(group.eventsMetadata[1].label).toBe('Starting');
131+
132+
const eventsWithStartedState = getActivityGroupFromEvents([
133+
scheduleActivityTaskEvent,
134+
pendingActivityTaskStartEventWithStartedState,
135+
]);
136+
expect(eventsWithStartedState.eventsMetadata[1].label).toBe('Running');
137+
138+
const eventsWithCanceledState = getActivityGroupFromEvents([
139+
scheduleActivityTaskEvent,
140+
pendingActivityTaskStartEventWithCancelRequestedState,
141+
]);
142+
expect(eventsWithCanceledState.eventsMetadata[1].label).toBe('Cancelling');
143+
144+
const eventsWithInvalidState = getActivityGroupFromEvents([
145+
scheduleActivityTaskEvent,
146+
// @ts-expect-error - state is not defined in the type
147+
{ ...pendingActivityTaskStartEvent, state: undefined },
148+
]);
149+
expect(eventsWithInvalidState.eventsMetadata[1].label).toBe('Starting');
150+
});
151+
123152
it('should return group eventsMetadata with correct labels', () => {
124153
const events: ExtendedActivityHistoryEvent[] = [
125154
scheduleActivityTaskEvent,

src/views/workflow-history/helpers/get-history-group-from-events/__tests__/get-decision-group-from-events.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,28 @@ describe('getDecisionGroupFromEvents', () => {
8585
expect(group.groupType).toBe('Decision');
8686
});
8787

88+
it('should return a group with correct label for pending decision event', () => {
89+
const events: ExtendedDecisionHistoryEvent[] = [
90+
scheduleDecisionTaskEvent,
91+
pendingDecisionTaskStartEvent,
92+
];
93+
const group = getDecisionGroupFromEvents(events);
94+
expect(group.eventsMetadata[1].label).toBe('Starting');
95+
96+
const eventsWithStartedState = getDecisionGroupFromEvents([
97+
scheduleDecisionTaskEvent,
98+
pendingDecisionTaskStartEventWithStartedState,
99+
]);
100+
expect(eventsWithStartedState.eventsMetadata[1].label).toBe('Running');
101+
102+
const eventsWithInvalidState = getDecisionGroupFromEvents([
103+
scheduleDecisionTaskEvent,
104+
// @ts-expect-error - state is not defined in the type
105+
{ ...pendingDecisionTaskStartEvent, state: undefined },
106+
]);
107+
expect(eventsWithInvalidState.eventsMetadata[1].label).toBe('Starting');
108+
});
109+
88110
it('should return group eventsMetadata with correct labels', () => {
89111
const events: ExtendedDecisionHistoryEvent[] = [
90112
scheduleDecisionTaskEvent,

src/views/workflow-history/helpers/get-history-group-from-events/get-activity-group-from-events.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,23 @@ export default function getActivityGroupFromEvents(
8282
});
8383
}
8484

85+
const pendingStateToLabel: Record<
86+
PendingActivityTaskStartEvent['pendingActivityTaskStartEventAttributes']['state'],
87+
string
88+
> = {
89+
PENDING_ACTIVITY_STATE_SCHEDULED: 'Starting',
90+
PENDING_ACTIVITY_STATE_STARTED: 'Running',
91+
PENDING_ACTIVITY_STATE_CANCEL_REQUESTED: 'Cancelling',
92+
};
93+
94+
const pendingState = pendingStartEvent?.[pendingStartAttr].state;
95+
8596
const eventToLabel: HistoryGroupEventToStringMap<ActivityHistoryGroup> = {
8697
activityTaskScheduledEventAttributes: 'Scheduled',
87-
pendingActivityTaskStartEventAttributes: 'Starting',
98+
pendingActivityTaskStartEventAttributes:
99+
pendingState && pendingStateToLabel[pendingState]
100+
? pendingStateToLabel[pendingState]
101+
: pendingStateToLabel.PENDING_ACTIVITY_STATE_SCHEDULED,
88102
activityTaskStartedEventAttributes: 'Started',
89103
activityTaskCompletedEventAttributes: 'Completed',
90104
activityTaskFailedEventAttributes: 'Failed',

src/views/workflow-history/helpers/get-history-group-from-events/get-decision-group-from-events.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { type PendingDecisionInfo } from '@/__generated__/proto-ts/uber/cadence/api/v1/PendingDecisionInfo';
2+
13
import type {
24
DecisionHistoryGroup,
35
ExtendedDecisionHistoryEvent,
@@ -77,10 +79,22 @@ export default function getDecisionGroupFromEvents(
7779
resetToDecisionEventId = timeoutEvent.eventId;
7880
}
7981

82+
const pendingStateToLabel: Record<
83+
PendingDecisionTaskStartEvent['pendingDecisionTaskStartEventAttributes']['state'],
84+
string
85+
> = {
86+
PENDING_DECISION_STATE_SCHEDULED: 'Starting',
87+
PENDING_DECISION_STATE_STARTED: 'Running',
88+
};
89+
const pendingState = pendingStartEvent?.[pendingStartAttr].state;
90+
8091
// populate event to label and status maps
8192
const eventToLabel: HistoryGroupEventToStringMap<DecisionHistoryGroup> = {
8293
decisionTaskScheduledEventAttributes: 'Scheduled',
83-
pendingDecisionTaskStartEventAttributes: 'Starting',
94+
pendingDecisionTaskStartEventAttributes:
95+
pendingState && pendingStateToLabel[pendingState]
96+
? pendingStateToLabel[pendingState]
97+
: pendingStateToLabel.PENDING_DECISION_STATE_SCHEDULED,
8498
decisionTaskStartedEventAttributes: 'Started',
8599
decisionTaskCompletedEventAttributes: 'Completed',
86100
decisionTaskFailedEventAttributes: 'Failed',

0 commit comments

Comments
 (0)