fix(editor): views requests never run late, refusals announced
This commit is contained in:
1 parent
9aa791db24
commit
9c7cbeaf13
8 files changed
+103
-28
No files matched your search
@@ -178,6 +178,11 @@ async function createAnnotations(page: Page) {
|
||||
.selectOption({ label: 'Zone essai' })
|
||||
await createFromPanel(page, dict)
|
||||
await toolButton(page, dict, 'link').click()
|
||||
// The access tool defaults to the rectangle (D5): the polygon is chosen to trace one.
|
||||
await page
|
||||
.getByTestId('access-shape')
|
||||
.getByText(dict['editor.annotations.shape.polygon'], { exact: true })
|
||||
.click()
|
||||
await trace([
|
||||
[30, 94],
|
||||
[70, 94],
|
||||
|
||||
@@ -262,7 +262,12 @@ export default function EditableAnnotations(props: Props) {
|
||||
const work = useWork(scene)
|
||||
const { ui, selected } = scene
|
||||
const visible = usePlaceVisible()
|
||||
useViewsRequestRun(scene, visible)
|
||||
useViewsRequestRun(scene, visible, () =>
|
||||
work.message.show(work.context.t('editor.views.request_busy'), {
|
||||
undo: false,
|
||||
tone: 'info',
|
||||
}),
|
||||
)
|
||||
const framing = useAnnotationWork((s) => s.frame !== null)
|
||||
const { asideRef, byDrawing } = useSelectionEscape(
|
||||
selected?.id ?? null,
|
||||
|
||||
@@ -29,7 +29,10 @@ export default function AnnotationSection({
|
||||
const { titleKey, Body } = ANNOTATION_SECTION_BODIES[section]
|
||||
const headingId = `annotation-section-${section}-title`
|
||||
return (
|
||||
<section aria-labelledby={headingId} className="space-y-4">
|
||||
<section
|
||||
aria-labelledby={headingId}
|
||||
className="space-y-4"
|
||||
>
|
||||
<Button type="button" variant="secondary" size="sm" onClick={onBack}>
|
||||
{t('editor.section.back')}
|
||||
</Button>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { DetailView, SheetView } from '@faunosteo/core-wasm/types'
|
||||
import ActionButton from '@/components/editor/fields/ActionButton'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import SelectField from '@/components/editor/fields/SelectField'
|
||||
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
||||
import { useViewUpdate } from '@/editor/useViewUpdate'
|
||||
@@ -66,24 +67,26 @@ export default function DetailViewRow({
|
||||
</div>
|
||||
<ViewDrawing view={view} readOnly={readOnly} />
|
||||
{missingAccess && (
|
||||
<div className="flex flex-wrap items-center gap-3 rounded-lg bg-[var(--color-surface-strong)] p-3 text-sm">
|
||||
<p>
|
||||
{t('editor.views.no_access').replace(
|
||||
'{name}',
|
||||
() =>
|
||||
parents.find((p) => p.value === view.parent_view_id)?.label ??
|
||||
'',
|
||||
)}
|
||||
</p>
|
||||
<ActionButton
|
||||
readOnly={readOnly}
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={onAddAccess}
|
||||
>
|
||||
{t('editor.views.add_access')}
|
||||
</ActionButton>
|
||||
</div>
|
||||
<Notice tone="warning" live={false}>
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<p>
|
||||
{t('editor.views.no_access').replace(
|
||||
'{name}',
|
||||
() =>
|
||||
parents.find((p) => p.value === view.parent_view_id)?.label ??
|
||||
'',
|
||||
)}
|
||||
</p>
|
||||
<ActionButton
|
||||
readOnly={readOnly}
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={onAddAccess}
|
||||
>
|
||||
{t('editor.views.add_access')}
|
||||
</ActionButton>
|
||||
</div>
|
||||
</Notice>
|
||||
)}
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{onRecrop && view.svg_asset_id === null && (
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect } from 'react'
|
||||
import { placeAtCentre } from './usePlacement'
|
||||
import { useAnnotationWork } from './workStore'
|
||||
import type { Scene } from '@/components/editor/annotations/EditableAnnotations'
|
||||
import {
|
||||
clearViewsRequest,
|
||||
@@ -21,7 +22,11 @@ function armed(scene: Scene, viewId: string): boolean {
|
||||
* the default rectangle once the drawing is measured. Each step ends the effect; the
|
||||
* next render runs the next one.
|
||||
*/
|
||||
function accessStep(scene: Scene, request: ViewsRequest & { kind: 'access' }) {
|
||||
function accessStep(
|
||||
scene: Scene,
|
||||
request: ViewsRequest & { kind: 'access' },
|
||||
refuse: () => void,
|
||||
) {
|
||||
const { dispatch, viewId, frame, model } = scene
|
||||
if (viewId !== request.parentId) {
|
||||
return dispatch({ type: 'view', viewId: request.parentId })
|
||||
@@ -34,21 +39,30 @@ function accessStep(scene: Scene, request: ViewsRequest & { kind: 'access' }) {
|
||||
if (!frame || !model.measured) return
|
||||
clearViewsRequest()
|
||||
placeAtCentre(scene, 'detail_trigger', 'add')
|
||||
if (useAnnotationWork.getState().creation === null) refuse()
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the views section's request once the drawing is shown: the frame creation, or the
|
||||
* access placement. A request whose view is gone is dropped.
|
||||
* access placement. A request that cannot run now (the drawing is hidden, its view is
|
||||
* gone) is dropped, never kept for a later visit; one the work in progress refuses is
|
||||
* told through `refuse`.
|
||||
*/
|
||||
export function useViewsRequestRun(scene: Scene, visible: boolean): void {
|
||||
export function useViewsRequestRun(
|
||||
scene: Scene,
|
||||
visible: boolean,
|
||||
refuse: () => void,
|
||||
): void {
|
||||
const request = useViewsRequest((s) => s.request)
|
||||
useEffect(() => {
|
||||
if (!request || !visible) return
|
||||
if (!request) return
|
||||
const { parentId: parent } = request
|
||||
const known = (id: string) => scene.doc.views.some((view) => view.id === id)
|
||||
if (parent !== null && !known(parent)) return clearViewsRequest()
|
||||
if (request.kind === 'access') return accessStep(scene, request)
|
||||
const gone =
|
||||
parent !== null && !scene.doc.views.some((view) => view.id === parent)
|
||||
if (!visible || gone) return clearViewsRequest()
|
||||
if (request.kind === 'access') return accessStep(scene, request, refuse)
|
||||
clearViewsRequest()
|
||||
startDetailView(parent ?? scene.viewId, scene.viewId, scene.dispatch)
|
||||
const shown = scene.viewId
|
||||
if (!startDetailView(parent ?? shown, shown, scene.dispatch)) refuse()
|
||||
})
|
||||
}
|
||||
@@ -1640,6 +1640,8 @@ export const en: Dict = {
|
||||
'editor.views.precise': 'Precise values',
|
||||
'editor.views.no_access': 'No access on “{name}”',
|
||||
'editor.views.add_access': 'Add the access',
|
||||
'editor.views.request_busy':
|
||||
'Finish or abandon the work in progress before starting.',
|
||||
'editor.views.crop.min_x': 'Crop: minimum x',
|
||||
'editor.views.crop.min_y': 'Crop: minimum y',
|
||||
'editor.views.crop.width': 'Crop: width',
|
||||
|
||||
@@ -1703,6 +1703,8 @@ export const fr: Dict = {
|
||||
'editor.views.precise': 'Valeurs précises',
|
||||
'editor.views.no_access': 'Aucun accès sur « {name} »',
|
||||
'editor.views.add_access': "Ajouter l'accès",
|
||||
'editor.views.request_busy':
|
||||
'Terminez ou abandonnez le travail en cours avant de commencer.',
|
||||
'editor.views.crop.min_x': 'Recadrage : x minimum',
|
||||
'editor.views.crop.min_y': 'Recadrage : y minimum',
|
||||
'editor.views.crop.width': 'Recadrage : largeur',
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { createHash } from 'node:crypto'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
render,
|
||||
screen,
|
||||
@@ -23,8 +24,10 @@ import { AnnounceContext } from '@/editor/focusRequest'
|
||||
import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
||||
import {
|
||||
clearViewsRequest,
|
||||
requestViews,
|
||||
useViewsRequest,
|
||||
} from '@/editor/annotations/viewsRequest'
|
||||
import { emptyForm } from '@/editor/annotations/creation'
|
||||
import { resetWork, useAnnotationWork } from '@/editor/annotations/workStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import {
|
||||
@@ -509,6 +512,44 @@ describe('« Gérer les vues » follows the new journey', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('requests the drawing cannot run', () => {
|
||||
it('a request made while the drawing is hidden is dropped, not kept for a later visit', async () => {
|
||||
const user = await openViews()
|
||||
act(() => requestViews({ kind: 'create', parentId: null }))
|
||||
await waitFor(() => expect(useViewsRequest.getState().request).toBeNull())
|
||||
await user.click(screen.getByRole('button', { name: 'Retour au dessin' }))
|
||||
expect(frame()).toBeNull()
|
||||
})
|
||||
|
||||
it('work in progress refuses the creation and the person is told', async () => {
|
||||
const user = await openViews()
|
||||
useAnnotationWork.setState({
|
||||
creation: {
|
||||
viewId: 'view-main',
|
||||
frame: null,
|
||||
origin: 'add',
|
||||
pending: {
|
||||
kind: 'point',
|
||||
geometry: { type: 'circle', cx: 5, cy: 5, r: 2 },
|
||||
},
|
||||
closed: true,
|
||||
form: emptyForm(doc(), 'point'),
|
||||
dialog: false,
|
||||
resumed: false,
|
||||
},
|
||||
})
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Tracer sur le dessin' }),
|
||||
)
|
||||
expect(
|
||||
await screen.findByText(
|
||||
'Terminez ou abandonnez le travail en cours avant de commencer.',
|
||||
),
|
||||
).toBeTruthy()
|
||||
expect(frame()).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Valeurs précises » and « Recadrer sur le dessin »', () => {
|
||||
it('the four fields stay folded until the disclosure opens', async () => {
|
||||
await openReady({ text: insert(emptyText(), detail()) })
|
||||
|
||||
Reference in new issue
Block a user