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.
168 lines
5.0 KiB
TypeScript
168 lines
5.0 KiB
TypeScript
import { useState, type Dispatch } from 'react'
|
|
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
|
import Button from '@/components/ui/Button'
|
|
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
|
import {
|
|
emptyForm,
|
|
withGeometry,
|
|
type CreationForm,
|
|
type PendingElement,
|
|
} from '@/editor/annotations/creation'
|
|
import {
|
|
confirmAttempt,
|
|
createAttempt,
|
|
type Attempt,
|
|
type CreationInput,
|
|
} from '@/editor/annotations/creationAttempt'
|
|
import type { Frame } from '@/editor/annotations/frame'
|
|
import type { UiAction } from '@/editor/annotations/uiState'
|
|
import { useT } from '@/i18n/useT'
|
|
import CorrectionNotice from './CorrectionNotice'
|
|
import CreationFields from './CreationFields'
|
|
import GeometryGroup from './GeometryGroup'
|
|
|
|
export interface CreationPanelProps {
|
|
pending: PendingElement
|
|
viewId: string
|
|
doc: AnatomicalSheetDocument
|
|
/** F of the current view; null while it is not measured. */
|
|
frame: Frame | null
|
|
dispatch: Dispatch<UiAction>
|
|
context: CommitContext
|
|
}
|
|
|
|
/** What an attempt leaves on screen: the core's words, or the form's own. */
|
|
function messagesOf(attempt: Attempt, words: (problem: string) => string) {
|
|
if (attempt.status === 'refused') return attempt.messages
|
|
return attempt.status === 'invalid' ? [words(attempt.problem)] : []
|
|
}
|
|
|
|
/**
|
|
* The typed fields and the outcome of « Créer » / « Utiliser cette position ». The form
|
|
* survives a change of the pending geometry (a second click): the panel is not remounted.
|
|
*/
|
|
function useCreation(props: CreationPanelProps) {
|
|
const t = useT()
|
|
const [form, setForm] = useState<CreationForm>(() => emptyForm(props.doc))
|
|
const [messages, setMessages] = useState<string[]>([])
|
|
const settle = (attempt: Attempt) => {
|
|
const { dispatch, pending } = props
|
|
setMessages(
|
|
messagesOf(attempt, (p) => t(`editor.annotations.required.${p}`)),
|
|
)
|
|
if (attempt.status === 'created') {
|
|
dispatch({ type: 'select', id: attempt.id ?? null })
|
|
}
|
|
if (attempt.status === 'correction') {
|
|
const next = { ...pending, correction: attempt.correction }
|
|
dispatch({ type: 'pending_update', pending: next })
|
|
}
|
|
}
|
|
const input: CreationInput = props
|
|
return {
|
|
form,
|
|
messages,
|
|
patch: (change: Partial<CreationForm>) => setForm({ ...form, ...change }),
|
|
create: () => settle(createAttempt(input, form)),
|
|
confirm: () => {
|
|
const { correction } = props.pending
|
|
if (correction) settle(confirmAttempt(input, form, correction))
|
|
},
|
|
}
|
|
}
|
|
|
|
/**
|
|
* « Nouveau point / Nouvelle zone / Nouvel accès »: the fields the core requires are
|
|
* collected first, then « Créer » inserts once through `accept` (no default labels).
|
|
* The geometry stays here, outside the document, until then.
|
|
*/
|
|
export default function CreationPanel(props: CreationPanelProps) {
|
|
const t = useT()
|
|
const creation = useCreation(props)
|
|
const { pending, dispatch } = props
|
|
const title = t(`editor.annotations.new.${pending.kind}`)
|
|
return (
|
|
<section
|
|
aria-label={title}
|
|
data-testid="annotation-creation"
|
|
className="space-y-3 rounded-xl border border-[var(--color-border)] p-4"
|
|
>
|
|
<h3
|
|
tabIndex={-1}
|
|
data-creation-heading
|
|
className="outline-none text-base font-semibold"
|
|
>
|
|
{title}
|
|
</h3>
|
|
<CreationFields
|
|
kind={pending.kind}
|
|
viewId={props.viewId}
|
|
form={creation.form}
|
|
doc={props.doc}
|
|
onChange={creation.patch}
|
|
/>
|
|
<GeometryGroup
|
|
idPrefix="creation"
|
|
geometry={pending.geometry}
|
|
locked={false}
|
|
onApply={(geometry) => {
|
|
const next = withGeometry(pending, geometry)
|
|
dispatch({ type: 'pending_update', pending: next })
|
|
return { ok: true }
|
|
}}
|
|
/>
|
|
{pending.correction && (
|
|
<CorrectionNotice
|
|
correction={pending.correction}
|
|
onConfirm={creation.confirm}
|
|
onCancel={() =>
|
|
dispatch({
|
|
type: 'pending_update',
|
|
pending: { ...pending, correction: null },
|
|
})
|
|
}
|
|
/>
|
|
)}
|
|
<Messages messages={creation.messages} />
|
|
<CreationActions
|
|
onCreate={creation.create}
|
|
onCancel={() => dispatch({ type: 'pending_drop' })}
|
|
/>
|
|
</section>
|
|
)
|
|
}
|
|
|
|
function CreationActions({
|
|
onCreate,
|
|
onCancel,
|
|
}: {
|
|
onCreate: () => void
|
|
onCancel: () => void
|
|
}) {
|
|
const t = useT()
|
|
return (
|
|
<div className="flex gap-2">
|
|
<Button type="button" onClick={onCreate}>
|
|
{t('editor.annotations.create')}
|
|
</Button>
|
|
<Button type="button" variant="secondary" onClick={onCancel}>
|
|
{t('editor.annotations.create_cancel')}
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function Messages({ messages }: { messages: string[] }) {
|
|
if (messages.length === 0) return null
|
|
return (
|
|
<div
|
|
role="alert"
|
|
className="space-y-1 text-sm text-[var(--color-danger-strong)]"
|
|
>
|
|
{messages.map((message) => (
|
|
<p key={message}>{message}</p>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|