refactor(stammbaum): extract chipLabel/otherName to shared relationshipLabels helper
Addresses @felix blocker: both functions were duplicated verbatim in StammbaumCard.svelte and StammbaumSidePanel.svelte. Now exported from $lib/relationshipLabels.ts with perspectivePersonId as an explicit param. 8 unit tests added (red→green). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,37 @@
|
||||
import * as m from '$lib/paraglide/messages.js';
|
||||
import type { components } from '$lib/generated/api';
|
||||
|
||||
type RelationshipDTO = components['schemas']['RelationshipDTO'];
|
||||
|
||||
export function chipLabel(rel: RelationshipDTO, perspectivePersonId: string): string {
|
||||
const viewpointIsSubject = rel.personId === perspectivePersonId;
|
||||
switch (rel.relationType) {
|
||||
case 'PARENT_OF':
|
||||
return viewpointIsSubject ? m.relation_parent_of() : m.relation_child_of();
|
||||
case 'SPOUSE_OF':
|
||||
return m.relation_spouse_of();
|
||||
case 'SIBLING_OF':
|
||||
return m.relation_sibling_of();
|
||||
case 'FRIEND':
|
||||
return m.relation_friend();
|
||||
case 'COLLEAGUE':
|
||||
return m.relation_colleague();
|
||||
case 'EMPLOYER':
|
||||
return m.relation_employer();
|
||||
case 'DOCTOR':
|
||||
return m.relation_doctor();
|
||||
case 'NEIGHBOR':
|
||||
return m.relation_neighbor();
|
||||
default:
|
||||
return m.relation_other();
|
||||
}
|
||||
}
|
||||
|
||||
export function otherName(rel: RelationshipDTO, perspectivePersonId: string): string {
|
||||
return rel.personId === perspectivePersonId
|
||||
? rel.relatedPersonDisplayName
|
||||
: rel.personDisplayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a backend inferred-label key (parent, uncle_aunt, ...) to its
|
||||
|
||||
Reference in New Issue
Block a user