Download web/src/pages/run/RunCases.tsx from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 7.83 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/pages/run/RunCases.tsx
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/src/pages/run/RunCases.tsx
-
curl -L -o RunCases.tsx https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/pages/run/RunCases.tsx
7.83 kB
| import { Alert, Badge, Button, Card, Checkbox, Drawer, Group, Loader, Stack, Table, Text, TextInput, Title } from '@mantine/core'; | |
| import { useEffect, useMemo, useState } from 'react'; | |
| import { useApproveCases, useCaseYaml, useCases, useGate } from '../../api/hooks'; | |
| import type { ApproveGate, PendingCase } from '../../api/types'; | |
| import { Can, Diff, ErrorAlert, Pre } from '../../components/common'; | |
| function CasePreview({ c, onClose }: { c: PendingCase | null; onClose: () => void }) { | |
| const yaml = useCaseYaml(c && c.origin === 'library' ? c.id : null); | |
| return ( | |
| <Drawer opened={!!c} onClose={onClose} position="right" size="xl" title={c ? `${c.id}: ${c.title}` : ''}> | |
| {c && ( | |
| <Stack> | |
| <Group gap={4}><Badge>{c.origin}</Badge><Badge color="gray">{c.priority}</Badge>{c.changed_by_patch && <Badge color="orange">changed by patch</Badge>}</Group> | |
| {c.diff ? (<><Title order={6}>{c.origin === 'generated' ? 'Generated draft YAML' : 'Diff vs library.git HEAD'}</Title>{c.origin === 'generated' ? <Pre maxHeight={600}>{c.diff}</Pre> : <Diff text={c.diff} />}</>) : null} | |
| {c.origin === 'library' && (<><Title order={6}>YAML ({yaml.data?.path ?? c.yaml_path})</Title>{yaml.isLoading ? <Loader size="sm" /> : <Pre maxHeight={600}>{yaml.data?.yaml ?? ''}</Pre>}</>)} | |
| </Stack> | |
| )} | |
| </Drawer> | |
| ); | |
| } | |
| export function RunCases({ id, waiting }: { id: string; waiting: boolean }) { | |
| const gate = useGate(id, waiting); | |
| const cases = useCases(id); | |
| const approve = useApproveCases(id); | |
| const g = waiting && gate.data?.gate === 'approve_cases' ? (gate.data as ApproveGate) : null; | |
| const [sel, setSel] = useState<Set<string>>(new Set()); | |
| const [comments, setComments] = useState<Record<string, string>>({}); | |
| const [preview, setPreview] = useState<PendingCase | null>(null); | |
| const pendingIds = useMemo(() => g?.pending.map((p) => p.id) ?? [], [g]); | |
| useEffect(() => setSel(new Set(pendingIds)), [pendingIds]); | |
| const submit = (approved: string[]) => { | |
| const rejected = pendingIds.filter((i) => !approved.includes(i)); | |
| const cm = Object.fromEntries(Object.entries(comments).filter(([, v]) => v.trim())); | |
| approve.mutate({ approved, rejected, comments: cm }); | |
| }; | |
| return ( | |
| <Stack> | |
| {g && ( | |
| <Card withBorder style={{ borderColor: 'var(--mantine-color-orange-6)' }} aria-label="approval gate"> | |
| <Stack gap="xs"> | |
| <Group justify="space-between" wrap="wrap"> | |
| <Title order={4}>Approval gate: {g.pending.length} case(s) need a decision</Title> | |
| <Text size="sm"> | |
| {g.policy === 'L0' ? 'Every new or changed case needs a person to approve it.' : `Approval level ${g.policy}: some cases were approved automatically because this business area has a proven track record.`} | |
| {g.auto_approved.length ? ` Approved automatically: ${g.auto_approved.join(', ')}.` : ''} Untick a case to skip it in this run. | |
| </Text> | |
| </Group> | |
| <Text size="xs" c="dimmed">Approving library cases rewrites their YAML approval_status line and commits it to library.git under your user. Unselected cases are rejected and deferred.</Text> | |
| <Table.ScrollContainer minWidth={760}> | |
| <Table fz="sm" aria-label="pending cases"> | |
| <Table.Thead><Table.Tr> | |
| <Table.Th><Checkbox aria-label="select all" checked={sel.size === pendingIds.length && pendingIds.length > 0} indeterminate={sel.size > 0 && sel.size < pendingIds.length} | |
| onChange={(e) => setSel(e.currentTarget.checked ? new Set(pendingIds) : new Set())} /></Table.Th> | |
| <Table.Th>Case</Table.Th><Table.Th>Business area</Table.Th><Table.Th>Priority</Table.Th><Table.Th>Origin</Table.Th><Table.Th>Why</Table.Th><Table.Th>Comment</Table.Th><Table.Th /></Table.Tr></Table.Thead> | |
| <Table.Tbody> | |
| {g.pending.map((p) => ( | |
| <Table.Tr key={p.id}> | |
| <Table.Td><Checkbox aria-label={`approve ${p.id}`} checked={sel.has(p.id)} onChange={(e) => { const on = e.currentTarget.checked; setSel((s) => { const n = new Set(s); if (on) n.add(p.id); else n.delete(p.id); return n; }); }} /></Table.Td> | |
| <Table.Td><Text size="sm" fw={600}>{p.id}</Text><Text size="xs" c="dimmed">{p.title}</Text></Table.Td> | |
| <Table.Td>{p.module}</Table.Td><Table.Td>{p.priority}</Table.Td> | |
| <Table.Td><Badge variant="light" color={p.origin === 'generated' ? 'dark' : 'gray'}>{p.origin}</Badge></Table.Td> | |
| <Table.Td>{[p.new_or_changed && 'new/changed', p.changed_by_patch && 'touched by patch', p.origin === 'generated' && 'generated draft'].filter(Boolean).join(', ')}</Table.Td> | |
| <Table.Td><TextInput size="xs" aria-label={`comment ${p.id}`} value={comments[p.id] ?? ''} onChange={(e) => { const v = e.currentTarget.value; setComments((c) => ({ ...c, [p.id]: v })); }} /></Table.Td> | |
| <Table.Td><Button size="compact-xs" variant="subtle" onClick={() => setPreview(p)}>{p.diff || p.origin === 'library' ? 'YAML / diff' : 'view'}</Button></Table.Td> | |
| </Table.Tr> | |
| ))} | |
| </Table.Tbody> | |
| </Table> | |
| </Table.ScrollContainer> | |
| <ErrorAlert error={approve.error} /> | |
| <Can perm="gate.approve_cases" fallback={<Alert color="gray">Your role cannot answer this gate (consultant or admin required).</Alert>}> | |
| <Group> | |
| <Button variant="filled" onClick={() => submit([...sel])} loading={approve.isPending} disabled={approve.isSuccess}>Approve selected ({sel.size})</Button> | |
| <Button variant="light" onClick={() => submit(pendingIds)} loading={approve.isPending} disabled={approve.isSuccess}>Approve all</Button> | |
| <Button color="red" variant="light" onClick={() => submit([])} loading={approve.isPending} disabled={approve.isSuccess}>Reject all</Button> | |
| {approve.isSuccess && <Text c="teal" size="sm" role="status">Answer recorded; the run resumes.</Text>} | |
| </Group> | |
| </Can> | |
| </Stack> | |
| </Card> | |
| )} | |
| <CasePreview c={preview} onClose={() => setPreview(null)} /> | |
| {cases.data && ( | |
| <Card withBorder> | |
| <Title order={2} size="h5">In scope ({cases.data.test_cases.length}) / deferred ({cases.data.deferred.length})</Title> | |
| <Table.ScrollContainer minWidth={640}> | |
| <Table fz="xs" aria-label="cases in scope"> | |
| <Table.Thead><Table.Tr><Table.Th>Case</Table.Th><Table.Th>Priority</Table.Th><Table.Th>Origin</Table.Th><Table.Th>Patch</Table.Th><Table.Th>Map rows</Table.Th></Table.Tr></Table.Thead> | |
| <Table.Tbody> | |
| {cases.data.test_cases.map((c) => <Table.Tr key={c.id}><Table.Td>{c.id} <Text span c="dimmed">{c.title}</Text></Table.Td><Table.Td>{c.priority}</Table.Td><Table.Td>{c.origin}</Table.Td><Table.Td>{c.changed_by_patch ? 'touched' : ''}</Table.Td><Table.Td>{c.map_ids.join(', ')}</Table.Td></Table.Tr>)} | |
| </Table.Tbody> | |
| </Table> | |
| </Table.ScrollContainer> | |
| <Text size="xs" mt="xs">Deferred: {cases.data.deferred.slice(0, 60).map((d) => `${d.id} (${d.reason})`).join('; ')}{cases.data.deferred.length > 60 ? ' ...' : ''}</Text> | |
| {cases.data.approval_log.length > 0 && <Text size="xs" mt="xs">Approval log: {cases.data.approval_log.filter((a) => a.gate === 'approve_cases').length} decision(s) by {[...new Set(cases.data.approval_log.map((a) => a.actor))].join(', ')}</Text>} | |
| </Card> | |
| )} | |
| </Stack> | |
| ); | |
| } | |