-
Notifications
You must be signed in to change notification settings - Fork 125
feat: Fetcher updates #1090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Fetcher updates #1090
Conversation
There was a problem hiding this 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 enhances the workflow history fetcher with several improvements: smaller first page sizes for better initial load performance, a new callback mechanism for immediate event change reactions, and reorganized initialization logic.
- Separated page size configuration into first page (200) and subsequent pages (1000) for optimized loading
- Added
onEventsChangecallback touseWorkflowHistoryFetcherfor non-throttled event change handling - Moved fetcher initialization (
start()) to occur directly after instance creation
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| workflow-history.tsx | Updated import and added placeholder callback for onEventsChange parameter |
| use-workflow-history-fetcher.ts | Added onEventsChange parameter, moved start() call to initialization, and integrated callback in change handler |
| use-workflow-history-fetcher.test.tsx | Updated test setup to include mock onEventsChange callback |
| workflow-history-fetcher.ts | Implemented dynamic page sizing logic and refactored listener management |
| workflow-history-fetcher.test.tsx | Added tests for page size validation and enhanced mock endpoint to capture page sizes |
| workflow-history-page-size.config.ts | Split single page size constant into separate first and subsequent page size exports |
| workflow-history.test.tsx | Updated mock to pass through onEventsChange parameter |
| workflow-history-v2.tsx | Updated import to use named export |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/views/workflow-history/hooks/use-workflow-history-fetcher.ts
Outdated
Show resolved
Hide resolved
src/views/workflow-history/hooks/use-workflow-history-fetcher.ts
Outdated
Show resolved
Hide resolved
src/views/workflow-history/helpers/__tests__/workflow-history-fetcher.test.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| if (shouldContinue) { | ||
| this.shouldContinue = shouldContinue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if start is called twice?
start( shouldContinue )start( null )
It appears that the 2nd start would retain the prior shouldContinue. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% correct. You've just reminded me that i thought about it and forgot to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But to put more context, it is not an issue.
Null is not allowed as an argument and undefined would use the default method. It just doesn't make sense to keep the condition.
| // if the pages count is greater than the last flattened pages count, then we need to flatten the pages and call the onEventsChange callback | ||
| if (pagesCount > lastFlattenedPagesCount) { | ||
| lastFlattenedPagesCount = pagesCount; | ||
| onEventsChange( | ||
| state.data?.pages?.flatMap((page) => page.history?.events || []) || [] | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow.
It sounds like historyQuery is throttled.
On the other hand, the unthrottled flow is...
- When
onChange, then getstate. - Take this
stateand flatten it (for what purpose?) - Then take the flattened result and pass it to
onEventsChange(why?)
I'm probably missing something obvious with grouping in the history page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, history queue is throttled. Since it seems hard to understand this pattern i moved lastFlattenedPagesCount to be a ref outside the component.
The reason why we flatten is that Pages is a react-query construct. But helpers and other components accepts arrays of events. It made sense to send events here since the method name is onEventsChange. If we didn't do in this hook we would need to do it in the parent.
| const pageSizes = getCapturedPageSizes(); | ||
| expect(pageSizes).toHaveLength(1); | ||
| expect(pageSizes[0]).toBe('200'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to assert behavior of setup and mockEndpoints rather than the "unit under test".
Is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which part exactly is testing the setup method?
What the test does here is capturing what request msw received and make sure that the first request had a query param of 200. The query for rest APIs are sent from the fetcher but received and captured by the setup method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like your intent is to introspect the inner workings of the fetcher?
To suggest an alternative approach:
- Let's generalize it beyond
pageSize. - Unit tests need to assert correct internal behavior.
- And asserting the outcome falls short.
- One solution: The fetcher returns an introspection object.
- Example: Return
debugInfowhich provides detailed insights.
I suggest this because the purpose of CapturedPageSizes wasn't immediately clear.
| const unsubscribe = fetcherRef.current.onChange((state) => { | ||
| const pagesCount = state.data?.pages?.length || 0; | ||
| // If the pages count is greater than the last flattened pages count, then we need to flatten the pages and call the onEventsChange callback | ||
| // Depending on ref variable instead of historyQueue is because historyQueue is throttled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a typo, means historyQuery instead?
| if (pagesCount > lastFlattenedPagesCountRef.current) { | ||
| lastFlattenedPagesCountRef.current = pagesCount; | ||
| onEventsChange( | ||
| state.data?.pages?.flatMap((page) => page.history?.events || []) || [] | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must be missing something.
My understanding:
- When
onChangefires - Then emit
onEventsChangewith fresh data
I would have expected:
- Within
onChange - Call
onEventsChangewithstate.data.pages
I'm a bit confused why we don't pass state.data.pages directly (bypassing the flattening step)?
The hook, as currently implemented, knows too much about the fetcher internals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is a follow up question on this or the message didn't show up for you as it was outdated. We can continue the discussion there.
Summary
This is a follow-up on fetcher PRs (#1062, #1063 , #1064 ) to add few missing features:
onEventsChangeprop touseWorkflowHistoryFetcherthat allow reacting to events change faster that the throttled state. This will be used for non delayed grouping of events.Also fixing one issue with fetcher:
Testing
Tested as part of #1091