Skip to content

refactor: extract dashboard tab data-fetching into dedicated TabView components - #3797

Merged
akshaydeo merged 1 commit into
devfrom
05-27-fix_fetch_only_active_tabs_data_in_dashboard
May 27, 2026
Merged

refactor: extract dashboard tab data-fetching into dedicated TabView components#3797
akshaydeo merged 1 commit into
devfrom
05-27-fix_fetch_only_active_tabs_data_in_dashboard

Conversation

@impoiler

Copy link
Copy Markdown
Contributor

Summary

Refactors the dashboard page by extracting per-tab data fetching logic into dedicated *TabView wrapper components, replacing the large collection of manual state variables, lazy query hooks, and ensure*DataLoaded ref-tracking functions that previously lived directly in page.tsx.

Changes

  • Introduced five new forwardRef tab view components (OverviewTabView, ProviderUsageTabView, MCPTabView, ModelRankingsTabView, DimensionRankingsTabView), each owning its own RTK Query subscriptions, loading state, and getData/loadData imperative handle.
  • Replaced ~300 lines of manual state, lazy hooks, fetch functions, and generation-counter deduplication logic in page.tsx with refs to the new tab view components. Export data aggregation now iterates over those refs rather than a large useMemo object.
  • Each tab view uses an active prop (driven by the current tab value or pdfMode) to skip fetching when the tab is not visible, delegating the skip logic to RTK Query's built-in skip option instead of manual fetchedRef/loadingRef guards.
  • Exported useGetModelRankingsQuery, useGetDimensionRankingsQuery, useGetMCPCostHistogramQuery, and useGetMCPTopToolsQuery non-lazy hooks from the store APIs to support the new subscription-based approach.
  • Moved sanitizeSeriesLabels into the tab views that need it (OverviewTabView, ProviderUsageTabView) rather than keeping it in the page.
  • Reordered the "User Rankings" tab trigger to appear before "Customer Rankings" and "BU Rankings" in the tab list.
  • Removed the background warm-up setTimeout effect and the filter-change useEffect that reset all fetch flags, as RTK Query cache invalidation now handles re-fetching automatically.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

cd ui
pnpm i || npm i
pnpm build || npm run build
  1. Open the dashboard and verify each tab loads its data correctly when first visited.
  2. Change a filter (e.g., time range or provider) and confirm all visible and previously loaded tabs refresh.
  3. Trigger a CSV and PDF export and confirm all tab data is included.
  4. Verify PDF export correctly force-mounts all tabs and captures each section.

Screenshots/Recordings

No visual changes expected; this is a pure refactor of data-fetching logic.

Breaking changes

  • Yes
  • No

Related issues

Security considerations

None.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@akshaydeo, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 36 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b57322bb-cfd1-4d79-9083-ca54b1fffcad

📥 Commits

Reviewing files that changed from the base of the PR and between c6a89b9 and 230db16.

📒 Files selected for processing (8)
  • ui/app/workspace/dashboard/components/tabViews/dimensionRankingsTabView.tsx
  • ui/app/workspace/dashboard/components/tabViews/mcpTabView.tsx
  • ui/app/workspace/dashboard/components/tabViews/modelRankingsTabView.tsx
  • ui/app/workspace/dashboard/components/tabViews/overviewTabView.tsx
  • ui/app/workspace/dashboard/components/tabViews/providerUsageTabView.tsx
  • ui/app/workspace/dashboard/page.tsx
  • ui/lib/store/apis/logsApi.ts
  • ui/lib/store/apis/mcpLogsApi.ts
📝 Walkthrough

Walkthrough

This PR refactors the Dashboard page from a monolithic component with local RTK query orchestration into a modular tab-view architecture. Five new tab view components encapsulate data fetching and expose imperative ref APIs. The Dashboard page aggregates these refs to fetch and export data across all active tabs.

Changes

Dashboard Tab View Refactor

Layer / File(s) Summary
RTK Query Hook Exports
ui/lib/store/apis/logsApi.ts, ui/lib/store/apis/mcpLogsApi.ts
useGetModelRankingsQuery, useGetDimensionRankingsQuery, useGetMCPCostHistogramQuery, and useGetMCPTopToolsQuery hooks are exported to support tab view components.
Overview Tab View
ui/app/workspace/dashboard/components/tabViews/overviewTabView.tsx
Wires six histogram and stats queries with active-driven skip; sanitizes/deduplicates model labels; exposes getData() and loadData() imperative API via forwardRef.
Provider Usage Tab View
ui/app/workspace/dashboard/components/tabViews/providerUsageTabView.tsx
Wires cost/token/latency histogram queries; sanitizes/deduplicates provider labels; exposes imperative ref for data access and on-demand loading.
Model Rankings Tab View
ui/app/workspace/dashboard/components/tabViews/modelRankingsTabView.tsx
Wires model rankings and histogram queries with concurrent lazy loading; exposes imperative ref with null-normalized data returns.
MCP Tab View
ui/app/workspace/dashboard/components/tabViews/mcpTabView.tsx
Wires three MCP histogram queries (histogram, cost histogram, top-tools) with active-driven skip and concurrent lazy loading.
Dimension Rankings Tab View
ui/app/workspace/dashboard/components/tabViews/dimensionRankingsTabView.tsx
Wires dimension-specific ranking queries; exposes imperative ref returning requested dataKey and triggering on-demand fetch.
Dashboard Page Integration
ui/app/workspace/dashboard/page.tsx
Removes local RTK query state; introduces tab view refs; adds filter parsing, getDashboardData()/handlePreloadData() aggregation, PDF export with preload/layout override, and re-wires tab content rendering.

Sequence Diagram(s)

sequenceDiagram
  participant DashboardPage
  participant TabViewRefs as Tab View Refs<br/>(Overview, Provider, etc.)
  participant RTKQueries as RTK Query Hooks
  participant TabPresentational as Tab Components<br/>(MCPTab, OverviewTab, etc.)
  DashboardPage->>DashboardPage: parse filters from URL
  DashboardPage->>TabViewRefs: pass filters, active state, pdfMode
  Note over TabViewRefs: active = true for current tab
  TabViewRefs->>RTKQueries: skip = false, fetch data
  RTKQueries-->>TabViewRefs: histogram, rankings, stats
  DashboardPage->>TabViewRefs: getDashboardData() for export
  TabViewRefs-->>DashboardPage: aggregated Partial<DashboardData>
  DashboardPage->>TabViewRefs: handlePreloadData() on PDF export
  TabViewRefs->>RTKQueries: loadData() triggers all lazy queries
  DashboardPage->>DashboardPage: handlePdfExport() enables pdfMode
  DashboardPage->>TabPresentational: unhide force-mounted tabs, measure
  TabPresentational-->>DashboardPage: rendered DOM ready for capture
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • maximhq/bifrost#3650: Both PRs modify ui/app/workspace/dashboard/page.tsx to change how URL-derived filters are constructed and passed into the dashboard data-fetching flow; #3650 adds team_ids/customer_ids/business_unit_ids to filters, which this PR's new tab-view refactor consumes.

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

🐰 Five tab views spring to life with refs held tight,
Data fetching split apart, no monolith in sight,
Imperative handles dance through the dashboard page,
PDF exports preload with style and with grace!
hop hop

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: extracting dashboard tab data-fetching logic into dedicated TabView components, which matches the core refactoring work shown in the changeset.
Description check ✅ Passed The description comprehensively covers all required template sections: clear summary of the refactor, detailed changes explaining the new components and removed logic, marked type (Refactor), affected areas (UI), testing steps, breaking changes status, and a completion checklist.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 05-27-fix_fetch_only_active_tabs_data_in_dashboard

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

Export paths have correctness issues with inactive tabs returning null data; the refactor itself is clean but export functionality needs resolution before merging

The tab view components are well-structured. Risk is in getDashboardData and handlePdfExport: inactive tabs (skip=true) return null from getData(), and modelData is emitted by both OverviewTabView and ModelRankingsTabView causing one to overwrite the other. PDF export calls handlePreloadData before setPdfMode(true), so inactive tab refs are null and loadData() is never called for them.

page.tsx — getDashboardData and handlePdfExport

Important Files Changed

Filename Overview
ui/app/workspace/dashboard/page.tsx Removed ~300 lines of manual state/lazy-hook boilerplate; export plumbing has known issues (inactive-tab null data in CSV, PDF capture timing) discussed in previous threads
ui/app/workspace/dashboard/components/tabViews/overviewTabView.tsx New component encapsulating Overview tab data-fetching; modelData key overlaps with ModelRankingsTabView
ui/app/workspace/dashboard/components/tabViews/modelRankingsTabView.tsx getData() emits modelData colliding with OverviewTabView when both are mounted
ui/lib/store/apis/logsApi.ts Exports useGetModelRankingsQuery and useGetDimensionRankingsQuery non-lazy hooks
ui/lib/store/apis/mcpLogsApi.ts Exports useGetMCPCostHistogramQuery and useGetMCPTopToolsQuery non-lazy hooks

Reviews (6): Last reviewed commit: "fix: fetch only active tabs data in dash..." | Re-trigger Greptile

@impoiler impoiler self-assigned this May 27, 2026
@impoiler
impoiler force-pushed the 05-26-feat_adds_team_bu_and_customers_ranking_on_dashboard branch from eac19fe to 4d50443 Compare May 27, 2026 12:19
@impoiler
impoiler force-pushed the 05-27-fix_fetch_only_active_tabs_data_in_dashboard branch from 11e3a09 to 18253b0 Compare May 27, 2026 12:19
Comment thread ui/app/workspace/dashboard/page.tsx
@impoiler
impoiler force-pushed the 05-27-fix_fetch_only_active_tabs_data_in_dashboard branch from 18253b0 to be859cc Compare May 27, 2026 12:30
@impoiler
impoiler force-pushed the 05-26-feat_adds_team_bu_and_customers_ranking_on_dashboard branch from 4d50443 to ba36910 Compare May 27, 2026 12:30
@impoiler
impoiler force-pushed the 05-27-fix_fetch_only_active_tabs_data_in_dashboard branch from a957ea9 to c6a89b9 Compare May 27, 2026 13:16
@impoiler
impoiler force-pushed the 05-26-feat_adds_team_bu_and_customers_ranking_on_dashboard branch from 712f0b2 to 75c1e18 Compare May 27, 2026 13:16
@coderabbitai
coderabbitai Bot requested a review from akshaydeo May 27, 2026 13:18
@coderabbitai
coderabbitai Bot requested a review from danpiths May 27, 2026 13:18
Comment thread ui/app/workspace/dashboard/page.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ui/app/workspace/dashboard/page.tsx`:
- Around line 348-394: The PDF export's section ordering in handlePdfExport is
out of sync with the UI tab order: update the ids array inside handlePdfExport
so the element IDs follow the same visual tab sequence (move
"dashboard-section-user-rankings" to appear before
"dashboard-section-customer-rankings" and "dashboard-section-bu-rankings"), then
return the mapped elements as before; ensure you only change the order of the
IDs in the ids constant so exported PDF pages match the on-screen tabs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7273bbc2-3fbb-442e-971d-b71468a54e3a

📥 Commits

Reviewing files that changed from the base of the PR and between 75c1e18 and c6a89b9.

📒 Files selected for processing (8)
  • ui/app/workspace/dashboard/components/tabViews/dimensionRankingsTabView.tsx
  • ui/app/workspace/dashboard/components/tabViews/mcpTabView.tsx
  • ui/app/workspace/dashboard/components/tabViews/modelRankingsTabView.tsx
  • ui/app/workspace/dashboard/components/tabViews/overviewTabView.tsx
  • ui/app/workspace/dashboard/components/tabViews/providerUsageTabView.tsx
  • ui/app/workspace/dashboard/page.tsx
  • ui/lib/store/apis/logsApi.ts
  • ui/lib/store/apis/mcpLogsApi.ts

Comment thread ui/app/workspace/dashboard/page.tsx
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 27, 2026

akshaydeo commented May 27, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • May 27, 1:44 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 27, 1:58 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 27, 1:59 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo changed the base branch from 05-26-feat_adds_team_bu_and_customers_ranking_on_dashboard to graphite-base/3797 May 27, 2026 13:56
@akshaydeo
akshaydeo changed the base branch from graphite-base/3797 to dev May 27, 2026 13:57
@akshaydeo
akshaydeo dismissed coderabbitai[bot]’s stale review May 27, 2026 13:57

The base branch was changed.

@akshaydeo
akshaydeo force-pushed the 05-27-fix_fetch_only_active_tabs_data_in_dashboard branch from c6a89b9 to 230db16 Compare May 27, 2026 13:57
@akshaydeo
akshaydeo merged commit 189bfe9 into dev May 27, 2026
14 of 15 checks passed
@akshaydeo
akshaydeo deleted the 05-27-fix_fetch_only_active_tabs_data_in_dashboard branch May 27, 2026 13:59
akshaydeo pushed a commit that referenced this pull request May 29, 2026
…` components (#3797)

## Summary

Refactors the dashboard page by extracting per-tab data fetching logic into dedicated `*TabView` wrapper components, replacing the large collection of manual state variables, lazy query hooks, and `ensure*DataLoaded` ref-tracking functions that previously lived directly in `page.tsx`.

## Changes

- Introduced five new `forwardRef` tab view components (`OverviewTabView`, `ProviderUsageTabView`, `MCPTabView`, `ModelRankingsTabView`, `DimensionRankingsTabView`), each owning its own RTK Query subscriptions, loading state, and `getData`/`loadData` imperative handle.
- Replaced ~300 lines of manual state, lazy hooks, fetch functions, and generation-counter deduplication logic in `page.tsx` with refs to the new tab view components. Export data aggregation now iterates over those refs rather than a large `useMemo` object.
- Each tab view uses an `active` prop (driven by the current tab value or `pdfMode`) to skip fetching when the tab is not visible, delegating the skip logic to RTK Query's built-in `skip` option instead of manual `fetchedRef`/`loadingRef` guards.
- Exported `useGetModelRankingsQuery`, `useGetDimensionRankingsQuery`, `useGetMCPCostHistogramQuery`, and `useGetMCPTopToolsQuery` non-lazy hooks from the store APIs to support the new subscription-based approach.
- Moved `sanitizeSeriesLabels` into the tab views that need it (`OverviewTabView`, `ProviderUsageTabView`) rather than keeping it in the page.
- Reordered the "User Rankings" tab trigger to appear before "Customer Rankings" and "BU Rankings" in the tab list.
- Removed the background warm-up `setTimeout` effect and the filter-change `useEffect` that reset all fetch flags, as RTK Query cache invalidation now handles re-fetching automatically.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [x] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [x] UI (React)
- [ ] Docs

## How to test

```sh
cd ui
pnpm i || npm i
pnpm build || npm run build
```

1. Open the dashboard and verify each tab loads its data correctly when first visited.
2. Change a filter (e.g., time range or provider) and confirm all visible and previously loaded tabs refresh.
3. Trigger a CSV and PDF export and confirm all tab data is included.
4. Verify PDF export correctly force-mounts all tabs and captures each section.

## Screenshots/Recordings

No visual changes expected; this is a pure refactor of data-fetching logic.

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

None.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
@coderabbitai coderabbitai Bot mentioned this pull request Jul 1, 2026
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