fix(editor): free paths never reshaped on attach, category zone chosen explicitly
This commit is contained in:
1 parent
f1175bb3a1
commit
a69eba569b
13 files changed
+333
-117
No files matched your search
@@ -528,3 +528,12 @@ Shown when a drawing attached to a view that was unmeasured would put the geomet
|
||||
|---|---|---|---|
|
||||
| `editor.views.repair.more_outside` | D'autres éléments sortiraient aussi du nouveau cadre : {names}. Rien n'a été appliqué. Annulez, corrigez-les, puis choisissez de nouveau l'illustration. | Other elements would also fall outside the new frame: {names}. Nothing was applied. Cancel, fix them, then choose the drawing again. | New: `newly_invalid` inside the dialog (the old wording sent to a locked tab) |
|
||||
| `editor.views.repair.not_measurable` | Avec cette illustration, une vue qui porte des annotations ne serait pas mesurable. Rien n'a été appliqué. | With this drawing, a view holding annotations would not be measurable. Nothing was applied. | New: `view_unmeasured` / `changed_unmeasured` inside the dialog |
|
||||
|
||||
## Lot O1 (owner decisions 2026-11-04: free paths never reshaped, C45; explicit category zone, C46)
|
||||
|
||||
| Key | FR | EN | Old wording and why |
|
||||
|---|---|---|---|
|
||||
| `editor.views.repair.path_blocked` | Ce tracé libre est conservé tel quel. L'illustration ne peut pas être attachée tant qu'il sort du nouveau cadre : l'éditeur ne sait pas encore corriger les points d'un tracé libre. | This free path is kept as it is. The drawing cannot be attached while it falls outside the new frame: the editor cannot yet correct the points of a free path. | Old « Ce tracé n'a pas de coordonnées à corriger ici. Remplacez-le par un polygone pour pouvoir attacher l'illustration. »: the conversion to a triangle is refused by the owner. The reason is plain, nothing offered. The repair dialog no longer uses `editor.annotations.replace_polygon` (kept for the properties panel) |
|
||||
| `editor.findings.zone` | Zone | Zone | New: label of the required zone choice in the « Ajouter une catégorie » form |
|
||||
| `editor.findings.add_category_no_zone` | Créez d'abord une zone pour ajouter une catégorie. | Create a zone first to add a category. | New: hint shown while « Ajouter une catégorie » is disabled because no zone exists |
|
||||
| `editor.findings.required` | Renseignez le nom en français et en anglais (et la zone et le type d'une catégorie). | Fill in the name in French and in English (and the zone and the type of a category). | Old « … (et le type d'une catégorie). »: the zone is now a required choice of a category |
|
||||
@@ -314,6 +314,77 @@ test.describe('editor geometry (adversarial)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('a free path outside the new frame blocks the attach, is never reshaped and survives a save', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
const seededPath =
|
||||
'M 300 300 l 40 0 C 350 320 380 360 400 400 q 20 -30 -40 -50 ' +
|
||||
'A 30 20 0 0 1 320 330 H 310 V 305 Z'
|
||||
const path = {
|
||||
...pointOf('out-path', 'main', { cx: 0, cy: 0, r: 1 }, 'Tracé libre'),
|
||||
kind: 'zone',
|
||||
geometry: { type: 'path', d: seededPath },
|
||||
}
|
||||
const point = pointOf(
|
||||
'out-point',
|
||||
'main',
|
||||
{ cx: 500, cy: 400, r: 20 },
|
||||
'Point hors cadre',
|
||||
)
|
||||
const actor = await editorActor('fr')
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
const seed = await seedDraft(actor, {
|
||||
drawing: null,
|
||||
shape: (document) => {
|
||||
standardShape(document)
|
||||
const views = document.views as { id: string }[]
|
||||
document.views = views.filter((view) => view.id === 'main')
|
||||
document.annotations = [point, path]
|
||||
},
|
||||
})
|
||||
await openEditor(page, dict, actor, seed.sheetId)
|
||||
await selectTab(page, dict, 'views')
|
||||
await page.getByTestId('view-main-file').setInputFiles({
|
||||
name: 'petit.svg',
|
||||
mimeType: 'image/svg+xml',
|
||||
buffer: Buffer.from(
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">' +
|
||||
'<rect x="2" y="2" width="96" height="96" fill="#eee"/></svg>',
|
||||
),
|
||||
})
|
||||
const dialog = page.getByRole('dialog', {
|
||||
name: dict['editor.views.repair.title'],
|
||||
})
|
||||
await expect(dialog).toBeVisible()
|
||||
const row = dialog.getByTestId('repair-out-path')
|
||||
await expect(
|
||||
row.getByText(dict['editor.views.repair.path_blocked']),
|
||||
).toBeVisible()
|
||||
await expect(row.getByRole('button')).toHaveCount(0)
|
||||
await expect(
|
||||
dialog.getByRole('button', { name: dict['editor.views.repair.apply'] }),
|
||||
).toBeDisabled()
|
||||
await dialog
|
||||
.getByRole('button', { name: dict['editor.views.repair.cancel'] })
|
||||
.click()
|
||||
await expect(dialog).toBeHidden()
|
||||
|
||||
// An unrelated change is saved: the path is still the seeded one, byte for byte.
|
||||
await selectTab(page, dict, 'general')
|
||||
const nameFr = page.getByLabel(dict['editor.general.name_fr'], {
|
||||
exact: true,
|
||||
})
|
||||
await nameFr.fill('Fiche sans toucher au tracé')
|
||||
await nameFr.press('Tab')
|
||||
await saveDraft(page, dict, seed.revision + 1)
|
||||
const saved = await serverDocument<{
|
||||
annotations: { id: string; geometry: Record<string, unknown> }[]
|
||||
}>(seed.draftId)
|
||||
const kept = saved.annotations.find((a) => a.id === 'out-path')
|
||||
expect(kept?.geometry).toEqual({ type: 'path', d: seededPath })
|
||||
})
|
||||
|
||||
test('an unmeasured view: drawing tools and add buttons disabled, the hint shown', async ({
|
||||
page,
|
||||
requests,
|
||||
|
||||
@@ -119,6 +119,7 @@ async function createFindings(page: Page) {
|
||||
await names('Zone essai', 'Trial zone')
|
||||
await create()
|
||||
await clickButton(page, dict['editor.findings.add_category'])
|
||||
await page.locator('#finding-new-zone').selectOption({ label: 'Zone essai' })
|
||||
await page.locator('#finding-new-kind').selectOption('dysfunction')
|
||||
await names('Dysfonction essai', 'Trial dysfunction')
|
||||
await create()
|
||||
|
||||
@@ -153,6 +153,7 @@ test.describe('editor structures (A4)', () => {
|
||||
await page
|
||||
.getByRole('button', { name: dict['editor.findings.add_category'] })
|
||||
.click()
|
||||
await page.locator('#finding-new-zone').selectOption({ label: 'Zone B' })
|
||||
await page.locator('#finding-new-kind').selectOption('anamnesis')
|
||||
await page.locator('#finding-new-name-fr').fill('Anamnèse B')
|
||||
await page.locator('#finding-new-name-en').fill('History B')
|
||||
|
||||
@@ -3,13 +3,18 @@ import type { PendingFinding } from '@/components/editor/findings/FindingCreateF
|
||||
import { canAddNode, type FindingItem } from '@/editor/findings/tree'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** « Ajouter une zone / une catégorie / un constat »: each starts a creation form. */
|
||||
/**
|
||||
* « Ajouter une zone / une catégorie / un constat »: each starts a creation form. Only
|
||||
* the node depends on the selection; a category names its zone in its own form (C46).
|
||||
*/
|
||||
export default function AddBar({
|
||||
selected,
|
||||
hasZone,
|
||||
readOnly,
|
||||
onStart,
|
||||
}: {
|
||||
selected: FindingItem | undefined
|
||||
hasZone: boolean
|
||||
readOnly: boolean
|
||||
onStart: (pending: PendingFinding) => void
|
||||
}) {
|
||||
@@ -28,8 +33,8 @@ export default function AddBar({
|
||||
readOnly={readOnly}
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
disabled={!selected}
|
||||
onClick={() => onStart({ kind: 'category', parent: selected ?? null })}
|
||||
disabled={!hasZone}
|
||||
onClick={() => onStart({ kind: 'category', parent: null })}
|
||||
>
|
||||
{t('editor.findings.add_category')}
|
||||
</ActionButton>
|
||||
@@ -42,6 +47,11 @@ export default function AddBar({
|
||||
>
|
||||
{t('editor.findings.add_node')}
|
||||
</ActionButton>
|
||||
{!hasZone && !readOnly && (
|
||||
<p className="basis-full text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.findings.add_category_no_zone')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -7,9 +7,13 @@ import type {
|
||||
import ActionButton from '@/components/editor/fields/ActionButton'
|
||||
import DraftField from '@/components/editor/fields/DraftField'
|
||||
import SelectField from '@/components/editor/fields/SelectField'
|
||||
import type { FindingItem, FindingKind } from '@/editor/findings/tree'
|
||||
import {
|
||||
buildItems,
|
||||
type FindingItem,
|
||||
type FindingKind,
|
||||
} from '@/editor/findings/tree'
|
||||
import type { IdPrefix } from '@/editor/ids'
|
||||
import { elementLabel, isBlank, useSheetDocument } from '@/editor/sheetDocument'
|
||||
import { isBlank, useSheetDocument } from '@/editor/sheetDocument'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
@@ -23,7 +27,7 @@ export const CATEGORY_KINDS: readonly FindingCategoryKind[] = [
|
||||
|
||||
export interface PendingFinding {
|
||||
kind: FindingKind
|
||||
/** The zone, category or node the new element goes under; null for a zone. */
|
||||
/** The category or node a node goes under; null for a zone and a category. */
|
||||
parent: FindingItem | null
|
||||
}
|
||||
|
||||
@@ -37,18 +41,24 @@ export default function FindingCreateForm({
|
||||
onCancel,
|
||||
}: {
|
||||
pending: PendingFinding
|
||||
onCreated: (id: string) => void
|
||||
onCreated: (id: string, parent: FindingItem | null) => void
|
||||
onCancel: () => void
|
||||
}) {
|
||||
const t = useT()
|
||||
const title = useFormTitle(pending)
|
||||
const edit = useEditCommand()
|
||||
const zones = useZoneChoice()
|
||||
const title = useFormTitle(pending, zones.chosen)
|
||||
const [fr, setFr] = useState('')
|
||||
const [en, setEn] = useState('')
|
||||
const [kind, setKind] = useState('')
|
||||
const create = () => {
|
||||
const parent = pending.kind === 'category' ? zones.chosen : pending.parent
|
||||
const missingParent = pending.kind === 'category' && !parent
|
||||
const incomplete =
|
||||
isBlank(fr) || isBlank(en) || (pending.kind === 'category' && !kind)
|
||||
isBlank(fr) ||
|
||||
isBlank(en) ||
|
||||
missingParent ||
|
||||
(pending.kind === 'category' && !kind)
|
||||
if (incomplete) {
|
||||
edit.reject('form', 'editor.findings.required')
|
||||
return
|
||||
@@ -56,14 +66,16 @@ export default function FindingCreateForm({
|
||||
let createdId = ''
|
||||
const added = edit.runNew('form', PREFIX[pending.kind], (id) => {
|
||||
createdId = id
|
||||
return insertCommand(pending, id, { fr: fr.trim(), en: en.trim() }, kind)
|
||||
const name = { fr: fr.trim(), en: en.trim() }
|
||||
return insertCommand({ ...pending, parent }, id, name, kind)
|
||||
})
|
||||
if (added) onCreated(createdId)
|
||||
if (added) onCreated(createdId, parent)
|
||||
}
|
||||
return (
|
||||
<div className="space-y-2 rounded-lg border border-dashed border-[var(--color-border)] p-3">
|
||||
<p className="text-sm font-medium">{title}</p>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
{pending.kind === 'category' && <ZoneSelect zones={zones} />}
|
||||
{pending.kind === 'category' && (
|
||||
<SelectField
|
||||
id="finding-new-kind"
|
||||
@@ -109,19 +121,58 @@ export default function FindingCreateForm({
|
||||
)
|
||||
}
|
||||
|
||||
/** A category lands at zone level, so its title names the zone, whatever is selected. */
|
||||
function useFormTitle(pending: PendingFinding): string {
|
||||
const t = useT()
|
||||
interface ZoneChoice {
|
||||
zones: readonly FindingItem[]
|
||||
zoneId: string
|
||||
setZoneId: (id: string) => void
|
||||
chosen: FindingItem | null
|
||||
}
|
||||
|
||||
/** The zones to choose from; with exactly one, it is preselected, otherwise nothing is. */
|
||||
function useZoneChoice(): ZoneChoice {
|
||||
const doc = useSheetDocument()
|
||||
const zones = doc ? buildItems(doc).filter((i) => i.kind === 'zone') : []
|
||||
const [zoneId, setZoneId] = useState(
|
||||
zones.length === 1 ? zones[0].zoneId : '',
|
||||
)
|
||||
const chosen = zones.find((zone) => zone.zoneId === zoneId) ?? null
|
||||
return { zones, zoneId, setZoneId, chosen }
|
||||
}
|
||||
|
||||
function ZoneSelect({ zones }: { zones: ZoneChoice }) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
if (pending.kind !== 'category') return t(`editor.findings.new.${pending.kind}`)
|
||||
if (!doc || !pending.parent) return t('editor.findings.add_category')
|
||||
const zone = elementLabel(
|
||||
doc,
|
||||
{ kind: 'zone', id: pending.parent.zoneId },
|
||||
locale,
|
||||
return (
|
||||
<SelectField
|
||||
id="finding-new-zone"
|
||||
label={t('editor.findings.zone')}
|
||||
value={zones.zoneId}
|
||||
options={[
|
||||
{ value: '', label: t('editor.field.choose') },
|
||||
...zones.zones.map((zone) => ({
|
||||
value: zone.zoneId,
|
||||
label: zone.name[locale],
|
||||
})),
|
||||
]}
|
||||
onCommit={zones.setZoneId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** A category lands at zone level: its title names the zone chosen in the form. */
|
||||
function useFormTitle(
|
||||
pending: PendingFinding,
|
||||
zone: FindingItem | null,
|
||||
): string {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
if (pending.kind !== 'category')
|
||||
return t(`editor.findings.new.${pending.kind}`)
|
||||
if (!zone) return t('editor.findings.add_category')
|
||||
return t('editor.findings.new.category_in_zone').replace(
|
||||
'{zone}',
|
||||
zone.name[locale],
|
||||
)
|
||||
return t('editor.findings.new.category_in_zone').replace('{zone}', zone)
|
||||
}
|
||||
|
||||
const PREFIX: Record<FindingKind, IdPrefix> = {
|
||||
@@ -146,7 +197,7 @@ function insertCommand(
|
||||
if (pending.kind === 'category') {
|
||||
return {
|
||||
op: 'insert',
|
||||
parent: { kind: 'zone', id: pending.parent?.zoneId ?? '' },
|
||||
parent: pending.parent?.key,
|
||||
element: {
|
||||
kind: 'finding_category',
|
||||
value: {
|
||||
|
||||
@@ -72,10 +72,10 @@ export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
|
||||
setSelectedId(found.item.id)
|
||||
setFocusId({ id: found.item.id })
|
||||
})
|
||||
const created = (id: string) => {
|
||||
const created = (id: string, parent: FindingItem | null) => {
|
||||
if (!pending) return
|
||||
if (pending.parent) toggle(pending.parent.id, true)
|
||||
setSelectedId(createdItemId(pending.kind, pending.parent, id))
|
||||
if (parent) toggle(parent.id, true)
|
||||
setSelectedId(createdItemId(pending.kind, parent, id))
|
||||
setPending(null)
|
||||
}
|
||||
const askDelete = (item: FindingItem) => {
|
||||
@@ -96,7 +96,12 @@ export default function FindingsTab({ readOnly, focus }: EditorTabProps) {
|
||||
aria-label={t('editor.tab.findings')}
|
||||
className="min-h-24 space-y-3"
|
||||
>
|
||||
<AddBar selected={selected} readOnly={readOnly} onStart={setPending} />
|
||||
<AddBar
|
||||
selected={selected}
|
||||
hasZone={items.some((item) => item.kind === 'zone')}
|
||||
readOnly={readOnly}
|
||||
onStart={setPending}
|
||||
/>
|
||||
{pending && !readOnly && (
|
||||
<FindingCreateForm
|
||||
key={`${pending.kind}-${pending.parent?.id ?? ''}`}
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
blockedIds,
|
||||
initialGeometries,
|
||||
listedAnnotations,
|
||||
polygonReplacement,
|
||||
type RepairOffer,
|
||||
type RepairResult,
|
||||
} from '@/editor/repair'
|
||||
@@ -119,7 +118,6 @@ function RepairForm({
|
||||
key={annotation.id}
|
||||
annotation={annotation}
|
||||
geometry={state.geometries[annotation.id]}
|
||||
offer={offer}
|
||||
messages={refused?.byAnnotation[annotation.id]}
|
||||
onChange={(geometry) => state.change(annotation.id, geometry)}
|
||||
onPending={state.report}
|
||||
@@ -155,7 +153,6 @@ function Refusal({ general }: { general: string | null }) {
|
||||
interface RowProps {
|
||||
annotation: Annotation
|
||||
geometry: Geometry | undefined
|
||||
offer: RepairOffer
|
||||
messages: string[] | undefined
|
||||
onChange: (geometry: Geometry) => void
|
||||
onPending: (id: string, pending: boolean) => void
|
||||
@@ -164,7 +161,6 @@ interface RowProps {
|
||||
function RepairRow({
|
||||
annotation,
|
||||
geometry,
|
||||
offer,
|
||||
messages,
|
||||
onChange,
|
||||
onPending,
|
||||
@@ -194,11 +190,7 @@ function RepairRow({
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<PathBlock
|
||||
onConvert={() =>
|
||||
onChange(polygonReplacement(offer.frames[annotation.view_id]))
|
||||
}
|
||||
/>
|
||||
<PathBlock />
|
||||
)}
|
||||
{messages && messages.length > 0 && (
|
||||
<ul
|
||||
@@ -214,16 +206,11 @@ function RepairRow({
|
||||
)
|
||||
}
|
||||
|
||||
function PathBlock({ onConvert }: { onConvert: () => void }) {
|
||||
function PathBlock() {
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.views.repair.path_blocked')}
|
||||
</p>
|
||||
<Button type="button" variant="secondary" size="sm" onClick={onConvert}>
|
||||
{t('editor.annotations.replace_polygon')}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.views.repair.path_blocked')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
@@ -13,12 +13,7 @@ import {
|
||||
type CommitContext,
|
||||
} from './annotations/annotationCommit'
|
||||
import { isEditable } from './annotations/geometryEdit'
|
||||
import {
|
||||
centreTriangle,
|
||||
correctedCircle,
|
||||
parseFrame,
|
||||
type Frame,
|
||||
} from './annotations/frame'
|
||||
import { correctedCircle, parseFrame, type Frame } from './annotations/frame'
|
||||
import {
|
||||
geometryAccept,
|
||||
rejectedDrawingFault,
|
||||
@@ -60,7 +55,7 @@ function clampedVertex(frame: Frame, [x, y]: Point): Point {
|
||||
/**
|
||||
* A proposal in the new frame: a point goes through the creation arithmetic (candidate
|
||||
* C), a polygon gets each vertex clamped into the frame. A path has no numbers to move:
|
||||
* it is returned as it is, and the user converts it.
|
||||
* it is returned as it is and blocks the attach (owner decision, R25).
|
||||
*/
|
||||
export function proposeGeometry(frame: Frame, geometry: Geometry): Geometry {
|
||||
if (geometry.type === 'circle') {
|
||||
@@ -74,11 +69,6 @@ export function proposeGeometry(frame: Frame, geometry: Geometry): Geometry {
|
||||
return geometry
|
||||
}
|
||||
|
||||
/** « Remplacer par un polygone » inside the temporary form: a triangle to edit. */
|
||||
export function polygonReplacement(frame: Frame): Geometry {
|
||||
return { type: 'polygon', points: centreTriangle(frame) }
|
||||
}
|
||||
|
||||
/** The annotations the refusal lists, in document order. */
|
||||
export function listedAnnotations(
|
||||
offer: RepairOffer,
|
||||
|
||||
@@ -1394,7 +1394,8 @@ export const en: Dict = {
|
||||
'editor.views.repair.body_one': '{count} annotation falls outside the new frame of this drawing. The proposed values are computed in that frame. Nothing is applied before "Attach and apply": the drawing and the new values are then applied together, and a single Undo restores them together.',
|
||||
'editor.views.repair.body_other': '{count} annotations fall outside the new frame of this drawing. The proposed values are computed in that frame. Nothing is applied before "Attach and apply": the drawing and the new values are then applied together, and a single Undo restores them together.',
|
||||
'editor.views.repair.row': '{kind} "{name}"',
|
||||
'editor.views.repair.path_blocked': 'This path has no coordinates to correct here. Replace it with a polygon to be able to attach the drawing.',
|
||||
'editor.views.repair.path_blocked':
|
||||
"This free path is kept as it is. The drawing cannot be attached while it falls outside the new frame: the editor cannot yet correct the points of a free path.",
|
||||
'editor.views.repair.refused': 'Nothing was applied: the document check refuses these values.',
|
||||
'editor.views.repair.more_outside': 'Other elements would also fall outside the new frame: {names}. Nothing was applied. Cancel, fix them, then choose the drawing again.',
|
||||
'editor.views.repair.not_measurable': 'With this drawing, a view holding annotations would not be measurable. Nothing was applied.',
|
||||
@@ -1453,7 +1454,11 @@ export const en: Dict = {
|
||||
'editor.findings.kind.consultation_reason': 'Reason for consultation',
|
||||
'editor.findings.kind.anamnesis': 'Anamnesis',
|
||||
'editor.findings.kind.custom': 'Custom',
|
||||
'editor.findings.required': 'Fill in the name in French and English (and the type of a category).',
|
||||
'editor.findings.required':
|
||||
"Fill in the name in French and in English (and the zone and the type of a category).",
|
||||
'editor.findings.zone': "Zone",
|
||||
'editor.findings.add_category_no_zone':
|
||||
"Create a zone first to add a category.",
|
||||
'editor.findings.create': 'Create',
|
||||
'editor.findings.cancel': 'Cancel',
|
||||
'editor.findings.empty': 'No findings zone yet.',
|
||||
|
||||
@@ -1425,7 +1425,8 @@ export const fr: Dict = {
|
||||
'editor.views.repair.body_one': "{count} annotation sort du nouveau cadre de cette illustration. Les valeurs proposées sont calculées dans ce cadre. Rien n'est appliqué avant « Attacher et appliquer » : l'illustration et les nouvelles valeurs sont alors appliquées ensemble, et un seul Annuler les restaure ensemble.",
|
||||
'editor.views.repair.body_other': "{count} annotations sortent du nouveau cadre de cette illustration. Les valeurs proposées sont calculées dans ce cadre. Rien n'est appliqué avant « Attacher et appliquer » : l'illustration et les nouvelles valeurs sont alors appliquées ensemble, et un seul Annuler les restaure ensemble.",
|
||||
'editor.views.repair.row': '{kind} « {name} »',
|
||||
'editor.views.repair.path_blocked': "Ce tracé n'a pas de coordonnées à corriger ici. Remplacez-le par un polygone pour pouvoir attacher l'illustration.",
|
||||
'editor.views.repair.path_blocked':
|
||||
"Ce tracé libre est conservé tel quel. L'illustration ne peut pas être attachée tant qu'il sort du nouveau cadre : l'éditeur ne sait pas encore corriger les points d'un tracé libre.",
|
||||
'editor.views.repair.refused': "Rien n'a été appliqué : le contrôle du document refuse ces valeurs.",
|
||||
'editor.views.repair.more_outside': "D'autres éléments sortiraient aussi du nouveau cadre : {names}. Rien n'a été appliqué. Annulez, corrigez-les, puis choisissez de nouveau l'illustration.",
|
||||
'editor.views.repair.not_measurable': "Avec cette illustration, une vue qui porte des annotations ne serait pas mesurable. Rien n'a été appliqué.",
|
||||
@@ -1484,7 +1485,11 @@ export const fr: Dict = {
|
||||
'editor.findings.kind.consultation_reason': 'Motif de consultation',
|
||||
'editor.findings.kind.anamnesis': 'Anamnèse',
|
||||
'editor.findings.kind.custom': 'Personnalisée',
|
||||
'editor.findings.required': "Renseignez le nom en français et en anglais (et le type d'une catégorie).",
|
||||
'editor.findings.required':
|
||||
"Renseignez le nom en français et en anglais (et la zone et le type d'une catégorie).",
|
||||
'editor.findings.zone': "Zone",
|
||||
'editor.findings.add_category_no_zone':
|
||||
"Créez d'abord une zone pour ajouter une catégorie.",
|
||||
'editor.findings.create': 'Créer',
|
||||
'editor.findings.cancel': 'Annuler',
|
||||
'editor.findings.empty': "Aucune zone de constats pour l'instant.",
|
||||
|
||||
@@ -253,6 +253,9 @@ describe('Constats tab', () => {
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Créer' }))
|
||||
expect(screen.getByRole('alert')).toBeInTheDocument()
|
||||
await user.selectOptions(screen.getByLabelText('Zone'), 'zone-a')
|
||||
await user.click(screen.getByRole('button', { name: 'Créer' }))
|
||||
expect(screen.getByRole('alert')).toBeInTheDocument()
|
||||
await user.selectOptions(
|
||||
screen.getByLabelText('Type de catégorie'),
|
||||
'anamnesis',
|
||||
@@ -277,19 +280,7 @@ describe('Constats tab', () => {
|
||||
expect(doc().finding_zones[0].categories[1].children).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('names the zone a category lands in and appends it at zone level, a node selected', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
items()[0].focus()
|
||||
await user.keyboard('{ArrowDown}{ArrowRight}{ArrowRight}')
|
||||
expect(items()[2]).toHaveAttribute('aria-selected', 'true')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
expect(
|
||||
screen.getByText('Nouvelle catégorie dans la zone « Zone A »'),
|
||||
).toBeInTheDocument()
|
||||
async function fillCategory(user: ReturnType<typeof userEvent.setup>) {
|
||||
await user.type(
|
||||
screen.getByLabelText('Nom (FR)', { selector: '#finding-new-name-fr' }),
|
||||
'Nouv',
|
||||
@@ -302,10 +293,86 @@ describe('Constats tab', () => {
|
||||
screen.getByLabelText('Type de catégorie'),
|
||||
'anamnesis',
|
||||
)
|
||||
}
|
||||
|
||||
it('lands in the zone chosen in the form, not the zone of the selected node (C46)', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
items()[0].focus()
|
||||
await user.keyboard('{ArrowDown}{ArrowRight}{ArrowRight}')
|
||||
expect(items()[2]).toHaveAttribute('aria-selected', 'true')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
expect(screen.getByLabelText('Zone')).toHaveValue('')
|
||||
await user.selectOptions(screen.getByLabelText('Zone'), 'zone-b')
|
||||
expect(
|
||||
screen.getByText('Nouvelle catégorie dans la zone « Zone B »'),
|
||||
).toBeInTheDocument()
|
||||
await fillCategory(user)
|
||||
await user.click(screen.getByRole('button', { name: 'Créer' }))
|
||||
const categories = doc().finding_zones[0].categories
|
||||
expect(categories.map((c) => c.id)).toEqual(['fcat-a', expect.any(String)])
|
||||
expect(categories[0].children[0].children).toHaveLength(1)
|
||||
expect(doc().finding_zones[1].categories).toHaveLength(1)
|
||||
expect(doc().finding_zones[1].categories[0].kind).toBe('anamnesis')
|
||||
expect(doc().finding_zones[0].categories.map((c) => c.id)).toEqual([
|
||||
'fcat-a',
|
||||
])
|
||||
})
|
||||
|
||||
it('appends the category after the existing ones of the chosen zone', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
await user.selectOptions(screen.getByLabelText('Zone'), 'zone-a')
|
||||
await fillCategory(user)
|
||||
await user.click(screen.getByRole('button', { name: 'Créer' }))
|
||||
const ids = doc().finding_zones[0].categories.map((c) => c.id)
|
||||
expect(ids).toEqual(['fcat-a', expect.any(String)])
|
||||
})
|
||||
|
||||
it('is enabled with nothing selected and preselects nothing among several zones', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
const add = screen.getByRole('button', { name: 'Ajouter une catégorie' })
|
||||
expect(add).toBeEnabled()
|
||||
await user.click(items()[2])
|
||||
await user.click(add)
|
||||
expect(screen.getByLabelText('Zone')).toHaveValue('')
|
||||
})
|
||||
|
||||
it('preselects the zone when exactly one exists', async () => {
|
||||
const text = edit(baseText(), {
|
||||
op: 'insert',
|
||||
element: {
|
||||
kind: 'zone',
|
||||
value: { id: 'zone-a', name: name('Zone A'), categories: [] },
|
||||
},
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
expect(screen.getByLabelText('Zone')).toHaveValue('zone-a')
|
||||
expect(
|
||||
screen.getByText('Nouvelle catégorie dans la zone « Zone A »'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('is disabled with its hint while no zone exists', async () => {
|
||||
await openReady()
|
||||
render(<FindingsTab {...props} />)
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
).toBeDisabled()
|
||||
expect(
|
||||
screen.getByText("Créez d'abord une zone pour ajouter une catégorie."),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('disables « Ajouter un constat » on a zone and at depth 8', async () => {
|
||||
@@ -529,35 +596,20 @@ describe('Constats tab', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the category form title (N1 review)', () => {
|
||||
const parentOf = (id: string) => {
|
||||
const found = buildItems(doc()).find((item) => item.id.includes(`"${id}"`) && item.path.at(-1) === id || item.zoneId === id && item.kind === 'zone')
|
||||
if (!found) throw new Error(`no ${id}`)
|
||||
return found
|
||||
}
|
||||
const title = (parent: ReturnType<typeof parentOf> | null) => {
|
||||
describe('the category form title (N1 review, C46)', () => {
|
||||
it('names the chosen zone, and falls back to an existing label before the choice', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<FindingCreateForm
|
||||
pending={{ kind: 'category', parent }}
|
||||
pending={{ kind: 'category', parent: null }}
|
||||
onCreated={vi.fn()}
|
||||
onCancel={vi.fn()}
|
||||
/>,
|
||||
)
|
||||
return document.querySelector('p.font-medium')?.textContent
|
||||
}
|
||||
|
||||
it.each(['zone-a', 'fcat-a', 'node-a'])(
|
||||
'names the zone when the parent is %s',
|
||||
async (id) => {
|
||||
await openReady({ text: treeText() })
|
||||
expect(title(parentOf(id))).toBe(
|
||||
'Nouvelle catégorie dans la zone « Zone A »',
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
it('falls back to an existing label, never a missing key, without a parent', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
expect(title(null)).toBe('Ajouter une catégorie')
|
||||
const title = () => document.querySelector('p.font-medium')?.textContent
|
||||
expect(title()).toBe('Ajouter une catégorie')
|
||||
await user.selectOptions(screen.getByLabelText('Zone'), 'zone-a')
|
||||
expect(title()).toBe('Nouvelle catégorie dans la zone « Zone A »')
|
||||
})
|
||||
})
|
||||
@@ -16,11 +16,7 @@ import type {
|
||||
import ViewsTab from '@/components/editor/tabs/ViewsTab'
|
||||
import { cleanSvg } from '@/editor/core/cleaning'
|
||||
import { attachToView } from '@/editor/drawingUpload'
|
||||
import {
|
||||
applyRepair,
|
||||
polygonReplacement,
|
||||
proposeGeometry,
|
||||
} from '@/editor/repair'
|
||||
import { applyRepair, proposeGeometry } from '@/editor/repair'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { getDict } from '@/i18n'
|
||||
import { emptyText, insert, point, svgBytes } from '../helpers/editorFixtures'
|
||||
@@ -125,13 +121,9 @@ describe('proposals (UI arithmetic in the new frame)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('leaves a path to the conversion, which offers a triangle in the frame', () => {
|
||||
it('returns a path as it is: its points are never reshaped', () => {
|
||||
const path: Geometry = { type: 'path', d: 'M 1 1 L 5 5 Z' }
|
||||
expect(proposeGeometry(frame, path)).toBe(path)
|
||||
expect(polygonReplacement(frame)).toMatchObject({
|
||||
type: 'polygon',
|
||||
points: expect.arrayContaining([expect.any(Array)]),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -222,6 +214,30 @@ describe('applyRepair', () => {
|
||||
expect(store.getState().undo).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('never rewrites a free path: its d is kept and the batch is refused', async () => {
|
||||
const pathValue = {
|
||||
...(point('anno-p', 0, 0, 1).value as Annotation),
|
||||
kind: 'zone' as const,
|
||||
geometry: { type: 'path' as const, d: COMPLEX_PATH },
|
||||
} as Annotation
|
||||
await openReady({ text: unmeasuredText([pathValue]) })
|
||||
await holdNewDrawing()
|
||||
const before = store.getState().documentText
|
||||
const offer = offerOf()
|
||||
expect(offer.refusal.annotationIds).toContain('anno-p')
|
||||
const geometries = {
|
||||
...proposals(offer),
|
||||
'anno-p': proposeGeometry(
|
||||
offer.frames['view-main'],
|
||||
annotation('anno-p').geometry as Geometry,
|
||||
),
|
||||
}
|
||||
expect(geometries['anno-p']).toEqual({ type: 'path', d: COMPLEX_PATH })
|
||||
expect(applyRepair(offer, geometries, context)).toMatchObject({ ok: false })
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
expect(store.getState().undo).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('is blocked while a recovery offer is pending', async () => {
|
||||
await openReady({ text: unmeasuredText() })
|
||||
await holdNewDrawing()
|
||||
@@ -274,6 +290,10 @@ function serverGets(text: string) {
|
||||
const SVG =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect width="4" height="4"/></svg>'
|
||||
|
||||
const COMPLEX_PATH =
|
||||
'M 300 300 l 40 0 C 350 320 380 360 400 400 q 20 -30 -40 -50 ' +
|
||||
'A 30 20 0 0 1 320 330 H 310 V 305 Z'
|
||||
|
||||
async function pickAndOpenDialog(text = unmeasuredText()) {
|
||||
await openReady({ text })
|
||||
serverGets(SVG)
|
||||
@@ -363,15 +383,17 @@ describe('the repair dialog', () => {
|
||||
expect(screen.queryByText(/Déplacez d'abord/)).toBeNull()
|
||||
})
|
||||
|
||||
it('blocks a path until it is replaced by a polygon, inside the same form', async () => {
|
||||
it('blocks a free path with its reason, no conversion, and cancel keeps everything', async () => {
|
||||
const pathValue = {
|
||||
...(point('anno-p', 0, 0, 1).value as Annotation),
|
||||
kind: 'zone' as const,
|
||||
geometry: { type: 'path' as const, d: 'M 300 300 L 400 300 L 350 400 Z' },
|
||||
geometry: { type: 'path' as const, d: COMPLEX_PATH },
|
||||
} as Annotation
|
||||
const { user, dialog } = await pickAndOpenDialog(
|
||||
unmeasuredText([pathValue]),
|
||||
)
|
||||
const before = store.getState().documentText
|
||||
const undoLength = store.getState().undo.length
|
||||
const apply = within(dialog).getByRole('button', {
|
||||
name: t('editor.views.repair.apply'),
|
||||
})
|
||||
@@ -380,15 +402,22 @@ describe('the repair dialog', () => {
|
||||
expect(
|
||||
within(row).getByText(t('editor.views.repair.path_blocked')),
|
||||
).toBeTruthy()
|
||||
expect(within(row).queryByRole('button')).toBeNull()
|
||||
expect(within(dialog).queryByText(/polygone/i)).toBeNull()
|
||||
await user.click(apply)
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
await user.click(
|
||||
within(row).getByRole('button', {
|
||||
name: t('editor.annotations.replace_polygon'),
|
||||
within(dialog).getByRole('button', {
|
||||
name: t('editor.views.repair.cancel'),
|
||||
}),
|
||||
)
|
||||
expect(apply).toBeEnabled()
|
||||
await user.click(apply)
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
expect(annotation('anno-p').geometry).toMatchObject({ type: 'polygon' })
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
expect(store.getState().undo).toHaveLength(undoLength)
|
||||
expect(annotation('anno-p').geometry).toEqual({
|
||||
type: 'path',
|
||||
d: COMPLEX_PATH,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user