EnergyVenom's picture
Deploy production-hardening: security, reliability, account page, feature switches, metrics, docs
4545bb3 verified
Raw History Blame Contribute Delete
3.32 kB
import { Tooltip } from '@mantine/core';
import { Link } from 'react-router-dom';
import type { Schemas } from '../../api/client';
import { decisionWords, RUN_STATUS_WORDS } from '../../glossary';
import { runAreas, runTitle, shortWhen } from '../../runName';
import type { EnvKind } from './EnvSwitcher';
import { isWaiting, useWaitsOnMe, waitingForWords } from '../../waiting';
import { runState, StatusDot } from './StatusDot';
type RunSummary = Schemas['RunSummary'];
// Accessible names avoid the phrase "scenario review": that is the name of the review region itself.
export const runStatusWords = (r: Pick<RunSummary, 'status' | 'pending_gate'>, mine = true) =>
isWaiting(r) && !mine ? waitingForWords(r.pending_gate).toLowerCase()
: r.pending_gate === 'approve_cases' ? 'waiting for you to approve the scenarios'
: r.pending_gate === 'human_review' ? 'waiting for your decision on failures'
: r.status === 'waiting_approval' || r.status === 'waiting_review' ? 'waiting for you'
: RUN_STATUS_WORDS[r.status] ?? r.status.replace('_', ' ');
/** One short status for a run row: dot + word (UI-SIMPLIFY 3.1). */
export const rowWords = (r: Pick<RunSummary, 'status' | 'pending_gate'>, decision?: string | null, mine = true) =>
isWaiting(r) && !mine ? waitingForWords(r.pending_gate)
: r.pending_gate === 'approve_cases' ? 'Needs your approval' : r.pending_gate === 'human_review' ? 'Needs your decision'
: r.status === 'queued' ? 'Starting' : r.status === 'running' ? 'Testing'
: r.status === 'completed' ? (decision ? decisionWords(decision) : 'Finished')
: r.status === 'interrupted' ? 'Paused' : r.status === 'cancelled' ? 'Cancelled' : 'Stopped';
/** A test run in the sidebar, like a conversation: state dot, business area, when, where, and what it needs from you. */
export function RunListItem({ run, active, compact = false, envKind }: { run: RunSummary; active: boolean; compact?: boolean; envKind?: EnvKind }) {
const state = runState(run);
const mine = useWaitsOnMe()(run);
const words = runStatusWords(run, mine);
const label = `${runTitle(run)}, ${words}`;
const d = run.decision ?? Object.values(run.decisions ?? {})[0] ?? null;
if (compact) {
return (
<Tooltip label={label} position="right" withArrow>
<Link to={`/runs/${run.run_id}`} className="fpt-runitem" data-compact="true" data-state={state} data-testid={`side-run-${run.run_id}`}
aria-current={active ? 'page' : undefined} aria-label={label}>
<StatusDot state={state} label={words} decorative />
</Link>
</Tooltip>
);
}
void envKind;
return (
<Link to={`/runs/${run.run_id}`} className="fpt-runitem" data-state={state} data-testid={`side-run-${run.run_id}`}
aria-current={active ? 'page' : undefined} aria-label={label} title={label}>
<span className="fpt-runitem-text">
<span className="fpt-runitem-title">{runAreas(run)}</span>
<span className="fpt-runitem-sub">{shortWhen(run.created_at)}<span aria-hidden> · </span>
<span className="fpt-runitem-state" data-state={state}><StatusDot state={state} label={words} decorative size={8} />{rowWords(run, d, mine)}</span>
</span>
</span>
</Link>
);
}