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:
1 parent
8e4f02620a
commit
18085cecf8
50 files changed
+2642
-1504
No files matched your search
@@ -33,12 +33,58 @@ const entry = (patch: Partial<HistoryEntry> = {}): HistoryEntry => ({
|
||||
})
|
||||
const stateOf = (value: unknown) => ({ [ENTRY_KEY]: value })
|
||||
|
||||
const node = { kind: 'finding', zone_id: 'z', path: ['f', 'n'] } as const
|
||||
|
||||
describe('sanitizeView', () => {
|
||||
it('keeps a tab and a section, and holds no layer yet', () => {
|
||||
it('keeps a tab and a section, and drops a malformed layer', () => {
|
||||
const raw = { tab: 'annotations', section: 'views', finding: { key: {} } }
|
||||
expect(sanitizeView(raw)).toEqual(view('annotations', { section: 'views' }))
|
||||
})
|
||||
|
||||
it('keeps the reading layers of Constats: the dialog and the sheet over it', () => {
|
||||
const dialog = {
|
||||
tab: 'findings',
|
||||
section: 'drawing',
|
||||
finding: { key: node },
|
||||
}
|
||||
expect(sanitizeView(dialog)?.finding).toEqual({
|
||||
key: node,
|
||||
citations: false,
|
||||
})
|
||||
const sheet = { ...dialog, finding: { key: node, citations: true } }
|
||||
expect(sanitizeView(sheet)?.finding).toEqual({ key: node, citations: true })
|
||||
expect(layerCount(sanitizeView(sheet)!)).toBe(2)
|
||||
})
|
||||
|
||||
it('a sheet needs a finding node, a layer needs the Constats tab', () => {
|
||||
const family = { kind: 'finding', zone_id: 'z', path: ['f'] }
|
||||
const raw = { tab: 'findings', section: 'drawing' }
|
||||
const asked = { ...raw, finding: { key: family, citations: true } }
|
||||
expect(sanitizeView(asked)?.finding).toEqual({
|
||||
key: family,
|
||||
citations: false,
|
||||
})
|
||||
const elsewhere = {
|
||||
tab: 'general',
|
||||
finding: { key: node, citations: false },
|
||||
}
|
||||
expect(sanitizeView(elsewhere)?.finding).toBeNull()
|
||||
})
|
||||
|
||||
it('a creation is a form: read back only where forms are kept', () => {
|
||||
const raw = {
|
||||
tab: 'findings',
|
||||
section: 'drawing',
|
||||
finding: { create: { kind: 'node', parent: node } },
|
||||
}
|
||||
expect(sanitizeView(raw)?.finding).toEqual({
|
||||
create: { kind: 'node', parent: node },
|
||||
})
|
||||
expect(sanitizeView(raw, false)?.finding).toBeNull()
|
||||
const odd = { ...raw, finding: { create: { kind: 'x', parent: null } } }
|
||||
expect(sanitizeView(odd)?.finding).toBeNull()
|
||||
})
|
||||
|
||||
it('drops what is no view: an unknown tab, a non-object', () => {
|
||||
expect(sanitizeView({ tab: 'nowhere', section: 'views' })).toBeNull()
|
||||
expect(sanitizeView('general')).toBeNull()
|
||||
@@ -115,6 +161,38 @@ describe('planWrite', () => {
|
||||
expect(planWrite(inSection, view('general'), false)).toBe('push')
|
||||
})
|
||||
|
||||
it('a finding dialog and its sheet go back one layer at a time', () => {
|
||||
const dialog = view('findings', {
|
||||
finding: { key: node, citations: false },
|
||||
})
|
||||
const sheet = view('findings', { finding: { key: node, citations: true } })
|
||||
expect(planWrite(entry({ view: view('findings') }), dialog, false)).toBe(
|
||||
'push',
|
||||
)
|
||||
expect(planWrite(entry({ view: dialog }), sheet, false)).toBe('push')
|
||||
const onSheet = entry({ view: sheet, below: dialog })
|
||||
expect(planWrite(onSheet, dialog, false)).toBe('back')
|
||||
const opened = entry({ view: dialog, below: view('findings') })
|
||||
expect(planWrite(opened, view('findings'), false)).toBe('back')
|
||||
})
|
||||
|
||||
it('a layer left for another tab is a push, a replace hint overrides a removal', () => {
|
||||
const sheet = view('findings', { finding: { key: node, citations: true } })
|
||||
const top = entry({ view: sheet, below: view('findings') })
|
||||
// « Tout afficher » and « Aller à »: a step forward, Back returns to the sheet
|
||||
expect(planWrite(top, view('references'), false)).toBe('push')
|
||||
// a deletion or a vanished element: no Back step to a dead dialog
|
||||
expect(planWrite(top, view('findings'), true)).toBe('replace')
|
||||
// a creation turned into its element: same layer, replaced
|
||||
const create = view('findings', {
|
||||
finding: { create: { kind: 'node', parent: null } },
|
||||
})
|
||||
const created = view('findings', {
|
||||
finding: { key: node, citations: false },
|
||||
})
|
||||
expect(planWrite(entry({ view: create }), created, true)).toBe('replace')
|
||||
})
|
||||
|
||||
it('goes back for a layer removed when the entry holds the view below', () => {
|
||||
const layer = view('findings', { reference: { create: true } })
|
||||
const opened = entry({ view: layer, below: view('findings') })
|
||||
|
||||
Reference in new issue
Block a user