From 14a271f61acbb22626c8474bd4599dcbc7c932d0 Mon Sep 17 00:00:00 2001 From: Kevin Janssen Date: Wed, 18 Nov 2026 09:14:42 +0100 Subject: [PATCH] Make order search, device results and decisions visible in the WebUI --- tests/browser/approval-inbox.spec.ts | 10 ++- tests/browser/order-composer.spec.ts | 9 +++ web/src/approval-inbox.tsx | 7 +- web/src/devices.tsx | 32 +++++--- web/src/main.tsx | 114 +++++++++++++++++++++------ web/src/navigation.tsx | 3 + web/src/order-presentation.tsx | 19 ++++- web/src/style.css | 6 +- 8 files changed, 155 insertions(+), 45 deletions(-) diff --git a/tests/browser/approval-inbox.spec.ts b/tests/browser/approval-inbox.spec.ts index 665cd6f..0e5ebcb 100644 --- a/tests/browser/approval-inbox.spec.ts +++ b/tests/browser/approval-inbox.spec.ts @@ -34,6 +34,7 @@ test('reviews the fixed MCP request, rejects it once and blocks a changed hash', targets:[{...target,hostname:'WERK-LINUX'}], created_at:created, jobs:[], job_count:0, execution_state:null }; const path = '/api/v1/tenants/'+saved.tenant_id; let approval = 'pending_approval', corrupt = false, rights = true; + const decision = { principal: 'Marta', at: created, testsimulation: true }; const decisions: unknown[] = []; const listing = (items: unknown[]) => ({items,next_cursor:null,completeness:'complete',truncated:false,as_of:created}); await page.route(origin+'/auth/config', r => r.fulfill({json:{dev_login_enabled:true,local_login_enabled:false,oidc_configured:false,oidc_login_url:null}})); @@ -44,13 +45,13 @@ test('reviews the fixed MCP request, rejects it once and blocks a changed hash', if (url.pathname === '/api/v1/approvals') { const pending = approval === 'pending_approval'; const visible = rights && !url.searchParams.has('count_only') && (url.searchParams.get('status') === 'pending') === pending; - return route.fulfill({json:{...listing(visible ? [{...summary,approval_state:approval}]:[]), customers:rights?[customer]:[], + return route.fulfill({json:{...listing(visible ? [{...summary,approval_state:approval,decision:pending ? null : decision}]:[]), customers:rights?[customer]:[], can_review:rights,pending_count:rights && pending?1:0}}); } if (url.pathname === path+'/operation-plans/'+saved.plan_id) return route.fulfill({json:{ ...summary, plan_payload:saved, payload:saved, plan_hash:corrupt?'f'.repeat(64):key,plan_payload_bytes:[...Buffer.from(raw)], resolved_targets:[target], excluded_targets:[], jobs:[{...job,...target,job_id:payload.job_id,attempt_id:payload.attempt_id}], - expires_at:expires, approval_state:approval, authorization_status:'required' + expires_at:expires, approval_state:approval, authorization_status:'required', decision:approval === 'rejected' ? decision : null }}); if (url.pathname === path+'/operation-plans/'+saved.plan_id+'/authorizations' && req.method() === 'POST') { decisions.push(req.postDataJSON()); approval='rejected'; @@ -75,7 +76,12 @@ test('reviews the fixed MCP request, rejects it once and blocks a changed hash', await page.getByRole('link',{name:/^Genehmigungen/}).click(); await expect(inbox.getByText('Keine offenen Genehmigungen.')).toBeVisible(); await inbox.getByRole('button',{name:'Verlauf'}).click(); + const entry = inbox.locator('td[data-label="Entschieden von und am"]'); + await expect(entry).toContainText('Marta'); + await expect(entry).toContainText('Simulierter Testentscheid'); + await expect(entry.locator('time')).toHaveAttribute('datetime', created); await inbox.getByRole('button',{name:'Freies Skript'}).click(); + await expect(page.locator('section[data-plan-id] time')).toHaveAttribute('datetime', created); await expect(page.locator('section[data-plan-id] .order-status')).toHaveText('Abgelehnt'); await expect(reject).toHaveCount(0); corrupt=true; approval='pending_approval'; await page.reload(); diff --git a/tests/browser/order-composer.spec.ts b/tests/browser/order-composer.spec.ts index 66f432e..a2c9fce 100644 --- a/tests/browser/order-composer.spec.ts +++ b/tests/browser/order-composer.spec.ts @@ -217,6 +217,15 @@ test('shows the bound script text alongside single and per-device results', asyn await expect(page.getByLabel('stderr Textansicht')).toHaveText('Fehler auf Windows'); await page.getByRole('button', { name: 'Ergebnis schließen für test-windows' }).click(); await expect(page.getByRole('region', { name: 'Gespeichertes Konsolenergebnis' })).toHaveCount(0); + resultReads.clear(); + await openOrder(multiOperationId + '/' + jobs[1]!.job_id); + await expect(page.getByRole('heading', { name: 'Ergebnis für test-windows' })).toBeVisible(); + await expect(page.getByLabel('stderr Textansicht')).toHaveText('Fehler auf Windows'); + expect([...resultReads]).toEqual([jobs[1]!.job_id]); + resultReads.clear(); + await openOrder(multiOperationId + '/' + randomUUID()); + await expect(page.getByRole('alert')).toContainText('gehört nicht zu diesem Auftrag'); + expect(resultReads.size).toBe(0); expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(390); mismatchedPlan = true; await page.reload(); diff --git a/web/src/approval-inbox.tsx b/web/src/approval-inbox.tsx index 16a9c87..63ebf3a 100644 --- a/web/src/approval-inbox.tsx +++ b/web/src/approval-inbox.tsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import { page, record, request, objectId, tenant, type Tenant } from './api'; +import { page, record, request, objectId, tenant } from './api'; import { ErrorBox, useResource } from './resource'; import { OrderRows, PageButtons } from './order-presentation'; @@ -15,7 +15,7 @@ export function usePendingApprovals(enabled: boolean, revision = 0) { }, [enabled, revision], enabled); return resource.error ? null : resource.data; } -export function ApprovalInbox({ open }: { customers?: Tenant[]; open: (tenantId: string, planId: string) => void }) { +export function ApprovalInbox({ open, ownId }: { ownId: string; open: (tenantId: string, planId: string) => void }) { const [view, setView] = useState<'pending'|'history'>('pending'); const [customer, setCustomer] = useState(''); const [pages, setPages] = useState([]); @@ -44,7 +44,8 @@ export function ApprovalInbox({ open }: { customers?: Tenant[]; open: (tenantId: {!list.data && !list.error &&

Anträge werden geladen …

} {list.data && (!!list.data.items.length - ? open(objectId(row,'tenant'), objectId(row,'plan'))}/> + ? open(objectId(row,'tenant'), objectId(row,'plan'))}/> :

{view === 'pending' ? 'Keine offenen Genehmigungen.' : 'Keine abgeschlossenen Anträge.'}

)} {list.data && } ; diff --git a/web/src/devices.tsx b/web/src/devices.tsx index f1c7111..0d8db1f 100644 --- a/web/src/devices.tsx +++ b/web/src/devices.tsx @@ -15,7 +15,8 @@ import { AdminControl } from './management'; import { allowed } from './safety'; import { CatalogCheckNotice } from './catalog-check'; import { ErrorBox, errorText, useResource } from './resource'; -import { NavIcon } from './navigation'; +import { NavIcon, orderDetailRoute } from './navigation'; +import { orderTitle, Status } from './order-presentation'; import { RecoveryReview, recoveryAsset, recoveryTenant } from './recovery-review'; import { EchoProbeReview } from './echo-probe-review'; import { EchoCompletionReview } from './echo-completion-review'; @@ -107,7 +108,7 @@ type Props = { onSelection: (s: Target) => void; onCreateOrder: () => void; onEnroll: () => void; - onOperation: (customer: string, id: string) => void; + onOperation: (customer: string, id: string, jobId: string) => void; }; function devicePath(customer: string, asset: string) { return tenantPath(customer, '/devices/' + encodeURIComponent(asset)); @@ -127,7 +128,7 @@ function DeviceDetail({ agent: string; auth: Session; back: () => void; - openOperation: (id: string) => void; + openOperation: (id: string, jobId: string) => void; changed: () => void; }) { const path = devicePath(customer, asset); @@ -212,14 +213,21 @@ function DeviceDetail({

Keine Aufträge für dieses Gerät.

) : ( )} @@ -352,7 +360,7 @@ export function Devices({ {...target} auth={auth} back={back} - openOperation={(id) => onOperation(target.customer, id)} + openOperation={(id, jobId) => onOperation(target.customer, id, jobId)} changed={() => { back(); setRoutes([]); diff --git a/web/src/main.tsx b/web/src/main.tsx index 16a8016..eb13119 100644 --- a/web/src/main.tsx +++ b/web/src/main.tsx @@ -1,13 +1,13 @@ -import { actionTitle, deviceName, display, Fact, identityName, OrderRows, orderTitle, PageButtons, Requester, Status, statusOf, targets, when } from './order-presentation'; +import { actionTitle, ApprovalDecision, deviceName, display, Fact, identityName, OrderRows, orderTitle, PageButtons, Requester, Status, statusOf, statusText, targets, when } from './order-presentation'; import { Devices } from './devices'; import { CustomerManagement } from './customer-management'; import { ErrorBox, useResource, errorText } from './resource'; -import { NavIcon, type NavKey } from './navigation'; +import { NavIcon, orderDetailRoute, type NavKey } from './navigation'; import { OrderComposer } from './order-composer'; import { ApprovalInbox, usePendingApprovals } from './approval-inbox'; import { ScriptLibrary } from './script-library'; import { McpTokenManagement } from './mcp-token-management'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { createRoot } from 'react-dom/client'; import { actions, Action, ApiError, authConfig, approvalBlockers, expectedStdout, objectId, page, PlanInput, pretty, record, RecordValue, request, session, Session, stringField, tenant, tenantPath, validateInput, windowsPowerShellRemoteSignedProfile, fullMaintenanceScriptProfile } from './api'; import './style.css'; @@ -357,6 +357,9 @@ function PlanDetail({ tenantId, id, auth, onOperation, customerName, mode = 'rev } {data.approval_state ? : 'Vorbereitet'} + {typeof data.approval_state === 'string' && data.approval_state !== 'pending_approval' && + + } {display(saved.reason, 'Kein Anlass angegeben')}

Zielgeräte und Zeitfenster

@@ -393,18 +396,70 @@ function PlanDetail({ tenantId, id, auth, onOperation, customerName, mode = 'rev ; } -function Operations({ tenantId, open, customerName }: { tenantId: string; open: (id: string) => void; customerName?: string }) { +const emptyOrderFilters = { q: '', device: '', status: '', from: '', to: '' }; +type OrderFilters = typeof emptyOrderFilters; +const orderStatuses = ['pending_approval', 'approved', 'queued', 'running', 'succeeded', 'partially_succeeded', + 'failed', 'needs_attention', 'rejected', 'expired', 'revoked', 'cancelled']; +function orderDay(value: string, next = false) { + const date = new Date(value + 'T00:00:00'); + if (next) date.setDate(date.getDate() + 1); + return date.toISOString(); +} +function Operations({ tenantId, open, customerName, filters, apply }: { + tenantId: string; open: (id: string) => void; customerName?: string; + filters: OrderFilters; apply: (filters: OrderFilters) => void; +}) { const [pages, setPages] = useState([]); + const [draft, setDraft] = useState(filters); + const [filterError, setFilterError] = useState(null); const cursor = pages[pages.length - 1]; - const list = useResource(async signal => page(await request(tenantPath(tenantId, - '/operations?sort=recent' + (cursor ? '&cursor=' + encodeURIComponent(cursor) : '')), { signal })), [tenantId, cursor], true); - if (list.error) return ; + const params = new URLSearchParams({sort:'recent', limit:'25'}); + if (cursor) params.set('cursor', cursor); + if (filters.q) params.set('q', filters.q); + if (filters.device) params.set('device', filters.device); + if (filters.status) params.set('status', filters.status); + if (filters.from) params.set('from', orderDay(filters.from)); + if (filters.to) params.set('until', orderDay(filters.to, true)); + const query = params.toString(); + const list = useResource(async signal => page(await request(tenantPath(tenantId, '/operations?' + query), { signal })), [tenantId, query], true); + const filtering = Object.values(filters).some(Boolean); + function reset() { + setDraft(emptyOrderFilters); + setFilterError(null); + setPages([]); + apply(emptyOrderFilters); + } return
+
{ + event.preventDefault(); + if (draft.from && draft.to && draft.from > draft.to) { + setFilterError('Das Enddatum darf nicht vor dem Startdatum liegen.'); + return; + } + setPages([]); + setFilterError(null); + apply({ ...draft, q: draft.q.trim(), device: draft.device.trim() }); + }}> + + + + + +
+ + {(filtering || Object.values(draft).some(Boolean)) && } +
+ + + {!list.data && !list.error &&

Aufträge werden geladen …

} - {list.data && (list.data.items.length + {list.data && !list.error && (list.data.items.length ? open(objectId(row,'operation'))}/> - :

Für diesen Kunden gibt es noch keine Aufträge.

)} - {list.data && } + :

{filtering ? 'Keine Aufträge passen zu den Filtern.' : 'Für diesen Kunden gibt es noch keine Aufträge.'}

)} + {list.data && !list.error && }
; } function OrderScript({ tenantId, operation, names }: { tenantId: string; operation: RecordValue; names: RecordValue[] }) { @@ -449,16 +504,17 @@ function OrderScript({ tenantId, operation, names }: { tenantId: string; operati })} ; } -function OperationDetail({ tenantId, id, auth, openPlan, customerName }: { - tenantId: string; id: string; auth: Session; openPlan: (id: string) => void; customerName?: string +function OperationDetail({ tenantId, id, resultId: linkedResult, auth, openPlan, customerName }: { + tenantId: string; id: string; resultId?: string; auth: Session; openPlan: (id: string) => void; customerName?: string }) { const op = useResource(async signal => record(await request(tenantPath(tenantId, '/operations/' + encodeURIComponent(id)), { signal })), [tenantId, id], true); - const [jobId, setJobId] = useState(null); + const [jobId, setJobId] = useState(linkedResult ?? null); const data = op.error ? null : op.data; if (!data) return
{!op.error &&

Auftrag wird geladen …

}
; const names = targets(data); const jobs = Array.isArray(data.jobs) ? data.jobs.map(j => record(j)) : []; - const singleJob = jobs.length === 1 ? jobs[0] : null; + const resultMissing = !!linkedResult && !jobs.some(job => job.job_id === linkedResult); + const singleJob = jobs.length === 1 && !resultMissing ? jobs[0] : null; const name = (job: RecordValue) => { const target = names.find(t => t.asset_id === job.asset_id && t.agent_id === job.agent_id); return target ? deviceName(target) : display(job.asset_id, 'Gerät unbekannt'); @@ -470,9 +526,10 @@ function OperationDetail({ tenantId, id, auth, openPlan, customerName }: { {display(data.reason, 'Kein Anlass angegeben')}
{singleJob ? + id={objectId(singleJob, 'job')} hostname={name(singleJob)} auth={auth} scrollToResult={!!linkedResult}/> :

Geräte und Ergebnisse

+ {resultMissing &&

Das verlinkte Geräteergebnis gehört nicht zu diesem Auftrag oder ist nicht mehr verfügbar.

} {jobs.length ?
    {jobs.map(job => { const resultId = objectId(job, 'job'); const hostname = name(job); @@ -486,7 +543,8 @@ function OperationDetail({ tenantId, id, auth, openPlan, customerName }: { aria-label={action + ' für ' + hostname} onClick={() => setJobId(expanded ? null : resultId)}>{action}
- {expanded && } + {expanded && } ; })} : <>

{names.map(deviceName).join(', ')}

{data.approval_state === 'pending_approval' @@ -500,13 +558,19 @@ function OperationDetail({ tenantId, id, auth, openPlan, customerName }: { ; } -function JobDetail({ tenantId, id, auth, hostname }: { tenantId: string; id: string; auth: Session; hostname: string }) { +function JobDetail({ tenantId, id, auth, hostname, scrollToResult }: { + tenantId: string; id: string; auth: Session; hostname: string; scrollToResult?: boolean +}) { const job = useResource(async signal => record(await request(tenantPath(tenantId, '/jobs/'+encodeURIComponent(id)), { signal })), [tenantId, id], true); + const result = useRef(null); + useEffect(() => { + if (scrollToResult) result.current?.scrollIntoView({ block:'start' }); + }, [id, scrollToResult]); const [error, setError] = useState(null), [busy, setBusy] = useState(false); const data = job.error ? null : job.data; const state = data?.state; const terminal = ['succeeded','failed','cancelled','expired','unknown','closed_unknown']; - return

Ergebnis für {hostname}

+ return

Ergebnis für {hostname}

{!data && !job.error &&

Ergebnis wird geladen …

} {data && <>} {data && allowed(auth,'jobs:cancel') && !terminal.includes(String(state)) && !data.cancel_requested &&
Abbruch anfordern @@ -567,7 +631,8 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) { ); const customers = tenants.data?.items ?? auth.tenants; const [selectedCustomer, setCustomer] = useState(auth.tenants[0]?.tenant_id ?? ''); - const [detailKind, detailTenant, detailId] = route.tab.split('/'); + const [detailKind, detailTenant, detailId, detailJob] = route.tab.split('/'); + const [orderFilters, setOrderFilters] = useState(emptyOrderFilters); const detailRoute = (route.page === 'genehmigungen' && detailKind === 'pruefen') || (route.page === 'auftraege' && (detailKind === 'ansehen' || detailKind === 'entwurf')); const customer = detailRoute && detailTenant ? detailTenant : selectedCustomer; @@ -601,9 +666,9 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) { // Gate rendering during a tenant change; a previously loaded session is scoped to its own customer. const scoped = current.data?.id === customer ? current.data.auth : null; const customerName = customers.find((c) => c.tenant_id === customer)?.name ?? ''; - function openOperation(tenantId: string, id: string) { + function openOperation(tenantId: string, id: string, jobId?: string) { switchCustomer(tenantId); - go('auftraege', `ansehen/${tenantId}/${id}`); + go('auftraege', orderDetailRoute(tenantId, id, jobId)); } function openReview(tenantId: string, id: string) { switchCustomer(tenantId); @@ -741,7 +806,7 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) { ← Zu den Genehmigungen - : <>

Genehmigungen

+ : <>

Genehmigungen

)} {route.page === 'auftraege' && ( route.tab === 'neu' ? <> @@ -759,13 +824,14 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) { {detailKind === 'entwurf' ? - : openReview(customer,id)} />} : <>

Aufträge

{allowed(scoped, 'operations:plan') && Neuer Auftrag}
- openOperation(customer,id)} /> + openOperation(customer,id)} + filters={orderFilters} apply={setOrderFilters}/> )} {route.page === 'verwaltung' && ( diff --git a/web/src/navigation.tsx b/web/src/navigation.tsx index 1498d0b..479415d 100644 --- a/web/src/navigation.tsx +++ b/web/src/navigation.tsx @@ -1,4 +1,7 @@ export type NavKey = 'geraete' | 'auftraege' | 'genehmigungen' | 'skripte' | 'kunden' | 'verwaltung'; +export function orderDetailRoute(tenantId: string, operationId: string, jobId?: string) { + return ['ansehen', tenantId, operationId, ...(jobId ? [jobId] : [])].map(encodeURIComponent).join('/'); +} const glyphs = { geraete: 'M3 4h18v12H3z M8 20h8 M12 16v4', auftraege: 'M8 5H5v16h14V5h-3 M9 3h6v4H9z M8 12h8 M8 16h5', diff --git a/web/src/order-presentation.tsx b/web/src/order-presentation.tsx index 17e8907..dcb1b2e 100644 --- a/web/src/order-presentation.tsx +++ b/web/src/order-presentation.tsx @@ -39,11 +39,23 @@ export function Requester({ id, ownId }: { id: unknown; ownId?: string }) { export function Status({ value }: { value: unknown }) { return {statusText(value)}; } export function Fact({ label, children }: { label: string; children: ReactNode }) { return
{label}
{children}
; } -export function OrderRows({ items, customerName, decisionList, open }: { - items: RecordValue[]; customerName?: string; decisionList?: boolean; open: (row: RecordValue) => void +export function ApprovalDecision({ order, ownId }: { order: RecordValue; ownId?: string }) { + const decision = order.decision && typeof order.decision === 'object' ? record(order.decision) : null; + if (typeof decision?.principal !== 'string' || typeof decision.at !== 'string') { + return {order.approval_state === 'expired' ? 'Automatisch abgelaufen' : 'Entscheidung nicht belegt'}; + } + return <> + {decision.testsimulation === true && Simulierter Testentscheid} + ; +} + +export function OrderRows({ items, customerName, decisionList, decisionHistory, ownId, open }: { + items: RecordValue[]; customerName?: string; decisionList?: boolean; decisionHistory?: boolean; + ownId?: string; open: (row: RecordValue) => void }) { return
+ {decisionHistory && } {items.map(row => { const all = targets(row); const devices = all.slice(0, 2).map(deviceName).join(', '); @@ -53,8 +65,9 @@ export function OrderRows({ items, customerName, decisionList, open }: { {revision && Version {String(revision.version)}} - + + {decisionHistory && } ; })}
AuftragKundeGeräte{decisionList ? 'Eingereicht von' : 'Erstellt'}StatusEntschieden von und am
{display(row.customer_name, customerName)} {devices || (typeof row.planned_job_count === 'number' ? String(row.planned_job_count) : 'Unbekannt')}{all.length > 2 && ' und '+(all.length-2)+' weitere'}{decisionList ? : when(row.created_at)}{decisionList ? : when(row.created_at)}
; } diff --git a/web/src/style.css b/web/src/style.css index c0c553a..8da939c 100644 --- a/web/src/style.css +++ b/web/src/style.css @@ -117,7 +117,11 @@ section.fleet { padding:0; overflow:hidden; } .job-row { display:flex; align-items:center; gap:10px; flex-wrap:wrap; } .job-row strong { flex:1 1 8rem; } .job-row button { margin:0; } -.job-result { margin-top:22px; border-color:#b9d5c8; background:#f2f8f5; } +.device-job-name { flex:1 1 14rem; min-width:0; } +.job-result { margin-top:22px; scroll-margin-top:16px; border-color:#b9d5c8; background:#f2f8f5; } +.order-filters { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,10rem),1fr)); gap:12px; padding:16px 20px; border-bottom:1px solid var(--line); } +.order-filters label { margin:0; min-width:0; } +.order-filter-actions,.order-filters .error { grid-column:1/-1; } .job-result > h3 { font-size:1.15rem; } .job-result > section { margin:0; padding:0; border:0; background:none; } .job-result > section > p:first-child { margin-top:0; }