Skip to content

ref(dashboards): Remove Widget Viewer manual caching layer#109689

Merged
gggritso merged 5 commits intomasterfrom
georgegritsouk/dain-1253-remove-widget-viewer-caching-code
Mar 3, 2026
Merged

ref(dashboards): Remove Widget Viewer manual caching layer#109689
gggritso merged 5 commits intomasterfrom
georgegritsouk/dain-1253-remove-widget-viewer-caching-code

Conversation

@gggritso
Copy link
Member

@gggritso gggritso commented Mar 2, 2026

Remove the manual caching system where WidgetCard pushed fetched data into a WidgetViewerContext, which DashboardDetail then read and passed as props to the Widget Viewer modal. Since widget data fetching now uses hooks backed by TanStack Query, the query cache serves as the data store. When the modal opens and renders the same query hooks, TanStack Query returns cached data instantly, making the manual caching layer redundant.

This deletes the WidgetViewerContext entirely, removes the cached data props and conditional rendering branches from the modal, and simplifies the DashboardDetail component state.

Also increases stale time for dashboard widget queries using a custom GranularityLadder that scales with the selected time range. This ensures the TanStack Query cache serves data when the Widget Viewer opens, reducing redundant API requests. The stale times are more generous than Insights/Explore since dashboards are more static.

Refs DAIN-1253

@linear
Copy link

linear bot commented Mar 2, 2026

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 2, 2026
@gggritso gggritso changed the title refactor(dashboards): Remove Widget Viewer manual caching layer ref(dashboards): Remove Widget Viewer manual caching layer Mar 2, 2026
@gggritso gggritso marked this pull request as ready for review March 2, 2026 21:02
@gggritso gggritso requested a review from a team as a code owner March 2, 2026 21:02
Copy link
Contributor

@DominikB2014 DominikB2014 left a comment

Choose a reason for hiding this comment

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

Lgtm! Just to confirm, did you test out the react query caching as well, just to ensure it's working as expected and we didn't mess up any query keys.

@gggritso
Copy link
Member Author

gggritso commented Mar 3, 2026

@DominikB2014 I did, yeah! I actually used the TanStack Devtools UI for the first time, pretty handy 👍🏻

gggritso and others added 5 commits March 3, 2026 11:42
Remove the convoluted caching system where WidgetCard pushed fetched
data into a WidgetViewerContext, which DashboardDetail then read and
passed as props to the Widget Viewer modal. Since widget data fetching
now uses hooks backed by TanStack Query, the query cache serves as the
data store, making this manual caching layer redundant.

- Delete widgetViewerContext.tsx
- Remove WidgetViewerContext provider from DashboardDetail
- Remove cached data props from WidgetViewerModalOptions interface
- Remove chartUnmodified state and conditional cached-data rendering
- Remove setChartUnmodified from ViewerTableV2
- Update tests to not rely on cached data behavior

Refs DAIN-1253
Co-Authored-By: Claude <noreply@anthropic.com>
This will increase the amount of request re-use. Using my judgement for
this one, we can tweak later.
Tests now provide proper mock API responses instead of relying on
cached data props. Add events-stats meta for duration formatting,
adjust session request counts for mount fetches, and provide span
event data for table rendering.

Co-Authored-By: Claude <noreply@anthropic.com>
Function is only used within the same file now that the dashboard
stale time logic uses its own GranularityLadder.
Replace GranularityLadder with RangeMap since it maps duration ranges
directly to millisecond values without the intermediate string
conversion step.

Co-Authored-By: Claude <noreply@anthropic.com>
@gggritso gggritso force-pushed the georgegritsouk/dain-1253-remove-widget-viewer-caching-code branch from 75a27bd to 670cb46 Compare March 3, 2026 16:42
@gggritso gggritso merged commit 169e789 into master Mar 3, 2026
78 of 82 checks passed
@gggritso gggritso deleted the georgegritsouk/dain-1253-remove-widget-viewer-caching-code branch March 3, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants