Show people surname first
Employee names now read "Winkler, Hannah" wherever a person appears in a list, a table, a heading or a tree node. That is the order a personnel list is kept in, it is the order people are looked up in, and it finally matches the sorting — the employee list has always been ordered by surname, which made an alphabetical page look unsorted. The name was being assembled inline in about twenty places. A rename that catches half of them is worse than none, so it now goes through fmtName in lib/format.ts and every display site calls it. Sentences keep the natural order: "Hannah Winkler wurde versetzt" reads like German, "Winkler, Hannah wurde versetzt" reads like a form. So the toasts are unchanged and only labels moved. Two things the change would have quietly broken: The org chart's own filter matched against "first last". It now matches either order, with or without the comma, so typing what you see works and so does typing what you remember. The print model sorted by the last word of the composed name, which happened to be the surname and is now the first name — every printed unit would have come out sorted by first name. It sorts on the surname field itself now, which is what it meant all along. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -56,8 +56,27 @@ export function initials(firstName: string, lastName: string): string {
|
||||
return `${a}${b}`;
|
||||
}
|
||||
|
||||
// "Dr. Max Mustermann, MSc MBA" — prefix titles precede the name, suffix
|
||||
// titles follow after a comma, both space-joined in the stored order.
|
||||
// „Mustermann, Max" — der Nachname zuerst.
|
||||
//
|
||||
// So steht es in jeder Personalliste, und danach wird gesucht: wer jemanden
|
||||
// sucht, hat den Nachnamen im Kopf. Nebenbei stimmt die Anzeige damit auch
|
||||
// mit der Sortierung überein, die schon immer nach Nachnamen ging — vorher
|
||||
// las sich eine alphabetische Liste, als wäre sie ungeordnet.
|
||||
//
|
||||
// Eine Stelle für alle: der Name wurde an gut zwanzig Orten einzeln
|
||||
// zusammengesetzt, und eine Umstellung, die die Hälfte davon vergisst, ist
|
||||
// schlimmer als gar keine.
|
||||
export function fmtName(firstName: string, lastName: string): string {
|
||||
const nach = lastName?.trim() ?? "";
|
||||
const vor = firstName?.trim() ?? "";
|
||||
if (!nach) return vor;
|
||||
if (!vor) return nach;
|
||||
return `${nach}, ${vor}`;
|
||||
}
|
||||
|
||||
// "Mustermann, Dr. Max, MSc MBA" — vorangestellte Titel stehen beim
|
||||
// Vornamen, nachgestellte am Ende. Der Nachname bleibt vorne, damit auch die
|
||||
// Überschrift einer Personalakte so beginnt wie ihr Eintrag in der Liste.
|
||||
export function fmtFullName(
|
||||
firstName: string,
|
||||
lastName: string,
|
||||
@@ -66,7 +85,7 @@ export function fmtFullName(
|
||||
): string {
|
||||
const prefix = titlePrefix && titlePrefix.length > 0 ? `${titlePrefix.join(" ")} ` : "";
|
||||
const suffix = titleSuffix && titleSuffix.length > 0 ? `, ${titleSuffix.join(" ")}` : "";
|
||||
return `${prefix}${firstName} ${lastName}${suffix}`;
|
||||
return `${fmtName(`${prefix}${firstName}`, lastName)}${suffix}`;
|
||||
}
|
||||
|
||||
// Whole years between two ISO dates. Compares the "MM-DD" tails as strings,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Tx } from "./db";
|
||||
import type { Database } from "./supabase/types";
|
||||
import { fmtName } from "./format";
|
||||
|
||||
export type OpenNote = Database["public"]["Tables"]["employee_notes"]["Row"] & {
|
||||
employeeName: string;
|
||||
@@ -26,7 +27,7 @@ export async function loadOpenNotes(tx: Tx): Promise<OpenNote[]> {
|
||||
const { first_name, last_name, ...note } = row;
|
||||
return {
|
||||
...(note as Database["public"]["Tables"]["employee_notes"]["Row"]),
|
||||
employeeName: first_name && last_name ? `${first_name} ${last_name}` : "Unbekannt",
|
||||
employeeName: first_name && last_name ? fmtName(first_name, last_name) : "Unbekannt",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { OrgEmployee, OrgUnitNode, OrgVacancy } from "@/components/orgchart/types";
|
||||
import { fmtName } from "@/lib/format";
|
||||
|
||||
// Das Modell für den Druck.
|
||||
//
|
||||
@@ -18,6 +19,8 @@ import type { OrgEmployee, OrgUnitNode, OrgVacancy } from "@/components/orgchart
|
||||
|
||||
export type PrintPerson = {
|
||||
id: string;
|
||||
/** Getrennt mitgeführt, weil danach sortiert wird — siehe nachName. */
|
||||
lastName: string;
|
||||
name: string;
|
||||
jobTitle: string;
|
||||
personnelNumber: number;
|
||||
@@ -52,7 +55,8 @@ export type PrintModel = {
|
||||
function personFrom(e: OrgEmployee): PrintPerson {
|
||||
return {
|
||||
id: e.id,
|
||||
name: `${e.first_name} ${e.last_name}`,
|
||||
lastName: e.last_name,
|
||||
name: fmtName(e.first_name, e.last_name),
|
||||
jobTitle: e.job_title,
|
||||
personnelNumber: e.personnel_number,
|
||||
isChief: e.is_chief,
|
||||
@@ -61,9 +65,16 @@ function personFrom(e: OrgEmployee): PrintPerson {
|
||||
};
|
||||
}
|
||||
|
||||
/** Nachname, dann Vorname — wie in jeder Liste, die jemand durchsucht. */
|
||||
/**
|
||||
* Nachname, dann Vorname — wie in jeder Liste, die jemand durchsucht.
|
||||
*
|
||||
* Der Nachname kommt aus dem eigenen Feld, nicht aus dem zusammengesetzten
|
||||
* Namen. Vorher wurde das letzte Wort genommen, was bei „Hannah Winkler"
|
||||
* zufällig stimmte; seit die Anzeige „Winkler, Hannah" lautet, wäre das
|
||||
* letzte Wort der Vorname, und die Liste stünde nach Vornamen sortiert da.
|
||||
*/
|
||||
function nachName(a: PrintPerson, b: PrintPerson): number {
|
||||
return a.name.split(" ").slice(-1)[0].localeCompare(b.name.split(" ").slice(-1)[0], "de") || a.name.localeCompare(b.name, "de");
|
||||
return a.lastName.localeCompare(b.lastName, "de") || a.name.localeCompare(b.name, "de");
|
||||
}
|
||||
|
||||
export function buildPrintModel(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Tx } from "./db";
|
||||
import { todayIso } from "./format";
|
||||
import { fmtName, todayIso } from "./format";
|
||||
import { breadcrumbLabel, loadOrgMaps, type OrgMaps } from "./org";
|
||||
|
||||
// Eine offene Stelle ist keine eigene Sache mehr. Sie ist eine Planstelle
|
||||
@@ -128,7 +128,7 @@ export async function loadOpenPositions(tx: Tx): Promise<OpenPositionResolved[]>
|
||||
const prev = lastEndByPosition.get(e.position_id);
|
||||
if (e.valid_to && (!prev || e.valid_to > prev)) lastEndByPosition.set(e.position_id, e.valid_to);
|
||||
}
|
||||
const chiefNameByUnit = new Map(chiefs.map((c) => [c.org_unit_id, `${c.first_name} ${c.last_name}`]));
|
||||
const chiefNameByUnit = new Map(chiefs.map((c) => [c.org_unit_id, fmtName(c.first_name, c.last_name)]));
|
||||
|
||||
return open.map((p) => {
|
||||
const managerUnit = managerUnitFor(orgMaps, p.org_unit_id, p.is_chief);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { todayIso, yearsBetweenIso } from "./format";
|
||||
import { fmtName, todayIso, yearsBetweenIso } from "./format";
|
||||
import type { EmploymentStatus, HistoryEventType, Weekday } from "./supabase/types";
|
||||
|
||||
export { todayIso };
|
||||
@@ -266,7 +266,7 @@ export function aggregateReport(
|
||||
const value = measureValue(rowsForGroup, measure, asOf);
|
||||
const people: ReportPerson[] = rowsForGroup.map((e) => ({
|
||||
id: e.id,
|
||||
name: `${e.first_name} ${e.last_name}`,
|
||||
name: fmtName(e.first_name, e.last_name),
|
||||
title: e.job_title,
|
||||
team: e.org_unit_id ? (lookups.teamName.get(e.org_unit_id) ?? "–") : "–",
|
||||
entry_date: e.entry_date,
|
||||
@@ -404,7 +404,7 @@ export function aggregateEvents(
|
||||
// code working unchanged for both report modes.
|
||||
const people: ReportPerson[] = rowsForGroup.map((e) => ({
|
||||
id: e.employee_id,
|
||||
name: `${e.first_name} ${e.last_name}`,
|
||||
name: fmtName(e.first_name, e.last_name),
|
||||
title: e.description,
|
||||
team: e.org_unit_id ? (lookups.teamName.get(e.org_unit_id) ?? "–") : "–",
|
||||
entry_date: e.event_date,
|
||||
|
||||
Reference in New Issue
Block a user