feat(relationship): editable relationships with LocalDate+DatePrecision dates and notes (#841)
All checks were successful
CI / Unit & Component Tests (push) Successful in 5m10s
CI / OCR Service Tests (push) Successful in 24s
CI / Backend Unit Tests (push) Successful in 5m14s
CI / fail2ban Regex (push) Successful in 50s
CI / Semgrep Security Scan (push) Successful in 27s
CI / Compose Bucket Idempotency (push) Successful in 1m5s
All checks were successful
CI / Unit & Component Tests (push) Successful in 5m10s
CI / OCR Service Tests (push) Successful in 24s
CI / Backend Unit Tests (push) Successful in 5m14s
CI / fail2ban Regex (push) Successful in 50s
CI / Semgrep Security Scan (push) Successful in 27s
CI / Compose Bucket Idempotency (push) Successful in 1m5s
Closes #837 Makes `PersonRelationship` fully editable (type, related person, dates, notes), migrates its dates from `Integer fromYear/toYear` to `LocalDate + DatePrecision` (mirroring the #773 person pattern, ADR-039 / V76), activates the previously-dead `notes` column, and gives the Zeitstrahl's derived **Heirat** events full date precision for free. Both Open Decisions confirmed as adopted: **no `@Version`** (last-write-wins, single-writer archive) and **`DELETE` ownership-mismatch aligned 403 → 404** (anti-enumeration, matching the new `PUT`). ## What's in it - **V78** migrates `person_relationships.from_year/to_year` → `from_date`/`to_date` + NOT-NULL `*_date_precision` (default `UNKNOWN`); pre-check abort on corrupt years, `YYYY-01-01`/`YEAR` backfill, 5 named CHECK constraints, year columns dropped. - **`PUT /api/persons/{id}/relationships/{relId}`** (`@RequirePermission(WRITE_ALL)`) re-runs every create invariant (self / coherence / order / reverse-PARENT_OF / duplicate) and re-flags family membership; orientation preserved per viewpoint. - New `ErrorCode.INVALID_RELATIONSHIP_DATES` registered in all four sites (§3.6). - `TimelineEventService` sources the derived marriage date from `SPOUSE_OF.fromDate` + precision. - Frontend: `RelationshipDateField` (DAY/MONTH/YEAR), upsert-capable `AddRelationshipForm` (pre-fill + notes + in-flight submit lock), `RelationshipChip` Edit affordance, `updateRelationship` server action, read-view date range + notes, `formatRelationshipDateRange` helper. `api.ts` regenerated. - Docs: ADR-044, db-orm/db-relationships diagrams, DEPLOYMENT §5 deploy note, RTM REQ-001…REQ-019. ## Requirements All 19 EARS requirements implemented red/green and marked `Done` in `.specify/rtm.md`. ## Test plan - **Backend** (targeted, green): `RelationshipMigrationTest` (Testcontainers pg16, 8), `RelationshipServiceTest` (22), `RelationshipControllerTest` (15), `RelationshipServiceIntegrationTest` (real DB, 10), `DerivedEventsAssemblyTest` (17), `ArchitectureTest` (14); `clean package` builds. - **Frontend** (green): `relationshipDates.spec.ts`, `AddRelationshipForm.svelte.spec.ts`, `RelationshipChip.svelte.spec.ts`, `PersonRelationshipsCard.svelte.test.ts`, `page.server.spec.ts`, `messages.spec.ts`. `npm run check` = 798 (below the ~834 baseline); `npm run lint` clean. ## Notes for reviewers - **Spec deviation:** the edit form was built by making `AddRelationshipForm` upsert-capable rather than a duplicate `EditRelationshipForm` (DRY); RTM rows reference `AddRelationshipForm.svelte.spec.ts`. - `api.ts` regenerated from the live spec; only relationship-relevant hunks remain (one springdoc `PageableObject` field-reorder pruned). - **Deploy:** V78 is one-way and not rolling-deploy-safe — stop old JAR → start new JAR (Flyway runs first); targeted `pg_restore -t person_relationships` for rollback. No maintenance window. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Marcel <marcel@familienarchiv> Reviewed-on: #841
This commit was merged in pull request #841.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { enhance } from '$app/forms';
|
||||
import { m } from '$lib/paraglide/messages.js';
|
||||
import PersonTypeahead from '$lib/person/PersonTypeahead.svelte';
|
||||
import RelationshipDateField from '$lib/person/relationship/RelationshipDateField.svelte';
|
||||
import type { components } from '$lib/generated/api';
|
||||
import type { DatePrecision } from '$lib/shared/utils/documentDate';
|
||||
|
||||
type RelationshipDTO = components['schemas']['RelationshipDTO'];
|
||||
type RelationType = NonNullable<RelationshipDTO['relationType']>;
|
||||
@@ -10,71 +13,96 @@ type RelationType = NonNullable<RelationshipDTO['relationType']>;
|
||||
export type RelFormData = {
|
||||
relatedPersonId: string;
|
||||
relationType: RelationType;
|
||||
fromYear?: number;
|
||||
toYear?: number;
|
||||
fromDate?: string;
|
||||
fromDatePrecision?: DatePrecision;
|
||||
toDate?: string;
|
||||
toDatePrecision?: DatePrecision;
|
||||
notes?: string;
|
||||
};
|
||||
|
||||
interface Props {
|
||||
personId: string;
|
||||
// When present the form is an EDIT: pre-filled and posting to ?/updateRelationship.
|
||||
relationship?: RelationshipDTO;
|
||||
onSubmit?: (data: RelFormData) => Promise<void>;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
let { personId, onSubmit }: Props = $props();
|
||||
let { personId, relationship, onSubmit, onClose }: Props = $props();
|
||||
|
||||
const isEdit = $derived(relationship != null);
|
||||
|
||||
let open = $state(false);
|
||||
let addType = $state<RelationType>('PARENT_OF');
|
||||
let addRelatedPersonId = $state('');
|
||||
let addRelatedPersonName = $state('');
|
||||
let addFromYear = $state('');
|
||||
let addToYear = $state('');
|
||||
let notes = $state('');
|
||||
let callbackError = $state<string | null>(null);
|
||||
let submitting = $state(false);
|
||||
|
||||
const yearError = $derived.by(() => {
|
||||
const from = addFromYear.trim();
|
||||
const to = addToYear.trim();
|
||||
if (!from || !to) return null;
|
||||
const fromInt = parseInt(from, 10);
|
||||
const toInt = parseInt(to, 10);
|
||||
if (Number.isNaN(fromInt) || Number.isNaN(toInt)) return null;
|
||||
return toInt < fromInt ? m.relation_year_error_bis_before_von() : null;
|
||||
// Seed once at mount (reading props in a closure avoids state_referenced_locally).
|
||||
// The parent re-creates this form per edited row, so the relationship never
|
||||
// changes under a live instance.
|
||||
onMount(() => {
|
||||
if (!relationship) return;
|
||||
open = true;
|
||||
addType = relationship.relationType ?? 'PARENT_OF';
|
||||
const viewpointIsSubject = relationship.personId === personId;
|
||||
addRelatedPersonId =
|
||||
(viewpointIsSubject ? relationship.relatedPersonId : relationship.personId) ?? '';
|
||||
addRelatedPersonName =
|
||||
(viewpointIsSubject ? relationship.relatedPersonDisplayName : relationship.personDisplayName) ??
|
||||
'';
|
||||
notes = relationship.notes ?? '';
|
||||
});
|
||||
|
||||
const selfError = $derived(
|
||||
addRelatedPersonId !== '' && addRelatedPersonId === personId ? m.relation_error_self() : null
|
||||
);
|
||||
|
||||
const submitDisabled = $derived(
|
||||
yearError !== null || selfError !== null || addRelatedPersonId === ''
|
||||
);
|
||||
const submitDisabled = $derived(selfError !== null || addRelatedPersonId === '');
|
||||
|
||||
function reset() {
|
||||
addType = 'PARENT_OF';
|
||||
addRelatedPersonId = '';
|
||||
addRelatedPersonName = '';
|
||||
addFromYear = '';
|
||||
addToYear = '';
|
||||
notes = '';
|
||||
callbackError = null;
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
if (isEdit) {
|
||||
onClose?.();
|
||||
return;
|
||||
}
|
||||
open = false;
|
||||
reset();
|
||||
}
|
||||
|
||||
async function handleCallbackSubmit(event: Event) {
|
||||
async function handleCallbackSubmit(event: SubmitEvent) {
|
||||
event.preventDefault();
|
||||
if (submitDisabled || !onSubmit) return;
|
||||
const data: RelFormData = { relatedPersonId: addRelatedPersonId, relationType: addType };
|
||||
const from = parseInt(addFromYear.trim(), 10);
|
||||
if (!Number.isNaN(from)) data.fromYear = from;
|
||||
const to = parseInt(addToYear.trim(), 10);
|
||||
if (!Number.isNaN(to)) data.toYear = to;
|
||||
const fd = new FormData(event.currentTarget as HTMLFormElement);
|
||||
const fromDate = (fd.get('fromDate') as string) || undefined;
|
||||
const toDate = (fd.get('toDate') as string) || undefined;
|
||||
const data: RelFormData = {
|
||||
relatedPersonId: addRelatedPersonId,
|
||||
relationType: addType,
|
||||
fromDate,
|
||||
fromDatePrecision: fromDate ? (fd.get('fromDatePrecision') as DatePrecision) : undefined,
|
||||
toDate,
|
||||
toDatePrecision: toDate ? (fd.get('toDatePrecision') as DatePrecision) : undefined,
|
||||
notes: (fd.get('notes') as string)?.trim() || undefined
|
||||
};
|
||||
submitting = true;
|
||||
try {
|
||||
await onSubmit(data);
|
||||
open = false;
|
||||
reset();
|
||||
} catch {
|
||||
callbackError = m.error_internal_error();
|
||||
} finally {
|
||||
submitting = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -113,39 +141,32 @@ async function handleCallbackSubmit(event: Event) {
|
||||
compact
|
||||
/>
|
||||
</div>
|
||||
<label class="block">
|
||||
<span class="font-sans text-xs font-medium text-ink-2"
|
||||
>{m.relation_form_field_from_year()}</span
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
name="fromYear"
|
||||
inputmode="numeric"
|
||||
pattern="[0-9]*"
|
||||
bind:value={addFromYear}
|
||||
placeholder={m.relation_form_year_placeholder()}
|
||||
class="mt-1 block w-full rounded-sm border border-line bg-surface px-2 py-1.5 text-sm text-ink focus:border-primary focus:outline-none"
|
||||
/>
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="font-sans text-xs font-medium text-ink-2">{m.relation_form_field_to_year()}</span
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
name="toYear"
|
||||
inputmode="numeric"
|
||||
pattern="[0-9]*"
|
||||
bind:value={addToYear}
|
||||
aria-describedby={yearError ? 'add-rel-year-error' : undefined}
|
||||
class="mt-1 block w-full rounded-sm border border-line bg-surface px-2 py-1.5 text-sm text-ink focus:border-primary focus:outline-none"
|
||||
/>
|
||||
{#if yearError}
|
||||
<p id="add-rel-year-error" class="mt-1 text-xs text-red-700" role="alert">
|
||||
{yearError}
|
||||
</p>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
<div class="mt-3 grid gap-3 md:grid-cols-2">
|
||||
<RelationshipDateField
|
||||
name="fromDate"
|
||||
legend={m.relation_label_from_date()}
|
||||
initialIso={relationship?.fromDate ?? ''}
|
||||
initialPrecision={relationship?.fromDatePrecision ?? null}
|
||||
/>
|
||||
<RelationshipDateField
|
||||
name="toDate"
|
||||
legend={m.relation_label_to_date()}
|
||||
initialIso={relationship?.toDate ?? ''}
|
||||
initialPrecision={relationship?.toDatePrecision ?? null}
|
||||
/>
|
||||
</div>
|
||||
<label class="mt-3 block">
|
||||
<span class="font-sans text-xs font-medium text-ink-2">{m.relation_label_notes()}</span>
|
||||
<textarea
|
||||
name="notes"
|
||||
maxlength="2000"
|
||||
rows="2"
|
||||
bind:value={notes}
|
||||
placeholder={m.relation_notes_placeholder()}
|
||||
class="mt-1 block w-full rounded-sm border border-line bg-surface px-2 py-1.5 font-serif text-sm text-ink-3 focus:border-primary focus:outline-none"
|
||||
></textarea>
|
||||
</label>
|
||||
{#if selfError}
|
||||
<p class="mt-2 text-xs text-red-700" role="alert">{selfError}</p>
|
||||
{/if}
|
||||
@@ -162,10 +183,18 @@ async function handleCallbackSubmit(event: Event) {
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={submitDisabled}
|
||||
class="rounded-sm bg-primary px-3 py-1.5 font-sans text-xs font-medium text-primary-fg transition hover:bg-primary/80 disabled:opacity-40"
|
||||
disabled={submitDisabled || submitting}
|
||||
aria-busy={submitting}
|
||||
class="inline-flex items-center gap-1.5 rounded-sm bg-primary px-3 py-1.5 font-sans text-xs font-medium text-primary-fg transition hover:bg-primary/80 disabled:opacity-40"
|
||||
>
|
||||
{m.relation_btn_add()}
|
||||
{#if submitting}
|
||||
<span
|
||||
class="h-3 w-3 animate-spin rounded-full border-2 border-primary-fg/40 border-t-primary-fg"
|
||||
data-testid="submit-spinner"
|
||||
aria-hidden="true"
|
||||
></span>
|
||||
{/if}
|
||||
{isEdit ? m.relation_btn_save() : m.relation_btn_add()}
|
||||
</button>
|
||||
</div>
|
||||
{/snippet}
|
||||
@@ -185,18 +214,27 @@ async function handleCallbackSubmit(event: Event) {
|
||||
{:else}
|
||||
<form
|
||||
method="POST"
|
||||
action="?/addRelationship"
|
||||
action={isEdit ? '?/updateRelationship' : '?/addRelationship'}
|
||||
use:enhance={() => {
|
||||
submitting = true;
|
||||
return async ({ result, update }) => {
|
||||
await update();
|
||||
submitting = false;
|
||||
if (result.type === 'success') {
|
||||
open = false;
|
||||
reset();
|
||||
if (isEdit) {
|
||||
onClose?.();
|
||||
} else {
|
||||
open = false;
|
||||
reset();
|
||||
}
|
||||
}
|
||||
};
|
||||
}}
|
||||
class="mt-3 rounded-sm border border-line bg-muted/40 p-3"
|
||||
>
|
||||
{#if relationship}
|
||||
<input type="hidden" name="relId" value={relationship.id} />
|
||||
{/if}
|
||||
{@render formFields()}
|
||||
</form>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user