File size: 4,331 Bytes
af1bee9
fb43301
5ce1088
 
 
 
 
 
 
af1bee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ce1088
 
af1bee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ce1088
af1bee9
 
 
 
 
 
 
 
 
 
5ce1088
af1bee9
 
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Badge, Card, Loader, Stack, Table, Text, Title } from '@mantine/core';
import { useDataPlan, useScripts } from '../../api/hooks';
import { ErrorAlert } from '../../components/common';

/** A recipe's outputs as "name: value" pairs, not a JSON blob. */
function outputWords(o: unknown): string {
  if (o == null || typeof o !== 'object') return o == null ? '' : String(o);
  return Object.entries(o as Record<string, unknown>).map(([k, v]) => `${k}: ${v == null ? '' : typeof v === 'object' ? JSON.stringify(v) : String(v)}`).join(', ');
}

const DATA_COLOR: Record<string, string> = { found: 'teal', not_found: 'red', seeded: 'dark', seed_refused: 'orange', unsupported: 'gray', skipped: 'gray' };

export function RunData({ id }: { id: string }) {
  const q = useDataPlan(id);
  if (q.isLoading) return <Loader />;
  if (q.error) return <ErrorAlert error={q.error} />;
  const d = q.data!;
  return (
    <Stack>

      <Card withBorder>

        <Title order={2} size="h5">Recipes ({Object.keys(d.data_refs).length})</Title>

        <Text size="xs" c="dimmed">Read-only finds via the egress gate; seeding only with SEED_ALLOWED=1 on a test pod; BIP is a stub.</Text>

        <Table.ScrollContainer minWidth={640}>

          <Table fz="xs" aria-label="data recipes">

            <Table.Thead><Table.Tr><Table.Th>Recipe</Table.Th><Table.Th>Strategy</Table.Th><Table.Th>Status</Table.Th><Table.Th>Outputs</Table.Th><Table.Th>Note</Table.Th></Table.Tr></Table.Thead>

            <Table.Tbody>

              {Object.values(d.data_refs).map((r) => (

                <Table.Tr key={r.recipe_id}><Table.Td>{r.recipe_id}</Table.Td><Table.Td>{r.strategy}</Table.Td>

                  <Table.Td><Badge size="xs" color={DATA_COLOR[r.status] ?? 'gray'}>{r.status.replace(/_/g, ' ')}</Badge></Table.Td>

                  <Table.Td>{outputWords(r.outputs)}</Table.Td><Table.Td>{r.note}</Table.Td></Table.Tr>

              ))}

            </Table.Tbody>

          </Table>

        </Table.ScrollContainer>

      </Card>

      <Card withBorder>

        <Title order={2} size="h5">Case to recipes</Title>

        <Table fz="xs" aria-label="data plan">

          <Table.Tbody>

            {Object.entries(d.data_plan).map(([c, rs]) => <Table.Tr key={c}><Table.Td>{c}</Table.Td><Table.Td>{rs.join(', ') || <Text span c="orange" size="xs">no recipe</Text>}</Table.Td></Table.Tr>)}

          </Table.Tbody>

        </Table>

        {d.gaps.length > 0 && <Text c="orange" size="sm">Gaps: {d.gaps.map((g) => `${g.case_id}/${g.recipe_id}: ${g.reason}`).join('; ')}</Text>}

      </Card>

    </Stack>
  );
}

export function RunScripts({ id }: { id: string }) {
  const q = useScripts(id);
  if (q.isLoading) return <Loader />;
  if (q.error) return <ErrorAlert error={q.error} />;
  const rows = Object.values(q.data ?? {});
  const yn = (v: boolean | null) => (v === null ? 'Not checked' : v ? 'Passed' : 'Failed');
  return (
    <Card withBorder>

      <Title order={2} size="h5">Scripts ({rows.length}): {rows.filter((r) => r.status === 'existing').length} existing, {rows.filter((r) => r.status === 'generated').length} generated drafts</Title>

      <Table.ScrollContainer minWidth={700}>

        <Table fz="xs" aria-label="scripts">

          <Table.Thead><Table.Tr><Table.Th>Case</Table.Th><Table.Th>Status</Table.Th><Table.Th>Path</Table.Th><Table.Th>Lint</Table.Th><Table.Th>Dry-run</Table.Th><Table.Th>Last outcome</Table.Th></Table.Tr></Table.Thead>

          <Table.Tbody>

            {rows.map((s) => (

              <Table.Tr key={s.case_id}><Table.Td>{s.case_id}</Table.Td><Table.Td><Badge size="xs" variant="light" color={s.status === 'existing' ? 'dark' : 'gray'}>{s.status}</Badge></Table.Td>

                <Table.Td style={{ wordBreak: 'break-all' }}>{s.path || s.note}</Table.Td><Table.Td>{yn(s.lint_ok)}</Table.Td><Table.Td>{yn(s.dry_run_ok)}</Table.Td>

                <Table.Td>{s.last_outcome ? <Badge size="xs" variant="light" color={s.last_outcome === 'passed' ? 'teal' : s.last_outcome === 'failed' ? 'red' : 'gray'}>{s.last_outcome.replace(/_/g, ' ')}</Badge> : <Text span size="xs" c="dimmed">Not run yet</Text>}</Table.Td></Table.Tr>

            ))}

          </Table.Tbody>

        </Table>

      </Table.ScrollContainer>

    </Card>
  );
}