diff --git a/apps/app/src/components/editor/findings/DiscardConfirm.tsx b/apps/app/src/components/editor/findings/DiscardConfirm.tsx
index c87f427f..d1c30359 100644
--- a/apps/app/src/components/editor/findings/DiscardConfirm.tsx
+++ b/apps/app/src/components/editor/findings/DiscardConfirm.tsx
@@ -12,8 +12,11 @@ const BOX =
/**
* True when no open dialog lies over `host`: each open one is `host`, holds it, or comes
- * before it in the page (the editor's layers are stacked in tree order: the references
- * dialog after the finding dialog, the reference dialog after both).
+ * before it in the page.
+ * Invariant: an open dialog after `host` in tree order lies over it. The editor's layers
+ * keep it (the finding dialog in the tab body, then the references dialog, then the
+ * reference dialog); a modal mounted earlier in the tree must never open over a form
+ * that uses this confirmation, or its question would be focused under that modal.
*/
const onTop = (host: Element) =>
[...document.querySelectorAll('dialog[open]')].every(
diff --git a/apps/app/src/components/editor/references/CitationsDraftList.tsx b/apps/app/src/components/editor/references/CitationsDraftList.tsx
index 8af671e9..db466981 100644
--- a/apps/app/src/components/editor/references/CitationsDraftList.tsx
+++ b/apps/app/src/components/editor/references/CitationsDraftList.tsx
@@ -90,7 +90,7 @@ function DraftRow({ id, props, onRemove }: RowProps) {
)
}
-/** « Citer une référence » among those not cited yet, and « Nouvelle référence ». */
+/** « Citer une référence existante » among those not cited yet, and « Nouvelle référence ». */
function AddRow({ props }: { props: DraftListProps }) {
const t = useT()
const options = useCitableOptions(props.ids)
@@ -135,19 +135,25 @@ export default function CitationsDraftList(props: DraftListProps) {
{t('editor.findings.references_none')}
)}
-
- {ids.map((id, at) => (
- {
- focus.removing(at)
- props.onRemove(id)
- }}
- />
- ))}
-
+ {ids.length > 0 && (
+
+ {ids.map((id, at) => (
+ {
+ focus.removing(at)
+ props.onRemove(id)
+ }}
+ />
+ ))}
+
+ )}
)
diff --git a/apps/app/src/editor/useEditorNavigation.ts b/apps/app/src/editor/useEditorNavigation.ts
index 3f938d7c..6cf4b1e5 100644
--- a/apps/app/src/editor/useEditorNavigation.ts
+++ b/apps/app/src/editor/useEditorNavigation.ts
@@ -138,7 +138,7 @@ export interface EditorNavigation {
openCitations: (citedBy: ElementKey, opener?: Opener) => void
/**
* A close of the citations dialog: a user one is refused by its draft (it asks first),
- * a forced one goes (the draft is dropped).
+ * a forced one goes (the draft is dropped, and said so).
*/
closeCitations: (forced?: boolean) => boolean
/** « X références », where the focus returns once the citations dialog is closed. */
@@ -393,7 +393,7 @@ function useFindingClosing({ dispatch, announce, guards, mark }: LayerContext) {
/** The citations dialog over the finding dialog: opened for a family or a node only. */
function useCitationsLayer(ctx: LayerContext, openers: Openers) {
- const { dispatch, guards, mark } = ctx
+ const { dispatch, announce, guards, mark } = ctx
const openCitations = useCallback(
(citedBy: ElementKey, opener?: Opener) => {
if (!isCitable(citedBy)) return
@@ -406,12 +406,15 @@ function useCitationsLayer(ctx: LayerContext, openers: Openers) {
)
const closeCitations = useCallback(
(forced = false) => {
- if (!guards.ask('citations', forced).allowed) return false
+ const answer = guards.ask('citations', forced)
+ if (!answer.allowed) return false
+ // A forced close of a draft says it was dropped, as the other forced closes.
+ if (answer.note) announce(answer.note)
mark()
dispatch({ type: 'close_citations' })
return true
},
- [guards, dispatch, mark],
+ [guards, announce, dispatch, mark],
)
return { openCitations, closeCitations }
}
diff --git a/apps/app/src/editor/useReferenceMoves.ts b/apps/app/src/editor/useReferenceMoves.ts
index 5d448fb6..376f83e5 100644
--- a/apps/app/src/editor/useReferenceMoves.ts
+++ b/apps/app/src/editor/useReferenceMoves.ts
@@ -42,7 +42,10 @@ export interface ReferenceMoves {
backToFinding: (key: ElementKey) => void
}
-/** What the open dialog was started from: its opener, and a citing form for a creation. */
+/**
+ * What the open dialog was started from: its opener, and a citing form for a creation
+ * (forgotten once the dialog closes or is replaced).
+ */
interface Held {
opener: Opener
cite: CiteCreated | null
@@ -72,22 +75,25 @@ function useOpening({ dispatch, mark }: LayerContext, held: Held) {
}
/** A user close: the form may refuse it (a dirty draft asks first). */
-function useClose({ dispatch, guards, mark }: LayerContext) {
+function useClose({ dispatch, guards, mark }: LayerContext, held: Held) {
return useCallback(
(forced = false) => {
if (!guards.ask('reference', forced).allowed) return false
+ held.cite = null
mark()
dispatch({ type: 'close_reference' })
return true
},
- [guards, dispatch, mark],
+ [guards, dispatch, mark, held],
)
}
/** The replace that is no Back step; with `text`, forced and said with a dropped draft. */
-function useReplace({ dispatch, announce, guards, mark }: LayerContext) {
+function useReplace(ctx: LayerContext, held: Held) {
+ const { dispatch, announce, guards, mark } = ctx
return useCallback(
(id: string | null, text?: string) => {
+ held.cite = null
const note = text ? guards.ask('reference', true).note : undefined
if (text) announce(note ? `${note}. ${text}` : text)
mark(true)
@@ -95,13 +101,13 @@ function useReplace({ dispatch, announce, guards, mark }: LayerContext) {
id ? { type: 'open_reference', id } : { type: 'close_reference' },
)
},
- [guards, announce, dispatch, mark],
+ [guards, announce, dispatch, mark, held],
)
}
/** The moves that take it away: a user close, and the replace that is no Back step. */
-function useClosing(ctx: LayerContext) {
- return { close: useClose(ctx), replace: useReplace(ctx) }
+function useClosing(ctx: LayerContext, held: Held) {
+ return { close: useClose(ctx, held), replace: useReplace(ctx, held) }
}
/**
@@ -169,7 +175,7 @@ export function useReferenceMoves(
const element = held.opener
return element?.isConnected && !element.closest('[hidden]') ? element : null
}, [held])
- const closing = useClosing(ctx)
+ const closing = useClosing(ctx, held)
return {
...useOpening(ctx, held),
...closing,
diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts
index 7f063a91..0b9e1901 100644
--- a/apps/app/src/i18n/en.ts
+++ b/apps/app/src/i18n/en.ts
@@ -1253,7 +1253,7 @@ export const en: Dict = {
'editor.references.none_doi': 'None',
'editor.references.none_url': 'None',
'editor.references.new_tab': '(new tab)',
- 'editor.references.delete_hint': 'To delete this reference, first remove each of its citations: “Go to”, then “Edit” and “Remove” in the finding or the family.',
+ 'editor.references.delete_hint': 'To delete this reference, first remove each of its citations: “Go to”, then “X references”, “Edit” and “Remove” in the references of the finding or the family.',
'editor.references.add': 'Add a reference',
'editor.references.added': 'Reference added: {citation}',
'editor.references.added_show': 'Show',
@@ -1640,7 +1640,7 @@ export const en: Dict = {
'editor.findings.no': 'No',
'editor.findings.references': 'Cited references',
'editor.findings.references_none': 'No reference cited.',
- 'editor.findings.reference_add': 'Cite a reference',
+ 'editor.findings.reference_add': 'Cite an existing reference',
'editor.findings.edit': 'Edit',
'editor.findings.save': 'Save',
'editor.findings.saved': 'Changes saved',
diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts
index 489bd77e..0165ee5c 100644
--- a/apps/app/src/i18n/fr.ts
+++ b/apps/app/src/i18n/fr.ts
@@ -1284,7 +1284,7 @@ export const fr: Dict = {
'editor.references.none_doi': 'Aucun',
'editor.references.none_url': 'Aucune',
'editor.references.new_tab': '(nouvel onglet)',
- 'editor.references.delete_hint': 'Pour supprimer cette référence, retirez d\'abord chacune de ses citations : « Aller à », puis « Modifier » et « Retirer » dans le constat ou la famille.',
+ 'editor.references.delete_hint': 'Pour supprimer cette référence, retirez d\'abord chacune de ses citations : « Aller à », puis « X références », « Modifier » et « Retirer » dans les références du constat ou de la famille.',
'editor.references.add': 'Ajouter une référence',
'editor.references.added': 'Référence ajoutée : {citation}',
'editor.references.added_show': 'Afficher',
@@ -1670,7 +1670,7 @@ export const fr: Dict = {
'editor.findings.no': 'Non',
'editor.findings.references': 'Références citées',
'editor.findings.references_none': 'Aucune référence citée.',
- 'editor.findings.reference_add': 'Citer une référence',
+ 'editor.findings.reference_add': 'Citer une référence existante',
'editor.findings.edit': 'Modifier',
'editor.findings.save': 'Enregistrer',
'editor.findings.saved': 'Modifications enregistrées',
diff --git a/apps/app/tests/unit/editor-citations-edit.test.tsx b/apps/app/tests/unit/editor-citations-edit.test.tsx
index 28968bcd..823f072f 100644
--- a/apps/app/tests/unit/editor-citations-edit.test.tsx
+++ b/apps/app/tests/unit/editor-citations-edit.test.tsx
@@ -182,10 +182,13 @@ const removeRow = (user: User, citation: RegExp) =>
}),
)
const cite = (user: User, id: string) =>
- user.selectOptions(inCitations().getByLabelText('Citer une référence'), id)
+ user.selectOptions(
+ inCitations().getByLabelText('Citer une référence existante'),
+ id,
+ )
describe('the « Modifier » of the references dialog', () => {
- it('switches to the edit mode: no history entry, no « Tout afficher », no « Aller à »', async () => {
+ it('edit mode: no history entry, no « Tout afficher », no « Aller à »', async () => {
const user = await mount()
await openCitations(user)
const before = written()!.id
@@ -243,6 +246,17 @@ describe('the draft', () => {
expect(inCitations().queryByText('Modifications enregistrées')).toBeNull()
})
+ it('the draft list is named; an empty draft shows no list', async () => {
+ const user = await mount(1280, sheetText([]))
+ await editCitations(user, '0 référence')
+ expect(inCitations().queryByRole('list')).toBeNull()
+ expect(inCitations().getByText('Aucune référence citée.')).toBeVisible()
+ await cite(user, 'ref-b')
+ expect(
+ inCitations().getByRole('list', { name: 'Références citées' }),
+ ).toBeVisible()
+ })
+
it('a dangling id is named and removable', async () => {
const user = await mount(1280, sheetText(['ref-a', 'ref-x']))
await editCitations(user)
@@ -252,7 +266,7 @@ describe('the draft', () => {
expect(nodeA().reference_ids).toEqual(['ref-a'])
})
- it('a save keeps citations changed elsewhere: removals and additions on the current list', async () => {
+ it('a save applies the draft to the current list (changes made elsewhere stay)', async () => {
const user = await mount()
await editCitations(user)
await removeRow(user, /Barone/)
@@ -331,7 +345,9 @@ describe('leaving the edit mode with changes', () => {
expect(button(/^Retirer/)).toBeDisabled()
expect(button(/^Modifier la référence/)).toBeDisabled()
expect(button('Nouvelle référence')).toBeDisabled()
- expect(inCitations().queryByLabelText('Citer une référence')).toBeNull()
+ expect(
+ inCitations().queryByLabelText('Citer une référence existante'),
+ ).toBeNull()
expect(inCitations().queryByRole('button', { name: 'Annuler' })).toBeNull()
await user.click(button('Abandonner'))
await waitFor(() =>
@@ -512,7 +528,7 @@ describe('a reference over the references dialog of a dirty finding (criterion 2
await user.type(inReference().getByLabelText('Citation'), ' x')
}
- it('the finding asks next with the references dialog closed, focused; the jump goes after it', async () => {
+ it('the finding asks next, references dialog closed, focused; then the jump goes', async () => {
const user = await mount()
await stacked(user)
expect(jump().defaultPrevented).toBe(true)
@@ -543,7 +559,7 @@ describe('a reference over the references dialog of a dirty finding (criterion 2
expect(api.traverseTo).not.toHaveBeenCalled()
})
- it('a citations draft under a clean reference dialog asks once the reference is closed', async () => {
+ it('a citations draft under a clean reference dialog asks once it is closed', async () => {
const user = await mount()
await editCitations(user)
await removeRow(user, /Code rural/)
diff --git a/apps/app/tests/unit/editor-citations-guards.test.tsx b/apps/app/tests/unit/editor-citations-guards.test.tsx
index 56dc5836..7ff552d9 100644
--- a/apps/app/tests/unit/editor-citations-guards.test.tsx
+++ b/apps/app/tests/unit/editor-citations-guards.test.tsx
@@ -140,6 +140,16 @@ describe('closeCitations', () => {
expect(closed).toBe(true)
expect(nav.state.finding).toMatchObject({ citations: false })
})
+
+ it('a forced close of a draft says it was dropped', async () => {
+ cited()
+ register('citations')
+ act(() => {
+ nav.closeCitations(true)
+ })
+ await act(async () => undefined)
+ expect(nav.live).toContain('dropped')
+ })
})
describe('a creation started over the citations dialog', () => {
@@ -158,6 +168,19 @@ describe('a creation started over the citations dialog', () => {
expect(nav.state.finding).toMatchObject({ citations: true })
})
+ it('a creation closed or replaced forgets its citing form', async () => {
+ cited()
+ const cite = vi.fn()
+ act(() => nav.references.start(null, cite))
+ act(() => nav.references.close(true))
+ await act(async () => nav.references.created('ref-x'))
+ expect(cite).not.toHaveBeenCalled()
+ act(() => nav.references.start(null, cite))
+ act(() => nav.references.replace(null))
+ await act(async () => nav.references.created('ref-y'))
+ expect(cite).not.toHaveBeenCalled()
+ })
+
it('a later creation from the library sets the notice, cites nothing', async () => {
cited()
const cite = vi.fn()
diff --git a/apps/app/tests/unit/editor-finding-dialog.test.tsx b/apps/app/tests/unit/editor-finding-dialog.test.tsx
index 55116ebe..0adf479f 100644
--- a/apps/app/tests/unit/editor-finding-dialog.test.tsx
+++ b/apps/app/tests/unit/editor-finding-dialog.test.tsx
@@ -857,7 +857,9 @@ describe('the finding dialog holds no citation control (Rev 5, owner item 1)', (
await openFinding(user, /Node A/)
expect(inDialog().getByText('Références citées')).toBeVisible()
expect(inDialog().queryByText('Alpha')).toBeNull()
- expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
+ expect(
+ inDialog().queryByLabelText('Citer une référence existante'),
+ ).toBeNull()
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
expect(
inDialog().getByRole('button', { name: '1 référence' }),
@@ -895,7 +897,9 @@ describe('the finding dialog holds no citation control (Rev 5, owner item 1)', (
expect(
inDialog().getByRole('button', { name: '0 référence' }),
).toBeVisible()
- expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
+ expect(
+ inDialog().queryByLabelText('Citer une référence existante'),
+ ).toBeNull()
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
})
diff --git a/apps/app/tests/unit/editor-findings.test.tsx b/apps/app/tests/unit/editor-findings.test.tsx
index 64009e1e..45f549e1 100644
--- a/apps/app/tests/unit/editor-findings.test.tsx
+++ b/apps/app/tests/unit/editor-findings.test.tsx
@@ -630,9 +630,13 @@ describe('Constats tab', () => {
await save()
expect(node().description).toEqual({})
// Neither mode cites: the references dialog holds the citations (Rev 5).
- expect(inFindingDialog().queryByLabelText('Citer une référence')).toBeNull()
+ expect(
+ inFindingDialog().queryByLabelText('Citer une référence existante'),
+ ).toBeNull()
await startEdit(user)
- expect(inFindingDialog().queryByLabelText('Citer une référence')).toBeNull()
+ expect(
+ inFindingDialog().queryByLabelText('Citer une référence existante'),
+ ).toBeNull()
act(() => {
store.getState().commit({
op: 'update',
@@ -706,7 +710,7 @@ describe('Constats tab', () => {
expect(all.filter((item) => item.kind === 'node')).toHaveLength(2)
})
- it('the trigger reads « expanded » while the references dialog of its finding is open', async () => {
+ it('the trigger opens the references dialog of its finding, focus back on close', async () => {
let text = insert(treeText(), {
kind: 'reference',
value: { id: 'ref-a', type: 'book', citation: 'A', url: null, doi: null },
@@ -750,7 +754,7 @@ describe('Constats tab', () => {
expect(screen.queryByLabelText('Renvoi vers un vétérinaire')).toBeNull()
expect(screen.getByLabelText('Description (FR)')).toBeInTheDocument()
rerender()
- expect(screen.queryByLabelText('Citer une référence')).toBeNull()
+ expect(screen.queryByLabelText('Citer une référence existante')).toBeNull()
// the open form is kept, its fields read-only, « Enregistrer » disabled
expect(screen.getByLabelText('Nom (FR)')).toHaveAttribute('readonly')
expect(screen.getByRole('button', { name: 'Enregistrer' })).toBeDisabled()
diff --git a/apps/app/tests/unit/editor-references-panel.test.tsx b/apps/app/tests/unit/editor-references-panel.test.tsx
index 81fb4181..b442a439 100644
--- a/apps/app/tests/unit/editor-references-panel.test.tsx
+++ b/apps/app/tests/unit/editor-references-panel.test.tsx
@@ -223,7 +223,7 @@ describe('opening', () => {
expect(panel()).not.toHaveTextContent('Denoix')
})
- it('view mode: an open tile marks the current finding, « Aller à » only; « Modifier » is the dialog’s', async () => {
+ it('a tile marks the finding, « Aller à » only; « Modifier » on the dialog', async () => {
const user = await mount()
await openFromFinding(user)
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
diff --git a/apps/app/tests/unit/i18n.dicts.test.ts b/apps/app/tests/unit/i18n.dicts.test.ts
index b11b0f0c..3bd55a3c 100644
--- a/apps/app/tests/unit/i18n.dicts.test.ts
+++ b/apps/app/tests/unit/i18n.dicts.test.ts
@@ -18,12 +18,13 @@ describe('i18n dicts', () => {
})
describe('the delete hint of a cited reference (final review rev 4, item 2)', () => {
- it('names the buttons of each step: « Aller à », « Modifier », « Retirer »', () => {
+ it('names each step: « Aller à », « X références », « Modifier », « Retirer »', () => {
for (const dict of [fr, en]) {
const hint = dict['editor.references.delete_hint']
const labels = [
dict['editor.references.go_to'],
- dict['editor.findings.edit'],
+ dict['editor.findings.references_open_other'].replace('{count}', 'X'),
+ dict['editor.citations.edit'],
dict['editor.action.remove'],
]
const at = labels.map((label) => hint.indexOf(label))