Skip to content

Conversation

Assem-Uber
Copy link
Contributor

@Assem-Uber Assem-Uber commented Jul 23, 2025

Summary:
Event groups sorting now is based on last event time. This is causing some inconveniance because of the following:

  • Hard to traverse the history with that sorting
  • Event groups location is changing based on the newly loaded events.
  • Pending events sometimes shows after the completion event
  • Scrolling to event is programatically can be hard because of change groups changing index.

Changes:

  • Extracted firstEventId for groups to be more representable than group id.
  • Change sorting logic to depend on numerical value of firstEventId

Screenshots:
Screenshot 2025-07-23 at 15 48 27

Screenshot 2025-07-23 at 15 53 46

@adhityamamallan adhityamamallan requested a review from Copilot July 23, 2025 15:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR changes the workflow history event sorting mechanism from time-based to event ID-based sorting to improve user experience and fix issues with dynamic group positioning.

  • Adds firstEventId field to history group types and implementations
  • Replaces time-based sorting with numeric event ID sorting using a new helper function
  • Updates all test fixtures and mocks to include the new firstEventId field

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
workflow-history.types.ts Adds firstEventId field to BaseHistoryGroup type definition
workflow-history.tsx Updates sorting logic to use getSortableEventId instead of timeMs
get-sortable-event-id.ts New helper function to convert event IDs to sortable numeric values
get-common-history-group-fields.ts Extracts and assigns firstEventId from the first event in each group
Various test files Updates test fixtures and mocks to include the new firstEventId field

Comment on lines +2 to +3
if (!eventId) return Number.MAX_SAFE_INTEGER;
const numericEventId = parseInt(eventId, 10);
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function treats empty strings as falsy but parseInt(' ', 10) would return NaN, which is handled later. However, parseInt('', 10) also returns NaN. The current logic will return MAX_SAFE_INTEGER for empty strings in the first check, but the test expects it to handle whitespace-only strings. Consider using eventId?.trim() to handle whitespace consistently.

Suggested change
if (!eventId) return Number.MAX_SAFE_INTEGER;
const numericEventId = parseInt(eventId, 10);
const trimmedEventId = eventId?.trim();
if (!trimmedEventId) return Number.MAX_SAFE_INTEGER;
const numericEventId = parseInt(trimmedEventId, 10);

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done to avoid typescript issue about non string values passed to parseInt

expect(getSortableEventId(null)).toBe(Number.MAX_SAFE_INTEGER);
expect(getSortableEventId(undefined)).toBe(Number.MAX_SAFE_INTEGER);
expect(getSortableEventId('')).toBe(Number.MAX_SAFE_INTEGER);
expect(getSortableEventId(' ')).toBe(Number.MAX_SAFE_INTEGER);
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test expects whitespace-only strings to return MAX_SAFE_INTEGER, but the current implementation only checks for falsy values. A string with spaces is truthy, so it will proceed to parseInt(' ', 10) which returns NaN, then return MAX_SAFE_INTEGER. While the test passes, the logic path is inconsistent with the other empty value checks.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The confusion is from the way the typescript issue was handled which made a split in the handling but the results are consistent at the end

@adhityamamallan
Copy link
Member

adhityamamallan commented Jul 24, 2025

Extracted firstEventId for groups to be more representable than group id.

Will we change the existing usages of group ID to use firstEventId instead?

expect(getSortableEventId('-999999')).toBe(-999999);
});

it('should return Number.MAX_SAFE_INTEGER for strings starting with non-digits', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work for pending events? Will pending event IDs even be passed to this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending events are always the second event so the sorting would happen on the scheduled event

Copy link
Contributor Author

@Assem-Uber Assem-Uber Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case we want to have them sorted we can have use computedEventId for sorting too but also change the id to be scheduledId-Pending instead of Pending-scheduledId so that it will be ordered by id and ignore the string postfix -Pending

@Assem-Uber Assem-Uber merged commit 6cfecb0 into cadence-workflow:master Jul 24, 2025
1 check passed
@Assem-Uber Assem-Uber deleted the feature/13642/change-events-ordering-to-event-id branch July 24, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants