feat(editor): « Citer » button and family labels in references
This commit is contained in:
1 parent
240c2ba0e7
commit
8c3fcca0b9
16 files changed
+507
-53
No files matched your search
@@ -277,8 +277,9 @@ test.describe('references dialog, view mode', () => {
|
|||||||
)
|
)
|
||||||
await showCitations(page)
|
await showCitations(page)
|
||||||
await expect(heads(page)).toHaveCount(0)
|
await expect(heads(page)).toHaveCount(0)
|
||||||
|
// Rev 6: « Dysfonction A » is a family, its empty line says so.
|
||||||
await expect(panel(page)).toContainText(
|
await expect(panel(page)).toContainText(
|
||||||
dict['editor.references.panel_empty'],
|
dict['editor.references.panel_empty_family'],
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -419,6 +420,33 @@ const removeRow = (page: Page, citation: string) =>
|
|||||||
page,
|
page,
|
||||||
new RegExp(`^${dict['editor.action.remove']} ${citation}`),
|
new RegExp(`^${dict['editor.action.remove']} ${citation}`),
|
||||||
).click()
|
).click()
|
||||||
|
const citeSelect = (page: Page) =>
|
||||||
|
citationsDialog(page).getByLabel(dict['editor.findings.reference_add'])
|
||||||
|
|
||||||
|
/** « Constat A » carries a name long enough to wrap in a dialog title at 320 px. */
|
||||||
|
const LONG_NAME =
|
||||||
|
'Constat A au nom particulièrement long, qui ne tient pas sur une seule ligne du titre'
|
||||||
|
function longNameShape(document: Record<string, unknown>) {
|
||||||
|
shape(document)
|
||||||
|
const zone = (document.finding_zones as { categories: unknown[] }[])[0]
|
||||||
|
const family = zone.categories[0] as { children: { name: unknown }[] }
|
||||||
|
family.children[0].name = { fr: LONG_NAME, en: LONG_NAME }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The ✕ of `dialog`: a box of at least 44 × 44 px, inside the viewport (Rev 6). */
|
||||||
|
async function expectCloseBox(page: Page, dialog: Locator, at: string) {
|
||||||
|
const close = dialog.getByRole('button', { name: dict['common.close'] })
|
||||||
|
const box = async () => (await close.boundingBox())!
|
||||||
|
// Polled: the panel scales in (0.96 to 1) right after it opens.
|
||||||
|
await expect
|
||||||
|
.poll(async () => (await box()).width, { message: `✕ width at ${at}` })
|
||||||
|
.toBeGreaterThanOrEqual(44)
|
||||||
|
expect((await box()).height, `✕ height at ${at}`).toBeGreaterThanOrEqual(44)
|
||||||
|
const { x, width } = await box()
|
||||||
|
expect(x + width, `✕ inside at ${at}`).toBeLessThanOrEqual(
|
||||||
|
page.viewportSize()!.width + 0.5,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
test.describe('references dialog, edit mode', () => {
|
test.describe('references dialog, edit mode', () => {
|
||||||
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
|
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
|
||||||
@@ -438,9 +466,9 @@ test.describe('references dialog, edit mode', () => {
|
|||||||
await editCitations(page)
|
await editCitations(page)
|
||||||
await expectAccessible(page, 'the references dialog, edit mode')
|
await expectAccessible(page, 'the references dialog, edit mode')
|
||||||
await removeRow(page, 'Référence A')
|
await removeRow(page, 'Référence A')
|
||||||
await citationsDialog(page)
|
await citeSelect(page).selectOption('ref-d')
|
||||||
.getByLabel(dict['editor.findings.reference_add'])
|
await expect(draftRows(page)).toHaveCount(2)
|
||||||
.selectOption('ref-d')
|
await inDialog(page, dict['editor.citations.cite']).click()
|
||||||
await expect(draftRows(page)).toHaveCount(3)
|
await expect(draftRows(page)).toHaveCount(3)
|
||||||
await inDialog(page, dict['editor.findings.save']).click()
|
await inDialog(page, dict['editor.findings.save']).click()
|
||||||
await expect(editButton(page)).toBeFocused()
|
await expect(editButton(page)).toBeFocused()
|
||||||
@@ -465,6 +493,40 @@ test.describe('references dialog, edit mode', () => {
|
|||||||
expect(nodeOf(saved).reference_ids).toEqual(['ref-a', 'ref-b', 'ref-c'])
|
expect(nodeOf(saved).reference_ids).toEqual(['ref-a', 'ref-b', 'ref-c'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('keyboard: ArrowDown on the select only chooses, ✕ closes without asking; axe', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
test.setTimeout(150_000)
|
||||||
|
await open(page)
|
||||||
|
await editCitations(page)
|
||||||
|
const cite = inDialog(page, dict['editor.citations.cite'])
|
||||||
|
await expect(cite).toBeDisabled()
|
||||||
|
await citeSelect(page).focus()
|
||||||
|
await page.keyboard.press('ArrowDown')
|
||||||
|
await expect(citeSelect(page)).not.toHaveValue('')
|
||||||
|
await expect(cite).toBeEnabled()
|
||||||
|
await expect(draftRows(page)).toHaveCount(3)
|
||||||
|
await expectAccessible(page, 'the edit mode with a choice not cited')
|
||||||
|
await inDialog(page, dict['common.close']).click()
|
||||||
|
await expect(page.locator('dialog[open]')).toHaveCount(1)
|
||||||
|
await expect(citationsDialog(page).getByText(confirmText)).toHaveCount(0)
|
||||||
|
await expect(historyButton(page, dict, 'undo')).toHaveAttribute(
|
||||||
|
'aria-disabled',
|
||||||
|
'true',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('the ✕ is a 44 px box beside a long title at 1280 px', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
test.setTimeout(150_000)
|
||||||
|
await open(page, longNameShape)
|
||||||
|
await openFinding(page, dict, 'Constat A')
|
||||||
|
await expectCloseBox(page, findingDialog(page), '1280 px')
|
||||||
|
await showCitations(page)
|
||||||
|
await expectCloseBox(page, citationsDialog(page), '1280 px, references')
|
||||||
|
})
|
||||||
|
|
||||||
test('a dirty draft: ✕ and Back ask, « Abandonner » writes nothing', async ({
|
test('a dirty draft: ✕ and Back ask, « Abandonner » writes nothing', async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -718,6 +780,18 @@ test.describe('references dialog, read-only at 375 px', () => {
|
|||||||
await expect(place(page, 'findings')).toBeVisible()
|
await expect(place(page, 'findings')).toBeVisible()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('the ✕ is a 44 px box beside a long title at 375 and 320 px @phone', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
test.setTimeout(150_000)
|
||||||
|
await open(page, longNameShape)
|
||||||
|
await openFinding(page, dict, 'Constat A')
|
||||||
|
await expectCloseBox(page, findingDialog(page), '375 px')
|
||||||
|
await page.setViewportSize({ width: 320, height: 640 })
|
||||||
|
await expectCloseBox(page, findingDialog(page), '320 px')
|
||||||
|
await expectNoHorizontalOverflow(page, 'the finding dialog at 320 px')
|
||||||
|
})
|
||||||
|
|
||||||
test('by touch: taps act on the references dialog only, the finding dialog under it stays @phone', async ({
|
test('by touch: taps act on the references dialog only, the finding dialog under it stays @phone', async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import ActionButton from '@/components/editor/fields/ActionButton'
|
|||||||
import { useItemMode } from '@/components/editor/findings/useItemMode'
|
import { useItemMode } from '@/components/editor/findings/useItemMode'
|
||||||
import Dialog from '@/components/ui/Dialog'
|
import Dialog from '@/components/ui/Dialog'
|
||||||
import { useEditorReadOnly } from '@/editor/editingContext'
|
import { useEditorReadOnly } from '@/editor/editingContext'
|
||||||
import type { EditorTarget } from '@/editor/navigation'
|
import { elementLabel, type EditorTarget } from '@/editor/navigation'
|
||||||
import { findingPath } from '@/editor/references/panel'
|
import { findingPath } from '@/editor/references/panel'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { Guards } from '@/editor/useEditorNavigation'
|
import type { Guards } from '@/editor/useEditorNavigation'
|
||||||
@@ -141,7 +141,7 @@ export default function CitationsDialog(props: CitationsDialogProps) {
|
|||||||
open={citedBy !== null}
|
open={citedBy !== null}
|
||||||
layer
|
layer
|
||||||
size="lg"
|
size="lg"
|
||||||
title={t(title)}
|
title={t(elementLabel(title, citedBy))}
|
||||||
titleId={CITATIONS_TITLE_ID}
|
titleId={CITATIONS_TITLE_ID}
|
||||||
returnFocus={props.returnFocus}
|
returnFocus={props.returnFocus}
|
||||||
onClose={() => (onClose() ? undefined : 'kept')}
|
onClose={() => (onClose() ? undefined : 'kept')}
|
||||||
|
|||||||
@@ -1,13 +1,27 @@
|
|||||||
import { useEffect, useRef } from 'react'
|
import { useEffect, useRef } from 'react'
|
||||||
import SelectField from '@/components/editor/fields/SelectField'
|
|
||||||
import Button from '@/components/ui/Button'
|
import Button from '@/components/ui/Button'
|
||||||
|
import FormField, { fieldDescribedBy } from '@/components/ui/FormField'
|
||||||
|
import Select from '@/components/ui/Select'
|
||||||
|
import type { SelectOption } from '@/components/editor/fields/SelectField'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
|
/** The select's choice (Rev 6): local to the form, never in the draft until « Citer ». */
|
||||||
|
export interface CiteChoice {
|
||||||
|
/** The placeholder, then the references the draft does not cite yet. */
|
||||||
|
options: readonly SelectOption[]
|
||||||
|
/** The chosen id while it is still offered, else '' (the placeholder). */
|
||||||
|
chosen: string
|
||||||
|
onChoose: (id: string) => void
|
||||||
|
/** « Enregistrer » found it chosen but not cited: the line at the select. */
|
||||||
|
pending: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export interface DraftListProps {
|
export interface DraftListProps {
|
||||||
/** The draft's cited ids, in the order they will be saved. */
|
/** The draft's cited ids, in the order they will be saved. */
|
||||||
ids: readonly string[]
|
ids: readonly string[]
|
||||||
readOnly: boolean
|
readOnly: boolean
|
||||||
|
choice: CiteChoice
|
||||||
onAdd: (id: string) => void
|
onAdd: (id: string) => void
|
||||||
onRemove: (id: string) => void
|
onRemove: (id: string) => void
|
||||||
/** « Modifier la référence »: the reference dialog over this one. */
|
/** « Modifier la référence »: the reference dialog over this one. */
|
||||||
@@ -19,8 +33,11 @@ export interface DraftListProps {
|
|||||||
/** The add choice: its id, so the focus can land on it once the last row is removed. */
|
/** The add choice: its id, so the focus can land on it once the last row is removed. */
|
||||||
const ADD_ID = 'citations-add-reference'
|
const ADD_ID = 'citations-add-reference'
|
||||||
|
|
||||||
|
/** « Citer »: its id, where a refused save puts the focus. */
|
||||||
|
export const CITE_ID = 'citations-cite-reference'
|
||||||
|
|
||||||
/** The references the draft does not cite yet, after the « choose » placeholder. */
|
/** The references the draft does not cite yet, after the « choose » placeholder. */
|
||||||
function useCitableOptions(ids: readonly string[]) {
|
export function useCitableOptions(ids: readonly string[]) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const doc = useSheetDocument()
|
const doc = useSheetDocument()
|
||||||
const options = (doc?.references ?? [])
|
const options = (doc?.references ?? [])
|
||||||
@@ -90,23 +107,64 @@ function DraftRow({ id, props, onRemove }: RowProps) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** « Citer une référence existante » among those not cited yet, and « Nouvelle référence ». */
|
/**
|
||||||
|
* « Citer une référence existante »: browsing or picking only chooses; « Citer » cites the
|
||||||
|
* choice, empties the select and gives it the focus back.
|
||||||
|
*/
|
||||||
|
function CiteField({ props }: { props: DraftListProps }) {
|
||||||
|
const t = useT()
|
||||||
|
const { choice } = props
|
||||||
|
const error = choice.pending
|
||||||
|
? t('editor.citations.pending_choice')
|
||||||
|
: undefined
|
||||||
|
const cite = () => {
|
||||||
|
props.onAdd(choice.chosen)
|
||||||
|
choice.onChoose('')
|
||||||
|
document.getElementById(ADD_ID)?.focus()
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<FormField
|
||||||
|
id={ADD_ID}
|
||||||
|
label={t('editor.findings.reference_add')}
|
||||||
|
error={error}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Select
|
||||||
|
id={ADD_ID}
|
||||||
|
value={choice.chosen}
|
||||||
|
onChange={(event) => choice.onChoose(event.target.value)}
|
||||||
|
aria-invalid={choice.pending}
|
||||||
|
aria-describedby={fieldDescribedBy(ADD_ID, undefined, error)}
|
||||||
|
className="min-w-0 flex-1"
|
||||||
|
>
|
||||||
|
{choice.options.map((option) => (
|
||||||
|
<option key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
<Button
|
||||||
|
id={CITE_ID}
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
disabled={choice.chosen === ''}
|
||||||
|
onClick={cite}
|
||||||
|
>
|
||||||
|
{t('editor.citations.cite')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</FormField>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The way to cite an existing reference (edit tier only), and « Nouvelle référence ». */
|
||||||
function AddRow({ props }: { props: DraftListProps }) {
|
function AddRow({ props }: { props: DraftListProps }) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const options = useCitableOptions(props.ids)
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-wrap items-end gap-2">
|
<div className="flex flex-wrap items-end gap-2">
|
||||||
{!props.readOnly && (
|
{!props.readOnly && <CiteField props={props} />}
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<SelectField
|
|
||||||
id={ADD_ID}
|
|
||||||
label={t('editor.findings.reference_add')}
|
|
||||||
value=""
|
|
||||||
options={options}
|
|
||||||
onCommit={(id) => id !== '' && props.onAdd(id)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||||
import { FormActions } from '@/components/editor/findings/DiscardConfirm'
|
import { FormActions } from '@/components/editor/findings/DiscardConfirm'
|
||||||
import ReadOnlyNotice from '@/components/editor/findings/ReadOnlyNotice'
|
import ReadOnlyNotice from '@/components/editor/findings/ReadOnlyNotice'
|
||||||
@@ -18,7 +18,10 @@ import { useEditCommand } from '@/editor/useEditCommand'
|
|||||||
import type { Guards } from '@/editor/useEditorNavigation'
|
import type { Guards } from '@/editor/useEditorNavigation'
|
||||||
import type { ReferenceMoves } from '@/editor/useReferenceMoves'
|
import type { ReferenceMoves } from '@/editor/useReferenceMoves'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import CitationsDraftList from './CitationsDraftList'
|
import CitationsDraftList, {
|
||||||
|
CITE_ID,
|
||||||
|
useCitableOptions,
|
||||||
|
} from './CitationsDraftList'
|
||||||
|
|
||||||
export interface CitationsEditFormProps {
|
export interface CitationsEditFormProps {
|
||||||
citedBy: ElementKey
|
citedBy: ElementKey
|
||||||
@@ -83,20 +86,53 @@ function useCreation(props: CitationsEditFormProps, form: Draft) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The select's choice (Rev 6): local, outside the draft (a choice alone is never asked
|
||||||
|
* about), shown only while the draft still offers it, else the placeholder.
|
||||||
|
*/
|
||||||
|
function useCiteChoice(ids: readonly string[]) {
|
||||||
|
const options = useCitableOptions(ids)
|
||||||
|
const [state, setState] = useState({ id: '', asked: false })
|
||||||
|
const chosen = options.some((o) => o.value === state.id) ? state.id : ''
|
||||||
|
return {
|
||||||
|
options,
|
||||||
|
chosen,
|
||||||
|
pending: state.asked && chosen !== '',
|
||||||
|
onChoose: (id: string) => setState({ id, asked: false }),
|
||||||
|
/** A choice waits for « Citer »: true, its line shows and « Citer » takes the focus. */
|
||||||
|
holdsSave: () => {
|
||||||
|
if (chosen === '') return false
|
||||||
|
setState({ id: chosen, asked: true })
|
||||||
|
document.getElementById(CITE_ID)?.focus()
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** The form's state: the draft, its guard, its save, its cancel and its creation. */
|
/** The form's state: the draft, its guard, its save, its cancel and its creation. */
|
||||||
function useCitationsForm(props: CitationsEditFormProps) {
|
function useCitationsForm(props: CitationsEditFormProps) {
|
||||||
const form = useFormDraft(NO_EDITS, props.guards, sameEdits, 'citations')
|
const form = useFormDraft(NO_EDITS, props.guards, sameEdits, 'citations')
|
||||||
const saving = useCitationsSave(props, form)
|
const saving = useCitationsSave(props, form)
|
||||||
|
const choice = useCiteChoice(saving.shown)
|
||||||
const cancel = () =>
|
const cancel = () =>
|
||||||
form.dirty && !props.readOnly
|
form.dirty && !props.readOnly
|
||||||
? form.guard.askToLeave()
|
? form.guard.askToLeave()
|
||||||
: props.onDone(false)
|
: props.onDone(false)
|
||||||
return { ...form, ...saving, cancel, create: useCreation(props, form) }
|
const submit = () => (choice.holdsSave() ? undefined : saving.save())
|
||||||
|
return {
|
||||||
|
...form,
|
||||||
|
...saving,
|
||||||
|
choice,
|
||||||
|
cancel,
|
||||||
|
submit,
|
||||||
|
create: useCreation(props, form),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The references dialog's edit mode (Rev 5): a draft of the citations (cite, remove, a new
|
* The references dialog's edit mode (Rev 5): a draft of the citations (cite, remove, a new
|
||||||
* reference cited), one `update` on « Enregistrer » (none when nothing changed), nothing on
|
* reference cited), one `update` on « Enregistrer » (none when nothing changed; refused
|
||||||
|
* while a choice in the select waits for « Citer », Rev 6), nothing on
|
||||||
* « Annuler » or a close. The draft's layer is `citations`: a dirty one is asked before a
|
* « Annuler » or a close. The draft's layer is `citations`: a dirty one is asked before a
|
||||||
* close, a Back or a leave. Read only: the draft stays, only « Abandonner » is left.
|
* close, a Back or a leave. Read only: the draft stays, only « Abandonner » is left.
|
||||||
*/
|
*/
|
||||||
@@ -115,13 +151,14 @@ export default function CitationsEditForm(props: CitationsEditFormProps) {
|
|||||||
noValidate
|
noValidate
|
||||||
onSubmit={(event) => {
|
onSubmit={(event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
form.save()
|
form.submit()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props.readOnly && <ReadOnlyNotice />}
|
{props.readOnly && <ReadOnlyNotice />}
|
||||||
<CitationsDraftList
|
<CitationsDraftList
|
||||||
ids={form.shown}
|
ids={form.shown}
|
||||||
readOnly={props.readOnly}
|
readOnly={props.readOnly}
|
||||||
|
choice={form.choice}
|
||||||
onAdd={(id) => form.set(addId(form.draft, id))}
|
onAdd={(id) => form.set(addId(form.draft, id))}
|
||||||
onRemove={(id) => form.set(removeId(form.draft, id))}
|
onRemove={(id) => form.set(removeId(form.draft, id))}
|
||||||
onEditReference={props.references.open}
|
onEditReference={props.references.open}
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
import type { LocalizedText, Reference } from '@faunosteo/core-wasm/types'
|
import type {
|
||||||
|
ElementKey,
|
||||||
|
LocalizedText,
|
||||||
|
Reference,
|
||||||
|
} from '@faunosteo/core-wasm/types'
|
||||||
import Icon from '@/components/ui/Icon'
|
import Icon from '@/components/ui/Icon'
|
||||||
import { targetOfKey, type EditorTarget } from '@/editor/navigation'
|
import {
|
||||||
|
elementLabel,
|
||||||
|
targetOfKey,
|
||||||
|
type EditorTarget,
|
||||||
|
} from '@/editor/navigation'
|
||||||
import { usePlural } from '@/editor/plural'
|
import { usePlural } from '@/editor/plural'
|
||||||
import type { CitationEntry } from '@/editor/references/panel'
|
import type { CitationEntry } from '@/editor/references/panel'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
@@ -47,19 +55,22 @@ function ShowAllLink({ onShowAll }: { onShowAll: () => void }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** « {n} références citées par ce constat » and the way to the whole library. */
|
/** « {n} références citées par ce constat » (or « cette famille ») and the whole library. */
|
||||||
function Summary({
|
function Summary({
|
||||||
count,
|
count,
|
||||||
|
citedBy,
|
||||||
onShowAll,
|
onShowAll,
|
||||||
}: {
|
}: {
|
||||||
count: number
|
count: number
|
||||||
|
citedBy: ElementKey
|
||||||
onShowAll: () => void
|
onShowAll: () => void
|
||||||
}) {
|
}) {
|
||||||
const plural = usePlural()
|
const plural = usePlural()
|
||||||
|
const label = elementLabel('editor.references.panel_count', citedBy)
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-wrap items-center justify-between gap-x-3">
|
<div className="flex flex-wrap items-center justify-between gap-x-3">
|
||||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
{count > 0 && plural('editor.references.panel_count', count)}
|
{count > 0 && plural(label, count)}
|
||||||
</p>
|
</p>
|
||||||
<ShowAllLink onShowAll={onShowAll} />
|
<ShowAllLink onShowAll={onShowAll} />
|
||||||
</div>
|
</div>
|
||||||
@@ -152,10 +163,10 @@ export default function CitationsPanel(props: Props) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FindingPath path={panel.path} />
|
<FindingPath path={panel.path} />
|
||||||
<Summary count={count} onShowAll={onShowAll} />
|
<Summary count={count} citedBy={props.citedBy} onShowAll={onShowAll} />
|
||||||
{count === 0 && (
|
{count === 0 && (
|
||||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
{t('editor.references.panel_empty')}
|
{t(elementLabel('editor.references.panel_empty', props.citedBy))}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<Entries panel={panel} props={props} />
|
<Entries panel={panel} props={props} />
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||||
import type { CiterItem } from '@/editor/references/citations'
|
import type { CiterItem } from '@/editor/references/citations'
|
||||||
import { sameKey } from '@/editor/findings/tree'
|
import { sameKey } from '@/editor/findings/tree'
|
||||||
|
import { elementLabel } from '@/editor/navigation'
|
||||||
import { usePlural } from '@/editor/plural'
|
import { usePlural } from '@/editor/plural'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
@@ -12,7 +13,7 @@ export default function CitersList({
|
|||||||
onGoTo,
|
onGoTo,
|
||||||
}: {
|
}: {
|
||||||
citers: readonly CiterItem[]
|
citers: readonly CiterItem[]
|
||||||
/** The finding the citations panel belongs to: its row carries « ce constat ». */
|
/** The panel's own element: its row carries « ce constat » or « cette famille ». */
|
||||||
current?: ElementKey
|
current?: ElementKey
|
||||||
onGoTo: (key: ElementKey) => void
|
onGoTo: (key: ElementKey) => void
|
||||||
}) {
|
}) {
|
||||||
@@ -26,6 +27,13 @@ export default function CitersList({
|
|||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
// The current family's row says « cette famille » once, without a second badge (Rev 6).
|
||||||
|
const isCurrent = (citer: CiterItem) =>
|
||||||
|
current !== undefined && sameKey(citer.key, current)
|
||||||
|
const ownLabel = elementLabel(
|
||||||
|
'editor.references.this_finding',
|
||||||
|
current ?? null,
|
||||||
|
)
|
||||||
// « Aller à » alone repeats per citer: the name says where each one goes (M6).
|
// « Aller à » alone repeats per citer: the name says where each one goes (M6).
|
||||||
const where = (citer: CiterItem) =>
|
const where = (citer: CiterItem) =>
|
||||||
[...citer.trail, citer.name].map((name) => name[locale]).join(' › ')
|
[...citer.trail, citer.name].map((name) => name[locale]).join(' › ')
|
||||||
@@ -43,12 +51,12 @@ export default function CitersList({
|
|||||||
{' › '}
|
{' › '}
|
||||||
</span>
|
</span>
|
||||||
{citer.name[locale]}
|
{citer.name[locale]}
|
||||||
{current && sameKey(citer.key, current) && (
|
{isCurrent(citer) && (
|
||||||
<span className="ml-1 rounded-md bg-[var(--color-surface-strong)] px-2 py-0.5 text-xs">
|
<span className="ml-1 rounded-md bg-[var(--color-surface-strong)] px-2 py-0.5 text-xs">
|
||||||
{t('editor.references.this_finding')}
|
{t(ownLabel)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{citer.isFamily && (
|
{citer.isFamily && !isCurrent(citer) && (
|
||||||
<span className="ml-1 rounded-md bg-[var(--color-surface-strong)] px-2 py-0.5 text-xs">
|
<span className="ml-1 rounded-md bg-[var(--color-surface-strong)] px-2 py-0.5 text-xs">
|
||||||
{t('editor.references.family')}
|
{t('editor.references.family')}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||||
import Button from '@/components/ui/Button'
|
import Button from '@/components/ui/Button'
|
||||||
import Icon from '@/components/ui/Icon'
|
import Icon from '@/components/ui/Icon'
|
||||||
|
import { elementLabel } from '@/editor/navigation'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,9 +11,12 @@ import { useT } from '@/i18n/useT'
|
|||||||
export default function NoResult({
|
export default function NoResult({
|
||||||
query,
|
query,
|
||||||
onClear,
|
onClear,
|
||||||
|
filteredBy,
|
||||||
}: {
|
}: {
|
||||||
query: string
|
query: string
|
||||||
onClear: () => void
|
onClear: () => void
|
||||||
|
/** The family or finding the list is filtered by, null for the whole library. */
|
||||||
|
filteredBy: ElementKey | null
|
||||||
}) {
|
}) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
// A filtered finding that cites nothing: no search to clear, the chip has the way out.
|
// A filtered finding that cites nothing: no search to clear, the chip has the way out.
|
||||||
@@ -21,7 +26,7 @@ export default function NoResult({
|
|||||||
data-testid="editor-references-no-result"
|
data-testid="editor-references-no-result"
|
||||||
className="text-sm text-[var(--color-ink-muted)]"
|
className="text-sm text-[var(--color-ink-muted)]"
|
||||||
>
|
>
|
||||||
{t('editor.references.panel_empty')}
|
{t(elementLabel('editor.references.panel_empty', filteredBy))}
|
||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import type { KeyboardEvent, RefObject } from 'react'
|
import type { KeyboardEvent, RefObject } from 'react'
|
||||||
|
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||||
import ActionButton from '@/components/editor/fields/ActionButton'
|
import ActionButton from '@/components/editor/fields/ActionButton'
|
||||||
import Icon from '@/components/ui/Icon'
|
import Icon from '@/components/ui/Icon'
|
||||||
import Input from '@/components/ui/Input'
|
import Input from '@/components/ui/Input'
|
||||||
import Select from '@/components/ui/Select'
|
import Select from '@/components/ui/Select'
|
||||||
|
import { elementLabel } from '@/editor/navigation'
|
||||||
import { usePlural } from '@/editor/plural'
|
import { usePlural } from '@/editor/plural'
|
||||||
import { REFERENCE_SORTS, type ReferenceSort } from '@/editor/references/sort'
|
import { REFERENCE_SORTS, type ReferenceSort } from '@/editor/references/sort'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
@@ -25,9 +27,11 @@ interface Props {
|
|||||||
filter: FilterChip | null
|
filter: FilterChip | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The finding filter: its name, « × » and « Revenir au constat ». */
|
/** The finding filter: its name, « × » and « Revenir au constat » (family wording for one). */
|
||||||
export interface FilterChip {
|
export interface FilterChip {
|
||||||
name: string
|
name: string
|
||||||
|
/** The filtering element: a family takes the family wording. */
|
||||||
|
key: ElementKey
|
||||||
onRemove: () => void
|
onRemove: () => void
|
||||||
onBack: () => void
|
onBack: () => void
|
||||||
}
|
}
|
||||||
@@ -39,7 +43,9 @@ const BUTTON =
|
|||||||
/** « Références du constat : X » with « × », and the way back to the finding. */
|
/** « Références du constat : X » with « × », and the way back to the finding. */
|
||||||
function FilterBar({ filter }: { filter: FilterChip }) {
|
function FilterBar({ filter }: { filter: FilterChip }) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const fill = (key: string) => t(key).replace('{name}', () => filter.name)
|
const label = (key: string) => elementLabel(key, filter.key)
|
||||||
|
const fill = (key: string) =>
|
||||||
|
t(label(key)).replace('{name}', () => filter.name)
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-testid="editor-references-filter"
|
data-testid="editor-references-filter"
|
||||||
@@ -61,7 +67,7 @@ function FilterBar({ filter }: { filter: FilterChip }) {
|
|||||||
onClick={filter.onBack}
|
onClick={filter.onBack}
|
||||||
className={`${BUTTON} text-sm text-[var(--color-accent-strong)] underline`}
|
className={`${BUTTON} text-sm text-[var(--color-accent-strong)] underline`}
|
||||||
>
|
>
|
||||||
{t('editor.references.filter_back')}
|
{t(label('editor.references.filter_back'))}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
useFocusRequest,
|
useFocusRequest,
|
||||||
type FocusRequest,
|
type FocusRequest,
|
||||||
} from '@/editor/focusRequest'
|
} from '@/editor/focusRequest'
|
||||||
|
import { elementLabel } from '@/editor/navigation'
|
||||||
import { citersOf } from '@/editor/references/citations'
|
import { citersOf } from '@/editor/references/citations'
|
||||||
import {
|
import {
|
||||||
citedIds,
|
citedIds,
|
||||||
@@ -33,7 +34,8 @@ function useFilterFinding(layer: ReferenceLayer) {
|
|||||||
const gone = doc !== null && layer.filter !== null && finding === null
|
const gone = doc !== null && layer.filter !== null && finding === null
|
||||||
// The vanished finding is the trigger; the move and its wording are the latest ones.
|
// The vanished finding is the trigger; the move and its wording are the latest ones.
|
||||||
const clear = useRef<() => void>(() => undefined)
|
const clear = useRef<() => void>(() => undefined)
|
||||||
clear.current = () => layer.clearFilter(t('editor.references.filter_gone'))
|
const gonePhrase = elementLabel('editor.references.filter_gone', layer.filter)
|
||||||
|
clear.current = () => layer.clearFilter(t(gonePhrase))
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (gone) clear.current()
|
if (gone) clear.current()
|
||||||
}, [gone])
|
}, [gone])
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
type FindingKind,
|
type FindingKind,
|
||||||
} from '@/editor/findings/tree'
|
} from '@/editor/findings/tree'
|
||||||
import { useFocusRequest, visibleElement } from '@/editor/focusRequest'
|
import { useFocusRequest, visibleElement } from '@/editor/focusRequest'
|
||||||
|
import { elementLabel } from '@/editor/navigation'
|
||||||
import { useEditorStore } from '@/editor/state/editorStore'
|
import { useEditorStore } from '@/editor/state/editorStore'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
import type { EditorPlaceProps, FindingLayer } from '@/editor/tabs'
|
import type { EditorPlaceProps, FindingLayer } from '@/editor/tabs'
|
||||||
@@ -109,9 +110,12 @@ function useGoneRule(layer: FindingLayer, loaded: boolean) {
|
|||||||
if (key === null || currentItems().some(present)) return
|
if (key === null || currentItems().some(present)) return
|
||||||
if (handled.current === stamp) return
|
if (handled.current === stamp) return
|
||||||
handled.current = stamp
|
handled.current = stamp
|
||||||
|
// A family's own dialog names the family; a creation keeps the finding wording.
|
||||||
|
const shown = 'key' in view ? view.key : null
|
||||||
|
const gone = t(elementLabel('editor.findings.gone', shown))
|
||||||
// After this commit's effects: a tile in edit re-registers its guard in them, and the
|
// After this commit's effects: a tile in edit re-registers its guard in them, and the
|
||||||
// forced close below must still be able to ask it.
|
// forced close below must still be able to ask it.
|
||||||
queueMicrotask(() => layer.replace(null, t('editor.findings.gone')))
|
queueMicrotask(() => layer.replace(null, gone))
|
||||||
}, [loaded, view, layer, t])
|
}, [loaded, view, layer, t])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ function useFilterChip(lib: ReferenceLibraryState, layer: ReferenceLayer) {
|
|||||||
const key = layer.filter
|
const key = layer.filter
|
||||||
return {
|
return {
|
||||||
name: finding.name[locale],
|
name: finding.name[locale],
|
||||||
|
key,
|
||||||
onRemove: () => layer.clearFilter(),
|
onRemove: () => layer.clearFilter(),
|
||||||
onBack: () => layer.backToFinding(key),
|
onBack: () => layer.backToFinding(key),
|
||||||
}
|
}
|
||||||
@@ -90,7 +91,11 @@ function LibraryNotices(body: BodyProps) {
|
|||||||
)}
|
)}
|
||||||
{body.lib.all.length === 0 && <EmptyLine />}
|
{body.lib.all.length === 0 && <EmptyLine />}
|
||||||
{body.lib.all.length > 0 && shown.positions.length === 0 && (
|
{body.lib.all.length > 0 && shown.positions.length === 0 && (
|
||||||
<NoResult query={shown.view.query} onClear={body.act.clearSearch} />
|
<NoResult
|
||||||
|
query={shown.view.query}
|
||||||
|
onClear={body.act.clearSearch}
|
||||||
|
filteredBy={body.props.layer.filter}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{reorderable && shown.positions.length > 0 && (
|
{reorderable && shown.positions.length > 0 && (
|
||||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
|
|||||||
@@ -198,6 +198,16 @@ export function isCitable(key: ElementKey): boolean {
|
|||||||
return key.kind === 'finding' && key.path.length > 0
|
return key.kind === 'finding' && key.path.length > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A family: a finding key of one id (read from the key, so a vanished family is one too). */
|
||||||
|
export function isFamilyKey(key: ElementKey): boolean {
|
||||||
|
return key.kind === 'finding' && key.path.length === 1
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The label key that names `key`: its `_family` variant for a family (Rev 6). */
|
||||||
|
export function elementLabel(label: string, key: ElementKey | null): string {
|
||||||
|
return key && isFamilyKey(key) ? `${label}_family` : label
|
||||||
|
}
|
||||||
|
|
||||||
/** Only a citable element has a citations dialog: any other key leaves the state as it is. */
|
/** Only a citable element has a citations dialog: any other key leaves the state as it is. */
|
||||||
function openCitations(state: NavigationState, citedBy: ElementKey) {
|
function openCitations(state: NavigationState, citedBy: ElementKey) {
|
||||||
const finding = { key: citedBy, citations: true }
|
const finding = { key: citedBy, citations: true }
|
||||||
|
|||||||
@@ -1229,15 +1229,23 @@ export const en: Dict = {
|
|||||||
'editor.annotations.deselected': 'No annotation selected.',
|
'editor.annotations.deselected': 'No annotation selected.',
|
||||||
'editor.references.search': 'Search a reference',
|
'editor.references.search': 'Search a reference',
|
||||||
'editor.references.dialog_title': 'References of the finding',
|
'editor.references.dialog_title': 'References of the finding',
|
||||||
|
'editor.references.dialog_title_family': 'References of the family',
|
||||||
'editor.citations.edit': 'Edit',
|
'editor.citations.edit': 'Edit',
|
||||||
'editor.citations.edit_title': 'Edit the references of the finding',
|
'editor.citations.edit_title': 'Edit the references of the finding',
|
||||||
|
'editor.citations.edit_title_family': 'Edit the references of the family',
|
||||||
'editor.citations.edit_reference': 'Edit the reference',
|
'editor.citations.edit_reference': 'Edit the reference',
|
||||||
'editor.citations.new_reference': 'New reference',
|
'editor.citations.new_reference': 'New reference',
|
||||||
|
'editor.citations.cite': 'Cite',
|
||||||
|
'editor.citations.pending_choice': 'Reference chosen but not cited yet: choose « Cite » or go back to the empty choice.',
|
||||||
'editor.references.panel_count_one': '{count} reference cited by this finding',
|
'editor.references.panel_count_one': '{count} reference cited by this finding',
|
||||||
'editor.references.panel_count_other': '{count} references cited by this finding',
|
'editor.references.panel_count_other': '{count} references cited by this finding',
|
||||||
|
'editor.references.panel_count_family_one': '{count} reference cited by this family',
|
||||||
|
'editor.references.panel_count_family_other': '{count} references cited by this family',
|
||||||
'editor.references.panel_show_all': 'Show all in the References tab',
|
'editor.references.panel_show_all': 'Show all in the References tab',
|
||||||
'editor.references.panel_empty': 'This finding cites no reference.',
|
'editor.references.panel_empty': 'This finding cites no reference.',
|
||||||
|
'editor.references.panel_empty_family': 'This family cites no reference.',
|
||||||
'editor.references.this_finding': 'this finding',
|
'editor.references.this_finding': 'this finding',
|
||||||
|
'editor.references.this_finding_family': 'this family',
|
||||||
'editor.references.missing': 'Reference not found',
|
'editor.references.missing': 'Reference not found',
|
||||||
'editor.references.cited_one': 'Cited {count} time',
|
'editor.references.cited_one': 'Cited {count} time',
|
||||||
'editor.references.cited_other': 'Cited {count} times',
|
'editor.references.cited_other': 'Cited {count} times',
|
||||||
@@ -1259,9 +1267,13 @@ export const en: Dict = {
|
|||||||
'editor.references.added_show': 'Show',
|
'editor.references.added_show': 'Show',
|
||||||
'editor.references.gone': 'This reference no longer exists',
|
'editor.references.gone': 'This reference no longer exists',
|
||||||
'editor.references.filter_chip': 'References of the finding: {name}',
|
'editor.references.filter_chip': 'References of the finding: {name}',
|
||||||
|
'editor.references.filter_chip_family': 'References of the family: {name}',
|
||||||
'editor.references.filter_remove': 'Remove the filter of the finding {name}',
|
'editor.references.filter_remove': 'Remove the filter of the finding {name}',
|
||||||
|
'editor.references.filter_remove_family': 'Remove the filter of the family {name}',
|
||||||
'editor.references.filter_back': 'Back to the finding',
|
'editor.references.filter_back': 'Back to the finding',
|
||||||
|
'editor.references.filter_back_family': 'Back to the family',
|
||||||
'editor.references.filter_gone': 'The finding no longer exists: the filter is removed',
|
'editor.references.filter_gone': 'The finding no longer exists: the filter is removed',
|
||||||
|
'editor.references.filter_gone_family': 'The family no longer exists: the filter is removed',
|
||||||
'editor.references.clear_search': 'Clear the search',
|
'editor.references.clear_search': 'Clear the search',
|
||||||
'editor.references.sort_by': 'Sort by',
|
'editor.references.sort_by': 'Sort by',
|
||||||
'editor.references.sort.sheet': 'Sheet order',
|
'editor.references.sort.sheet': 'Sheet order',
|
||||||
@@ -1649,6 +1661,7 @@ export const en: Dict = {
|
|||||||
'editor.findings.discard': 'Discard',
|
'editor.findings.discard': 'Discard',
|
||||||
'editor.findings.draft_dropped': 'Entry discarded',
|
'editor.findings.draft_dropped': 'Entry discarded',
|
||||||
'editor.findings.gone': 'This finding no longer exists',
|
'editor.findings.gone': 'This finding no longer exists',
|
||||||
|
'editor.findings.gone_family': 'This family no longer exists',
|
||||||
// Provisional EN, pending the owner's wording.
|
// Provisional EN, pending the owner's wording.
|
||||||
'editor.leave.draft_dropped':
|
'editor.leave.draft_dropped':
|
||||||
'An unsaved entry was discarded when you left the editor',
|
'An unsaved entry was discarded when you left the editor',
|
||||||
|
|||||||
@@ -1260,15 +1260,23 @@ export const fr: Dict = {
|
|||||||
'editor.annotations.deselected': 'Aucune annotation sélectionnée.',
|
'editor.annotations.deselected': 'Aucune annotation sélectionnée.',
|
||||||
'editor.references.search': 'Rechercher une référence',
|
'editor.references.search': 'Rechercher une référence',
|
||||||
'editor.references.dialog_title': 'Références du constat',
|
'editor.references.dialog_title': 'Références du constat',
|
||||||
|
'editor.references.dialog_title_family': 'Références de la famille',
|
||||||
'editor.citations.edit': 'Modifier',
|
'editor.citations.edit': 'Modifier',
|
||||||
'editor.citations.edit_title': 'Modifier les références du constat',
|
'editor.citations.edit_title': 'Modifier les références du constat',
|
||||||
|
'editor.citations.edit_title_family': 'Modifier les références de la famille',
|
||||||
'editor.citations.edit_reference': 'Modifier la référence',
|
'editor.citations.edit_reference': 'Modifier la référence',
|
||||||
'editor.citations.new_reference': 'Nouvelle référence',
|
'editor.citations.new_reference': 'Nouvelle référence',
|
||||||
|
'editor.citations.cite': 'Citer',
|
||||||
|
'editor.citations.pending_choice': 'Référence choisie mais pas encore citée : choisissez « Citer » ou revenez au choix vide.',
|
||||||
'editor.references.panel_count_one': '{count} référence citée par ce constat',
|
'editor.references.panel_count_one': '{count} référence citée par ce constat',
|
||||||
'editor.references.panel_count_other': '{count} références citées par ce constat',
|
'editor.references.panel_count_other': '{count} références citées par ce constat',
|
||||||
|
'editor.references.panel_count_family_one': '{count} référence citée par cette famille',
|
||||||
|
'editor.references.panel_count_family_other': '{count} références citées par cette famille',
|
||||||
'editor.references.panel_show_all': 'Tout afficher dans l\'onglet Références',
|
'editor.references.panel_show_all': 'Tout afficher dans l\'onglet Références',
|
||||||
'editor.references.panel_empty': 'Ce constat ne cite aucune référence.',
|
'editor.references.panel_empty': 'Ce constat ne cite aucune référence.',
|
||||||
|
'editor.references.panel_empty_family': 'Cette famille ne cite aucune référence.',
|
||||||
'editor.references.this_finding': 'ce constat',
|
'editor.references.this_finding': 'ce constat',
|
||||||
|
'editor.references.this_finding_family': 'cette famille',
|
||||||
'editor.references.missing': 'Référence introuvable',
|
'editor.references.missing': 'Référence introuvable',
|
||||||
'editor.references.cited_one': 'Citée {count} fois',
|
'editor.references.cited_one': 'Citée {count} fois',
|
||||||
'editor.references.cited_other': 'Citée {count} fois',
|
'editor.references.cited_other': 'Citée {count} fois',
|
||||||
@@ -1290,9 +1298,13 @@ export const fr: Dict = {
|
|||||||
'editor.references.added_show': 'Afficher',
|
'editor.references.added_show': 'Afficher',
|
||||||
'editor.references.gone': "Cette référence n'existe plus",
|
'editor.references.gone': "Cette référence n'existe plus",
|
||||||
'editor.references.filter_chip': 'Références du constat : {name}',
|
'editor.references.filter_chip': 'Références du constat : {name}',
|
||||||
|
'editor.references.filter_chip_family': 'Références de la famille : {name}',
|
||||||
'editor.references.filter_remove': 'Retirer le filtre du constat {name}',
|
'editor.references.filter_remove': 'Retirer le filtre du constat {name}',
|
||||||
|
'editor.references.filter_remove_family': 'Retirer le filtre de la famille {name}',
|
||||||
'editor.references.filter_back': 'Revenir au constat',
|
'editor.references.filter_back': 'Revenir au constat',
|
||||||
|
'editor.references.filter_back_family': 'Revenir à la famille',
|
||||||
'editor.references.filter_gone': "Le constat n'existe plus : le filtre est retiré",
|
'editor.references.filter_gone': "Le constat n'existe plus : le filtre est retiré",
|
||||||
|
'editor.references.filter_gone_family': "La famille n'existe plus : le filtre est retiré",
|
||||||
'editor.references.clear_search': 'Effacer la recherche',
|
'editor.references.clear_search': 'Effacer la recherche',
|
||||||
'editor.references.sort_by': 'Trier par',
|
'editor.references.sort_by': 'Trier par',
|
||||||
'editor.references.sort.sheet': 'Ordre de la fiche',
|
'editor.references.sort.sheet': 'Ordre de la fiche',
|
||||||
@@ -1679,6 +1691,7 @@ export const fr: Dict = {
|
|||||||
'editor.findings.discard': 'Abandonner',
|
'editor.findings.discard': 'Abandonner',
|
||||||
'editor.findings.draft_dropped': 'Saisie abandonnée',
|
'editor.findings.draft_dropped': 'Saisie abandonnée',
|
||||||
'editor.findings.gone': "Ce constat n'existe plus",
|
'editor.findings.gone': "Ce constat n'existe plus",
|
||||||
|
'editor.findings.gone_family': "Cette famille n'existe plus",
|
||||||
'editor.leave.draft_dropped':
|
'editor.leave.draft_dropped':
|
||||||
"Une saisie non enregistrée a été abandonnée en quittant l'éditeur",
|
"Une saisie non enregistrée a été abandonnée en quittant l'éditeur",
|
||||||
'editor.findings.flip_narrow': 'Élargissez la fenêtre pour poursuivre : votre saisie est conservée.',
|
'editor.findings.flip_narrow': 'Élargissez la fenêtre pour poursuivre : votre saisie est conservée.',
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
/** Rev 5 Task 12: the references dialog's edit mode (draft, save, guards, stacked dialogs). */
|
/** Rev 5 Task 12: the references dialog's edit mode (draft, save, guards, stacked dialogs). */
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import { act, cleanup, screen, waitFor, within } from '@testing-library/react'
|
import {
|
||||||
|
act,
|
||||||
|
cleanup,
|
||||||
|
fireEvent,
|
||||||
|
screen,
|
||||||
|
waitFor,
|
||||||
|
within,
|
||||||
|
} from '@testing-library/react'
|
||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
import type { Location, NavigateFunction } from 'react-router-dom'
|
import type { Location, NavigateFunction } from 'react-router-dom'
|
||||||
import { flushAfterModals } from '@/components/ui/afterModalsClosed'
|
import { flushAfterModals } from '@/components/ui/afterModalsClosed'
|
||||||
@@ -182,11 +189,13 @@ const removeRow = (user: User, citation: RegExp) =>
|
|||||||
name: new RegExp(`^Retirer ${citation.source}`),
|
name: new RegExp(`^Retirer ${citation.source}`),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
const cite = (user: User, id: string) =>
|
const select = () =>
|
||||||
user.selectOptions(
|
inCitations().getByLabelText('Citer une référence existante')
|
||||||
inCitations().getByLabelText('Citer une référence existante'),
|
/** Rev 6: a choice in the select, then « Citer ». */
|
||||||
id,
|
async function cite(user: User, id: string) {
|
||||||
)
|
await user.selectOptions(select(), id)
|
||||||
|
await user.click(button('Citer'))
|
||||||
|
}
|
||||||
|
|
||||||
describe('the « Modifier » of the references dialog', () => {
|
describe('the « Modifier » of the references dialog', () => {
|
||||||
it('edit mode: no history entry, no « Tout afficher », no « Aller à »', async () => {
|
it('edit mode: no history entry, no « Tout afficher », no « Aller à »', async () => {
|
||||||
@@ -295,6 +304,93 @@ describe('the draft', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('« Citer » (Rev 6)', () => {
|
||||||
|
const citeButton = () => button('Citer')
|
||||||
|
const pendingLine =
|
||||||
|
'Référence choisie mais pas encore citée : choisissez « Citer » ou revenez au choix vide.'
|
||||||
|
|
||||||
|
it('a choice or an arrow key leaves the draft clean: ✕ closes without a question', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await editCitations(user)
|
||||||
|
expect(citeButton()).toBeDisabled()
|
||||||
|
await user.selectOptions(select(), 'ref-b')
|
||||||
|
fireEvent.keyDown(select(), { key: 'ArrowDown' })
|
||||||
|
fireEvent.change(select(), { target: { value: 'ref-b' } })
|
||||||
|
expect(rows()).toEqual(['ref-a', 'ref-c'])
|
||||||
|
expect(citeButton()).toBeEnabled()
|
||||||
|
await user.click(button('Fermer'))
|
||||||
|
await waitFor(() => expect(citations()).toBeUndefined())
|
||||||
|
expect(undos()).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('« Citer » cites once, resets and focuses the select, stays in edit mode', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await editCitations(user)
|
||||||
|
await user.selectOptions(select(), 'ref-b')
|
||||||
|
expect(citeButton()).toHaveAttribute('type', 'button')
|
||||||
|
await user.click(citeButton())
|
||||||
|
expect(rows()).toEqual(['ref-a', 'ref-c', 'ref-b'])
|
||||||
|
expect(select()).toHaveValue('')
|
||||||
|
expect(select()).toHaveFocus()
|
||||||
|
expect(citeButton()).toBeDisabled()
|
||||||
|
await user.click(citeButton())
|
||||||
|
expect(rows()).toEqual(['ref-a', 'ref-c', 'ref-b'])
|
||||||
|
expect(
|
||||||
|
inCitations().getByRole('heading', {
|
||||||
|
name: 'Modifier les références du constat',
|
||||||
|
}),
|
||||||
|
).toBeVisible()
|
||||||
|
expect(undos()).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a choice no longer offered goes back to the placeholder', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await editCitations(user)
|
||||||
|
await user.selectOptions(select(), 'ref-b')
|
||||||
|
act(() => {
|
||||||
|
store.getState().commit({
|
||||||
|
op: 'remove',
|
||||||
|
key: { kind: 'reference', id: 'ref-b' },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
await waitFor(() => expect(select()).toHaveValue(''))
|
||||||
|
expect(citeButton()).toBeDisabled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('« Enregistrer » with a choice not cited refuses: the line, focus on « Citer »', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await editCitations(user)
|
||||||
|
await user.selectOptions(select(), 'ref-b')
|
||||||
|
await user.click(button('Enregistrer'))
|
||||||
|
expect(undos()).toBe(0)
|
||||||
|
expect(inCitations().getByRole('alert')).toHaveTextContent(pendingLine)
|
||||||
|
expect(citeButton()).toHaveFocus()
|
||||||
|
expect(
|
||||||
|
inCitations().getByRole('heading', {
|
||||||
|
name: 'Modifier les références du constat',
|
||||||
|
}),
|
||||||
|
).toBeVisible()
|
||||||
|
await user.selectOptions(select(), '')
|
||||||
|
expect(inCitations().queryByText(pendingLine)).toBeNull()
|
||||||
|
await user.click(button('Enregistrer'))
|
||||||
|
await waitFor(() => expect(button('Modifier')).toHaveFocus())
|
||||||
|
expect(undos()).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('read only: no select and no « Citer »', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await editCitations(user)
|
||||||
|
act(() => {
|
||||||
|
setWidth(900)
|
||||||
|
window.dispatchEvent(new Event('resize'))
|
||||||
|
})
|
||||||
|
expect(inCitations().queryByRole('button', { name: 'Citer' })).toBeNull()
|
||||||
|
expect(
|
||||||
|
inCitations().queryByLabelText('Citer une référence existante'),
|
||||||
|
).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const live = () =>
|
const live = () =>
|
||||||
document.querySelector('p.sr-only[aria-live="polite"]')!.textContent ?? ''
|
document.querySelector('p.sr-only[aria-live="polite"]')!.textContent ?? ''
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ const ref = (id: string, citation: string, url = '', doi = '') =>
|
|||||||
},
|
},
|
||||||
}) as const
|
}) as const
|
||||||
|
|
||||||
function sheetText(): string {
|
function sheetText(family = ['ref-a', 'ref-b']): string {
|
||||||
let text = baseText()
|
let text = baseText()
|
||||||
text = insert(text, ref('ref-a', 'Barone, Ostéologie'))
|
text = insert(text, ref('ref-a', 'Barone, Ostéologie'))
|
||||||
text = insert(text, ref('ref-b', 'Denoix', 'https://exemple.org/Épaule'))
|
text = insert(text, ref('ref-b', 'Denoix', 'https://exemple.org/Épaule'))
|
||||||
@@ -77,7 +77,7 @@ function sheetText(): string {
|
|||||||
kind: 'dysfunction',
|
kind: 'dysfunction',
|
||||||
name: name('Cat A'),
|
name: name('Cat A'),
|
||||||
description: {},
|
description: {},
|
||||||
reference_ids: ['ref-a', 'ref-b'],
|
reference_ids: family,
|
||||||
review_status: 'to_confirm',
|
review_status: 'to_confirm',
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
@@ -86,8 +86,8 @@ function sheetText(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** The sheet plus one finding node under Cat A (default: citing ref-a and ref-c). */
|
/** The sheet plus one finding node under Cat A (default: citing ref-a and ref-c). */
|
||||||
function nodeText(ids = ['ref-a', 'ref-c']): string {
|
function nodeText(ids = ['ref-a', 'ref-c'], family?: string[]): string {
|
||||||
return edit(sheetText(), {
|
return edit(sheetText(family), {
|
||||||
op: 'insert',
|
op: 'insert',
|
||||||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||||
element: {
|
element: {
|
||||||
@@ -590,3 +590,115 @@ describe('the panel review fixes', () => {
|
|||||||
await focusIs(heading)
|
await focusIs(heading)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('the family wording (Rev 6)', () => {
|
||||||
|
const familyHeading = (name: string) =>
|
||||||
|
within(citationsDialog()).getByRole('heading', { name })
|
||||||
|
const chip = () => screen.getByTestId('editor-references-filter')
|
||||||
|
const showAll = (user: User) =>
|
||||||
|
user.click(
|
||||||
|
within(panel()).getByRole('button', {
|
||||||
|
name: "Tout afficher dans l'onglet Références",
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
it('a family: dialog title, count, its own tile row, edit title', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await select(user, /Cat A/)
|
||||||
|
await user.click(trigger())
|
||||||
|
await focusIs(closeButton)
|
||||||
|
expect(familyHeading('Références de la famille')).toBeVisible()
|
||||||
|
expect(panel()).toHaveTextContent('2 références citées par cette famille')
|
||||||
|
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||||
|
const tile = tiles()[0] as HTMLElement
|
||||||
|
expect(within(tile).getByText('cette famille')).toBeInTheDocument()
|
||||||
|
expect(within(tile).queryByText('famille')).toBeNull()
|
||||||
|
await user.click(
|
||||||
|
within(citationsDialog()).getByRole('button', { name: 'Modifier' }),
|
||||||
|
)
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(
|
||||||
|
familyHeading('Modifier les références de la famille'),
|
||||||
|
).toBeVisible(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a finding keeps the finding wording', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await openFromFinding(user)
|
||||||
|
expect(heading()).toBeVisible()
|
||||||
|
expect(panel()).toHaveTextContent('2 références citées par ce constat')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('an empty family: the empty line, then the filtered tab names the family', async () => {
|
||||||
|
const user = await mount(1280, nodeText(['ref-a', 'ref-c'], []))
|
||||||
|
await select(user, /Cat A/)
|
||||||
|
await user.click(trigger('0 référence'))
|
||||||
|
await focusIs(closeButton)
|
||||||
|
expect(panel()).toHaveTextContent('Cette famille ne cite aucune référence.')
|
||||||
|
await showAll(user)
|
||||||
|
await closed()
|
||||||
|
expect(chip()).toHaveTextContent('Références de la famille : Cat A')
|
||||||
|
expect(
|
||||||
|
within(chip()).getByRole('button', {
|
||||||
|
name: 'Retirer le filtre de la famille Cat A',
|
||||||
|
}),
|
||||||
|
).toBeVisible()
|
||||||
|
expect(
|
||||||
|
within(chip()).getByRole('button', { name: 'Revenir à la famille' }),
|
||||||
|
).toBeVisible()
|
||||||
|
expect(screen.getByTestId('editor-references-no-result')).toHaveTextContent(
|
||||||
|
'Cette famille ne cite aucune référence.',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a filtered family removed by an undo says the family is gone', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
act(() => {
|
||||||
|
store.getState().commit({
|
||||||
|
op: 'insert',
|
||||||
|
parent: { kind: 'zone', id: 'zone-a' },
|
||||||
|
element: {
|
||||||
|
kind: 'finding_category',
|
||||||
|
value: {
|
||||||
|
id: 'fcat-b',
|
||||||
|
kind: 'dysfunction',
|
||||||
|
name: name('Cat B'),
|
||||||
|
description: {},
|
||||||
|
reference_ids: ['ref-c'],
|
||||||
|
review_status: 'to_confirm',
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
await select(user, /Cat B/)
|
||||||
|
await user.click(trigger('1 référence'))
|
||||||
|
await showAll(user)
|
||||||
|
await closed()
|
||||||
|
expect(chip()).toHaveTextContent('Références de la famille : Cat B')
|
||||||
|
act(() => {
|
||||||
|
store.getState().undoStep()
|
||||||
|
})
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(live()).toHaveTextContent(
|
||||||
|
"La famille n'existe plus : le filtre est retiré",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a family that vanishes closes its dialog and says the family is gone', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await select(user, /Cat A/)
|
||||||
|
act(() => {
|
||||||
|
store.getState().commit({
|
||||||
|
op: 'remove',
|
||||||
|
key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
await waitFor(() => expect(findingDialog()).toBeNull())
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(live()).toHaveTextContent("Cette famille n'existe plus"),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in new issue
Block a user