Download web/src/components/shell/panelTabs.tsx from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/shell/panelTabs.tsx
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/src/components/shell/panelTabs.tsx
-
curl -L -o panelTabs.tsx https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/shell/panelTabs.tsx
10.5 kB
| import { Anchor, Button, CopyButton, Group, Skeleton, Stack, Text, Title } from '@mantine/core'; | |
| import { IconCheck, IconFileReport, IconFileSpreadsheet, IconFileTypePdf, IconLink, IconListNumbers } from '@/components/icons'; | |
| import { useEffect, useState } from 'react'; | |
| import { Link } from 'react-router-dom'; | |
| import { MODULE_NAMES } from '../../domain/agents'; | |
| import { useGate, useReport, useRun, useRunReadiness, useRunScenarios, useScenario } from '../../api/hooks'; | |
| import type { ApproveGate } from '../../api/types'; | |
| import { scriptUrl } from '../../pages/run/RunGuide'; | |
| import { RunScripts } from '../../pages/run/RunData'; | |
| import { OUTCOME, ScenarioBody } from '../../pages/run/ScenarioReview'; | |
| import { decisionSentence } from '../../pages/run/SignOffReport'; | |
| import { AiText, Can, DecisionBadge, ErrorAlert, Prio } from '../common'; | |
| import { CoworkerAvatar } from '../CoworkerAvatar'; | |
| import { coworkerForNode } from '../../domain/coworkers'; | |
| import { EmptyState } from './EmptyState'; | |
| import '../../pages/run/report.css'; | |
| const ORIGIN: Record<string, { label: string; tone: string }> = { | |
| library: { label: 'Library', tone: 'neutral' }, generated: { label: 'New', tone: 'lav' }, ai: { label: 'Written by the AI model', tone: 'lav' }, | |
| }; | |
| /** Panel Report tab: the verdict per business area, the counts, the downloads and the way to the full report. */ | |
| export function ReportSummary({ runId, hideVerdict = false }: { runId: string; hideVerdict?: boolean }) { | |
| const run = useRun(runId); | |
| const done = run.data?.status === 'completed'; | |
| const rep = useReport(runId); | |
| const rd = useRunReadiness(runId); | |
| const stopped = ['failed', 'killed', 'cancelled', 'interrupted'].includes(run.data?.status ?? ''); | |
| if (stopped) { // no coworker is on it any more: say so, never "Scout is on the run now" | |
| return <EmptyState icon={<IconFileReport size={28} />} title="This test run stopped before it finished, so it has no report." | |
| body="The run guide says why it stopped and lets you carry on from where it stopped." | |
| action={<Button component={Link} to={`/runs/${runId}`} size="xs" variant="default">Open the run guide</Button>} />; | |
| } | |
| if (!done) { | |
| const who = coworkerForNode(run.data?.pending_gate === 'approve_cases' ? 'approval_gate' : run.data?.pending_gate === 'human_review' ? 'human_review' : run.data?.current_node); | |
| return <EmptyState icon={<IconFileReport size={28} />} title="The report appears when the test run has finished." | |
| body={who ? `${who.name} is on the run now. The guide shows each step.` : 'The run guide shows each step meanwhile.'} | |
| action={<Button component={Link} to={`/runs/${runId}`} size="xs" variant="default">Open the run guide</Button>} />; | |
| } | |
| const mods = rd.data?.modules ?? []; | |
| const tested = mods.reduce((n, m) => n + m.counts.passed + m.counts.passed_on_retry + m.counts.failing, 0); | |
| const failing = mods.reduce((n, m) => n + m.counts.failing, 0); | |
| const notRun = mods.reduce((n, m) => n + m.counts.not_run, 0); | |
| const defects = mods.reduce((n, m) => n + m.confirmed_defects.length, 0); | |
| const gaps = mods.reduce((n, m) => n + m.steps.filter((s) => s.state === 'gap').length, 0); | |
| const link = typeof window !== 'undefined' ? `${window.location.origin}/runs/${runId}/report` : ''; | |
| const decisions = rep.data?.decisions ?? run.data?.decisions ?? {}; | |
| const writer = coworkerForNode('reporter'); | |
| return ( | |
| <Stack gap="sm" className="rpt-panel"> | |
| <ErrorAlert error={rep.error} /> | |
| {Object.entries(decisions).map(([m, d]) => ( | |
| <div key={m}> | |
| {!hideVerdict && ( | |
| <Group justify="space-between" wrap="nowrap" gap={8}> | |
| <Text fw={600} size="sm">{MODULE_NAMES[m] ?? m}</Text> | |
| <DecisionBadge decision={d} size="sm" /> | |
| </Group> | |
| )} | |
| {!hideVerdict && <Text size="sm" mt={6}>{decisionSentence(d, rep.data?.criteria?.[m] ?? {}, rep.data?.target)}</Text>} | |
| {rep.data?.files?.[m]?.pdf && ( | |
| <Button component="a" href={`/api/runs/${encodeURIComponent(runId)}/report/${m}/pdf`} download variant="default" size="xs" mt={8} | |
| leftSection={<IconFileTypePdf size={13} />} data-testid="panel-pdf-link">Download PDF{Object.keys(decisions).length > 1 ? ` (${m})` : ''}</Button> | |
| )} | |
| </div> | |
| ))} | |
| <dl className="rpt-mini fpt-num"> | |
| <div><dt>Tested</dt><dd>{tested}</dd></div> | |
| <div><dt>Failing</dt><dd>{failing}</dd></div> | |
| <div><dt>Not run</dt><dd>{notRun}</dd></div> | |
| <div><dt>Defects</dt><dd>{defects ? <Link to="/tickets">{defects}</Link> : 0}</dd></div> | |
| <div><dt>Not covered yet</dt><dd>{gaps}</dd></div> | |
| </dl> | |
| {writer && <p className="rpt-writer"><CoworkerAvatar name={writer.name} size={20} /><span><b>{writer.name}</b> wrote this report.</span></p>} | |
| <Group gap={6} wrap="wrap"> | |
| <CopyButton value={link}>{({ copied, copy }) => <Button size="xs" variant="default" onClick={copy} leftSection={copied ? <IconCheck size={13} /> : <IconLink size={13} />}>{copied ? 'Link copied' : 'Share'}</Button>}</CopyButton> | |
| <Button component="a" href={scriptUrl(runId)} download variant="default" size="xs" leftSection={<IconFileSpreadsheet size={13} />} data-testid="panel-results-excel">Download the results (Excel)</Button> | |
| </Group> | |
| <Button component={Link} to={`/runs/${runId}/report`} leftSection={<IconFileReport size={14} />}>{rd.data?.signoff ? 'Open the full report' : 'Open the full report and sign off'}</Button> | |
| </Stack> | |
| ); | |
| } | |
| /** Panel Excel tab: the test script (and, once finished, the results) as Excel; scripts for admins. */ | |
| export function ExcelPanel({ runId, finished }: { runId: string; finished: boolean }) { | |
| return ( | |
| <Stack gap="sm"> | |
| <div className="pw-card rpt-file"> | |
| <Group gap={8} wrap="nowrap" align="flex-start"> | |
| <IconFileSpreadsheet size={22} className="rpt-file-icon" aria-hidden /> | |
| <div className="rpt-file-body"> | |
| <Text fw={600} size="sm">Test script (Excel)</Text> | |
| <Text size="xs" c="dimmed">Every step and the result we expect, with columns for your verdict and comments.</Text> | |
| <Button component="a" href={scriptUrl(runId)} download variant="default" size="xs" mt={8} data-testid="panel-excel-script">Download the test script (Excel)</Button> | |
| </div> | |
| </Group> | |
| </div> | |
| {finished && ( | |
| <div className="pw-card rpt-file"> | |
| <Group gap={8} wrap="nowrap" align="flex-start"> | |
| <IconFileSpreadsheet size={22} className="rpt-file-icon" aria-hidden /> | |
| <div className="rpt-file-body"> | |
| <Text fw={600} size="sm">Results (Excel)</Text> | |
| <Text size="xs" c="dimmed">The same workbook, with the outcome of every scenario in this test run.</Text> | |
| <Button component="a" href={scriptUrl(runId)} download variant="default" size="xs" mt={8}>Download the results (Excel)</Button> | |
| </div> | |
| </Group> | |
| </div> | |
| )} | |
| <Can perm="admin"> | |
| <Text fw={600} size="sm" mt="xs">Automation scripts (admin)</Text> | |
| <RunScripts id={runId} /> | |
| <Anchor component={Link} to={`/runs/${runId}/scripts`} size="sm">Open the Scripts view</Anchor> | |
| </Can> | |
| </Stack> | |
| ); | |
| } | |
| /** Panel Steps tab: one scenario, in the words of the review rows, for the selected `?scenario=`. */ | |
| export function ScenarioSteps({ runId, scenarioId }: { runId?: string; scenarioId: string | null }) { | |
| // The run's full scenario list is large (~250 KB) and slow on a busy machine; the Steps tab must not wait for it. | |
| // Use it when it is already loaded, and otherwise fetch the one selected scenario directly (a few KB). | |
| const sc = useRunScenarios(runId ?? ''); | |
| const gate = useGate(runId ?? '', !!runId); | |
| const inRun = (sc.data?.scenarios ?? []).find((x) => x.id === scenarioId); | |
| const lib = useScenario(scenarioId && !inRun ? scenarioId : null, runId); | |
| const found = inRun ?? lib.data; | |
| const loading = !!scenarioId && !found && !lib.isError; | |
| // a scenario that has not loaded in 10 s gets an error line with Try again (never an endless spinner) | |
| const [slow, setSlow] = useState(false); | |
| useEffect(() => { | |
| setSlow(false); | |
| if (!loading) return; | |
| const t = window.setTimeout(() => setSlow(true), 10_000); | |
| return () => window.clearTimeout(t); | |
| }, [loading, scenarioId]); | |
| const retry = () => { setSlow(false); if (scenarioId && !inRun) void lib.refetch(); }; | |
| if (!scenarioId) return <EmptyState icon={<IconListNumbers size={28} />} title="Pick a scenario to see its steps here" body="Use “Show steps” on a scenario or a screen." />; | |
| const s = found; | |
| if ((loading && slow) || (!loading && !s && lib.isError)) { | |
| return ( | |
| <Stack gap={8} role="alert"> | |
| <Text size="sm">{slow ? 'The scenario is taking too long to load.' : 'The scenario could not be loaded.'}</Text> | |
| <Button size="xs" variant="default" w="fit-content" onClick={retry}>Try again</Button> | |
| </Stack> | |
| ); | |
| } | |
| if (loading) { | |
| return ( | |
| <Stack gap={10} aria-busy="true" aria-label="Loading the scenario"> | |
| <Skeleton height={14} width="40%" radius="xl" /><Skeleton height={18} width="85%" radius="xl" /><Skeleton height={60} radius="md" /> | |
| </Stack> | |
| ); | |
| } | |
| if (!s) return <ErrorAlert error={lib.error ?? new Error(`Scenario ${scenarioId} not found`)} />; | |
| const g = gate.data?.gate === 'approve_cases' ? (gate.data as ApproveGate) : null; | |
| const p = g?.pending.find((x) => x.id === s.id); | |
| const origin = ORIGIN[p?.origin ?? s.origin ?? 'library'] ?? ORIGIN.library; | |
| const out = s.outcome ? OUTCOME[s.outcome] : undefined; | |
| return ( | |
| <Stack gap={8}> | |
| <Text size="xs" c="dimmed">Steps of <span className="fpt-idpill">{s.id}</span></Text> | |
| <Title order={2} className="rpt-h3">{s.title}</Title> | |
| <Group gap={10} wrap="wrap"> | |
| <Prio words={s.priority_words} /> | |
| {origin.tone === 'lav' && origin.label !== 'New' ? <AiText>{origin.label}</AiText> : <span className="fpt-dimtext">{origin.label}</span>} | |
| {out && <span className="fpt-dimtext">In this run: <span className="fpt-statustext" data-tone={out.tone}>{out.label}</span></span>} | |
| </Group> | |
| <ScenarioBody s={s} p={p} /> | |
| </Stack> | |
| ); | |
| } | |