U2 Task 3 (A6, A14, R-2). A fixed-height strip over the drawing and the right column replaces the tool line, the sr-only selection tag of the edit body and TracingBar: lead (name + status, type + detail), notice (refusal, first geometry issue + n, unmeasured view with its link, no category, no child view), commands (Fermer le trace, Retirer le dernier sommet, Annuler le trace). A fixed-height line under the drawing holds the add buttons and the gesture message: a kept drop says « Point deplace » with « Defaire » (same store undo as the header), a refused drop says « Deplacement refuse : ... » as a red alert. 6 s, held by mouse hover and focus inside, closed by any commit, undo or redo. trace_pop and Backspace remove the last vertex. The busy « Aller a » target is the strip's tracing commands. scrollbar-gutter stable, scoped to the editor. e2e helper expectNoShift (boxes, scroll height, gutter, client width, layout-shift sum). DraftHeader untouched: no shift seen. Rewritten assertions (old -> new): - tab unit « Sélection : point » on annotation-selection-tag -> strip detail « Point » - tab unit tag sr-only, not live -> strip lead outside any live region - tab unit « 1 sommet posé. » -> « 1 sommet posé » (board 04 wording) - tab unit D6b tag present / « zone » -> strip detail « Point » / « Zone · 3 sommets » - keep-alive, sections, escape units: tracing-bar -> tracing-commands - e2e selectionTag helper -> strip title with data-selection; the twin's tag is twinSelectionTag (deselect 375 px describe) - e2e deselect « tag position absolute » (edit) -> strip height 64 px, drawing top unchanged; twin Escape test keeps tag 0, properties 0, overview visible - e2e deselect and journey tracing-bar / annotation-selection-tag -> tracing-commands / selectionTag - e2e historyButton scoped to history-buttons (the message's « Défaire » has the same accessible name)
315 lines
9.0 KiB
TypeScript
315 lines
9.0 KiB
TypeScript
import { useState, type Dispatch } from 'react'
|
|
import { flushSync } from 'react-dom'
|
|
import type {
|
|
AnatomicalSheetDocument,
|
|
Annotation,
|
|
Geometry,
|
|
Marking,
|
|
} from '@faunosteo/core-wasm/types'
|
|
import ActionButton from '@/components/editor/fields/ActionButton'
|
|
import DeleteDialog from '@/components/editor/DeleteDialog'
|
|
import Button from '@/components/ui/Button'
|
|
import {
|
|
updateGeometry,
|
|
type CommitContext,
|
|
} from '@/editor/annotations/annotationCommit'
|
|
import { useDeselect } from '@/editor/annotations/deselect'
|
|
import EditorGlyph from '@/components/editor/EditorGlyph'
|
|
import { isEditable } from '@/editor/annotations/geometryEdit'
|
|
import type { UiAction } from '@/editor/annotations/uiState'
|
|
import { geometryErrorsById } from '@/editor/issues'
|
|
import { focusRow } from '@/editor/focusRequest'
|
|
import { targetOfKey } from '@/editor/navigation'
|
|
import type { EditorPlaceProps } from '@/editor/tabs'
|
|
import { useEditCommand } from '@/editor/useEditCommand'
|
|
import { useEditorStore } from '@/editor/state/editorStore'
|
|
import { useT } from '@/i18n/useT'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
import AnnotationFields from './AnnotationFields'
|
|
import type { ApplyResult } from './GeometryGroup'
|
|
import { annotationName } from './AnnotationList'
|
|
import GeometryGroup from './GeometryGroup'
|
|
import ReviewBadge from './ReviewBadge'
|
|
|
|
export interface PropertiesPanelProps {
|
|
annotation: Annotation
|
|
doc: AnatomicalSheetDocument
|
|
/** Not editable now: every field shows as text and no action is offered. */
|
|
readOnly: boolean
|
|
/** The view is not measured: geometry is shown as text only, the rest stays editable. */
|
|
geometryLocked: boolean
|
|
dispatch: Dispatch<UiAction>
|
|
context: CommitContext
|
|
navigate: EditorPlaceProps['navigate']
|
|
/** Clears the selection: the overview shows again. */
|
|
onShowAll: () => void
|
|
/** A tracing runs: the selection is not left from here. */
|
|
busy?: boolean
|
|
/** Put before every id, for a twin of the panel that lives beside another one. */
|
|
idPrefix?: string
|
|
}
|
|
|
|
/** What still names this annotation as invalid: never hidden, never shown as valid. */
|
|
export function useGeometryIssues(id: string): string[] {
|
|
const state = useEditorStore((s) => s.previewState)
|
|
const issues = state ? geometryErrorsById(state).get(id) : undefined
|
|
return [...new Set((issues ?? []).map((issue) => issue.message))]
|
|
}
|
|
|
|
export default function PropertiesPanel(props: PropertiesPanelProps) {
|
|
const t = useT()
|
|
const locale = useLocaleStore((s) => s.locale)
|
|
const { annotation, doc, readOnly } = props
|
|
const edit = useEditCommand()
|
|
const name = annotationName(annotation, doc.views, locale)
|
|
return (
|
|
<section
|
|
aria-label={t('editor.annotations.properties')}
|
|
data-testid="annotation-properties"
|
|
className="space-y-4 rounded-xl border border-[var(--color-border)] p-4"
|
|
>
|
|
<ShowAll id={annotation.id} onShowAll={props.onShowAll} />
|
|
<header className="flex items-start justify-between gap-2">
|
|
<h3
|
|
tabIndex={-1}
|
|
data-properties-heading
|
|
className="outline-none text-base font-semibold"
|
|
>
|
|
{t(`editor.annotations.kind.${annotation.kind}`)}
|
|
</h3>
|
|
<ReviewBadge status={annotation.review_status} />
|
|
</header>
|
|
<AnnotationFields
|
|
annotation={annotation}
|
|
doc={doc}
|
|
readOnly={readOnly}
|
|
edit={edit}
|
|
idPrefix={props.idPrefix}
|
|
/>
|
|
<GeometrySection {...props} />
|
|
<StatusActions annotation={annotation} readOnly={readOnly} edit={edit} />
|
|
<div className="flex flex-wrap gap-2 border-t border-[var(--color-border)] pt-2.5">
|
|
<DeselectButton annotationId={annotation.id} {...props} />
|
|
<Deletion id={annotation.id} name={name} readOnly={readOnly} />
|
|
</div>
|
|
</section>
|
|
)
|
|
}
|
|
|
|
/** Back to the overview, focus on the row of the annotation that was open. */
|
|
function ShowAll({ id, onShowAll }: { id: string; onShowAll: () => void }) {
|
|
const t = useT()
|
|
return (
|
|
<Button
|
|
type="button"
|
|
variant="secondary"
|
|
size="sm"
|
|
onClick={() => {
|
|
flushSync(onShowAll)
|
|
focusRow({ kind: 'annotation', id })
|
|
}}
|
|
>
|
|
{t('editor.annotations.show_all')}
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
/** Leaves the annotation open: the overview shows again, the focus on its row. */
|
|
function DeselectButton({
|
|
annotationId,
|
|
onShowAll,
|
|
busy,
|
|
}: { annotationId: string } & Pick<
|
|
PropertiesPanelProps,
|
|
'onShowAll' | 'busy'
|
|
>) {
|
|
const t = useT()
|
|
const { byButton } = useDeselect(annotationId, onShowAll)
|
|
if (busy) return null
|
|
return (
|
|
<Button
|
|
type="button"
|
|
variant="secondary"
|
|
size="sm"
|
|
className="min-h-11 gap-1.5 xl:min-h-9"
|
|
// Keeps the focus in a field being typed, so its blur commit runs in byButton.
|
|
onMouseDown={(event) => event.preventDefault()}
|
|
onClick={byButton}
|
|
>
|
|
<EditorGlyph name="deselect" size={16} />
|
|
{t('editor.annotations.deselect')}
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
function GeometrySection(props: PropertiesPanelProps) {
|
|
const t = useT()
|
|
const { annotation, readOnly, geometryLocked } = props
|
|
const locked = readOnly || geometryLocked
|
|
const { geometry } = annotation
|
|
return (
|
|
<div className="space-y-2">
|
|
{geometryLocked && !readOnly && (
|
|
<UnmeasuredHint navigate={props.navigate} viewId={annotation.view_id} />
|
|
)}
|
|
{isEditable(geometry) ? (
|
|
<GeometryGroup
|
|
key={annotation.id}
|
|
idPrefix={`${props.idPrefix ?? ''}annotation`}
|
|
geometry={geometry}
|
|
locked={locked}
|
|
onApply={(next) => applyGeometry(annotation, next, props.context)}
|
|
/>
|
|
) : (
|
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
|
{t(
|
|
geometry === null
|
|
? 'editor.annotations.no_geometry'
|
|
: 'editor.annotations.path',
|
|
)}
|
|
</p>
|
|
)}
|
|
{!locked && !isEditable(geometry) && (
|
|
<TraceReplacement id={annotation.id} dispatch={props.dispatch} />
|
|
)}
|
|
<GeometryIssues id={annotation.id} />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function applyGeometry(
|
|
annotation: Annotation,
|
|
next: Geometry,
|
|
context: CommitContext,
|
|
): ApplyResult {
|
|
const result = updateGeometry(annotation, next, context)
|
|
return result.ok ? { ok: true } : { ok: false, messages: result.messages }
|
|
}
|
|
|
|
function TraceReplacement({
|
|
id,
|
|
dispatch,
|
|
}: {
|
|
id: string
|
|
dispatch: Dispatch<UiAction>
|
|
}) {
|
|
const t = useT()
|
|
return (
|
|
<Button
|
|
type="button"
|
|
variant="secondary"
|
|
size="sm"
|
|
onClick={() =>
|
|
dispatch({ type: 'trace_start', target: 'replace', annotationId: id })
|
|
}
|
|
>
|
|
{t('editor.annotations.replace_polygon')}
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
function GeometryIssues({ id }: { id: string }) {
|
|
const issues = useGeometryIssues(id)
|
|
if (issues.length === 0) return null
|
|
return (
|
|
<ul
|
|
role="alert"
|
|
data-testid="annotation-geometry-issues"
|
|
className="list-disc pl-5 text-sm text-[var(--color-danger-strong)]"
|
|
>
|
|
{issues.map((issue) => (
|
|
<li key={issue}>{issue}</li>
|
|
))}
|
|
</ul>
|
|
)
|
|
}
|
|
|
|
/** Points to the views section, on the view whose drawing cannot be measured. */
|
|
export function UnmeasuredHint({
|
|
navigate,
|
|
viewId,
|
|
}: Pick<PropertiesPanelProps, 'navigate'> & { viewId: string }) {
|
|
const t = useT()
|
|
return (
|
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
|
{t('editor.annotations.unmeasured.hint')}{' '}
|
|
<button
|
|
type="button"
|
|
className="underline"
|
|
onClick={() => navigate(targetOfKey({ kind: 'view', id: viewId }))}
|
|
>
|
|
{t('editor.place.views')}
|
|
</button>
|
|
</p>
|
|
)
|
|
}
|
|
|
|
function StatusActions({
|
|
annotation,
|
|
readOnly,
|
|
edit,
|
|
}: {
|
|
annotation: Annotation
|
|
readOnly: boolean
|
|
edit: ReturnType<typeof useEditCommand>
|
|
}) {
|
|
const t = useT()
|
|
const mark = (status: Marking) =>
|
|
edit.run('status', {
|
|
op: 'set_status',
|
|
key: { kind: 'annotation', id: annotation.id },
|
|
status,
|
|
})
|
|
const reviewed = annotation.review_status === 'reviewed'
|
|
return (
|
|
<div className="space-y-1">
|
|
<ActionButton
|
|
readOnly={readOnly}
|
|
variant="secondary"
|
|
size="sm"
|
|
onClick={() => mark(reviewed ? 'to_confirm' : 'reviewed')}
|
|
>
|
|
{t(
|
|
reviewed
|
|
? 'editor.annotations.to_confirm'
|
|
: 'editor.annotations.mark_reviewed',
|
|
)}
|
|
</ActionButton>
|
|
{edit.fieldError('status') && (
|
|
<p role="alert" className="text-sm text-[var(--color-danger-strong)]">
|
|
{edit.fieldError('status')}
|
|
</p>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function Deletion({
|
|
id,
|
|
name,
|
|
readOnly,
|
|
}: {
|
|
id: string
|
|
name: string
|
|
readOnly: boolean
|
|
}) {
|
|
const t = useT()
|
|
const [open, setOpen] = useState(false)
|
|
return (
|
|
<>
|
|
<ActionButton
|
|
readOnly={readOnly}
|
|
variant="danger"
|
|
size="sm"
|
|
onClick={() => setOpen(true)}
|
|
>
|
|
{t('editor.action.delete')}
|
|
</ActionButton>
|
|
<DeleteDialog
|
|
target={open ? { key: { kind: 'annotation', id }, label: name } : null}
|
|
onClose={() => setOpen(false)}
|
|
/>
|
|
</>
|
|
)
|
|
}
|