Skip to content

Commit d7ad6ae

Browse files
Assem-UberCopilot
andcommitted
feat: Create a grouping utility that only parses new events (cadence-workflow#1065)
* grouping utility Signed-off-by: Assem Hafez <assem.hafez@uber.com> * update test cases Signed-off-by: Assem Hafez <assem.hafez@uber.com> * change the api of onChange and add destroy method Signed-off-by: Assem Hafez <assem.hafez@uber.com> * replace getGroups with getState Signed-off-by: Assem Hafez <assem.hafez@uber.com> * call onchange after updating pending events Signed-off-by: Assem Hafez <assem.hafez@uber.com> * use sync processBatch for first page Signed-off-by: Assem Hafez <assem.hafez@uber.com> * Update src/views/workflow-history/helpers/workflow-history-grouper.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply PR comments * Update src/views/workflow-history/helpers/workflow-history-grouper.types.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Signed-off-by: Assem Hafez <assem.hafez@uber.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 6ef3012 commit d7ad6ae

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

src/views/workflow-history/helpers/__tests__/workflow-history-grouper.test.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import type {
1616
Props,
1717
} from '../workflow-history-grouper.types';
1818

19-
// Commonly used mocks
20-
2119
// Track all setups for cleanup
2220
const allCleanups: Array<() => void> = [];
2321

@@ -633,11 +631,6 @@ describe(WorkflowHistoryGrouper.name, () => {
633631
// First batch is processed immediately, so processedEventsCount should be at least 1
634632
expect(state.processedEventsCount).toBeGreaterThan(0);
635633

636-
// If there are remaining events, status could be 'processing'
637-
if (state.remainingEventsCount > 0) {
638-
expect(state.status).toBe('processing');
639-
}
640-
641634
// Wait for processing to complete
642635
await waitForProcessing();
643636

src/views/workflow-history/helpers/workflow-history-grouper.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default class WorkflowHistoryGrouper {
9393
* Updates pending events (activities and decisions).
9494
* This should be called separately from updateEvents.
9595
*/
96-
public async updatePendingEvents(params: ProcessEventsParams) {
96+
public updatePendingEvents(params: ProcessEventsParams) {
9797
// Update pending events (add new ones, remove stale ones)
9898

9999
const currentPendingActivities = this.currentPendingActivities;
@@ -184,10 +184,10 @@ export default class WorkflowHistoryGrouper {
184184

185185
/**
186186
* Schedules the next batch using the best available API.
187-
* Uses Scheduler API if available, otherwise falls back to Promise microtask.
187+
* Uses Scheduler API if available, otherwise falls back to setTimeout.
188188
*/
189189
private scheduleNextBatch() {
190-
// if first batch process immediately, this helps avoiding UI delays
190+
// If first batch, process immediately; this helps avoid UI delays
191191
if (this.lastProcessedEventIndex === -1) {
192192
this.processBatch();
193193
} else if (
@@ -200,6 +200,7 @@ export default class WorkflowHistoryGrouper {
200200
.postTask(() => this.processBatch(), { priority: 'background' })
201201
.catch(() => {
202202
// Fallback to setTimeout if postTask fails
203+
// setTimeout adds the processBatch to Macro Task Queue (lowest priority queue) to allow current microtasks (UI updates) to complete first
203204
setTimeout(() => this.processBatch(), 0);
204205
});
205206
} else {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ export type ProcessEventsParams = {
1111
pendingStartDecision: PendingDecisionTaskStartEvent | null;
1212
};
1313

14-
export type ProcessEventsResult = {
15-
groups: HistoryEventsGroups;
16-
lastProcessedEventIndex: number;
17-
};
18-
1914
/**
2015
* Processing status for incremental grouping operations.
2116
*/

0 commit comments

Comments
 (0)