fix(ui): sidebar catalog counts follow global time range

useCatalog now accepts optional from/to query params and LayoutShell
threads the TopBar time range through, so the per-app exchange counts
shown in the sidebar align with the Exchanges tab window. Previously
the sidebar relied on the backend's 24h default — 73.5k in the sidebar
coexisted with 0 hits in a 1h Exchanges search, confusing users.

Other useCatalog callers stay on the default (no time range), matching
their existing behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-23 19:15:01 +02:00
parent 166568edea
commit b799d55835
2 changed files with 7 additions and 3 deletions

View File

@@ -38,14 +38,16 @@ export interface CatalogApp {
deployment: DeploymentSummary | null; deployment: DeploymentSummary | null;
} }
export function useCatalog(environment?: string) { export function useCatalog(environment?: string, from?: string, to?: string) {
const refetchInterval = useRefreshInterval(15_000); const refetchInterval = useRefreshInterval(15_000);
return useQuery({ return useQuery({
queryKey: ['catalog', environment], queryKey: ['catalog', environment, from, to],
queryFn: async () => { queryFn: async () => {
const token = useAuthStore.getState().accessToken; const token = useAuthStore.getState().accessToken;
const params = new URLSearchParams(); const params = new URLSearchParams();
if (environment) params.set('environment', environment); if (environment) params.set('environment', environment);
if (from) params.set('from', from);
if (to) params.set('to', to);
const qs = params.toString(); const qs = params.toString();
const res = await fetch(`${config.apiBaseUrl}/catalog${qs ? `?${qs}` : ''}`, { const res = await fetch(`${config.apiBaseUrl}/catalog${qs ? `?${qs}` : ''}`, {
headers: { headers: {

View File

@@ -361,7 +361,9 @@ function LayoutContent() {
const selectedEnv = useEnvironmentStore((s) => s.environment); const selectedEnv = useEnvironmentStore((s) => s.environment);
const setSelectedEnvRaw = useEnvironmentStore((s) => s.setEnvironment); const setSelectedEnvRaw = useEnvironmentStore((s) => s.setEnvironment);
const { data: catalog } = useCatalog(selectedEnv); const catalogFrom = timeRange.start.toISOString();
const catalogTo = timeRange.end.toISOString();
const { data: catalog } = useCatalog(selectedEnv, catalogFrom, catalogTo);
// Env is always required now (path-based endpoint). For cross-env "all agents" // Env is always required now (path-based endpoint). For cross-env "all agents"
// we'd need a separate flat endpoint; sidebar uses env-filtered list directly. // we'd need a separate flat endpoint; sidebar uses env-filtered list directly.
const { data: agents } = useAgents(); // env pulled from store internally const { data: agents } = useAgents(); // env pulled from store internally