feat(app): Constats description, vet referral and citations, keyboard focus after collapse and delete

This commit is contained in:
bchanot committed 2026-11-04 13:50:20 +01:00
1 parent 26097852ff
commit 91d06c9817
9 files changed
+374 -13

No files matched your search

+50 -6
View File
@@ -43,22 +43,66 @@ export type FindingElement =
| { kind: 'finding_category'; value: FindingCategory }
| { kind: 'finding_node'; value: FindingNode }
/** The same element under another name (the core decides what that does to its marking). */
export function withName(
/** What the detail panel edits; a zone takes the name only. */
export type FindingPatch = Partial<
Pick<
FindingNode,
'name' | 'description' | 'reference_ids' | 'requires_vet_referral'
>
>
/** The same element with `patch` applied (the core decides what it does to the marking). */
export function patchElement(
item: FindingItem,
name: LocalizedText,
patch: FindingPatch,
): FindingElement {
const { element } = item
switch (element.kind) {
case 'zone':
return { kind: 'zone', value: { ...element.value, name } }
return {
kind: 'zone',
value: { ...element.value, name: patch.name ?? element.value.name },
}
case 'finding_category':
return { kind: 'finding_category', value: { ...element.value, name } }
return {
kind: 'finding_category',
value: {
...element.value,
name: patch.name ?? element.value.name,
description: patch.description ?? element.value.description,
reference_ids: patch.reference_ids ?? element.value.reference_ids,
},
}
case 'finding_node':
return { kind: 'finding_node', value: { ...element.value, name } }
return { kind: 'finding_node', value: { ...element.value, ...patch } }
}
}
/** Whether `id` sits under `ancestorId` in the tree. */
export function isUnder(
items: readonly FindingItem[],
id: string,
ancestorId: string,
): boolean {
let parent = items.find((i) => i.id === id)?.parentId ?? null
while (parent !== null) {
if (parent === ancestorId) return true
parent = items.find((i) => i.id === parent)?.parentId ?? null
}
return false
}
/** Where the selection goes when `item` is removed: the previous sibling, else the parent. */
export function fallbackAfterRemoval(
items: readonly FindingItem[],
item: FindingItem,
): string | null {
const previous = items.find(
(i) => i.parentId === item.parentId && i.index === item.index - 1,
)
return previous?.id ?? item.parentId
}
export const itemId = (zoneId: string, path: readonly string[]): string =>
JSON.stringify([zoneId, ...path])