import { createEffect, createMemo, createSignal, Show } from 'solid-js'; import type { ScanPlan } from './core/scan-plan'; import { latestAvailableDraft } from './plan-view'; import { projectName } from './scan-display'; import { createSecurityStore, type OperationPort, type SecurityPort } from './gui/store'; import { Operations } from './gui/Operations'; import type { HostUi } from './gui/Findings'; import { RunDetail } from './gui/RunDetail'; import { RunList } from './gui/RunList'; import { ScanComposer } from './gui/ScanComposer'; import { SetupCard, type SetupPort } from './gui/SetupCard'; import { securityStyles } from './security-styles'; export type { OperationPort, SecurityPort } from './gui/store'; export type { SetupInfo, SetupPort } from './gui/SetupCard'; type Composer = { plan?: ScanPlan; edit?: boolean }; const blankComposer: Composer = {}; /** The Desktop panel: layout and routing. State lives in the store; each area is a component. */ export function SecurityPanel(props: { directory: string; port: SecurityPort; operations?: OperationPort; setup?: SetupPort; /** The host's code and Markdown renderers, for findings. Plain text without them. */ ui?: HostUi; /** Fallback refresh interval when events are missed. Defaults to 30 seconds. */ fallbackMs?: number; }) { const store = createSecurityStore({ port: props.port, operations: props.operations, fallbackMs: props.fallbackMs, }); let other: HTMLDetailsElement | undefined; const [selectedId, selectRun] = createSignal(); const [composer, setComposer] = createSignal(); const runs = () => store.catalog.runs; const current = createMemo(() => runs().find((run) => run.runId === selectedId()) ?? runs()[0]); const draft = createMemo(() => latestAvailableDraft(store.catalog, store.now())?.plan); const openComposer = () => composer() ?? (store.loaded() && !runs().length ? blankComposer : undefined); const capabilities = () => props.operations?.capabilities; const showOperations = () => !!props.operations && store.loaded(); // Validations and fixes started from a finding are shown on that finding. const unattached = createMemo(() => store.operations().filter((op) => !op.plan.source)); const attention = () => unattached().some((op) => ['prepared', 'running', 'awaiting_answers'].includes(op.status)); const showOther = () => { if (!other) return; other.open = true; other.scrollIntoView({ block: 'nearest' }); }; // Open on its own only when something there needs the user; otherwise it stays as they left it. createEffect(() => { if (attention() && other) other.open = true; }); const validation = () => props.operations && (capabilities()?.validation ?? true) ? props.operations : undefined; const waiting = () => store.operations().filter((op) => op.status === 'awaiting_answers').length; return (

Security

{projectName(props.directory)} {store.running() ? ` ยท ${store.running()} running` : ''}

{(setup) => void store.refresh()} />}
A policy draft is waiting for your answers.
{(plan) => (
A prepared scan is ready: {plan().repository}
)}
{(state) => ( setComposer(undefined) : undefined} onStarted={(runId) => { selectRun(runId); setComposer(undefined); }} /> )} {(runId) => ( {(run) => ( setComposer({ plan, edit: true })} onReview={(plan) => setComposer({ plan })} /> )} )}
(other = element)} class="gs-section gs-other"> Policy drafts and other activity {unattached().length}
); }