feat(editor): four tabs, Annotations sections, references from the header
U1 Lot B1. Four tabs (Général, Annotations, Constats, Vérification); views,
categories and regions become full-width Annotations sections opened from the
overview panel; references move to a header-toggled panel (minimal, Lot D
completes it); « Aller à » goes through EditorTarget and the navigation hook.
EditorWorkspace owns the navigation; DraftHeader split in HeaderActions and
SaveLine; EditorTabs split in TabList and MoreTabs.
R-24, assertions removed or rewritten (file: old -> new):
unit
- editor-route.test: seven tab names -> four; « Plus » at 800 px with
Références clicked -> no « Plus »; below 640 px five others -> Général,
Constats, and Constats opens the findings tab; + references panel cases
- editor-route-recovery.test: tab Références + editor-tab-references label ->
header button + editor-references-panel labelled by its heading
- editor-mode.test: small tier `more` of five -> [general, findings]
- editor-focus-request.test: {key,serial} -> {target,serial}; ReferencesTab and
VertebraeTab -> ReferencesPanel and RegionsSection; issueTarget tab/key ->
target place/section/key (vertebrae tab -> annotations/regions); consumed
context (serial) -> (serial, outcome); annotation case adds heading focus
- editor-verification.test: onGoTo('annotations', key) -> navigate(targetOfKey
(key), opener); props onSelectTab/onGoTo -> navigate
- editor-annotations-tab.test: props onSelectTab -> navigate + section props;
no_category text « (onglet Général) » -> « (Annotations, section
Catégories) »
- editor-tabs-general.test: categories cases render GeneralTab ->
CategoriesSection(doc); + Général holds no categories editor
- editor-tabs-lists.test: tab imports -> panel and section; read-only
references « no button » -> only « Fermer les références »
- editor-tabs-views, editor-drawing-upload, editor-repair.test: ViewsTab ->
ViewsSection import, assertions kept; editor-findings.test: navigate prop
e2e
- support/editor selectTab: exact name -> pattern (error badge in the name);
+ place, openSection, showDrawing, backToDrawing, openReferences, TABS
- support/warm-up: seven tabs -> four + sections + references panel
- editor-access: seven-tab axe loops -> four tabs + three sections + panel
(edit and read-only); narrow widths add panel overflow and axe
- editor-drawings: tab Vues -> openSection views; tab Annotations ->
showDrawing
- editor-structures: tab Général (categories) -> openSection categories, axe
label « general tab » -> « categories section »; tab Références ->
openReferences/closeReferences; tab Vertèbres -> openSection regions; tab
Annotations -> showDrawing
- editor-geometry: three tab Vues -> openSection views
- editor-equine: tab Général (categories add) -> openSection categories; five
tabs loop -> two tabs + sections + panel; tab Annotations -> showDrawing
- editor-journey: tab Vues, tab Général (category), tab Annotations ->
openSection views/categories, showDrawing; frozen axe scrolls to the header
- lan/trial-lan (not run): tab Vues -> Annotations tab + views entry
Verified: typecheck, lint, vitest 107 files / 1125 tests, whole shell suite on
the sandbox 151 passed, 49 skipped, 0 failed.
This commit is contained in:
1 parent
95b1b7e461
commit
bc2dba7c14
56 files changed
+2387
-667
No files matched your search
@@ -0,0 +1,35 @@
|
|||||||
|
# V1-2.6 U1 new FR/EN labels: proposals
|
||||||
|
|
||||||
|
Everything below is a proposal (C44), not ratified: it goes to the owner's separate review. Each lot
|
||||||
|
appends its rows to its own section (key, FR, EN, where it shows). Removed keys are listed with their lot.
|
||||||
|
|
||||||
|
## Lot B1 (four tabs, Annotations sections, references from the header)
|
||||||
|
|
||||||
|
| Key | FR | EN | Where | Status |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| `editor.tab.errors_one` / `_other` | {count} erreur / {count} erreurs | {count} error / {count} errors | Vérification tab badge, in its accessible name | board text, plural form proposed |
|
||||||
|
| `editor.place.drawing` | Dessin | Drawing | Live region, « Annotations · Dessin » | proposal |
|
||||||
|
| `editor.place.views` | Vues | Views | Section heading, live region, « Aller à » fallback, hint link | proposal |
|
||||||
|
| `editor.place.categories` | Catégories | Categories | Same | proposal |
|
||||||
|
| `editor.place.regions` | Régions vertébrales | Vertebral regions | Same | T17 name |
|
||||||
|
| `editor.place.references` | Références | References | Panel heading, live region | proposal |
|
||||||
|
| `editor.section.back` | Retour au dessin | Back to the drawing | First control of each section | plan wording |
|
||||||
|
| `editor.references.open` | Références | References | Header button | board text |
|
||||||
|
| `editor.references.close` | Fermer les références | Close the references | Panel close button | proposal |
|
||||||
|
| `editor.live.references_closed` | Références fermées | References closed | Live region on panel close | proposal |
|
||||||
|
| `editor.live.creation_kept` | Une création est en cours : terminez-la ou abandonnez-la pour atteindre cette annotation. | A creation is in progress: finish or abandon it to reach this annotation. | Live region, « Aller à » kept | proposal |
|
||||||
|
| `editor.live.tracing_kept` | Un tracé est en cours : terminez-le ou annulez-le pour atteindre cette annotation. | A tracing is in progress: finish or cancel it to reach this annotation. | Same | proposal |
|
||||||
|
| `editor.overview.label` | Aperçu de la fiche | Sheet overview | Overview panel region name | proposal |
|
||||||
|
| `editor.overview.views` | Vues | Views | Overview card | board text |
|
||||||
|
| `editor.overview.view_main` / `view_detail` | Vue principale / Vue détaillée | Main view / Detail view | Overview rows | board text |
|
||||||
|
| `editor.overview.annotations_one` / `_other` | {count} annotation / {count} annotations | same | Overview rows | board text |
|
||||||
|
| `editor.overview.manage_views` / `see_views` | Gérer les vues / Voir les vues | Manage views / See the views | Overview entry, edit / read-only | board text |
|
||||||
|
| `editor.overview.categories` | Catégories | Categories | Overview card | board text |
|
||||||
|
| `editor.overview.categories_empty` | Aucune catégorie pour l'instant. | No category yet. | Overview card | proposal |
|
||||||
|
| `editor.overview.edit_categories` / `see_categories` | Modifier les catégories / Voir les catégories | Edit categories / See the categories | Overview entry | board text |
|
||||||
|
| `editor.overview.regions_one` / `_other` | Régions vertébrales ({count} région) / ({count} régions) | Vertebral regions ({count} region) / ({count} regions) | Overview entry (T17) | proposal |
|
||||||
|
|
||||||
|
Reworded prose (no new key): `admin.failure.view.asset.unknown`, `editor.annotations.unmeasured.hint`,
|
||||||
|
`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).
|
||||||
@@ -99,6 +99,14 @@ async function createNonEquineSheet(page: Page, tag: string) {
|
|||||||
await expect(page).toHaveURL(/\/app\/admin\/sheets\/[0-9a-f-]{36}\/draft$/)
|
await expect(page).toHaveURL(/\/app\/admin\/sheets\/[0-9a-f-]{36}\/draft$/)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The views section: the Annotations tab, then the overview entry (U1 moved the views). */
|
||||||
|
async function openViews(page: Page) {
|
||||||
|
await page
|
||||||
|
.getByRole('tab', { name: dict['editor.tab.annotations'], exact: true })
|
||||||
|
.click()
|
||||||
|
await page.locator('[data-section-entry="views"]').click()
|
||||||
|
}
|
||||||
|
|
||||||
test('trial through the LAN origin: MFA, new sheet, SVG import, save, reload', async ({
|
test('trial through the LAN origin: MFA, new sheet, SVG import, save, reload', async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -121,9 +129,7 @@ test('trial through the LAN origin: MFA, new sheet, SVG import, save, reload', a
|
|||||||
await signIn(page)
|
await signIn(page)
|
||||||
await challenge(page, secret)
|
await challenge(page, secret)
|
||||||
await createNonEquineSheet(page, tag)
|
await createNonEquineSheet(page, tag)
|
||||||
await page
|
await openViews(page)
|
||||||
.getByRole('tab', { name: dict['editor.tab.views'], exact: true })
|
|
||||||
.click()
|
|
||||||
await page
|
await page
|
||||||
.locator('[data-testid$="-file"]')
|
.locator('[data-testid$="-file"]')
|
||||||
.first()
|
.first()
|
||||||
@@ -144,9 +150,7 @@ test('trial through the LAN origin: MFA, new sheet, SVG import, save, reload', a
|
|||||||
await page.getByRole('button', { name: dict['common.save'] }).click()
|
await page.getByRole('button', { name: dict['common.save'] }).click()
|
||||||
await expect(revisionLine(page)).toHaveText(`Révision ${before + 1}`)
|
await expect(revisionLine(page)).toHaveText(`Révision ${before + 1}`)
|
||||||
await page.reload()
|
await page.reload()
|
||||||
await page
|
await openViews(page)
|
||||||
.getByRole('tab', { name: dict['editor.tab.views'], exact: true })
|
|
||||||
.click()
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByRole('tabpanel').getByText(dict['editor.views.drawing.ok']),
|
page.getByRole('tabpanel').getByText(dict['editor.views.drawing.ok']),
|
||||||
).toBeVisible()
|
).toBeVisible()
|
||||||
|
|||||||
@@ -9,15 +9,21 @@ import {
|
|||||||
import { stepUpAdmin } from '../support/admin'
|
import { stepUpAdmin } from '../support/admin'
|
||||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||||
import {
|
import {
|
||||||
|
SECTIONS,
|
||||||
|
TABS,
|
||||||
|
closeReferences,
|
||||||
draftPath,
|
draftPath,
|
||||||
draftTitle,
|
draftTitle,
|
||||||
editorActor,
|
editorActor,
|
||||||
makeActor,
|
makeActor,
|
||||||
openEditor,
|
openEditor,
|
||||||
|
openReferences,
|
||||||
|
openSection,
|
||||||
pointOf,
|
pointOf,
|
||||||
seedDraft,
|
seedDraft,
|
||||||
selectTab,
|
selectTab,
|
||||||
shapeWith,
|
shapeWith,
|
||||||
|
showDrawing,
|
||||||
type Actor,
|
type Actor,
|
||||||
} from '../support/editor'
|
} from '../support/editor'
|
||||||
import { signIn } from '../support/shell'
|
import { signIn } from '../support/shell'
|
||||||
@@ -31,15 +37,6 @@ import { signIn } from '../support/shell'
|
|||||||
const dict = fr
|
const dict = fr
|
||||||
|
|
||||||
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
|
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
|
||||||
const TABS = [
|
|
||||||
'general',
|
|
||||||
'views',
|
|
||||||
'annotations',
|
|
||||||
'findings',
|
|
||||||
'references',
|
|
||||||
'vertebrae',
|
|
||||||
'verification',
|
|
||||||
] as const
|
|
||||||
|
|
||||||
const seedShape = shapeWith(
|
const seedShape = shapeWith(
|
||||||
pointOf('p1', 'main', { cx: 500, cy: 400, r: 40 }, 'Point un'),
|
pointOf('p1', 'main', { cx: 500, cy: 400, r: 40 }, 'Point un'),
|
||||||
@@ -150,6 +147,9 @@ test.describe('editor access, narrow screens and axe', () => {
|
|||||||
).toHaveCount(0)
|
).toHaveCount(0)
|
||||||
await expectNoHorizontalOverflow(page, `the draft at ${width} px`)
|
await expectNoHorizontalOverflow(page, `the draft at ${width} px`)
|
||||||
await expectAccessible(page, `the draft at ${width} px`)
|
await expectAccessible(page, `the draft at ${width} px`)
|
||||||
|
await openReferences(page, dict)
|
||||||
|
await expectNoHorizontalOverflow(page, `the panel at ${width} px`)
|
||||||
|
await expectAccessible(page, `the references panel at ${width} px`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +178,20 @@ test.describe('editor access, narrow screens and axe', () => {
|
|||||||
await expectNoHorizontalOverflow(page, `the ${tab} tab at 1 024 px`)
|
await expectNoHorizontalOverflow(page, `the ${tab} tab at 1 024 px`)
|
||||||
await expectAccessible(page, `the ${tab} tab (edit)`)
|
await expectAccessible(page, `the ${tab} tab (edit)`)
|
||||||
}
|
}
|
||||||
|
for (const section of SECTIONS) {
|
||||||
|
await openSection(page, dict, section)
|
||||||
|
await page.waitForLoadState('networkidle')
|
||||||
|
await expectNoHorizontalOverflow(
|
||||||
|
page,
|
||||||
|
`the ${section} section at 1 024 px`,
|
||||||
|
)
|
||||||
|
await expectAccessible(page, `the ${section} section (edit)`)
|
||||||
|
}
|
||||||
|
await showDrawing(page, dict)
|
||||||
|
await openReferences(page, dict)
|
||||||
|
await expectNoHorizontalOverflow(page, 'the references panel at 1 024 px')
|
||||||
|
await expectAccessible(page, 'the references panel (edit)')
|
||||||
|
await closeReferences(page, dict)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('axe on every tab of a read-only draft', async ({ page, requests }) => {
|
test('axe on every tab of a read-only draft', async ({ page, requests }) => {
|
||||||
@@ -197,5 +211,12 @@ test.describe('editor access, narrow screens and axe', () => {
|
|||||||
await page.waitForLoadState('networkidle')
|
await page.waitForLoadState('networkidle')
|
||||||
await expectAccessible(page, `the ${tab} tab (read-only)`)
|
await expectAccessible(page, `the ${tab} tab (read-only)`)
|
||||||
}
|
}
|
||||||
|
for (const section of SECTIONS) {
|
||||||
|
await openSection(page, dict, section)
|
||||||
|
await expectAccessible(page, `the ${section} section (read-only)`)
|
||||||
|
}
|
||||||
|
await showDrawing(page, dict)
|
||||||
|
await openReferences(page, dict)
|
||||||
|
await expectAccessible(page, 'the references panel (read-only)')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -4,14 +4,15 @@ import { expect, expectAccessible, test } from '../support/browser'
|
|||||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||||
import {
|
import {
|
||||||
DRAWING_SVG,
|
DRAWING_SVG,
|
||||||
INKSCAPE_EXPORT,
|
|
||||||
editorActor,
|
editorActor,
|
||||||
|
INKSCAPE_EXPORT,
|
||||||
openEditor,
|
openEditor,
|
||||||
seedDraft,
|
openSection,
|
||||||
selectTab,
|
|
||||||
standardShape,
|
|
||||||
serverDocument,
|
|
||||||
saveDraft,
|
saveDraft,
|
||||||
|
seedDraft,
|
||||||
|
serverDocument,
|
||||||
|
showDrawing,
|
||||||
|
standardShape,
|
||||||
} from '../support/editor'
|
} from '../support/editor'
|
||||||
|
|
||||||
// V1-2.6 A2 (contract C16, C20): a drawing imported into a view. A hostile file is
|
// V1-2.6 A2 (contract C16, C20): a drawing imported into a view. A hostile file is
|
||||||
@@ -54,7 +55,7 @@ test.describe('editor drawings (A2)', () => {
|
|||||||
requests.forbid(actor.account.email, actor.account.password)
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
const seed = await seedDraft(actor, { drawing: null })
|
const seed = await seedDraft(actor, { drawing: null })
|
||||||
await openEditor(page, dict, actor, seed.sheetId)
|
await openEditor(page, dict, actor, seed.sheetId)
|
||||||
await selectTab(page, dict, 'views')
|
await openSection(page, dict, 'views')
|
||||||
await expect(
|
await expect(
|
||||||
mainDrawing(page).getByText(dict['editor.views.drawing.none']),
|
mainDrawing(page).getByText(dict['editor.views.drawing.none']),
|
||||||
).toBeVisible()
|
).toBeVisible()
|
||||||
@@ -81,7 +82,7 @@ test.describe('editor drawings (A2)', () => {
|
|||||||
requests.forbid(actor.account.email, actor.account.password)
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
const seed = await seedDraft(actor, { drawing: null })
|
const seed = await seedDraft(actor, { drawing: null })
|
||||||
await openEditor(page, dict, actor, seed.sheetId)
|
await openEditor(page, dict, actor, seed.sheetId)
|
||||||
await selectTab(page, dict, 'views')
|
await openSection(page, dict, 'views')
|
||||||
|
|
||||||
await mainFile(page).setInputFiles(
|
await mainFile(page).setInputFiles(
|
||||||
file(INKSCAPE_EXPORT, 'inkscape-1.4.3.svg'),
|
file(INKSCAPE_EXPORT, 'inkscape-1.4.3.svg'),
|
||||||
@@ -130,7 +131,7 @@ test.describe('editor drawings (A2)', () => {
|
|||||||
requests.forbid(actor.account.email, actor.account.password)
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
const seed = await seedDraft(actor, { drawing: null, shape: standardShape })
|
const seed = await seedDraft(actor, { drawing: null, shape: standardShape })
|
||||||
await openEditor(page, dict, actor, seed.sheetId)
|
await openEditor(page, dict, actor, seed.sheetId)
|
||||||
await selectTab(page, dict, 'views')
|
await openSection(page, dict, 'views')
|
||||||
|
|
||||||
await mainFile(page).setInputFiles(file(DRAWING_SVG, 'valide.svg'))
|
await mainFile(page).setInputFiles(file(DRAWING_SVG, 'valide.svg'))
|
||||||
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
||||||
@@ -164,7 +165,7 @@ test.describe('editor drawings (A2)', () => {
|
|||||||
detail.getByText(dict['editor.views.drawing.inherited']),
|
detail.getByText(dict['editor.views.drawing.inherited']),
|
||||||
).toBeVisible()
|
).toBeVisible()
|
||||||
|
|
||||||
await selectTab(page, dict, 'annotations')
|
await showDrawing(page, dict)
|
||||||
await page
|
await page
|
||||||
.getByRole('group', { name: dict['editor.annotations.views'] })
|
.getByRole('group', { name: dict['editor.annotations.views'] })
|
||||||
.getByRole('button', { name: 'Détail A' })
|
.getByRole('button', { name: 'Détail A' })
|
||||||
|
|||||||
@@ -11,14 +11,19 @@ import { stepUpAdmin } from '../support/admin'
|
|||||||
import { expect, expectAccessible, test } from '../support/browser'
|
import { expect, expectAccessible, test } from '../support/browser'
|
||||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||||
import {
|
import {
|
||||||
|
type Actor,
|
||||||
|
closeReferences,
|
||||||
editorActor,
|
editorActor,
|
||||||
openEditor,
|
openEditor,
|
||||||
|
openReferences,
|
||||||
|
openSection,
|
||||||
|
SECTIONS,
|
||||||
seedDraft,
|
seedDraft,
|
||||||
selectTab,
|
selectTab,
|
||||||
serverDocument,
|
serverDocument,
|
||||||
|
showDrawing,
|
||||||
standardShape,
|
standardShape,
|
||||||
toolButton,
|
toolButton,
|
||||||
type Actor,
|
|
||||||
} from '../support/editor'
|
} from '../support/editor'
|
||||||
import { signIn } from '../support/shell'
|
import { signIn } from '../support/shell'
|
||||||
|
|
||||||
@@ -121,7 +126,7 @@ async function measureRenames(page: Page, label: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function measureAdditions(page: Page, label: string) {
|
async function measureAdditions(page: Page, label: string) {
|
||||||
await selectTab(page, dict, 'general')
|
await openSection(page, dict, 'categories')
|
||||||
await startProbe(page)
|
await startProbe(page)
|
||||||
for (let round = 0; round <= SAMPLES; round++) {
|
for (let round = 0; round <= SAMPLES; round++) {
|
||||||
await page.locator('#category-new-fr').fill(`Catégorie ${round}`)
|
await page.locator('#category-new-fr').fill(`Catégorie ${round}`)
|
||||||
@@ -287,14 +292,11 @@ test.describe('equine working copy and commit latency', () => {
|
|||||||
// once blanked the page on nodes that omit their defaulted fields).
|
// once blanked the page on nodes that omit their defaulted fields).
|
||||||
await selectTab(page, dict, 'findings')
|
await selectTab(page, dict, 'findings')
|
||||||
await expect(page.getByTestId('finding-item').first()).toBeVisible()
|
await expect(page.getByTestId('finding-item').first()).toBeVisible()
|
||||||
for (const tab of [
|
for (const tab of ['general', 'verification'])
|
||||||
'general',
|
|
||||||
'views',
|
|
||||||
'references',
|
|
||||||
'vertebrae',
|
|
||||||
'verification',
|
|
||||||
])
|
|
||||||
await selectTab(page, dict, tab)
|
await selectTab(page, dict, tab)
|
||||||
|
for (const section of SECTIONS) await openSection(page, dict, section)
|
||||||
|
await openReferences(page, dict)
|
||||||
|
await closeReferences(page, dict)
|
||||||
expect(errors, 'page errors on the equine copy').toEqual([])
|
expect(errors, 'page errors on the equine copy').toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -314,7 +316,7 @@ test.describe('equine working copy and commit latency', () => {
|
|||||||
'equine: add category (insert)',
|
'equine: add category (insert)',
|
||||||
)
|
)
|
||||||
// A geometry edit: the first annotation's centre, through the geometry group.
|
// A geometry edit: the first annotation's centre, through the geometry group.
|
||||||
await selectTab(page, dict, 'annotations')
|
await showDrawing(page, dict)
|
||||||
await page
|
await page
|
||||||
.getByRole('list', { name: dict['editor.annotations.list'] })
|
.getByRole('list', { name: dict['editor.annotations.list'] })
|
||||||
.getByRole('button')
|
.getByRole('button')
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ import {
|
|||||||
editorActor,
|
editorActor,
|
||||||
geometryField,
|
geometryField,
|
||||||
openEditor,
|
openEditor,
|
||||||
|
openSection,
|
||||||
pointOf,
|
pointOf,
|
||||||
saveDraft,
|
saveDraft,
|
||||||
seedDraft,
|
seedDraft,
|
||||||
serverDocument,
|
|
||||||
selectTab,
|
selectTab,
|
||||||
|
serverDocument,
|
||||||
shapeWith,
|
shapeWith,
|
||||||
standardShape,
|
standardShape,
|
||||||
} from '../support/editor'
|
} from '../support/editor'
|
||||||
@@ -201,7 +202,7 @@ test.describe('editor geometry (adversarial)', () => {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
requests.forbid(actor.account.email, actor.account.password)
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
await selectTab(page, dict, 'views')
|
await openSection(page, dict, 'views')
|
||||||
const detail = page.getByRole('listitem', { name: 'Détail A' })
|
const detail = page.getByRole('listitem', { name: 'Détail A' })
|
||||||
await detail
|
await detail
|
||||||
.getByRole('button', { name: dict['editor.views.crop.toggle'] })
|
.getByRole('button', { name: dict['editor.views.crop.toggle'] })
|
||||||
@@ -257,7 +258,7 @@ test.describe('editor geometry (adversarial)', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
await openEditor(page, dict, actor, seed.sheetId)
|
await openEditor(page, dict, actor, seed.sheetId)
|
||||||
await selectTab(page, dict, 'views')
|
await openSection(page, dict, 'views')
|
||||||
await page.getByTestId('view-main-file').setInputFiles({
|
await page.getByTestId('view-main-file').setInputFiles({
|
||||||
name: 'petit.svg',
|
name: 'petit.svg',
|
||||||
mimeType: 'image/svg+xml',
|
mimeType: 'image/svg+xml',
|
||||||
@@ -344,7 +345,7 @@ test.describe('editor geometry (adversarial)', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
await openEditor(page, dict, actor, seed.sheetId)
|
await openEditor(page, dict, actor, seed.sheetId)
|
||||||
await selectTab(page, dict, 'views')
|
await openSection(page, dict, 'views')
|
||||||
await page.getByTestId('view-main-file').setInputFiles({
|
await page.getByTestId('view-main-file').setInputFiles({
|
||||||
name: 'petit.svg',
|
name: 'petit.svg',
|
||||||
mimeType: 'image/svg+xml',
|
mimeType: 'image/svg+xml',
|
||||||
|
|||||||
@@ -9,16 +9,18 @@ import {
|
|||||||
clickDrawing,
|
clickDrawing,
|
||||||
createFromPanel,
|
createFromPanel,
|
||||||
creationPanel,
|
creationPanel,
|
||||||
INKSCAPE_EXPORT,
|
|
||||||
editorActor,
|
editorActor,
|
||||||
fillCreation,
|
fillCreation,
|
||||||
geometryField,
|
geometryField,
|
||||||
|
INKSCAPE_EXPORT,
|
||||||
|
openDraft,
|
||||||
|
openSection,
|
||||||
saveDraft,
|
saveDraft,
|
||||||
serverDocument,
|
|
||||||
secondSession,
|
secondSession,
|
||||||
selectTab,
|
selectTab,
|
||||||
|
serverDocument,
|
||||||
|
showDrawing,
|
||||||
toolButton,
|
toolButton,
|
||||||
openDraft,
|
|
||||||
} from '../support/editor'
|
} from '../support/editor'
|
||||||
import { signIn } from '../support/shell'
|
import { signIn } from '../support/shell'
|
||||||
|
|
||||||
@@ -79,7 +81,7 @@ async function createSheetFromAdmin(page: Page, tag: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function importDrawing(page: Page) {
|
async function importDrawing(page: Page) {
|
||||||
await selectTab(page, dict, 'views')
|
await openSection(page, dict, 'views')
|
||||||
// The real Inkscape 1.4.3 export, cleaned by the core in the page (viewBox 0 0 200 150).
|
// The real Inkscape 1.4.3 export, cleaned by the core in the page (viewBox 0 0 200 150).
|
||||||
await page.getByTestId('view-view-main-file').setInputFiles({
|
await page.getByTestId('view-view-main-file').setInputFiles({
|
||||||
name: 'inkscape-1.4.3.svg',
|
name: 'inkscape-1.4.3.svg',
|
||||||
@@ -105,7 +107,7 @@ async function importDrawing(page: Page) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createFindings(page: Page) {
|
async function createFindings(page: Page) {
|
||||||
await selectTab(page, dict, 'general')
|
await openSection(page, dict, 'categories')
|
||||||
await page.locator('#category-new-fr').fill('Catégorie essai')
|
await page.locator('#category-new-fr').fill('Catégorie essai')
|
||||||
await page.locator('#category-new-en').fill('Trial category')
|
await page.locator('#category-new-en').fill('Trial category')
|
||||||
await clickButton(page, dict['editor.general.category_add'])
|
await clickButton(page, dict['editor.general.category_add'])
|
||||||
@@ -132,7 +134,7 @@ async function createFindings(page: Page) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createAnnotations(page: Page) {
|
async function createAnnotations(page: Page) {
|
||||||
await selectTab(page, dict, 'annotations')
|
await showDrawing(page, dict)
|
||||||
const trace = async (points: number[][]) => {
|
const trace = async (points: number[][]) => {
|
||||||
for (const [x, y] of points) await clickDrawing(page, x, y)
|
for (const [x, y] of points) await clickDrawing(page, x, y)
|
||||||
await clickButton(page, dict['editor.annotations.trace_close'])
|
await clickButton(page, dict['editor.annotations.trace_close'])
|
||||||
@@ -420,6 +422,11 @@ test.describe('editor journey (owner trial steps)', () => {
|
|||||||
`select status from public.anatomical_sheet_reviews where version_id = '${draftId}'`,
|
`select status from public.anatomical_sheet_reviews where version_id = '${draftId}'`,
|
||||||
),
|
),
|
||||||
).toBe('verifying')
|
).toBe('verifying')
|
||||||
|
// The submit button sits at the page's end: back at the header, whose « Références »
|
||||||
|
// button the sticky top bar covers while the page is scrolled.
|
||||||
|
await page
|
||||||
|
.getByRole('heading', { level: 1, name: 'Brouillon, version 1' })
|
||||||
|
.evaluate((heading) => heading.scrollIntoView({ block: 'center' }))
|
||||||
await expectAccessible(page, 'the frozen draft')
|
await expectAccessible(page, 'the frozen draft')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -4,8 +4,11 @@ import { expect, expectAccessible, test } from '../support/browser'
|
|||||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||||
import {
|
import {
|
||||||
bareShape,
|
bareShape,
|
||||||
|
closeReferences,
|
||||||
editorActor,
|
editorActor,
|
||||||
openEditor,
|
openEditor,
|
||||||
|
openReferences,
|
||||||
|
openSection,
|
||||||
pointOf,
|
pointOf,
|
||||||
saveDraft,
|
saveDraft,
|
||||||
seedDraft,
|
seedDraft,
|
||||||
@@ -13,6 +16,7 @@ import {
|
|||||||
serverDocument,
|
serverDocument,
|
||||||
serverRevision,
|
serverRevision,
|
||||||
shapeWith,
|
shapeWith,
|
||||||
|
showDrawing,
|
||||||
} from '../support/editor'
|
} from '../support/editor'
|
||||||
|
|
||||||
// V1-2.6 A4 (contract C9 to C12, C19): the structures around the drawing. Annotation
|
// V1-2.6 A4 (contract C9 to C12, C19): the structures around the drawing. Annotation
|
||||||
@@ -56,7 +60,7 @@ test.describe('editor structures (A4)', () => {
|
|||||||
requests.forbid(actor.account.email, actor.account.password)
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
|
|
||||||
// A category added, then renamed in place.
|
// A category added, then renamed in place.
|
||||||
await selectTab(page, dict, 'general')
|
await openSection(page, dict, 'categories')
|
||||||
await page.locator('#category-new-fr').fill('Catégorie B')
|
await page.locator('#category-new-fr').fill('Catégorie B')
|
||||||
await page.locator('#category-new-en').fill('Category B')
|
await page.locator('#category-new-en').fill('Category B')
|
||||||
await page
|
await page
|
||||||
@@ -67,10 +71,10 @@ test.describe('editor structures (A4)', () => {
|
|||||||
await expect(names).toHaveCount(2)
|
await expect(names).toHaveCount(2)
|
||||||
await commitText(names.nth(1), 'Catégorie B bis')
|
await commitText(names.nth(1), 'Catégorie B bis')
|
||||||
await expect(names.nth(1)).toHaveValue('Catégorie B bis')
|
await expect(names.nth(1)).toHaveValue('Catégorie B bis')
|
||||||
await expectAccessible(page, 'the general tab')
|
await expectAccessible(page, 'the categories section')
|
||||||
|
|
||||||
// Two references, the second moved up.
|
// Two references, the second moved up.
|
||||||
await selectTab(page, dict, 'references')
|
await openReferences(page, dict)
|
||||||
for (const citation of ['Première référence', 'Seconde référence']) {
|
for (const citation of ['Première référence', 'Seconde référence']) {
|
||||||
await page.locator('#reference-new-type').selectOption('book')
|
await page.locator('#reference-new-type').selectOption('book')
|
||||||
await page.locator('#reference-new-citation').fill(citation)
|
await page.locator('#reference-new-citation').fill(citation)
|
||||||
@@ -100,7 +104,8 @@ test.describe('editor structures (A4)', () => {
|
|||||||
await expect(citations).toHaveCount(1)
|
await expect(citations).toHaveCount(1)
|
||||||
|
|
||||||
// A region with its count.
|
// A region with its count.
|
||||||
await selectTab(page, dict, 'vertebrae')
|
await closeReferences(page, dict)
|
||||||
|
await openSection(page, dict, 'regions')
|
||||||
await page.locator('#region-new-code').fill('T')
|
await page.locator('#region-new-code').fill('T')
|
||||||
await page.locator('#region-new-fr').fill('Thoracique')
|
await page.locator('#region-new-fr').fill('Thoracique')
|
||||||
await page.locator('#region-new-en').fill('Thoracic')
|
await page.locator('#region-new-en').fill('Thoracic')
|
||||||
@@ -245,7 +250,7 @@ test.describe('editor structures (A4)', () => {
|
|||||||
requests.forbid(actor.account.email, actor.account.password)
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
|
|
||||||
// The category is used by the point: the dialog lists it and offers no deletion.
|
// The category is used by the point: the dialog lists it and offers no deletion.
|
||||||
await selectTab(page, dict, 'general')
|
await openSection(page, dict, 'categories')
|
||||||
await page
|
await page
|
||||||
.getByRole('listitem')
|
.getByRole('listitem')
|
||||||
.filter({ has: page.locator('#category-cat-a-name-fr') })
|
.filter({ has: page.locator('#category-cat-a-name-fr') })
|
||||||
@@ -283,7 +288,7 @@ test.describe('editor structures (A4)', () => {
|
|||||||
.click()
|
.click()
|
||||||
|
|
||||||
// The point goes first; the zone then deletes with its descendants named.
|
// The point goes first; the zone then deletes with its descendants named.
|
||||||
await selectTab(page, dict, 'annotations')
|
await showDrawing(page, dict)
|
||||||
await page
|
await page
|
||||||
.getByRole('list', { name: dict['editor.annotations.list'] })
|
.getByRole('list', { name: dict['editor.annotations.list'] })
|
||||||
.getByRole('button', { name: /Point lié/ })
|
.getByRole('button', { name: /Point lié/ })
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { createHash, randomUUID } from 'node:crypto'
|
|||||||
import { readFileSync } from 'node:fs'
|
import { readFileSync } from 'node:fs'
|
||||||
import { join } from 'node:path'
|
import { join } from 'node:path'
|
||||||
import type { Dict } from '@/i18n/types'
|
import type { Dict } from '@/i18n/types'
|
||||||
import type { Browser, BrowserContext, Page } from '@playwright/test'
|
import type { Browser, BrowserContext, Locator, Page } from '@playwright/test'
|
||||||
import {
|
import {
|
||||||
enrolTotp,
|
enrolTotp,
|
||||||
refusal,
|
refusal,
|
||||||
@@ -323,10 +323,72 @@ export async function openDraft(page: Page, dict: Dict, sheetId: string) {
|
|||||||
await expect(page.getByRole('tablist')).toBeVisible()
|
await expect(page.getByRole('tablist')).toBeVisible()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The four tabs of the editor (U1): the references moved to a panel, the rest to Annotations. */
|
||||||
|
export const TABS = [
|
||||||
|
'general',
|
||||||
|
'annotations',
|
||||||
|
'findings',
|
||||||
|
'verification',
|
||||||
|
] as const
|
||||||
|
|
||||||
|
/** The Annotations sections and the panel, in the order the overview offers them. */
|
||||||
|
export const SECTIONS = ['views', 'categories', 'regions'] as const
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clicks a tab by role. The name is a pattern: the Vérification tab adds « n erreur(s) »
|
||||||
|
* to its name while the in-page check has errors.
|
||||||
|
*/
|
||||||
export async function selectTab(page: Page, dict: Dict, tab: string) {
|
export async function selectTab(page: Page, dict: Dict, tab: string) {
|
||||||
|
const name = dict[`editor.tab.${tab}`]
|
||||||
|
await page.getByRole('tab', { name: new RegExp(`^${name}( |$)`) }).click()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The visible place with this `data-place` name; a hidden copy never answers. */
|
||||||
|
export function place(page: Page, name: string): Locator {
|
||||||
|
return page.locator(`[data-place="${name}"]:visible`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** « Retour au dessin »: leaves an Annotations section for the drawing. */
|
||||||
|
export async function backToDrawing(page: Page, dict: Dict) {
|
||||||
|
await page.getByRole('button', { name: dict['editor.section.back'] }).click()
|
||||||
|
await expect(place(page, 'annotations.drawing')).toBeVisible()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The Annotations tab on its drawing, whatever section it was left on. */
|
||||||
|
export async function showDrawing(page: Page, dict: Dict) {
|
||||||
|
await selectTab(page, dict, 'annotations')
|
||||||
|
const back = page.getByRole('button', { name: dict['editor.section.back'] })
|
||||||
|
if (await back.isVisible()) await backToDrawing(page, dict)
|
||||||
|
await expect(place(page, 'annotations.drawing')).toBeVisible()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Opens an Annotations section through its overview entry. */
|
||||||
|
export async function openSection(
|
||||||
|
page: Page,
|
||||||
|
dict: Dict,
|
||||||
|
section: (typeof SECTIONS)[number],
|
||||||
|
) {
|
||||||
|
await showDrawing(page, dict)
|
||||||
|
await page.locator(`[data-section-entry="${section}"]`).click()
|
||||||
|
await expect(place(page, `annotations.${section}`)).toBeVisible()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Opens the references panel from the header button. */
|
||||||
|
export async function openReferences(page: Page, dict: Dict) {
|
||||||
|
const toggle = page.getByRole('button', {
|
||||||
|
name: dict['editor.references.open'],
|
||||||
|
exact: true,
|
||||||
|
})
|
||||||
|
if ((await toggle.getAttribute('aria-expanded')) !== 'true')
|
||||||
|
await toggle.click()
|
||||||
|
await expect(place(page, 'references')).toBeVisible()
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function closeReferences(page: Page, dict: Dict) {
|
||||||
await page
|
await page
|
||||||
.getByRole('tab', { name: dict[`editor.tab.${tab}`], exact: true })
|
.getByRole('button', { name: dict['editor.references.close'] })
|
||||||
.click()
|
.click()
|
||||||
|
await expect(place(page, 'references')).toHaveCount(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The revision the server holds for the draft. */
|
/** The revision the server holds for the draft. */
|
||||||
|
|||||||
@@ -2,31 +2,26 @@
|
|||||||
* Global setup of the shell suite (V1-2.6): the Vite dev server discovers some
|
* Global setup of the shell suite (V1-2.6): the Vite dev server discovers some
|
||||||
* dependencies only when a route first loads them and answers with a full page
|
* dependencies only when a route first loads them and answers with a full page
|
||||||
* reload, which wiped a form a test had begun to fill. One throwaway session
|
* reload, which wiped a form a test had begun to fill. One throwaway session
|
||||||
* visits the editor routes and every tab once before the tests start, so the
|
* visits the editor routes, every tab, every Annotations section and the references panel once before the tests start, so the
|
||||||
* reload happens here and not in a test.
|
* reload happens here and not in a test.
|
||||||
*/
|
*/
|
||||||
import { chromium, type FullConfig } from '@playwright/test'
|
import { chromium, type FullConfig } from '@playwright/test'
|
||||||
import { fr } from '@/i18n/fr'
|
import { fr } from '@/i18n/fr'
|
||||||
import { stepUpAdmin } from './admin'
|
import { stepUpAdmin } from './admin'
|
||||||
import {
|
import {
|
||||||
|
TABS,
|
||||||
|
closeReferences,
|
||||||
draftPath,
|
draftPath,
|
||||||
editorActor,
|
editorActor,
|
||||||
|
openReferences,
|
||||||
|
openSection,
|
||||||
secondSession,
|
secondSession,
|
||||||
seedDraft,
|
seedDraft,
|
||||||
|
SECTIONS,
|
||||||
standardShape,
|
standardShape,
|
||||||
} from './editor'
|
} from './editor'
|
||||||
import { signIn } from './shell'
|
import { signIn } from './shell'
|
||||||
|
|
||||||
const TABS = [
|
|
||||||
'general',
|
|
||||||
'views',
|
|
||||||
'annotations',
|
|
||||||
'findings',
|
|
||||||
'references',
|
|
||||||
'vertebrae',
|
|
||||||
'verification',
|
|
||||||
] as const
|
|
||||||
|
|
||||||
export default async function warmUp(config: FullConfig): Promise<void> {
|
export default async function warmUp(config: FullConfig): Promise<void> {
|
||||||
const baseURL = config.projects[0].use.baseURL ?? ''
|
const baseURL = config.projects[0].use.baseURL ?? ''
|
||||||
const actor = await editorActor('fr')
|
const actor = await editorActor('fr')
|
||||||
@@ -42,10 +37,18 @@ export default async function warmUp(config: FullConfig): Promise<void> {
|
|||||||
}
|
}
|
||||||
for (const tab of TABS) {
|
for (const tab of TABS) {
|
||||||
await page
|
await page
|
||||||
.getByRole('tab', { name: fr[`editor.tab.${tab}`], exact: true })
|
.getByRole('tab', {
|
||||||
|
name: new RegExp(`^${fr[`editor.tab.${tab}`]}( |$)`),
|
||||||
|
})
|
||||||
.click()
|
.click()
|
||||||
await page.waitForLoadState('networkidle')
|
await page.waitForLoadState('networkidle')
|
||||||
}
|
}
|
||||||
|
for (const section of SECTIONS) {
|
||||||
|
await openSection(page, fr, section)
|
||||||
|
await page.waitForLoadState('networkidle')
|
||||||
|
}
|
||||||
|
await openReferences(page, fr)
|
||||||
|
await closeReferences(page, fr)
|
||||||
await page.goto('/app/admin/sheets/new')
|
await page.goto('/app/admin/sheets/new')
|
||||||
await page.waitForLoadState('networkidle')
|
await page.waitForLoadState('networkidle')
|
||||||
await browser.close()
|
await browser.close()
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef } from 'react'
|
||||||
import { useParams } from 'react-router-dom'
|
import { useParams } from 'react-router-dom'
|
||||||
import {
|
import {
|
||||||
getOfficialSheetAdmin,
|
getOfficialSheetAdmin,
|
||||||
type OfficialSheetAdmin,
|
type OfficialSheetAdmin,
|
||||||
} from '@faunosteo/supabase'
|
} from '@faunosteo/supabase'
|
||||||
import ConflictDialog from '@/components/editor/ConflictDialog'
|
import EditorWorkspace from '@/components/editor/EditorWorkspace'
|
||||||
import CopyIssueNotice from '@/components/editor/CopyIssueNotice'
|
|
||||||
import DraftHeader from '@/components/editor/DraftHeader'
|
|
||||||
import EditorTabBody from '@/components/editor/EditorTabBody'
|
|
||||||
import EditorTabs, { PANEL_ID } from '@/components/editor/EditorTabs'
|
|
||||||
import ModeNotice from '@/components/editor/ModeNotice'
|
|
||||||
import RecoveryNotice from '@/components/editor/RecoveryNotice'
|
|
||||||
import CatalogueFailureNotice from '@/components/catalogue/CatalogueFailureNotice'
|
import CatalogueFailureNotice from '@/components/catalogue/CatalogueFailureNotice'
|
||||||
import AccessDenied from '@/components/shell/AccessDenied'
|
import AccessDenied from '@/components/shell/AccessDenied'
|
||||||
import PermissionsUnavailable from '@/components/shell/PermissionsUnavailable'
|
import PermissionsUnavailable from '@/components/shell/PermissionsUnavailable'
|
||||||
@@ -22,7 +16,6 @@ import { failureMessage } from '@/admin/labels'
|
|||||||
import { useAdminPermissions } from '@/admin/permissions'
|
import { useAdminPermissions } from '@/admin/permissions'
|
||||||
import { isRightsRefusal, useAdminQuery } from '@/admin/useAdminQuery'
|
import { isRightsRefusal, useAdminQuery } from '@/admin/useAdminQuery'
|
||||||
import { useLeaveGuard } from '@/app/useLeaveGuard'
|
import { useLeaveGuard } from '@/app/useLeaveGuard'
|
||||||
import { saveFailureMessage } from '@/editor/messages'
|
|
||||||
import {
|
import {
|
||||||
editorMode,
|
editorMode,
|
||||||
hasEditRight,
|
hasEditRight,
|
||||||
@@ -30,12 +23,6 @@ import {
|
|||||||
storeCanEdit,
|
storeCanEdit,
|
||||||
} from '@/editor/mode'
|
} from '@/editor/mode'
|
||||||
import { leaveGuardArmed, useEditorStore } from '@/editor/state/editorStore'
|
import { leaveGuardArmed, useEditorStore } from '@/editor/state/editorStore'
|
||||||
import { FocusConsumedContext, type FocusRequest } from '@/editor/focusRequest'
|
|
||||||
import {
|
|
||||||
initialTab,
|
|
||||||
type EditorTabId,
|
|
||||||
type EditorTabProps,
|
|
||||||
} from '@/editor/tabs'
|
|
||||||
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
||||||
import { useTabTier } from '@/editor/useViewport'
|
import { useTabTier } from '@/editor/useViewport'
|
||||||
import { useAuthStore } from '@/state/authStore'
|
import { useAuthStore } from '@/state/authStore'
|
||||||
@@ -50,22 +37,6 @@ interface DraftEditorProps {
|
|||||||
reloadSheet: () => void
|
reloadSheet: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A refused save under the header, phrased from the closed kind and the copy's real flag. */
|
|
||||||
function SaveFailureNotice() {
|
|
||||||
const t = useT()
|
|
||||||
const failure = useEditorStore((s) => s.saveFailure)
|
|
||||||
const unsaved = useEditorStore((s) => s.unsaved)
|
|
||||||
const copyWritten = useEditorStore((s) => s.copyWritten)
|
|
||||||
const conflictOpen = useEditorStore((s) => s.conflict !== null)
|
|
||||||
if (failure === null || (failure === 'draft_conflict' && conflictOpen))
|
|
||||||
return null
|
|
||||||
return (
|
|
||||||
<Notice tone="error">
|
|
||||||
{saveFailureMessage(t, failure, { unsaved, copyWritten })}
|
|
||||||
</Notice>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The draft page once the sheet is read: opens the store session for this version, derives
|
* The draft page once the sheet is read: opens the store session for this version, derives
|
||||||
* the mode, and renders what the store holds. Components only render and call actions.
|
* the mode, and renders what the store holds. Components only render and call actions.
|
||||||
@@ -79,31 +50,17 @@ function DraftEditor({
|
|||||||
}: DraftEditorProps) {
|
}: DraftEditorProps) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const tier = useTabTier()
|
const tier = useTabTier()
|
||||||
const [chosen, setTab] = useState<EditorTabId | null>(null)
|
|
||||||
const [focus, setFocus] = useState<FocusRequest | undefined>()
|
|
||||||
const clearFocus = (serial: number) =>
|
|
||||||
setFocus((prev) => (prev?.serial === serial ? undefined : prev))
|
|
||||||
const goTo: EditorTabProps['onGoTo'] = (next, key) => {
|
|
||||||
setTab(next)
|
|
||||||
setFocus((prev) => ({ key, serial: (prev?.serial ?? 0) + 1 }))
|
|
||||||
}
|
|
||||||
const saveFailure = useEditorStore((s) => s.saveFailure)
|
const saveFailure = useEditorStore((s) => s.saveFailure)
|
||||||
const status = useEditorStore((s) => s.status)
|
const status = useEditorStore((s) => s.status)
|
||||||
const sessionVersion = useEditorStore((s) => s.versionId)
|
const sessionVersion = useEditorStore((s) => s.versionId)
|
||||||
const failure = useEditorStore((s) => s.failure)
|
const failure = useEditorStore((s) => s.failure)
|
||||||
const recovery = useEditorStore((s) => s.recovery)
|
const recovery = useEditorStore((s) => s.recovery)
|
||||||
const previewState = useEditorStore((s) => s.previewState)
|
|
||||||
const opened = status === 'ready' && sessionVersion === versionId
|
|
||||||
// Chosen once per opened version: later edits never move the user off their tab.
|
|
||||||
if (chosen === null && opened && previewState) {
|
|
||||||
setTab(initialTab(previewState, tier))
|
|
||||||
}
|
|
||||||
const tab = chosen ?? 'annotations'
|
|
||||||
const mode = modeAfterSave(
|
const mode = modeAfterSave(
|
||||||
editorMode({ hasRight, sheet, wide: tier === 'wide' }),
|
editorMode({ hasRight, sheet, wide: tier === 'wide' }),
|
||||||
saveFailure,
|
saveFailure,
|
||||||
)
|
)
|
||||||
const canEdit = storeCanEdit(mode)
|
const canEdit = storeCanEdit(mode)
|
||||||
|
const readOnly = mode !== 'edit' || recovery !== 'none'
|
||||||
const firstCanEdit = useRef(canEdit)
|
const firstCanEdit = useRef(canEdit)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -114,7 +71,7 @@ function DraftEditor({
|
|||||||
}, [versionId, userId])
|
}, [versionId, userId])
|
||||||
useEffect(() => useEditorStore.getState().setCanEdit(canEdit), [canEdit])
|
useEffect(() => useEditorStore.getState().setCanEdit(canEdit), [canEdit])
|
||||||
useLeaveGuard(useEditorStore(leaveGuardArmed))
|
useLeaveGuard(useEditorStore(leaveGuardArmed))
|
||||||
useUndoShortcuts(mode === 'edit' && recovery === 'none')
|
useUndoShortcuts(!readOnly)
|
||||||
|
|
||||||
if (status === 'failed' && failure !== null) {
|
if (status === 'failed' && failure !== null) {
|
||||||
if (failure === 'denied') return <AccessDenied />
|
if (failure === 'denied') return <AccessDenied />
|
||||||
@@ -129,29 +86,14 @@ function DraftEditor({
|
|||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const readOnly = mode !== 'edit' || recovery !== 'none'
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<EditorWorkspace
|
||||||
<DraftHeader sheet={sheet} mode={mode} />
|
sheet={sheet}
|
||||||
<ModeNotice mode={mode} sheet={sheet} />
|
mode={mode}
|
||||||
<SaveFailureNotice />
|
|
||||||
<RecoveryNotice />
|
|
||||||
<CopyIssueNotice />
|
|
||||||
<EditorTabs active={tab} tier={tier} onSelect={setTab} />
|
|
||||||
<div id={PANEL_ID} role="tabpanel" aria-label={t(`editor.tab.${tab}`)}>
|
|
||||||
<FocusConsumedContext value={clearFocus}>
|
|
||||||
<EditorTabBody
|
|
||||||
tab={tab}
|
|
||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
onSelectTab={setTab}
|
tier={tier}
|
||||||
focus={focus}
|
|
||||||
onGoTo={goTo}
|
|
||||||
reloadSheet={reloadSheet}
|
reloadSheet={reloadSheet}
|
||||||
/>
|
/>
|
||||||
</FocusConsumedContext>
|
|
||||||
</div>
|
|
||||||
<ConflictDialog />
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,40 +2,14 @@ import { useState } from 'react'
|
|||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import type { OfficialSheetAdmin } from '@faunosteo/supabase'
|
import type { OfficialSheetAdmin } from '@faunosteo/supabase'
|
||||||
import Badge from '@/components/ui/Badge'
|
import Badge from '@/components/ui/Badge'
|
||||||
import Button from '@/components/ui/Button'
|
|
||||||
import Icon from '@/components/ui/Icon'
|
import Icon from '@/components/ui/Icon'
|
||||||
import Notice from '@/components/ui/Notice'
|
import Notice from '@/components/ui/Notice'
|
||||||
import { localized } from '@/admin/labels'
|
import { localized } from '@/admin/labels'
|
||||||
import { loadFailureMessage } from '@/editor/messages'
|
|
||||||
import type { EditorMode } from '@/editor/mode'
|
import type { EditorMode } from '@/editor/mode'
|
||||||
import { useEditorStore } from '@/editor/state/editorStore'
|
|
||||||
import { usePageHeading } from '@/app/usePageHeading'
|
import { usePageHeading } from '@/app/usePageHeading'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import ConfirmDialog from './ConfirmDialog'
|
import HeaderActions from './HeaderActions'
|
||||||
|
|
||||||
type Translate = ReturnType<typeof useT>
|
|
||||||
|
|
||||||
interface Status {
|
|
||||||
copyIssue: 'cap' | 'quota' | null
|
|
||||||
saving: boolean
|
|
||||||
unsaved: boolean
|
|
||||||
revision: number
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Board 04's line; only the copy failures replace it (the copy is temporary, this tab's). */
|
|
||||||
function statusText(t: Translate, status: Status): string {
|
|
||||||
if (status.copyIssue !== null)
|
|
||||||
return t(`editor.draft.status.copy_${status.copyIssue}`)
|
|
||||||
if (status.saving) return t('editor.draft.status.saving')
|
|
||||||
const revision = t('editor.draft.status.revision').replace(
|
|
||||||
'{revision}',
|
|
||||||
String(status.revision),
|
|
||||||
)
|
|
||||||
return status.unsaved
|
|
||||||
? `${revision} · ${t('editor.draft.status.unsaved')}`
|
|
||||||
: revision
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Breadcrumb of board 04: Administration › Fiches officielles › the sheet › the draft. */
|
/** Breadcrumb of board 04: Administration › Fiches officielles › the sheet › the draft. */
|
||||||
function Breadcrumb({
|
function Breadcrumb({
|
||||||
@@ -71,42 +45,27 @@ function Breadcrumb({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The draft's header: title and badges, the revision line with the unsaved state, and in
|
* The draft's header: breadcrumb, title and badges, then the actions (references, the
|
||||||
* edit mode « Annuler les modifications » (confirmed) and « Enregistrer ». « Annuler les
|
* save line, « Abandonner les modifications » and « Enregistrer » in edit mode).
|
||||||
* modifications » is the store's `discardChanges`; with an older base it reloads.
|
|
||||||
*/
|
*/
|
||||||
export default function DraftHeader({
|
export default function DraftHeader({
|
||||||
sheet,
|
sheet,
|
||||||
mode,
|
mode,
|
||||||
|
referencesOpen,
|
||||||
|
onToggleReferences,
|
||||||
}: {
|
}: {
|
||||||
sheet: OfficialSheetAdmin
|
sheet: OfficialSheetAdmin
|
||||||
mode: EditorMode
|
mode: EditorMode
|
||||||
|
referencesOpen: boolean
|
||||||
|
onToggleReferences: (opener: HTMLElement) => void
|
||||||
}) {
|
}) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const heading = usePageHeading()
|
const heading = usePageHeading()
|
||||||
const unsaved = useEditorStore((s) => s.unsaved)
|
|
||||||
const saving = useEditorStore((s) => s.saving)
|
|
||||||
const blocked = useEditorStore((s) => s.recovery !== 'none')
|
|
||||||
const revision = useEditorStore((s) => s.savedRevision)
|
|
||||||
const copyIssue = useEditorStore((s) => s.copyIssue)
|
|
||||||
const [asking, setAsking] = useState(false)
|
|
||||||
const [failure, setFailure] = useState<string | null>(null)
|
const [failure, setFailure] = useState<string | null>(null)
|
||||||
const title = t('editor.draft.title').replace(
|
const title = t('editor.draft.title').replace(
|
||||||
'{number}',
|
'{number}',
|
||||||
String(sheet.draft_version?.version_number ?? ''),
|
String(sheet.draft_version?.version_number ?? ''),
|
||||||
)
|
)
|
||||||
|
|
||||||
const discard = async () => {
|
|
||||||
setAsking(false)
|
|
||||||
const result = await useEditorStore
|
|
||||||
.getState()
|
|
||||||
.discardChanges({ confirmed: true })
|
|
||||||
setFailure(
|
|
||||||
!result.ok && result.reason === 'load'
|
|
||||||
? loadFailureMessage(t, result.failure)
|
|
||||||
: null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<header className="space-y-3">
|
<header className="space-y-3">
|
||||||
<Breadcrumb sheet={sheet} title={title} />
|
<Breadcrumb sheet={sheet} title={title} />
|
||||||
@@ -126,42 +85,14 @@ export default function DraftHeader({
|
|||||||
{t('editor.draft.read_only')}
|
{t('editor.draft.read_only')}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
<p
|
<HeaderActions
|
||||||
role="status"
|
editable={mode === 'edit'}
|
||||||
className="ml-auto text-sm text-[var(--color-ink-muted)]"
|
referencesOpen={referencesOpen}
|
||||||
>
|
onToggleReferences={onToggleReferences}
|
||||||
{statusText(t, { copyIssue, saving, unsaved, revision })}
|
onFailure={setFailure}
|
||||||
</p>
|
/>
|
||||||
{mode === 'edit' && (
|
|
||||||
<div className="flex flex-wrap gap-2">
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="secondary"
|
|
||||||
disabled={!unsaved || saving || blocked}
|
|
||||||
onClick={() => setAsking(true)}
|
|
||||||
>
|
|
||||||
{t('editor.draft.discard')}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
disabled={!unsaved || saving || blocked}
|
|
||||||
onClick={() => void useEditorStore.getState().save()}
|
|
||||||
>
|
|
||||||
{t('common.save')}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
{failure && <Notice tone="error">{failure}</Notice>}
|
{failure && <Notice tone="error">{failure}</Notice>}
|
||||||
<ConfirmDialog
|
|
||||||
open={asking}
|
|
||||||
title={t('editor.draft.discard')}
|
|
||||||
body={t('editor.draft.discard_ask')}
|
|
||||||
confirmLabel={t('editor.draft.discard_confirm')}
|
|
||||||
cancelLabel={t('common.cancel')}
|
|
||||||
onConfirm={() => void discard()}
|
|
||||||
onCancel={() => setAsking(false)}
|
|
||||||
/>
|
|
||||||
</header>
|
</header>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,53 @@
|
|||||||
import type { ComponentType } from 'react'
|
import type { ComponentType } from 'react'
|
||||||
import type { EditorTabId, EditorTabProps } from '@/editor/tabs'
|
import type { AnnotationSection } from '@/editor/navigation'
|
||||||
|
import {
|
||||||
|
panelDomId,
|
||||||
|
type EditorPlaceProps,
|
||||||
|
type EditorTabId,
|
||||||
|
} from '@/editor/tabs'
|
||||||
|
import { useT } from '@/i18n/useT'
|
||||||
import AnnotationsTab from './tabs/AnnotationsTab'
|
import AnnotationsTab from './tabs/AnnotationsTab'
|
||||||
import FindingsTab from './tabs/FindingsTab'
|
import FindingsTab from './tabs/FindingsTab'
|
||||||
import GeneralTab from './tabs/GeneralTab'
|
import GeneralTab from './tabs/GeneralTab'
|
||||||
import ReferencesTab from './tabs/ReferencesTab'
|
|
||||||
import VerificationTab from './tabs/VerificationTab'
|
import VerificationTab from './tabs/VerificationTab'
|
||||||
import VertebraeTab from './tabs/VertebraeTab'
|
|
||||||
import ViewsTab from './tabs/ViewsTab'
|
|
||||||
|
|
||||||
/** One component per tab (Lots F-J fill them); only the active one is mounted. */
|
const BODIES: Record<
|
||||||
const BODIES: Record<EditorTabId, ComponentType<EditorTabProps>> = {
|
Exclude<EditorTabId, 'annotations'>,
|
||||||
|
ComponentType<EditorPlaceProps>
|
||||||
|
> = {
|
||||||
general: GeneralTab,
|
general: GeneralTab,
|
||||||
views: ViewsTab,
|
|
||||||
annotations: AnnotationsTab,
|
|
||||||
findings: FindingsTab,
|
findings: FindingsTab,
|
||||||
references: ReferencesTab,
|
|
||||||
vertebrae: VertebraeTab,
|
|
||||||
verification: VerificationTab,
|
verification: VerificationTab,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function EditorTabBody({
|
/** What only the Annotations tab needs beyond the common place props. */
|
||||||
tab,
|
export interface AnnotationNav {
|
||||||
...props
|
section: AnnotationSection
|
||||||
}: EditorTabProps & { tab: EditorTabId }) {
|
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
|
||||||
const Body = BODIES[tab]
|
onBack: () => void
|
||||||
return <Body {...props} />
|
}
|
||||||
|
|
||||||
|
interface Props extends EditorPlaceProps {
|
||||||
|
tab: EditorTabId
|
||||||
|
annotations: AnnotationNav
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The panel of the active tab; a place unmounts when left (kept alive in Lot B2). */
|
||||||
|
export default function EditorTabBody({ tab, annotations, ...props }: Props) {
|
||||||
|
const t = useT()
|
||||||
|
const Body = tab === 'annotations' ? null : BODIES[tab]
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
id={panelDomId(tab)}
|
||||||
|
role="tabpanel"
|
||||||
|
aria-label={t(`editor.tab.${tab}`)}
|
||||||
|
data-place={Body ? tab : undefined}
|
||||||
|
>
|
||||||
|
{Body ? (
|
||||||
|
<Body {...props} />
|
||||||
|
) : (
|
||||||
|
<AnnotationsTab {...props} {...annotations} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
import { useState, type KeyboardEvent } from 'react'
|
import { useState, type KeyboardEvent } from 'react'
|
||||||
import { useEditorStore } from '@/editor/state/editorStore'
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
import { tabsFor, type EditorTabId } from '@/editor/tabs'
|
import { usePlural } from '@/editor/plural'
|
||||||
|
import {
|
||||||
|
MORE_BUTTON_ID,
|
||||||
|
panelDomId,
|
||||||
|
tabDomId,
|
||||||
|
tabsFor,
|
||||||
|
type EditorTabId,
|
||||||
|
} from '@/editor/tabs'
|
||||||
import type { TabTier } from '@/editor/useViewport'
|
import type { TabTier } from '@/editor/useViewport'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
export const PANEL_ID = 'editor-panel'
|
|
||||||
export const tabDomId = (tab: EditorTabId) => `editor-tab-${tab}`
|
|
||||||
|
|
||||||
const BASE =
|
const BASE =
|
||||||
'min-h-11 whitespace-nowrap border-b-2 px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
|
'min-h-11 whitespace-nowrap border-b-2 px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
|
||||||
const ACTIVE =
|
const ACTIVE =
|
||||||
@@ -14,8 +18,9 @@ const ACTIVE =
|
|||||||
const IDLE =
|
const IDLE =
|
||||||
'border-transparent text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]'
|
'border-transparent text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]'
|
||||||
|
|
||||||
/** The blocking-error count on the Vérification tab; absent at zero. */
|
/** The blocking-error count on the Vérification tab, as text; absent at zero. */
|
||||||
function ErrorCount({ tab }: { tab: EditorTabId }) {
|
function ErrorCount({ tab }: { tab: EditorTabId }) {
|
||||||
|
const plural = usePlural()
|
||||||
const count = useEditorStore(
|
const count = useEditorStore(
|
||||||
(s) =>
|
(s) =>
|
||||||
s.previewState?.report.issues.filter((i) => i.severity === 'error')
|
s.previewState?.report.issues.filter((i) => i.severity === 'error')
|
||||||
@@ -23,35 +28,24 @@ function ErrorCount({ tab }: { tab: EditorTabId }) {
|
|||||||
)
|
)
|
||||||
if (tab !== 'verification' || count === 0) return null
|
if (tab !== 'verification' || count === 0) return null
|
||||||
return (
|
return (
|
||||||
<span
|
<>
|
||||||
aria-hidden="true"
|
{' '}
|
||||||
className="ml-2 rounded-md bg-red-50 px-1.5 text-xs text-red-700"
|
<span className="ml-1 rounded-md bg-red-50 px-1.5 text-xs text-red-700">
|
||||||
>
|
{plural('editor.tab.errors', count)}
|
||||||
{count}
|
|
||||||
</span>
|
</span>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EditorTabsProps {
|
interface TabListProps {
|
||||||
|
shown: readonly EditorTabId[]
|
||||||
active: EditorTabId
|
active: EditorTabId
|
||||||
tier: TabTier
|
|
||||||
onSelect: (tab: EditorTabId) => void
|
onSelect: (tab: EditorTabId) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** The tablist proper: the shown tabs only, arrows move between them. */
|
||||||
* The draft's tabs (boards 04 and 05): all seven wide, the static lists of 640 px and over
|
function TabList({ shown, active, onSelect }: TabListProps) {
|
||||||
* and below it narrow, with « Plus » opening a disclosure of the others (no measurement).
|
|
||||||
*/
|
|
||||||
export default function EditorTabs({
|
|
||||||
active,
|
|
||||||
tier,
|
|
||||||
onSelect,
|
|
||||||
}: EditorTabsProps) {
|
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const { shown, more } = tabsFor(tier)
|
|
||||||
const [open, setOpen] = useState(false)
|
|
||||||
const moreActive = more.includes(active)
|
|
||||||
|
|
||||||
const onKeyDown = (event: KeyboardEvent) => {
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
const at = shown.indexOf(active)
|
const at = shown.indexOf(active)
|
||||||
const step =
|
const step =
|
||||||
@@ -62,14 +56,7 @@ export default function EditorTabs({
|
|||||||
onSelect(next)
|
onSelect(next)
|
||||||
document.getElementById(tabDomId(next))?.focus()
|
document.getElementById(tabDomId(next))?.focus()
|
||||||
}
|
}
|
||||||
const pick = (tab: EditorTabId) => {
|
|
||||||
onSelect(tab)
|
|
||||||
setOpen(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
|
||||||
<div className="flex items-end gap-1 overflow-x-auto border-b border-[var(--color-border)]">
|
|
||||||
<div
|
<div
|
||||||
role="tablist"
|
role="tablist"
|
||||||
aria-label={t('editor.tab.list')}
|
aria-label={t('editor.tab.list')}
|
||||||
@@ -83,7 +70,7 @@ export default function EditorTabs({
|
|||||||
type="button"
|
type="button"
|
||||||
role="tab"
|
role="tab"
|
||||||
aria-selected={tab === active}
|
aria-selected={tab === active}
|
||||||
aria-controls={PANEL_ID}
|
aria-controls={panelDomId(tab)}
|
||||||
tabIndex={tab === active ? 0 : -1}
|
tabIndex={tab === active ? 0 : -1}
|
||||||
onClick={() => onSelect(tab)}
|
onClick={() => onSelect(tab)}
|
||||||
className={`-mb-px ${BASE} ${tab === active ? ACTIVE : IDLE}`}
|
className={`-mb-px ${BASE} ${tab === active ? ACTIVE : IDLE}`}
|
||||||
@@ -93,22 +80,39 @@ export default function EditorTabs({
|
|||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
{more.length > 0 && (
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MoreTabsProps {
|
||||||
|
more: readonly EditorTabId[]
|
||||||
|
active: EditorTabId
|
||||||
|
onSelect: (tab: EditorTabId) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Below 640 px: « Plus » and its disclosure of the tabs that do not fit. */
|
||||||
|
function MoreTabs({ more, active, onSelect }: MoreTabsProps) {
|
||||||
|
const t = useT()
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const pick = (tab: EditorTabId) => {
|
||||||
|
onSelect(tab)
|
||||||
|
setOpen(false)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
<button
|
<button
|
||||||
|
id={MORE_BUTTON_ID}
|
||||||
type="button"
|
type="button"
|
||||||
aria-expanded={open}
|
aria-expanded={open}
|
||||||
aria-controls="editor-tabs-more"
|
aria-controls="editor-tabs-more"
|
||||||
onClick={() => setOpen((value) => !value)}
|
onClick={() => setOpen((value) => !value)}
|
||||||
className={`-mb-px ${BASE} ${moreActive ? ACTIVE : IDLE}`}
|
className={`-mb-px ${BASE} ${more.includes(active) ? ACTIVE : IDLE}`}
|
||||||
>
|
>
|
||||||
{t('editor.tab.more')}
|
{t('editor.tab.more')}
|
||||||
</button>
|
</button>
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{open && (
|
{open && (
|
||||||
<ul
|
<ul
|
||||||
id="editor-tabs-more"
|
id="editor-tabs-more"
|
||||||
className="flex flex-wrap gap-1 border-b border-[var(--color-border)] py-1"
|
className="order-last flex w-full flex-wrap gap-1 border-t border-[var(--color-border)] py-1"
|
||||||
>
|
>
|
||||||
{more.map((tab) => (
|
{more.map((tab) => (
|
||||||
<li key={tab}>
|
<li key={tab}>
|
||||||
@@ -126,6 +130,32 @@ export default function EditorTabs({
|
|||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EditorTabsProps {
|
||||||
|
active: EditorTabId
|
||||||
|
tier: TabTier
|
||||||
|
onSelect: (tab: EditorTabId) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The draft's tab row (boards 04 and 05): the four tabs from 640 px, Annotations and
|
||||||
|
* Vérification below it with « Plus » opening a disclosure of the others (no measurement).
|
||||||
|
*/
|
||||||
|
export default function EditorTabs({
|
||||||
|
active,
|
||||||
|
tier,
|
||||||
|
onSelect,
|
||||||
|
}: EditorTabsProps) {
|
||||||
|
const { shown, more } = tabsFor(tier)
|
||||||
|
return (
|
||||||
|
<div className="flex flex-wrap items-end gap-1 border-b border-[var(--color-border)]">
|
||||||
|
<TabList shown={shown} active={active} onSelect={onSelect} />
|
||||||
|
{more.length > 0 && (
|
||||||
|
<MoreTabs more={more} active={active} onSelect={onSelect} />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import type { OfficialSheetAdmin } from '@faunosteo/supabase'
|
||||||
|
import Notice from '@/components/ui/Notice'
|
||||||
|
import {
|
||||||
|
AnnounceContext,
|
||||||
|
FocusConsumedContext,
|
||||||
|
ownedBy,
|
||||||
|
type PlaceName,
|
||||||
|
} from '@/editor/focusRequest'
|
||||||
|
import { saveFailureMessage } from '@/editor/messages'
|
||||||
|
import type { EditorMode } from '@/editor/mode'
|
||||||
|
import type { NavigationState } from '@/editor/navigation'
|
||||||
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
|
import { initialTab } from '@/editor/tabs'
|
||||||
|
import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
||||||
|
import type { TabTier } from '@/editor/useViewport'
|
||||||
|
import { useT } from '@/i18n/useT'
|
||||||
|
import ConflictDialog from './ConflictDialog'
|
||||||
|
import CopyIssueNotice from './CopyIssueNotice'
|
||||||
|
import DraftHeader from './DraftHeader'
|
||||||
|
import EditorTabBody from './EditorTabBody'
|
||||||
|
import EditorTabs from './EditorTabs'
|
||||||
|
import ModeNotice from './ModeNotice'
|
||||||
|
import RecoveryNotice from './RecoveryNotice'
|
||||||
|
import ReferencesPanel from './references/ReferencesPanel'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
sheet: OfficialSheetAdmin
|
||||||
|
mode: EditorMode
|
||||||
|
/** Not editable now: a mode that cannot save, or a recovery offer not answered yet. */
|
||||||
|
readOnly: boolean
|
||||||
|
tier: TabTier
|
||||||
|
reloadSheet: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A refused save under the header, phrased from the closed kind and the copy's real flag. */
|
||||||
|
function SaveFailureNotice() {
|
||||||
|
const t = useT()
|
||||||
|
const failure = useEditorStore((s) => s.saveFailure)
|
||||||
|
const unsaved = useEditorStore((s) => s.unsaved)
|
||||||
|
const copyWritten = useEditorStore((s) => s.copyWritten)
|
||||||
|
const conflictOpen = useEditorStore((s) => s.conflict !== null)
|
||||||
|
if (failure === null || (failure === 'draft_conflict' && conflictOpen))
|
||||||
|
return null
|
||||||
|
return (
|
||||||
|
<Notice tone="error">
|
||||||
|
{saveFailureMessage(t, failure, { unsaved, copyWritten })}
|
||||||
|
</Notice>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The `data-place` the shown tab and section name. */
|
||||||
|
function shownPlace({ tab, section }: NavigationState): PlaceName {
|
||||||
|
return tab === 'annotations' ? `annotations.${section}` : tab
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The draft page once the version is ready: header, notices, tab row, the references
|
||||||
|
* panel and the shown place. Owns the navigation state, so the first tab is known at
|
||||||
|
* mount (`initialTab`) and later edits never move the user off their tab.
|
||||||
|
*/
|
||||||
|
export default function EditorWorkspace(props: Props) {
|
||||||
|
const { sheet, mode, readOnly, tier, reloadSheet } = props
|
||||||
|
const previewState = useEditorStore((s) => s.previewState)
|
||||||
|
const nav = useEditorNavigation(
|
||||||
|
previewState ? initialTab(previewState, tier) : 'annotations',
|
||||||
|
)
|
||||||
|
const { state } = nav
|
||||||
|
const toggleReferences = (opener: HTMLElement) =>
|
||||||
|
state.references.open
|
||||||
|
? nav.closeReferences()
|
||||||
|
: nav.openReferences(null, opener)
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<DraftHeader
|
||||||
|
sheet={sheet}
|
||||||
|
mode={mode}
|
||||||
|
referencesOpen={state.references.open}
|
||||||
|
onToggleReferences={toggleReferences}
|
||||||
|
/>
|
||||||
|
<ModeNotice mode={mode} sheet={sheet} />
|
||||||
|
<SaveFailureNotice />
|
||||||
|
<RecoveryNotice />
|
||||||
|
<CopyIssueNotice />
|
||||||
|
<EditorTabs active={state.tab} tier={tier} onSelect={nav.selectTab} />
|
||||||
|
<FocusConsumedContext value={nav.consumed}>
|
||||||
|
<AnnounceContext value={nav.announce}>
|
||||||
|
{state.referencesMounted && (
|
||||||
|
<ReferencesPanel
|
||||||
|
readOnly={readOnly}
|
||||||
|
focus={ownedBy(state.focus, 'references')}
|
||||||
|
open={state.references.open}
|
||||||
|
onClose={nav.closeReferences}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<EditorTabBody
|
||||||
|
tab={state.tab}
|
||||||
|
readOnly={readOnly}
|
||||||
|
navigate={nav.navigate}
|
||||||
|
focus={ownedBy(state.focus, shownPlace(state))}
|
||||||
|
reloadSheet={reloadSheet}
|
||||||
|
annotations={{
|
||||||
|
section: state.section,
|
||||||
|
onOpenSection: nav.openSection,
|
||||||
|
onBack: nav.backToDrawing,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</AnnounceContext>
|
||||||
|
</FocusConsumedContext>
|
||||||
|
<p aria-live="polite" className="sr-only">
|
||||||
|
{nav.live}
|
||||||
|
</p>
|
||||||
|
<ConflictDialog />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import Button from '@/components/ui/Button'
|
||||||
|
import Icon from '@/components/ui/Icon'
|
||||||
|
import { loadFailureMessage } from '@/editor/messages'
|
||||||
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
|
import { REFERENCES_BUTTON_ID } from '@/editor/tabs'
|
||||||
|
import { useT } from '@/i18n/useT'
|
||||||
|
import ConfirmDialog from './ConfirmDialog'
|
||||||
|
import SaveLine from './SaveLine'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
/** Edit mode: « Abandonner » and « Enregistrer » are offered. */
|
||||||
|
editable: boolean
|
||||||
|
referencesOpen: boolean
|
||||||
|
onToggleReferences: (opener: HTMLElement) => void
|
||||||
|
/** A failed reload after a discard, worded for the notice under the header. */
|
||||||
|
onFailure: (message: string | null) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/** « Abandonner les modifications »: asks first, then the store reloads the server draft. */
|
||||||
|
function DiscardButton({ onFailure }: Pick<Props, 'onFailure'>) {
|
||||||
|
const t = useT()
|
||||||
|
const unsaved = useEditorStore((s) => s.unsaved)
|
||||||
|
const saving = useEditorStore((s) => s.saving)
|
||||||
|
const blocked = useEditorStore((s) => s.recovery !== 'none')
|
||||||
|
const [asking, setAsking] = useState(false)
|
||||||
|
const discard = async () => {
|
||||||
|
setAsking(false)
|
||||||
|
const result = await useEditorStore
|
||||||
|
.getState()
|
||||||
|
.discardChanges({ confirmed: true })
|
||||||
|
onFailure(
|
||||||
|
!result.ok && result.reason === 'load'
|
||||||
|
? loadFailureMessage(t, result.failure)
|
||||||
|
: null,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
disabled={!unsaved || saving || blocked}
|
||||||
|
onClick={() => setAsking(true)}
|
||||||
|
>
|
||||||
|
{t('editor.draft.discard')}
|
||||||
|
</Button>
|
||||||
|
<ConfirmDialog
|
||||||
|
open={asking}
|
||||||
|
title={t('editor.draft.discard')}
|
||||||
|
body={t('editor.draft.discard_ask')}
|
||||||
|
confirmLabel={t('editor.draft.discard_confirm')}
|
||||||
|
cancelLabel={t('common.cancel')}
|
||||||
|
onConfirm={() => void discard()}
|
||||||
|
onCancel={() => setAsking(false)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SaveButton() {
|
||||||
|
const t = useT()
|
||||||
|
const unsaved = useEditorStore((s) => s.unsaved)
|
||||||
|
const saving = useEditorStore((s) => s.saving)
|
||||||
|
const blocked = useEditorStore((s) => s.recovery !== 'none')
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
disabled={!unsaved || saving || blocked}
|
||||||
|
onClick={() => void useEditorStore.getState().save()}
|
||||||
|
>
|
||||||
|
{t('common.save')}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The right group of the header: references, the save line, discard and save. */
|
||||||
|
export default function HeaderActions(props: Props) {
|
||||||
|
const t = useT()
|
||||||
|
return (
|
||||||
|
<div className="ml-auto flex flex-wrap items-center gap-2">
|
||||||
|
<Button
|
||||||
|
id={REFERENCES_BUTTON_ID}
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
aria-expanded={props.referencesOpen}
|
||||||
|
aria-controls="editor-references-panel"
|
||||||
|
onClick={(event) => props.onToggleReferences(event.currentTarget)}
|
||||||
|
>
|
||||||
|
<Icon name="book" size={16} className="mr-2" />
|
||||||
|
{t('editor.references.open')}
|
||||||
|
</Button>
|
||||||
|
<span
|
||||||
|
aria-hidden="true"
|
||||||
|
className="hidden h-6 w-px bg-[var(--color-border)] sm:block"
|
||||||
|
/>
|
||||||
|
<SaveLine />
|
||||||
|
{props.editable && (
|
||||||
|
<>
|
||||||
|
<DiscardButton onFailure={props.onFailure} />
|
||||||
|
<SaveButton />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
|
type Translate = ReturnType<typeof useT>
|
||||||
|
|
||||||
|
interface Status {
|
||||||
|
copyIssue: 'cap' | 'quota' | null
|
||||||
|
saving: boolean
|
||||||
|
unsaved: boolean
|
||||||
|
revision: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Board 04's line; only the copy failures replace it (the copy is temporary, this tab's). */
|
||||||
|
function statusText(t: Translate, status: Status): string {
|
||||||
|
if (status.copyIssue !== null)
|
||||||
|
return t(`editor.draft.status.copy_${status.copyIssue}`)
|
||||||
|
if (status.saving) return t('editor.draft.status.saving')
|
||||||
|
const revision = t('editor.draft.status.revision').replace(
|
||||||
|
'{revision}',
|
||||||
|
String(status.revision),
|
||||||
|
)
|
||||||
|
return status.unsaved
|
||||||
|
? `${revision} · ${t('editor.draft.status.unsaved')}`
|
||||||
|
: revision
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The revision line with its unsaved state, announced politely when it changes. */
|
||||||
|
export default function SaveLine() {
|
||||||
|
const t = useT()
|
||||||
|
const unsaved = useEditorStore((s) => s.unsaved)
|
||||||
|
const saving = useEditorStore((s) => s.saving)
|
||||||
|
const revision = useEditorStore((s) => s.savedRevision)
|
||||||
|
const copyIssue = useEditorStore((s) => s.copyIssue)
|
||||||
|
return (
|
||||||
|
<p role="status" className="text-sm text-[var(--color-ink-muted)]">
|
||||||
|
{statusText(t, { copyIssue, saving, unsaved, revision })}
|
||||||
|
</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -87,7 +87,13 @@ export default function CreationPanel(props: CreationPanelProps) {
|
|||||||
data-testid="annotation-creation"
|
data-testid="annotation-creation"
|
||||||
className="space-y-3 rounded-xl border border-[var(--color-border)] p-4"
|
className="space-y-3 rounded-xl border border-[var(--color-border)] p-4"
|
||||||
>
|
>
|
||||||
<h3 className="text-base font-semibold">{title}</h3>
|
<h3
|
||||||
|
tabIndex={-1}
|
||||||
|
data-creation-heading
|
||||||
|
className="outline-none text-base font-semibold"
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</h3>
|
||||||
<CreationFields
|
<CreationFields
|
||||||
kind={pending.kind}
|
kind={pending.kind}
|
||||||
viewId={props.viewId}
|
viewId={props.viewId}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useReducer, useState, type Dispatch } from 'react'
|
import { useEffect, useReducer, useState, type Dispatch } from 'react'
|
||||||
import type {
|
import type {
|
||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
Annotation,
|
Annotation,
|
||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
||||||
import { annotationFocus } from '@/editor/annotations/focusTarget'
|
import { useAnnotationRequest } from '@/editor/annotations/focusTarget'
|
||||||
import { keyboardPending, type NewKind } from '@/editor/annotations/creation'
|
import { keyboardPending, type NewKind } from '@/editor/annotations/creation'
|
||||||
import { parseFrame, type Frame } from '@/editor/annotations/frame'
|
import { parseFrame, type Frame } from '@/editor/annotations/frame'
|
||||||
import { isEditable } from '@/editor/annotations/geometryEdit'
|
import { isEditable } from '@/editor/annotations/geometryEdit'
|
||||||
@@ -22,14 +22,15 @@ import {
|
|||||||
useViewModel,
|
useViewModel,
|
||||||
type ViewModel,
|
type ViewModel,
|
||||||
} from '@/editor/annotations/useViewModel'
|
} from '@/editor/annotations/useViewModel'
|
||||||
import { useFocusRequest } from '@/editor/focusRequest'
|
import type { AnnotationSection } from '@/editor/navigation'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import AnnotationCanvas from './AnnotationCanvas'
|
import AnnotationCanvas from './AnnotationCanvas'
|
||||||
import AnnotationList, { annotationName } from './AnnotationList'
|
import AnnotationList, { annotationName } from './AnnotationList'
|
||||||
import CreationPanel from './CreationPanel'
|
import CreationPanel from './CreationPanel'
|
||||||
import KeyboardAdd from './KeyboardAdd'
|
import KeyboardAdd from './KeyboardAdd'
|
||||||
|
import OverviewPanel from './OverviewPanel'
|
||||||
import PropertiesPanel, { UnmeasuredHint } from './PropertiesPanel'
|
import PropertiesPanel, { UnmeasuredHint } from './PropertiesPanel'
|
||||||
import SelectionTag from './SelectionTag'
|
import SelectionTag from './SelectionTag'
|
||||||
import TracingBar from './TracingBar'
|
import TracingBar from './TracingBar'
|
||||||
@@ -37,8 +38,9 @@ import ViewSwitcher from './ViewSwitcher'
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
doc: AnatomicalSheetDocument
|
doc: AnatomicalSheetDocument
|
||||||
onSelectTab: EditorTabProps['onSelectTab']
|
navigate: EditorPlaceProps['navigate']
|
||||||
focus: EditorTabProps['focus']
|
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
|
||||||
|
focus: EditorPlaceProps['focus']
|
||||||
}
|
}
|
||||||
|
|
||||||
/** What both columns read: the tab's state, the view, its frame and its selection. */
|
/** What both columns read: the tab's state, the view, its frame and its selection. */
|
||||||
@@ -52,21 +54,46 @@ interface Scene {
|
|||||||
frame: Frame | null
|
frame: Frame | null
|
||||||
selected: Annotation | undefined
|
selected: Annotation | undefined
|
||||||
setRoot: (root: RootAttributes | null) => void
|
setRoot: (root: RootAttributes | null) => void
|
||||||
onSelectTab: EditorTabProps['onSelectTab']
|
navigate: EditorPlaceProps['navigate']
|
||||||
|
onOpenSection: Props['onOpenSection']
|
||||||
}
|
}
|
||||||
|
|
||||||
function useScene({ doc, onSelectTab, focus }: Props): Scene {
|
/**
|
||||||
|
* The shown view no longer exists (an undo, a deletion in the views section): the full
|
||||||
|
* reset to the main view drops the pending creation, the tracing and the selection, so
|
||||||
|
* nothing pending is inserted on another view. It fires only for a view absent from the
|
||||||
|
* document, since `view` always returns a new state.
|
||||||
|
*/
|
||||||
|
function useViewFallback(
|
||||||
|
doc: AnatomicalSheetDocument,
|
||||||
|
shown: string | null,
|
||||||
|
dispatch: Dispatch<UiAction>,
|
||||||
|
) {
|
||||||
|
useEffect(() => {
|
||||||
|
if (shown === null || doc.views.some((view) => view.id === shown)) return
|
||||||
|
const main = mainViewId(doc)
|
||||||
|
if (doc.views.some((view) => view.id === main)) {
|
||||||
|
dispatch({ type: 'view', viewId: main })
|
||||||
|
}
|
||||||
|
}, [doc, shown, dispatch])
|
||||||
|
}
|
||||||
|
|
||||||
|
function useScene({ doc, navigate, onOpenSection, focus }: Props): Scene {
|
||||||
const [ui, dispatch] = useReducer(uiReducer, initialUi)
|
const [ui, dispatch] = useReducer(uiReducer, initialUi)
|
||||||
useFocusRequest(focus, (key) => {
|
|
||||||
const target = annotationFocus(doc, key)
|
|
||||||
if (!target) return
|
|
||||||
dispatch({ type: 'view', viewId: target.viewId })
|
|
||||||
dispatch({ type: 'select', id: target.annotationId })
|
|
||||||
})
|
|
||||||
const [root, setRoot] = useState<RootAttributes | null>(null)
|
const [root, setRoot] = useState<RootAttributes | null>(null)
|
||||||
const viewId = ui.viewId ?? mainViewId(doc)
|
const viewId = ui.viewId ?? mainViewId(doc)
|
||||||
const model = useViewModel(doc, viewId)
|
const model = useViewModel(doc, viewId)
|
||||||
const own = model.measured && root?.viewId === viewId
|
const own = model.measured && root?.viewId === viewId
|
||||||
|
useViewFallback(doc, ui.viewId, dispatch)
|
||||||
|
useAnnotationRequest(focus, doc, {
|
||||||
|
viewId,
|
||||||
|
selectedId: ui.selectedId,
|
||||||
|
busy: ui.pending ? 'creation' : ui.tracing ? 'tracing' : null,
|
||||||
|
show: (view, id) => {
|
||||||
|
dispatch({ type: 'view', viewId: view })
|
||||||
|
dispatch({ type: 'select', id })
|
||||||
|
},
|
||||||
|
})
|
||||||
return {
|
return {
|
||||||
doc,
|
doc,
|
||||||
ui,
|
ui,
|
||||||
@@ -76,7 +103,8 @@ function useScene({ doc, onSelectTab, focus }: Props): Scene {
|
|||||||
frame: own ? parseFrame(root.viewBox) : null,
|
frame: own ? parseFrame(root.viewBox) : null,
|
||||||
selected: model.annotations.find((a) => a.id === ui.selectedId),
|
selected: model.annotations.find((a) => a.id === ui.selectedId),
|
||||||
setRoot,
|
setRoot,
|
||||||
onSelectTab,
|
navigate,
|
||||||
|
onOpenSection,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +151,8 @@ function CanvasColumn({
|
|||||||
hint={ui.hint}
|
hint={ui.hint}
|
||||||
model={model}
|
model={model}
|
||||||
noCategory={noCategory}
|
noCategory={noCategory}
|
||||||
onSelectTab={scene.onSelectTab}
|
viewId={scene.viewId}
|
||||||
|
navigate={scene.navigate}
|
||||||
/>
|
/>
|
||||||
{selected && <TagOf annotation={selected} doc={doc} />}
|
{selected && <TagOf annotation={selected} doc={doc} />}
|
||||||
<CanvasStage scene={scene} placement={placement} />
|
<CanvasStage scene={scene} placement={placement} />
|
||||||
@@ -217,7 +246,6 @@ function SidePanel({
|
|||||||
scene: Scene
|
scene: Scene
|
||||||
context: CommitContext
|
context: CommitContext
|
||||||
}) {
|
}) {
|
||||||
const t = useT()
|
|
||||||
const { doc, ui, dispatch, model, frame, selected } = scene
|
const { doc, ui, dispatch, model, frame, selected } = scene
|
||||||
if (ui.pending) {
|
if (ui.pending) {
|
||||||
return (
|
return (
|
||||||
@@ -234,9 +262,13 @@ function SidePanel({
|
|||||||
}
|
}
|
||||||
if (!selected) {
|
if (!selected) {
|
||||||
return (
|
return (
|
||||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
<OverviewPanel
|
||||||
{t('editor.annotations.select_hint')}
|
doc={doc}
|
||||||
</p>
|
viewId={scene.viewId}
|
||||||
|
readOnly={false}
|
||||||
|
onSelectView={(id) => dispatch({ type: 'view', viewId: id })}
|
||||||
|
onOpenSection={scene.onOpenSection}
|
||||||
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
@@ -248,7 +280,7 @@ function SidePanel({
|
|||||||
geometryLocked={!model.measured}
|
geometryLocked={!model.measured}
|
||||||
dispatch={dispatch}
|
dispatch={dispatch}
|
||||||
context={context}
|
context={context}
|
||||||
onSelectTab={scene.onSelectTab}
|
navigate={scene.navigate}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -284,20 +316,24 @@ function ToolNotes({
|
|||||||
hint,
|
hint,
|
||||||
model,
|
model,
|
||||||
noCategory,
|
noCategory,
|
||||||
onSelectTab,
|
viewId,
|
||||||
|
navigate,
|
||||||
}: {
|
}: {
|
||||||
tool: ToolId
|
tool: ToolId
|
||||||
hint: string | null
|
hint: string | null
|
||||||
model: ViewModel
|
model: ViewModel
|
||||||
noCategory: boolean
|
noCategory: boolean
|
||||||
onSelectTab: EditorTabProps['onSelectTab']
|
viewId: string
|
||||||
|
navigate: EditorPlaceProps['navigate']
|
||||||
}) {
|
}) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const linkBlocked = tool === 'link' && model.children.length === 0
|
const linkBlocked = tool === 'link' && model.children.length === 0
|
||||||
return (
|
return (
|
||||||
<div className="space-y-1 text-sm text-[var(--color-ink-muted)]">
|
<div className="space-y-1 text-sm text-[var(--color-ink-muted)]">
|
||||||
<p>{t(`editor.annotations.tool_hint.${tool}`)}</p>
|
<p>{t(`editor.annotations.tool_hint.${tool}`)}</p>
|
||||||
{!model.measured && <UnmeasuredHint onSelectTab={onSelectTab} />}
|
{!model.measured && (
|
||||||
|
<UnmeasuredHint navigate={navigate} viewId={viewId} />
|
||||||
|
)}
|
||||||
{noCategory && <p>{t('editor.annotations.no_category')}</p>}
|
{noCategory && <p>{t('editor.annotations.no_category')}</p>}
|
||||||
{linkBlocked && <p>{t('editor.annotations.no_child_view')}</p>}
|
{linkBlocked && <p>{t('editor.annotations.no_child_view')}</p>}
|
||||||
{hint && (
|
{hint && (
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
import type {
|
||||||
|
AnatomicalSheetDocument,
|
||||||
|
SheetView,
|
||||||
|
} from '@faunosteo/core-wasm/types'
|
||||||
|
import { 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'
|
||||||
|
|
||||||
|
const CARD = 'space-y-2 rounded-xl border border-[var(--color-border)] p-4'
|
||||||
|
const TITLE = 'text-sm font-semibold'
|
||||||
|
const ROW =
|
||||||
|
'flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2 text-left text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
|
||||||
|
const ENTRY =
|
||||||
|
'inline-flex min-h-11 items-center rounded-lg border border-[var(--color-border)] px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
|
||||||
|
|
||||||
|
export interface OverviewPanelProps {
|
||||||
|
doc: AnatomicalSheetDocument
|
||||||
|
/** The view the canvas shows. */
|
||||||
|
viewId: string
|
||||||
|
/** Read-only modes only consult: the entries read « Voir … ». */
|
||||||
|
readOnly: boolean
|
||||||
|
onSelectView: (viewId: string) => void
|
||||||
|
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function SectionEntry({
|
||||||
|
section,
|
||||||
|
label,
|
||||||
|
onOpen,
|
||||||
|
}: {
|
||||||
|
section: AnnotationSection
|
||||||
|
label: string
|
||||||
|
onOpen: OverviewPanelProps['onOpenSection']
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-section-entry={section}
|
||||||
|
onClick={(event) => onOpen(section, event.currentTarget)}
|
||||||
|
className={ENTRY}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ViewRow({
|
||||||
|
view,
|
||||||
|
current,
|
||||||
|
count,
|
||||||
|
onSelect,
|
||||||
|
}: {
|
||||||
|
view: SheetView
|
||||||
|
current: boolean
|
||||||
|
count: number
|
||||||
|
onSelect: () => void
|
||||||
|
}) {
|
||||||
|
const t = useT()
|
||||||
|
const plural = usePlural()
|
||||||
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
|
return (
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-current={current}
|
||||||
|
onClick={onSelect}
|
||||||
|
className={`${ROW} ${current ? 'bg-[var(--color-surface-strong)]' : ''}`}
|
||||||
|
>
|
||||||
|
<span className="min-w-0">
|
||||||
|
<span className="block truncate font-medium">
|
||||||
|
{view.name[locale]}
|
||||||
|
</span>
|
||||||
|
<span className="text-[var(--color-ink-muted)]">
|
||||||
|
{t(
|
||||||
|
view.kind === 'main'
|
||||||
|
? 'editor.overview.view_main'
|
||||||
|
: 'editor.overview.view_detail',
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<span className="shrink-0 text-[var(--color-ink-muted)]">
|
||||||
|
{plural('editor.overview.annotations', count)}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ViewsCard(props: OverviewPanelProps) {
|
||||||
|
const t = useT()
|
||||||
|
const { doc, viewId, readOnly, onSelectView, onOpenSection } = props
|
||||||
|
const counts = useOverviewCounts(doc)
|
||||||
|
return (
|
||||||
|
<section aria-labelledby="overview-views" className={CARD}>
|
||||||
|
<h3 id="overview-views" className={TITLE}>
|
||||||
|
{t('editor.overview.views')}
|
||||||
|
</h3>
|
||||||
|
<ul>
|
||||||
|
{doc.views.map((view) => (
|
||||||
|
<ViewRow
|
||||||
|
key={view.id}
|
||||||
|
view={view}
|
||||||
|
current={view.id === viewId}
|
||||||
|
count={counts.annotationsByView.get(view.id) ?? 0}
|
||||||
|
onSelect={() => onSelectView(view.id)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
<SectionEntry
|
||||||
|
section="views"
|
||||||
|
label={t(
|
||||||
|
readOnly
|
||||||
|
? 'editor.overview.see_views'
|
||||||
|
: 'editor.overview.manage_views',
|
||||||
|
)}
|
||||||
|
onOpen={onOpenSection}
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CategoriesCard(props: OverviewPanelProps) {
|
||||||
|
const t = useT()
|
||||||
|
const plural = usePlural()
|
||||||
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
|
const { doc, readOnly, onOpenSection } = props
|
||||||
|
const counts = useOverviewCounts(doc)
|
||||||
|
return (
|
||||||
|
<section aria-labelledby="overview-categories" className={CARD}>
|
||||||
|
<h3 id="overview-categories" className={TITLE}>
|
||||||
|
{t('editor.overview.categories')}
|
||||||
|
</h3>
|
||||||
|
{doc.categories.length === 0 && (
|
||||||
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
|
{t('editor.overview.categories_empty')}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<ul className="flex flex-wrap gap-2">
|
||||||
|
{doc.categories.map((category) => (
|
||||||
|
<li
|
||||||
|
key={category.id}
|
||||||
|
className="inline-flex items-center gap-2 rounded-full border border-[var(--color-border)] px-3 py-1 text-sm"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
aria-hidden="true"
|
||||||
|
className="size-3 rounded-full border border-[var(--color-border)]"
|
||||||
|
style={{ backgroundColor: category.color ?? undefined }}
|
||||||
|
/>
|
||||||
|
{category.name[locale]}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<SectionEntry
|
||||||
|
section="categories"
|
||||||
|
label={t(
|
||||||
|
readOnly
|
||||||
|
? 'editor.overview.see_categories'
|
||||||
|
: 'editor.overview.edit_categories',
|
||||||
|
)}
|
||||||
|
onOpen={onOpenSection}
|
||||||
|
/>
|
||||||
|
{/* T17 / BDR-102: no vertebra role exists before U6, so this entry is always shown. */}
|
||||||
|
<SectionEntry
|
||||||
|
section="regions"
|
||||||
|
label={plural('editor.overview.regions', counts.regions)}
|
||||||
|
onOpen={onOpenSection}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Board 01's overview: the views and the categories, with the entries to their sections. */
|
||||||
|
export default function OverviewPanel(props: OverviewPanelProps) {
|
||||||
|
const t = useT()
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
role="region"
|
||||||
|
aria-label={t('editor.overview.label')}
|
||||||
|
data-testid="annotation-overview"
|
||||||
|
className="space-y-3"
|
||||||
|
>
|
||||||
|
<ViewsCard {...props} />
|
||||||
|
<CategoriesCard {...props} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -15,7 +15,8 @@ import {
|
|||||||
import { isEditable } from '@/editor/annotations/geometryEdit'
|
import { isEditable } from '@/editor/annotations/geometryEdit'
|
||||||
import type { UiAction } from '@/editor/annotations/uiState'
|
import type { UiAction } from '@/editor/annotations/uiState'
|
||||||
import { geometryErrorsById } from '@/editor/issues'
|
import { geometryErrorsById } from '@/editor/issues'
|
||||||
import type { EditorTabId } from '@/editor/tabs'
|
import { targetOfKey } from '@/editor/navigation'
|
||||||
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||||
import { useEditCommand } from '@/editor/useEditCommand'
|
import { useEditCommand } from '@/editor/useEditCommand'
|
||||||
import { useEditorStore } from '@/editor/state/editorStore'
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
@@ -35,7 +36,7 @@ export interface PropertiesPanelProps {
|
|||||||
geometryLocked: boolean
|
geometryLocked: boolean
|
||||||
dispatch: Dispatch<UiAction>
|
dispatch: Dispatch<UiAction>
|
||||||
context: CommitContext
|
context: CommitContext
|
||||||
onSelectTab: (tab: EditorTabId) => void
|
navigate: EditorPlaceProps['navigate']
|
||||||
}
|
}
|
||||||
|
|
||||||
/** What still names this annotation as invalid: never hidden, never shown as valid. */
|
/** What still names this annotation as invalid: never hidden, never shown as valid. */
|
||||||
@@ -58,7 +59,11 @@ export default function PropertiesPanel(props: PropertiesPanelProps) {
|
|||||||
className="space-y-4 rounded-xl border border-[var(--color-border)] p-4"
|
className="space-y-4 rounded-xl border border-[var(--color-border)] p-4"
|
||||||
>
|
>
|
||||||
<header className="flex items-start justify-between gap-2">
|
<header className="flex items-start justify-between gap-2">
|
||||||
<h3 className="text-base font-semibold">
|
<h3
|
||||||
|
tabIndex={-1}
|
||||||
|
data-properties-heading
|
||||||
|
className="outline-none text-base font-semibold"
|
||||||
|
>
|
||||||
{t(`editor.annotations.kind.${annotation.kind}`)}
|
{t(`editor.annotations.kind.${annotation.kind}`)}
|
||||||
</h3>
|
</h3>
|
||||||
<ReviewBadge status={annotation.review_status} />
|
<ReviewBadge status={annotation.review_status} />
|
||||||
@@ -83,7 +88,9 @@ function GeometrySection(props: PropertiesPanelProps) {
|
|||||||
const { geometry } = annotation
|
const { geometry } = annotation
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{geometryLocked && !readOnly && <UnmeasuredHint {...props} />}
|
{geometryLocked && !readOnly && (
|
||||||
|
<UnmeasuredHint navigate={props.navigate} viewId={annotation.view_id} />
|
||||||
|
)}
|
||||||
{isEditable(geometry) ? (
|
{isEditable(geometry) ? (
|
||||||
<GeometryGroup
|
<GeometryGroup
|
||||||
key={annotation.id}
|
key={annotation.id}
|
||||||
@@ -156,9 +163,11 @@ function GeometryIssues({ id }: { id: string }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Points to the views section, on the view whose drawing cannot be measured. */
|
||||||
export function UnmeasuredHint({
|
export function UnmeasuredHint({
|
||||||
onSelectTab,
|
navigate,
|
||||||
}: Pick<PropertiesPanelProps, 'onSelectTab'>) {
|
viewId,
|
||||||
|
}: Pick<PropertiesPanelProps, 'navigate'> & { viewId: string }) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
return (
|
return (
|
||||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
@@ -166,9 +175,14 @@ export function UnmeasuredHint({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="underline"
|
className="underline"
|
||||||
onClick={() => onSelectTab('views')}
|
onClick={(event) =>
|
||||||
|
navigate(
|
||||||
|
targetOfKey({ kind: 'view', id: viewId }),
|
||||||
|
event.currentTarget,
|
||||||
|
)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{t('editor.tab.views')}
|
{t('editor.place.views')}
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ export default function TracingBar({
|
|||||||
const t = useT()
|
const t = useT()
|
||||||
const plural = usePlural()
|
const plural = usePlural()
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<div
|
||||||
|
tabIndex={-1}
|
||||||
|
data-testid="tracing-bar"
|
||||||
|
className="flex flex-wrap items-center gap-2 outline-none"
|
||||||
|
>
|
||||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
{plural('editor.annotations.tracing', count)}
|
{plural('editor.annotations.tracing', count)}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||||
|
import Button from '@/components/ui/Button'
|
||||||
|
import type { FocusRequest } from '@/editor/focusRequest'
|
||||||
|
import type { AnnotationSection as SectionId } from '@/editor/navigation'
|
||||||
|
import { useT } from '@/i18n/useT'
|
||||||
|
import { ANNOTATION_SECTION_BODIES } from './registry'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
section: Exclude<SectionId, 'drawing'>
|
||||||
|
doc: AnatomicalSheetDocument
|
||||||
|
readOnly: boolean
|
||||||
|
focus?: FocusRequest
|
||||||
|
onBack: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A full-width Annotations section: « Retour au dessin » first, then its heading, then
|
||||||
|
* the body. The registry names the body, so a section is replaced without touching this
|
||||||
|
* frame or the navigation.
|
||||||
|
*/
|
||||||
|
export default function AnnotationSection({
|
||||||
|
section,
|
||||||
|
doc,
|
||||||
|
readOnly,
|
||||||
|
focus,
|
||||||
|
onBack,
|
||||||
|
}: Props) {
|
||||||
|
const t = useT()
|
||||||
|
const { titleKey, Body } = ANNOTATION_SECTION_BODIES[section]
|
||||||
|
const headingId = `annotation-section-${section}-title`
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
data-place={`annotations.${section}`}
|
||||||
|
aria-labelledby={headingId}
|
||||||
|
className="space-y-4"
|
||||||
|
>
|
||||||
|
<Button type="button" variant="secondary" size="sm" onClick={onBack}>
|
||||||
|
{t('editor.section.back')}
|
||||||
|
</Button>
|
||||||
|
<h2
|
||||||
|
id={headingId}
|
||||||
|
tabIndex={-1}
|
||||||
|
data-place-heading
|
||||||
|
className="outline-none text-xl font-semibold"
|
||||||
|
>
|
||||||
|
{t(titleKey)}
|
||||||
|
</h2>
|
||||||
|
<Body doc={doc} readOnly={readOnly} focus={focus} />
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
+11
-9
@@ -5,13 +5,19 @@ import DeleteDialog, {
|
|||||||
import RegionForm from '@/components/editor/vertebrae/RegionForm'
|
import RegionForm from '@/components/editor/vertebrae/RegionForm'
|
||||||
import RegionRow from '@/components/editor/vertebrae/RegionRow'
|
import RegionRow from '@/components/editor/vertebrae/RegionRow'
|
||||||
import { useRowFocus } from '@/editor/focusRequest'
|
import { useRowFocus } from '@/editor/focusRequest'
|
||||||
|
import type { SectionBodyProps } from './registry'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
|
||||||
/** Vertèbres: the vertebral regions (code, names, count, optional range), ordered. */
|
/**
|
||||||
export default function VertebraeTab({ readOnly, focus }: EditorTabProps) {
|
* Annotations, section Régions vertébrales: the regions (code, names, count, optional
|
||||||
|
* range), ordered. The level-1 editor, until the vertebra role replaces it (U6).
|
||||||
|
*/
|
||||||
|
export default function RegionsSection({
|
||||||
|
readOnly,
|
||||||
|
focus,
|
||||||
|
}: Pick<SectionBodyProps, 'readOnly' | 'focus'>) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
useRowFocus(focus)
|
useRowFocus(focus)
|
||||||
const locale = useLocaleStore((s) => s.locale)
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
@@ -19,11 +25,7 @@ export default function VertebraeTab({ readOnly, focus }: EditorTabProps) {
|
|||||||
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
||||||
const regions = doc?.vertebral_config.regions ?? []
|
const regions = doc?.vertebral_config.regions ?? []
|
||||||
return (
|
return (
|
||||||
<section
|
<div data-testid="editor-section-regions" className="min-h-24 space-y-3">
|
||||||
data-testid="editor-tab-vertebrae"
|
|
||||||
aria-label={t('editor.tab.vertebrae')}
|
|
||||||
className="min-h-24 space-y-3"
|
|
||||||
>
|
|
||||||
{doc && regions.length === 0 && (
|
{doc && regions.length === 0 && (
|
||||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
{t('editor.vertebra.empty')}
|
{t('editor.vertebra.empty')}
|
||||||
@@ -48,6 +50,6 @@ export default function VertebraeTab({ readOnly, focus }: EditorTabProps) {
|
|||||||
</ul>
|
</ul>
|
||||||
{doc && !readOnly && <RegionForm />}
|
{doc && !readOnly && <RegionForm />}
|
||||||
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
||||||
</section>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
+9
-10
@@ -6,16 +6,19 @@ import DetailViewForm from '@/components/editor/views/DetailViewForm'
|
|||||||
import DetailViewRow from '@/components/editor/views/DetailViewRow'
|
import DetailViewRow from '@/components/editor/views/DetailViewRow'
|
||||||
import MainViewCard from '@/components/editor/views/MainViewCard'
|
import MainViewCard from '@/components/editor/views/MainViewCard'
|
||||||
import { useRowFocus } from '@/editor/focusRequest'
|
import { useRowFocus } from '@/editor/focusRequest'
|
||||||
|
import type { SectionBodyProps } from './registry'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vues et illustrations: the main view and its drawing, the detail views (parent, own
|
* Annotations, section Vues: the main view and its drawing, the detail views (parent,
|
||||||
* drawing or crop), the upload of a drawing and the frame changes it brings.
|
* own drawing or crop), the upload of a drawing and the frame changes it brings.
|
||||||
*/
|
*/
|
||||||
export default function ViewsTab({ readOnly, focus }: EditorTabProps) {
|
export default function ViewsSection({
|
||||||
|
readOnly,
|
||||||
|
focus,
|
||||||
|
}: Pick<SectionBodyProps, 'readOnly' | 'focus'>) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
useRowFocus(focus)
|
useRowFocus(focus)
|
||||||
const locale = useLocaleStore((s) => s.locale)
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
@@ -26,11 +29,7 @@ export default function ViewsTab({ readOnly, focus }: EditorTabProps) {
|
|||||||
const main = views.find((view) => view.kind === 'main')
|
const main = views.find((view) => view.kind === 'main')
|
||||||
const details = views.filter((view) => view.kind === 'detail')
|
const details = views.filter((view) => view.kind === 'detail')
|
||||||
return (
|
return (
|
||||||
<section
|
<div data-testid="editor-section-views" className="min-h-24 space-y-4">
|
||||||
data-testid="editor-tab-views"
|
|
||||||
aria-label={t('editor.tab.views')}
|
|
||||||
className="min-h-24 space-y-4"
|
|
||||||
>
|
|
||||||
{main?.kind === 'main' && (
|
{main?.kind === 'main' && (
|
||||||
<MainViewCard view={main} readOnly={readOnly} />
|
<MainViewCard view={main} readOnly={readOnly} />
|
||||||
)}
|
)}
|
||||||
@@ -64,6 +63,6 @@ export default function ViewsTab({ readOnly, focus }: EditorTabProps) {
|
|||||||
</ul>
|
</ul>
|
||||||
{doc && !readOnly && <DetailViewForm views={views} />}
|
{doc && !readOnly && <DetailViewForm views={views} />}
|
||||||
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
||||||
</section>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import type { ComponentType } from 'react'
|
||||||
|
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||||
|
import CategoriesSection from '@/components/editor/general/CategoriesSection'
|
||||||
|
import type { FocusRequest } from '@/editor/focusRequest'
|
||||||
|
import type { AnnotationSection } from '@/editor/navigation'
|
||||||
|
import RegionsSection from './RegionsSection'
|
||||||
|
import ViewsSection from './ViewsSection'
|
||||||
|
|
||||||
|
/** What every section body receives from its frame. */
|
||||||
|
export interface SectionBodyProps {
|
||||||
|
doc: AnatomicalSheetDocument
|
||||||
|
readOnly: boolean
|
||||||
|
focus?: FocusRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
type SectionName = Exclude<AnnotationSection, 'drawing'>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The one place later steps edit: U3 replaces `categories`, U4 replaces `views`, U6 adds
|
||||||
|
* the vertebra-role path and removes `regions` once the role exists.
|
||||||
|
*/
|
||||||
|
export const ANNOTATION_SECTION_BODIES: Record<
|
||||||
|
SectionName,
|
||||||
|
{ titleKey: string; Body: ComponentType<SectionBodyProps> }
|
||||||
|
> = {
|
||||||
|
views: { titleKey: 'editor.place.views', Body: ViewsSection },
|
||||||
|
categories: { titleKey: 'editor.place.categories', Body: CategoriesSection },
|
||||||
|
regions: { titleKey: 'editor.place.regions', Body: RegionsSection },
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ export interface FindingTreeProps {
|
|||||||
onToggle: (id: string, open: boolean) => void
|
onToggle: (id: string, open: boolean) => void
|
||||||
/** Moves focus to this item (after a deletion); null leaves focus alone. */
|
/** Moves focus to this item (after a deletion); null leaves focus alone. */
|
||||||
focusId: { id: string } | null
|
focusId: { id: string } | null
|
||||||
|
/** Called once the request has been applied, so it never replays on a later visit. */
|
||||||
|
onFocused: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,14 +25,17 @@ export default function FindingTree(props: FindingTreeProps) {
|
|||||||
const t = useT()
|
const t = useT()
|
||||||
const refs = useRef(new Map<string, HTMLElement>())
|
const refs = useRef(new Map<string, HTMLElement>())
|
||||||
const focusAfter = useRef<string | null>(null)
|
const focusAfter = useRef<string | null>(null)
|
||||||
const { visible, selectedId, expanded, onSelect, onToggle, focusId } = props
|
const { visible, selectedId, expanded, onSelect, onToggle } = props
|
||||||
|
const { focusId, onFocused } = props
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (focusAfter.current) refs.current.get(focusAfter.current)?.focus()
|
if (focusAfter.current) refs.current.get(focusAfter.current)?.focus()
|
||||||
focusAfter.current = null
|
focusAfter.current = null
|
||||||
})
|
})
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (focusId) refs.current.get(focusId.id)?.focus()
|
if (!focusId) return
|
||||||
}, [focusId])
|
refs.current.get(focusId.id)?.focus()
|
||||||
|
onFocused()
|
||||||
|
}, [focusId, onFocused])
|
||||||
const current = visible.find((item) => item.id === selectedId) ?? visible[0]
|
const current = visible.find((item) => item.id === selectedId) ?? visible[0]
|
||||||
const onKeyDown = (event: KeyboardEvent, item: FindingItem) => {
|
const onKeyDown = (event: KeyboardEvent, item: FindingItem) => {
|
||||||
const move = keyMove(visible, item, expanded, event.key)
|
const move = keyMove(visible, item, expanded, event.key)
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import TextField from '@/components/editor/fields/TextField'
|
|||||||
import DeleteDialog, {
|
import DeleteDialog, {
|
||||||
type DeleteTarget,
|
type DeleteTarget,
|
||||||
} from '@/components/editor/DeleteDialog'
|
} from '@/components/editor/DeleteDialog'
|
||||||
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
import { FOCUS_CLASS, focusAttrs, useRowFocus } from '@/editor/focusRequest'
|
||||||
|
import type { FocusRequest } from '@/editor/navigation'
|
||||||
import { isBlank, nullable } from '@/editor/sheetDocument'
|
import { isBlank, nullable } from '@/editor/sheetDocument'
|
||||||
import { useEditCommand } from '@/editor/useEditCommand'
|
import { useEditCommand } from '@/editor/useEditCommand'
|
||||||
import type { Locale } from '@/i18n/types'
|
import type { Locale } from '@/i18n/types'
|
||||||
@@ -22,11 +23,14 @@ const CARD = 'rounded-lg border border-[var(--color-border)] p-3'
|
|||||||
export default function CategoriesSection({
|
export default function CategoriesSection({
|
||||||
doc,
|
doc,
|
||||||
readOnly,
|
readOnly,
|
||||||
|
focus,
|
||||||
}: {
|
}: {
|
||||||
doc: AnatomicalSheetDocument
|
doc: AnatomicalSheetDocument
|
||||||
readOnly: boolean
|
readOnly: boolean
|
||||||
|
focus?: FocusRequest
|
||||||
}) {
|
}) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
|
useRowFocus(focus)
|
||||||
const locale = useLocaleStore((s) => s.locale)
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { useState, type KeyboardEvent } from 'react'
|
||||||
|
import DeleteDialog, {
|
||||||
|
type DeleteTarget,
|
||||||
|
} from '@/components/editor/DeleteDialog'
|
||||||
|
import ReferenceForm from '@/components/editor/references/ReferenceForm'
|
||||||
|
import ReferenceRow from '@/components/editor/references/ReferenceRow'
|
||||||
|
import Icon from '@/components/ui/Icon'
|
||||||
|
import { useRowFocus } from '@/editor/focusRequest'
|
||||||
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||||
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
|
interface Props extends Pick<EditorPlaceProps, 'readOnly' | 'focus'> {
|
||||||
|
open: boolean
|
||||||
|
onClose: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The references side panel, minimal until Lot D: the sheet's bibliography, cited by id
|
||||||
|
* from the findings, opened by the header button. Not a dialog: it keeps the page usable.
|
||||||
|
* Mounted at the first opening and kept (hidden) afterwards.
|
||||||
|
*/
|
||||||
|
export default function ReferencesPanel({
|
||||||
|
readOnly,
|
||||||
|
focus,
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
}: Props) {
|
||||||
|
const t = useT()
|
||||||
|
useRowFocus(focus)
|
||||||
|
const doc = useSheetDocument()
|
||||||
|
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
||||||
|
const references = doc?.references ?? []
|
||||||
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.key !== 'Escape' || event.defaultPrevented) return
|
||||||
|
event.stopPropagation()
|
||||||
|
onClose()
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
id="editor-references-panel"
|
||||||
|
data-place="references"
|
||||||
|
data-testid="editor-references-panel"
|
||||||
|
aria-labelledby="editor-references-title"
|
||||||
|
hidden={!open}
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
|
className="space-y-3 rounded-xl border border-[var(--color-border)] p-4"
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<h2
|
||||||
|
id="editor-references-title"
|
||||||
|
tabIndex={-1}
|
||||||
|
data-place-heading
|
||||||
|
className="outline-none text-xl font-semibold"
|
||||||
|
>
|
||||||
|
{t('editor.place.references')}
|
||||||
|
</h2>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={t('editor.references.close')}
|
||||||
|
onClick={onClose}
|
||||||
|
className="inline-flex min-h-11 min-w-11 items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||||
|
>
|
||||||
|
<Icon name="close" size={18} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{doc && references.length === 0 && (
|
||||||
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
|
{t('editor.reference.empty')}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<ul className="space-y-3">
|
||||||
|
{references.map((reference, index) => (
|
||||||
|
<ReferenceRow
|
||||||
|
key={reference.id}
|
||||||
|
reference={reference}
|
||||||
|
index={index}
|
||||||
|
count={references.length}
|
||||||
|
readOnly={readOnly}
|
||||||
|
onDelete={() =>
|
||||||
|
setDeleting({
|
||||||
|
key: { kind: 'reference', id: reference.id },
|
||||||
|
label: reference.citation,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
{doc && !readOnly && <ReferenceForm />}
|
||||||
|
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,74 +1,112 @@
|
|||||||
import { useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||||
import CatalogueCanvas from '@/components/catalogue/CatalogueCanvas'
|
import CatalogueCanvas from '@/components/catalogue/CatalogueCanvas'
|
||||||
import AnnotationList, {
|
import AnnotationList, {
|
||||||
annotationName,
|
annotationName,
|
||||||
} from '@/components/editor/annotations/AnnotationList'
|
} from '@/components/editor/annotations/AnnotationList'
|
||||||
import EditableAnnotations from '@/components/editor/annotations/EditableAnnotations'
|
import EditableAnnotations from '@/components/editor/annotations/EditableAnnotations'
|
||||||
|
import OverviewPanel from '@/components/editor/annotations/OverviewPanel'
|
||||||
import PropertiesPanel from '@/components/editor/annotations/PropertiesPanel'
|
import PropertiesPanel from '@/components/editor/annotations/PropertiesPanel'
|
||||||
|
import AnnotationSection from '@/components/editor/annotations/sections/AnnotationSection'
|
||||||
import ViewSwitcher from '@/components/editor/annotations/ViewSwitcher'
|
import ViewSwitcher from '@/components/editor/annotations/ViewSwitcher'
|
||||||
import SelectionTag from '@/components/editor/annotations/SelectionTag'
|
import SelectionTag from '@/components/editor/annotations/SelectionTag'
|
||||||
import { annotationFocus } from '@/editor/annotations/focusTarget'
|
import { useAnnotationRequest } from '@/editor/annotations/focusTarget'
|
||||||
import { mainViewId, useViewModel } from '@/editor/annotations/useViewModel'
|
import { mainViewId, useViewModel } from '@/editor/annotations/useViewModel'
|
||||||
import { useFocusRequest } from '@/editor/focusRequest'
|
import type { AnnotationSection as SectionId } from '@/editor/navigation'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import { useEditorStore } from '@/editor/state/editorStore'
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
|
||||||
|
export interface AnnotationsTabProps extends EditorPlaceProps {
|
||||||
|
/** The section shown: the drawing workspace, or a full-width section. */
|
||||||
|
section: SectionId
|
||||||
|
onOpenSection: (section: SectionId, opener: HTMLElement) => void
|
||||||
|
onBack: () => void
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotations: the canvas with its tools, the list of the view, the creation and
|
* Annotations: the drawing workspace (canvas with its tools, the overview or the
|
||||||
* properties panels. Read-only, the same view is browsable (canvas, list, properties as
|
* properties and creation panels), or one of its full-width sections. Read-only, the
|
||||||
* text) with no tool and no action.
|
* same view is browsable (canvas, list, properties as text) with no tool and no action.
|
||||||
*/
|
*/
|
||||||
export default function AnnotationsTab(props: EditorTabProps) {
|
export default function AnnotationsTab(props: AnnotationsTabProps) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const doc = useSheetDocument()
|
const doc = useSheetDocument()
|
||||||
const preview = useEditorStore((s) => s.preview)
|
const preview = useEditorStore((s) => s.preview)
|
||||||
|
const { section, readOnly, focus, navigate, onOpenSection, onBack } = props
|
||||||
|
if (section !== 'drawing') {
|
||||||
|
if (!doc) return null
|
||||||
|
return (
|
||||||
|
<AnnotationSection
|
||||||
|
section={section}
|
||||||
|
doc={doc}
|
||||||
|
readOnly={readOnly}
|
||||||
|
focus={focus}
|
||||||
|
onBack={onBack}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const body = { doc, navigate, onOpenSection, focus }
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
|
data-place="annotations.drawing"
|
||||||
data-testid="editor-tab-annotations"
|
data-testid="editor-tab-annotations"
|
||||||
aria-label={t('editor.tab.annotations')}
|
aria-label={t('editor.tab.annotations')}
|
||||||
className="min-h-24 space-y-3"
|
className="min-h-24 space-y-3"
|
||||||
>
|
>
|
||||||
{doc && preview && props.readOnly && (
|
{doc && preview && readOnly && (
|
||||||
<ReadOnlyAnnotations
|
<ReadOnlyAnnotations {...body} doc={doc} />
|
||||||
doc={doc}
|
|
||||||
onSelectTab={props.onSelectTab}
|
|
||||||
focus={props.focus}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
{doc && preview && !props.readOnly && (
|
{doc && preview && !readOnly && (
|
||||||
<EditableAnnotations
|
<EditableAnnotations {...body} doc={doc} />
|
||||||
doc={doc}
|
|
||||||
onSelectTab={props.onSelectTab}
|
|
||||||
focus={props.focus}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The shown view is gone (an undo elsewhere): back to the main view, selection cleared. */
|
||||||
|
function useViewFallback(
|
||||||
|
doc: AnatomicalSheetDocument,
|
||||||
|
shown: string,
|
||||||
|
setViewId: (id: string) => void,
|
||||||
|
setSelectedId: (id: string | null) => void,
|
||||||
|
) {
|
||||||
|
useEffect(() => {
|
||||||
|
if (doc.views.some((view) => view.id === shown)) return
|
||||||
|
const main = mainViewId(doc)
|
||||||
|
if (!doc.views.some((view) => view.id === main)) return
|
||||||
|
setViewId(main)
|
||||||
|
setSelectedId(null)
|
||||||
|
}, [doc, shown, setViewId, setSelectedId])
|
||||||
|
}
|
||||||
|
|
||||||
function ReadOnlyAnnotations({
|
function ReadOnlyAnnotations({
|
||||||
doc,
|
doc,
|
||||||
onSelectTab,
|
navigate,
|
||||||
|
onOpenSection,
|
||||||
focus,
|
focus,
|
||||||
}: {
|
}: {
|
||||||
doc: AnatomicalSheetDocument
|
doc: AnatomicalSheetDocument
|
||||||
onSelectTab: EditorTabProps['onSelectTab']
|
navigate: EditorPlaceProps['navigate']
|
||||||
focus: EditorTabProps['focus']
|
onOpenSection: AnnotationsTabProps['onOpenSection']
|
||||||
|
focus: EditorPlaceProps['focus']
|
||||||
}) {
|
}) {
|
||||||
const locale = useLocaleStore((s) => s.locale)
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
const preview = useEditorStore((s) => s.preview)
|
const preview = useEditorStore((s) => s.preview)
|
||||||
const handleVersion = useEditorStore((s) => s.handleVersion)
|
const handleVersion = useEditorStore((s) => s.handleVersion)
|
||||||
const [viewId, setViewId] = useState(mainViewId(doc))
|
const [viewId, setViewId] = useState(mainViewId(doc))
|
||||||
const [selectedId, setSelectedId] = useState<string | null>(null)
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||||
useFocusRequest(focus, (key) => {
|
useViewFallback(doc, viewId, setViewId, setSelectedId)
|
||||||
const target = annotationFocus(doc, key)
|
useAnnotationRequest(focus, doc, {
|
||||||
if (!target) return
|
viewId,
|
||||||
setViewId(target.viewId)
|
selectedId,
|
||||||
setSelectedId(target.annotationId)
|
busy: null,
|
||||||
|
show: (view, id) => {
|
||||||
|
setViewId(view)
|
||||||
|
setSelectedId(id)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
const model = useViewModel(doc, viewId)
|
const model = useViewModel(doc, viewId)
|
||||||
const view = doc.views.find((v) => v.id === viewId)
|
const view = doc.views.find((v) => v.id === viewId)
|
||||||
@@ -106,7 +144,7 @@ function ReadOnlyAnnotations({
|
|||||||
onSelect={setSelectedId}
|
onSelect={setSelectedId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{selected && (
|
{selected ? (
|
||||||
<PropertiesPanel
|
<PropertiesPanel
|
||||||
key={selected.id}
|
key={selected.id}
|
||||||
annotation={selected}
|
annotation={selected}
|
||||||
@@ -115,7 +153,18 @@ function ReadOnlyAnnotations({
|
|||||||
geometryLocked={!model.measured}
|
geometryLocked={!model.measured}
|
||||||
dispatch={() => undefined}
|
dispatch={() => undefined}
|
||||||
context={{ t: (key) => key, locale }}
|
context={{ t: (key) => key, locale }}
|
||||||
onSelectTab={onSelectTab}
|
navigate={navigate}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<OverviewPanel
|
||||||
|
doc={doc}
|
||||||
|
viewId={viewId}
|
||||||
|
readOnly
|
||||||
|
onSelectView={(id) => {
|
||||||
|
setViewId(id)
|
||||||
|
setSelectedId(null)
|
||||||
|
}}
|
||||||
|
onOpenSection={onOpenSection}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo, useState } from 'react'
|
import { useCallback, useMemo, useState } from 'react'
|
||||||
import DeleteDialog, {
|
import DeleteDialog, {
|
||||||
type DeleteTarget,
|
type DeleteTarget,
|
||||||
} from '@/components/editor/DeleteDialog'
|
} from '@/components/editor/DeleteDialog'
|
||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
import { useFocusRequest } from '@/editor/focusRequest'
|
import { useFocusRequest } from '@/editor/focusRequest'
|
||||||
import { useEditorStore } from '@/editor/state/editorStore'
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
|
||||||
@@ -34,18 +34,41 @@ function currentItems(): FindingItem[] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Constats: the tree zones → categories → nodes, edited one command at a time. */
|
/** The deletion flow: the target, the item to select after it, and the focus left behind. */
|
||||||
export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
|
function useFindingDeletion(
|
||||||
const t = useT()
|
items: readonly FindingItem[],
|
||||||
|
selectedId: string | null,
|
||||||
|
select: (id: string | null) => void,
|
||||||
|
focusItem: (id: string | null) => void,
|
||||||
|
) {
|
||||||
const locale = useLocaleStore((s) => s.locale)
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
|
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
||||||
|
const [fallback, setFallback] = useState<string | null>(null)
|
||||||
|
const askDelete = (item: FindingItem) => {
|
||||||
|
setFallback(fallbackAfterRemoval(items, item))
|
||||||
|
setDeleting({ key: item.key, label: item.name[locale] })
|
||||||
|
}
|
||||||
|
const closeDelete = () => {
|
||||||
|
setDeleting(null)
|
||||||
|
const gone = !currentItems().some((item) => item.id === selectedId)
|
||||||
|
if (gone) {
|
||||||
|
select(fallback)
|
||||||
|
focusItem(fallback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { deleting, askDelete, closeDelete }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Constats: the tree zones → categories → nodes, edited one command at a time. */
|
||||||
|
export default function FindingsTab({ readOnly, focus }: EditorPlaceProps) {
|
||||||
|
const t = useT()
|
||||||
const doc = useSheetDocument()
|
const doc = useSheetDocument()
|
||||||
const [selectedId, setSelectedId] = useState<string | null>(null)
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||||
const [expanded, setExpanded] = useState<ReadonlySet<string>>(new Set())
|
const [expanded, setExpanded] = useState<ReadonlySet<string>>(new Set())
|
||||||
const [seeded, setSeeded] = useState(false)
|
const [seeded, setSeeded] = useState(false)
|
||||||
const [pending, setPending] = useState<PendingFinding | null>(null)
|
const [pending, setPending] = useState<PendingFinding | null>(null)
|
||||||
const [fallback, setFallback] = useState<string | null>(null)
|
|
||||||
const [focusId, setFocusId] = useState<{ id: string } | null>(null)
|
const [focusId, setFocusId] = useState<{ id: string } | null>(null)
|
||||||
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
const clearFocusId = useCallback(() => setFocusId(null), [])
|
||||||
const items = useMemo(() => (doc ? buildItems(doc) : []), [doc])
|
const items = useMemo(() => (doc ? buildItems(doc) : []), [doc])
|
||||||
if (doc && !seeded) {
|
if (doc && !seeded) {
|
||||||
setSeeded(true)
|
setSeeded(true)
|
||||||
@@ -65,12 +88,13 @@ export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
|
|||||||
return next
|
return next
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
useFocusRequest(focus, (key) => {
|
useFocusRequest(focus, (target) => {
|
||||||
const found = itemForKey(items, key)
|
const found = target.key && itemForKey(items, target.key)
|
||||||
if (!found) return
|
if (!found) return 'none'
|
||||||
setExpanded((prev) => new Set([...prev, ...found.ancestors]))
|
setExpanded((prev) => new Set([...prev, ...found.ancestors]))
|
||||||
setSelectedId(found.item.id)
|
setSelectedId(found.item.id)
|
||||||
setFocusId({ id: found.item.id })
|
setFocusId({ id: found.item.id })
|
||||||
|
return 'found'
|
||||||
})
|
})
|
||||||
const created = (id: string, parent: FindingItem | null) => {
|
const created = (id: string, parent: FindingItem | null) => {
|
||||||
if (!pending) return
|
if (!pending) return
|
||||||
@@ -78,18 +102,12 @@ export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
|
|||||||
setSelectedId(createdItemId(pending.kind, parent, id))
|
setSelectedId(createdItemId(pending.kind, parent, id))
|
||||||
setPending(null)
|
setPending(null)
|
||||||
}
|
}
|
||||||
const askDelete = (item: FindingItem) => {
|
const { deleting, askDelete, closeDelete } = useFindingDeletion(
|
||||||
setFallback(fallbackAfterRemoval(items, item))
|
items,
|
||||||
setDeleting({ key: item.key, label: item.name[locale] })
|
selectedId,
|
||||||
}
|
setSelectedId,
|
||||||
const closeDelete = () => {
|
(id) => setFocusId(id ? { id } : null),
|
||||||
setDeleting(null)
|
)
|
||||||
const gone = !currentItems().some((item) => item.id === selectedId)
|
|
||||||
if (gone) {
|
|
||||||
setSelectedId(fallback)
|
|
||||||
setFocusId(fallback ? { id: fallback } : null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
data-testid="editor-tab-findings"
|
data-testid="editor-tab-findings"
|
||||||
@@ -122,6 +140,7 @@ export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
|
|||||||
onSelect={setSelectedId}
|
onSelect={setSelectedId}
|
||||||
onToggle={toggle}
|
onToggle={toggle}
|
||||||
focusId={focusId}
|
focusId={focusId}
|
||||||
|
onFocused={clearFocusId}
|
||||||
/>
|
/>
|
||||||
{selected && (
|
{selected && (
|
||||||
<FindingDetail
|
<FindingDetail
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import AttributionSection from '@/components/editor/general/AttributionSection'
|
import AttributionSection from '@/components/editor/general/AttributionSection'
|
||||||
import CategoriesSection from '@/components/editor/general/CategoriesSection'
|
|
||||||
import TextsSection from '@/components/editor/general/TextsSection'
|
import TextsSection from '@/components/editor/general/TextsSection'
|
||||||
import { useRowFocus } from '@/editor/focusRequest'
|
import { useRowFocus } from '@/editor/focusRequest'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
/** Général: the sheet's texts, attribution and annotation categories. */
|
/** Général: the sheet's texts and attribution. */
|
||||||
export default function GeneralTab({ readOnly, focus }: EditorTabProps) {
|
export default function GeneralTab({ readOnly, focus }: EditorPlaceProps) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
useRowFocus(focus)
|
useRowFocus(focus)
|
||||||
const doc = useSheetDocument()
|
const doc = useSheetDocument()
|
||||||
@@ -21,7 +20,6 @@ export default function GeneralTab({ readOnly, focus }: EditorTabProps) {
|
|||||||
<>
|
<>
|
||||||
<TextsSection doc={doc} readOnly={readOnly} />
|
<TextsSection doc={doc} readOnly={readOnly} />
|
||||||
<AttributionSection doc={doc} readOnly={readOnly} />
|
<AttributionSection doc={doc} readOnly={readOnly} />
|
||||||
<CategoriesSection doc={doc} readOnly={readOnly} />
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import DeleteDialog, {
|
|
||||||
type DeleteTarget,
|
|
||||||
} from '@/components/editor/DeleteDialog'
|
|
||||||
import ReferenceForm from '@/components/editor/references/ReferenceForm'
|
|
||||||
import ReferenceRow from '@/components/editor/references/ReferenceRow'
|
|
||||||
import { useRowFocus } from '@/editor/focusRequest'
|
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
|
||||||
import { useT } from '@/i18n/useT'
|
|
||||||
|
|
||||||
/** Références: the sheet's bibliography, cited by id from the findings. */
|
|
||||||
export default function ReferencesTab({ readOnly, focus }: EditorTabProps) {
|
|
||||||
const t = useT()
|
|
||||||
useRowFocus(focus)
|
|
||||||
const doc = useSheetDocument()
|
|
||||||
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
|
||||||
const references = doc?.references ?? []
|
|
||||||
return (
|
|
||||||
<section
|
|
||||||
data-testid="editor-tab-references"
|
|
||||||
aria-label={t('editor.tab.references')}
|
|
||||||
className="min-h-24 space-y-3"
|
|
||||||
>
|
|
||||||
{doc && references.length === 0 && (
|
|
||||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
|
||||||
{t('editor.reference.empty')}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
<ul className="space-y-3">
|
|
||||||
{references.map((reference, index) => (
|
|
||||||
<ReferenceRow
|
|
||||||
key={reference.id}
|
|
||||||
reference={reference}
|
|
||||||
index={index}
|
|
||||||
count={references.length}
|
|
||||||
readOnly={readOnly}
|
|
||||||
onDelete={() =>
|
|
||||||
setDeleting({
|
|
||||||
key: { kind: 'reference', id: reference.id },
|
|
||||||
label: reference.citation,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
{doc && !readOnly && <ReferenceForm />}
|
|
||||||
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
|
||||||
</section>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -13,23 +13,16 @@ import VerificationSummary from '@/components/editor/verification/VerificationSu
|
|||||||
import Notice from '@/components/ui/Notice'
|
import Notice from '@/components/ui/Notice'
|
||||||
import { useEditorStore } from '@/editor/state/editorStore'
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorTabProps } from '@/editor/tabs'
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||||
import { splitIssues } from '@/editor/verification'
|
import { splitIssues } from '@/editor/verification'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
interface PanelProps extends EditorTabProps {
|
interface PanelProps extends EditorPlaceProps {
|
||||||
report: SheetReport
|
report: SheetReport
|
||||||
doc: AnatomicalSheetDocument
|
doc: AnatomicalSheetDocument
|
||||||
}
|
}
|
||||||
|
|
||||||
function Panel({
|
function Panel({ report, doc, readOnly, navigate, reloadSheet }: PanelProps) {
|
||||||
report,
|
|
||||||
doc,
|
|
||||||
readOnly,
|
|
||||||
onSelectTab,
|
|
||||||
onGoTo,
|
|
||||||
reloadSheet,
|
|
||||||
}: PanelProps) {
|
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const { errors, warnings } = splitIssues(report)
|
const { errors, warnings } = splitIssues(report)
|
||||||
const { to_confirm } = report.completeness.statuses
|
const { to_confirm } = report.completeness.statuses
|
||||||
@@ -43,25 +36,13 @@ function Panel({
|
|||||||
{errors.length + warnings.length === 0 && (
|
{errors.length + warnings.length === 0 && (
|
||||||
<Notice tone="success">{t('editor.verification.none')}</Notice>
|
<Notice tone="success">{t('editor.verification.none')}</Notice>
|
||||||
)}
|
)}
|
||||||
<IssueList
|
<IssueList issues={errors} tone="error" doc={doc} navigate={navigate} />
|
||||||
issues={errors}
|
|
||||||
tone="error"
|
|
||||||
doc={doc}
|
|
||||||
onSelectTab={onSelectTab}
|
|
||||||
onGoTo={onGoTo}
|
|
||||||
/>
|
|
||||||
{warnings.length > 0 && (
|
{warnings.length > 0 && (
|
||||||
<h3 className="text-sm font-medium">
|
<h3 className="text-sm font-medium">
|
||||||
{t('editor.verification.warnings_title')}
|
{t('editor.verification.warnings_title')}
|
||||||
</h3>
|
</h3>
|
||||||
)}
|
)}
|
||||||
<IssueList
|
<IssueList issues={warnings} tone="info" doc={doc} navigate={navigate} />
|
||||||
issues={warnings}
|
|
||||||
tone="info"
|
|
||||||
doc={doc}
|
|
||||||
onSelectTab={onSelectTab}
|
|
||||||
onGoTo={onGoTo}
|
|
||||||
/>
|
|
||||||
{to_confirm > 0 && (
|
{to_confirm > 0 && (
|
||||||
<Notice tone="info">{t('editor.verification.to_confirm_info')}</Notice>
|
<Notice tone="info">{t('editor.verification.to_confirm_info')}</Notice>
|
||||||
)}
|
)}
|
||||||
@@ -76,7 +57,7 @@ function Panel({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Vérification: the in-page check of the draft (not the server's verdict) and its submission. */
|
/** Vérification: the in-page check of the draft (not the server's verdict) and its submission. */
|
||||||
export default function VerificationTab(props: EditorTabProps) {
|
export default function VerificationTab(props: EditorPlaceProps) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const report = useEditorStore((s) => s.previewState?.report)
|
const report = useEditorStore((s) => s.previewState?.report)
|
||||||
const doc = useSheetDocument()
|
const doc = useSheetDocument()
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import type {
|
import type {
|
||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
ElementKey,
|
|
||||||
SheetIssue,
|
SheetIssue,
|
||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
import Button from '@/components/ui/Button'
|
import Button from '@/components/ui/Button'
|
||||||
import Notice from '@/components/ui/Notice'
|
import Notice from '@/components/ui/Notice'
|
||||||
import { issueMessageKey, issueTarget } from '@/editor/verification'
|
import { issueMessageKey, issueTarget, placeKey } from '@/editor/verification'
|
||||||
import type { EditorTabId } from '@/editor/tabs'
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
|
||||||
@@ -14,8 +13,7 @@ interface IssueListProps {
|
|||||||
issues: readonly SheetIssue[]
|
issues: readonly SheetIssue[]
|
||||||
tone: 'error' | 'info'
|
tone: 'error' | 'info'
|
||||||
doc: AnatomicalSheetDocument
|
doc: AnatomicalSheetDocument
|
||||||
onSelectTab: (tab: EditorTabId) => void
|
navigate: EditorPlaceProps['navigate']
|
||||||
onGoTo?: (tab: EditorTabId, key: ElementKey) => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** One notice per issue: the page's own message, the element's name, « Aller à … ». */
|
/** One notice per issue: the page's own message, the element's name, « Aller à … ». */
|
||||||
@@ -23,8 +21,7 @@ export default function IssueList({
|
|||||||
issues,
|
issues,
|
||||||
tone,
|
tone,
|
||||||
doc,
|
doc,
|
||||||
onSelectTab,
|
navigate,
|
||||||
onGoTo,
|
|
||||||
}: IssueListProps) {
|
}: IssueListProps) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const locale = useLocaleStore((s) => s.locale)
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
@@ -47,15 +44,13 @@ export default function IssueList({
|
|||||||
size="sm"
|
size="sm"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
className="mt-2"
|
className="mt-2"
|
||||||
onClick={() =>
|
onClick={(event) =>
|
||||||
target.key && onGoTo
|
navigate(target.target, event.currentTarget)
|
||||||
? onGoTo(target.tab, target.key)
|
|
||||||
: onSelectTab(target.tab)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{t('editor.verification.goto').replace(
|
{t('editor.verification.goto').replace(
|
||||||
'{tab}',
|
'{tab}',
|
||||||
target.name ?? t(`editor.tab.${target.tab}`),
|
target.name ?? t(placeKey(target.target)),
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,20 +1,81 @@
|
|||||||
|
import { useContext, useEffect, useRef } from 'react'
|
||||||
import type {
|
import type {
|
||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
ElementKey,
|
ElementKey,
|
||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
|
import {
|
||||||
|
AnnounceContext,
|
||||||
|
useFocusRequest,
|
||||||
|
visibleElement,
|
||||||
|
type FocusRequest,
|
||||||
|
} from '../focusRequest'
|
||||||
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
/** What « Aller à … » seeds in the Annotations tab: a view, and maybe an annotation. */
|
/** What « Aller à … » seeds on the drawing: the view and the annotation a key names. */
|
||||||
export function annotationFocus(
|
export function annotationFocus(
|
||||||
doc: AnatomicalSheetDocument,
|
doc: AnatomicalSheetDocument,
|
||||||
key: ElementKey,
|
key: ElementKey,
|
||||||
): { viewId: string; annotationId: string | null } | null {
|
): { viewId: string; annotationId: string } | null {
|
||||||
if (key.kind === 'view') {
|
|
||||||
const view = doc.views.find((v) => v.id === key.id)
|
|
||||||
return view ? { viewId: view.id, annotationId: null } : null
|
|
||||||
}
|
|
||||||
if (key.kind !== 'annotation') return null
|
if (key.kind !== 'annotation') return null
|
||||||
const annotation = doc.annotations.find((a) => a.id === key.id)
|
const annotation = doc.annotations.find((a) => a.id === key.id)
|
||||||
return annotation
|
return annotation
|
||||||
? { viewId: annotation.view_id, annotationId: annotation.id }
|
? { viewId: annotation.view_id, annotationId: annotation.id }
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** What the request needs to know of the drawing, and the one thing it may do to it. */
|
||||||
|
export interface DrawingState {
|
||||||
|
viewId: string
|
||||||
|
selectedId: string | null
|
||||||
|
/** A creation or a tracing in progress: the request is kept, not served. */
|
||||||
|
busy: 'creation' | 'tracing' | null
|
||||||
|
show: (viewId: string, annotationId: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const BUSY_TARGET = {
|
||||||
|
creation: '[data-creation-heading]',
|
||||||
|
tracing: '[data-testid="tracing-bar"]',
|
||||||
|
} as const
|
||||||
|
|
||||||
|
const focusFirst = (selector: string) => visibleElement(selector)?.focus()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* « Aller à » an annotation on the drawing: shows its view, selects it, then focuses the
|
||||||
|
* properties heading once it has rendered. While a creation or a tracing is in progress
|
||||||
|
* the request is kept: nothing is dispatched (it would drop the work), the panel or bar
|
||||||
|
* takes the focus and the live region says why.
|
||||||
|
*/
|
||||||
|
export function useAnnotationRequest(
|
||||||
|
focus: FocusRequest | undefined,
|
||||||
|
doc: AnatomicalSheetDocument,
|
||||||
|
drawing: DrawingState,
|
||||||
|
): void {
|
||||||
|
const t = useT()
|
||||||
|
const announce = useContext(AnnounceContext)
|
||||||
|
const awaiting = useRef<string | null>(null)
|
||||||
|
useFocusRequest(focus, (target) => {
|
||||||
|
const found = target.key ? annotationFocus(doc, target.key) : null
|
||||||
|
if (!found) return 'none'
|
||||||
|
if (drawing.busy) {
|
||||||
|
announce(t(`editor.live.${drawing.busy}_kept`))
|
||||||
|
focusFirst(BUSY_TARGET[drawing.busy])
|
||||||
|
return 'kept'
|
||||||
|
}
|
||||||
|
const same =
|
||||||
|
drawing.selectedId === found.annotationId &&
|
||||||
|
drawing.viewId === found.viewId
|
||||||
|
if (same) focusFirst('[data-properties-heading]')
|
||||||
|
else {
|
||||||
|
awaiting.current = found.annotationId
|
||||||
|
drawing.show(found.viewId, found.annotationId)
|
||||||
|
}
|
||||||
|
return 'found'
|
||||||
|
})
|
||||||
|
useEffect(() => {
|
||||||
|
if (awaiting.current === null || drawing.selectedId !== awaiting.current) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
awaiting.current = null
|
||||||
|
focusFirst('[data-properties-heading]')
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { useMemo } from 'react'
|
||||||
|
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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])
|
||||||
|
}
|
||||||
@@ -1,10 +1,38 @@
|
|||||||
import { createContext, useContext, useEffect, useRef } from 'react'
|
import { createContext, useContext, useEffect, useRef } from 'react'
|
||||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||||
|
import type {
|
||||||
|
AnnotationSection,
|
||||||
|
EditorTarget,
|
||||||
|
FocusRequest,
|
||||||
|
} from './navigation'
|
||||||
|
import type { EditorTabId } from './tabs'
|
||||||
|
|
||||||
/** « Aller à … »: the element to show and a serial so each request is consumed once. */
|
export type { FocusRequest }
|
||||||
export interface FocusRequest {
|
|
||||||
key: ElementKey
|
/**
|
||||||
serial: number
|
* What a place did with a request: `found` the element and focused it, `kept` a creation
|
||||||
|
* or tracing in progress instead of jumping, `none` when it holds no such element.
|
||||||
|
*/
|
||||||
|
export type FocusOutcome = 'found' | 'kept' | 'none'
|
||||||
|
|
||||||
|
/** The `data-place` name of the place a target shows. */
|
||||||
|
export type PlaceName =
|
||||||
|
| EditorTabId
|
||||||
|
| `annotations.${AnnotationSection}`
|
||||||
|
| 'references'
|
||||||
|
|
||||||
|
export function placeOf(target: EditorTarget): PlaceName {
|
||||||
|
if (target.place === 'references') return 'references'
|
||||||
|
if (target.tab !== 'annotations') return target.tab
|
||||||
|
return `annotations.${target.section ?? 'drawing'}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The request, only when `place` is the one its target names (a hidden place never answers). */
|
||||||
|
export function ownedBy(
|
||||||
|
focus: FocusRequest | undefined,
|
||||||
|
place: PlaceName,
|
||||||
|
): FocusRequest | undefined {
|
||||||
|
return focus && placeOf(focus.target) === place ? focus : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The attributes that make a row of a list reachable by a focus request. */
|
/** The attributes that make a row of a list reachable by a focus request. */
|
||||||
@@ -19,37 +47,73 @@ export function focusAttrs(key: ElementKey) {
|
|||||||
export const FOCUS_CLASS =
|
export const FOCUS_CLASS =
|
||||||
'focus:outline focus:outline-2 focus:outline-[var(--color-accent)]'
|
'focus:outline focus:outline-2 focus:outline-[var(--color-accent)]'
|
||||||
|
|
||||||
/** The route's answer to a consumed request: it clears it, so a remounted tab never replays. */
|
/** The workspace's answer to a handled request: it clears it, so a remount never replays. */
|
||||||
export const FocusConsumedContext = createContext<(serial: number) => void>(
|
export const FocusConsumedContext = createContext<
|
||||||
|
(serial: number, outcome: FocusOutcome) => void
|
||||||
|
>(() => undefined)
|
||||||
|
|
||||||
|
/** Says something to the polite live region of the workspace. */
|
||||||
|
export const AnnounceContext = createContext<(text: string) => void>(
|
||||||
() => undefined,
|
() => undefined,
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Runs `apply` once per request, after the tab has rendered, then reports it consumed. */
|
/**
|
||||||
|
* Runs `apply` once per request, after the place has rendered, then reports the outcome.
|
||||||
|
* The workspace passes a request only to the place its target names.
|
||||||
|
*/
|
||||||
export function useFocusRequest(
|
export function useFocusRequest(
|
||||||
focus: FocusRequest | undefined,
|
focus: FocusRequest | undefined,
|
||||||
apply: (key: ElementKey) => void,
|
apply: (target: EditorTarget) => FocusOutcome,
|
||||||
): void {
|
): void {
|
||||||
const handled = useRef<number | null>(null)
|
const handled = useRef<number | null>(null)
|
||||||
const consumed = useContext(FocusConsumedContext)
|
const consumed = useContext(FocusConsumedContext)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!focus || handled.current === focus.serial) return
|
if (!focus || handled.current === focus.serial) return
|
||||||
handled.current = focus.serial
|
handled.current = focus.serial
|
||||||
apply(focus.key)
|
consumed(focus.serial, apply(focus.target))
|
||||||
consumed(focus.serial)
|
|
||||||
}, [focus, apply, consumed])
|
}, [focus, apply, consumed])
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Scrolls to and focuses the row tagged with `key`. */
|
/** The first element matching `selector` that no hidden place contains. */
|
||||||
export function focusRow(key: ElementKey): void {
|
export function visibleElement(selector: string): HTMLElement | null {
|
||||||
|
const found = [...document.querySelectorAll<HTMLElement>(selector)]
|
||||||
|
return found.find((element) => !element.closest('[hidden]')) ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Scrolls to and focuses the visible row tagged with `key`; false when there is none. */
|
||||||
|
export function focusRow(key: ElementKey): boolean {
|
||||||
const wanted = JSON.stringify(key)
|
const wanted = JSON.stringify(key)
|
||||||
const row = [
|
const row = [
|
||||||
...document.querySelectorAll<HTMLElement>('[data-focus-key]'),
|
...document.querySelectorAll<HTMLElement>('[data-focus-key]'),
|
||||||
].find((candidate) => candidate.dataset.focusKey === wanted)
|
].find(
|
||||||
row?.scrollIntoView?.({ block: 'center' })
|
(candidate) =>
|
||||||
row?.focus()
|
candidate.dataset.focusKey === wanted && !candidate.closest('[hidden]'),
|
||||||
|
)
|
||||||
|
if (!row) return false
|
||||||
|
row.scrollIntoView?.({ block: 'center' })
|
||||||
|
row.focus()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Row-based tabs (Général, Vues, Références, Vertèbres): focus the named row. */
|
/** Row-based places (Général, Vues, Catégories, Régions, Références): focus the named row. */
|
||||||
export function useRowFocus(focus: FocusRequest | undefined): void {
|
export function useRowFocus(focus: FocusRequest | undefined): void {
|
||||||
useFocusRequest(focus, focusRow)
|
useFocusRequest(focus, (target) =>
|
||||||
|
target.key && focusRow(target.key) ? 'found' : 'none',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commits the text being typed before a place is left: blurs the focused field, so its
|
||||||
|
* `TextField` commits on blur. Safari and iPadOS do not move the focus to a tapped button,
|
||||||
|
* so the blur is forced rather than assumed.
|
||||||
|
*/
|
||||||
|
export function commitFocusedField(): void {
|
||||||
|
const active = document.activeElement
|
||||||
|
if (
|
||||||
|
active instanceof HTMLInputElement ||
|
||||||
|
active instanceof HTMLTextAreaElement ||
|
||||||
|
active instanceof HTMLSelectElement
|
||||||
|
) {
|
||||||
|
active.blur()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+15
-13
@@ -1,15 +1,12 @@
|
|||||||
import type { ElementKey, PreviewState } from '@faunosteo/core-wasm/types'
|
import type { PreviewState } from '@faunosteo/core-wasm/types'
|
||||||
import type { FocusRequest } from './focusRequest'
|
import type { EditorTarget, FocusRequest } from './navigation'
|
||||||
import { unmeasuredViews } from './issues'
|
import { unmeasuredViews } from './issues'
|
||||||
import type { TabTier } from './useViewport'
|
import type { TabTier } from './useViewport'
|
||||||
|
|
||||||
export const EDITOR_TABS = [
|
export const EDITOR_TABS = [
|
||||||
'general',
|
'general',
|
||||||
'views',
|
|
||||||
'annotations',
|
'annotations',
|
||||||
'findings',
|
'findings',
|
||||||
'references',
|
|
||||||
'vertebrae',
|
|
||||||
'verification',
|
'verification',
|
||||||
] as const
|
] as const
|
||||||
export type EditorTabId = (typeof EDITOR_TABS)[number]
|
export type EditorTabId = (typeof EDITOR_TABS)[number]
|
||||||
@@ -17,7 +14,7 @@ export type EditorTabId = (typeof EDITOR_TABS)[number]
|
|||||||
/** Board 05: the tabs shown beside « Plus » at each width; the rest sit under « Plus ». */
|
/** Board 05: the tabs shown beside « Plus » at each width; the rest sit under « Plus ». */
|
||||||
const SHOWN: Record<TabTier, readonly EditorTabId[]> = {
|
const SHOWN: Record<TabTier, readonly EditorTabId[]> = {
|
||||||
wide: EDITOR_TABS,
|
wide: EDITOR_TABS,
|
||||||
medium: ['general', 'annotations', 'findings', 'verification'],
|
medium: EDITOR_TABS,
|
||||||
small: ['annotations', 'verification'],
|
small: ['annotations', 'verification'],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,16 +37,21 @@ export function initialTab(state: PreviewState, tier: TabTier): EditorTabId {
|
|||||||
return SHOWN[tier].includes(wanted) ? wanted : 'annotations'
|
return SHOWN[tier].includes(wanted) ? wanted : 'annotations'
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Props of every tab body (Lots F-J fill them): read-only flag, tab jump, sheet reload. */
|
/** Props of every place (tab body, Annotations section, references panel). */
|
||||||
export interface EditorTabProps {
|
export interface EditorPlaceProps {
|
||||||
/** Not editable now: a mode that cannot save, or a recovery offer not answered yet. */
|
/** Not editable now: a mode that cannot save, or a recovery offer not answered yet. */
|
||||||
readOnly: boolean
|
readOnly: boolean
|
||||||
/** « Aller à … » and any link between tabs. */
|
/** « Aller à … » and any link between places; `opener` takes the focus back on return. */
|
||||||
onSelectTab: (tab: EditorTabId) => void
|
navigate: (target: EditorTarget, opener?: HTMLElement | null) => void
|
||||||
/** « Aller à … » with an element: the tab seeds its own selection from it once. */
|
/** « Aller à … » with an element: the place seeds its own selection from it once. */
|
||||||
focus?: FocusRequest
|
focus?: FocusRequest
|
||||||
/** Switches tab and asks it to show the element. */
|
|
||||||
onGoTo?: (tab: EditorTabId, key: ElementKey) => void
|
|
||||||
/** Reads the sheet's overview again (after a submission: the round freezes the draft). */
|
/** Reads the sheet's overview again (after a submission: the round freezes the draft). */
|
||||||
reloadSheet: () => void
|
reloadSheet: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const tabDomId = (tab: EditorTabId) => `editor-tab-${tab}`
|
||||||
|
export const panelDomId = (tab: EditorTabId) => `editor-panel-${tab}`
|
||||||
|
/** The « Plus » disclosure button, focused when the active tab sits under it. */
|
||||||
|
export const MORE_BUTTON_ID = 'editor-tabs-more-button'
|
||||||
|
/** The header button that toggles the references panel. */
|
||||||
|
export const REFERENCES_BUTTON_ID = 'editor-references-button'
|
||||||
@@ -0,0 +1,246 @@
|
|||||||
|
import {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useReducer,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
type Dispatch,
|
||||||
|
type RefObject,
|
||||||
|
} from 'react'
|
||||||
|
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||||
|
import { useT } from '@/i18n/useT'
|
||||||
|
import {
|
||||||
|
commitFocusedField,
|
||||||
|
placeOf,
|
||||||
|
visibleElement,
|
||||||
|
type FocusOutcome,
|
||||||
|
type PlaceName,
|
||||||
|
} from './focusRequest'
|
||||||
|
import {
|
||||||
|
initialNavigation,
|
||||||
|
navigationReducer,
|
||||||
|
type AnnotationSection,
|
||||||
|
type EditorTarget,
|
||||||
|
type NavigationAction,
|
||||||
|
type NavigationState,
|
||||||
|
} from './navigation'
|
||||||
|
import {
|
||||||
|
MORE_BUTTON_ID,
|
||||||
|
REFERENCES_BUTTON_ID,
|
||||||
|
tabDomId,
|
||||||
|
type EditorTabId,
|
||||||
|
} from './tabs'
|
||||||
|
|
||||||
|
type MoveKind =
|
||||||
|
| 'go_to'
|
||||||
|
| 'section'
|
||||||
|
| 'back'
|
||||||
|
| 'references'
|
||||||
|
| 'references_closed'
|
||||||
|
|
||||||
|
/** A programmatic move: a new object per move, so the effect after it runs once. */
|
||||||
|
interface Move {
|
||||||
|
kind: MoveKind
|
||||||
|
}
|
||||||
|
|
||||||
|
type Opener = HTMLElement | null | undefined
|
||||||
|
|
||||||
|
export interface EditorNavigation {
|
||||||
|
state: NavigationState
|
||||||
|
/** The polite live region's text; a repeat alternates a trailing no-break space. */
|
||||||
|
live: string
|
||||||
|
navigate: (target: EditorTarget, opener?: Opener) => void
|
||||||
|
selectTab: (tab: EditorTabId) => void
|
||||||
|
openSection: (section: AnnotationSection, opener?: Opener) => void
|
||||||
|
backToDrawing: () => void
|
||||||
|
openReferences: (citedBy: ElementKey | null, opener?: Opener) => void
|
||||||
|
closeReferences: () => void
|
||||||
|
consumed: (serial: number, outcome: FocusOutcome) => void
|
||||||
|
announce: (text: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const isShown = (element: HTMLElement | null): boolean =>
|
||||||
|
element !== null && element.isConnected && !element.closest('[hidden]')
|
||||||
|
|
||||||
|
const headingOf = (place: PlaceName) =>
|
||||||
|
visibleElement(`[data-place="${place}"] [data-place-heading]`)
|
||||||
|
|
||||||
|
const CANVAS_BOX =
|
||||||
|
'[data-place="annotations.drawing"] [role="group"][tabindex="0"]'
|
||||||
|
|
||||||
|
/** The tab's button, or « Plus » while the tab sits in the closed list. */
|
||||||
|
const tabButton = (tab: EditorTabId) =>
|
||||||
|
document.getElementById(tabDomId(tab)) ??
|
||||||
|
document.getElementById(MORE_BUTTON_ID)
|
||||||
|
|
||||||
|
/** The place the shown tab and section name. */
|
||||||
|
function shownPlace(state: NavigationState): PlaceName {
|
||||||
|
return state.tab === 'annotations'
|
||||||
|
? `annotations.${state.section}`
|
||||||
|
: state.tab
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The text the live region says for a move to `target`. */
|
||||||
|
function useMoveText(): (target: EditorTarget) => string {
|
||||||
|
const t = useT()
|
||||||
|
return useCallback(
|
||||||
|
(target) => {
|
||||||
|
if (target.place === 'references') return t('editor.place.references')
|
||||||
|
const tab = t(`editor.tab.${target.tab}`)
|
||||||
|
if (!target.section) return tab
|
||||||
|
return `${tab} · ${t(`editor.place.${target.section}`)}`
|
||||||
|
},
|
||||||
|
[t],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function useLiveRegion() {
|
||||||
|
const [live, setLive] = useState('')
|
||||||
|
const announce = useCallback((text: string) => {
|
||||||
|
setLive((previous) => (previous === text ? `${text} ` : text))
|
||||||
|
}, [])
|
||||||
|
return { live, announce }
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Openers {
|
||||||
|
references: RefObject<HTMLElement | null>
|
||||||
|
section: RefObject<HTMLElement | null>
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The commands of the workspace: each commits the typed text, then moves. */
|
||||||
|
function useMoves(
|
||||||
|
dispatch: Dispatch<NavigationAction>,
|
||||||
|
announce: (text: string) => void,
|
||||||
|
openers: Openers,
|
||||||
|
) {
|
||||||
|
const t = useT()
|
||||||
|
const moveText = useMoveText()
|
||||||
|
const [move, setMove] = useState<Move | null>(null)
|
||||||
|
const go = useCallback(
|
||||||
|
(action: NavigationAction, kind: MoveKind, text: string) => {
|
||||||
|
commitFocusedField()
|
||||||
|
announce(text)
|
||||||
|
dispatch(action)
|
||||||
|
setMove({ kind })
|
||||||
|
},
|
||||||
|
[announce, dispatch],
|
||||||
|
)
|
||||||
|
const navigate = useCallback(
|
||||||
|
(target: EditorTarget, opener?: Opener) => {
|
||||||
|
if (target.place === 'references') {
|
||||||
|
openers.references.current = opener ?? null
|
||||||
|
}
|
||||||
|
go({ type: 'go_to', target }, 'go_to', moveText(target))
|
||||||
|
},
|
||||||
|
[go, moveText, openers],
|
||||||
|
)
|
||||||
|
const openSection = useCallback(
|
||||||
|
(section: AnnotationSection, opener?: Opener) => {
|
||||||
|
openers.section.current = opener ?? null
|
||||||
|
const text = `${t('editor.tab.annotations')} · ${t(`editor.place.${section}`)}`
|
||||||
|
go({ type: 'open_section', section }, 'section', text)
|
||||||
|
},
|
||||||
|
[go, openers, t],
|
||||||
|
)
|
||||||
|
const backToDrawing = useCallback(() => {
|
||||||
|
const text = `${t('editor.tab.annotations')} · ${t('editor.place.drawing')}`
|
||||||
|
go({ type: 'back_to_drawing' }, 'back', text)
|
||||||
|
}, [go, t])
|
||||||
|
const openReferences = useCallback(
|
||||||
|
(citedBy: ElementKey | null, opener?: Opener) => {
|
||||||
|
openers.references.current = opener ?? null
|
||||||
|
const action = { type: 'open_references', citedBy } as const
|
||||||
|
go(action, 'references', t('editor.place.references'))
|
||||||
|
},
|
||||||
|
[go, openers, t],
|
||||||
|
)
|
||||||
|
const closeReferences = useCallback(() => {
|
||||||
|
const text = t('editor.live.references_closed')
|
||||||
|
go({ type: 'close_references' }, 'references_closed', text)
|
||||||
|
}, [go, t])
|
||||||
|
return {
|
||||||
|
move,
|
||||||
|
navigate,
|
||||||
|
openSection,
|
||||||
|
backToDrawing,
|
||||||
|
openReferences,
|
||||||
|
closeReferences,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** « Retour au dessin »: the entry that opened the section, else the canvas box. */
|
||||||
|
function backTarget(opener: HTMLElement | null): HTMLElement | null {
|
||||||
|
if (opener && isShown(opener)) return opener
|
||||||
|
const entry = opener?.dataset.sectionEntry
|
||||||
|
const again = entry && visibleElement(`[data-section-entry="${entry}"]`)
|
||||||
|
return again || visibleElement(CANVAS_BOX)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Where the focus lands after a programmatic move; never `body`. */
|
||||||
|
function landingOf(move: Move, state: NavigationState): HTMLElement | null {
|
||||||
|
if (move.kind === 'references') return headingOf('references')
|
||||||
|
const place = state.focus ? placeOf(state.focus.target) : shownPlace(state)
|
||||||
|
return headingOf(place) ?? tabButton(state.tab)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After each move: a request an element answered is done; else (no owner answered, or
|
||||||
|
* the move had no request) the focus goes to the heading or the tab button.
|
||||||
|
*/
|
||||||
|
function useMoveFocus(
|
||||||
|
move: Move | null,
|
||||||
|
state: NavigationState,
|
||||||
|
outcomes: RefObject<Map<number, FocusOutcome>>,
|
||||||
|
dispatch: Dispatch<NavigationAction>,
|
||||||
|
openers: Openers,
|
||||||
|
) {
|
||||||
|
const handled = useRef<Move | null>(null)
|
||||||
|
useEffect(() => {
|
||||||
|
if (!move || handled.current === move) return
|
||||||
|
handled.current = move
|
||||||
|
if (move.kind === 'references_closed') {
|
||||||
|
const opener = openers.references.current
|
||||||
|
const target =
|
||||||
|
opener && isShown(opener)
|
||||||
|
? opener
|
||||||
|
: document.getElementById(REFERENCES_BUTTON_ID)
|
||||||
|
target?.focus()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const serial = state.focus?.serial
|
||||||
|
if (move.kind === 'go_to' && serial !== undefined) {
|
||||||
|
const outcome = outcomes.current.get(serial)
|
||||||
|
outcomes.current.delete(serial)
|
||||||
|
if (outcome === 'found' || outcome === 'kept') return
|
||||||
|
dispatch({ type: 'focus_consumed', serial })
|
||||||
|
}
|
||||||
|
if (move.kind === 'back') backTarget(openers.section.current)?.focus()
|
||||||
|
else landingOf(move, state)?.focus()
|
||||||
|
}, [move, state, outcomes, dispatch, openers])
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Navigation of the draft editor: the reducer plus the DOM side (focus, live region). */
|
||||||
|
export function useEditorNavigation(initialTab: EditorTabId): EditorNavigation {
|
||||||
|
const [state, dispatch] = useReducer(
|
||||||
|
navigationReducer,
|
||||||
|
initialTab,
|
||||||
|
initialNavigation,
|
||||||
|
)
|
||||||
|
const { live, announce } = useLiveRegion()
|
||||||
|
const outcomes = useRef(new Map<number, FocusOutcome>())
|
||||||
|
const openers = useRef<Openers>({
|
||||||
|
references: { current: null },
|
||||||
|
section: { current: null },
|
||||||
|
}).current
|
||||||
|
const moves = useMoves(dispatch, announce, openers)
|
||||||
|
const consumed = useCallback((serial: number, outcome: FocusOutcome) => {
|
||||||
|
outcomes.current.set(serial, outcome)
|
||||||
|
dispatch({ type: 'focus_consumed', serial })
|
||||||
|
}, [])
|
||||||
|
const selectTab = useCallback((tab: EditorTabId) => {
|
||||||
|
commitFocusedField()
|
||||||
|
dispatch({ type: 'select_tab', tab })
|
||||||
|
}, [])
|
||||||
|
useMoveFocus(moves.move, state, outcomes, dispatch, openers)
|
||||||
|
return { state, live, selectTab, consumed, announce, ...moves }
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import type {
|
|||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
import type { Locale } from '@/i18n/types'
|
import type { Locale } from '@/i18n/types'
|
||||||
import { elementLabel } from './sheetDocument'
|
import { elementLabel } from './sheetDocument'
|
||||||
import type { EditorTabId } from './tabs'
|
import { targetOfKey, type EditorTarget } from './navigation'
|
||||||
|
|
||||||
/** The server's cap on the document text (contract §12.2), shown beside the measure. */
|
/** The server's cap on the document text (contract §12.2), shown beside the measure. */
|
||||||
export const DOCUMENT_BYTES_CAP = 2_097_152
|
export const DOCUMENT_BYTES_CAP = 2_097_152
|
||||||
@@ -61,24 +61,26 @@ export function splitIssues(report: SheetReport): {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ROOT_TAB: Record<string, EditorTabId> = {
|
|
||||||
views: 'views',
|
|
||||||
annotations: 'annotations',
|
|
||||||
finding_zones: 'findings',
|
|
||||||
categories: 'general',
|
|
||||||
references: 'references',
|
|
||||||
}
|
|
||||||
const REGION_PATH = /^vertebral_config\.regions\[(\d+)\]/
|
const REGION_PATH = /^vertebral_config\.regions\[(\d+)\]/
|
||||||
const ROOT_PATH = /^(\w+)\[(\d+)\]/
|
const ROOT_PATH = /^(\w+)\[(\d+)\]/
|
||||||
|
|
||||||
export interface IssueTarget {
|
export interface IssueTarget {
|
||||||
tab: EditorTabId
|
/** The place to show, carrying the element when the path resolves in the document. */
|
||||||
/** The element the path names, when it resolves in the document. */
|
target: EditorTarget
|
||||||
key: ElementKey | null
|
/** The element's label, when it resolves. */
|
||||||
/** Its label. */
|
|
||||||
name: string | null
|
name: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** One key per list a path root names: `targetOfKey` is the only key-to-place table. */
|
||||||
|
const ROOT_SAMPLE: Record<string, ElementKey> = {
|
||||||
|
views: { kind: 'view', id: '' },
|
||||||
|
annotations: { kind: 'annotation', id: '' },
|
||||||
|
finding_zones: { kind: 'zone', id: '' },
|
||||||
|
categories: { kind: 'category', id: '' },
|
||||||
|
references: { kind: 'reference', id: '' },
|
||||||
|
}
|
||||||
|
const REGION_SAMPLE: ElementKey = { kind: 'region', code: '' }
|
||||||
|
|
||||||
type Kind = 'view' | 'annotation' | 'category' | 'zone' | 'reference'
|
type Kind = 'view' | 'annotation' | 'category' | 'zone' | 'reference'
|
||||||
const ROOT_KIND: Record<string, Kind> = {
|
const ROOT_KIND: Record<string, Kind> = {
|
||||||
views: 'view',
|
views: 'view',
|
||||||
@@ -127,22 +129,39 @@ function keyOf(doc: AnatomicalSheetDocument, path: string): ElementKey | null {
|
|||||||
return { kind: ROOT_KIND[match[1]], id: item.id } as ElementKey
|
return { kind: ROOT_KIND[match[1]], id: item.id } as ElementKey
|
||||||
}
|
}
|
||||||
|
|
||||||
function tabOf(path: string): EditorTabId | null {
|
const placeAlone = (sample: ElementKey): EditorTarget => ({
|
||||||
if (REGION_PATH.test(path)) return 'vertebrae'
|
...targetOfKey(sample),
|
||||||
|
key: null,
|
||||||
|
})
|
||||||
|
|
||||||
|
/** The place a path root names, without an element (the key does not resolve). */
|
||||||
|
function rootPlace(path: string): EditorTarget | null {
|
||||||
|
if (REGION_PATH.test(path)) return placeAlone(REGION_SAMPLE)
|
||||||
const root = ROOT_PATH.exec(path)?.[1]
|
const root = ROOT_PATH.exec(path)?.[1]
|
||||||
return root ? (ROOT_TAB[root] ?? null) : null
|
const sample = root ? ROOT_SAMPLE[root] : undefined
|
||||||
|
return sample ? placeAlone(sample) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The tab and element an issue path names (« Aller à … »); null when it names none. */
|
/** The place and element an issue path names (« Aller à … »); null when it names none. */
|
||||||
export function issueTarget(
|
export function issueTarget(
|
||||||
doc: AnatomicalSheetDocument,
|
doc: AnatomicalSheetDocument,
|
||||||
path: string,
|
path: string,
|
||||||
locale: Locale,
|
locale: Locale,
|
||||||
): IssueTarget | null {
|
): IssueTarget | null {
|
||||||
const tab = tabOf(path)
|
const place = rootPlace(path)
|
||||||
if (!tab) return null
|
if (!place) return null
|
||||||
const key = keyOf(doc, path)
|
const key = keyOf(doc, path)
|
||||||
return { tab, key, name: key ? elementLabel(doc, key, locale) : null }
|
if (!key) return { target: place, name: null }
|
||||||
|
return { target: targetOfKey(key), name: elementLabel(doc, key, locale) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The i18n key of the name of the place a target shows. */
|
||||||
|
export function placeKey(target: EditorTarget): string {
|
||||||
|
if (target.place === 'references') return 'editor.place.references'
|
||||||
|
if (target.section && target.section !== 'drawing') {
|
||||||
|
return `editor.place.${target.section}`
|
||||||
|
}
|
||||||
|
return `editor.tab.${target.tab}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/** « 2 097 152 » with plain spaces, as the plan words the size. */
|
/** « 2 097 152 » with plain spaces, as the plan words the size. */
|
||||||
|
|||||||
+32
-9
@@ -1184,7 +1184,7 @@ export const en: Dict = {
|
|||||||
'admin.overview.open_draft': 'Open the draft',
|
'admin.overview.open_draft': 'Open the draft',
|
||||||
'admin.overview.view_draft': 'View the draft',
|
'admin.overview.view_draft': 'View the draft',
|
||||||
'admin.failure.round.open': 'A review is already under way on this draft: it cannot be submitted again.',
|
'admin.failure.round.open': 'A review is already under way on this draft: it cannot be submitted again.',
|
||||||
'admin.failure.view.asset.unknown': "A drawing of the draft is not registered for this sheet: choose it again in the Views and drawings tab.",
|
'admin.failure.view.asset.unknown': "A drawing of the draft is not registered for this sheet: choose it again in Annotations, Views section.",
|
||||||
'admin.failure.draft.frozen': 'A review is under way on this draft: it can no longer be edited.',
|
'admin.failure.draft.frozen': 'A review is under way on this draft: it can no longer be edited.',
|
||||||
'admin.failure.draft.not_a_draft': 'This version is no longer a draft.',
|
'admin.failure.draft.not_a_draft': 'This version is no longer a draft.',
|
||||||
'admin.failure.sheet.inactive': 'This sheet is archived: its draft can no longer be edited.',
|
'admin.failure.sheet.inactive': 'This sheet is archived: its draft can no longer be edited.',
|
||||||
@@ -1192,13 +1192,37 @@ export const en: Dict = {
|
|||||||
'admin.failure.sheet.historical_read_only': 'The historical sheet cannot be edited: create a working copy.',
|
'admin.failure.sheet.historical_read_only': 'The historical sheet cannot be edited: create a working copy.',
|
||||||
'editor.tab.list': 'Draft sections',
|
'editor.tab.list': 'Draft sections',
|
||||||
'editor.tab.general': 'General',
|
'editor.tab.general': 'General',
|
||||||
'editor.tab.views': 'Views and drawings',
|
|
||||||
'editor.tab.annotations': 'Annotations',
|
'editor.tab.annotations': 'Annotations',
|
||||||
'editor.tab.findings': 'Findings',
|
'editor.tab.findings': 'Findings',
|
||||||
'editor.tab.references': 'References',
|
|
||||||
'editor.tab.vertebrae': 'Vertebrae',
|
|
||||||
'editor.tab.verification': 'Verification',
|
'editor.tab.verification': 'Verification',
|
||||||
'editor.tab.more': 'More',
|
'editor.tab.more': 'More',
|
||||||
|
'editor.tab.errors_one': '{count} error',
|
||||||
|
'editor.tab.errors_other': '{count} errors',
|
||||||
|
'editor.place.drawing': 'Drawing',
|
||||||
|
'editor.place.views': 'Views',
|
||||||
|
'editor.place.categories': 'Categories',
|
||||||
|
'editor.place.regions': 'Vertebral regions',
|
||||||
|
'editor.place.references': 'References',
|
||||||
|
'editor.section.back': 'Back to the drawing',
|
||||||
|
'editor.live.creation_kept': "A creation is in progress: finish or abandon it to reach this annotation.",
|
||||||
|
'editor.live.tracing_kept': "A tracing is in progress: finish or cancel it to reach this annotation.",
|
||||||
|
'editor.live.references_closed': 'References closed',
|
||||||
|
'editor.overview.label': 'Sheet overview',
|
||||||
|
'editor.overview.views': 'Views',
|
||||||
|
'editor.overview.view_main': 'Main view',
|
||||||
|
'editor.overview.view_detail': 'Detail view',
|
||||||
|
'editor.overview.annotations_one': '{count} annotation',
|
||||||
|
'editor.overview.annotations_other': '{count} annotations',
|
||||||
|
'editor.overview.manage_views': 'Manage views',
|
||||||
|
'editor.overview.see_views': 'See the views',
|
||||||
|
'editor.overview.categories': 'Categories',
|
||||||
|
'editor.overview.categories_empty': 'No category yet.',
|
||||||
|
'editor.overview.edit_categories': 'Edit categories',
|
||||||
|
'editor.overview.see_categories': 'See the categories',
|
||||||
|
'editor.overview.regions_one': 'Vertebral regions ({count} region)',
|
||||||
|
'editor.overview.regions_other': 'Vertebral regions ({count} regions)',
|
||||||
|
'editor.references.open': 'References',
|
||||||
|
'editor.references.close': 'Close the references',
|
||||||
'editor.draft.loading': 'Loading the draft…',
|
'editor.draft.loading': 'Loading the draft…',
|
||||||
'editor.draft.none': 'This sheet has no draft.',
|
'editor.draft.none': 'This sheet has no draft.',
|
||||||
'editor.draft.overview_link': 'View the sheet',
|
'editor.draft.overview_link': 'View the sheet',
|
||||||
@@ -1386,7 +1410,7 @@ export const en: Dict = {
|
|||||||
'editor.views.new_hint': 'Fill in the crop for a cropped view; leave it empty for a view that will have its own drawing (chosen once the view is added).',
|
'editor.views.new_hint': 'Fill in the crop for a cropped view; leave it empty for a view that will have its own drawing (chosen once the view is added).',
|
||||||
'editor.views.add': 'Add the view',
|
'editor.views.add': 'Add the view',
|
||||||
'editor.views.required': 'Fill in the French and English names of the view.',
|
'editor.views.required': 'Fill in the French and English names of the view.',
|
||||||
'editor.views.frame.newly_invalid': 'This frame change would put the geometry of these elements in error: {names}. Move them first (Annotations tab).',
|
'editor.views.frame.newly_invalid': 'This frame change would put the geometry of these elements in error: {names}. Move them first (Annotations, drawing).',
|
||||||
'editor.views.frame.view_unmeasured': 'This change would make a view that holds annotations unmeasurable: {names}.',
|
'editor.views.frame.view_unmeasured': 'This change would make a view that holds annotations unmeasurable: {names}.',
|
||||||
'editor.views.frame.kept': 'The drawing stays uploaded; the view keeps its previous drawing.',
|
'editor.views.frame.kept': 'The drawing stays uploaded; the view keeps its previous drawing.',
|
||||||
'editor.views.frame.newly_invalid_repairable': 'These elements fall outside the new frame: {names}. Choose the drawing again to repair them as you attach it.',
|
'editor.views.frame.newly_invalid_repairable': 'These elements fall outside the new frame: {names}. Choose the drawing again to repair them as you attach it.',
|
||||||
@@ -1476,13 +1500,13 @@ export const en: Dict = {
|
|||||||
'editor.annotations.tool_hint.zone': 'Tool: zone · click to place the vertices; Enter or « Close the tracing » finishes, Esc cancels.',
|
'editor.annotations.tool_hint.zone': 'Tool: zone · click to place the vertices; Enter or « Close the tracing » finishes, Esc cancels.',
|
||||||
'editor.annotations.tool_hint.link': 'Tool: link to a detail view · trace the outline that opens the view; Enter finishes, Esc cancels.',
|
'editor.annotations.tool_hint.link': 'Tool: link to a detail view · trace the outline that opens the view; Enter finishes, Esc cancels.',
|
||||||
'editor.annotations.views': 'Views',
|
'editor.annotations.views': 'Views',
|
||||||
'editor.annotations.unmeasured.hint': 'This drawing cannot be measured: add or fix its illustration (tab Views and drawings) before placing or moving elements.',
|
'editor.annotations.unmeasured.hint': 'This drawing cannot be measured: add or fix its illustration (Annotations, Views section) before placing or moving elements.',
|
||||||
'editor.annotations.outside': 'Click inside the drawing.',
|
'editor.annotations.outside': 'Click inside the drawing.',
|
||||||
'editor.annotations.correction': 'The point does not fit where you clicked. Corrected position proposed: x = {x}, y = {y}.',
|
'editor.annotations.correction': 'The point does not fit where you clicked. Corrected position proposed: x = {x}, y = {y}.',
|
||||||
'editor.annotations.correction_use': 'Use this position',
|
'editor.annotations.correction_use': 'Use this position',
|
||||||
'editor.annotations.correction_cancel': 'Cancel',
|
'editor.annotations.correction_cancel': 'Cancel',
|
||||||
'editor.annotations.no_category': 'Create an annotation category first (tab General).',
|
'editor.annotations.no_category': 'Create an annotation category first (Annotations, Categories section).',
|
||||||
'editor.annotations.no_child_view': 'No detail view opens from this view: create one in the Views and drawings tab.',
|
'editor.annotations.no_child_view': 'No detail view opens from this view: create one in Annotations, Views section.',
|
||||||
'editor.annotations.add.point': 'Add a point',
|
'editor.annotations.add.point': 'Add a point',
|
||||||
'editor.annotations.add.zone': 'Add a zone',
|
'editor.annotations.add.zone': 'Add a zone',
|
||||||
'editor.annotations.add.detail_trigger': 'Add a link',
|
'editor.annotations.add.detail_trigger': 'Add a link',
|
||||||
@@ -1518,7 +1542,6 @@ export const en: Dict = {
|
|||||||
'editor.annotations.list': 'Annotations of the view',
|
'editor.annotations.list': 'Annotations of the view',
|
||||||
'editor.annotations.list_empty': 'No annotation in this view.',
|
'editor.annotations.list_empty': 'No annotation in this view.',
|
||||||
'editor.annotations.selection': 'Selection: {kind} « {name} »',
|
'editor.annotations.selection': 'Selection: {kind} « {name} »',
|
||||||
'editor.annotations.select_hint': 'Select an annotation on the drawing or in the list to see its properties.',
|
|
||||||
'editor.annotations.properties': 'Annotation properties',
|
'editor.annotations.properties': 'Annotation properties',
|
||||||
'editor.annotations.tracing_one': '{count} vertex placed.',
|
'editor.annotations.tracing_one': '{count} vertex placed.',
|
||||||
'editor.annotations.tracing_other': '{count} vertices placed.',
|
'editor.annotations.tracing_other': '{count} vertices placed.',
|
||||||
|
|||||||
+32
-9
@@ -1215,7 +1215,7 @@ export const fr: Dict = {
|
|||||||
'admin.overview.open_draft': 'Ouvrir le brouillon',
|
'admin.overview.open_draft': 'Ouvrir le brouillon',
|
||||||
'admin.overview.view_draft': 'Consulter le brouillon',
|
'admin.overview.view_draft': 'Consulter le brouillon',
|
||||||
'admin.failure.round.open': "Une revue est déjà en cours sur ce brouillon : il ne peut pas être soumis de nouveau.",
|
'admin.failure.round.open': "Une revue est déjà en cours sur ce brouillon : il ne peut pas être soumis de nouveau.",
|
||||||
'admin.failure.view.asset.unknown': "Une illustration du brouillon n'est pas enregistrée pour cette fiche : choisissez-la de nouveau dans l'onglet Vues et illustrations.",
|
'admin.failure.view.asset.unknown': "Une illustration du brouillon n'est pas enregistrée pour cette fiche : choisissez-la de nouveau dans Annotations, section Vues.",
|
||||||
'admin.failure.draft.frozen': 'Une revue est en cours sur ce brouillon : il ne peut plus être modifié.',
|
'admin.failure.draft.frozen': 'Une revue est en cours sur ce brouillon : il ne peut plus être modifié.',
|
||||||
'admin.failure.draft.not_a_draft': "Cette version n'est plus un brouillon.",
|
'admin.failure.draft.not_a_draft': "Cette version n'est plus un brouillon.",
|
||||||
'admin.failure.sheet.inactive': 'Cette fiche est archivée : son brouillon ne peut plus être modifié.',
|
'admin.failure.sheet.inactive': 'Cette fiche est archivée : son brouillon ne peut plus être modifié.',
|
||||||
@@ -1223,13 +1223,37 @@ export const fr: Dict = {
|
|||||||
'admin.failure.sheet.historical_read_only': 'La fiche historique ne se modifie pas : créez une copie de travail.',
|
'admin.failure.sheet.historical_read_only': 'La fiche historique ne se modifie pas : créez une copie de travail.',
|
||||||
'editor.tab.list': 'Sections du brouillon',
|
'editor.tab.list': 'Sections du brouillon',
|
||||||
'editor.tab.general': 'Général',
|
'editor.tab.general': 'Général',
|
||||||
'editor.tab.views': 'Vues et illustrations',
|
|
||||||
'editor.tab.annotations': 'Annotations',
|
'editor.tab.annotations': 'Annotations',
|
||||||
'editor.tab.findings': 'Constats',
|
'editor.tab.findings': 'Constats',
|
||||||
'editor.tab.references': 'Références',
|
|
||||||
'editor.tab.vertebrae': 'Vertèbres',
|
|
||||||
'editor.tab.verification': 'Vérification',
|
'editor.tab.verification': 'Vérification',
|
||||||
'editor.tab.more': 'Plus',
|
'editor.tab.more': 'Plus',
|
||||||
|
'editor.tab.errors_one': '{count} erreur',
|
||||||
|
'editor.tab.errors_other': '{count} erreurs',
|
||||||
|
'editor.place.drawing': 'Dessin',
|
||||||
|
'editor.place.views': 'Vues',
|
||||||
|
'editor.place.categories': 'Catégories',
|
||||||
|
'editor.place.regions': 'Régions vertébrales',
|
||||||
|
'editor.place.references': 'Références',
|
||||||
|
'editor.section.back': 'Retour au dessin',
|
||||||
|
'editor.live.creation_kept': "Une création est en cours : terminez-la ou abandonnez-la pour atteindre cette annotation.",
|
||||||
|
'editor.live.tracing_kept': "Un tracé est en cours : terminez-le ou annulez-le pour atteindre cette annotation.",
|
||||||
|
'editor.live.references_closed': 'Références fermées',
|
||||||
|
'editor.overview.label': 'Aperçu de la fiche',
|
||||||
|
'editor.overview.views': 'Vues',
|
||||||
|
'editor.overview.view_main': 'Vue principale',
|
||||||
|
'editor.overview.view_detail': 'Vue détaillée',
|
||||||
|
'editor.overview.annotations_one': '{count} annotation',
|
||||||
|
'editor.overview.annotations_other': '{count} annotations',
|
||||||
|
'editor.overview.manage_views': 'Gérer les vues',
|
||||||
|
'editor.overview.see_views': 'Voir les vues',
|
||||||
|
'editor.overview.categories': 'Catégories',
|
||||||
|
'editor.overview.categories_empty': 'Aucune catégorie pour l\'instant.',
|
||||||
|
'editor.overview.edit_categories': 'Modifier les catégories',
|
||||||
|
'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.references.open': 'Références',
|
||||||
|
'editor.references.close': 'Fermer les références',
|
||||||
'editor.draft.loading': 'Chargement du brouillon…',
|
'editor.draft.loading': 'Chargement du brouillon…',
|
||||||
'editor.draft.none': "Cette fiche n'a pas de brouillon.",
|
'editor.draft.none': "Cette fiche n'a pas de brouillon.",
|
||||||
'editor.draft.overview_link': 'Voir la fiche',
|
'editor.draft.overview_link': 'Voir la fiche',
|
||||||
@@ -1417,7 +1441,7 @@ export const fr: Dict = {
|
|||||||
'editor.views.new_hint': 'Saisissez le recadrage pour une vue recadrée ; laissez-le vide pour une vue qui aura sa propre illustration (à choisir une fois la vue ajoutée).',
|
'editor.views.new_hint': 'Saisissez le recadrage pour une vue recadrée ; laissez-le vide pour une vue qui aura sa propre illustration (à choisir une fois la vue ajoutée).',
|
||||||
'editor.views.add': 'Ajouter la vue',
|
'editor.views.add': 'Ajouter la vue',
|
||||||
'editor.views.required': 'Renseignez les noms français et anglais de la vue.',
|
'editor.views.required': 'Renseignez les noms français et anglais de la vue.',
|
||||||
'editor.views.frame.newly_invalid': "Ce changement de cadre mettrait en erreur la géométrie de : {names}. Déplacez d'abord ces éléments (onglet Annotations).",
|
'editor.views.frame.newly_invalid': "Ce changement de cadre mettrait en erreur la géométrie de : {names}. Déplacez d'abord ces éléments (Annotations, dessin).",
|
||||||
'editor.views.frame.view_unmeasured': 'Ce changement rendrait non mesurable une vue qui porte des annotations : {names}.',
|
'editor.views.frame.view_unmeasured': 'Ce changement rendrait non mesurable une vue qui porte des annotations : {names}.',
|
||||||
'editor.views.frame.kept': "L'illustration reste téléversée ; la vue garde son illustration précédente.",
|
'editor.views.frame.kept': "L'illustration reste téléversée ; la vue garde son illustration précédente.",
|
||||||
'editor.views.frame.newly_invalid_repairable': "Ces éléments sortent du nouveau cadre : {names}. Choisissez de nouveau l'illustration pour les réparer en l'attachant.",
|
'editor.views.frame.newly_invalid_repairable': "Ces éléments sortent du nouveau cadre : {names}. Choisissez de nouveau l'illustration pour les réparer en l'attachant.",
|
||||||
@@ -1507,13 +1531,13 @@ export const fr: Dict = {
|
|||||||
'editor.annotations.tool_hint.zone': 'Outil : zone · cliquez pour poser les sommets ; Entrée ou « Fermer le tracé » termine, Échap annule.',
|
'editor.annotations.tool_hint.zone': 'Outil : zone · cliquez pour poser les sommets ; Entrée ou « Fermer le tracé » termine, Échap annule.',
|
||||||
'editor.annotations.tool_hint.link': 'Outil : accès à une vue détaillée · tracez le contour qui ouvre la vue ; Entrée termine, Échap annule.',
|
'editor.annotations.tool_hint.link': 'Outil : accès à une vue détaillée · tracez le contour qui ouvre la vue ; Entrée termine, Échap annule.',
|
||||||
'editor.annotations.views': 'Vues',
|
'editor.annotations.views': 'Vues',
|
||||||
'editor.annotations.unmeasured.hint': "Ce dessin n'est pas mesurable : ajoutez ou corrigez son illustration (onglet Vues et illustrations) avant de placer ou de déplacer des éléments.",
|
'editor.annotations.unmeasured.hint': "Ce dessin n'est pas mesurable : ajoutez ou corrigez son illustration (Annotations, section Vues) avant de placer ou de déplacer des éléments.",
|
||||||
'editor.annotations.outside': "Cliquez à l'intérieur du dessin.",
|
'editor.annotations.outside': "Cliquez à l'intérieur du dessin.",
|
||||||
'editor.annotations.correction': "Le point ne tient pas à l'endroit choisi. Position corrigée proposée : x = {x}, y = {y}.",
|
'editor.annotations.correction': "Le point ne tient pas à l'endroit choisi. Position corrigée proposée : x = {x}, y = {y}.",
|
||||||
'editor.annotations.correction_use': 'Utiliser cette position',
|
'editor.annotations.correction_use': 'Utiliser cette position',
|
||||||
'editor.annotations.correction_cancel': 'Annuler',
|
'editor.annotations.correction_cancel': 'Annuler',
|
||||||
'editor.annotations.no_category': "Créez d'abord une catégorie d'annotation (onglet Général).",
|
'editor.annotations.no_category': "Créez d'abord une catégorie d'annotation (Annotations, section Catégories).",
|
||||||
'editor.annotations.no_child_view': "Aucune vue détaillée ne s'ouvre depuis cette vue : créez-en une dans l'onglet Vues et illustrations.",
|
'editor.annotations.no_child_view': "Aucune vue détaillée ne s'ouvre depuis cette vue : créez-en une dans Annotations, section Vues.",
|
||||||
'editor.annotations.add.point': 'Ajouter un point',
|
'editor.annotations.add.point': 'Ajouter un point',
|
||||||
'editor.annotations.add.zone': 'Ajouter une zone',
|
'editor.annotations.add.zone': 'Ajouter une zone',
|
||||||
'editor.annotations.add.detail_trigger': 'Ajouter un accès',
|
'editor.annotations.add.detail_trigger': 'Ajouter un accès',
|
||||||
@@ -1549,7 +1573,6 @@ export const fr: Dict = {
|
|||||||
'editor.annotations.list': 'Annotations de la vue',
|
'editor.annotations.list': 'Annotations de la vue',
|
||||||
'editor.annotations.list_empty': 'Aucune annotation dans cette vue.',
|
'editor.annotations.list_empty': 'Aucune annotation dans cette vue.',
|
||||||
'editor.annotations.selection': 'Sélection : {kind} « {name} »',
|
'editor.annotations.selection': 'Sélection : {kind} « {name} »',
|
||||||
'editor.annotations.select_hint': 'Sélectionnez une annotation sur le dessin ou dans la liste pour voir ses propriétés.',
|
|
||||||
'editor.annotations.properties': "Propriétés de l'annotation",
|
'editor.annotations.properties': "Propriétés de l'annotation",
|
||||||
'editor.annotations.tracing_one': '{count} sommet posé.',
|
'editor.annotations.tracing_one': '{count} sommet posé.',
|
||||||
'editor.annotations.tracing_other': '{count} sommets posés.',
|
'editor.annotations.tracing_other': '{count} sommets posés.',
|
||||||
|
|||||||
@@ -41,7 +41,14 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
|||||||
submitSheetReview: vi.fn(),
|
submitSheetReview: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const props = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
|
const props = {
|
||||||
|
readOnly: false,
|
||||||
|
navigate: vi.fn(),
|
||||||
|
reloadSheet: vi.fn(),
|
||||||
|
section: 'drawing' as const,
|
||||||
|
onOpenSection: vi.fn(),
|
||||||
|
onBack: vi.fn(),
|
||||||
|
}
|
||||||
const named = (id: string, cx: number, cy: number, r: number) =>
|
const named = (id: string, cx: number, cy: number, r: number) =>
|
||||||
point(id, cx, cy, r)
|
point(id, cx, cy, r)
|
||||||
const annotations = () => store.getState().previewState!.document.annotations
|
const annotations = () => store.getState().previewState!.document.annotations
|
||||||
@@ -484,7 +491,7 @@ describe('tools and categories', () => {
|
|||||||
expect(screen.getByRole('button', { name: 'Point' })).toBeDisabled()
|
expect(screen.getByRole('button', { name: 'Point' })).toBeDisabled()
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(
|
screen.getByText(
|
||||||
"Créez d'abord une catégorie d'annotation (onglet Général).",
|
"Créez d'abord une catégorie d'annotation (Annotations, section Catégories).",
|
||||||
),
|
),
|
||||||
).toBeInTheDocument()
|
).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
import { SheetFailure } from '@faunosteo/supabase'
|
import { SheetFailure } from '@faunosteo/supabase'
|
||||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||||
import ViewsTab from '@/components/editor/tabs/ViewsTab'
|
import ViewsSection from '@/components/editor/annotations/sections/ViewsSection'
|
||||||
import { cleanSvg } from '@/editor/core/cleaning'
|
import { cleanSvg } from '@/editor/core/cleaning'
|
||||||
import { createHash } from 'node:crypto'
|
import { createHash } from 'node:crypto'
|
||||||
import { getDict } from '@/i18n'
|
import { getDict } from '@/i18n'
|
||||||
@@ -35,7 +35,7 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
|||||||
confirmSheetAssetUpload: vi.fn(),
|
confirmSheetAssetUpload: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const props = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
|
const props = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
||||||
const NEW_ASSET = '22222222-2222-4222-8222-222222222222'
|
const NEW_ASSET = '22222222-2222-4222-8222-222222222222'
|
||||||
const doc = (): AnatomicalSheetDocument =>
|
const doc = (): AnatomicalSheetDocument =>
|
||||||
JSON.parse(store.getState().documentText)
|
JSON.parse(store.getState().documentText)
|
||||||
@@ -91,7 +91,7 @@ async function pick(text: string, name = 'dessin.svg') {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
useLocaleStore.setState({ locale: 'fr' })
|
useLocaleStore.setState({ locale: 'fr' })
|
||||||
await openReady()
|
await openReady()
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
})
|
})
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
|||||||
submitSheetReview: vi.fn(),
|
submitSheetReview: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const props = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
|
const props = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
||||||
const doc = (): AnatomicalSheetDocument =>
|
const doc = (): AnatomicalSheetDocument =>
|
||||||
JSON.parse(store.getState().documentText)
|
JSON.parse(store.getState().documentText)
|
||||||
const name = (n: string) => ({ fr: n, en: n })
|
const name = (n: string) => ({ fr: n, en: n })
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
/** Lot J fix: « Aller à … » seeds each tab's own selection once. */
|
/** « Aller à … »: each request reaches the place its target names, once, and never lands on body. */
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { cleanup, render, screen } from '@testing-library/react'
|
import { cleanup, render, screen, waitFor } from '@testing-library/react'
|
||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
import type {
|
import type {
|
||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
ElementKey,
|
ElementKey,
|
||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
import FindingsTab from '@/components/editor/tabs/FindingsTab'
|
import FindingsTab from '@/components/editor/tabs/FindingsTab'
|
||||||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
import RegionsSection from '@/components/editor/annotations/sections/RegionsSection'
|
||||||
import VertebraeTab from '@/components/editor/tabs/VertebraeTab'
|
import EditorTabBody from '@/components/editor/EditorTabBody'
|
||||||
|
import EditorTabs from '@/components/editor/EditorTabs'
|
||||||
|
import ReferencesPanel from '@/components/editor/references/ReferencesPanel'
|
||||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||||
import { FocusConsumedContext, type FocusRequest } from '@/editor/focusRequest'
|
import {
|
||||||
|
FocusConsumedContext,
|
||||||
|
ownedBy,
|
||||||
|
type FocusRequest,
|
||||||
|
} from '@/editor/focusRequest'
|
||||||
|
import { targetOfKey, type EditorTarget } from '@/editor/navigation'
|
||||||
|
import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
||||||
import { issueTarget } from '@/editor/verification'
|
import { issueTarget } from '@/editor/verification'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import { edit, insert, point } from '../helpers/editorFixtures'
|
import { edit, insert, point } from '../helpers/editorFixtures'
|
||||||
@@ -32,7 +40,17 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
|||||||
submitSheetReview: vi.fn(),
|
submitSheetReview: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const base = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
|
const base = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
||||||
|
const section = {
|
||||||
|
section: 'drawing' as const,
|
||||||
|
onOpenSection: vi.fn(),
|
||||||
|
onBack: vi.fn(),
|
||||||
|
}
|
||||||
|
const panel = { open: true, onClose: vi.fn() }
|
||||||
|
const request = (key: ElementKey, serial = 1): FocusRequest => ({
|
||||||
|
target: targetOfKey(key),
|
||||||
|
serial,
|
||||||
|
})
|
||||||
const doc = (): AnatomicalSheetDocument =>
|
const doc = (): AnatomicalSheetDocument =>
|
||||||
JSON.parse(store.getState().documentText)
|
JSON.parse(store.getState().documentText)
|
||||||
const name = (n: string) => ({ fr: n, en: n })
|
const name = (n: string) => ({ fr: n, en: n })
|
||||||
@@ -90,24 +108,29 @@ describe('focus requests', () => {
|
|||||||
zone_id: 'zone-a',
|
zone_id: 'zone-a',
|
||||||
path: ['fcat-a', 'node-a'],
|
path: ['fcat-a', 'node-a'],
|
||||||
}
|
}
|
||||||
render(<FindingsTab {...base} focus={{ key, serial: 1 }} />)
|
render(<FindingsTab {...base} focus={request(key)} />)
|
||||||
const item = await screen.findByRole('treeitem', { name: /Nœud A/ })
|
const item = await screen.findByRole('treeitem', { name: /Nœud A/ })
|
||||||
expect(item.getAttribute('aria-selected')).toBe('true')
|
expect(item.getAttribute('aria-selected')).toBe('true')
|
||||||
|
await waitFor(() => expect(document.activeElement).toBe(item))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Annotations: selects the annotation of the request', async () => {
|
it('Annotations: selects the annotation and focuses the properties heading', async () => {
|
||||||
const text = insert(baseText(), point('anno-b', 20, 20, 3))
|
const text = insert(baseText(), point('anno-b', 20, 20, 3))
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
render(
|
render(
|
||||||
<AnnotationsTab
|
<AnnotationsTab
|
||||||
{...base}
|
{...base}
|
||||||
focus={{ key: { kind: 'annotation', id: 'anno-b' }, serial: 1 }}
|
{...section}
|
||||||
|
focus={request({ kind: 'annotation', id: 'anno-b' })}
|
||||||
/>,
|
/>,
|
||||||
)
|
)
|
||||||
expect(await screen.findAllByText(/anno-b|Sélection/)).not.toHaveLength(0)
|
expect(await screen.findAllByText(/anno-b|Sélection/)).not.toHaveLength(0)
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(document.activeElement).toHaveAttribute('data-properties-heading'),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Références and Vertèbres: focus the named row', async () => {
|
it('Références and Régions: focus the named row', async () => {
|
||||||
let text = insert(baseText(), {
|
let text = insert(baseText(), {
|
||||||
kind: 'reference',
|
kind: 'reference',
|
||||||
value: {
|
value: {
|
||||||
@@ -129,9 +152,10 @@ describe('focus requests', () => {
|
|||||||
})
|
})
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
render(
|
render(
|
||||||
<ReferencesTab
|
<ReferencesPanel
|
||||||
{...base}
|
{...base}
|
||||||
focus={{ key: { kind: 'reference', id: 'ref-a' }, serial: 1 }}
|
{...panel}
|
||||||
|
focus={request({ kind: 'reference', id: 'ref-a' })}
|
||||||
/>,
|
/>,
|
||||||
)
|
)
|
||||||
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
||||||
@@ -139,9 +163,9 @@ describe('focus requests', () => {
|
|||||||
)
|
)
|
||||||
cleanup()
|
cleanup()
|
||||||
render(
|
render(
|
||||||
<VertebraeTab
|
<RegionsSection
|
||||||
{...base}
|
{...base}
|
||||||
focus={{ key: { kind: 'region', code: 'C' }, serial: 1 }}
|
focus={request({ kind: 'region', code: 'C' })}
|
||||||
/>,
|
/>,
|
||||||
)
|
)
|
||||||
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
||||||
@@ -161,15 +185,37 @@ describe('focus requests', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
const focus = {
|
const focus = request({ kind: 'reference', id: 'ref-a' })
|
||||||
key: { kind: 'reference', id: 'ref-a' } as ElementKey,
|
const view = render(<ReferencesPanel {...base} {...panel} focus={focus} />)
|
||||||
serial: 1,
|
|
||||||
}
|
|
||||||
const view = render(<ReferencesTab {...base} focus={focus} />)
|
|
||||||
;(document.activeElement as HTMLElement).blur()
|
;(document.activeElement as HTMLElement).blur()
|
||||||
view.rerender(<ReferencesTab {...base} focus={focus} />)
|
view.rerender(<ReferencesPanel {...base} {...panel} focus={focus} />)
|
||||||
expect(document.activeElement?.getAttribute('data-focus-key')).toBeNull()
|
expect(document.activeElement?.getAttribute('data-focus-key')).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('reports found, or none when the place holds no such element', async () => {
|
||||||
|
await openReady({ text: findingsText() })
|
||||||
|
const consumed = vi.fn()
|
||||||
|
const gone: ElementKey = { kind: 'zone', id: 'zone-gone' }
|
||||||
|
render(
|
||||||
|
<FocusConsumedContext value={consumed}>
|
||||||
|
<FindingsTab {...base} focus={request(gone, 4)} />
|
||||||
|
</FocusConsumedContext>,
|
||||||
|
)
|
||||||
|
await waitFor(() => expect(consumed).toHaveBeenCalledWith(4, 'none'))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('ownedBy', () => {
|
||||||
|
it('passes a request only to the place its target names', () => {
|
||||||
|
const view = request({ kind: 'view', id: 'view-main' })
|
||||||
|
expect(ownedBy(view, 'annotations.views')).toBe(view)
|
||||||
|
expect(ownedBy(view, 'annotations.drawing')).toBeUndefined()
|
||||||
|
expect(ownedBy(view, 'general')).toBeUndefined()
|
||||||
|
const ref = request({ kind: 'reference', id: 'ref-a' })
|
||||||
|
expect(ownedBy(ref, 'references')).toBe(ref)
|
||||||
|
expect(ownedBy(ref, 'findings')).toBeUndefined()
|
||||||
|
expect(ownedBy(undefined, 'general')).toBeUndefined()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('issueTarget', () => {
|
describe('issueTarget', () => {
|
||||||
@@ -178,50 +224,122 @@ describe('issueTarget', () => {
|
|||||||
const d = doc()
|
const d = doc()
|
||||||
const path = 'finding_zones[0].categories[0].children[0].reference_ids[1]'
|
const path = 'finding_zones[0].categories[0].children[0].reference_ids[1]'
|
||||||
expect(issueTarget(d, path, 'fr')).toMatchObject({
|
expect(issueTarget(d, path, 'fr')).toMatchObject({
|
||||||
|
target: {
|
||||||
|
place: 'tab',
|
||||||
tab: 'findings',
|
tab: 'findings',
|
||||||
key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a', 'node-a'] },
|
key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a', 'node-a'] },
|
||||||
|
},
|
||||||
name: 'Nœud A',
|
name: 'Nœud A',
|
||||||
})
|
})
|
||||||
expect(issueTarget(d, 'finding_zones[0]', 'fr')?.key).toEqual({
|
expect(issueTarget(d, 'finding_zones[0]', 'fr')?.target).toMatchObject({
|
||||||
kind: 'zone',
|
key: { kind: 'zone', id: 'zone-a' },
|
||||||
id: 'zone-a',
|
|
||||||
})
|
})
|
||||||
expect(
|
expect(
|
||||||
issueTarget(d, 'vertebral_config.regions[3].count_range', 'fr'),
|
issueTarget(d, 'vertebral_config.regions[3].count_range', 'fr'),
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
tab: 'vertebrae',
|
target: { tab: 'annotations', section: 'regions', key: null },
|
||||||
key: null,
|
|
||||||
})
|
})
|
||||||
expect(issueTarget(d, 'nothing', 'fr')).toBeNull()
|
expect(issueTarget(d, 'nothing', 'fr')).toBeNull()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
/** The route's contract: one tab mounted at a time, the request cleared once consumed. */
|
/** The workspace's wiring in miniature: the hook, the tab row, the shown body. */
|
||||||
function Harness() {
|
function Probe({ go, tier }: { go: EditorTarget; tier: 'wide' | 'small' }) {
|
||||||
const [tab, setTab] = useState<'references' | 'vertebrae'>('references')
|
const nav = useEditorNavigation('verification')
|
||||||
const [focus, setFocus] = useState<FocusRequest | undefined>({
|
const { state } = nav
|
||||||
key: { kind: 'reference', id: 'ref-a' },
|
return (
|
||||||
serial: 1,
|
<FocusConsumedContext value={nav.consumed}>
|
||||||
|
<EditorTabs active={state.tab} tier={tier} onSelect={nav.selectTab} />
|
||||||
|
<button onClick={() => nav.navigate(go)}>go</button>
|
||||||
|
<EditorTabBody
|
||||||
|
tab={state.tab}
|
||||||
|
{...base}
|
||||||
|
navigate={nav.navigate}
|
||||||
|
focus={ownedBy(state.focus, state.tab)}
|
||||||
|
annotations={{
|
||||||
|
section: state.section,
|
||||||
|
onOpenSection: nav.openSection,
|
||||||
|
onBack: nav.backToDrawing,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</FocusConsumedContext>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('a request that finds nothing', () => {
|
||||||
|
const missing: EditorTarget = {
|
||||||
|
place: 'tab',
|
||||||
|
tab: 'findings',
|
||||||
|
section: null,
|
||||||
|
key: { kind: 'zone', id: 'zone-gone' },
|
||||||
|
}
|
||||||
|
|
||||||
|
it('lands on the tab button, never on body', async () => {
|
||||||
|
await openReady({ text: findingsText() })
|
||||||
|
const user = userEvent.setup()
|
||||||
|
render(<Probe go={missing} tier="wide" />)
|
||||||
|
await user.click(screen.getByText('go'))
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(document.activeElement).toBe(
|
||||||
|
screen.getByRole('tab', { name: 'Constats' }),
|
||||||
|
),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('below 640 px lands on « Plus » while the tab sits in its closed list', async () => {
|
||||||
|
await openReady({ text: findingsText() })
|
||||||
|
const user = userEvent.setup()
|
||||||
|
render(<Probe go={missing} tier="small" />)
|
||||||
|
await user.click(screen.getByText('go'))
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(document.activeElement).toBe(
|
||||||
|
screen.getByRole('button', { name: 'Plus' }),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a found element keeps the focus it took', async () => {
|
||||||
|
await openReady({ text: findingsText() })
|
||||||
|
const user = userEvent.setup()
|
||||||
|
const key: ElementKey = { kind: 'zone', id: 'zone-a' }
|
||||||
|
render(<Probe go={targetOfKey(key)} tier="wide" />)
|
||||||
|
await user.click(screen.getByText('go'))
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(document.activeElement).toBe(
|
||||||
|
screen.getByRole('treeitem', { name: /Zone A/ }),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
/** The route's contract: one place mounted at a time, the request cleared once consumed. */
|
||||||
|
function Harness() {
|
||||||
|
const [shown, setShown] = useState<'references' | 'regions'>('references')
|
||||||
|
const [focus, setFocus] = useState<FocusRequest | undefined>(
|
||||||
|
request({ kind: 'reference', id: 'ref-a' }),
|
||||||
|
)
|
||||||
const clear = (serial: number) =>
|
const clear = (serial: number) =>
|
||||||
setFocus((prev) => (prev?.serial === serial ? undefined : prev))
|
setFocus((prev) => (prev?.serial === serial ? undefined : prev))
|
||||||
const Body = tab === 'references' ? ReferencesTab : VertebraeTab
|
|
||||||
return (
|
return (
|
||||||
<FocusConsumedContext value={clear}>
|
<FocusConsumedContext value={clear}>
|
||||||
<button
|
<button
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
setTab(tab === 'references' ? 'vertebrae' : 'references')
|
setShown(shown === 'references' ? 'regions' : 'references')
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
switch
|
switch
|
||||||
</button>
|
</button>
|
||||||
<Body {...base} focus={focus} />
|
{shown === 'references' ? (
|
||||||
|
<ReferencesPanel {...base} {...panel} focus={focus} />
|
||||||
|
) : (
|
||||||
|
<RegionsSection {...base} focus={focus} />
|
||||||
|
)}
|
||||||
</FocusConsumedContext>
|
</FocusConsumedContext>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('a consumed request', () => {
|
describe('a consumed request', () => {
|
||||||
it('is not replayed when the tab is left and reopened', async () => {
|
it('is not replayed when the place is left and reopened', async () => {
|
||||||
const text = insert(baseText(), {
|
const text = insert(baseText(), {
|
||||||
kind: 'reference',
|
kind: 'reference',
|
||||||
value: {
|
value: {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ describe('modeAfterSave', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('tabsFor', () => {
|
describe('tabsFor', () => {
|
||||||
it('the static lists of board 05', () => {
|
it('the static lists of board 05, four tabs', () => {
|
||||||
expect(tabsFor('wide').more).toEqual([])
|
expect(tabsFor('wide').more).toEqual([])
|
||||||
expect(tabsFor('medium').shown).toEqual([
|
expect(tabsFor('medium').shown).toEqual([
|
||||||
'general',
|
'general',
|
||||||
@@ -106,12 +106,6 @@ describe('tabsFor', () => {
|
|||||||
'verification',
|
'verification',
|
||||||
])
|
])
|
||||||
expect(tabsFor('small').shown).toEqual(['annotations', 'verification'])
|
expect(tabsFor('small').shown).toEqual(['annotations', 'verification'])
|
||||||
expect(tabsFor('small').more).toEqual([
|
expect(tabsFor('small').more).toEqual(['general', 'findings'])
|
||||||
'general',
|
|
||||||
'views',
|
|
||||||
'findings',
|
|
||||||
'references',
|
|
||||||
'vertebrae',
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -13,7 +13,7 @@ import type {
|
|||||||
Annotation,
|
Annotation,
|
||||||
Geometry,
|
Geometry,
|
||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
import ViewsTab from '@/components/editor/tabs/ViewsTab'
|
import ViewsSection from '@/components/editor/annotations/sections/ViewsSection'
|
||||||
import { cleanSvg } from '@/editor/core/cleaning'
|
import { cleanSvg } from '@/editor/core/cleaning'
|
||||||
import { attachToView } from '@/editor/drawingUpload'
|
import { attachToView } from '@/editor/drawingUpload'
|
||||||
import { applyRepair, proposeGeometry } from '@/editor/repair'
|
import { applyRepair, proposeGeometry } from '@/editor/repair'
|
||||||
@@ -36,7 +36,7 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
|||||||
confirmSheetAssetUpload: vi.fn(),
|
confirmSheetAssetUpload: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const props = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
|
const props = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
||||||
const NEW_ASSET = '22222222-2222-4222-8222-222222222222'
|
const NEW_ASSET = '22222222-2222-4222-8222-222222222222'
|
||||||
const t = (key: string) => getDict('fr')[key as never] as string
|
const t = (key: string) => getDict('fr')[key as never] as string
|
||||||
const doc = (): AnatomicalSheetDocument =>
|
const doc = (): AnatomicalSheetDocument =>
|
||||||
@@ -297,7 +297,7 @@ const COMPLEX_PATH =
|
|||||||
async function pickAndOpenDialog(text = unmeasuredText()) {
|
async function pickAndOpenDialog(text = unmeasuredText()) {
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
serverGets(SVG)
|
serverGets(SVG)
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
const input = screen.getByTestId('view-view-main-file') as HTMLInputElement
|
const input = screen.getByTestId('view-view-main-file') as HTMLInputElement
|
||||||
await user.upload(input, new File([SVG], 'd.svg', { type: 'image/svg+xml' }))
|
await user.upload(input, new File([SVG], 'd.svg', { type: 'image/svg+xml' }))
|
||||||
|
|||||||
@@ -90,10 +90,10 @@ describe('the blocking offer', () => {
|
|||||||
).toBeEnabled()
|
).toBeEnabled()
|
||||||
expect(useLeaveGuardStore.getState().armed).toBe(true)
|
expect(useLeaveGuardStore.getState().armed).toBe(true)
|
||||||
// consultation: tabs still switch
|
// consultation: tabs still switch
|
||||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
await user.click(screen.getByRole('button', { name: 'Références' }))
|
||||||
expect(screen.getByTestId('editor-tab-references')).toHaveAttribute(
|
expect(screen.getByTestId('editor-references-panel')).toHaveAttribute(
|
||||||
'aria-label',
|
'aria-labelledby',
|
||||||
'Références',
|
'editor-references-title',
|
||||||
)
|
)
|
||||||
// editing: refused by the store, no save offered
|
// editing: refused by the store, no save offered
|
||||||
expect(commitMove(40)).toMatchObject({
|
expect(commitMove(40)).toMatchObject({
|
||||||
|
|||||||
@@ -43,18 +43,10 @@ afterEach(() => {
|
|||||||
|
|
||||||
const ready = () =>
|
const ready = () =>
|
||||||
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||||
const TABS = [
|
const TABS = ['Général', 'Annotations', 'Constats', 'Vérification']
|
||||||
'Général',
|
|
||||||
'Vues et illustrations',
|
|
||||||
'Annotations',
|
|
||||||
'Constats',
|
|
||||||
'Références',
|
|
||||||
'Vertèbres',
|
|
||||||
'Vérification',
|
|
||||||
]
|
|
||||||
|
|
||||||
describe('edit mode', () => {
|
describe('edit mode', () => {
|
||||||
it('header, badges, the seven tabs, nothing read-only', async () => {
|
it('header, badges, the four tabs, nothing read-only', async () => {
|
||||||
mountDraft()
|
mountDraft()
|
||||||
await ready()
|
await ready()
|
||||||
expect(screen.getByText('Brouillon')).toBeInTheDocument()
|
expect(screen.getByText('Brouillon')).toBeInTheDocument()
|
||||||
@@ -136,8 +128,7 @@ describe('tabs', () => {
|
|||||||
expect(screen.getByRole('tabpanel')).toHaveAccessibleName('Constats')
|
expect(screen.getByRole('tabpanel')).toHaveAccessibleName('Constats')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('640 to 1 023 px: four tabs and « Plus »; the others sit under the disclosure', async () => {
|
it('640 to 1 023 px: the four tabs, no « Plus »', async () => {
|
||||||
const user = userEvent.setup()
|
|
||||||
mountDraft({ width: 800 })
|
mountDraft({ width: 800 })
|
||||||
await ready()
|
await ready()
|
||||||
const shown = within(screen.getByRole('tablist')).getAllByRole('tab')
|
const shown = within(screen.getByRole('tablist')).getAllByRole('tab')
|
||||||
@@ -147,17 +138,10 @@ describe('tabs', () => {
|
|||||||
'Constats',
|
'Constats',
|
||||||
'Vérification',
|
'Vérification',
|
||||||
])
|
])
|
||||||
const more = screen.getByRole('button', { name: 'Plus' })
|
expect(screen.queryByRole('button', { name: 'Plus' })).toBeNull()
|
||||||
expect(more).toHaveAttribute('aria-expanded', 'false')
|
|
||||||
expect(screen.queryByRole('button', { name: 'Références' })).toBeNull()
|
|
||||||
await user.click(more)
|
|
||||||
expect(more).toHaveAttribute('aria-expanded', 'true')
|
|
||||||
await user.click(screen.getByRole('button', { name: 'Références' }))
|
|
||||||
expect(screen.getByTestId('editor-tab-references')).toBeInTheDocument()
|
|
||||||
expect(more).toHaveAttribute('aria-expanded', 'false')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('below 640 px: two tabs and « Plus » listing the five others', async () => {
|
it('below 640 px: two tabs and « Plus » listing Général and Constats', async () => {
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
mountDraft({ width: 375 })
|
mountDraft({ width: 375 })
|
||||||
await ready()
|
await ready()
|
||||||
@@ -169,13 +153,63 @@ describe('tabs', () => {
|
|||||||
await user.click(screen.getByRole('button', { name: 'Plus' }))
|
await user.click(screen.getByRole('button', { name: 'Plus' }))
|
||||||
const more = document.getElementById('editor-tabs-more') as HTMLElement
|
const more = document.getElementById('editor-tabs-more') as HTMLElement
|
||||||
const rest = within(more).getAllByRole('button')
|
const rest = within(more).getAllByRole('button')
|
||||||
expect(rest.map((b) => b.textContent)).toEqual([
|
expect(rest.map((b) => b.textContent)).toEqual(['Général', 'Constats'])
|
||||||
'Général',
|
await user.click(rest[1])
|
||||||
'Vues et illustrations',
|
expect(screen.getByTestId('editor-tab-findings')).toBeInTheDocument()
|
||||||
'Constats',
|
expect(document.getElementById('editor-tabs-more')).toBeNull()
|
||||||
'Références',
|
})
|
||||||
'Vertèbres',
|
})
|
||||||
])
|
|
||||||
|
describe('references panel', () => {
|
||||||
|
const button = () => screen.getByRole('button', { name: 'Références' })
|
||||||
|
|
||||||
|
it('the header button opens it on its heading and ✕ returns the focus', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
mountDraft()
|
||||||
|
await ready()
|
||||||
|
expect(button()).toHaveAttribute('aria-expanded', 'false')
|
||||||
|
expect(screen.queryByTestId('editor-references-panel')).toBeNull()
|
||||||
|
await user.click(button())
|
||||||
|
const panel = screen.getByTestId('editor-references-panel')
|
||||||
|
expect(panel).toBeVisible()
|
||||||
|
expect(button()).toHaveAttribute('aria-expanded', 'true')
|
||||||
|
expect(document.activeElement).toBe(
|
||||||
|
within(panel).getByRole('heading', { name: 'Références' }),
|
||||||
|
)
|
||||||
|
expect(screen.getByRole('tab', { name: 'Annotations' })).toHaveAttribute(
|
||||||
|
'aria-selected',
|
||||||
|
'true',
|
||||||
|
)
|
||||||
|
await user.click(
|
||||||
|
within(panel).getByRole('button', { name: 'Fermer les références' }),
|
||||||
|
)
|
||||||
|
expect(panel).not.toBeVisible()
|
||||||
|
expect(document.activeElement).toBe(button())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Escape inside the panel closes it, the content is kept for the next opening', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
mountDraft()
|
||||||
|
await ready()
|
||||||
|
await user.click(button())
|
||||||
|
const panel = screen.getByTestId('editor-references-panel')
|
||||||
|
await user.keyboard('{Escape}')
|
||||||
|
expect(panel).not.toBeVisible()
|
||||||
|
await user.click(button())
|
||||||
|
expect(screen.getByTestId('editor-references-panel')).toBe(panel)
|
||||||
|
expect(panel).toBeVisible()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('read-only: the panel lists the references with no edit control', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
mountDraft({ width: 800 })
|
||||||
|
await ready()
|
||||||
|
await user.click(button())
|
||||||
|
const panel = screen.getByTestId('editor-references-panel')
|
||||||
|
expect(within(panel).queryByRole('textbox')).toBeNull()
|
||||||
|
expect(
|
||||||
|
within(panel).queryByRole('button', { name: 'Ajouter la référence' }),
|
||||||
|
).toBeNull()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,277 @@
|
|||||||
|
/** U1 Lot B1: the Annotations sections, their entries, the view fallback, « Aller à » kept. */
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import {
|
||||||
|
act,
|
||||||
|
cleanup,
|
||||||
|
fireEvent,
|
||||||
|
render,
|
||||||
|
screen,
|
||||||
|
waitFor,
|
||||||
|
within,
|
||||||
|
} from '@testing-library/react'
|
||||||
|
import userEvent from '@testing-library/user-event'
|
||||||
|
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||||
|
import {
|
||||||
|
AnnounceContext,
|
||||||
|
FocusConsumedContext,
|
||||||
|
type FocusRequest,
|
||||||
|
} from '@/editor/focusRequest'
|
||||||
|
import { targetOfKey } from '@/editor/navigation'
|
||||||
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
||||||
|
import {
|
||||||
|
baseText,
|
||||||
|
openReady,
|
||||||
|
resetStore,
|
||||||
|
serverHas,
|
||||||
|
store,
|
||||||
|
} from '../helpers/editorHarness'
|
||||||
|
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||||
|
|
||||||
|
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(),
|
||||||
|
}))
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
useLocaleStore.setState({ locale: 'fr' })
|
||||||
|
const identity = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }
|
||||||
|
Object.defineProperty(window.SVGElement.prototype, 'getScreenCTM', {
|
||||||
|
configurable: true,
|
||||||
|
value: () => ({ ...identity, inverse: () => identity }),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup()
|
||||||
|
resetStore()
|
||||||
|
setWidth(1024)
|
||||||
|
})
|
||||||
|
|
||||||
|
const ready = () =>
|
||||||
|
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||||
|
const entry = (name: string | RegExp) => screen.getByRole('button', { name })
|
||||||
|
const place = (name: string) =>
|
||||||
|
document.querySelector<HTMLElement>(`[data-place="${name}"]`)
|
||||||
|
|
||||||
|
describe('the overview entries', () => {
|
||||||
|
beforeEach(() => serverHas(baseText(), 3))
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['Gérer les vues', 'views', 'Vues'],
|
||||||
|
['Modifier les catégories', 'categories', 'Catégories'],
|
||||||
|
[/^Régions vertébrales/, 'regions', 'Régions vertébrales'],
|
||||||
|
] as const)(
|
||||||
|
'%s opens its section on the heading; « Retour au dessin » refocuses the entry',
|
||||||
|
async (label, section, title) => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
mountDraft()
|
||||||
|
await ready()
|
||||||
|
await user.click(entry(label))
|
||||||
|
const shown = place(`annotations.${section}`)!
|
||||||
|
expect(shown).toBeVisible()
|
||||||
|
expect(document.activeElement).toBe(
|
||||||
|
within(shown).getByRole('heading', { level: 2, name: title }),
|
||||||
|
)
|
||||||
|
expect(screen.getByRole('tab', { name: 'Annotations' })).toHaveAttribute(
|
||||||
|
'aria-selected',
|
||||||
|
'true',
|
||||||
|
)
|
||||||
|
expect(place('annotations.drawing')).toBeNull()
|
||||||
|
await user.click(screen.getByRole('button', { name: 'Retour au dessin' }))
|
||||||
|
expect(place('annotations.drawing')).toBeVisible()
|
||||||
|
expect(document.activeElement).toHaveAttribute(
|
||||||
|
'data-section-entry',
|
||||||
|
section,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
it('the regions entry is there with no role code, counting the regions', async () => {
|
||||||
|
mountDraft()
|
||||||
|
await ready()
|
||||||
|
expect(entry('Régions vertébrales (0 région)')).toBeVisible()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('announces the section reached, politely', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
mountDraft()
|
||||||
|
await ready()
|
||||||
|
await user.click(entry('Gérer les vues'))
|
||||||
|
const live = document.querySelector('p[aria-live="polite"]')!
|
||||||
|
expect(live).toHaveTextContent('Annotations · Vues')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('read-only: the entries read « Voir … » and still open the sections', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
mountDraft({ width: 800 })
|
||||||
|
await ready()
|
||||||
|
expect(screen.queryByRole('button', { name: 'Gérer les vues' })).toBeNull()
|
||||||
|
await user.click(entry('Voir les catégories'))
|
||||||
|
expect(place('annotations.categories')).toBeVisible()
|
||||||
|
expect(
|
||||||
|
within(place('annotations.categories')!).queryByRole('textbox'),
|
||||||
|
).toBeNull()
|
||||||
|
await user.click(screen.getByRole('button', { name: 'Retour au dessin' }))
|
||||||
|
await user.click(entry('Voir les vues'))
|
||||||
|
expect(place('annotations.views')).toBeVisible()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const props = {
|
||||||
|
readOnly: false,
|
||||||
|
navigate: vi.fn(),
|
||||||
|
reloadSheet: vi.fn(),
|
||||||
|
section: 'drawing' as const,
|
||||||
|
onOpenSection: vi.fn(),
|
||||||
|
onBack: vi.fn(),
|
||||||
|
}
|
||||||
|
|
||||||
|
const detailView = {
|
||||||
|
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: 20, width: 40, height: 60 },
|
||||||
|
parent_view_id: 'view-main',
|
||||||
|
},
|
||||||
|
} as const
|
||||||
|
|
||||||
|
const consumed = vi.fn()
|
||||||
|
const announce = vi.fn()
|
||||||
|
const Drawing = ({ focus }: { focus?: FocusRequest }) => (
|
||||||
|
<FocusConsumedContext value={consumed}>
|
||||||
|
<AnnounceContext value={announce}>
|
||||||
|
<AnnotationsTab {...props} focus={focus} />
|
||||||
|
</AnnounceContext>
|
||||||
|
</FocusConsumedContext>
|
||||||
|
)
|
||||||
|
|
||||||
|
async function mountDrawing(text = drawnText()) {
|
||||||
|
consumed.mockReset()
|
||||||
|
announce.mockReset()
|
||||||
|
await openReady({ text })
|
||||||
|
const user = userEvent.setup()
|
||||||
|
const view = render(<Drawing />)
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(
|
||||||
|
screen.getByTestId('annotation-canvas-drawing').querySelector('svg'),
|
||||||
|
).not.toBeNull(),
|
||||||
|
)
|
||||||
|
return { user, view }
|
||||||
|
}
|
||||||
|
|
||||||
|
const addPoint = async (user: ReturnType<typeof userEvent.setup>) => {
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(
|
||||||
|
screen.getByRole('button', { name: 'Ajouter un point' }),
|
||||||
|
).toBeEnabled(),
|
||||||
|
)
|
||||||
|
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('the shown view disappears (undo)', () => {
|
||||||
|
async function onDetailView() {
|
||||||
|
const base = await mountDrawing()
|
||||||
|
act(
|
||||||
|
() => void store.getState().commit({ op: 'insert', element: detailView }),
|
||||||
|
)
|
||||||
|
await base.user.click(await screen.findByRole('button', { name: 'Tête' }))
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
|
||||||
|
it('a pending point on it: back to the main view, the creation cleared', async () => {
|
||||||
|
const { user } = await onDetailView()
|
||||||
|
await addPoint(user)
|
||||||
|
expect(await screen.findByTestId('annotation-creation')).toBeInTheDocument()
|
||||||
|
act(() => void store.getState().undoStep())
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(screen.queryByTestId('annotation-creation')).toBeNull(),
|
||||||
|
)
|
||||||
|
expect(screen.queryByRole('button', { name: 'Tête' })).toBeNull()
|
||||||
|
expect(screen.getByTestId('annotation-overview')).toBeInTheDocument()
|
||||||
|
expect(store.getState().previewState!.document.annotations).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a tracing on it: the tracing is cleared too', async () => {
|
||||||
|
const { user } = await onDetailView()
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(screen.getByRole('button', { name: 'Zone' })).toBeEnabled(),
|
||||||
|
)
|
||||||
|
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||||
|
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||||
|
clientX: 20,
|
||||||
|
clientY: 30,
|
||||||
|
})
|
||||||
|
expect(screen.getByTestId('tracing-bar')).toBeInTheDocument()
|
||||||
|
act(() => void store.getState().undoStep())
|
||||||
|
await waitFor(() => expect(screen.queryByTestId('tracing-bar')).toBeNull())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('dispatches nothing while the shown view still exists', async () => {
|
||||||
|
const { user } = await onDetailView()
|
||||||
|
await addPoint(user)
|
||||||
|
const panel = await screen.findByTestId('annotation-creation')
|
||||||
|
const element = point('anno-x', 30, 40, 2, 'view-det')
|
||||||
|
act(() => void store.getState().commit({ op: 'insert', element }))
|
||||||
|
expect(screen.getByTestId('annotation-creation')).toBe(panel)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('« Aller à » an annotation while something is in progress', () => {
|
||||||
|
const key = { kind: 'annotation', id: 'anno-a' } as const
|
||||||
|
const request = { target: targetOfKey(key), serial: 7 }
|
||||||
|
|
||||||
|
async function withProgress(
|
||||||
|
start: (user: ReturnType<typeof userEvent.setup>) => Promise<void>,
|
||||||
|
) {
|
||||||
|
const text = insert(drawnText(), point('anno-a', 50, 50, 5))
|
||||||
|
const { user, view } = await mountDrawing(text)
|
||||||
|
await start(user)
|
||||||
|
view.rerender(<Drawing focus={request} />)
|
||||||
|
return { consumed, announce }
|
||||||
|
}
|
||||||
|
|
||||||
|
it('a pending creation is kept: its panel takes the focus, the live region says why', async () => {
|
||||||
|
const { consumed, announce } = await withProgress(addPoint)
|
||||||
|
await waitFor(() => expect(consumed).toHaveBeenCalledWith(7, 'kept'))
|
||||||
|
expect(screen.getByTestId('annotation-creation')).toBeInTheDocument()
|
||||||
|
expect(document.activeElement).toHaveAttribute('data-creation-heading')
|
||||||
|
expect(announce).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining('création est en cours'),
|
||||||
|
)
|
||||||
|
expect(screen.queryByTestId('annotation-properties')).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('an open zone tracing is kept: the bar takes the focus', async () => {
|
||||||
|
const { consumed, announce } = await withProgress(async (user) => {
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(screen.getByRole('button', { name: 'Zone' })).toBeEnabled(),
|
||||||
|
)
|
||||||
|
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||||
|
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||||
|
clientX: 20,
|
||||||
|
clientY: 20,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
await waitFor(() => expect(consumed).toHaveBeenCalledWith(7, 'kept'))
|
||||||
|
expect(document.activeElement).toBe(screen.getByTestId('tracing-bar'))
|
||||||
|
expect(announce).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining('tracé est en cours'),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('with nothing in progress the annotation is selected and its heading focused', async () => {
|
||||||
|
const { consumed } = await withProgress(async () => undefined)
|
||||||
|
await waitFor(() => expect(consumed).toHaveBeenCalledWith(7, 'found'))
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(document.activeElement).toHaveAttribute('data-properties-heading'),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -4,6 +4,7 @@ import { cleanup, render, screen, within } from '@testing-library/react'
|
|||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||||
import DeleteDialog from '@/components/editor/DeleteDialog'
|
import DeleteDialog from '@/components/editor/DeleteDialog'
|
||||||
|
import CategoriesSection from '@/components/editor/general/CategoriesSection'
|
||||||
import GeneralTab from '@/components/editor/tabs/GeneralTab'
|
import GeneralTab from '@/components/editor/tabs/GeneralTab'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import { edit, insert } from '../helpers/editorFixtures'
|
import { edit, insert } from '../helpers/editorFixtures'
|
||||||
@@ -24,7 +25,7 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
|||||||
submitSheetReview: vi.fn(),
|
submitSheetReview: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const props = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
|
const props = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
||||||
const doc = (): AnatomicalSheetDocument =>
|
const doc = (): AnatomicalSheetDocument =>
|
||||||
JSON.parse(store.getState().documentText)
|
JSON.parse(store.getState().documentText)
|
||||||
|
|
||||||
@@ -102,11 +103,17 @@ describe('Général: texts and attribution', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Général: annotation categories', () => {
|
describe('Annotations, section Catégories', () => {
|
||||||
|
it('Général no longer holds the categories editor', async () => {
|
||||||
|
await openReady()
|
||||||
|
render(<GeneralTab {...props} />)
|
||||||
|
expect(screen.queryByText("Catégories d'annotation")).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
it('renames, recolours and adds a category', async () => {
|
it('renames, recolours and adds a category', async () => {
|
||||||
await openReady()
|
await openReady()
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<GeneralTab {...props} />)
|
render(<CategoriesSection doc={doc()} readOnly={false} />)
|
||||||
const row = screen.getByLabelText('Nom de la catégorie (FR)', {
|
const row = screen.getByLabelText('Nom de la catégorie (FR)', {
|
||||||
selector: '#category-cat-a-name-fr',
|
selector: '#category-cat-a-name-fr',
|
||||||
})
|
})
|
||||||
@@ -140,7 +147,7 @@ describe('Général: annotation categories', () => {
|
|||||||
it('a new category needs both names', async () => {
|
it('a new category needs both names', async () => {
|
||||||
await openReady()
|
await openReady()
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<GeneralTab {...props} />)
|
render(<CategoriesSection doc={doc()} readOnly={false} />)
|
||||||
await user.click(
|
await user.click(
|
||||||
screen.getByRole('button', { name: 'Ajouter la catégorie' }),
|
screen.getByRole('button', { name: 'Ajouter la catégorie' }),
|
||||||
)
|
)
|
||||||
@@ -151,7 +158,7 @@ describe('Général: annotation categories', () => {
|
|||||||
it('a used category cannot be deleted: the dialog lists the dependents', async () => {
|
it('a used category cannot be deleted: the dialog lists the dependents', async () => {
|
||||||
await openReady()
|
await openReady()
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<GeneralTab {...props} />)
|
render(<CategoriesSection doc={doc()} readOnly={false} />)
|
||||||
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
||||||
const dialog = await screen.findByRole('dialog')
|
const dialog = await screen.findByRole('dialog')
|
||||||
expect(within(dialog).getByText(/utilise cette catégorie/)).toBeTruthy()
|
expect(within(dialog).getByText(/utilise cette catégorie/)).toBeTruthy()
|
||||||
@@ -171,7 +178,7 @@ describe('Général: annotation categories', () => {
|
|||||||
})
|
})
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<GeneralTab {...props} />)
|
render(<CategoriesSection doc={doc()} readOnly={false} />)
|
||||||
const buttons = screen.getAllByRole('button', { name: 'Supprimer' })
|
const buttons = screen.getAllByRole('button', { name: 'Supprimer' })
|
||||||
await user.click(buttons[1])
|
await user.click(buttons[1])
|
||||||
const dialog = await screen.findByRole('dialog')
|
const dialog = await screen.findByRole('dialog')
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|||||||
import { cleanup, render, screen, within } from '@testing-library/react'
|
import { cleanup, render, screen, within } from '@testing-library/react'
|
||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
import ReferencesPanel from '@/components/editor/references/ReferencesPanel'
|
||||||
import VertebraeTab from '@/components/editor/tabs/VertebraeTab'
|
import RegionsSection from '@/components/editor/annotations/sections/RegionsSection'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import { edit, insert, point } from '../helpers/editorFixtures'
|
import { edit, insert, point } from '../helpers/editorFixtures'
|
||||||
import {
|
import {
|
||||||
@@ -24,7 +24,7 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
|||||||
submitSheetReview: vi.fn(),
|
submitSheetReview: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const props = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
|
const props = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
||||||
const doc = (): AnatomicalSheetDocument =>
|
const doc = (): AnatomicalSheetDocument =>
|
||||||
JSON.parse(store.getState().documentText)
|
JSON.parse(store.getState().documentText)
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ describe('Références', () => {
|
|||||||
it('adds a reference only with a type and a citation', async () => {
|
it('adds a reference only with a type and a citation', async () => {
|
||||||
await openReady()
|
await openReady()
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<ReferencesTab {...props} />)
|
render(<ReferencesPanel {...props} open onClose={vi.fn()} />)
|
||||||
await user.click(
|
await user.click(
|
||||||
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
||||||
)
|
)
|
||||||
@@ -72,7 +72,7 @@ describe('Références', () => {
|
|||||||
)
|
)
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<ReferencesTab {...props} />)
|
render(<ReferencesPanel {...props} open onClose={vi.fn()} />)
|
||||||
const url = screen.getByLabelText('Adresse web (URL)', {
|
const url = screen.getByLabelText('Adresse web (URL)', {
|
||||||
selector: '#reference-ref-a-url',
|
selector: '#reference-ref-a-url',
|
||||||
})
|
})
|
||||||
@@ -111,7 +111,7 @@ describe('Références', () => {
|
|||||||
})
|
})
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<ReferencesTab {...props} />)
|
render(<ReferencesPanel {...props} open onClose={vi.fn()} />)
|
||||||
await user.click(screen.getAllByRole('button', { name: 'Supprimer' })[0])
|
await user.click(screen.getAllByRole('button', { name: 'Supprimer' })[0])
|
||||||
const refused = await screen.findByRole('dialog')
|
const refused = await screen.findByRole('dialog')
|
||||||
expect(within(refused).getByText(/cite cette référence/)).toBeTruthy()
|
expect(within(refused).getByText(/cite cette référence/)).toBeTruthy()
|
||||||
@@ -127,10 +127,12 @@ describe('Références', () => {
|
|||||||
|
|
||||||
it('read-only shows the citations as text', async () => {
|
it('read-only shows the citations as text', async () => {
|
||||||
await openReady({ text: insert(baseText(), reference('ref-a', 'Alpha')) })
|
await openReady({ text: insert(baseText(), reference('ref-a', 'Alpha')) })
|
||||||
render(<ReferencesTab {...props} readOnly />)
|
render(<ReferencesPanel {...props} open onClose={vi.fn()} readOnly />)
|
||||||
expect(screen.getByText('Alpha')).toBeTruthy()
|
expect(screen.getByText('Alpha')).toBeTruthy()
|
||||||
expect(screen.queryByRole('textbox')).toBeNull()
|
expect(screen.queryByRole('textbox')).toBeNull()
|
||||||
expect(screen.queryByRole('button')).toBeNull()
|
expect(
|
||||||
|
screen.getAllByRole('button').map((b) => b.getAttribute('aria-label')),
|
||||||
|
).toEqual(['Fermer les références'])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -149,7 +151,7 @@ describe('Vertèbres', () => {
|
|||||||
it('adds a region with a typed code; a bad count or half range never reaches the core', async () => {
|
it('adds a region with a typed code; a bad count or half range never reaches the core', async () => {
|
||||||
await openReady()
|
await openReady()
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<VertebraeTab {...props} />)
|
render(<RegionsSection {...props} />)
|
||||||
await user.type(screen.getByLabelText('Code'), 'C')
|
await user.type(screen.getByLabelText('Code'), 'C')
|
||||||
await user.type(screen.getByLabelText('Nom (FR)'), 'Cervicales')
|
await user.type(screen.getByLabelText('Nom (FR)'), 'Cervicales')
|
||||||
await user.type(screen.getByLabelText('Nom (EN)'), 'Cervical')
|
await user.type(screen.getByLabelText('Nom (EN)'), 'Cervical')
|
||||||
@@ -178,7 +180,7 @@ describe('Vertèbres', () => {
|
|||||||
const text = insert(insert(baseText(), region('C', 7)), region('T', 18))
|
const text = insert(insert(baseText(), region('C', 7)), region('T', 18))
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<VertebraeTab {...props} />)
|
render(<RegionsSection {...props} />)
|
||||||
const count = screen.getByLabelText('Nombre de vertèbres', {
|
const count = screen.getByLabelText('Nombre de vertèbres', {
|
||||||
selector: '#region-T-count',
|
selector: '#region-T-count',
|
||||||
})
|
})
|
||||||
@@ -238,7 +240,7 @@ describe('Vertèbres', () => {
|
|||||||
})
|
})
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<VertebraeTab {...props} />)
|
render(<RegionsSection {...props} />)
|
||||||
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
||||||
const dialog = await screen.findByRole('dialog')
|
const dialog = await screen.findByRole('dialog')
|
||||||
expect(
|
expect(
|
||||||
@@ -249,7 +251,7 @@ describe('Vertèbres', () => {
|
|||||||
|
|
||||||
it('read-only has no control', async () => {
|
it('read-only has no control', async () => {
|
||||||
await openReady({ text: insert(baseText(), region('C', 7)) })
|
await openReady({ text: insert(baseText(), region('C', 7)) })
|
||||||
render(<VertebraeTab {...props} readOnly />)
|
render(<RegionsSection {...props} readOnly />)
|
||||||
expect(screen.queryByRole('textbox')).toBeNull()
|
expect(screen.queryByRole('textbox')).toBeNull()
|
||||||
expect(screen.queryByRole('button')).toBeNull()
|
expect(screen.queryByRole('button')).toBeNull()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type {
|
|||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
NewElement,
|
NewElement,
|
||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
import ViewsTab from '@/components/editor/tabs/ViewsTab'
|
import ViewsSection from '@/components/editor/annotations/sections/ViewsSection'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import { ASSET, emptyText, insert, point } from '../helpers/editorFixtures'
|
import { ASSET, emptyText, insert, point } from '../helpers/editorFixtures'
|
||||||
import {
|
import {
|
||||||
@@ -29,7 +29,7 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
|||||||
submitSheetReview: vi.fn(),
|
submitSheetReview: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const props = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
|
const props = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
||||||
const doc = (): AnatomicalSheetDocument =>
|
const doc = (): AnatomicalSheetDocument =>
|
||||||
JSON.parse(store.getState().documentText)
|
JSON.parse(store.getState().documentText)
|
||||||
const detail = (
|
const detail = (
|
||||||
@@ -56,7 +56,7 @@ afterEach(() => {
|
|||||||
async function openCrop(text: string) {
|
async function openCrop(text: string) {
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
await user.click(
|
await user.click(
|
||||||
screen.getByRole('button', { name: 'Modifier le recadrage' }),
|
screen.getByRole('button', { name: 'Modifier le recadrage' }),
|
||||||
)
|
)
|
||||||
@@ -77,7 +77,7 @@ const cropField = (name: string) =>
|
|||||||
describe('Vues et illustrations: drawing states', () => {
|
describe('Vues et illustrations: drawing states', () => {
|
||||||
it('a valid main drawing shows its state and no hint', async () => {
|
it('a valid main drawing shows its state and no hint', async () => {
|
||||||
await openReady()
|
await openReady()
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
expect(screen.getByText('Illustration valide')).toBeTruthy()
|
expect(screen.getByText('Illustration valide')).toBeTruthy()
|
||||||
expect(
|
expect(
|
||||||
screen.queryByText(/Utilisez « Choisir une illustration »/),
|
screen.queryByText(/Utilisez « Choisir une illustration »/),
|
||||||
@@ -86,7 +86,7 @@ describe('Vues et illustrations: drawing states', () => {
|
|||||||
|
|
||||||
it('a main view without drawing shows the hint pointing at the button', async () => {
|
it('a main view without drawing shows the hint pointing at the button', async () => {
|
||||||
await openReady({ text: emptyText() })
|
await openReady({ text: emptyText() })
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
expect(screen.getByText('Aucune illustration')).toBeTruthy()
|
expect(screen.getByText('Aucune illustration')).toBeTruthy()
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(/Utilisez « Choisir une illustration »/),
|
screen.getByText(/Utilisez « Choisir une illustration »/),
|
||||||
@@ -104,7 +104,7 @@ describe('Vues et illustrations: drawing states', () => {
|
|||||||
)
|
)
|
||||||
store.getState().open('ver-1', 'user-1', { canEdit: true })
|
store.getState().open('ver-1', 'user-1', { canEdit: true })
|
||||||
await vi.waitFor(() => expect(store.getState().status).toBe('ready'))
|
await vi.waitFor(() => expect(store.getState().status).toBe('ready'))
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
expect(screen.getByText(/Illustration introuvable/)).toBeTruthy()
|
expect(screen.getByText(/Illustration introuvable/)).toBeTruthy()
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(/Utilisez « Choisir une illustration »/),
|
screen.getByText(/Utilisez « Choisir une illustration »/),
|
||||||
@@ -124,7 +124,7 @@ describe('Vues et illustrations: drawing states', () => {
|
|||||||
sb.downloadSheetDrawing.mockResolvedValue(bytes)
|
sb.downloadSheetDrawing.mockResolvedValue(bytes)
|
||||||
store.getState().open('ver-1', 'user-1', { canEdit: true })
|
store.getState().open('ver-1', 'user-1', { canEdit: true })
|
||||||
await vi.waitFor(() => expect(store.getState().status).toBe('ready'))
|
await vi.waitFor(() => expect(store.getState().status).toBe('ready'))
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(
|
screen.getByText(
|
||||||
/Illustration refusée : elle n'est pas sous la forme enregistrée/,
|
/Illustration refusée : elle n'est pas sous la forme enregistrée/,
|
||||||
@@ -143,7 +143,7 @@ describe('Vues et illustrations: drawing states', () => {
|
|||||||
)
|
)
|
||||||
store.getState().open('ver-1', 'user-1', { canEdit: true })
|
store.getState().open('ver-1', 'user-1', { canEdit: true })
|
||||||
await vi.waitFor(() => expect(store.getState().status).toBe('ready'))
|
await vi.waitFor(() => expect(store.getState().status).toBe('ready'))
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(/ne correspond pas à son empreinte SHA-256 enregistrée/),
|
screen.getByText(/ne correspond pas à son empreinte SHA-256 enregistrée/),
|
||||||
).toBeTruthy()
|
).toBeTruthy()
|
||||||
@@ -155,7 +155,7 @@ describe('Vues et illustrations: drawing states', () => {
|
|||||||
;(own.value as { svg_asset_id: string | null }).svg_asset_id = ASSET
|
;(own.value as { svg_asset_id: string | null }).svg_asset_id = ASSET
|
||||||
await openReady({ text: insert(baseText(), own) })
|
await openReady({ text: insert(baseText(), own) })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
const open = () =>
|
const open = () =>
|
||||||
user.click(
|
user.click(
|
||||||
screen.getByRole('button', {
|
screen.getByRole('button', {
|
||||||
@@ -182,7 +182,7 @@ describe('Vues et illustrations: drawing states', () => {
|
|||||||
|
|
||||||
it('read-only shows states as text and no action', async () => {
|
it('read-only shows states as text and no action', async () => {
|
||||||
await openReady({ text: insert(baseText(), detail()) })
|
await openReady({ text: insert(baseText(), detail()) })
|
||||||
render(<ViewsTab {...props} readOnly />)
|
render(<ViewsSection {...props} readOnly />)
|
||||||
expect(screen.getByText('Illustration valide')).toBeTruthy()
|
expect(screen.getByText('Illustration valide')).toBeTruthy()
|
||||||
expect(screen.queryByRole('button')).toBeNull()
|
expect(screen.queryByRole('button')).toBeNull()
|
||||||
expect(screen.queryByRole('textbox')).toBeNull()
|
expect(screen.queryByRole('textbox')).toBeNull()
|
||||||
@@ -193,7 +193,7 @@ describe('Vues et illustrations: detail views', () => {
|
|||||||
it('adds a detail view with names and a crop, in one insert', async () => {
|
it('adds a detail view with names and a crop, in one insert', async () => {
|
||||||
await openReady()
|
await openReady()
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
await user.click(screen.getByRole('button', { name: 'Ajouter la vue' }))
|
await user.click(screen.getByRole('button', { name: 'Ajouter la vue' }))
|
||||||
expect(screen.getByRole('alert')).toHaveTextContent('Renseignez les noms')
|
expect(screen.getByRole('alert')).toHaveTextContent('Renseignez les noms')
|
||||||
await user.type(document.getElementById('view-new-fr')!, 'Tête')
|
await user.type(document.getElementById('view-new-fr')!, 'Tête')
|
||||||
@@ -224,7 +224,7 @@ describe('Vues et illustrations: detail views', () => {
|
|||||||
it('renames on blur and refuses a blank name locally', async () => {
|
it('renames on blur and refuses a blank name locally', async () => {
|
||||||
await openReady({ text: insert(baseText(), detail()) })
|
await openReady({ text: insert(baseText(), detail()) })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
const name = document.getElementById('view-view-d-name-en')!
|
const name = document.getElementById('view-view-d-name-en')!
|
||||||
await user.clear(name)
|
await user.clear(name)
|
||||||
await user.type(name, 'Lower leg')
|
await user.type(name, 'Lower leg')
|
||||||
@@ -243,7 +243,7 @@ describe('Vues et illustrations: detail views', () => {
|
|||||||
)
|
)
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
||||||
const dialog = await screen.findByRole('dialog')
|
const dialog = await screen.findByRole('dialog')
|
||||||
expect(within(dialog).getByText(/ne peut pas être supprimé/)).toBeTruthy()
|
expect(within(dialog).getByText(/ne peut pas être supprimé/)).toBeTruthy()
|
||||||
@@ -359,7 +359,7 @@ describe('Vues et illustrations: crop group under the frame check', () => {
|
|||||||
const text = insert(insert(baseText(), detail()), detail2())
|
const text = insert(insert(baseText(), detail()), detail2())
|
||||||
await openReady({ text })
|
await openReady({ text })
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
render(<ViewsTab {...props} />)
|
render(<ViewsSection {...props} />)
|
||||||
await user.selectOptions(
|
await user.selectOptions(
|
||||||
document.getElementById('view-view-d-parent')!,
|
document.getElementById('view-view-d-parent')!,
|
||||||
'view-e',
|
'view-e',
|
||||||
|
|||||||
@@ -4,7 +4,12 @@ import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
|
|||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
import { SheetFailure } from '@faunosteo/supabase'
|
import { SheetFailure } from '@faunosteo/supabase'
|
||||||
import VerificationTab from '@/components/editor/tabs/VerificationTab'
|
import VerificationTab from '@/components/editor/tabs/VerificationTab'
|
||||||
import { ISSUE_CODES, issueMessageKey } from '@/editor/verification'
|
import {
|
||||||
|
ISSUE_CODES,
|
||||||
|
issueMessageKey,
|
||||||
|
issueTarget,
|
||||||
|
placeKey,
|
||||||
|
} from '@/editor/verification'
|
||||||
import { getDict } from '@/i18n'
|
import { getDict } from '@/i18n'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import { insert, point } from '../helpers/editorFixtures'
|
import { insert, point } from '../helpers/editorFixtures'
|
||||||
@@ -27,10 +32,9 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
|||||||
submitSheetReview: vi.fn(),
|
submitSheetReview: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const onSelectTab = vi.fn()
|
const navigate = vi.fn()
|
||||||
const reloadSheet = vi.fn()
|
const reloadSheet = vi.fn()
|
||||||
const onGoTo = vi.fn()
|
const props = { readOnly: false, navigate, reloadSheet }
|
||||||
const props = { readOnly: false, onSelectTab, onGoTo, reloadSheet }
|
|
||||||
const SUBMIT = 'Soumettre à la revue'
|
const SUBMIT = 'Soumettre à la revue'
|
||||||
|
|
||||||
/** An annotation without geometry: a blocking error of the core. */
|
/** An annotation without geometry: a blocking error of the core. */
|
||||||
@@ -48,8 +52,7 @@ beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
cleanup()
|
cleanup()
|
||||||
resetStore()
|
resetStore()
|
||||||
onSelectTab.mockReset()
|
navigate.mockReset()
|
||||||
onGoTo.mockReset()
|
|
||||||
reloadSheet.mockReset()
|
reloadSheet.mockReset()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -81,10 +84,15 @@ describe('Vérification panel', () => {
|
|||||||
await user.click(
|
await user.click(
|
||||||
screen.getAllByRole('button', { name: 'Aller à Sans tracé' })[0],
|
screen.getAllByRole('button', { name: 'Aller à Sans tracé' })[0],
|
||||||
)
|
)
|
||||||
expect(onGoTo).toHaveBeenCalledWith('annotations', {
|
expect(navigate).toHaveBeenCalledWith(
|
||||||
kind: 'annotation',
|
{
|
||||||
id: 'anno-bare',
|
place: 'tab',
|
||||||
})
|
tab: 'annotations',
|
||||||
|
section: 'drawing',
|
||||||
|
key: { kind: 'annotation', id: 'anno-bare' },
|
||||||
|
},
|
||||||
|
expect.any(HTMLElement),
|
||||||
|
)
|
||||||
expect(screen.queryByText('Aucun problème détecté')).toBeNull()
|
expect(screen.queryByText('Aucun problème détecté')).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -204,6 +212,62 @@ describe('Submission', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('issueTarget', () => {
|
||||||
|
const at = (path: string) => issueTarget(doc(), path, 'fr')?.target
|
||||||
|
const doc = () => JSON.parse(store.getState().documentText)
|
||||||
|
|
||||||
|
it('each issue root names its place and the element it resolves to', async () => {
|
||||||
|
await openReady({ text: textWithError() })
|
||||||
|
expect(at('views[0].frame')).toMatchObject({
|
||||||
|
place: 'tab',
|
||||||
|
tab: 'annotations',
|
||||||
|
section: 'views',
|
||||||
|
key: { kind: 'view', id: 'view-main' },
|
||||||
|
})
|
||||||
|
expect(at('categories[0].name')).toMatchObject({
|
||||||
|
place: 'tab',
|
||||||
|
tab: 'annotations',
|
||||||
|
section: 'categories',
|
||||||
|
key: { kind: 'category', id: 'cat-a' },
|
||||||
|
})
|
||||||
|
expect(at('vertebral_config.regions[0].count')).toMatchObject({
|
||||||
|
place: 'tab',
|
||||||
|
tab: 'annotations',
|
||||||
|
section: 'regions',
|
||||||
|
})
|
||||||
|
expect(at('references[0].citation')).toMatchObject({
|
||||||
|
place: 'references',
|
||||||
|
citedBy: null,
|
||||||
|
})
|
||||||
|
expect(at('finding_zones[0].name')).toMatchObject({
|
||||||
|
place: 'tab',
|
||||||
|
tab: 'findings',
|
||||||
|
})
|
||||||
|
expect(at('annotations[0].geometry')).toMatchObject({
|
||||||
|
tab: 'annotations',
|
||||||
|
section: 'drawing',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a path whose element is gone names the place alone, and the label names it', async () => {
|
||||||
|
await openReady({ text: textWithError() })
|
||||||
|
const gone = at('views[9].frame')
|
||||||
|
expect(gone).toEqual({
|
||||||
|
place: 'tab',
|
||||||
|
tab: 'annotations',
|
||||||
|
section: 'views',
|
||||||
|
key: null,
|
||||||
|
})
|
||||||
|
expect(placeKey(gone!)).toBe('editor.place.views')
|
||||||
|
expect(placeKey(at('references[9].citation')!)).toBe(
|
||||||
|
'editor.place.references',
|
||||||
|
)
|
||||||
|
expect(placeKey(at('annotations[9].geometry')!)).toBe(
|
||||||
|
'editor.tab.annotations',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('Issue messages', () => {
|
describe('Issue messages', () => {
|
||||||
it('has an FR and an EN message for every known code', () => {
|
it('has an FR and an EN message for every known code', () => {
|
||||||
for (const code of ISSUE_CODES) {
|
for (const code of ISSUE_CODES) {
|
||||||
|
|||||||
Reference in new issue
Block a user