Files
faunosteo/apps/app/src/editor/annotations/overview.ts
T
bchanot 6131225288 feat(editor): board 01 annotation card, side column from 1 024 px
Annotations of the view move from under the drawing to the overview card
(grouped by category, name filter, all rows); side column from lg.
Properties panel gains « Toutes les annotations ».

E2E mapping (R-24): after a creation the card is hidden (the new annotation is
selected), so list(...).getByText(name) became selectionTag toContainText
(annotations, geometry, journey); row clicks go through pickAnnotation
(annotations, geometry, journey, structures); geometry's list count 0 while a
creation is pending became selectionTag count 0.
2026-11-06 21:40:25 +01:00

65 lines
2.1 KiB
TypeScript

import { useMemo } from 'react'
import type {
AnatomicalSheetDocument,
Annotation,
AnnotationCategory,
} from '@faunosteo/core-wasm/types'
import { folded } from '@/catalogue/useCatalogue'
/**
* What the overview panel counts, read once per parsed document: the annotations of each
* view and the vertebral regions. A display count, no rule: no core call, no network.
*/
export interface OverviewCounts {
annotationsByView: ReadonlyMap<string, number>
regions: number
}
export function overviewCounts(doc: AnatomicalSheetDocument): OverviewCounts {
const annotationsByView = new Map<string, number>()
for (const annotation of doc.annotations) {
const count = annotationsByView.get(annotation.view_id) ?? 0
annotationsByView.set(annotation.view_id, count + 1)
}
return { annotationsByView, regions: doc.vertebral_config.regions.length }
}
export function useOverviewCounts(
doc: AnatomicalSheetDocument,
): OverviewCounts {
return useMemo(() => overviewCounts(doc), [doc])
}
/** The annotations of one category in the shown view; `category` is null for strays. */
export interface AnnotationGroup {
category: AnnotationCategory | null
annotations: Annotation[]
}
/**
* The annotations of a view grouped by category in document order, keeping those whose
* displayed name contains `term` (case and accents ignored). A group « Sans catégorie »
* exists only when an annotation names a category the document does not hold.
*/
export function groupAnnotations(
doc: AnatomicalSheetDocument,
viewId: string,
term: string,
nameOf: (annotation: Annotation) => string,
): AnnotationGroup[] {
const wanted = folded(term.trim())
const shown = doc.annotations.filter(
(a) => a.view_id === viewId && folded(nameOf(a)).includes(wanted),
)
const known = new Set(doc.categories.map((category) => category.id))
const groups: AnnotationGroup[] = doc.categories.map((category) => ({
category,
annotations: shown.filter((a) => a.category_id === category.id),
}))
groups.push({
category: null,
annotations: shown.filter((a) => !known.has(a.category_id)),
})
return groups.filter((group) => group.annotations.length > 0)
}