All files / client/src/hooks use-telemetry.ts

100% Statements 5/5
100% Branches 8/8
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                  3x       3x 3x 3x               3x    
import { useMemo } from "react";
import { TelemetryMetrics, useTelemetryStore } from "./use-telemetry-store";
 
/**
 * Helper hook bundling telemetry store subscription with some derived data
 * that is useful for UI components. Separates metrics-specific logic out of
 * pages and places it in a reusable hook.
 */
export function useTelemetry() {
  const telemetryData = useTelemetryStore();
 
  // derive a few commonly used rate values so callers don't have to guard
  // against null/undefined all over the place.
  const rates = useMemo(() => {
    const last: TelemetryMetrics | null = telemetryData.last;
    return {
      serialOutputPerSecond: last?.serialOutputPerSecond ?? 0,
      serialBytesPerSecond: last?.serialBytesPerSecond ?? 0,
      serialDroppedBytesPerSecond: last?.serialDroppedBytesPerSecond ?? 0,
      serialBytesTotal: last?.serialBytesTotal ?? 0,
    };
  }, [telemetryData.last]);
 
  return { telemetryData, rates };
}