feat(platform): harden telemetry pipeline and unify Semi UI workspaces
This commit is contained in:
@@ -2,6 +2,7 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { api } from '../../api/client';
|
||||
import type { MonitorMapResponse, MonitorSummary, MonitorWorkspaceResponse, Page, VehicleRealtimeRow } from '../../api/types';
|
||||
import { normalizeMonitorBounds } from '../domain/monitor';
|
||||
import { LIVE_QUERY_POLICY, QUERY_MEMORY, retainPreviousPageWithinScope } from '../queryPolicy';
|
||||
|
||||
export type MonitorFilters = {
|
||||
@@ -116,7 +117,8 @@ export function monitorQueryParams(filters: MonitorFilters, limit: number) {
|
||||
export function monitorMapQueryParams(filters: MonitorFilters, viewport: MonitorViewport) {
|
||||
const params = monitorQueryParams(filters, 10_000);
|
||||
params.set('zoom', String(viewport.zoom));
|
||||
if (viewport.bounds && parseMonitorSearchTerms(filters.keyword).length === 0) params.set('bounds', viewport.bounds);
|
||||
const bounds = normalizeMonitorBounds(viewport.bounds);
|
||||
if (bounds && parseMonitorSearchTerms(filters.keyword).length === 0) params.set('bounds', bounds);
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -203,6 +205,15 @@ export function useMonitorVehicleCard(vin: string, vehicle?: VehicleRealtimeRow,
|
||||
gcTime: QUERY_MEMORY.highVolumeGcTime,
|
||||
...LIVE_QUERY_POLICY
|
||||
});
|
||||
const telemetry = useQuery({
|
||||
queryKey: ['monitor', 'vehicle-card', 'telemetry', vin],
|
||||
queryFn: ({ signal }) => api.latestTelemetry(vin, signal),
|
||||
enabled: enabled && vehicle?.primaryProtocol === 'GB32960',
|
||||
staleTime: 10_000,
|
||||
refetchInterval: enabled && activelyTracked && vehicle?.primaryProtocol === 'GB32960' ? 20_000 : false,
|
||||
gcTime: QUERY_MEMORY.highVolumeGcTime,
|
||||
...LIVE_QUERY_POLICY
|
||||
});
|
||||
const address = useQuery({
|
||||
queryKey: ['monitor', 'vehicle-card', 'address', addressPoint?.vin, addressPoint?.key],
|
||||
queryFn: ({ signal }) => api.reverseGeocode(new URLSearchParams({
|
||||
@@ -214,5 +225,5 @@ export function useMonitorVehicleCard(vin: string, vehicle?: VehicleRealtimeRow,
|
||||
gcTime: QUERY_MEMORY.highVolumeGcTime
|
||||
});
|
||||
|
||||
return { detail, activeAlerts, address };
|
||||
return { detail, activeAlerts, telemetry, address };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user