Repository navigation
fix: refetch SQL query "All" options on every dashboard refresh #3862
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@hyperdx/app': patch | ||
| --- | ||
|
|
||
| fix: refetch the options of SQL query filters set to "All" on every dashboard refresh, so "All" picks up new values even when the filter's query ignores the time range. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useMemo } from 'react'; | ||
| import { useEffect, useMemo, useRef } from 'react'; | ||
| import { | ||
| ClickHouseQueryError, | ||
| ResponseJSON, | ||
|
|
@@ -158,7 +158,16 @@ export function useSqlQueryFilterValues({ | |
| dateRange, | ||
| variables, | ||
| getDashboardFilters, | ||
| }: DashboardState & { filters: SqlQueryDashboardFilter[] }) { | ||
| refreshKey, | ||
| }: DashboardState & { | ||
| filters: SqlQueryDashboardFilter[]; | ||
| /** | ||
| * When this changes, every query refetches, including one whose key didn't | ||
| * change because its SQL ignores the time range. A request already in | ||
| * flight is reused rather than repeated. | ||
| */ | ||
| refreshKey?: string; | ||
| }) { | ||
| const { sourcesById, isLoadingSources } = useSourcesById(); | ||
| const metadata = useMetadataWithSettings(); | ||
|
|
||
|
|
@@ -225,6 +234,15 @@ export function useSqlQueryFilterValues({ | |
| })), | ||
| }); | ||
|
|
||
| const lastRefreshKeyRef = useRef(refreshKey); | ||
| useEffect(() => { | ||
| if (lastRefreshKeyRef.current === refreshKey) return; | ||
| lastRefreshKeyRef.current = refreshKey; | ||
| for (const result of results) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — Refetched "All" options aren't treated as loading, so tiles run twice per refresh with stale options first For a query that ignores the time range, Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| void result.refetch({ cancelRefetch: false }); | ||
| } | ||
| }, [refreshKey, results]); | ||
|
|
||
| return useMemo(() => { | ||
| const data = new Map<string, { values: string[]; isLoading: boolean }>(); | ||
| const erroredFilterIds = new Set<string>(); | ||
|
|
||
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.
🟡 P2 — "doesn't refetch for an equal time range" checks the call count before any refetch could reach mockQuery
The
queryFnfirst awaitsrenderValuesCall(useSqlQueryFilterValues.tsx:217) and only then callsgetClickhouseClient().query. So a refetch fired by the effect on this rerender would not have calledmockQueryyet when line 174 runs synchronously, and the test passes even ifrefreshKeywere built fromDateidentity. Wait before asserting, for example withawait waitFor(() => expect(result.current...isFetching).toBe(false))or by flushing microtasks withawait act(async () => {}), then checktoHaveBeenCalledTimes(1).Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond