Filter the script library and show customer context across pages

This commit is contained in:
2026-11-18 09:28:11 +01:00
parent f8e5865412
commit 97ef5783c1
7 changed files with 97 additions and 22 deletions
+10
View File
@@ -100,7 +100,17 @@ test('creates and renames a customer, opens its inventory, and hides editing for
await page.getByRole('button', { name: 'Geräte von Nord GmbH anzeigen' }).click();
await expect(page.getByRole('heading', { name: 'Geräte', exact: true })).toBeVisible();
await expect(page.getByRole('combobox', { name: 'Kunde', exact: true })).toHaveValue(customerId);
await expect(page.getByRole('combobox', { name: 'Kunde im Gerätebestand', exact: true })).toHaveValue(customerId);
await expect(page.getByRole('row').filter({ hasText: 'NORD-PC' })).toContainText('Nord GmbH');
const navigation = page.getByRole('navigation', { name: 'Hauptnavigation' });
await navigation.getByRole('link', { name: 'Aufträge', exact: true }).click();
await expect(page.getByRole('combobox', { name: 'Kunde', exact: true })).toHaveValue(customerId);
await navigation.getByRole('link', { name: 'Skripte', exact: true }).click();
await expect(page.getByRole('combobox', { name: 'Kunde', exact: true })).toHaveValue(customerId);
await navigation.getByRole('link', { name: 'Genehmigungen', exact: true }).click();
await expect(page.locator('header').getByText('Nord GmbH')).toBeVisible();
await navigation.getByRole('link', { name: 'Geräte', exact: true }).click();
await expect(page.getByRole('combobox', { name: 'Kunde im Gerätebestand', exact: true })).toHaveValue(customerId);
expect(mutations).toEqual([
{ method: 'POST', path: '/api/v1/tenants', body: { name: 'Nord' } },
{ method: 'PATCH', path: `/api/v1/tenants/${customerId}`, body: { name: 'Nord GmbH' } }
+20 -2
View File
@@ -419,6 +419,10 @@ for (const library of [true, false]) {
test('publishes versions in the library and keeps the earlier script readable', async ({ page }) => {
const revisions = [{ ...script, script_sha256: hash(script.script_utf8) }];
const otherScripts = [
{ ...revisions[0], revision_id: randomUUID(), name: 'Windows Übersicht', interpreter: 'powershell' },
{ ...revisions[0], revision_id: randomUUID(), name: 'Linux Übersicht', interpreter: 'bash' }
];
const writes: string[] = [];
await page.route(origin + '/fixture', (r) =>
r.fulfill({
@@ -434,8 +438,11 @@ test('publishes versions in the library and keeps the earlier script readable',
await page.route(origin + '/api/v1/**', (r) => {
const req = r.request();
const path = '/api/v1/tenants/' + tenantId + '/script-revisions';
expect(new URL(req.url()).pathname).toBe(path);
if (req.method() === 'GET') return r.fulfill({ json: listing(revisions) });
const url = new URL(req.url());
expect(url.pathname).toBe(path);
if (req.method() === 'GET') return r.fulfill({ json: url.searchParams.has('cursor')
? listing(otherScripts)
: { ...listing(revisions), next_cursor: 'second-page' } });
writes.push(path);
expect(req.headers()['x-csrf-token']).toBe(auth.csrf_token);
const body = req.postDataJSON();
@@ -451,6 +458,17 @@ test('publishes versions in the library and keeps the earlier script readable',
return r.fulfill({ json: next });
});
await page.goto(origin + '/fixture');
const library = page.getByRole('region', { name: 'Skriptbibliothek' });
await library.getByLabel('Plattform', { exact: true }).selectOption('windows');
await library.getByRole('searchbox', { name: 'Skriptname' }).fill(' ÜBERSICHT ');
await expect(library.locator('tbody tr')).toHaveCount(1);
await expect(library.locator('tbody tr')).toContainText('Windows Übersicht');
await library.getByLabel('Plattform', { exact: true }).selectOption('linux');
await expect(library.locator('tbody tr')).toContainText('Linux Übersicht');
await library.getByRole('searchbox', { name: 'Skriptname' }).fill('ohne Treffer');
await expect(library.getByText('Keine Skripte passen zu den Filtern.')).toBeVisible();
await library.getByRole('button', { name: 'Filter zurücksetzen' }).click();
await expect(library.locator('tbody tr')).toHaveCount(3);
await page.getByRole('button', { name: script.name, exact: true }).click();
await page.getByRole('button', { name: 'Neue Version', exact: true }).click();
await page.getByLabel('Skriptinhalt').fill('uname -r\n');
+1 -1
View File
@@ -36,7 +36,7 @@ export function ApprovalInbox({ open, ownId }: { ownId: string; open: (tenantId:
{v === 'pending' ? 'Offen' : 'Verlauf'}
</button>)}
</div>
<div className="filters"><label>Kunde<select aria-label="Kunde im Genehmigungseingang" value={customer}
<div className="filters"><label>Kunde im Genehmigungseingang<select aria-label="Kunde im Genehmigungseingang" value={customer}
onChange={e => { setCustomer(e.target.value); setPages([]); }}>
<option value="">Alle berechtigten Kunden</option>
{list.data?.customers.map(c => <option key={c.tenant_id} value={c.tenant_id}>{c.name}</option>)}
+8 -3
View File
@@ -313,7 +313,11 @@ export function Devices({
[query, setQuery] = useState(''),
[status, setStatus] = useState(''),
[history, setHistory] = useState(false);
const [routes, setRoutes] = useState<string[]>([]);
const [trail, setTrail] = useState<{ filter: string; routes: string[] }>({ filter, routes: [] });
const routes = trail.filter === filter ? trail.routes : [];
function setRoutes(next: string[] | ((old: string[]) => string[])) {
setTrail(old => ({ filter, routes: typeof next === 'function' ? next(old.filter === filter ? old.routes : []) : next }));
}
const [customerId, assetId, agentId] = detailPath.split('/');
const target =
customerId && assetId && agentId ? { customer: customerId, asset: assetId, agent: agentId } : null;
@@ -328,6 +332,7 @@ export function Devices({
}, 200);
return () => clearTimeout(timer);
}, [search]);
useEffect(() => setTrail({ filter, routes: [] }), [filter]);
const list = useResource(
async (signal) => {
if (target) return null;
@@ -413,9 +418,9 @@ export function Devices({
/>
</label>
<label>
<span>Kunde</span>
<span>Kunde im Gerätebestand</span>
<select
aria-label="Kunde"
aria-label="Kunde im Gerätebestand"
value={filter}
onChange={(e) => {
setRoutes([]);
+21 -8
View File
@@ -635,22 +635,31 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
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;
const deviceCustomer = route.page === 'geraete' && detailKind && detailTenant && detailId ? detailKind : '';
const fixedCustomer = detailRoute ? detailTenant : deviceCustomer;
const customer = fixedCustomer || selectedCustomer;
const [inboxRevision, refreshInbox] = useState(0);
const pendingCount = usePendingApprovals(true, inboxRevision);
const [fleetFilter, setFleetFilter] = useState('');
const [allDeviceCustomers, setAllDeviceCustomers] = useState(true);
const fleetFilter = allDeviceCustomers ? '' : selectedCustomer;
const [selection, setSelection] = useState<{ customer: string; ids: string[] }>({
customer: '',
ids: []
});
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (fixedCustomer && fixedCustomer !== selectedCustomer && customers.some(c => c.tenant_id === fixedCustomer)) {
setCustomer(fixedCustomer);
setSelection({ customer: '', ids: [] });
}
}, [customers, fixedCustomer, selectedCustomer]);
function switchCustomer(id: string) {
if (id === selectedCustomer && !detailRoute) return;
if (id === selectedCustomer) return;
setSelection({ customer: '', ids: [] });
setCustomer(id);
}
function selectFleetCustomer(id: string) {
setFleetFilter(id);
setAllDeviceCustomers(!id);
setSelection({ customer: '', ids: [] });
if (id) switchCustomer(id);
}
@@ -666,6 +675,7 @@ 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 ?? '';
const canChooseCustomer = !fixedCustomer && route.page !== 'genehmigungen' && customers.length > 0;
function openOperation(tenantId: string, id: string, jobId?: string) {
switchCustomer(tenantId);
go('auftraege', orderDetailRoute(tenantId, id, jobId));
@@ -738,10 +748,10 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
<i aria-hidden="true">/</i>
<b>{pages[route.page]}</b>
</div>
{!['geraete', 'kunden','genehmigungen'].includes(route.page) && !detailRoute && (
{canChooseCustomer ? (
<label className="context">
<span>Kunde</span>
<select aria-label="Kunde" value={customer} onChange={(e) => switchCustomer(e.target.value)}>
<select aria-label="Kunde" title={customerName} value={customer} onChange={(e) => selectFleetCustomer(e.target.value)}>
{customers.map((c) => (
<option value={c.tenant_id} key={c.tenant_id}>
{c.name}
@@ -749,7 +759,10 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
))}
</select>
</label>
)}
) : <div className="context" aria-label={fixedCustomer ? 'Kunde der Detailansicht' : 'Aktiver Kunde'}>
<span>{fixedCustomer ? 'Kunde' : 'Aktiver Kunde'}</span>
<strong>{customerName || (tenants.data ? 'Nicht verfügbar' : 'Wird geladen …')}</strong>
</div>}
</header>
{auth.principal.simulated && (
<aside className="simulation" role="status">
@@ -764,7 +777,7 @@ function Workspace({ auth, logout }: { auth: Session; logout: () => void }) {
{route.page === 'geraete' && (
<Devices
detailPath={route.tab}
auth={scoped ?? auth}
auth={scoped ?? { ...auth, permissions: [] }}
customers={customers}
filter={fleetFilter}
onFilter={selectFleetCustomer}
+33 -6
View File
@@ -2,12 +2,14 @@ import { useState, type FormEvent } from 'react';
import { ApiError, request, tenantPath, type Session } from './api';
import { allowed } from './safety';
import { ErrorBox, errorText, useResource } from './resource';
import { NavIcon } from './navigation';
import {
identityNames,
interpreterNames,
latestRevisions,
loadRevisions,
parseRevision,
scriptPlatform,
type Identity,
type Interpreter,
type Revision,
@@ -109,8 +111,14 @@ export function ScriptLibrary({ tenantId, auth }: { tenantId: string; auth: Sess
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [notice, setNotice] = useState('');
const [search, setSearch] = useState('');
const [platform, setPlatform] = useState('');
const versions = (library.data ?? []).filter((item) => item.name === opened);
const latest = versions[0];
const query = search.trim().normalize('NFC').toLocaleLowerCase('de');
const shown = latestRevisions(library.data ?? []).filter((item) =>
(!platform || scriptPlatform(item.interpreter) === platform) &&
item.name.normalize('NFC').toLocaleLowerCase('de').includes(query));
function edit(existing?: Revision) {
setBase(existing?.version ?? 0);
setDraft(
@@ -240,9 +248,28 @@ export function ScriptLibrary({ tenantId, auth }: { tenantId: string; auth: Sess
</section>
) : (
<section aria-label="Skriptbibliothek" className="fleet">
{!library.data ? (
<div className="filters">
<label className="search-box">
<span>Skriptname</span>
<NavIcon name="suchen"/>
<input type="search" value={search} onChange={e => setSearch(e.target.value)}
maxLength={120} placeholder="Skripte suchen …"/>
</label>
<label><span>Plattform</span>
<select aria-label="Plattform" value={platform} onChange={e => setPlatform(e.target.value)}>
<option value="">Alle Plattformen</option>
<option value="linux">Linux</option>
<option value="windows">Windows</option>
</select>
</label>
{(search || platform) && <button className="quiet" type="button" onClick={() => {
setSearch('');
setPlatform('');
}}>Filter zurücksetzen</button>}
</div>
{!library.data && !library.error ? (
<p className="list-message" role="status">Bibliothek wird geladen …</p>
) : library.data.length ? (
) : shown.length ? (
<div className="table fleet-table script-table">
<table>
<thead>
@@ -254,7 +281,7 @@ export function ScriptLibrary({ tenantId, auth }: { tenantId: string; auth: Sess
</tr>
</thead>
<tbody>
{latestRevisions(library.data).map((item) => (
{shown.map((item) => (
<tr key={item.name}>
<td className="hostname">
<button
@@ -275,9 +302,9 @@ export function ScriptLibrary({ tenantId, auth }: { tenantId: string; auth: Sess
</tbody>
</table>
</div>
) : (
<p className="list-message">Für diesen Kunden sind noch keine Skripte veröffentlicht.</p>
)}
) : !library.error && <p className="list-message">{library.data?.length
? 'Keine Skripte passen zu den Filtern.'
: 'Für diesen Kunden sind noch keine Skripte veröffentlicht.'}</p>}
</section>
)}
</>
+4 -2
View File
@@ -67,7 +67,9 @@ thead th { background:#f7f9f8; color:var(--subtle); font-weight:620; font-size:.
.crumb { display:flex; gap:10px; align-items:center; color:var(--subtle); font-size:.85rem; }
.crumb i { color:#889b94; font-style:normal; } .crumb b { font-weight:600; color:var(--ink); }
.context { display:flex; align-items:center; gap:8px; margin:0; font-size:.84rem; color:var(--subtle); }
.context select { width:auto; max-width:35vw; margin:0; padding:5px 8px; font-size:.86rem; }
.context select,.context strong { width:auto; max-width:min(52vw,24rem); font-size:.86rem; color:var(--ink); }
.context select { margin:0; padding:5px 8px; font-weight:600; }
.context strong { overflow-wrap:anywhere; }
.content { max-width:1800px; margin:0 auto; padding:clamp(20px,3.6vw,52px) clamp(16px,3vw,48px) 50px; }
.page-title { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:12px; margin-bottom:24px; }
.page-title h1 { margin:0; }
@@ -144,7 +146,7 @@ section.fleet { padding:0; overflow:hidden; }
.sidebar nav {grid-area:nav; display:flex; gap:1px; margin:0; padding-bottom:4px; overflow-x:auto;}
.sidebar nav a {display:flex; flex:1; justify-content:center; gap:5px; padding:7px 5px; font-size:.82rem;}
.sidebar nav .nav-icon {width:14px;height:14px;} .sidebar nav a[aria-current=page]::before {display:none;}
.topline {min-height:42px;} .content {padding-top:22px;} .page-title {margin-bottom:14px;}
.topline {min-height:42px;flex-wrap:wrap;gap:6px 12px;} .content {padding-top:22px;} .page-title {margin-bottom:14px;}
.filters {flex-wrap:wrap;gap:8px;padding:12px 14px;align-items:stretch;} .filters label {flex:1 1 110px;} .filters .search-box {flex:1 0 100%;} .filters select {min-width:0;max-width:100%;} .fleet-tabs {padding:0 14px;}
.fleet-table thead {position:absolute;clip:rect(0,0,0,0);width:1px;height:1px;overflow:hidden;}
.fleet-table table,.fleet-table tbody {display:block;} .fleet-table tr {display:grid;position:relative;grid-template-columns:1fr 1fr;gap:8px 14px;padding:15px 16px;border-top:1px solid var(--line);}