Keep Command Center token usage surfaces mounted and updated during live analytics polling. - Preserve existing analytics data while background polls are in flight so token surfaces revalidate without disappearing. - Add live refresh intervals for Overview and Tokens token-usage data. - Cover in-place token stat, chart, and model-row updates with Command Center and area tests. - Add a patch changeset for the published Fusion package. Files changed: .changeset/fn-6970-command-center-token-live.md | 7 ++ .../components/command-center/CommandCenter.tsx | 4 + .../__tests__/CommandCenter.test.tsx | 81 +++++++++++++-- .../components/command-center/areas/AreaShell.tsx | 3 + .../components/command-center/areas/TokensArea.tsx | 4 + .../command-center/areas/__tests__/areas.test.tsx | 111 +++++++++++++++++++-- .../command-center/areas/useAnalyticsArea.ts | 12 ++- 7 files changed, 208 insertions(+), 14 deletions(-) Fusion-Task-Id: FN-6970 Fusion-Task-Lineage: 670bb5ac-bc7d-47d8-abed-ef6748292cc6
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { AlertCircle, Gauge, Loader2 } from "lucide-react";
|
|
import "./areas.css";
|
|
|
|
export interface AreaShellProps {
|
|
/** Stable test id prefix, e.g. "tokens" → cc-area-tokens. */
|
|
testId: string;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
/** True when the loaded data has nothing to display. */
|
|
isEmpty: boolean;
|
|
/** Custom empty-state message; defaults to the shared "no data" copy. */
|
|
emptyMessage?: string;
|
|
children: ReactNode;
|
|
}
|
|
|
|
/**
|
|
* Shared loading / error / empty wrapper for the historical-analytics areas,
|
|
* mirroring `ReliabilityView`'s state handling. Renders children only once
|
|
* there is data to show; never crashes on an empty area (degrades to the
|
|
* empty state instead).
|
|
*
|
|
* FNXC:CommandCenterTokenLive 2026-06-25-09:06:
|
|
* `isLoading` is a blocking initial-load signal. Background analytics polls with fallback data must keep children rendered so live token cards/charts do not disappear while revalidating.
|
|
*/
|
|
export function AreaShell({ testId, isLoading, error, isEmpty, emptyMessage, children }: AreaShellProps) {
|
|
const { t } = useTranslation("app");
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<div className="cc-loading-inline" data-testid={`cc-area-${testId}-loading`}>
|
|
<Loader2 size={18} className="spin" />
|
|
<span>{t("commandCenter.area.loading", "Loading…")}</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (error !== null) {
|
|
return (
|
|
<div className="cc-area-error" data-testid={`cc-area-${testId}-error`} role="alert">
|
|
<AlertCircle size={22} />
|
|
<p>{error}</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (isEmpty) {
|
|
return (
|
|
<div className="cc-area-empty" data-testid={`cc-area-${testId}-empty`}>
|
|
<Gauge size={24} />
|
|
<p>{emptyMessage ?? t("commandCenter.area.empty", "No data for the selected range.")}</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="cc-area" data-testid={`cc-area-${testId}`}>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|