Skip to content

chore(ui): load entity feed and task counts through one useEntityFeedCounts hook - #39791

Open
harsh-vador wants to merge 3 commits into
mainfrom
chore/feed-counts-hook
Open

harsh-vador wants to merge 3 commits into
mainfrom
chore/feed-counts-hook

Conversation

@harsh-vador

@harsh-vador harsh-vador commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes https://github.com/open-metadata/openmetadata-collate/issues/9240

Before this PR, 26 entity pages each fetched their feed and task counts with the same copied block:

  • a feedCount state;
  • a getFeedCounts reload;
  • two fetchers that wrote into that state (fetchEntityTaskCountsInto, fetchEntityActivityCountInto);
  • an effect to start them.

This PR replaces that block with one hook, useEntityFeedCounts(entityType, fqn, { enabled, includeActivity }), built on React Query. In production code, about 900 more lines are removed than added. Part of the activity feed cleanup (open-metadata/openmetadata-collate#9236).

Collate companion: open-metadata/openmetadata-collate#9312 (draft) moves Collate's last getFeedCounts caller to this hook. It merges after this PR.

Stacked on #39779 (→ #39733 → #39670). This PR targets chore/feed-small-dups, so the diff shows only these two commits. It is retargeted to main once the PRs below it merge.

Commit What
Add the hook Two queries per entity: the task counts, and the activity plus conversation counts. One failing request leaves the other count in place, as the page code did before. The hook returns feedCount, getEntityFeedCount and handleFeedCount, the names the pages already pass to their tabs and class bases, so no child component changes. getFeedCounts stays exported because Collate calls it, and it now uses the same fetchers. Its domain overload had no caller and is removed.
Move the pages Each page calls the hook with its entity type and fqn. Where the page already checked a permission before fetching, that check becomes enabled. The test case page only shows the open-task count, so it passes includeActivity: false. fetchEntityTaskCountsInto and fetchEntityActivityCountInto had no other caller and are removed.

What a user or reviewer can notice:

  • Same counts on every page, checked against a local backend (below).
  • Fewer duplicate requests. Several pages refetched every count when their permissions object loaded, so they sent each count request twice on open. The dashboard page, for example, sent 6 count requests and now sends 3. Counts still reload when the fqn changes, and through getEntityFeedCount (after a post, a task change, a tag update).
  • Revisiting an entity shows its cached counts immediately, then refreshes them in the background (staleTime 0, as everywhere else in the app).
  • The glossary page's onTasksChange used to reload only the task counts. It now reloads both, which is one more request after a task change.
  • The classic feed tab is unchanged. It only fetches counts itself when a page passes none: the user profile, whose counts have a different shape (owned or followed conversations, mentions).

Type of change:

  • Improvement

High-level design:

One hook, two React Query keys: ['entityFeedCounts', 'tasks', fqn] and ['entityFeedCounts', 'activity', entityType, fqn]. handleFeedCount writes a full FeedCounts into both keys, and getEntityFeedCount refetches the enabled ones. An error shows the same server.entity-feed-fetch-error toast as before.

Tests:

Use cases covered

  • The hook counts tasks, activity and conversations about the entity, and sends the same three requests as before.
  • With enabled: false, or without an fqn, it sends nothing, including through getEntityFeedCount.
  • With includeActivity: false, it loads and reloads only the task counts.
  • When the activity request fails, the task counts stay and the error toast shows.
  • getEntityFeedCount reloads every count, and handleFeedCount replaces them.
  • The tag page reloads the counts after a tag update. I checked this test fails without the reload.

Unit tests

  • hooks/useEntityFeedCounts.test.tsx: 7 tests.
  • utils/FeedUtilsPure.getFeedCounts.test.ts now covers fetchEntityActivityCounts.
  • The page tests mock the hook instead of the removed helpers. Tests that checked the old calls now check the hook's arguments, including enabled and includeActivity.
  • 214 suites (2,145 tests) pass across the changed folders, components/ActivityFeed, the hook and the utils.
  • tsc: no new errors. The 38 that remain are on main, in four unrelated test files.
  • ESLint: 0 errors. Warnings on the changed files went from 182 to 160. Prettier and organize-imports leave no diff.
  • The 183 browser-helper tests pass locally.

Before / after

Captured against a local backend with the same data, before (the base branch files) and after (this branch):

  • 9240-feed-counts.png:
    • the tab counts on a table and on a dashboard, and the dashboard's Activity tab;
    • the count requests each page sends while loading.
  • The counts are identical; the only pixel difference is anti-aliasing on a card edge.

UI screen recording:

Not applicable: a refactor with no visual change, with the before/after capture above.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>. The issue is in openmetadata-collate, so the title names the area instead.
  • My PR is linked to a GitHub issue via Fixes above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. Not applicable.
  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable). Not applicable, explained above.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md and fixed every 🔴 finding, or answered it on the line below.
    • openmetadata-collate imports only getFeedCounts, whose callback form is unchanged.
    • The class-base tab props keep the names getEntityFeedCount and handleFeedCount. Outside these files, Collate uses them only in its own PipelineDetails, which calls getFeedCounts.
  • Decision check: if this PR decides something the next contributor could undo, it adds a record under docs/decisions/. ADR:2026-12-04-getfeedcounts-is-kept-for-collate records that getFeedCounts stays exported, in its callback form, until open-metadata/openmetadata-collate#9311 moves Collate's last caller to the hook. The JSDoc on the export cites it.

🤖 Generated with Claude Code

@harsh-vador
harsh-vador requested a review from a team as a code owner December 4, 2026 09:53
@harsh-vador
harsh-vador requested review from chirag-madlani and removed request for a team December 4, 2026 09:53
@harsh-vador harsh-vador added the UI UI specific issues label Dec 4, 2026
@harsh-vador harsh-vador self-assigned this Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@harsh-vador
harsh-vador added this pull request to stack #39734 December 4, 2026 09:57
@harsh-vador

Copy link
Copy Markdown
Contributor Author

Playwright full suite on the activity feed cleanup stack

PR CI skips Playwright here, so I ran the whole suite on the stack instead (playwright-postgresql-e2e.yml, full_suite=true). The runs were on each branch before today's rebase onto main; the rebase changed no commit in the stack.

Run Covers Passed Failed Flaky (passed on retry)
47305108815 #39670, #39733, #39779 4,799 0 2: Flow/CustomizeWidgets "Pipeline Status Widget", Pages/Glossary "Change glossary term hierarchy using menu options across glossary"
47313014687 #39670, #39733, #39779, #39791 4,799 0 2: Flow/ServiceForm "Verify form selects are working properly", DataQuality/AddTestCaseNewFlow "Add Column Test Case"
  • No infrastructure issues in either run.
  • The flaky tests: none of the four is in an area these PRs change, and none repeats across the two runs.

@harsh-vador
harsh-vador force-pushed the chore/feed-counts-hook branch from a389f5e to b9f6550 Compare December 5, 2026 07:03
Base automatically changed from chore/feed-small-dups to main December 6, 2026 11:46
… counts

The hook loads an entity's task counts and its activity and conversation counts as two React Query queries, so one failing request leaves the other count in place and pages share the cached counts. It returns the feedCount, getEntityFeedCount and handleFeedCount the pages already pass down. getFeedCounts keeps its callback form for Collate, now built on the same fetchers; the unused domain overload is dropped.
…eedCounts

Each page held its own feedCount state, a getFeedCounts reload and two fetchers writing into that state. They now call the hook with their entity type, fqn and the permission they already checked; the test case page asks for task counts only. Pages that refetched every count when their permissions loaded now fetch once. The tag page still reloads the counts after a tag update. fetchEntityTaskCountsInto and fetchEntityActivityCountInto had no other caller and are removed.
After the entity pages moved to useEntityFeedCounts, openmetadata-collate is the only caller of getFeedCounts. Record that contract and cite it on the export, so a later cleanup does not delete it before Collate moves to the hook (openmetadata-collate#9311).
@harsh-vador
harsh-vador force-pushed the chore/feed-counts-hook branch from b9f6550 to 2c9209a Compare December 6, 2026 11:46
@gitar-bot

gitar-bot Bot commented Dec 6, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findings

Moving feed and task counts for 26 entity pages to React Query changes cache and reload behavior, so stale counts could mislead users.

Replaces the duplicated per-page feed and task count logic across 26 entity pages with a single React Query-based useEntityFeedCounts hook, removing roughly 900 net lines and cutting duplicate count requests on page load. The unrecorded cross-repo contract around getFeedCounts was resolved by documenting it in an ADR and JSDoc, since Collate still depends on it. No open issues found.

✅ 1 closed
✅ Quality: Unrecorded cross-repo contract: getFeedCounts kept only for collate

📄 openmetadata-ui/src/main/resources/ui/src/utils/FeedUtilsPure.ts:473-487
After this PR nothing in OpenMetadata calls getFeedCounts. The only remaining reference is its own definition in FeedUtilsPure.ts. The only thing keeping it alive is a line in the PR description: "getFeedCounts stays exported with its callback form unchanged because openmetadata-collate imports it." The repository squash-merges, so that sentence never reaches the tree or git log, and no record in docs/decisions/ states it. A later dedup pass will see an export with no caller and delete it or change its signature. That would break the collate build, and nothing in this repository would warn anyone.

The PR also changes that contract: it drops the (entityType, fqn, domain, callback) overload. A collate caller that passes domain would now have its string treated as the callback. The description only says the overload had no caller, and the tree does not show that this holds for collate.

The missing record would say: "getFeedCounts(entityType, entityFQN, callback) in utils/FeedUtilsPure.ts is a public export consumed by openmetadata-collate; its name, callback signature and the server.entity-feed-fetch-error toast on failure must not change without a coordinated collate change." Add that record in this PR, or add a JSDoc on the export that cites it.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch was previously deployed

1 inactive (outdated) deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant