fix(editor): veil ignores clicks, names merged apart, honest tests
U2 Task 6 fix round 1 (review minors 1 to 9). - R-6: `Dialog` takes `veilCloses`; the annotation dialog passes false, so its veil ignores clicks centred too. Other dialogs unchanged. - Save merges each name on its own (an EN refreshed meanwhile survives an FR-only edit); the merged annotation is typed per kind, no cast. - Tests: the category change and the region row really run (a second category and a region in the fixture); EN kept under an FR edit; focus to the drawing when a filter hides the row; a centred veil ignores a click; act() around the store write; ui.Dialog restores innerHeight and visualViewport after each test. - e2e: `pickAnnotation` no longer scrolls; `scrollToTop` is explicit where a low row leaves the drawing out of view (editor-zones x3, editor-geometry). editor-geometry runs the accepted repair from the page's end, buttons pressed in place, scroll unchanged. The touch and double-click tests wait on the clicks themselves; the stray click on the veil can fail. - CreationPanel's `required.fields` recorded as a shortcut for Task 7; TODO lines updated. focusTarget comment wrapped.
This commit is contained in:
1 parent
db3f306523
commit
9a0fe3784c
12 files changed
+234
-58
No files matched your search
@@ -262,6 +262,7 @@ export default function AnnotationDialog(props: AnnotationDialogProps) {
|
||||
open={visible && annotation !== undefined}
|
||||
layer
|
||||
anchor={props.anchor}
|
||||
veilCloses={false}
|
||||
title={title}
|
||||
returnFocus={props.returnFocus}
|
||||
onClose={() => (layer.close() ? undefined : 'kept')}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState } from 'react'
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
Annotation,
|
||||
Laterality,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import { FormActions } from '@/components/editor/findings/DiscardConfirm'
|
||||
import ReadOnlyNotice from '@/components/editor/findings/ReadOnlyNotice'
|
||||
@@ -66,34 +67,66 @@ const normalized = (draft: Draft): Draft => ({
|
||||
const sameDraft = (a: Draft, b: Draft) =>
|
||||
JSON.stringify(normalized(a)) === JSON.stringify(normalized(b))
|
||||
|
||||
/** The names as saved: trimmed, or none for a link left with both blank. */
|
||||
function namesOf(annotation: Annotation, draft: Draft) {
|
||||
const name = { fr: draft.fr.trim(), en: draft.en.trim() }
|
||||
const none = name.fr === '' && name.en === ''
|
||||
return annotation.kind === 'detail_trigger' && none ? null : name
|
||||
/** Whether the user changed a field of the draft since the form opened. */
|
||||
type Changed = (key: keyof Draft) => boolean
|
||||
|
||||
/**
|
||||
* Each name on its own: the draft's when the user changed it, else the CURRENT one (an EN
|
||||
* refreshed meanwhile is kept when only FR was edited).
|
||||
*/
|
||||
function namesOf(current: Annotation, now: Draft, changed: Changed) {
|
||||
return {
|
||||
fr: changed('fr') ? now.fr : (current.name?.fr ?? ''),
|
||||
en: changed('en') ? now.en : (current.name?.en ?? ''),
|
||||
}
|
||||
}
|
||||
|
||||
/** Category, laterality and colour: the changed ones from the draft. */
|
||||
function commonOf(current: Annotation, now: Draft, changed: Changed) {
|
||||
return {
|
||||
category_id: changed('categoryId') ? now.categoryId : current.category_id,
|
||||
// Not blank here: `missingFields` refused the save before.
|
||||
laterality: changed('laterality')
|
||||
? (now.laterality as Laterality)
|
||||
: current.laterality,
|
||||
color: changed('color') ? nullable(now.color) : current.color,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The CURRENT annotation with only the fields the user changed (`first` → `draft`): a
|
||||
* change made meanwhile elsewhere (a drag, a review toggle) is never overwritten.
|
||||
* change made meanwhile elsewhere (a drag, a review toggle, a refresh) is never
|
||||
* overwritten. Typed per kind, so a misspelt field fails to compile.
|
||||
*/
|
||||
function merged(current: Annotation, first: Draft, draft: Draft): Annotation {
|
||||
const was = normalized(first)
|
||||
const now = normalized(draft)
|
||||
const changed = (key: keyof Draft) => was[key] !== now[key]
|
||||
const value: Record<string, unknown> = { ...current }
|
||||
if (changed('fr') || changed('en')) value.name = namesOf(current, draft)
|
||||
if (changed('categoryId')) value.category_id = draft.categoryId
|
||||
if (changed('laterality')) value.laterality = draft.laterality
|
||||
if (changed('color')) value.color = nullable(draft.color.trim())
|
||||
const changed: Changed = (key) => was[key] !== now[key]
|
||||
const named = changed('fr') || changed('en')
|
||||
const names = namesOf(current, now, changed)
|
||||
const common = commonOf(current, now, changed)
|
||||
if (current.kind === 'detail_trigger') {
|
||||
if (changed('opensViewId')) value.opens_view_id = draft.opensViewId
|
||||
} else {
|
||||
if (changed('zoneId')) value.finding_zone_id = nullable(draft.zoneId)
|
||||
if (changed('regionCode'))
|
||||
value.vertebral_region_code = nullable(draft.regionCode)
|
||||
const none = names.fr === '' && names.en === ''
|
||||
return {
|
||||
...current,
|
||||
...common,
|
||||
name: named ? (none ? null : names) : current.name,
|
||||
opens_view_id: changed('opensViewId')
|
||||
? now.opensViewId
|
||||
: current.opens_view_id,
|
||||
}
|
||||
}
|
||||
return {
|
||||
...current,
|
||||
...common,
|
||||
name: named ? names : current.name,
|
||||
finding_zone_id: changed('zoneId')
|
||||
? nullable(now.zoneId)
|
||||
: current.finding_zone_id,
|
||||
vertebral_region_code: changed('regionCode')
|
||||
? nullable(now.regionCode)
|
||||
: current.vertebral_region_code,
|
||||
}
|
||||
return value as unknown as Annotation
|
||||
}
|
||||
|
||||
/** The annotation as the document holds it now, read by id at the save. */
|
||||
|
||||
@@ -47,6 +47,9 @@ function useCreation(props: CreationPanelProps) {
|
||||
const [messages, setMessages] = useState<string[]>([])
|
||||
const settle = (attempt: Attempt) => {
|
||||
const { dispatch, pending } = props
|
||||
// shortcut: the general lines `editor.annotations.required.{fields,names}` (R-3 removes
|
||||
// them) stay until Task 7. Upgrade: the creation dialog names each field through
|
||||
// `missingFields` and the `editor.annotations.missing.*` keys, as the edit form does.
|
||||
setMessages(
|
||||
messagesOf(attempt, (p) => t(`editor.annotations.required.${p}`)),
|
||||
)
|
||||
|
||||
@@ -27,6 +27,11 @@ export interface DialogProps {
|
||||
* under a lighter veil that ignores clicks (R-6). Without a box, the panel is centred.
|
||||
*/
|
||||
anchor?: RefObject<HTMLElement | null>
|
||||
/**
|
||||
* False: a click on the veil does nothing, even centred (R-6: the annotation dialogs, so
|
||||
* the tap that opened one never closes it). An anchored dialog's veil never closes.
|
||||
*/
|
||||
veilCloses?: boolean
|
||||
}
|
||||
|
||||
const SIZE: Record<NonNullable<DialogProps['size']>, string> = {
|
||||
@@ -83,6 +88,7 @@ function DialogSurface({
|
||||
children,
|
||||
size = 'md',
|
||||
anchor,
|
||||
veilCloses = true,
|
||||
}: Omit<DialogProps, 'open'>) {
|
||||
const t = useT()
|
||||
const reduced = useReducedMotion()
|
||||
@@ -107,7 +113,7 @@ function DialogSurface({
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{ duration: reduced ? 0 : 0.15 }}
|
||||
// R-6: over a column, the tap that opened the dialog never closes it.
|
||||
onClick={place ? undefined : onClose}
|
||||
onClick={place || !veilCloses ? undefined : onClose}
|
||||
/>
|
||||
<motion.div
|
||||
data-testid="dialog-panel"
|
||||
|
||||
Reference in new issue
Block a user