import type { ReactNode } from "react";
import type {
Principal,
Run,
SandboxResources,
SandboxState,
} from "@qltysh/fabro-api-client";
import { Link } from "react-router";
import {
formatBytesAsMemory,
formatCpuCores,
formatUsdMicros,
} from "../lib/format";
import { principalDisplay } from "../lib/principal-display";
import { useRun, useRunArtifacts, useRunSandboxDetails } from "../lib/queries";
import {
SANDBOX_LIFECYCLE_DISPLAY,
sandboxIsReady,
sandboxLifecycleKind,
} from "../lib/run-sandbox-lifecycle";
import { SANDBOX_STATE_DISPLAY } from "../lib/sandbox-state";
import { Tooltip } from "./ui";
const LABEL_CLASS =
"text-[10px] font-medium uppercase tracking-[0.08em] text-fg-muted";
const VALUE_WRAPPER_CLASS = "mt-1.5";
const VALUE_CLASS = "text-sm text-fg";
const VALUE_MONO_CLASS = "text-sm text-fg font-mono tabular-nums";
const EMPTY_VALUE_CLASS = "text-sm text-fg-muted";
function EmptyValue() {
return Not available;
}
function Skeleton({ widthClass }: { widthClass: string }) {
return (
);
}
function Cell({ label, children }: { label: string; children: ReactNode }) {
return (
);
}
function CreatedByValue({ actor }: { actor: Principal }) {
const created = principalDisplay(actor);
return (
{created.glyph}
{created.label}
);
}
export interface RunSummaryPanelViewProps {
run: Run | null;
runLoading: boolean;
sandboxState: SandboxState | null;
sandboxResources: SandboxResources | null;
sandboxLoading: boolean;
artifactsCount: number | null;
artifactsLoading: boolean;
}
function SandboxValue({
state,
resources,
}: {
state: SandboxState;
resources: SandboxResources | null;
}) {
const display = SANDBOX_STATE_DISPLAY[state] ?? SANDBOX_STATE_DISPLAY.unknown;
const cpu = resources?.cpu_cores;
const memory = resources?.memory_bytes;
const valueText =
cpu != null && memory != null
? `${formatCpuCores(cpu)} CPU · ${formatBytesAsMemory(memory)}`
: display.label;
return (
{valueText}
);
}
function SandboxLifecycleValue({
kind,
}: {
kind: keyof typeof SANDBOX_LIFECYCLE_DISPLAY;
}) {
const display = SANDBOX_LIFECYCLE_DISPLAY[kind];
return (
{display.label}
);
}
export function RunSummaryPanelView({
run,
runLoading,
sandboxState,
sandboxResources,
sandboxLoading,
artifactsCount,
artifactsLoading,
}: RunSummaryPanelViewProps) {
const diff = run?.diff ?? null;
const cost = formatUsdMicros(run?.billing?.total_usd_micros);
const sandboxKind = sandboxLifecycleKind(run?.sandbox);
return (
|
{runLoading ? (
) : run ? (
) : (
)}
|
{runLoading ? (
) : diff ? (
+{diff.additions.toLocaleString()}{" "}
−{diff.deletions.toLocaleString()}
in {diff.files_changed.toLocaleString()} {diff.files_changed === 1 ? "file" : "files"}
) : (
)}
|
{sandboxLoading ? (
) : sandboxState ? (
) : sandboxKind ? (
) : (
)}
|
{runLoading ? (
) : cost != null ? (
{cost}
) : (
)}
|
{artifactsLoading ? (
) : artifactsCount != null && artifactsCount > 0 ? (
{artifactsCount}
) : (
)}
|
{run?.retried_from && (
{run.retried_from.slice(0, 8)}
|
)}
);
}
export function RunSummaryPanel({ runId }: { runId: string }) {
const runQuery = useRun(runId);
const sandboxQuery = useRunSandboxDetails(
sandboxIsReady(runQuery.data?.sandbox) ? runId : undefined,
);
const artifactsQuery = useRunArtifacts(runId);
const sandboxReady = sandboxIsReady(runQuery.data?.sandbox);
return (
);
}