Org assignment history, mobile support, and a correctness pass

Data model
- employee_assignments records org placement over time (valid_from/valid_to),
  written by a trigger on `employees` rather than inside each RPC: ~70
  `update employees` statements spread over fifteen migrations mean per-call
  bookkeeping would miss paths today and again with every future RPC. A
  partial unique index enforces the one-open-interval invariant the trigger
  relies on when closing the current row.
- The Organigramm gains a Stichtag (default today). Membership comes from
  entry/exit/karenz, past placement from the new history, future placement
  projected from pending_org_changes. Placements predating the migration are
  backfilled with today's values and flagged as such in the UI, since
  employee_history only ever stored free text and cannot be reconstructed.

Correctness
- Reports and exports silently truncated at PostgREST's 1000-row cap
  (db.max_rows); employee_history is already past it at ~800 staff. Every
  whole-table read now pages explicitly.
- XLSX date cells were a day early: ExcelJS converts a Date to an Excel
  serial straight off getTime(), so a Date built at local midnight lands on
  the previous day's serial in any positive-offset zone.
- Date handling is pinned to Europe/Vienna throughout, and date-only strings
  are formatted without a Date round-trip. The dashboard's YTD window was
  built by round-tripping a local Date through toISOString(), which shifted
  it a day early and dropped 31 December entirely.
- Export routes parsed measure/group/split/eventType with unchecked `as`
  casts, so an unknown value reached column headers as `undefined` and the
  Content-Disposition filename. Parsed against the label maps now, with the
  filename slugged as a backstop.
- toXlsx keyed columns by header text, silently dropping the second of any
  two columns sharing a name — split columns take their header from data.
- The org chart tree walks had no cycle guard; nothing in the schema forbids
  a manager_id cycle, and one would hang the tab rather than misreport.
- The login page reflected ?error= verbatim, letting anyone put arbitrary
  text on the real sign-in screen; messages are looked up by code now.
- React Flow needs elementsSelectable on, or it sets pointer-events:none on
  the whole node and the expand control stops responding.

UI
- Mobile: the shell was unusable below lg — a fixed 236px margin pushed
  content off-screen with no mobile navigation at all. The sidebar is now a
  drawer, dvh replaces vh, safe-area insets are honoured, inputs are 16px so
  iOS stops zooming on focus, and form grids stack.
- Org chart nodes redesigned: per-kind accent stripes and icons, vacant
  roles called out, expand control moved to the bottom edge carrying the
  child count.
- Pagination is windowed; it previously rendered one link per page (54 for
  the employee list, unbounded for the audit log).
- Positions page reduced to open positions with a single "Besetzen" action.
- The employee Organisation tab links into the org chart focused on that
  person, reusing the chart's existing search-match highlighting.

Also included, uncommitted until now
- Dependants, HR notes, academic titles, split address fields, position
  validity and role/employment fields, with their migrations and UI.
- Docker/compose deployment setup, data-model and security-review docs.
This commit is contained in:
2026-07-24 23:38:10 +02:00
parent f96773da0f
commit 79f0e19bf8
101 changed files with 6120 additions and 700 deletions

View File

@@ -1,11 +1,25 @@
import { describe, expect, it } from "vitest";
import { daysBetween, fmtAge, fmtDate, initials, tenure } from "@/lib/format";
import { addDaysIso, daysBetweenIso, fmtAge, fmtDate, initials, tenure, toIsoDate, yearsBetweenIso } from "@/lib/format";
describe("fmtDate", () => {
it("formats an ISO date string in de-AT order", () => {
expect(fmtDate("2026-03-05")).toBe("05.03.2026");
});
// A date-only column has no time and no zone. Routing it through a Date
// would anchor it to UTC midnight and render the previous day wherever the
// renderer sits west of UTC — including a server/browser hydration split.
it("never shifts a date-only string across a day boundary", () => {
expect(fmtDate("2026-01-01")).toBe("01.01.2026");
expect(fmtDate("2026-12-31")).toBe("31.12.2026");
});
it("renders a timestamp in Vienna time regardless of the runtime zone", () => {
// 23:30 UTC on 5 March is already 6 March in Vienna (UTC+1 before the
// DST switch); the same instant is still 5 March in UTC.
expect(fmtDate("2026-03-05T23:30:00Z")).toBe("06.03.2026");
});
it("returns an em dash for null/undefined/empty input", () => {
expect(fmtDate(null)).toBe("");
expect(fmtDate(undefined)).toBe("");
@@ -67,12 +81,47 @@ describe("tenure", () => {
});
});
describe("daysBetween", () => {
describe("daysBetweenIso", () => {
it("computes whole days between two dates", () => {
expect(daysBetween("2026-01-01", "2026-01-11")).toBe(10);
expect(daysBetweenIso("2026-01-01", "2026-01-11")).toBe(10);
});
it("returns a negative number when the second date precedes the first", () => {
expect(daysBetween("2026-01-11", "2026-01-01")).toBe(-10);
expect(daysBetweenIso("2026-01-11", "2026-01-01")).toBe(-10);
});
// Both ends are anchored at UTC midnight, so the DST switch in between
// cannot turn 30 calendar days into 29.96 and round down.
it("is exact across a DST transition", () => {
expect(daysBetweenIso("2026-03-15", "2026-04-15")).toBe(31);
expect(daysBetweenIso("2026-10-15", "2026-11-15")).toBe(31);
});
});
describe("addDaysIso", () => {
it("rolls over month and year boundaries", () => {
expect(addDaysIso("2026-12-31", 1)).toBe("2027-01-01");
expect(addDaysIso("2026-01-31", 1)).toBe("2026-02-01");
});
it("handles a leap day", () => {
expect(addDaysIso("2028-02-28", 1)).toBe("2028-02-29");
});
});
describe("yearsBetweenIso", () => {
it("counts only completed years", () => {
expect(yearsBetweenIso("1990-05-15", "2026-05-15")).toBe(36);
expect(yearsBetweenIso("1990-05-15", "2026-05-14")).toBe(35);
});
});
describe("toIsoDate", () => {
it("passes a date-only string through untouched", () => {
expect(toIsoDate("2026-01-01")).toBe("2026-01-01");
});
it("resolves a timestamp to the Vienna calendar day", () => {
expect(toIsoDate("2026-03-05T23:30:00Z")).toBe("2026-03-06");
});
});