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.
This commit is contained in:
bchanot committed 2026-11-06 21:40:25 +01:00
1 parent 51fd3db608
commit 6131225288
16 files changed
+404 -94

No files matched your search

+1 -1
View File
@@ -50,7 +50,7 @@ export function useCatalogue() {
}
/** Lower case without accents, so « epaule » finds « Épaule ». */
function folded(text: string): string {
export function folded(text: string): string {
return text.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase()
}
@@ -1,11 +1,10 @@
import type { Annotation, SheetView } from '@faunosteo/core-wasm/types'
import type { AnnotationGroup } from '@/editor/annotations/overview'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import ReviewBadge from './ReviewBadge'
const LIST =
'max-h-64 divide-y divide-[var(--color-border)] overflow-y-auto rounded-lg ' +
'border border-[var(--color-border)]'
const LIST = 'max-h-96 space-y-2 overflow-y-auto'
const ROW =
'flex w-full items-center justify-between gap-2 px-3 py-2 text-left text-sm ' +
@@ -24,52 +23,91 @@ export function annotationName(
return opened?.name[locale] ?? annotation.id
}
/**
* The annotations of the view: name, kind, review badge; each row a button, reachable
* from the keyboard. Selection works in every mode, so a read-only draft is browsable.
*/
export default function AnnotationList({
annotations,
function Row({
annotation,
views,
selectedId,
onSelect,
}: {
annotations: readonly Annotation[]
annotation: Annotation
views: readonly SheetView[]
selectedId: string | null
onSelect: (id: string) => void
}) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
if (annotations.length === 0) {
return (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.annotations.list_empty')}
</p>
)
}
return (
<li>
<button
type="button"
data-focus-key={JSON.stringify({
kind: 'annotation',
id: annotation.id,
})}
onClick={() => onSelect(annotation.id)}
className={ROW}
>
<span className="min-w-0 truncate">
<span className="text-[var(--color-ink-muted)]">
{t(`editor.annotations.kind.${annotation.kind}`)}
</span>{' '}
{annotationName(annotation, views, locale)}
</span>
<ReviewBadge status={annotation.review_status} />
</button>
</li>
)
}
/** « Sans catégorie » or the category: swatch, name and the count of rows shown. */
function GroupTitle({ group }: { group: AnnotationGroup }) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const { category } = group
return (
<p className="flex items-center gap-2 px-3 text-sm font-semibold">
<span
aria-hidden="true"
className="size-3 rounded-full border border-[var(--color-border)]"
style={{ backgroundColor: category?.color ?? undefined }}
/>
<span className="min-w-0 flex-1 truncate">
{category ? category.name[locale] : t('editor.overview.uncategorised')}
</span>
<span className="font-normal text-[var(--color-ink-muted)]">
{group.annotations.length}
</span>
</p>
)
}
/**
* The annotations of the view by category, each row a button reachable from the keyboard.
* Selection works in every mode, so a read-only draft is browsable.
*/
export default function AnnotationList({
groups,
views,
onSelect,
}: {
groups: readonly AnnotationGroup[]
views: readonly SheetView[]
onSelect: (id: string) => void
}) {
const t = useT()
return (
<ul aria-label={t('editor.annotations.list')} className={LIST}>
{annotations.map((annotation) => (
<li key={annotation.id}>
<button
type="button"
aria-current={annotation.id === selectedId}
onClick={() => onSelect(annotation.id)}
className={`${ROW} ${
annotation.id === selectedId
? 'bg-[var(--color-surface-strong)]'
: ''
}`}
>
<span className="min-w-0 truncate">
<span className="text-[var(--color-ink-muted)]">
{t(`editor.annotations.kind.${annotation.kind}`)}
</span>{' '}
{annotationName(annotation, views, locale)}
</span>
<ReviewBadge status={annotation.review_status} />
</button>
{groups.map((group) => (
<li key={group.category?.id ?? 'none'}>
<GroupTitle group={group} />
<ul>
{group.annotations.map((annotation) => (
<Row
key={annotation.id}
annotation={annotation}
views={views}
onSelect={onSelect}
/>
))}
</ul>
</li>
))}
</ul>
@@ -28,7 +28,7 @@ import type { EditorPlaceProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import AnnotationCanvas from './AnnotationCanvas'
import AnnotationList, { annotationName } from './AnnotationList'
import { annotationName } from './AnnotationList'
import CreationPanel from './CreationPanel'
import KeyboardAdd from './KeyboardAdd'
import OverviewPanel from './OverviewPanel'
@@ -131,7 +131,7 @@ export default function EditableAnnotations(props: Props) {
const context = useCommitContext()
const placement = usePlacement({ ...scene, context })
return (
<div className="grid gap-4 xl:grid-cols-[minmax(0,1fr)_22rem]">
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
<CanvasColumn scene={scene} placement={placement} />
<aside>
<SidePanel scene={scene} context={context} />
@@ -180,12 +180,6 @@ function CanvasColumn({
linkDisabled={model.children.length === 0}
onAdd={(kind) => addAtCentre(kind, scene.frame, dispatch)}
/>
<AnnotationList
annotations={model.annotations}
views={doc.views}
selectedId={ui.selectedId}
onSelect={(id) => dispatch({ type: 'select', id })}
/>
</div>
)
}
@@ -281,6 +275,7 @@ function SidePanel({
viewId={scene.viewId}
readOnly={false}
onSelectView={(id) => dispatch({ type: 'view', viewId: id })}
onSelectAnnotation={(id) => dispatch({ type: 'select', id })}
onOpenSection={scene.onOpenSection}
/>
)
@@ -295,6 +290,7 @@ function SidePanel({
dispatch={dispatch}
context={context}
navigate={scene.navigate}
onShowAll={() => dispatch({ type: 'select', id: null })}
/>
)
}
@@ -1,12 +1,18 @@
import { useMemo, useState } from 'react'
import type {
AnatomicalSheetDocument,
SheetView,
} from '@faunosteo/core-wasm/types'
import { useOverviewCounts } from '@/editor/annotations/overview'
import Input from '@/components/ui/Input'
import {
groupAnnotations,
useOverviewCounts,
} from '@/editor/annotations/overview'
import type { AnnotationSection } from '@/editor/navigation'
import { usePlural } from '@/editor/plural'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import AnnotationList, { annotationName } from './AnnotationList'
const CARD = 'space-y-2 rounded-xl border border-[var(--color-border)] p-4'
const TITLE = 'text-sm font-semibold'
@@ -24,6 +30,7 @@ export interface OverviewPanelProps {
/** Put before every id (the read-only twin beside the kept edit panel). */
idPrefix?: string
onSelectView: (viewId: string) => void
onSelectAnnotation: (annotationId: string) => void
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
}
@@ -183,7 +190,59 @@ function CategoriesCard(props: OverviewPanelProps) {
)
}
/** Board 01's overview: the views and the categories, with the entries to their sections. */
function AnnotationsCard(props: OverviewPanelProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const { doc, viewId, onSelectAnnotation } = props
const [term, setTerm] = useState('')
const prefix = props.idPrefix ?? ''
const total = useOverviewCounts(doc).annotationsByView.get(viewId) ?? 0
const groups = useMemo(
() =>
groupAnnotations(doc, viewId, term, (a) =>
annotationName(a, doc.views, locale),
),
[doc, viewId, term, locale],
)
return (
<section aria-labelledby={`${prefix}overview-annotations`} className={CARD}>
<h3
id={`${prefix}overview-annotations`}
className={`${TITLE} flex items-center justify-between`}
>
{t('editor.annotations.list')}
<span className="font-normal text-[var(--color-ink-muted)]">
{total}
</span>
</h3>
<Input
type="search"
id={`${prefix}overview-filter`}
aria-label={t('editor.overview.filter')}
placeholder={t('editor.overview.filter')}
value={term}
onChange={(event) => setTerm(event.target.value)}
/>
{groups.length > 0 ? (
<AnnotationList
groups={groups}
views={doc.views}
onSelect={onSelectAnnotation}
/>
) : (
<p className="text-sm text-[var(--color-ink-muted)]">
{t(
total === 0
? 'editor.annotations.list_empty'
: 'editor.overview.no_match',
)}
</p>
)}
</section>
)
}
/** Board 01's overview: the views, the categories, then the annotations of the shown view. */
export default function OverviewPanel(props: OverviewPanelProps) {
const t = useT()
return (
@@ -195,6 +254,7 @@ export default function OverviewPanel(props: OverviewPanelProps) {
>
<ViewsCard {...props} />
<CategoriesCard {...props} />
<AnnotationsCard {...props} />
</div>
)
}
@@ -1,4 +1,5 @@
import { useState, type Dispatch } from 'react'
import { flushSync } from 'react-dom'
import type {
AnatomicalSheetDocument,
Annotation,
@@ -15,6 +16,7 @@ import {
import { isEditable } from '@/editor/annotations/geometryEdit'
import type { UiAction } from '@/editor/annotations/uiState'
import { geometryErrorsById } from '@/editor/issues'
import { focusRow } from '@/editor/focusRequest'
import { targetOfKey } from '@/editor/navigation'
import type { EditorPlaceProps } from '@/editor/tabs'
import { useEditCommand } from '@/editor/useEditCommand'
@@ -37,6 +39,8 @@ export interface PropertiesPanelProps {
dispatch: Dispatch<UiAction>
context: CommitContext
navigate: EditorPlaceProps['navigate']
/** Clears the selection: the overview shows again. */
onShowAll: () => void
/** Put before every id, for a twin of the panel that lives beside another one. */
idPrefix?: string
}
@@ -60,6 +64,7 @@ export default function PropertiesPanel(props: PropertiesPanelProps) {
data-testid="annotation-properties"
className="space-y-4 rounded-xl border border-[var(--color-border)] p-4"
>
<ShowAll id={annotation.id} onShowAll={props.onShowAll} />
<header className="flex items-start justify-between gap-2">
<h3
tabIndex={-1}
@@ -84,6 +89,24 @@ export default function PropertiesPanel(props: PropertiesPanelProps) {
)
}
/** Back to the overview, focus on the row of the annotation that was open. */
function ShowAll({ id, onShowAll }: { id: string; onShowAll: () => void }) {
const t = useT()
return (
<Button
type="button"
variant="secondary"
size="sm"
onClick={() => {
flushSync(onShowAll)
focusRow({ kind: 'annotation', id })
}}
>
{t('editor.annotations.show_all')}
</Button>
)
}
function GeometrySection(props: PropertiesPanelProps) {
const t = useT()
const { annotation, readOnly, geometryLocked } = props
@@ -1,9 +1,7 @@
import { useEffect, useState } from 'react'
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
import CatalogueCanvas from '@/components/catalogue/CatalogueCanvas'
import AnnotationList, {
annotationName,
} from '@/components/editor/annotations/AnnotationList'
import { annotationName } from '@/components/editor/annotations/AnnotationList'
import EditableAnnotations from '@/components/editor/annotations/EditableAnnotations'
import OverviewPanel from '@/components/editor/annotations/OverviewPanel'
import PropertiesPanel from '@/components/editor/annotations/PropertiesPanel'
@@ -166,7 +164,7 @@ function ReadOnlyAnnotations({
const selected = model.annotations.find((a) => a.id === selectedId)
if (!preview || !view) return null
return (
<div className="grid gap-4 xl:grid-cols-[minmax(0,1fr)_22rem]">
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
<div className="min-w-0 space-y-3">
<ViewSwitcher
views={doc.views}
@@ -190,12 +188,6 @@ function ReadOnlyAnnotations({
selectedId={selectedId}
onAnnotation={setSelectedId}
/>
<AnnotationList
annotations={model.annotations}
views={doc.views}
selectedId={selectedId}
onSelect={setSelectedId}
/>
</div>
{selected ? (
<PropertiesPanel
@@ -208,6 +200,7 @@ function ReadOnlyAnnotations({
dispatch={() => undefined}
context={{ t: (key) => key, locale }}
navigate={navigate}
onShowAll={() => setSelectedId(null)}
/>
) : (
<OverviewPanel
@@ -219,6 +212,7 @@ function ReadOnlyAnnotations({
setViewId(id)
setSelectedId(null)
}}
onSelectAnnotation={setSelectedId}
onOpenSection={onOpenSection}
/>
)}
+39 -1
View File
@@ -1,5 +1,10 @@
import { useMemo } from 'react'
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
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
@@ -24,3 +29,36 @@ export function useOverviewCounts(
): 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)
}
+4
View File
@@ -1221,6 +1221,10 @@ export const en: Dict = {
'editor.overview.see_categories': 'See the categories',
'editor.overview.regions_one': 'Vertebral regions ({count} region)',
'editor.overview.regions_other': 'Vertebral regions ({count} regions)',
'editor.overview.filter': 'Filter by name',
'editor.overview.uncategorised': 'No category',
'editor.overview.no_match': 'No annotation matches.',
'editor.annotations.show_all': 'All annotations',
'editor.references.open': 'References',
'editor.references.close': 'Close the references',
'editor.draft.loading': 'Loading the draft…',
+4
View File
@@ -1252,6 +1252,10 @@ export const fr: Dict = {
'editor.overview.see_categories': 'Voir les catégories',
'editor.overview.regions_one': 'Régions vertébrales ({count} région)',
'editor.overview.regions_other': 'Régions vertébrales ({count} régions)',
'editor.overview.filter': 'Filtrer par nom',
'editor.overview.uncategorised': 'Sans catégorie',
'editor.overview.no_match': 'Aucune annotation ne correspond.',
'editor.annotations.show_all': 'Toutes les annotations',
'editor.references.open': 'Références',
'editor.references.close': 'Fermer les références',
'editor.draft.loading': 'Chargement du brouillon…',