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:
1 parent
51fd3db608
commit
6131225288
16 files changed
+404
-94
No files matched your search
@@ -33,3 +33,14 @@ Reworded prose (no new key): `admin.failure.view.asset.unknown`, `editor.annotat
|
||||
`editor.annotations.no_category`, `editor.annotations.no_child_view`, `editor.views.frame.newly_invalid`
|
||||
(they named the removed tabs). Removed keys: `editor.tab.views`, `editor.tab.references`,
|
||||
`editor.tab.vertebrae` (renamed to `editor.place.*`), `editor.annotations.select_hint` (the overview replaces it).
|
||||
|
||||
## Lot C (annotation card, side column from 1 024 px)
|
||||
|
||||
| Key | FR | EN | Where | Status |
|
||||
|---|---|---|---|---|
|
||||
| `editor.overview.filter` | Filtrer par nom | Filter by name | Card field (name and placeholder) | board text |
|
||||
| `editor.overview.uncategorised` | Sans catégorie | No category | Group title, only if a document holds such an annotation | plan wording |
|
||||
| `editor.overview.no_match` | Aucune annotation ne correspond. | No annotation matches. | Card, filter without result | proposal |
|
||||
| `editor.annotations.show_all` | Toutes les annotations | All annotations | Properties panel, back to the card | plan wording |
|
||||
|
||||
Reused: `editor.annotations.list` (« Annotations de la vue », card title and list name), `editor.annotations.list_empty`.
|
||||
@@ -8,8 +8,10 @@ import {
|
||||
editorActor,
|
||||
geometryField,
|
||||
openEditor,
|
||||
pickAnnotation,
|
||||
saveDraft,
|
||||
seedDraft,
|
||||
selectionTag,
|
||||
selectTab,
|
||||
serverDocument,
|
||||
standardShape,
|
||||
@@ -92,7 +94,7 @@ test.describe('editor annotations (A3)', () => {
|
||||
.getByLabel(dict['editor.annotations.zone'])
|
||||
.selectOption('zone-a')
|
||||
await createFromPanel(page)
|
||||
await expect(list(page).getByText('Point un')).toBeVisible()
|
||||
await expect(selectionTag(page)).toContainText('Point un')
|
||||
await expect(properties(page)).toBeVisible()
|
||||
const placed = await geometryField(page, dict, 'cx').inputValue()
|
||||
expect(Math.abs(Number(placed) - 300)).toBeLessThan(1)
|
||||
@@ -110,7 +112,7 @@ test.describe('editor annotations (A3)', () => {
|
||||
.click()
|
||||
await fillCreation(page, { fr: 'Zone une', en: 'Zone one' })
|
||||
await createFromPanel(page)
|
||||
await expect(list(page).getByText('Zone une')).toBeVisible()
|
||||
await expect(selectionTag(page)).toContainText('Zone une')
|
||||
|
||||
// A link to the detail view: the same tracing, the opened view chosen.
|
||||
await tool(page, 'link').click()
|
||||
@@ -125,7 +127,7 @@ test.describe('editor annotations (A3)', () => {
|
||||
.click()
|
||||
await fillCreation(page, { fr: 'Accès un', en: 'Access one' }, 'detail-a')
|
||||
await createFromPanel(page)
|
||||
await expect(list(page).getByText('Accès un')).toBeVisible()
|
||||
await expect(selectionTag(page)).toContainText('Accès un')
|
||||
await expect(
|
||||
page.getByRole('button', {
|
||||
name: dict['editor.annotations.undo'],
|
||||
@@ -134,9 +136,7 @@ test.describe('editor annotations (A3)', () => {
|
||||
).toBeEnabled()
|
||||
|
||||
// A numeric edit of the point, then undo and redo.
|
||||
await list(page)
|
||||
.getByRole('button', { name: /Point un/ })
|
||||
.click()
|
||||
await pickAnnotation(page, dict, /Point un/)
|
||||
const cx = geometryField(page, dict, 'cx')
|
||||
await cx.fill('420')
|
||||
await cx.press('Enter')
|
||||
@@ -234,7 +234,7 @@ test.describe('editor annotations (A3)', () => {
|
||||
.focus()
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(creation(page)).toHaveCount(0)
|
||||
await expect(list(page).getByText('Clavier')).toBeVisible()
|
||||
await expect(selectionTag(page)).toContainText('Clavier')
|
||||
await expect(geometryField(page, dict, 'cx')).toHaveValue('250')
|
||||
|
||||
const cy = geometryField(page, dict, 'cy')
|
||||
@@ -252,7 +252,7 @@ test.describe('editor annotations (A3)', () => {
|
||||
.getByRole('button', { name: dict['editor.annotations.create'] })
|
||||
.focus()
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(list(page).getByText('Zone clavier')).toBeVisible()
|
||||
await expect(selectionTag(page)).toContainText('Zone clavier')
|
||||
const vertexX = page.getByLabel(
|
||||
dict['editor.annotations.geometry.vertex_x'].replace('{n}', '1'),
|
||||
)
|
||||
|
||||
@@ -10,9 +10,11 @@ import {
|
||||
geometryField,
|
||||
openEditor,
|
||||
openSection,
|
||||
pickAnnotation,
|
||||
pointOf,
|
||||
saveDraft,
|
||||
seedDraft,
|
||||
selectionTag,
|
||||
selectTab,
|
||||
serverDocument,
|
||||
shapeWith,
|
||||
@@ -30,8 +32,6 @@ const dict = fr
|
||||
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
|
||||
const creation = (page: Page) => page.getByTestId('annotation-creation')
|
||||
const notice = (page: Page) => page.getByTestId('correction-notice')
|
||||
const list = (page: Page) =>
|
||||
page.getByRole('list', { name: dict['editor.annotations.list'] })
|
||||
|
||||
const tool = (page: Page, id: string) =>
|
||||
page.getByRole('button', {
|
||||
@@ -93,7 +93,7 @@ test.describe('editor geometry (adversarial)', () => {
|
||||
await expect(notice(page)).toBeVisible()
|
||||
await expect(page.getByTestId('overlay-click-cross')).toBeAttached()
|
||||
const shown = await proposed(page)
|
||||
await expect(list(page)).toHaveCount(0)
|
||||
await expect(selectionTag(page)).toHaveCount(0) // an insertion selects it
|
||||
|
||||
// Cancelled: the notice goes, nothing was inserted.
|
||||
await notice(page)
|
||||
@@ -102,7 +102,7 @@ test.describe('editor geometry (adversarial)', () => {
|
||||
})
|
||||
.click()
|
||||
await expect(notice(page)).toHaveCount(0)
|
||||
await expect(list(page)).toHaveCount(0)
|
||||
await expect(selectionTag(page)).toHaveCount(0) // an insertion selects it
|
||||
|
||||
// Confirmed: the same attempt again, the corrected position inserted.
|
||||
await creation(page)
|
||||
@@ -114,7 +114,7 @@ test.describe('editor geometry (adversarial)', () => {
|
||||
.getByRole('button', { name: dict['editor.annotations.correction_use'] })
|
||||
.click()
|
||||
await expect(creation(page)).toHaveCount(0)
|
||||
await expect(list(page).getByText('Bord')).toBeVisible()
|
||||
await expect(selectionTag(page)).toContainText('Bord')
|
||||
await expect(geometryField(page, dict, 'cx')).toHaveValue(shown.x)
|
||||
await expect(geometryField(page, dict, 'cy')).toHaveValue(shown.y)
|
||||
})
|
||||
@@ -143,7 +143,7 @@ test.describe('editor geometry (adversarial)', () => {
|
||||
})
|
||||
.click()
|
||||
await expect(notice(page)).toHaveCount(0)
|
||||
await expect(list(page)).toHaveCount(0)
|
||||
await expect(selectionTag(page)).toHaveCount(0) // an insertion selects it
|
||||
// Then confirmed: the same attempt again inserts the corrected position.
|
||||
await creation(page)
|
||||
.getByRole('button', { name: dict['editor.annotations.create'] })
|
||||
@@ -152,7 +152,7 @@ test.describe('editor geometry (adversarial)', () => {
|
||||
await notice(page)
|
||||
.getByRole('button', { name: dict['editor.annotations.correction_use'] })
|
||||
.click()
|
||||
await expect(list(page).getByText('Bord détail')).toBeVisible()
|
||||
await expect(selectionTag(page)).toContainText('Bord détail')
|
||||
})
|
||||
|
||||
test('a point inherited out of its frame is repaired through the geometry group', async ({
|
||||
@@ -165,9 +165,7 @@ test.describe('editor geometry (adversarial)', () => {
|
||||
)
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
await viewChip(page, 'Détail A').click()
|
||||
await list(page)
|
||||
.getByRole('button', { name: /Hors cadre/ })
|
||||
.click()
|
||||
await pickAnnotation(page, dict, /Hors cadre/)
|
||||
const issues = page.getByTestId('annotation-geometry-issues')
|
||||
await expect(issues).toBeVisible()
|
||||
const verification = page.getByRole('tab', {
|
||||
@@ -454,9 +452,7 @@ test.describe('editor touch path (real browser)', () => {
|
||||
|
||||
// A movable selection needs the touch itself: the browser reads touch-action at
|
||||
// touchstart, so a drag of the selected marker must not be left to the pan.
|
||||
await list(page)
|
||||
.getByRole('button', { name: /Tactile/ })
|
||||
.click()
|
||||
await pickAnnotation(page, dict, /Tactile/)
|
||||
await expect.poll(touchAction).toBe('none')
|
||||
const cx = geometryField(page, dict, 'cx')
|
||||
await expect(cx).toHaveValue('500')
|
||||
|
||||
@@ -5,7 +5,8 @@ import { stepUpAdmin } from '../support/admin'
|
||||
import { expect, expectAccessible, test } from '../support/browser'
|
||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||
import {
|
||||
annotationList,
|
||||
pickAnnotation,
|
||||
selectionTag,
|
||||
clickDrawing,
|
||||
createFromPanel,
|
||||
creationPanel,
|
||||
@@ -175,20 +176,19 @@ const MODIFIED = { point: 3, vertex: 4 }
|
||||
|
||||
/** Applies (not only refuses) changes to a point, a zone and a link; read back at the save. */
|
||||
async function modifyAnnotations(page: Page) {
|
||||
const list = annotationList(page, dict)
|
||||
await list.getByRole('button', { name: /Point essai/ }).click()
|
||||
await pickAnnotation(page, dict, /Point essai/)
|
||||
const cx = geometryField(page, dict, 'cx')
|
||||
const before = Number(await cx.inputValue())
|
||||
await commitText(cx, String(before + MODIFIED.point))
|
||||
await expect(cx).toHaveValue(String(before + MODIFIED.point))
|
||||
await list.getByRole('button', { name: /Zone dessinée/ }).click()
|
||||
await pickAnnotation(page, dict, /Zone dessinée/)
|
||||
const vertex = page.getByLabel(
|
||||
dict['editor.annotations.geometry.vertex_x'].replace('{n}', '1'),
|
||||
)
|
||||
const start = Number(await vertex.inputValue())
|
||||
await commitText(vertex, String(start + MODIFIED.vertex))
|
||||
await expect(vertex).toHaveValue(String(start + MODIFIED.vertex))
|
||||
await list.getByRole('button', { name: /Accès essai/ }).click()
|
||||
await pickAnnotation(page, dict, /Accès essai/)
|
||||
await commitText(page.locator('#annotation-name-fr'), 'Accès modifié')
|
||||
await page.locator('#annotation-laterality').selectOption('bilateral')
|
||||
await expect(page.locator('#annotation-name-fr')).toHaveValue('Accès modifié')
|
||||
@@ -204,9 +204,7 @@ async function repairGeometry(page: Page) {
|
||||
await clickDrawing(page, 1, 1)
|
||||
await fillCreation(page, dict, { fr: 'Point de bord', en: 'Edge point' })
|
||||
await createFromPanel(page, dict)
|
||||
await expect(
|
||||
annotationList(page, dict).getByText('Point de bord'),
|
||||
).toBeVisible()
|
||||
await expect(selectionTag(page)).toContainText('Point de bord')
|
||||
const cx = geometryField(page, dict, 'cx')
|
||||
await cx.fill('9999')
|
||||
await cx.press('Enter')
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
openEditor,
|
||||
openReferences,
|
||||
openSection,
|
||||
pickAnnotation,
|
||||
pointOf,
|
||||
saveDraft,
|
||||
seedDraft,
|
||||
@@ -289,10 +290,7 @@ test.describe('editor structures (A4)', () => {
|
||||
|
||||
// The point goes first; the zone then deletes with its descendants named.
|
||||
await showDrawing(page, dict)
|
||||
await page
|
||||
.getByRole('list', { name: dict['editor.annotations.list'] })
|
||||
.getByRole('button', { name: /Point lié/ })
|
||||
.click()
|
||||
await pickAnnotation(page, dict, /Point lié/)
|
||||
await page
|
||||
.getByTestId('annotation-properties')
|
||||
.getByRole('button', { name: dict['editor.action.delete'] })
|
||||
|
||||
@@ -488,6 +488,24 @@ export const creationPanel = (page: Page) =>
|
||||
export const annotationList = (page: Page, dict: Dict) =>
|
||||
page.getByRole('list', { name: dict['editor.annotations.list'] })
|
||||
|
||||
/** The tag over the drawing while an annotation is selected (the card is then hidden). */
|
||||
export const selectionTag = (page: Page) =>
|
||||
page.getByTestId('annotation-selection-tag')
|
||||
|
||||
/** Selects an annotation from the overview card, leaving a selection first when there is one. */
|
||||
export async function pickAnnotation(
|
||||
page: Page,
|
||||
dict: Dict,
|
||||
name: RegExp | string,
|
||||
) {
|
||||
const all = page.getByRole('button', {
|
||||
name: dict['editor.annotations.show_all'],
|
||||
exact: true,
|
||||
})
|
||||
if (await all.isVisible()) await all.click()
|
||||
await annotationList(page, dict).getByRole('button', { name }).click()
|
||||
}
|
||||
|
||||
export const toolButton = (page: Page, dict: Dict, id: string) =>
|
||||
page.getByRole('button', {
|
||||
name: dict[`editor.annotations.tool.${id}`],
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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…',
|
||||
|
||||
@@ -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…',
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/** V1-2.6 U1 Lot C: board 01's « Annotations de la vue » card, in edit and read-only. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, render, screen, waitFor, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Annotation } from '@faunosteo/core-wasm/types'
|
||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
||||
import { openReady, resetStore } from '../helpers/editorHarness'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
...(await orig<typeof import('@faunosteo/supabase')>()),
|
||||
getSheetVersion: vi.fn(),
|
||||
downloadSheetDrawing: vi.fn(),
|
||||
saveSheetDraft: vi.fn(),
|
||||
getOfficialSheetAdmin: vi.fn(),
|
||||
submitSheetReview: vi.fn(),
|
||||
}))
|
||||
|
||||
const props = {
|
||||
readOnly: false,
|
||||
navigate: vi.fn(),
|
||||
reloadSheet: vi.fn(),
|
||||
section: 'drawing' as const,
|
||||
visited: ['drawing'] as const,
|
||||
onOpenSection: vi.fn(),
|
||||
onBack: vi.fn(),
|
||||
}
|
||||
|
||||
const named = (id: string, fr: string, category: string, view = 'view-main') => {
|
||||
const base = point(id, 50, 50, 5, view).value as Annotation
|
||||
return {
|
||||
kind: 'annotation',
|
||||
value: { ...base, category_id: category, name: { fr, en: fr } },
|
||||
} as const
|
||||
}
|
||||
|
||||
/** Two categories (b declared after a); the first annotation sits in b. */
|
||||
function sheet(): string {
|
||||
let text = insert(drawnText(), {
|
||||
kind: 'category',
|
||||
value: { id: 'cat-b', name: { fr: 'Os', en: 'Bone' }, color: '#aa0000' },
|
||||
})
|
||||
text = insert(text, named('a1', 'Épaule', 'cat-b'))
|
||||
text = insert(text, named('a2', 'Genou', 'cat-a'))
|
||||
return insert(text, {
|
||||
kind: 'view',
|
||||
value: {
|
||||
kind: 'detail',
|
||||
id: 'view-det',
|
||||
name: { fr: 'Tête', en: 'Head' },
|
||||
svg_asset_id: null,
|
||||
view_box: { min_x: 10, min_y: 10, width: 80, height: 80 },
|
||||
parent_view_id: 'view-main',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
resetStore()
|
||||
})
|
||||
|
||||
async function mount(readOnly = false) {
|
||||
await openReady({ text: sheet() })
|
||||
render(<AnnotationsTab {...props} readOnly={readOnly} />)
|
||||
await screen.findByRole('list', { name: 'Annotations de la vue' })
|
||||
}
|
||||
|
||||
const card = () => screen.getByRole('list', { name: 'Annotations de la vue' })
|
||||
const rows = () => within(card()).getAllByRole('button')
|
||||
|
||||
describe.each([
|
||||
['edit', false],
|
||||
['read-only', true],
|
||||
])('the annotation card (%s)', (_mode, readOnly) => {
|
||||
it('groups the rows by category in document order, with a count per group', async () => {
|
||||
await mount(readOnly)
|
||||
const titles = within(card())
|
||||
.getAllByRole('listitem')
|
||||
.filter((item) => item.querySelector('ul'))
|
||||
.map((item) => item.querySelector('p')?.textContent)
|
||||
expect(titles).toEqual(['N1', 'Os1'])
|
||||
expect(rows().map((b) => b.textContent)).toEqual([
|
||||
expect.stringContaining('Genou'),
|
||||
expect.stringContaining('Épaule'),
|
||||
])
|
||||
})
|
||||
|
||||
it('filters on the displayed name, ignoring case and accents', async () => {
|
||||
await mount(readOnly)
|
||||
const user = userEvent.setup()
|
||||
await user.type(screen.getByRole('searchbox', { name: 'Filtrer par nom' }), 'EPAULE')
|
||||
expect(rows()).toHaveLength(1)
|
||||
expect(rows()[0]).toHaveTextContent('Épaule')
|
||||
await user.type(screen.getByRole('searchbox'), 'zzz')
|
||||
expect(screen.getByText('Aucune annotation ne correspond.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('a row selects the annotation; « Toutes les annotations » returns with focus on its row', async () => {
|
||||
await mount(readOnly)
|
||||
const user = userEvent.setup()
|
||||
await user.click(rows()[1])
|
||||
expect(await screen.findByTestId('annotation-properties')).toBeVisible()
|
||||
await user.click(screen.getByRole('button', { name: 'Toutes les annotations' }))
|
||||
expect(screen.getByTestId('annotation-overview')).toBeVisible()
|
||||
await waitFor(() => expect(document.activeElement).toBe(rows()[1]))
|
||||
})
|
||||
|
||||
it('a view row switches the canvas view', async () => {
|
||||
await mount(readOnly)
|
||||
const user = userEvent.setup()
|
||||
const views = screen.getByRole('region', { name: 'Aperçu de la fiche' })
|
||||
await user.click(within(views).getByRole('button', { name: /^Tête/ }))
|
||||
expect(within(views).getByRole('button', { name: /^Tête/ })).toHaveAttribute(
|
||||
'aria-current',
|
||||
'true',
|
||||
)
|
||||
expect(screen.getByText('Aucune annotation dans cette vue.')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the side column', () => {
|
||||
it('sits beside the canvas from lg (1 024 px), not xl', async () => {
|
||||
await mount()
|
||||
const grid = screen.getByTestId('annotation-overview').closest('.grid')
|
||||
expect(grid?.className).toContain('lg:grid-cols-[minmax(0,1fr)_22rem]')
|
||||
expect(grid?.className).not.toContain('xl:')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user