Skip to content

Commit 6cfecb0

Browse files
authored
Change event sorting to event id (#963)
* change event sorting to event id * remove unused file * update fixtures
1 parent e005574 commit 6cfecb0

File tree

8 files changed

+56
-1
lines changed

8 files changed

+56
-1
lines changed

src/views/workflow-history/__fixtures__/workflow-history-event-groups.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const mockActivityEventGroup: ActivityHistoryGroup = {
2626
startTimeMs: 1725747370599,
2727
timeLabel: 'Mock time label',
2828
events: completedActivityTaskEvents,
29+
firstEventId: completedActivityTaskEvents[0].eventId,
2930
};
3031

3132
export const mockDecisionEventGroup: DecisionHistoryGroup = {
@@ -38,6 +39,7 @@ export const mockDecisionEventGroup: DecisionHistoryGroup = {
3839
startTimeMs: 1725747370599,
3940
timeLabel: 'Mock time label',
4041
events: completedDecisionTaskEvents,
42+
firstEventId: completedDecisionTaskEvents[0].eventId,
4143
};
4244

4345
export const mockTimerEventGroup: TimerHistoryGroup = {
@@ -50,6 +52,7 @@ export const mockTimerEventGroup: TimerHistoryGroup = {
5052
startTimeMs: 1725747380000,
5153
timeLabel: 'Mock time label',
5254
events: [startTimerTaskEvent],
55+
firstEventId: startTimerTaskEvent.eventId,
5356
};
5457

5558
export const mockChildWorkflowEventGroup: ChildWorkflowExecutionHistoryGroup = {
@@ -62,6 +65,7 @@ export const mockChildWorkflowEventGroup: ChildWorkflowExecutionHistoryGroup = {
6265
startTimeMs: 1725769671830,
6366
timeLabel: 'Mock time label',
6467
events: completedChildWorkflowEvents,
68+
firstEventId: completedChildWorkflowEvents[0].eventId,
6569
};
6670

6771
export const mockSignalExternalWorkflowEventGroup: SignalExternalWorkflowExecutionHistoryGroup =
@@ -75,6 +79,7 @@ export const mockSignalExternalWorkflowEventGroup: SignalExternalWorkflowExecuti
7579
startTimeMs: 1725769470356,
7680
timeLabel: 'Mock time label',
7781
events: signaledExternalWorkflowEvents,
82+
firstEventId: signaledExternalWorkflowEvents[0].eventId,
7883
};
7984

8085
export const mockRequestCancelExternalWorkflowEventGroup: RequestCancelExternalWorkflowExecutionHistoryGroup =
@@ -88,6 +93,7 @@ export const mockRequestCancelExternalWorkflowEventGroup: RequestCancelExternalW
8893
startTimeMs: 1725749470886,
8994
timeLabel: 'Mock time label',
9095
events: requestedCancelExternalWorkflowEvents,
96+
firstEventId: requestedCancelExternalWorkflowEvents[0].eventId,
9197
};
9298

9399
export const mockSingleEventGroup: SingleEventHistoryGroup = {
@@ -100,4 +106,5 @@ export const mockSingleEventGroup: SingleEventHistoryGroup = {
100106
startTimeMs: 1725747380000,
101107
timeLabel: 'Mock time label',
102108
events: [startWorkflowExecutionEvent],
109+
firstEventId: startWorkflowExecutionEvent.eventId,
103110
};

src/views/workflow-history/helpers/__tests__/get-common-history-group-fields.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ describe('getCommonHistoryGroupFields', () => {
181181
expect(group.eventsMetadata[0].negativeFields).toEqual(['startReason']);
182182
expect(group.eventsMetadata[1].negativeFields).toBeUndefined();
183183
});
184+
185+
it('should return group with firstEventId equal to first event id', () => {
186+
const group = setup({});
187+
expect(group.firstEventId).toEqual(group.events[0].eventId);
188+
});
184189
});
185190

186191
// using timer events for testing
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import getSortableEventId from '../get-sortable-event-id';
2+
3+
describe('getSortableEventId', () => {
4+
it('should return Number.MAX_SAFE_INTEGER for empty input', () => {
5+
expect(getSortableEventId(null)).toBe(Number.MAX_SAFE_INTEGER);
6+
expect(getSortableEventId(undefined)).toBe(Number.MAX_SAFE_INTEGER);
7+
expect(getSortableEventId('')).toBe(Number.MAX_SAFE_INTEGER);
8+
expect(getSortableEventId(' ')).toBe(Number.MAX_SAFE_INTEGER);
9+
});
10+
11+
it('should parse valid positive integer strings', () => {
12+
expect(getSortableEventId('0')).toBe(0);
13+
expect(getSortableEventId('1')).toBe(1);
14+
expect(getSortableEventId('123')).toBe(123);
15+
expect(getSortableEventId('999999')).toBe(999999);
16+
});
17+
18+
it('should parse valid negative integer strings', () => {
19+
expect(getSortableEventId('-1')).toBe(-1);
20+
expect(getSortableEventId('-123')).toBe(-123);
21+
expect(getSortableEventId('-999999')).toBe(-999999);
22+
});
23+
24+
it('should return Number.MAX_SAFE_INTEGER for strings starting with non-digits', () => {
25+
expect(getSortableEventId('abc')).toBe(Number.MAX_SAFE_INTEGER);
26+
expect(getSortableEventId('abc123')).toBe(Number.MAX_SAFE_INTEGER);
27+
expect(getSortableEventId('!@#$%')).toBe(Number.MAX_SAFE_INTEGER);
28+
expect(getSortableEventId('😀123')).toBe(Number.MAX_SAFE_INTEGER);
29+
expect(getSortableEventId('\x00123')).toBe(Number.MAX_SAFE_INTEGER);
30+
});
31+
});

src/views/workflow-history/helpers/get-common-history-group-fields.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default function getCommonHistoryGroupFields<
2727
| 'timeLabel'
2828
| 'closeTimeMs'
2929
| 'startTimeMs'
30+
| 'firstEventId'
3031
> {
3132
const eventsMetadata = events.map((event, index) => {
3233
const attrs = event.attributes as GroupT['events'][number]['attributes'];
@@ -51,6 +52,7 @@ export default function getCommonHistoryGroupFields<
5152
};
5253
});
5354

55+
const groupFirstEventId = events[0].eventId;
5456
const groupStatus = eventsMetadata[eventsMetadata.length - 1].status;
5557
const groupTimeMs = eventsMetadata[eventsMetadata.length - 1].timeMs;
5658
const groupStartTimeMs = eventsMetadata[0].timeMs;
@@ -67,5 +69,6 @@ export default function getCommonHistoryGroupFields<
6769
startTimeMs: groupStartTimeMs,
6870
closeTimeMs: groupCloseTimeMs,
6971
timeLabel: groupTimeLabel,
72+
firstEventId: groupFirstEventId,
7073
};
7174
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function getSortableEventId(eventId: string | null | undefined) {
2+
if (!eventId) return Number.MAX_SAFE_INTEGER;
3+
const numericEventId = parseInt(eventId, 10);
4+
if (isNaN(numericEventId)) return Number.MAX_SAFE_INTEGER;
5+
return numericEventId;
6+
}

src/views/workflow-history/workflow-history-filters-status/helpers/__tests__/filter-groups-by-group-status.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const ACTIVITY_HISTORY_GROUP_COMPLETED: ActivityHistoryGroup = {
1212
timeLabel: 'Mock time label',
1313
groupType: 'Activity',
1414
events: [],
15+
firstEventId: null,
1516
};
1617

1718
describe(filterGroupsByGroupStatus.name, () => {

src/views/workflow-history/workflow-history.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { useSuspenseDescribeWorkflow } from '../workflow-page/hooks/use-describe
3737
import workflowHistoryFiltersConfig from './config/workflow-history-filters.config';
3838
import WORKFLOW_HISTORY_PAGE_SIZE_CONFIG from './config/workflow-history-page-size.config';
3939
import compareUngroupedEvents from './helpers/compare-ungrouped-events';
40+
import getSortableEventId from './helpers/get-sortable-event-id';
4041
import getVisibleGroupsHasMissingEvents from './helpers/get-visible-groups-has-missing-events';
4142
import { groupHistoryEvents } from './helpers/group-history-events';
4243
import pendingActivitiesInfoToEvents from './helpers/pending-activities-info-to-events';
@@ -150,7 +151,7 @@ export default function WorkflowHistory({ params }: Props) {
150151
() =>
151152
sortBy(
152153
Object.entries(eventGroups),
153-
([_, { timeMs }]) => timeMs,
154+
([_, { firstEventId }]) => getSortableEventId(firstEventId),
154155
'ASC'
155156
).filter(([_, g]) =>
156157
workflowHistoryFiltersConfig.every((f) =>

src/views/workflow-history/workflow-history.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type BaseHistoryGroup = {
6060
startTimeMs: number | null;
6161
closeTimeMs?: number | null;
6262
timeLabel: string;
63+
firstEventId: string | null;
6364
badges?: HistoryGroupBadge[];
6465
resetToDecisionEventId?: string | null;
6566
};

0 commit comments

Comments
 (0)