import { Anchor, Button, CloseButton, Drawer, Group, Select, Skeleton, Stack, Table, Text, TextInput, UnstyledButton } from '@mantine/core'; import { useMediaQuery } from '@mantine/hooks'; import { IconAdjustments, IconBooks, IconBrain, IconCalendarTime, IconChevronDown, IconChevronRight, IconFileReport, IconPower, IconRobot, IconSearch, IconShieldCheck, IconUpload, IconUsers, IconWand, } from '@/components/icons'; import { useState, type ReactNode } from 'react'; import { useQuery } from '@tanstack/react-query'; import { Link, useParams, useSearchParams } from 'react-router-dom'; import { getJson } from '../../api/client'; import type { Pattern } from '../../api/types'; import { ScenarioBody } from '../run/ScenarioReview'; import { MODULE_NAMES } from '../../domain/agents'; import './library.css'; import { useHistory, usePods, useRuns, useScenario, useScenarioLibrary, useTickets } from '../../api/hooks'; import { Can, ErrorAlert, GlossaryButton, PageHeader, Pager, Prio } from '../../components/common'; import { envKind } from '../../components/shell/EnvSwitcher'; import { ScenarioSteps } from '../../components/shell/panelTabs'; import { decisionWords } from '../../domain/glossary'; import { runTitle, shortWhen } from '../../domain/runName'; import '../setup/admin.css'; const DECISION_TONE: Record = { GO: 'green', 'NO-GO': 'red', HELD: 'amber' }; const MODULES = ['P2P', 'AP', 'O2C', 'R2R', 'A2R', 'EXP', 'HCM', 'P2M', 'PPM', 'SCM', 'SCP', 'CX']; /** A library status in plain words. */ export function libraryStatusWords(status: string): { words: string; tone: string } { const known: Record = { approved: { words: 'Approved', tone: 'green' }, draft: { words: 'Awaiting approval', tone: 'amber' }, active: { words: 'In use', tone: 'green' }, staged: { words: 'Being checked', tone: 'neutral' }, retired: { words: 'No longer used', tone: 'neutral' }, deprecated: { words: 'No longer used', tone: 'neutral' }, }; return known[status] ?? { words: status ? status.charAt(0).toUpperCase() + status.slice(1).replace(/_/g, ' ') : 'Unknown', tone: 'neutral' }; } export function ScenariosLibraryPage() { const [params, setParams] = useSearchParams(); const [module, setModule] = useState(params.get('area')); const [step, setStep] = useState(null); const [priority, setPriority] = useState(null); const [q, setQ] = useState(''); const [offset, setOffset] = useState(0); const wide = useMediaQuery('(min-width: 1280px)'); const open = params.get('scenario'); const setOpen = (id: string | null) => { const p = new URLSearchParams(params); if (id) p.set('scenario', id); else p.delete('scenario'); setParams(p, { replace: true }); }; const limit = 25; const lib = useScenarioLibrary({ module: module ?? undefined, step: step ?? undefined, priority: priority ?? undefined, q: q || undefined, limit, offset }); const reset = () => setOffset(0); const items = lib.data?.items ?? []; const pickArea = (v: string | null) => { setModule(v); setStep(null); reset(); }; const pickStep = (v: string | null) => { setStep(v); reset(); }; // wide screens: a tree of business areas with the chosen area's process steps under it (Testomat's suite tree); // narrower screens: the same choices as two selects above the list const tree = ( ); const areaSelects = ( <> ); const heading = step ?? (module ? MODULE_NAMES[module] ?? module : 'All scenarios'); return ( {lib.data?.total ?? 0} scenario{lib.data?.total === 1 ? '' : 's'}}>
{wide && tree}
{heading} {!wide && areaSelects} } value={q} w={220} onChange={(e) => { setQ(e.currentTarget.value); reset(); }} />