fix(editor): stale cite choice reset, pending line under the add row
This commit is contained in:
1 parent
70eb2fcbb4
commit
1d119c3684
6 files changed
+91
-29
No files matched your search
@@ -493,7 +493,7 @@ 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 ({
|
test('ArrowDown only chooses, a refused save stays level, ✕ asks nothing; axe', async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
test.setTimeout(150_000)
|
test.setTimeout(150_000)
|
||||||
@@ -507,6 +507,23 @@ test.describe('references dialog, edit mode', () => {
|
|||||||
await expect(cite).toBeEnabled()
|
await expect(cite).toBeEnabled()
|
||||||
await expect(draftRows(page)).toHaveCount(3)
|
await expect(draftRows(page)).toHaveCount(3)
|
||||||
await expectAccessible(page, 'the edit mode with a choice not cited')
|
await expectAccessible(page, 'the edit mode with a choice not cited')
|
||||||
|
// « Enregistrer » refuses the pending choice; its line leaves both buttons level.
|
||||||
|
await inDialog(page, dict['editor.findings.save']).click()
|
||||||
|
await expect(citationsDialog(page).getByRole('alert')).toHaveText(
|
||||||
|
dict['editor.citations.pending_choice'],
|
||||||
|
)
|
||||||
|
await expect(cite).toBeFocused()
|
||||||
|
const middle = async (target: Locator) => {
|
||||||
|
const box = (await target.boundingBox())!
|
||||||
|
return box.y + box.height / 2
|
||||||
|
}
|
||||||
|
const level = await middle(citeSelect(page))
|
||||||
|
for (const control of [
|
||||||
|
cite,
|
||||||
|
inDialog(page, dict['editor.citations.new_reference']),
|
||||||
|
]) {
|
||||||
|
expect(Math.abs((await middle(control)) - level)).toBeLessThanOrEqual(2)
|
||||||
|
}
|
||||||
await inDialog(page, dict['common.close']).click()
|
await inDialog(page, dict['common.close']).click()
|
||||||
await expect(page.locator('dialog[open]')).toHaveCount(1)
|
await expect(page.locator('dialog[open]')).toHaveCount(1)
|
||||||
await expect(citationsDialog(page).getByText(confirmText)).toHaveCount(0)
|
await expect(citationsDialog(page).getByText(confirmText)).toHaveCount(0)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useEffect, useRef } from 'react'
|
|||||||
import type { Reference } from '@faunosteo/core-wasm/types'
|
import type { Reference } from '@faunosteo/core-wasm/types'
|
||||||
import Badge from '@/components/ui/Badge'
|
import Badge from '@/components/ui/Badge'
|
||||||
import Button from '@/components/ui/Button'
|
import Button from '@/components/ui/Button'
|
||||||
import FormField, { fieldDescribedBy } from '@/components/ui/FormField'
|
import FormField from '@/components/ui/FormField'
|
||||||
import Select from '@/components/ui/Select'
|
import Select from '@/components/ui/Select'
|
||||||
import type { SelectOption } from '@/components/editor/fields/SelectField'
|
import type { SelectOption } from '@/components/editor/fields/SelectField'
|
||||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||||
@@ -37,6 +37,9 @@ 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'
|
||||||
|
|
||||||
|
/** The line of a choice not cited at « Enregistrer » (Rev 6), described by the select. */
|
||||||
|
const PENDING_ID = 'citations-pending-choice'
|
||||||
|
|
||||||
/** « Citer »: its id, where a refused save puts the focus. */
|
/** « Citer »: its id, where a refused save puts the focus. */
|
||||||
export const CITE_ID = 'citations-cite-reference'
|
export const CITE_ID = 'citations-cite-reference'
|
||||||
|
|
||||||
@@ -131,9 +134,6 @@ function DraftRow({ id, props, onRemove }: RowProps) {
|
|||||||
function CiteField({ props }: { props: DraftListProps }) {
|
function CiteField({ props }: { props: DraftListProps }) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const { choice } = props
|
const { choice } = props
|
||||||
const error = choice.pending
|
|
||||||
? t('editor.citations.pending_choice')
|
|
||||||
: undefined
|
|
||||||
const cite = () => {
|
const cite = () => {
|
||||||
props.onAdd(choice.chosen)
|
props.onAdd(choice.chosen)
|
||||||
choice.onChoose('')
|
choice.onChoose('')
|
||||||
@@ -141,18 +141,14 @@ function CiteField({ props }: { props: DraftListProps }) {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
<FormField
|
<FormField id={ADD_ID} label={t('editor.findings.reference_add')}>
|
||||||
id={ADD_ID}
|
|
||||||
label={t('editor.findings.reference_add')}
|
|
||||||
error={error}
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Select
|
<Select
|
||||||
id={ADD_ID}
|
id={ADD_ID}
|
||||||
value={choice.chosen}
|
value={choice.chosen}
|
||||||
onChange={(event) => choice.onChoose(event.target.value)}
|
onChange={(event) => choice.onChoose(event.target.value)}
|
||||||
aria-invalid={choice.pending}
|
aria-invalid={choice.pending}
|
||||||
aria-describedby={fieldDescribedBy(ADD_ID, undefined, error)}
|
aria-describedby={choice.pending ? PENDING_ID : undefined}
|
||||||
className="min-w-0 flex-1"
|
className="min-w-0 flex-1"
|
||||||
>
|
>
|
||||||
{choice.options.map((option) => (
|
{choice.options.map((option) => (
|
||||||
@@ -176,20 +172,35 @@ function CiteField({ props }: { props: DraftListProps }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The way to cite an existing reference (edit tier only), and « Nouvelle référence ». */
|
/**
|
||||||
|
* The way to cite an existing reference (edit tier only), and « Nouvelle référence »; the
|
||||||
|
* pending line goes under the whole row, so both buttons stay level with the select.
|
||||||
|
*/
|
||||||
function AddRow({ props }: { props: DraftListProps }) {
|
function AddRow({ props }: { props: DraftListProps }) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
|
const pending = props.choice.pending && !props.readOnly
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-wrap items-end gap-2">
|
<div className="space-y-1">
|
||||||
{!props.readOnly && <CiteField props={props} />}
|
<div className="flex flex-wrap items-end gap-2">
|
||||||
<Button
|
{!props.readOnly && <CiteField props={props} />}
|
||||||
type="button"
|
<Button
|
||||||
variant="secondary"
|
type="button"
|
||||||
disabled={props.readOnly}
|
variant="secondary"
|
||||||
onClick={(event) => props.onNew(event.currentTarget)}
|
disabled={props.readOnly}
|
||||||
>
|
onClick={(event) => props.onNew(event.currentTarget)}
|
||||||
{t('editor.citations.new_reference')}
|
>
|
||||||
</Button>
|
{t('editor.citations.new_reference')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{pending && (
|
||||||
|
<p
|
||||||
|
id={PENDING_ID}
|
||||||
|
role="alert"
|
||||||
|
className="text-sm text-[var(--color-danger)]"
|
||||||
|
>
|
||||||
|
{t('editor.citations.pending_choice')}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,6 +161,9 @@ function useCiteChoice(ids: readonly string[]) {
|
|||||||
const options = useCitableOptions(ids)
|
const options = useCitableOptions(ids)
|
||||||
const [state, setState] = useState({ id: '', asked: false })
|
const [state, setState] = useState({ id: '', asked: false })
|
||||||
const chosen = options.some((o) => o.value === state.id) ? state.id : ''
|
const chosen = options.some((o) => o.value === state.id) ? state.id : ''
|
||||||
|
// A choice no longer offered is dropped (a render-time adjustment, no effect): its
|
||||||
|
// reference coming back by a redo never brings it, or its line, back.
|
||||||
|
if (state.id !== '' && chosen === '') setState({ id: '', asked: false })
|
||||||
return {
|
return {
|
||||||
options,
|
options,
|
||||||
chosen,
|
chosen,
|
||||||
|
|||||||
@@ -30,10 +30,6 @@ export default function CitersList({
|
|||||||
// The current family's row says « cette famille » once, without a second badge (Rev 6).
|
// The current family's row says « cette famille » once, without a second badge (Rev 6).
|
||||||
const isCurrent = (citer: CiterItem) =>
|
const isCurrent = (citer: CiterItem) =>
|
||||||
current !== undefined && sameKey(citer.key, current)
|
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(' › ')
|
||||||
@@ -53,7 +49,12 @@ export default function CitersList({
|
|||||||
{citer.name[locale]}
|
{citer.name[locale]}
|
||||||
{isCurrent(citer) && (
|
{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(ownLabel)}
|
{t(
|
||||||
|
elementLabel(
|
||||||
|
'editor.references.this_finding',
|
||||||
|
current ?? null,
|
||||||
|
),
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{citer.isFamily && !isCurrent(citer) && (
|
{citer.isFamily && !isCurrent(citer) && (
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ 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)
|
||||||
const gonePhrase = elementLabel('editor.references.filter_gone', layer.filter)
|
clear.current = () =>
|
||||||
clear.current = () => layer.clearFilter(t(gonePhrase))
|
layer.clearFilter(
|
||||||
|
t(elementLabel('editor.references.filter_gone', layer.filter)),
|
||||||
|
)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (gone) clear.current()
|
if (gone) clear.current()
|
||||||
}, [gone])
|
}, [gone])
|
||||||
|
|||||||
@@ -344,6 +344,8 @@ describe('« Citer » (Rev 6)', () => {
|
|||||||
await editCitations(user)
|
await editCitations(user)
|
||||||
expect(citeButton()).toBeDisabled()
|
expect(citeButton()).toBeDisabled()
|
||||||
await user.selectOptions(select(), 'ref-b')
|
await user.selectOptions(select(), 'ref-b')
|
||||||
|
// happy-dom moves nothing on a key: this covers the change event only. The real
|
||||||
|
// ArrowDown is proven in Chromium (e2e/shell/editor-citations.spec.ts, keyboard test).
|
||||||
fireEvent.keyDown(select(), { key: 'ArrowDown' })
|
fireEvent.keyDown(select(), { key: 'ArrowDown' })
|
||||||
fireEvent.change(select(), { target: { value: 'ref-b' } })
|
fireEvent.change(select(), { target: { value: 'ref-b' } })
|
||||||
expect(rows()).toEqual(['ref-a', 'ref-c'])
|
expect(rows()).toEqual(['ref-a', 'ref-c'])
|
||||||
@@ -387,6 +389,32 @@ describe('« Citer » (Rev 6)', () => {
|
|||||||
expect(citeButton()).toBeDisabled()
|
expect(citeButton()).toBeDisabled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('a vanished choice stays reset when its reference comes back by an undo', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await editCitations(user)
|
||||||
|
await user.selectOptions(select(), 'ref-b')
|
||||||
|
await user.click(button('Enregistrer'))
|
||||||
|
expect(inCitations().getByRole('alert')).toBeInTheDocument()
|
||||||
|
act(() => {
|
||||||
|
store.getState().commit({
|
||||||
|
op: 'remove',
|
||||||
|
key: { kind: 'reference', id: 'ref-b' },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
await waitFor(() => expect(select()).toHaveValue(''))
|
||||||
|
act(() => {
|
||||||
|
store.getState().undoStep()
|
||||||
|
})
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(
|
||||||
|
inCitations().getByRole('option', { name: 'Denoix' }),
|
||||||
|
).toBeInTheDocument(),
|
||||||
|
)
|
||||||
|
expect(select()).toHaveValue('')
|
||||||
|
expect(citeButton()).toBeDisabled()
|
||||||
|
expect(inCitations().queryByRole('alert')).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
it('« Enregistrer » with a choice not cited refuses: the line, focus on « Citer »', async () => {
|
it('« Enregistrer » with a choice not cited refuses: the line, focus on « Citer »', async () => {
|
||||||
const user = await mount()
|
const user = await mount()
|
||||||
await editCitations(user)
|
await editCitations(user)
|
||||||
|
|||||||
Reference in new issue
Block a user