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
+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>
)}
</>