Berichte: Mehrfachauswahl in allen Kriterien
Jedes Auswahlkriterium der Berichte nimmt mehrere Werte: die weiteren Kriterien, Organisationseinheit, Standort, Kostenstelle, Ereignistyp und dessen Untertypen. Mehrere Werte eines Kriteriums verbinden sich mit "oder", verschiedene Kriterien mit "und". In der Adresszeile trennt "|", weil ein Wert des Personenkreises selbst ein Komma enthaelt; ein einzelner Wert liest sich wie bisher, gespeicherte Berichte gelten unveraendert. Ein Untertyp schraenkt nur seinen eigenen Ereignistyp ein. Exporte und Zielsystem-Dateien uebernehmen dieselbe Auswahl. Geprueft: lint, tsc, types:check, 955 Tests, Waechter.
This commit is contained in:
@@ -6,7 +6,8 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { deleteReport, saveReport } from "@/actions/reports";
|
||||
import { Button, LINK_BUTTON_CLASS } from "@/components/ui/Button";
|
||||
import { CONTROL_CLASS, DateField, SelectField, TextField } from "@/components/ui/Field";
|
||||
import { DateField, SelectField, TextField } from "@/components/ui/Field";
|
||||
import { MehrfachAuswahl } from "@/components/ui/MehrfachAuswahl";
|
||||
import { Modal } from "@/components/ui/Modal";
|
||||
import { useToast } from "@/components/ui/Toast";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
@@ -19,10 +20,11 @@ import {
|
||||
ZEITRAUM_KRITERIEN,
|
||||
type Criteria,
|
||||
} from "@/lib/report-criteria";
|
||||
import { werteListe, werteParameter } from "@/lib/werteliste";
|
||||
import {
|
||||
AVERAGE_MEASURES,
|
||||
EIN_UND_AUSTRITT,
|
||||
ereignisFilterLabel,
|
||||
ereignisTypenLabel,
|
||||
EVENT_DATE_OPEN,
|
||||
EVENT_GROUP_LABELS,
|
||||
EREIGNIS_AUSWAHL,
|
||||
@@ -103,9 +105,10 @@ type EventsProps = CommonProps & {
|
||||
mode: "events";
|
||||
eventGroup: EventGroupDimension;
|
||||
eventSplit: EventGroupDimension | "";
|
||||
eventType: string;
|
||||
/** Beendigungsart bzw. Art der Langzeitabwesenheit; leer heisst „alle". */
|
||||
eventSubtype: string;
|
||||
/** Gewählte Ereignistypen; leer heisst „alle". */
|
||||
eventTypes: EreignisFilter[];
|
||||
/** Beendigungsarten bzw. Arten der Langzeitabwesenheit; leer heisst „alle". */
|
||||
eventSubtypes: string[];
|
||||
eventFilters: { division: string; location: string; from: string; to: string };
|
||||
};
|
||||
|
||||
@@ -159,20 +162,14 @@ function KriterienBlock({
|
||||
{offen && (
|
||||
<div className="mt-3 flex flex-col gap-2">
|
||||
{AUSWAHL_KRITERIEN.map((k) => (
|
||||
<select
|
||||
<MehrfachAuswahl
|
||||
key={k.key}
|
||||
aria-label={`Nach ${k.label} filtern`}
|
||||
value={criteria.auswahl[k.key] ?? ""}
|
||||
onChange={(e) => onChange({ [k.key]: e.target.value || undefined })}
|
||||
className={CONTROL_CLASS}
|
||||
>
|
||||
<option value="">{k.alle}</option>
|
||||
{k.optionen.map((o) => (
|
||||
<option key={o.wert} value={o.wert}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
ariaLabel={`Nach ${k.label} filtern`}
|
||||
alle={k.alle}
|
||||
optionen={k.optionen}
|
||||
werte={criteria.auswahl[k.key] ?? []}
|
||||
onChange={(werte) => onChange({ [k.key]: werteParameter(werte) })}
|
||||
/>
|
||||
))}
|
||||
|
||||
<fieldset className="rounded border border-border px-3 py-2">
|
||||
@@ -406,15 +403,22 @@ export function ReportsPageClient(props: ReportsPageClientProps) {
|
||||
const statusExportLabel = selectedStatuses.length === STATUS_OPTIONS.length ? "Alle" : selectedStatuses.join(", ");
|
||||
// Einheit und Standort stehen in der Adresszeile als Kennung; auf der Karte
|
||||
// hilft nur der Name.
|
||||
const einheitName = mode === "snapshot" ? units.find((u) => u.id === props.filters.division)?.name : undefined;
|
||||
const standortName = mode === "snapshot" ? locations.find((l) => l.id === props.filters.location)?.name : undefined;
|
||||
const namenVon = (liste: readonly { id: string; name: string }[], roh: string) =>
|
||||
werteListe(roh).map((id) => liste.find((x) => x.id === id)?.name ?? id);
|
||||
const einheitNamen = mode === "snapshot" ? namenVon(units, props.filters.division) : [];
|
||||
const standortNamen = mode === "snapshot" ? namenVon(locations, props.filters.location) : [];
|
||||
const kostenstellenNamen =
|
||||
mode === "snapshot"
|
||||
? namenVon(props.kostenstellen.map((k) => ({ id: k.id, name: `${k.code} · ${k.name}` })), props.filters.kostenstelle)
|
||||
: [];
|
||||
const auswahlTexte =
|
||||
mode === "snapshot"
|
||||
? [
|
||||
`Stichtag ${fmtDate(props.asOf || todayIso())}`,
|
||||
`Status ${statusExportLabel}`,
|
||||
...(einheitName ? [`Einheit ${einheitName}`] : []),
|
||||
...(standortName ? [`Standort ${standortName}`] : []),
|
||||
...(einheitNamen.length ? [`Einheit ${einheitNamen.join(" oder ")}`] : []),
|
||||
...(standortNamen.length ? [`Standort ${standortNamen.join(" oder ")}`] : []),
|
||||
...(kostenstellenNamen.length ? [`Kostenstelle ${kostenstellenNamen.join(" oder ")}`] : []),
|
||||
...beschreibeKriterien(props.criteria),
|
||||
]
|
||||
: [];
|
||||
@@ -425,7 +429,7 @@ export function ReportsPageClient(props: ReportsPageClientProps) {
|
||||
const heading =
|
||||
mode === "snapshot"
|
||||
? `${messgroesseLabel(props.measure, selectedStatuses)} nach ${GROUP_LABELS[props.group]}`
|
||||
: `${props.eventType ? ereignisFilterLabel(props.eventType as EreignisFilter) : "Ereignisse"} nach ${EVENT_GROUP_LABELS[props.eventGroup]}`;
|
||||
: `${ereignisTypenLabel(props.eventTypes)} nach ${EVENT_GROUP_LABELS[props.eventGroup]}`;
|
||||
const totalDisplay = mode === "snapshot" ? formatValue(props.measure, total) : String(Math.round(total));
|
||||
|
||||
return (
|
||||
@@ -509,42 +513,57 @@ export function ReportsPageClient(props: ReportsPageClientProps) {
|
||||
) : (
|
||||
<div className="rounded border border-border bg-white p-4">
|
||||
<div className="flex flex-col gap-3">
|
||||
<SelectField
|
||||
label="Ereignistyp"
|
||||
dense
|
||||
value={props.eventType}
|
||||
// Der Untertyp gehört zum Ereignistyp und fällt mit ihm weg.
|
||||
// Bliebe er in der Adresse stehen, filterte eine Auswahl
|
||||
// weiter, die auf dem Bildschirm nicht mehr zu sehen ist.
|
||||
onChange={(v) => updateParams({ eventType: v || undefined, eventSubtype: undefined })}
|
||||
options={[
|
||||
{ value: "", label: "Alle Ereignistypen" },
|
||||
// Eintritte und Austritte zusammen, gleich nach „Alle": ein
|
||||
// Filter über zwei Typen, kein eigenes Ereignis.
|
||||
{ value: EIN_UND_AUSTRITT, label: EIN_UND_AUSTRITT },
|
||||
...EVENT_TYPES.map((t) => ({ value: t, label: EVENT_TYPE_LABELS[t] })),
|
||||
]}
|
||||
/>
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-xs font-semibold uppercase tracking-wide text-ink-muted">Ereignistyp</span>
|
||||
<MehrfachAuswahl
|
||||
ariaLabel="Ereignistyp"
|
||||
alle="Alle Ereignistypen"
|
||||
optionen={[
|
||||
// Eintritte und Austritte zusammen, gleich am Anfang: ein
|
||||
// Filter über zwei Typen, kein eigenes Ereignis.
|
||||
{ wert: EIN_UND_AUSTRITT, label: EIN_UND_AUSTRITT },
|
||||
...EVENT_TYPES.map((t) => ({ wert: t, label: EVENT_TYPE_LABELS[t] })),
|
||||
]}
|
||||
werte={props.eventTypes}
|
||||
// Ein Untertyp gehört zu seinem Ereignistyp und fällt mit
|
||||
// ihm weg. Bliebe er in der Adresse stehen, filterte eine
|
||||
// Auswahl weiter, die auf dem Bildschirm nicht mehr zu sehen ist.
|
||||
onChange={(typen) => {
|
||||
const erlaubt = new Set(typen.flatMap((t) => untertypOptionen(t as EreignisFilter)));
|
||||
updateParams({
|
||||
eventType: werteParameter(typen),
|
||||
eventSubtype: werteParameter(props.eventSubtypes.filter((s) => erlaubt.has(s))),
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/* Nur dort, wo es einen gibt: eine Versetzung hat keine
|
||||
Beendigungsart, und ein leeres zweites Feld wäre eine Frage
|
||||
ohne Antwortmöglichkeit. */}
|
||||
{(() => {
|
||||
const typ = props.eventType ? (props.eventType as HistoryEventType) : null;
|
||||
const untertyp = typ ? EREIGNIS_UNTERTYP[typ] : undefined;
|
||||
ohne Antwortmöglichkeit. Je gewähltem Typ mit Untertyp ein
|
||||
Feld; alle schreiben in denselben Parameter, die Werte der
|
||||
Typen überschneiden sich nicht. */}
|
||||
{props.eventTypes.map((t) => {
|
||||
const typ = t as HistoryEventType;
|
||||
const untertyp = EREIGNIS_UNTERTYP[typ];
|
||||
if (!untertyp) return null;
|
||||
const eigene = untertypOptionen(typ);
|
||||
return (
|
||||
<SelectField
|
||||
label={untertyp.label}
|
||||
dense
|
||||
value={props.eventSubtype}
|
||||
onChange={(v) => updateParams({ eventSubtype: v || undefined })}
|
||||
options={[
|
||||
{ value: "", label: untertyp.alle },
|
||||
...untertypOptionen(typ).map((o) => ({ value: o, label: o })),
|
||||
]}
|
||||
/>
|
||||
<div key={t} className="flex flex-col gap-1">
|
||||
<span className="text-xs font-semibold uppercase tracking-wide text-ink-muted">{untertyp.label}</span>
|
||||
<MehrfachAuswahl
|
||||
ariaLabel={untertyp.label}
|
||||
alle={untertyp.alle}
|
||||
optionen={eigene.map((o) => ({ wert: o, label: o }))}
|
||||
werte={props.eventSubtypes.filter((s) => eigene.includes(s))}
|
||||
onChange={(neu) =>
|
||||
updateParams({
|
||||
eventSubtype: werteParameter([...props.eventSubtypes.filter((s) => !eigene.includes(s)), ...neu]),
|
||||
})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
})}
|
||||
<SelectField
|
||||
label="Gruppieren nach"
|
||||
dense
|
||||
@@ -610,50 +629,32 @@ export function ReportsPageClient(props: ReportsPageClientProps) {
|
||||
<div className="rounded border border-border bg-white p-4">
|
||||
<h3 className="mb-2 text-xs font-semibold uppercase tracking-wide text-ink-muted">Filter</h3>
|
||||
<div className="flex flex-col gap-2">
|
||||
<select
|
||||
aria-label="Nach Organisationseinheit filtern"
|
||||
value={mode === "snapshot" ? props.filters.division : props.eventFilters.division}
|
||||
onChange={(e) => updateParams({ division: e.target.value })}
|
||||
className={CONTROL_CLASS}
|
||||
>
|
||||
<option value="">Alle Organisationseinheiten</option>
|
||||
{units.map((u) => (
|
||||
// Einrückung mit geschützten Leerzeichen: ein <optgroup> je
|
||||
// Ebene ginge nicht, weil Einheiten dort auswählbar bleiben
|
||||
// müssen — eine Abteilung ist selbst ein Filterwert.
|
||||
<option key={u.id} value={u.id}>
|
||||
{" ".repeat(u.depth)}
|
||||
{u.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
aria-label="Nach Standort filtern"
|
||||
value={mode === "snapshot" ? props.filters.location : props.eventFilters.location}
|
||||
onChange={(e) => updateParams({ location: e.target.value })}
|
||||
className={CONTROL_CLASS}
|
||||
>
|
||||
<option value="">Alle Standorte</option>
|
||||
{locations.map((l) => (
|
||||
<option key={l.id} value={l.id}>
|
||||
{l.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<MehrfachAuswahl
|
||||
ariaLabel="Nach Organisationseinheit filtern"
|
||||
alle="Alle Organisationseinheiten"
|
||||
// Einrückung mit geschützten Leerzeichen: ein <optgroup> je Ebene
|
||||
// ginge nicht, weil Einheiten dort auswählbar bleiben müssen —
|
||||
// eine Abteilung ist selbst ein Filterwert. Der Chip zeigt den
|
||||
// Namen ohne Einrückung.
|
||||
optionen={units.map((u) => ({ wert: u.id, label: `${" ".repeat(u.depth)}${u.name}`, kurz: u.name }))}
|
||||
werte={werteListe(mode === "snapshot" ? props.filters.division : props.eventFilters.division)}
|
||||
onChange={(werte) => updateParams({ division: werteParameter(werte) })}
|
||||
/>
|
||||
<MehrfachAuswahl
|
||||
ariaLabel="Nach Standort filtern"
|
||||
alle="Alle Standorte"
|
||||
optionen={locations.map((l) => ({ wert: l.id, label: l.name }))}
|
||||
werte={werteListe(mode === "snapshot" ? props.filters.location : props.eventFilters.location)}
|
||||
onChange={(werte) => updateParams({ location: werteParameter(werte) })}
|
||||
/>
|
||||
{mode === "snapshot" && (
|
||||
<select
|
||||
aria-label="Nach Kostenstelle filtern"
|
||||
value={props.filters.kostenstelle}
|
||||
onChange={(e) => updateParams({ kostenstelle: e.target.value })}
|
||||
className={CONTROL_CLASS}
|
||||
>
|
||||
<option value="">Alle Kostenstellen</option>
|
||||
{props.kostenstellen.map((k) => (
|
||||
<option key={k.id} value={k.id}>
|
||||
{k.code} · {k.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<MehrfachAuswahl
|
||||
ariaLabel="Nach Kostenstelle filtern"
|
||||
alle="Alle Kostenstellen"
|
||||
optionen={props.kostenstellen.map((k) => ({ wert: k.id, label: `${k.code} · ${k.name}` }))}
|
||||
werte={werteListe(props.filters.kostenstelle)}
|
||||
onChange={(werte) => updateParams({ kostenstelle: werteParameter(werte) })}
|
||||
/>
|
||||
)}
|
||||
{mode === "snapshot" && (
|
||||
<>
|
||||
|
||||
84
components/ui/MehrfachAuswahl.tsx
Normal file
84
components/ui/MehrfachAuswahl.tsx
Normal file
@@ -0,0 +1,84 @@
|
||||
"use client";
|
||||
|
||||
import { X } from "lucide-react";
|
||||
import { CONTROL_CLASS } from "./Field";
|
||||
|
||||
// Mehrfachauswahl für die Filter der Berichte: eine Auswahlliste zum
|
||||
// Hinzufügen, gewählte Werte als Chips zum Entfernen — dieselbe Bedienung
|
||||
// wie die Picklist bei den Titeln, aber mit Wert und Beschriftung getrennt.
|
||||
//
|
||||
// Ohne Auswahl steht die Beschriftung für „keine Einschränkung" in der Liste
|
||||
// („Alle Standorte"). So sieht der leere Filter aus wie vorher die einfache
|
||||
// Auswahl, und niemand muss lernen, dass ein leeres Feld „alle" heisst.
|
||||
|
||||
export type MehrfachOption = {
|
||||
wert: string;
|
||||
label: string;
|
||||
/** Kürzere Beschriftung für den Chip, etwa ohne Einrückung. */
|
||||
kurz?: string;
|
||||
};
|
||||
|
||||
export function MehrfachAuswahl({
|
||||
optionen,
|
||||
werte,
|
||||
onChange,
|
||||
alle,
|
||||
ariaLabel,
|
||||
}: {
|
||||
optionen: readonly MehrfachOption[];
|
||||
werte: readonly string[];
|
||||
onChange: (werte: string[]) => void;
|
||||
/** Beschriftung für „keine Einschränkung". */
|
||||
alle: string;
|
||||
ariaLabel: string;
|
||||
}) {
|
||||
const verfuegbar = optionen.filter((o) => !werte.includes(o.wert));
|
||||
const chip = (wert: string) => {
|
||||
const o = optionen.find((x) => x.wert === wert);
|
||||
return o?.kurz ?? o?.label ?? wert;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<select
|
||||
// Nach jeder Wahl zurück auf den Platzhalter, statt den eben
|
||||
// hinzugefügten Wert stehen zu lassen — der steht schon als Chip da.
|
||||
key={werte.join("|")}
|
||||
aria-label={ariaLabel}
|
||||
defaultValue=""
|
||||
onChange={(e) => {
|
||||
if (e.target.value) onChange([...werte, e.target.value]);
|
||||
}}
|
||||
disabled={verfuegbar.length === 0}
|
||||
className={CONTROL_CLASS}
|
||||
>
|
||||
<option value="">{werte.length === 0 ? alle : "Weitere hinzufügen …"}</option>
|
||||
{verfuegbar.map((o) => (
|
||||
<option key={o.wert} value={o.wert}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{werte.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{werte.map((w) => (
|
||||
<span
|
||||
key={w}
|
||||
className="flex items-center gap-1 rounded-full bg-brand-500 px-2.5 py-1 text-xs font-semibold text-white"
|
||||
>
|
||||
{chip(w)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onChange(werte.filter((x) => x !== w))}
|
||||
aria-label={`${chip(w)} entfernen`}
|
||||
className="rounded-full text-white/80 hover:text-white focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-white"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user