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,211 @@
|
||||
import { useRef, type RefObject } from 'react'
|
||||
import type { ElementKey, Reference } from '@faunosteo/core-wasm/types'
|
||||
import ActionButton from '@/components/editor/fields/ActionButton'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import { usePlural } from '@/editor/plural'
|
||||
import type { CiterItem } from '@/editor/references/citations'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import CitersList from './CitersList'
|
||||
import ReferenceEditor from './ReferenceEditor'
|
||||
import ReferenceFacts from './ReferenceFacts'
|
||||
import type { ReferenceHost } from './referenceTypes'
|
||||
import type { LeaveGuard } from './useReferenceEdit'
|
||||
|
||||
/** What a tile asks of the library that owns its state. */
|
||||
export interface TileHandlers {
|
||||
toggle: () => void
|
||||
edit: () => void
|
||||
/** Leaves the edit view; false (the view stays) when a field refuses. */
|
||||
done: () => boolean
|
||||
remove: () => void
|
||||
move: (position: number) => void
|
||||
goTo: (key: ElementKey) => void
|
||||
registerLeave: (guard: LeaveGuard | null) => void
|
||||
}
|
||||
|
||||
export interface TileProps {
|
||||
host: ReferenceHost
|
||||
reference: Reference
|
||||
/** Position in the whole bibliography, not in a filtered list. */
|
||||
position: number
|
||||
count: number
|
||||
citers: readonly CiterItem[]
|
||||
open: boolean
|
||||
editing: boolean
|
||||
readOnly: boolean
|
||||
/** ↑ / ↓ only while neither the search nor a sort narrows or reorders the list. */
|
||||
movable: boolean
|
||||
on: TileHandlers
|
||||
}
|
||||
|
||||
/** DOM id prefix of a tile: host, position and id keep duplicates distinct (P31). */
|
||||
export const tileBase = (
|
||||
host: ReferenceHost,
|
||||
position: number,
|
||||
reference: Reference,
|
||||
) => `${host}-reference-${position}-${reference.id}`
|
||||
|
||||
const BUTTON_RING =
|
||||
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
|
||||
|
||||
/** The disclosure button: citation (two lines when closed), type and how often it is cited. */
|
||||
function TileHeader({
|
||||
base,
|
||||
props,
|
||||
headerRef,
|
||||
}: {
|
||||
base: string
|
||||
props: TileProps
|
||||
headerRef: RefObject<HTMLButtonElement | null>
|
||||
}) {
|
||||
const t = useT()
|
||||
const plural = usePlural()
|
||||
const { reference, open, editing, citers } = props
|
||||
const cited = citers.length
|
||||
const key = JSON.stringify({ kind: 'reference', id: reference.id })
|
||||
return (
|
||||
<button
|
||||
ref={headerRef}
|
||||
type="button"
|
||||
id={`${base}-header`}
|
||||
data-focus-key={key}
|
||||
aria-expanded={open || editing}
|
||||
aria-controls={`${base}-body`}
|
||||
onClick={props.on.toggle}
|
||||
className={`grid min-h-11 w-full grid-cols-[1.25rem_1fr] items-start gap-x-3 gap-y-1 rounded-lg p-3 text-left sm:grid-cols-[1.25rem_1fr_auto] ${BUTTON_RING}`}
|
||||
>
|
||||
<Icon
|
||||
name={open || editing ? 'chevron-down' : 'chevron-right'}
|
||||
size={18}
|
||||
/>
|
||||
<span
|
||||
className={`min-w-0 break-words text-sm ${open || editing ? '' : 'line-clamp-2'} ${editing ? 'font-semibold' : ''}`}
|
||||
>
|
||||
{editing ? t('editor.references.edit_title') : reference.citation}
|
||||
</span>
|
||||
<span className="col-start-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-[var(--color-ink-muted)] sm:col-start-3 sm:row-start-1 sm:flex-col sm:items-end">
|
||||
{!editing && (
|
||||
<span className="rounded-md bg-[var(--color-surface-strong)] px-2 py-0.5 font-medium text-[var(--color-ink)]">
|
||||
{t(`editor.reference.type.${reference.type}`)}
|
||||
</span>
|
||||
)}
|
||||
<span>
|
||||
{cited === 0
|
||||
? t('editor.references.uncited')
|
||||
: plural('editor.references.cited', cited)}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
/** « Modifier », « Supprimer » (uncited only, else the hint), « Monter » / « Descendre ». */
|
||||
function TileActions({ props }: { props: TileProps }) {
|
||||
const t = useT()
|
||||
const { position, count, citers, readOnly, movable, on } = props
|
||||
if (readOnly) return null
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<ActionButton
|
||||
readOnly={false}
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={on.edit}
|
||||
>
|
||||
{t('editor.references.edit')}
|
||||
</ActionButton>
|
||||
{citers.length === 0 && (
|
||||
<ActionButton
|
||||
readOnly={false}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-[var(--color-danger-strong)]"
|
||||
onClick={on.remove}
|
||||
>
|
||||
{t('editor.action.delete')}
|
||||
</ActionButton>
|
||||
)}
|
||||
{movable && (
|
||||
<>
|
||||
<ActionButton
|
||||
readOnly={false}
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
disabled={position === 0}
|
||||
onClick={() => on.move(position - 1)}
|
||||
>
|
||||
{t('editor.action.move_up')}
|
||||
</ActionButton>
|
||||
<ActionButton
|
||||
readOnly={false}
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
disabled={position >= count - 1}
|
||||
onClick={() => on.move(position + 1)}
|
||||
>
|
||||
{t('editor.action.move_down')}
|
||||
</ActionButton>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{citers.length > 0 && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.references.delete_hint')}
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* One reference as a collapsible tile (boards 23, 24): closed, open (facts, citers,
|
||||
* actions), or in edit (fields, citers, « Terminer »). Read-only: the facts and the
|
||||
* citers' « Aller à » only, no control that changes the draft.
|
||||
*/
|
||||
export default function ReferenceTile(props: TileProps) {
|
||||
const { host, reference, position, open, editing, on } = props
|
||||
const t = useT()
|
||||
const base = tileBase(host, position, reference)
|
||||
const headerRef = useRef<HTMLButtonElement>(null)
|
||||
const done = () => {
|
||||
if (on.done()) headerRef.current?.focus()
|
||||
}
|
||||
return (
|
||||
<li className="rounded-lg border border-[var(--color-border)] bg-[var(--color-surface)]">
|
||||
<TileHeader base={base} props={props} headerRef={headerRef} />
|
||||
{(open || editing) && (
|
||||
<div
|
||||
id={`${base}-body`}
|
||||
className="space-y-3 border-t border-[var(--color-border)] p-3"
|
||||
>
|
||||
{editing ? (
|
||||
<ReferenceEditor
|
||||
reference={reference}
|
||||
base={base}
|
||||
registerLeave={on.registerLeave}
|
||||
/>
|
||||
) : (
|
||||
<ReferenceFacts reference={reference} />
|
||||
)}
|
||||
<CitersList citers={props.citers} onGoTo={on.goTo} />
|
||||
{editing ? (
|
||||
<ActionButton
|
||||
readOnly={false}
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
// A press keeps the focus in its field: a refusal shown on blur would move
|
||||
// the button before the click lands. The click applies every field itself.
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
onClick={done}
|
||||
>
|
||||
{t('editor.references.done')}
|
||||
</ActionButton>
|
||||
) : (
|
||||
<TileActions props={props} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user