fix(editor): views requests never run late, refusals announced
This commit is contained in:
1 parent
9aa791db24
commit
9c7cbeaf13
8 files changed
+86
-11
No files matched your search
@@ -178,6 +178,11 @@ async function createAnnotations(page: Page) {
|
|||||||
.selectOption({ label: 'Zone essai' })
|
.selectOption({ label: 'Zone essai' })
|
||||||
await createFromPanel(page, dict)
|
await createFromPanel(page, dict)
|
||||||
await toolButton(page, dict, 'link').click()
|
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([
|
await trace([
|
||||||
[30, 94],
|
[30, 94],
|
||||||
[70, 94],
|
[70, 94],
|
||||||
|
|||||||
@@ -262,7 +262,12 @@ export default function EditableAnnotations(props: Props) {
|
|||||||
const work = useWork(scene)
|
const work = useWork(scene)
|
||||||
const { ui, selected } = scene
|
const { ui, selected } = scene
|
||||||
const visible = usePlaceVisible()
|
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 framing = useAnnotationWork((s) => s.frame !== null)
|
||||||
const { asideRef, byDrawing } = useSelectionEscape(
|
const { asideRef, byDrawing } = useSelectionEscape(
|
||||||
selected?.id ?? null,
|
selected?.id ?? null,
|
||||||
|
|||||||
@@ -29,7 +29,10 @@ export default function AnnotationSection({
|
|||||||
const { titleKey, Body } = ANNOTATION_SECTION_BODIES[section]
|
const { titleKey, Body } = ANNOTATION_SECTION_BODIES[section]
|
||||||
const headingId = `annotation-section-${section}-title`
|
const headingId = `annotation-section-${section}-title`
|
||||||
return (
|
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}>
|
<Button type="button" variant="secondary" size="sm" onClick={onBack}>
|
||||||
{t('editor.section.back')}
|
{t('editor.section.back')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { DetailView, SheetView } from '@faunosteo/core-wasm/types'
|
import type { DetailView, SheetView } from '@faunosteo/core-wasm/types'
|
||||||
import ActionButton from '@/components/editor/fields/ActionButton'
|
import ActionButton from '@/components/editor/fields/ActionButton'
|
||||||
|
import Notice from '@/components/ui/Notice'
|
||||||
import SelectField from '@/components/editor/fields/SelectField'
|
import SelectField from '@/components/editor/fields/SelectField'
|
||||||
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
import { FOCUS_CLASS, focusAttrs } from '@/editor/focusRequest'
|
||||||
import { useViewUpdate } from '@/editor/useViewUpdate'
|
import { useViewUpdate } from '@/editor/useViewUpdate'
|
||||||
@@ -66,7 +67,8 @@ export default function DetailViewRow({
|
|||||||
</div>
|
</div>
|
||||||
<ViewDrawing view={view} readOnly={readOnly} />
|
<ViewDrawing view={view} readOnly={readOnly} />
|
||||||
{missingAccess && (
|
{missingAccess && (
|
||||||
<div className="flex flex-wrap items-center gap-3 rounded-lg bg-[var(--color-surface-strong)] p-3 text-sm">
|
<Notice tone="warning" live={false}>
|
||||||
|
<div className="flex flex-wrap items-center gap-3">
|
||||||
<p>
|
<p>
|
||||||
{t('editor.views.no_access').replace(
|
{t('editor.views.no_access').replace(
|
||||||
'{name}',
|
'{name}',
|
||||||
@@ -84,6 +86,7 @@ export default function DetailViewRow({
|
|||||||
{t('editor.views.add_access')}
|
{t('editor.views.add_access')}
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
</div>
|
</div>
|
||||||
|
</Notice>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
{onRecrop && view.svg_asset_id === null && (
|
{onRecrop && view.svg_asset_id === null && (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { placeAtCentre } from './usePlacement'
|
import { placeAtCentre } from './usePlacement'
|
||||||
|
import { useAnnotationWork } from './workStore'
|
||||||
import type { Scene } from '@/components/editor/annotations/EditableAnnotations'
|
import type { Scene } from '@/components/editor/annotations/EditableAnnotations'
|
||||||
import {
|
import {
|
||||||
clearViewsRequest,
|
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
|
* the default rectangle once the drawing is measured. Each step ends the effect; the
|
||||||
* next render runs the next one.
|
* 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
|
const { dispatch, viewId, frame, model } = scene
|
||||||
if (viewId !== request.parentId) {
|
if (viewId !== request.parentId) {
|
||||||
return dispatch({ type: 'view', 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
|
if (!frame || !model.measured) return
|
||||||
clearViewsRequest()
|
clearViewsRequest()
|
||||||
placeAtCentre(scene, 'detail_trigger', 'add')
|
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
|
* 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)
|
const request = useViewsRequest((s) => s.request)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!request || !visible) return
|
if (!request) return
|
||||||
const { parentId: parent } = request
|
const { parentId: parent } = request
|
||||||
const known = (id: string) => scene.doc.views.some((view) => view.id === id)
|
const gone =
|
||||||
if (parent !== null && !known(parent)) return clearViewsRequest()
|
parent !== null && !scene.doc.views.some((view) => view.id === parent)
|
||||||
if (request.kind === 'access') return accessStep(scene, request)
|
if (!visible || gone) return clearViewsRequest()
|
||||||
|
if (request.kind === 'access') return accessStep(scene, request, refuse)
|
||||||
clearViewsRequest()
|
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.precise': 'Precise values',
|
||||||
'editor.views.no_access': 'No access on “{name}”',
|
'editor.views.no_access': 'No access on “{name}”',
|
||||||
'editor.views.add_access': 'Add the access',
|
'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_x': 'Crop: minimum x',
|
||||||
'editor.views.crop.min_y': 'Crop: minimum y',
|
'editor.views.crop.min_y': 'Crop: minimum y',
|
||||||
'editor.views.crop.width': 'Crop: width',
|
'editor.views.crop.width': 'Crop: width',
|
||||||
|
|||||||
@@ -1703,6 +1703,8 @@ export const fr: Dict = {
|
|||||||
'editor.views.precise': 'Valeurs précises',
|
'editor.views.precise': 'Valeurs précises',
|
||||||
'editor.views.no_access': 'Aucun accès sur « {name} »',
|
'editor.views.no_access': 'Aucun accès sur « {name} »',
|
||||||
'editor.views.add_access': "Ajouter l'accès",
|
'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_x': 'Recadrage : x minimum',
|
||||||
'editor.views.crop.min_y': 'Recadrage : y minimum',
|
'editor.views.crop.min_y': 'Recadrage : y minimum',
|
||||||
'editor.views.crop.width': 'Recadrage : largeur',
|
'editor.views.crop.width': 'Recadrage : largeur',
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { createHash } from 'node:crypto'
|
import { createHash } from 'node:crypto'
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import {
|
import {
|
||||||
|
act,
|
||||||
cleanup,
|
cleanup,
|
||||||
render,
|
render,
|
||||||
screen,
|
screen,
|
||||||
@@ -23,8 +24,10 @@ import { AnnounceContext } from '@/editor/focusRequest'
|
|||||||
import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
||||||
import {
|
import {
|
||||||
clearViewsRequest,
|
clearViewsRequest,
|
||||||
|
requestViews,
|
||||||
useViewsRequest,
|
useViewsRequest,
|
||||||
} from '@/editor/annotations/viewsRequest'
|
} from '@/editor/annotations/viewsRequest'
|
||||||
|
import { emptyForm } from '@/editor/annotations/creation'
|
||||||
import { resetWork, useAnnotationWork } from '@/editor/annotations/workStore'
|
import { resetWork, useAnnotationWork } from '@/editor/annotations/workStore'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import {
|
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 »', () => {
|
describe('« Valeurs précises » and « Recadrer sur le dessin »', () => {
|
||||||
it('the four fields stay folded until the disclosure opens', async () => {
|
it('the four fields stay folded until the disclosure opens', async () => {
|
||||||
await openReady({ text: insert(emptyText(), detail()) })
|
await openReady({ text: insert(emptyText(), detail()) })
|
||||||
|
|||||||
Reference in new issue
Block a user