feat(editor): collapsible reference tiles in the Références tab
Board 23 / 24 / 27 tiles: closed (citation on two lines, type, « Citée
{n} fois » / « Non citée »), open (Type, DOI, URL as safe links, the
citers with « famille » badge and « Aller à »), edit (« Terminer » with a
leave guard re-committing every changed field; a refusal keeps edit
and focuses the field). A cited reference shows the deletion hint, an
uncited one keeps « Supprimer ». Read-only keeps DOI, URL, « Aller à ».
« Terminer » keeps focus in the field on press, so a refusal message
can no longer move the button under the pointer.
Gates: typecheck, lint, test:run (app 1419), build, e2e:ui 251;
e2e:shell 16 specs on db:sandbox (editor-equine never listed): 111
passed / 99 skipped / 3 failed in the new editor-references.spec (two
test bugs, one app bug), fixed and rerun: 5 passed / 4 skipped; full-row
guard: no pre-existing row changed in any table.
## R-24 (removed or rewritten assertions)
| file | old | new |
|---|---|---|
| editor-citations.test.ts | `citationCounts` counts 2/1/0, memoised, empty | `citersOf`: ordered citers (Cat, Node), family flag, trail from zone, key, memoised, empty |
| editor-references-tab.test.tsx | cards say « citée N fois » (ref-a 1, ref-c 0) | « Citée 2 fois » (fixture gains a node citing ref-a), « Citée 1 fois », « Non citée » |
| same | ids `#tab-reference-ref-a-citation` exist when closed | header id `#tab-reference-0-ref-a-header`; field ids only inside an open edit tile |
| same | ↑/↓ on every card | in open tiles only, absent under a search |
| same | Ctrl+Z on an always-visible field | open tile, Modifier, then same assertion on `#tab-reference-0-ref-a-citation` |
| same | « Aller à » focuses the card (`listitem` count 3, focus key) | tile opened (aria-expanded true), header focused, 3 tiles |
| same | add: `getByText('Nouvelle source')` | tile header named « Nouvelle source » |
| same | read-only: no Supprimer / add | same after opening every tile |
| editor-tabs-lists.test.tsx | edit on blur and arrows on always-open cards | open tile, Modifier, blur applies, Terminer, Monter on opened tile |
| same | cited reference deletion refused in a dialog listing citers | REMOVED: no Supprimer on a cited tile (hint asserted, citer listed); uncited delete kept. The dialog's blocked path stays covered by `DeleteDialog`'s own tests |
| same | read-only: no button at all | read-only: facts shown, no Modifier / Supprimer / Citation textbox (header buttons exist now) |
| editor-keep-alive.test.tsx:~330 | tab-click commit of `#tab-reference-ref-1-citation` | opens tile + Modifier first, id `#tab-reference-0-ref-1-citation` |
| editor-keep-alive.test.tsx:~350,367 | `#panel-reference-ref-1-citation` | `#panel-reference-0-ref-1-citation` |
| editor-references-panel.test.tsx | « citée 2 fois / 1 fois » | « Citée 2 fois / 1 fois » |
| same | `#panel-reference-ref-a-citation`; no `#tab-reference-ref-a-citation` | `#panel-reference-0-ref-a-citation`; no `[id^="tab-reference-"]` while the tab tiles are closed |
| same | ids unique, tab and panel field ids present | tab tile opened in edit first; `tab-reference-0-ref-a-citation` and `panel-reference-0-ref-a-citation` unique |
| e2e editor-structures.spec.ts:~88-110 | citation inputs count 3/1/2, « citée 0 fois » x2, « citée 1 fois », move via row buttons | tile headers count, « Non citée » x2, « Citée 1 fois », tile opened before Monter/Supprimer, `tiles.nth(1)` contains the moved text (saved-list assertion unchanged) |
## i18n (fr / en)
Changed (in place, P18): `editor.references.cited_one|other`: « citée {count} fois » -> « Citée {count} fois »; « cited {count} time(s) » -> « Cited {count} time(s) ».
Added: `editor.references.uncited` Non citée / Not cited; `citers_one|other` « Citée {count} fois, par : » / « Cited {count} time(s), by: »; `no_citers` « Aucun constat ni aucune famille ne cite cette référence. » / « No finding or family cites this reference. »; `family` famille / family; `go_to` Aller à / Go to; `edit` Modifier / Edit; `done` Terminer / Done; `edit_title` Modifier la référence / Edit the reference; `url_label` URL / URL; `none_doi` Aucun / None; `none_url` Aucune / None; `new_tab` (nouvel onglet) / (new tab) (sr-only); `delete_hint` (REVUE wording, fr and en).
Removed: none. R10 grep (src, tests, e2e incl. editor-equine) found no reader of the old lowercase wording left.
This commit is contained in:
1 parent
4499bc740c
commit
c21995b3fb
26 files changed
+1532
-155
No files matched your search
@@ -0,0 +1,103 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import type { Reference } from '@faunosteo/core-wasm/types'
|
||||
import { isBlank, nullable } from '@/editor/sheetDocument'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
|
||||
/** The text fields of the edit view, in the order the leave guard tries them. */
|
||||
export const FIELDS = ['citation', 'doi', 'url'] as const
|
||||
export type Field = (typeof FIELDS)[number]
|
||||
type Drafts = Record<Field, string>
|
||||
|
||||
/** What the guard calls on a leave: true when every pending field was applied. */
|
||||
export type LeaveGuard = () => boolean
|
||||
|
||||
const committedOf = (reference: Reference): Drafts => ({
|
||||
citation: reference.citation,
|
||||
doi: reference.doi ?? '',
|
||||
url: reference.url ?? '',
|
||||
})
|
||||
|
||||
/** The document value a draft gives (a blank optional field is null, so ''). */
|
||||
const normalized = (field: Field, draft: string) =>
|
||||
field === 'citation' ? draft : (nullable(draft) ?? '')
|
||||
|
||||
const patched = (reference: Reference, field: Field, draft: string) =>
|
||||
field === 'citation'
|
||||
? { ...reference, citation: draft }
|
||||
: { ...reference, [field]: nullable(draft) }
|
||||
|
||||
/** One draft per text field; a new committed value (undo, reload) replaces its draft. */
|
||||
function useDrafts(reference: Reference) {
|
||||
const committed = committedOf(reference)
|
||||
const [drafts, setDrafts] = useState(committed)
|
||||
const [seen, setSeen] = useState(committed)
|
||||
const changed = FIELDS.filter((field) => seen[field] !== committed[field])
|
||||
if (changed.length > 0) {
|
||||
setSeen(committed)
|
||||
const fresh = changed.map((field) => [field, committed[field]])
|
||||
setDrafts({ ...drafts, ...Object.fromEntries(fresh) })
|
||||
}
|
||||
const setDraft = (field: Field, value: string) =>
|
||||
setDrafts({ ...drafts, [field]: value })
|
||||
return [drafts, setDraft] as const
|
||||
}
|
||||
|
||||
/**
|
||||
* The write path of one reference's edit view. A field applies to the draft when it
|
||||
* loses the focus (`commitField`); `leave` re-applies every field whose text differs from
|
||||
* the document, stops at the first refusal, shows it and focuses that field (P22, P22').
|
||||
* `base` is the DOM id prefix of the tile; `registerLeave` hands `leave` to the library.
|
||||
*/
|
||||
export function useReferenceEdit(
|
||||
reference: Reference,
|
||||
base: string,
|
||||
registerLeave: (guard: LeaveGuard | null) => void,
|
||||
) {
|
||||
const edit = useEditCommand()
|
||||
const [drafts, setDraft] = useDrafts(reference)
|
||||
const key = { kind: 'reference', id: reference.id } as const
|
||||
const update = (field: string, value: Reference) =>
|
||||
edit.run(field, {
|
||||
op: 'update',
|
||||
key,
|
||||
element: { kind: 'reference', value },
|
||||
})
|
||||
const apply = (current: Reference, field: Field): Reference | null => {
|
||||
const draft = drafts[field]
|
||||
if (field === 'citation' && isBlank(draft)) {
|
||||
edit.reject(field, 'editor.field.required')
|
||||
return null
|
||||
}
|
||||
const next = patched(current, field, draft)
|
||||
return update(field, next) ? next : null
|
||||
}
|
||||
const pending = (current: Reference, field: Field) =>
|
||||
normalized(field, drafts[field]) !== committedOf(current)[field]
|
||||
const leave: LeaveGuard = () => {
|
||||
let current = reference
|
||||
for (const field of FIELDS.filter((name) => pending(current, name))) {
|
||||
const next = apply(current, field)
|
||||
if (!next) {
|
||||
document.getElementById(`${base}-${field}`)?.focus()
|
||||
return false
|
||||
}
|
||||
current = next
|
||||
}
|
||||
return true
|
||||
}
|
||||
useEffect(() => {
|
||||
registerLeave(leave)
|
||||
return () => registerLeave(null)
|
||||
})
|
||||
useEffect(() => {
|
||||
document.getElementById(`${base}-citation`)?.focus()
|
||||
}, [base])
|
||||
return {
|
||||
edit,
|
||||
drafts,
|
||||
setDraft,
|
||||
commitField: (field: Field) =>
|
||||
pending(reference, field) && apply(reference, field),
|
||||
setType: (value: Reference) => update('type', value),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user