File size: 3,447 Bytes
fb62a97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { Tooltip } from '@mantine/core';
import { Link } from 'react-router-dom';
import type { Schemas } from '../../api/client';
import { decisionWords, RUN_STATUS_WORDS } from '../../domain/glossary';
import { runAreas, runTitle, shortWhen } from '../../domain/runName';
import type { EnvKind } from './EnvSwitcher';
import { isWaiting, useWaitsOnMe, waitingForWords } from '../../domain/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.pending_gate === 'sign_in' ? 'waiting for you to sign in to the pod'
      : r.status === 'waiting_approval' || r.status === 'waiting_sign_in' || 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.pending_gate === 'sign_in' ? 'Needs a sign-in'
    : 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>
  );
}