Ein (i) an jeder Kachel der Uebersicht

Beim Darueberfahren, per Tastatur oder Antippen erklaert ein Hinweis, was
die Zahl bedeutet und wie sie sich zusammensetzt. Bei den
Langzeitabwesenden steht ausdruecklich: exklusive Krankenstand --
gewoehnliche Krankenstaende werden nicht erfasst; die eigens erfasste Art
"Langer Krankenstand" ist enthalten.

Das (i) steht neben dem Link der Kachel, nicht darin: sonst oeffnete ein
Klick die Liste, und das overflow-hidden der Kachel schnitte den Hinweis ab.
Ein Test haelt die Texte gegen die Kachelbeschriftungen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-07 14:56:23 +02:00
parent 604ce9cebf
commit 71f6e1dde3
4 changed files with 254 additions and 40 deletions

View File

@@ -2,12 +2,21 @@ import { ChevronRight } from "lucide-react";
import Link from "next/link";
import { Fragment, Suspense } from "react";
import { AnstehendFilter } from "@/components/dashboard/AnstehendFilter";
import { AnstehendListe, type AnstehendEintrag } from "@/components/dashboard/AnstehendListe";
import {
AnstehendListe,
type AnstehendEintrag,
} from "@/components/dashboard/AnstehendListe";
import { DraftsCard } from "@/components/dashboard/DraftsCard";
import { Card, CARD_CLASS, CardTitle } from "@/components/ui/Card";
import { InfoHinweis } from "@/components/ui/InfoHinweis";
import { eventBadgeStyle, eventDotStyle } from "@/lib/colors";
import { istEingeschraenkt, parseArten, parseZeitraum } from "@/lib/dashboard-filter";
import {
istEingeschraenkt,
parseArten,
parseZeitraum,
} from "@/lib/dashboard-filter";
import { loadDashboardData } from "@/lib/dashboard-data";
import { KPI_ERKLAERUNGEN } from "@/lib/kpi-erklaerungen";
import { addDaysIso, fmtName, todayIso } from "@/lib/format";
import { divisionOf } from "@/lib/org";
import { deriveStatusAsOf } from "@/lib/reports";
@@ -29,7 +38,12 @@ const TONE: Record<string, { text: string; bar: string }> = {
};
/** Eine Kennzahl auf der Übersicht. */
type Kachel = { label: string; value: string | number; tone: keyof typeof TONE; href: string };
type Kachel = {
label: string;
value: string | number;
tone: keyof typeof TONE;
href: string;
};
/**
* Wie viele Spalten die Überschrift einer Gruppe überspannt — nach der Zahl
@@ -106,7 +120,9 @@ export default async function DashboardPage({
upcomingReturns,
upcomingNotes,
history,
} = await withUser(userId, (tx) => loadDashboardData(tx, { userId, today, yearStart, ytdBis, bisIso, arten }));
} = await withUser(userId, (tx) =>
loadDashboardData(tx, { userId, today, yearStart, ytdBis, bisIso, arten }),
);
// "Aktiv" means status Aktiv — somebody on Karenz is employed but not
// active, and is counted by its own tile instead. FTE follows the same
// set: Karenz contributes no capacity, so including it would overstate
@@ -115,11 +131,15 @@ export default async function DashboardPage({
// Note this is narrower than DEFAULT_STATUSES in lib/reports (Aktiv +
// Karenz), which still governs what the Berichte page shows when no
// status filter is chosen.
const statusOf = (row: (typeof staffRows)[number]) => deriveStatusAsOf(row, today);
const statusOf = (row: (typeof staffRows)[number]) =>
deriveStatusAsOf(row, today);
const activeStaff = staffRows.filter((row) => statusOf(row) === "Aktiv");
const activeCount = activeStaff.length;
const karenzCount = staffRows.filter((row) => statusOf(row) === "Karenz").length;
const fte = activeStaff.reduce((sum, row) => sum + Number(row.weekly_hours), 0) / 38.5;
const karenzCount = staffRows.filter(
(row) => statusOf(row) === "Karenz",
).length;
const fte =
activeStaff.reduce((sum, row) => sum + Number(row.weekly_hours), 0) / 38.5;
// Der Bereich einer Person steht nicht mehr auf ihr; er ergibt sich aus der
// Einheit ihrer Planstelle und deren Vorfahren. Die Bereichsleitung selbst
@@ -129,7 +149,10 @@ export default async function DashboardPage({
for (const row of activeStaff) {
const division = divisionOf(orgMaps, placements.get(row.id)?.orgUnitId);
if (!division) continue;
headcountByDivision.set(division.id, (headcountByDivision.get(division.id) ?? 0) + 1);
headcountByDivision.set(
division.id,
(headcountByDivision.get(division.id) ?? 0) + 1,
);
}
const divisionBars = orgMaps.unitList
.filter((u) => u.unit_type === "Bereich")
@@ -138,28 +161,28 @@ export default async function DashboardPage({
const maxDivisionCount = Math.max(1, ...divisionBars.map((d) => d.count));
const upcomingAlle: AnstehendEintrag[] = [
...(upcomingHires).map((e) => ({
...upcomingHires.map((e) => ({
id: e.id,
employeeId: e.id,
label: fmtName(e.first_name, e.last_name),
date: e.entry_date,
kind: "hire" as const,
})),
...(upcomingExits).map((e) => ({
...upcomingExits.map((e) => ({
id: e.id,
employeeId: e.id,
label: fmtName(e.first_name, e.last_name),
date: e.exit_date!,
kind: "exit" as const,
})),
...(upcomingReturns).map((e) => ({
...upcomingReturns.map((e) => ({
id: e.id,
employeeId: e.id,
label: fmtName(e.first_name, e.last_name),
date: e.karenz_return_date!,
kind: "return" as const,
})),
...(upcomingNotes).map((n) => ({
...upcomingNotes.map((n) => ({
id: n.id,
employeeId: n.employee_id!,
label: fmtName(n.first_name, n.last_name),
@@ -212,8 +235,18 @@ export default async function DashboardPage({
// Next daraus ein Array, und die Seite scheiterte an `.split(",")`.
href: "/employees?status=Aktiv,Karenz",
},
{ label: "Headcount Aktiv", value: activeCount, tone: "default", href: "/employees?status=Aktiv" },
{ label: "Langzeitabwesende", value: karenzCount, tone: "warning", href: "/employees?status=Karenz" },
{
label: "Headcount Aktiv",
value: activeCount,
tone: "default",
href: "/employees?status=Aktiv",
},
{
label: "Langzeitabwesende",
value: karenzCount,
tone: "warning",
href: "/employees?status=Karenz",
},
// Ohne Zeitgrenze — anders als die Karte „Anstehend" darunter, die nur
// den eingestellten Vorschauzeitraum zeigt. Ein Eintritt in vier
// Monaten ist vereinbart und zählt, auch wenn er dort nicht auftaucht.
@@ -223,7 +256,12 @@ export default async function DashboardPage({
tone: "info",
href: "/employees?status=Geplant",
},
{ label: "Aktive FTE", value: fte.toFixed(1), tone: "default", href: "/reports?mode=snapshot&measure=fte&status=Aktiv" },
{
label: "Aktive FTE",
value: fte.toFixed(1),
tone: "default",
href: "/reports?mode=snapshot&measure=fte&status=Aktiv",
},
],
},
{
@@ -248,7 +286,14 @@ export default async function DashboardPage({
},
{
titel: "Recruiting & Vakanzen",
kacheln: [{ label: "Offene Positionen", value: openPositions.length, tone: "brand", href: "/positions" }],
kacheln: [
{
label: "Offene Positionen",
value: openPositions.length,
tone: "brand",
href: "/positions",
},
],
},
];
@@ -290,13 +335,20 @@ export default async function DashboardPage({
{gruppe.titel}
</h2>
{gruppe.kacheln.map((kpi) => (
<Link
key={kpi.label}
href={kpi.href}
className={`${CARD_CLASS} group relative overflow-hidden p-4 pl-5 transition-shadow xl:[grid-row:2] hover:shadow-[var(--shadow-card-hover)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-500`}
>
<span className={`absolute inset-y-0 left-0 w-1 ${TONE[kpi.tone].bar}`} aria-hidden />
{/* Number first in the visual order: it is what the eye is
// Die Zelle trägt Kachel und (i) nebeneinander: das (i) liegt
// über der Kachel, gehört aber nicht zum Link — sonst öffnete
// ein Klick darauf die Liste, und der Tooltip würde vom
// overflow-hidden der Kachel abgeschnitten.
<div key={kpi.label} className="relative xl:[grid-row:2]">
<Link
href={kpi.href}
className={`${CARD_CLASS} group relative flex h-full flex-col overflow-hidden p-4 pl-5 pr-7 transition-shadow hover:shadow-[var(--shadow-card-hover)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-500`}
>
<span
className={`absolute inset-y-0 left-0 w-1 ${TONE[kpi.tone].bar}`}
aria-hidden
/>
{/* Number first in the visual order: it is what the eye is
looking for, and the label only qualifies it.
Kleiner, sobald alle acht in einer Reihe stehen: dort
@@ -305,14 +357,27 @@ export default async function DashboardPage({
ist. Die Kachel hat `overflow-hidden` — die Zahl wäre also
nicht zu breit, sondern abgeschnitten, und eine
abgeschnittene Kennzahl ist schlimmer als eine kleine. */}
<div className={`text-3xl font-extrabold leading-none tabular-nums xl:text-2xl ${TONE[kpi.tone].text}`}>
{kpi.value}
</div>
<div className="mt-1.5 flex items-center gap-1 text-xs font-semibold leading-tight text-ink-muted">
{kpi.label}
<ChevronRight className="h-3 w-3 shrink-0 opacity-0 transition-opacity group-hover:opacity-100" aria-hidden />
</div>
</Link>
<div
className={`text-3xl font-extrabold leading-none tabular-nums xl:text-2xl ${TONE[kpi.tone].text}`}
>
{kpi.value}
</div>
<div className="mt-1.5 flex items-center gap-1 text-xs font-semibold leading-tight text-ink-muted">
{kpi.label}
<ChevronRight
className="h-3 w-3 shrink-0 opacity-0 transition-opacity group-hover:opacity-100"
aria-hidden
/>
</div>
</Link>
{KPI_ERKLAERUNGEN[kpi.label] && (
<InfoHinweis
label={kpi.label}
text={KPI_ERKLAERUNGEN[kpi.label]}
className="absolute right-1.5 top-1.5"
/>
)}
</div>
))}
</Fragment>
))}
@@ -328,19 +393,25 @@ export default async function DashboardPage({
<div key={d.name}>
<div className="mb-1 flex justify-between text-xs">
<span className="text-ink-body">{d.name}</span>
<span className="font-semibold tabular-nums text-ink">{d.count}</span>
<span className="font-semibold tabular-nums text-ink">
{d.count}
</span>
</div>
{/* Rounded ends and a minimum width so the smallest division
still reads as a bar rather than a stray pixel. */}
<div className="h-1.5 overflow-hidden rounded-full bg-surface">
<div
className="h-full rounded-full bg-brand-500"
style={{ width: `${Math.max(2, (d.count / maxDivisionCount) * 100)}%` }}
style={{
width: `${Math.max(2, (d.count / maxDivisionCount) * 100)}%`,
}}
/>
</div>
</div>
))}
{divisionBars.length === 0 && <p className="text-sm text-ink-muted">Keine Daten vorhanden.</p>}
{divisionBars.length === 0 && (
<p className="text-sm text-ink-muted">Keine Daten vorhanden.</p>
)}
</div>
</Card>
@@ -365,11 +436,14 @@ export default async function DashboardPage({
<Card>
<CardTitle className="mb-1">Letzte Aktivitäten</CardTitle>
<ul className="flex flex-col divide-y divide-border-subtle">
{(history).map((h) => (
{history.map((h) => (
<li key={h.id} className="flex gap-2.5 py-2.5">
{/* Dot aligned to the first line of text, not centred on the
whole row, so it stays put as descriptions wrap. */}
<span className={`mt-1.5 h-2 w-2 shrink-0 rounded-full ${eventDotStyle(h.event_type)}`} aria-hidden />
<span
className={`mt-1.5 h-2 w-2 shrink-0 rounded-full ${eventDotStyle(h.event_type)}`}
aria-hidden
/>
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
{/* Der Name führt in die Akte. Ohne den Link war die Karte
@@ -384,17 +458,27 @@ export default async function DashboardPage({
{fmtName(h.first_name, h.last_name)}
</Link>
) : (
<span className="text-sm font-semibold text-ink">Unbekannt</span>
<span className="text-sm font-semibold text-ink">
Unbekannt
</span>
)}
<span className={`rounded-full px-2 py-0.5 text-[11px] font-semibold ${eventBadgeStyle(h.event_type)}`}>
<span
className={`rounded-full px-2 py-0.5 text-[11px] font-semibold ${eventBadgeStyle(h.event_type)}`}
>
{h.event_type}
</span>
</div>
<p className="mt-0.5 text-xs leading-relaxed text-ink-muted">{h.description}</p>
<p className="mt-0.5 text-xs leading-relaxed text-ink-muted">
{h.description}
</p>
</div>
</li>
))}
{(history).length === 0 && <p className="py-2 text-sm text-ink-muted">Keine Aktivitäten vorhanden.</p>}
{history.length === 0 && (
<p className="py-2 text-sm text-ink-muted">
Keine Aktivitäten vorhanden.
</p>
)}
</ul>
</Card>
</div>

View File

@@ -0,0 +1,48 @@
"use client";
import { Info } from "lucide-react";
import { useId } from "react";
// Ein (i), das beim Darüberfahren erklärt, was eine Zahl bedeutet.
//
// Ein Knopf und kein blosses Symbol: so erreicht man die Erklärung auch mit
// der Tastatur und durch Antippen, nicht nur mit der Maus. Der Text hängt per
// aria-describedby am Knopf und wird damit auch vorgelesen.
//
// Er steht **neben** einer Kachel, nicht in ihr: die Kacheln sind Links mit
// `overflow-hidden`, und ein Tooltip darin würde abgeschnitten — und ein
// Klick aufs (i) öffnete statt der Erklärung die verlinkte Liste.
export function InfoHinweis({
text,
label,
className = "",
}: {
text: string;
label: string;
className?: string;
}) {
const id = useId();
return (
<span className={`group/info ${className}`}>
<button
type="button"
aria-label={`Was bedeutet „${label}“?`}
aria-describedby={id}
className="flex h-5 w-5 items-center justify-center rounded-full text-ink-muted hover:text-ink
focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-brand-500"
>
<Info className="h-3.5 w-3.5" aria-hidden />
</button>
<span
id={id}
role="tooltip"
className="pointer-events-none invisible absolute right-0 top-7 z-30 w-64 rounded border border-border bg-white p-3
text-left text-xs font-normal leading-snug text-ink-body opacity-0 shadow-lg transition-opacity
group-hover/info:visible group-hover/info:opacity-100
group-focus-within/info:visible group-focus-within/info:opacity-100"
>
{text}
</span>
</span>
);
}

41
lib/kpi-erklaerungen.ts Normal file
View File

@@ -0,0 +1,41 @@
// Was die Kacheln der Übersicht bedeuten und wie sie sich zusammensetzen —
// der Text hinter dem (i) an jeder Kachel.
//
// Geschrieben für die Personalabteilung, nicht für die Entwicklung: was
// zählt, was nicht, und zu welchem Stichtag. Jede Aussage hier folgt der
// Rechnung in app/(app)/page.tsx und lib/dashboard-data.ts; ändert sich die
// Rechnung, ändert sich der Text mit. tests/unit/kpi-erklaerungen.test.ts
// prüft, dass zu jeder Kachel ein Text da ist.
//
// „Langzeitabwesende" sagt ausdrücklich, dass gewöhnlicher Krankenstand nicht
// darin steckt (er wird in Alpenwerk gar nicht erfasst) — der lange
// Krankenstand als eigene Abwesenheitsart aber schon. So entschieden von der
// Personalabteilung am 07.10.2026: die Zahl bleibt, der Text sagt, was sie ist.
export const KPI_ERKLAERUNGEN: Record<string, string> = {
"Headcount Aktives Dienstverhältnis":
"Alle Personen, mit denen heute ein Dienstverhältnis besteht: Headcount Aktiv plus Langzeitabwesende. " +
"Nicht enthalten: geplante Eintritte (noch nicht begonnen) und Ausgetretene. Jede Person zählt einmal, unabhängig von den Stunden.",
"Headcount Aktiv":
"Personen, die heute im Dienst sind (Status Aktiv). Nicht enthalten: Langzeitabwesende, geplante Eintritte und Ausgetretene. " +
"Jede Person zählt einmal, Teilzeit wie Vollzeit.",
Langzeitabwesende:
"Personen mit laufendem Dienstverhältnis, die heute langzeitabwesend sind — z. B. Karenz, Mutterschutz, Papamonat, " +
"Bildungskarenz, Präsenz- oder Zivildienst, Pflegekarenz, Sabbatical. Exklusive Krankenstand: gewöhnliche Krankenstände " +
"werden in Alpenwerk nicht erfasst und zählen hier nicht. Enthalten ist nur die eigens erfasste Abwesenheitsart „Langer Krankenstand“.",
"Geplante Eintritte":
"Erfasste Einstellungen mit Eintrittsdatum nach heute, ohne zeitliche Grenze. " +
"Sie zählen erst ab dem Eintrittstag zum Headcount.",
"Aktive FTE":
"Vollzeitäquivalente der Personen im Headcount Aktiv: Summe ihrer Wochenstunden geteilt durch 38,5. " +
"Eine Vollzeitkraft zählt 1,0, eine Teilzeitkraft mit 19,25 Stunden 0,5. Langzeitabwesende zählen nicht.",
"Eintritte (YTD)":
"Eintritte und Wiedereintritte vom 1. Jänner bis heute (YTD = year to date). " +
"Eintritte, die erst nach heute beginnen, zählen noch nicht.",
"Austritte (YTD)":
"Austritte mit Austrittsdatum vom 1. Jänner bis heute (YTD = year to date), einschliesslich „Nicht angetreten“. " +
"Vorgemerkte Austritte nach heute zählen noch nicht.",
"Offene Positionen":
"Planstellen, die heute gültig und mit niemandem besetzt sind. " +
"Eine Planstelle mit erfasstem, künftigem Eintritt gilt als besetzt.",
};

View File

@@ -0,0 +1,41 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { KPI_ERKLAERUNGEN } from "@/lib/kpi-erklaerungen";
// Zu jeder Kachel der Übersicht gehört eine Erklärung hinter dem (i). Die
// Schlüssel sind die Beschriftungen der Kacheln; wird eine Kachel umbenannt,
// verlöre sie ihr (i) still — deshalb wird hier gegen die Seite geprüft.
const SEITE = readFileSync(join(process.cwd(), "app/(app)/page.tsx"), "utf8");
const kachelBeschriftungen = [...SEITE.matchAll(/label: "([^"]+)"/g)].map((m) => m[1]);
describe("Die Erklärungen der Kacheln", () => {
it("gibt es zu jeder Kachel", () => {
expect(kachelBeschriftungen.length).toBeGreaterThanOrEqual(8);
for (const label of kachelBeschriftungen) {
expect(KPI_ERKLAERUNGEN[label], `Zur Kachel „${label}“ fehlt die Erklärung`).toBeTruthy();
}
});
it("gibt es nur zu Kacheln, die es gibt", () => {
for (const label of Object.keys(KPI_ERKLAERUNGEN)) {
expect(kachelBeschriftungen, `„${label}“ ist keine Kachel`).toContain(label);
}
});
it("sagen bei den Langzeitabwesenden, dass Krankenstand nicht dazugehört", () => {
expect(KPI_ERKLAERUNGEN.Langzeitabwesende).toMatch(/Exklusive Krankenstand/);
// … und ehrlich, was doch dazugehört: die eigens erfasste Art.
expect(KPI_ERKLAERUNGEN.Langzeitabwesende).toMatch(/Langer Krankenstand/);
});
it("nennen die Rechnung der FTE", () => {
expect(KPI_ERKLAERUNGEN["Aktive FTE"]).toMatch(/38,5/);
});
it("sagen bei YTD, dass bis heute gezählt wird", () => {
expect(KPI_ERKLAERUNGEN["Eintritte (YTD)"]).toMatch(/bis heute/);
expect(KPI_ERKLAERUNGEN["Austritte (YTD)"]).toMatch(/bis heute/);
});
});