Uebersicht: ein Klick waehlt aus, er waehlt nicht ab. Vorher war alles an und ein Klick blendete eine Art aus -- wer nur Eintritte sehen wollte, musste drei andere einzeln wegklicken. Jetzt zwei Zustaende ohne verstecktes Zusatzzeichen: ein Klick zeigt nur diese Art, ein zweiter auf dieselbe zeigt wieder alle. Austrittsart: "Freiwillig/Unfreiwillig" heisst jetzt "Wunsch Dienstnehmer/Wunsch Dienstgeber". Nur beschriftet, nicht umbenannt -- die gespeicherten Werte stehen seit Juli in Historie, Audit und im Cornerstone-Export, und ein Umbenennen gaebe alten Zeilen eine neue Bedeutung. Organigramm: gewaehlte Sicht, aufgeklappte Knoten und Darstellungsart ueberleben den Weg zu einer Person und zurueck. Der Speicher ist dabei die Quelle und keine Kopie im State: der naheliegende Bau -- im Effekt lesen, in useState schreiben -- ist genau das, wovor react-hooks/set-state-in-effect warnt, und haette bei jedem Aufbau kurz den zugeklappten Baum gezeigt.
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
"use client";
|
|
|
|
import { Printer } from "lucide-react";
|
|
import Link from "next/link";
|
|
import { SegmentedControl } from "@/components/ui/SegmentedControl";
|
|
import { useGemerktesWort } from "./ansicht-merken";
|
|
import { AsOfPicker } from "./AsOfPicker";
|
|
import { EmployeeTree } from "./EmployeeTree";
|
|
import { PositionTree } from "./PositionTree";
|
|
import type { OrgEmployee, OrgUnitNode, OrgVacancy } from "./types";
|
|
|
|
type View = "ma" | "pos";
|
|
|
|
const VIEWS: readonly View[] = ["ma", "pos"] as const;
|
|
|
|
type OrgChartClientProps = {
|
|
employees: OrgEmployee[];
|
|
units: OrgUnitNode[];
|
|
vacancies: OrgVacancy[];
|
|
asOf: string;
|
|
today: string;
|
|
projectedCount: number;
|
|
historyStartsAt: string | null;
|
|
/** Arrived via "Im Organigramm anzeigen" — unfold and centre this person. */
|
|
focusId: string | null;
|
|
};
|
|
|
|
export function OrgChartClient({
|
|
employees,
|
|
units,
|
|
vacancies,
|
|
asOf,
|
|
today,
|
|
projectedCount,
|
|
historyStartsAt,
|
|
focusId,
|
|
}: OrgChartClientProps) {
|
|
// Gemerkt, nicht neu gesetzt: wer aus der Organisationssicht eine Person
|
|
// öffnet, landete beim Zurückgehen wieder auf der Mitarbeitersicht.
|
|
const [view, setView] = useGemerktesWort<View>("alpenwerk.orgchart.sicht", "ma", VIEWS);
|
|
|
|
return (
|
|
<div className="flex flex-col gap-4">
|
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
<SegmentedControl<View>
|
|
value={view}
|
|
onChange={setView}
|
|
options={[
|
|
{ value: "ma", label: "Mitarbeiter" },
|
|
{ value: "pos", label: "Organisation" },
|
|
]}
|
|
/>
|
|
{/* Der Stichtag wandert mit: wer eine vergangene Struktur ansieht,
|
|
druckt sie auch. */}
|
|
<Link
|
|
href={asOf === today ? "/orgchart/print" : `/orgchart/print?asOf=${asOf}`}
|
|
className="inline-flex items-center gap-2 rounded-md border border-border px-3 py-2 text-sm font-semibold text-ink hover:bg-brand-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-500"
|
|
>
|
|
<Printer className="h-4 w-4" />
|
|
Als PDF
|
|
</Link>
|
|
</div>
|
|
|
|
<AsOfPicker asOf={asOf} today={today} projectedCount={projectedCount} historyStartsAt={historyStartsAt} />
|
|
|
|
{view === "ma" && <EmployeeTree employees={employees} focusId={focusId} />}
|
|
{view === "pos" && <PositionTree employees={employees} units={units} vacancies={vacancies} />}
|
|
</div>
|
|
);
|
|
}
|