Skip to content

Commit 844cdf0

Browse files
committed
StatsHouse UI: fix badge fetch
1 parent 35d1b1b commit 844cdf0

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

statshouse-ui/src/api/badges.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type { PlotParams, TimeRange, VariableKey, VariableParams } from '@/url2'
1010
import { useLiveModeStore } from '@/store2/liveModeStore';
1111
import { useMemo } from 'react';
1212
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
13-
import { useStatsHouse } from '@/store2';
1413
import { getLoadPlotUrlParamsLight } from '@/store2/plotDataStore/loadPlotData2';
14+
import { usePlotHeal } from '@/hooks/usePlotHeal';
1515

1616
export const ApiBadgesEndpoint = '/api/badges';
1717

@@ -52,10 +52,7 @@ export function useApiBadges<T = ApiBadges>(
5252
return getLoadPlotUrlParamsLight(plot, timeRange, timeShifts, variables, interval);
5353
}, [interval, plot, timeRange, timeShifts, variables]);
5454

55-
const plotHeals = useStatsHouse((s) => {
56-
const status = s.plotHeals[plot.id];
57-
return !(!!status && !status.status && status.lastTimestamp + status.timeout * 1000 > Date.now());
58-
});
55+
const plotHeals = usePlotHeal(plot.id);
5956

6057
const fetchParams = useMemo(() => {
6158
if (!plot?.id) {
@@ -65,7 +62,12 @@ export function useApiBadges<T = ApiBadges>(
6562
}, [interval, plot, priority, timeRange, timeShifts, variables]);
6663

6764
return useQuery({
68-
enabled: plotHeals && enabled,
65+
enabled: (): boolean => {
66+
if (enabled) {
67+
return plotHeals === true || plotHeals > Date.now();
68+
}
69+
return false;
70+
},
6971
select,
7072
queryKey: [ApiBadgesEndpoint, keyParams],
7173
queryFn: async ({ signal }) => {

statshouse-ui/src/components2/Plot/PlotView/PlotSubMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const PlotSubMenu = memo(function PlotSubMenu({ className }: PlotSubMenuP
2929
const { timeRange, timeShifts, variables } = useStatsHouseShallow(selectorStore);
3030
const metricName = useMetricName(true);
3131
const { receiveErrors, receiveWarnings, samplingFactorSrc, samplingFactorAgg, mappingFloodEvents, isLoading } =
32-
useMetricBadges(plot, timeRange, timeShifts, variables);
32+
useMetricBadges(plot, timeRange, timeShifts, variables, true, 1);
3333

3434
const linkCSV = useLinkCSV2(plot.id);
3535
return (

statshouse-ui/src/hooks/useMetricBadges.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// License, v. 2.0. If a copy of the MPL was not distributed with this
55
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
66

7-
import { ApiBadges, useApiBadges } from '../api/badges';
8-
import { getNewMetric, PlotParams, type TimeRange, type VariableKey, type VariableParams } from '../url2';
7+
import { type ApiBadges, useApiBadges } from '@/api/badges';
8+
import { getNewMetric, type PlotParams, type TimeRange, type VariableKey, type VariableParams } from '@/url2';
99
import { useMemo } from 'react';
1010

1111
const badgesSelector = (r?: ApiBadges) => ({
@@ -21,9 +21,11 @@ export function useMetricBadges(
2121
plot: PlotParams = defaultPlot,
2222
timeRange: TimeRange,
2323
timeShifts: number[],
24-
variables: Partial<Record<VariableKey, VariableParams>>
24+
variables: Partial<Record<VariableKey, VariableParams>>,
25+
enabled: boolean = false,
26+
priority: number = 2
2527
) {
26-
const queryData = useApiBadges(plot, timeRange, timeShifts, variables, badgesSelector);
28+
const queryData = useApiBadges(plot, timeRange, timeShifts, variables, badgesSelector, enabled, priority);
2729
return useMemo(
2830
() => ({
2931
isLoading: queryData.isLoading,

0 commit comments

Comments
 (0)