Skip to content

Conversation

@Assem-Uber
Copy link
Contributor

Summary
Creating a hook to be responsible of creating an instance of WorkflowHistoryFetcher and managing its state updates. This going to be used in the Workflow History Page.

Changes

  • Create a hook to manage the WorkflowHistoryFetcher
  • Fetch the first page on mount
  • Throttle rest of pages for 2 seconds to allow fetching more pages for each render
  • Return the query state and start/stop/fetchNextPage handlers

Assem-Uber and others added 6 commits November 3, 2025 09:56
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Copy link
Member

@macrotim macrotim left a comment

Choose a reason for hiding this comment

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

Looks good overall.

const unsubscribe = fetcherRef.current.onChange((state) => {
const pagesCount = state.data?.pages?.length || 0;
// immediately set if there is the first page without throttling other wise throttle
setHistoryQuery(() => state, pagesCount <= 1);
Copy link
Member

Choose a reason for hiding this comment

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

It took me a while to realize that pagesCount <= 1 is executeImmediately.

Copy link
Contributor Author

@Assem-Uber Assem-Uber Nov 5, 2025

Choose a reason for hiding this comment

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

Added it in a variable

Comment on lines +50 to +51
// Fetch first page
fetcherRef.current.start((state) => !state?.data?.pages?.length);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why we fetch the first page explicitly rather than relying on the flywheel / fetch-loop?

Copy link
Contributor Author

@Assem-Uber Assem-Uber Nov 5, 2025

Choose a reason for hiding this comment

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

Both works, in this case i went for being more explicit about loading the first page separately from the conditions for keep loading more. In any case we won't want to load and empty page, so it is some how safer to assume first page always loads. The other approach works too, i don't see issues with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Btw fetchSingleNextPage can also be used here, but i went with that assuming this is more readable. Let me know if it is not the same for you.

@@ -0,0 +1,88 @@
import { useCallback, useEffect, useRef } from 'react';
Copy link
Member

Choose a reason for hiding this comment

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

Is this file included in this PR because it's stacked on the prior PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, unfortunately both exists in this PR as they are dependant.

Copy link
Member

@macrotim macrotim left a comment

Choose a reason for hiding this comment

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

I believe there is room for a few improvements (mainly, to help new readers like me follow along).

Approving to unblock and low risk.

Assem-Uber and others added 10 commits November 5, 2025 13:57
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Signed-off-by: Assem Hafez <assem.hafez@uber.com>
@Assem-Uber Assem-Uber merged commit 4b858bb into cadence-workflow:master Nov 10, 2025
5 checks passed
@Assem-Uber Assem-Uber deleted the feature/15952/create-hook-for-history-fetcher branch November 10, 2025 10:31
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