feat(app): access labels on the editor, the catalogue and the bilan
This commit is contained in:
1 parent
0100e2e63d
commit
e064a4eed0
8 files changed
+283
-3
No files matched your search
@@ -154,6 +154,7 @@ function LoadedSheet({ versions, version, preview, state }: LoadedSheetProps) {
|
||||
detail={view.kind === 'detail'}
|
||||
selectedId={selectedId}
|
||||
onAnnotation={onAnnotation}
|
||||
onAccess={setViewId}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import AccessLabels from './AccessLabels'
|
||||
|
||||
export interface AnatomyCanvasProps {
|
||||
index: SheetIndex
|
||||
@@ -53,6 +54,8 @@ export default function AnatomyCanvas({
|
||||
// Each retry builds again; a failed build leaves the canvas empty behind the notice.
|
||||
const [attempt, setAttempt] = useState(0)
|
||||
const [failure, setFailure] = useState<ViewFailure | null>(null)
|
||||
// Bumped after each svg rebuild: the labels measure the drawing as rebuilt.
|
||||
const [built, setBuilt] = useState(0)
|
||||
// Derived at render: an engine failure shown while the engine stops becomes the stopped text.
|
||||
const stopped = useCoreStopped()
|
||||
const unsaved = useReportStore(isUnsaved)
|
||||
@@ -71,6 +74,7 @@ export default function AnatomyCanvas({
|
||||
const build = buildViewSvg(index, viewId)
|
||||
setFailure(build.ok ? null : build.failure)
|
||||
host.replaceChildren(...(build.ok ? [build.svg] : []))
|
||||
setBuilt((n) => n + 1)
|
||||
}, [index, viewId, attempt])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -152,6 +156,13 @@ export default function AnatomyCanvas({
|
||||
className={`w-full h-full [&>svg]:max-w-full [&>svg]:max-h-full [&>svg]:mx-auto ${detail ? BAND_BACKGROUND : ''}`}
|
||||
/>
|
||||
<div ref={tooltipRef} className="zone-tooltip" style={{ opacity: 0 }} />
|
||||
<AccessLabels
|
||||
box={wrapperRef}
|
||||
drawing={svgRef}
|
||||
layoutKey={`${viewId}:${built}`}
|
||||
hidden={failure !== null}
|
||||
onActivate={(accessId) => onZoneClick(accessId, viewId)}
|
||||
/>
|
||||
{failure && (
|
||||
<div className="absolute inset-0 grid place-items-center p-4">
|
||||
<div className="space-y-3 max-w-sm">
|
||||
|
||||
@@ -11,6 +11,7 @@ import { transformOf } from '@/catalogue/framing'
|
||||
import { useEmptyTap } from '@/catalogue/useEmptyTap'
|
||||
import { useFraming } from '@/catalogue/useFraming'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import AccessLabels from '@/components/canvas/AccessLabels'
|
||||
|
||||
export interface CatalogueCanvasProps {
|
||||
preview: CataloguePreview
|
||||
@@ -22,6 +23,8 @@ export interface CatalogueCanvasProps {
|
||||
onAnnotation: (annotationId: string) => void
|
||||
/** A tap on the empty drawing; without it the canvas behaves as the reader always did. */
|
||||
onEmpty?: () => void
|
||||
/** A label of a detail-view access: shows that view (the access's click does the same). */
|
||||
onAccess?: (opensViewId: string) => void
|
||||
}
|
||||
|
||||
type CanvasFailure = 'engine' | 'view'
|
||||
@@ -63,10 +66,15 @@ export default function CatalogueCanvas({
|
||||
selectedId,
|
||||
onAnnotation,
|
||||
onEmpty,
|
||||
onAccess,
|
||||
}: CatalogueCanvasProps) {
|
||||
const t = useT()
|
||||
const viewport = useRef<HTMLDivElement | null>(null)
|
||||
const host = useRef<HTMLDivElement | null>(null)
|
||||
const box = useRef<HTMLDivElement | null>(null)
|
||||
const zoom = useRef<HTMLDivElement | null>(null)
|
||||
// Bumped after each svg rebuild: the labels measure the drawing as rebuilt.
|
||||
const [built, setBuilt] = useState(0)
|
||||
const [attempt, setAttempt] = useState(0)
|
||||
const [failure, setFailure] = useState<CanvasFailure | null>(null)
|
||||
const stopped = useCoreStopped()
|
||||
@@ -120,6 +128,7 @@ export default function CatalogueCanvas({
|
||||
setFailure(build.ok ? null : build.failure)
|
||||
element.replaceChildren(...(build.ok ? [build.svg] : []))
|
||||
fitBands(element, detail)
|
||||
setBuilt((n) => n + 1)
|
||||
}, [preview, viewId, attempt, visible, detail])
|
||||
|
||||
useBandResize(host, detail)
|
||||
@@ -148,7 +157,7 @@ export default function CatalogueCanvas({
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className="relative overflow-hidden rounded-xl border border-[var(--color-border)] bg-[var(--color-surface)]">
|
||||
<div ref={box} className="relative overflow-hidden rounded-xl border border-[var(--color-border)] bg-[var(--color-surface)]">
|
||||
<div
|
||||
ref={viewport}
|
||||
tabIndex={0}
|
||||
@@ -167,7 +176,17 @@ export default function CatalogueCanvas({
|
||||
style={{ transform: transformOf(framing) }}
|
||||
/>
|
||||
</div>
|
||||
<div className="absolute right-2 top-2 flex gap-2">
|
||||
{onAccess && (
|
||||
<AccessLabels
|
||||
box={box}
|
||||
drawing={host}
|
||||
reserved={[zoom]}
|
||||
layoutKey={`${viewId}:${built}:${transformOf(framing)}`}
|
||||
hidden={failure !== null}
|
||||
onActivate={(_, opensViewId) => onAccess(opensViewId)}
|
||||
/>
|
||||
)}
|
||||
<div ref={zoom} className="absolute right-2 top-2 flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
|
||||
@@ -27,6 +27,8 @@ import type { Drop } from '@/editor/annotations/usePlacement'
|
||||
import type { HandleAction } from '@/editor/annotations/usePressGesture'
|
||||
import type { ToolId } from '@/editor/annotations/uiState'
|
||||
import { useAnnotationWork } from '@/editor/annotations/workStore'
|
||||
import { useEditorStore } from '@/editor/state/editorStore'
|
||||
import AccessLabels from '@/components/canvas/AccessLabels'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import AnnotationOverlay, { type OverlayProps } from './AnnotationOverlay'
|
||||
import HandleLayer, { type HandleLayerProps } from './HandleLayer'
|
||||
@@ -96,6 +98,7 @@ export interface AnnotationCanvasProps {
|
||||
export default function AnnotationCanvas(props: AnnotationCanvasProps) {
|
||||
const overlay = useRef<SVGSVGElement | null>(null)
|
||||
const viewport = useRef<HTMLDivElement | null>(null)
|
||||
const box = useRef<HTMLDivElement | null>(null)
|
||||
const build = useCanvasBuild(props.viewId, props.detail)
|
||||
useBandResize(build.host, props.detail)
|
||||
const gestures = useCanvasGestures({
|
||||
@@ -120,6 +123,7 @@ export default function AnnotationCanvas(props: AnnotationCanvasProps) {
|
||||
{...props}
|
||||
build={build}
|
||||
viewport={viewport}
|
||||
box={box}
|
||||
boxProps={withPreview(gestures.boxProps, preview)}
|
||||
finger={gestures.finger}
|
||||
layer={{
|
||||
@@ -207,12 +211,15 @@ function CanvasBox({
|
||||
selectedId,
|
||||
build,
|
||||
viewport,
|
||||
box,
|
||||
boxProps,
|
||||
finger,
|
||||
layer,
|
||||
onSelect,
|
||||
}: AnnotationCanvasProps & {
|
||||
build: Build
|
||||
viewport: RefObject<HTMLDivElement | null>
|
||||
box: RefObject<HTMLDivElement | null>
|
||||
boxProps: BoxProps
|
||||
/** A finger's drag in flight: the loupe above it (board 13). */
|
||||
finger: XY | null
|
||||
@@ -226,7 +233,7 @@ function CanvasBox({
|
||||
const cursor =
|
||||
tool === 'select' && !drawingFrame ? 'cursor-grab' : 'cursor-crosshair'
|
||||
return (
|
||||
<div data-canvas-box className={BOX}>
|
||||
<div ref={box} data-canvas-box className={BOX}>
|
||||
<div
|
||||
ref={viewport}
|
||||
tabIndex={0}
|
||||
@@ -244,6 +251,14 @@ function CanvasBox({
|
||||
{...layer}
|
||||
/>
|
||||
</div>
|
||||
<EditorLabels
|
||||
box={box}
|
||||
build={build}
|
||||
transform={layer.transform}
|
||||
selectedId={selectedId}
|
||||
hidden={creating || framed}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
{finger && root && (
|
||||
<Loupe
|
||||
finger={finger}
|
||||
@@ -261,6 +276,35 @@ function CanvasBox({
|
||||
)
|
||||
}
|
||||
|
||||
/** The access labels (D14, D16): a label selects its access; none during a frame or a creation. */
|
||||
function EditorLabels({
|
||||
box,
|
||||
build,
|
||||
transform,
|
||||
selectedId,
|
||||
hidden,
|
||||
onSelect,
|
||||
}: {
|
||||
box: RefObject<HTMLDivElement | null>
|
||||
build: Build
|
||||
transform: string
|
||||
selectedId: string | null
|
||||
hidden: boolean
|
||||
onSelect: (id: string) => void
|
||||
}) {
|
||||
const version = useEditorStore((s) => s.handleVersion)
|
||||
const layoutKey = `${build.root?.viewId ?? ''}:${transform}:${selectedId ?? ''}:${version}`
|
||||
return (
|
||||
<AccessLabels
|
||||
box={box}
|
||||
drawing={build.host}
|
||||
layoutKey={layoutKey}
|
||||
hidden={hidden || build.root === null}
|
||||
onActivate={(id) => onSelect(id)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const BOX =
|
||||
'relative min-w-0 flex-1 overflow-hidden rounded-xl border ' +
|
||||
'border-[var(--color-border)] bg-white'
|
||||
|
||||
@@ -331,6 +331,7 @@ function ReadOnlyAnnotations(props: TwinProps) {
|
||||
selectedId={selectedId}
|
||||
onAnnotation={pick}
|
||||
onEmpty={byDrawing}
|
||||
onAccess={twin.showView}
|
||||
/>
|
||||
</div>
|
||||
<aside ref={asideRef} data-annotation-aside="read">
|
||||
|
||||
@@ -13,6 +13,16 @@ import { en } from '@/i18n/en'
|
||||
import { controlStopped } from '../helpers/core'
|
||||
import { bundledSheet, loadTestSheet, minimalReport, sheetFromBundle } from '../helpers/sheet'
|
||||
|
||||
// happy-dom has no layout: every label the core layer holds is placed.
|
||||
vi.mock('@/anatomy/accessLabels', async (original) => ({
|
||||
...(await original<typeof import('@/anatomy/accessLabels')>()),
|
||||
placeAccessLabels: ({ labels }: { labels: { id: string }[] }) => ({
|
||||
placed: labels.map(({ id }) => ({ id, box: { x: 0, y: 0, w: 70, h: 20 }, leader: null })),
|
||||
overflow: [],
|
||||
button: null,
|
||||
}),
|
||||
}))
|
||||
|
||||
let sheet: SheetIndex
|
||||
beforeAll(async () => {
|
||||
sheet = await loadTestSheet()
|
||||
@@ -286,3 +296,49 @@ describe('AnatomyCanvas', () => {
|
||||
expect(container.querySelectorAll('[data-state="current"]')).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('AnatomyCanvas access labels (D12)', () => {
|
||||
const labelOf = (name: string) =>
|
||||
screen.findByRole('button', { name: fr['canvas.access.open']!.replace('{name}', name) })
|
||||
|
||||
it('shows a label for each access of the view and Enter on it asks the same core path as a click', async () => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const onZoneClick = vi.fn()
|
||||
const { container } = render(
|
||||
<AnatomyCanvas index={sheet} viewId="main" states={new Map()} onZoneClick={onZoneClick} />,
|
||||
)
|
||||
await waitFor(() => expect(container.querySelector('[data-anno-id="head-trigger"]')).not.toBeNull())
|
||||
const name = container
|
||||
.querySelector('[data-anno-id="head-trigger"]')!
|
||||
.getAttribute('data-anno-name-fr')!
|
||||
const label = await labelOf(name)
|
||||
label.focus()
|
||||
await userEvent.setup().keyboard('{Enter}')
|
||||
expect(onZoneClick).toHaveBeenCalledExactlyOnceWith('head-trigger', 'main')
|
||||
})
|
||||
|
||||
it('has the labels of the new view after a view change, none on a view without access', async () => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const noop = () => undefined
|
||||
const { container, rerender } = render(
|
||||
<AnatomyCanvas index={sheet} viewId="main" states={new Map()} onZoneClick={noop} />,
|
||||
)
|
||||
await screen.findAllByTestId('access-labels')
|
||||
await waitFor(() => expect(container.querySelectorAll('[data-testid="access-labels"] button')).not.toHaveLength(0))
|
||||
rerender(<AnatomyCanvas index={sheet} viewId="head" states={new Map()} onZoneClick={noop} />)
|
||||
await waitFor(() => expect(container.querySelector('[data-anno-id="atm"]')).not.toBeNull())
|
||||
await waitFor(() =>
|
||||
expect(container.querySelectorAll('[data-testid="access-labels"] button')).toHaveLength(0),
|
||||
)
|
||||
})
|
||||
|
||||
it('shows no label behind the failure notice', async () => {
|
||||
const down = Object.create(sheet) as SheetIndex
|
||||
down.canvasSvg = () => ({ ok: false, kind: 'core_unavailable' })
|
||||
const { container } = render(
|
||||
<AnatomyCanvas index={down} viewId="main" states={new Map()} onZoneClick={() => undefined} />,
|
||||
)
|
||||
await screen.findByText(fr['sheet.core_unavailable']!)
|
||||
expect(container.querySelector('[data-testid="access-labels"]')).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -21,6 +21,7 @@ import { usePlacement } from '@/editor/annotations/usePlacement'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import { AnnounceContext } from '@/editor/focusRequest'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { useAnnotationWork } from '@/editor/annotations/workStore'
|
||||
import {
|
||||
ASSET,
|
||||
drawnText,
|
||||
@@ -52,6 +53,15 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
submitSheetReview: vi.fn(),
|
||||
}))
|
||||
|
||||
// happy-dom has no layout: the labels are placed by this mock, set by the describe that
|
||||
// looks at them (no label elsewhere in this file).
|
||||
const place = vi.hoisted(() => vi.fn())
|
||||
vi.mock('@/anatomy/accessLabels', async (original) => ({
|
||||
...(await original<typeof import('@/anatomy/accessLabels')>()),
|
||||
placeAccessLabels: place,
|
||||
}))
|
||||
const NO_LABELS = { placed: [], overflow: [], button: null }
|
||||
|
||||
const props = {
|
||||
readOnly: false,
|
||||
navigate: vi.fn(),
|
||||
@@ -95,6 +105,8 @@ function stubCtm(): void {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
place.mockReset()
|
||||
place.mockReturnValue(NO_LABELS)
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
stubCtm()
|
||||
})
|
||||
@@ -2034,3 +2046,93 @@ describe('the strip', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('access labels (D12, D14, D16)', () => {
|
||||
const OPEN = 'Ouvrir la vue « Tête »'
|
||||
const withLink = () =>
|
||||
insert(
|
||||
insert(drawnText(), {
|
||||
kind: 'view',
|
||||
value: {
|
||||
kind: 'detail',
|
||||
id: 'view-det',
|
||||
name: { fr: 'Tête', en: 'Head' },
|
||||
svg_asset_id: null,
|
||||
view_box: { min_x: 10, min_y: 10, width: 80, height: 80 },
|
||||
parent_view_id: 'view-main',
|
||||
},
|
||||
}),
|
||||
{
|
||||
kind: 'annotation',
|
||||
value: {
|
||||
id: 'link-a',
|
||||
view_id: 'view-main',
|
||||
category_id: 'cat-a',
|
||||
laterality: 'unpaired',
|
||||
geometry: { type: 'circle', cx: 90, cy: 90, r: 3 },
|
||||
review_status: 'to_confirm',
|
||||
color: null,
|
||||
kind: 'detail_trigger',
|
||||
name: null,
|
||||
opens_view_id: 'view-det',
|
||||
} as Annotation,
|
||||
},
|
||||
)
|
||||
const labelled = () =>
|
||||
place.mockImplementation(({ labels }: { labels: { id: string }[] }) => ({
|
||||
placed: labels.map(({ id }) => ({ id, box: { x: 0, y: 0, w: 70, h: 20 }, leader: null })),
|
||||
overflow: [],
|
||||
button: null,
|
||||
}))
|
||||
const label = () => screen.findByRole('button', { name: OPEN })
|
||||
|
||||
it('a label selects its access and opens no view (D14)', async () => {
|
||||
labelled()
|
||||
await mount({ text: withLink() })
|
||||
await userEvent.setup().click(await label())
|
||||
expect(screen.getByTestId('edit-strip-title')).toHaveAttribute('data-selection')
|
||||
expect(screen.getByTestId('annotation-canvas')).toHaveAttribute('aria-label', 'Vue principale')
|
||||
expect(
|
||||
screen.getByTestId('annotation-canvas-drawing').querySelector('[data-anno-id="link-a"]'),
|
||||
).toHaveAttribute('data-state', 'current')
|
||||
})
|
||||
|
||||
it('is hidden while a frame is open on the view (D16)', async () => {
|
||||
labelled()
|
||||
await mount({ text: withLink() })
|
||||
await label()
|
||||
act(() =>
|
||||
useAnnotationWork.setState({
|
||||
frame: {
|
||||
purpose: 'create',
|
||||
viewId: 'view-main',
|
||||
drawnOn: 'view-main',
|
||||
box: null,
|
||||
startBox: null,
|
||||
keepRatio: false,
|
||||
moveAccess: false,
|
||||
moving: false,
|
||||
dialog: false,
|
||||
started: false,
|
||||
base: '',
|
||||
returnTo: 'view-main',
|
||||
},
|
||||
}),
|
||||
)
|
||||
await waitFor(() => expect(screen.queryByRole('button', { name: OPEN })).toBeNull())
|
||||
act(() => useAnnotationWork.setState({ frame: null }))
|
||||
expect(await label()).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('on the read-only twin a label shows its view, as the chip does', async () => {
|
||||
labelled()
|
||||
await mount({ text: withLink(), readOnly: true })
|
||||
fireEvent.click(await label())
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('catalogue-canvas')).toHaveAttribute(
|
||||
'aria-label',
|
||||
expect.stringContaining('Tête'),
|
||||
),
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -13,6 +13,13 @@ vi.mock('@/lib/supabase', () => ({
|
||||
isSupabaseConfigured: () => mocks.fake !== null,
|
||||
}))
|
||||
|
||||
// happy-dom has no layout: every label of the layer is placed, and the call is recorded.
|
||||
const place = vi.hoisted(() => vi.fn())
|
||||
vi.mock('@/anatomy/accessLabels', async (original) => ({
|
||||
...(await original<typeof import('@/anatomy/accessLabels')>()),
|
||||
placeAccessLabels: place,
|
||||
}))
|
||||
|
||||
import CatalogRoute from '@/app/routes/app/anatomy/CatalogRoute'
|
||||
import SheetRoute from '@/app/routes/app/anatomy/SheetRoute'
|
||||
import { coreRuntime } from '@/core/runtime'
|
||||
@@ -247,6 +254,45 @@ describe('/app/anatomy/:sheetId', () => {
|
||||
expect(screen.getByRole('tab', { name: 'Tête (vue latérale gauche)' })).toHaveAttribute('aria-selected', 'true')
|
||||
})
|
||||
|
||||
describe('access labels (D12, A8)', () => {
|
||||
beforeEach(() => {
|
||||
place.mockReset()
|
||||
place.mockImplementation(({ labels }: { labels: { id: string }[] }) => ({
|
||||
placed: labels.map(({ id }) => ({ id, box: { x: 0, y: 0, w: 70, h: 20 }, leader: null })),
|
||||
overflow: [],
|
||||
button: null,
|
||||
}))
|
||||
})
|
||||
|
||||
it('shows a label for the access; it shows the view, as the access click does', async () => {
|
||||
mount(`/app/anatomy/${SHEET}`)
|
||||
const canvas = await screen.findByTestId('catalogue-canvas-drawing')
|
||||
await waitFor(() => expect(canvas.querySelector('[data-anno-id="head-trigger"]')).not.toBeNull())
|
||||
const name = canvas.querySelector('[data-anno-id="head-trigger"]')!.getAttribute('data-anno-name-fr')!
|
||||
const label = await screen.findByRole('button', {
|
||||
name: fr['canvas.access.open']!.replace('{name}', name),
|
||||
})
|
||||
fireEvent.click(label)
|
||||
expect(screen.getByRole('tab', { name: 'Tête (vue latérale gauche)' })).toHaveAttribute('aria-selected', 'true')
|
||||
// The head view has no access: the labels are those of the rebuilt drawing, none.
|
||||
await waitFor(() => expect(canvas.querySelector('[data-anno-id="atm"]')).not.toBeNull())
|
||||
await waitFor(() => expect(screen.queryByTestId('access-labels')?.querySelector('button') ?? null).toBeNull())
|
||||
})
|
||||
|
||||
it('hands the zoom buttons to the placement as a reserved box', async () => {
|
||||
const zoom = { x: 300, y: 8, left: 300, top: 8, width: 150, height: 44, right: 450, bottom: 52 }
|
||||
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function (this: Element) {
|
||||
const own = this.className?.toString().includes('right-2 top-2') ? zoom : {}
|
||||
return { x: 0, y: 0, left: 0, top: 0, width: 0, height: 0, right: 0, bottom: 0, ...own, toJSON() {} }
|
||||
})
|
||||
mount(`/app/anatomy/${SHEET}`)
|
||||
await waitFor(() => expect(place).toHaveBeenCalled())
|
||||
const { reserved } = place.mock.calls.at(-1)![0] as { reserved: { x: number; w: number }[] }
|
||||
expect(reserved).toEqual([expect.objectContaining({ x: 300, w: 150 })])
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
})
|
||||
|
||||
it('lists the versions with the « Retirée » mark, each linking to its page', async () => {
|
||||
mount(`/app/anatomy/${SHEET}`)
|
||||
await userEvent.click(await screen.findByRole('button', { name: '2 versions antérieures' }))
|
||||
|
||||
Reference in new issue
Block a user