feat(editor): finding dialog and citations side sheet in the history

Constats opens each element in one modal dialog (view, edit with a
local draft, creation) driven by the editor view layer of the browser
history. The citations panel becomes a modal side sheet stacked over
it; its geometry, exit machinery and page inertness are removed.
Back and Forward restore the layers, a dirty form asks first.
This commit is contained in:
bchanot committed 2026-11-13 18:51:35 +01:00
1 parent 8e4f02620a
commit 18085cecf8
50 files changed
+2642 -1504

No files matched your search

+50 -16
View File
@@ -1,9 +1,11 @@
import { describe, expect, it } from 'vitest'
import type { ElementKey } from '@faunosteo/core-wasm/types'
import {
citationsOfView,
initialNavigation,
navigationReducer,
targetOfKey,
viewOf,
type EditorTarget,
type NavigationState,
} from '../../src/editor/navigation'
@@ -74,7 +76,7 @@ describe('navigationReducer', () => {
expect(state.visitedTabs).toEqual(['annotations'])
expect(state.visitedSections).toEqual(['drawing'])
expect(initialNavigation('general').visitedSections).toEqual([])
expect(state.citationsOf).toBeNull()
expect(state.finding).toBeNull()
expect(state.libraryReset).toBe(0)
})
@@ -97,21 +99,21 @@ describe('navigationReducer', () => {
type: 'go_to',
target: targetOfKey(key),
})
expect(state).toMatchObject({ tab: 'references', citationsOf: null })
expect(state).toMatchObject({ tab: 'references', finding: null })
expect(state.visitedTabs).toEqual(['general', 'references'])
expect(state.focus?.target).toEqual(targetOfKey(key))
})
it('go_to a tab closes the citations panel', () => {
it('go_to a tab closes the finding layers', () => {
const state = run(
initialNavigation('general'),
{ type: 'open_citations', citedBy: node },
{ type: 'go_to', target: targetOfKey(finding) },
)
expect(state.citationsOf).toBeNull()
expect(state.finding).toBeNull()
})
it('select_tab closes the panel and keeps the section, no request', () => {
it('select_tab closes the layers and keeps the section, no request', () => {
const state = run(
initialNavigation('annotations'),
{ type: 'open_section', section: 'regions' },
@@ -121,16 +123,16 @@ describe('navigationReducer', () => {
expect(state).toMatchObject({
tab: 'findings',
section: 'regions',
citationsOf: null,
finding: null,
focus: undefined,
})
})
it('open_citations opens for a finding node only', () => {
const base = initialNavigation('findings')
expect(
run(base, { type: 'open_citations', citedBy: node }).citationsOf,
).toBe(node)
const opened = run(base, { type: 'open_citations', citedBy: node })
expect(citationsOfView(opened)).toBe(node)
expect(opened.finding).toEqual({ key: node, citations: true })
for (const refused of [
finding,
view,
@@ -141,7 +143,7 @@ describe('navigationReducer', () => {
}
})
it('show_all_references closes the panel, shows the tab and bumps the reset', () => {
it('show_all_references closes the layers, shows the tab and bumps the reset', () => {
const state = run(
initialNavigation('findings'),
{ type: 'open_citations', citedBy: node },
@@ -149,7 +151,7 @@ describe('navigationReducer', () => {
)
expect(state).toMatchObject({
tab: 'references',
citationsOf: null,
finding: null,
libraryReset: 1,
focus: undefined,
})
@@ -183,13 +185,45 @@ describe('navigationReducer', () => {
{ type: 'open_citations', citedBy: node },
)
expect(opened).toMatchObject({ tab: 'annotations', section: 'views' })
expect(opened.citationsOf).toBe(node)
expect(citationsOfView(opened)).toBe(node)
const closed = run(opened, { type: 'close_citations' })
expect(closed).toMatchObject({
tab: 'annotations',
section: 'views',
citationsOf: null,
expect(closed).toMatchObject({ tab: 'annotations', section: 'views' })
expect(citationsOfView(closed)).toBeNull()
// the sheet closes alone: the finding dialog under it stays
expect(closed.finding).toEqual({ key: node, citations: false })
})
it('open_finding shows the dialog of a key on Constats, close_finding takes both layers', () => {
const opened = run(initialNavigation('general'), {
type: 'open_finding',
key: finding,
})
expect(opened).toMatchObject({ tab: 'findings' })
expect(opened.finding).toEqual({ key: finding, citations: false })
const sheet = run(opened, { type: 'open_citations', citedBy: node })
expect(sheet.finding).toEqual({ key: node, citations: true })
expect(run(sheet, { type: 'close_finding' }).finding).toBeNull()
})
it('create_finding holds the kind and the parent, a creation has no sheet', () => {
const state = run(initialNavigation('findings'), {
type: 'create_finding',
kind: 'node',
parent: finding,
})
expect(state.finding).toEqual({ create: { kind: 'node', parent: finding } })
expect(citationsOfView(state)).toBeNull()
expect(run(state, { type: 'close_citations' })).toBe(state)
})
it('restore_view puts back the layers of the view it is given', () => {
const base = initialNavigation('findings')
const restored = run(base, {
type: 'restore_view',
view: { ...viewOf(base), finding: { key: node, citations: true } },
})
expect(citationsOfView(restored)).toBe(node)
expect(restored.focus).toBeUndefined()
})
it('focus_consumed clears only its serial and serials are not reused', () => {