feat(editor): search, sort, count and add in the Références tab

Search (citation, DOI, URL) with « Effacer la recherche » and Escape;
« Trier par » sheet order, citation (locale collator), citation count,
type (business order); every sort stable on stored order, display only:
document, stored order, ids and history unchanged (unit + e2e). Count
« {n} références » / « {n} sur {total} » counts matching references
only. « Monter » / « Descendre » only in sheet order without search
(A1). « Ajouter une référence » resets search and sort and appends a
draft tile in edit; a tile in edit stays pinned while sorted or
searched; tile state pruned of absent ids. Reset path ready for « Tout
afficher » (R2.4).

Gates: typecheck, lint, test:run (app 1452), build, e2e:ui 251;
e2e:shell 16 specs on db:sandbox (editor-equine never listed): 115
passed / 102 skipped / 2 failed: editor-structures (test-side, fixed,
rerun with editor-references 12 passed / 11 skipped) and admin.spec A0
« Target crashed » during axe on the rights screen (not R2: that
screen renders every grant, 1 282 accumulated e2e fixtures; reported as
an open risk); full-row guard: no pre-existing row changed in any table.

## R-24 (removed or rewritten assertions)
| file | old | new |
|---|---|---|
| editor-references-tab.test.tsx | `#tab-reference-new-citation` present on load | null until « Ajouter une référence » |
| same | no match text « Aucune référence ne correspond. » | notice « Aucune référence ne contient « zzz ». » |
| same | add: form always visible, add clears the search, `getByText('Nouvelle source')` | click « Ajouter une référence » first; new tile header open, focused, search empty, 4 tiles |
| same | « a refused add keeps the search » | REMOVED (P24: add resets the search at once); replaced by « draft opens with citation focused, refused add keeps the draft, no write » |
| editor-tabs-lists.test.tsx | add form directly | click « Ajouter une référence » before the form assertions (same assertions after) |
| editor-keep-alive.test.tsx | form survives tab round trip | same, after opening the draft |
| editor-no-loss.test.tsx | reference form keeps typed text | same, after opening the draft |
| e2e editor-shell.spec (2), editor-shell-crossing.spec, editor-structures.spec | fill `#tab-reference-new-*` directly; `getByText(citation)` visible | open the draft first; structures asserts the new header is focused |
| e2e editor-references.spec keyboard walk | focus search, Tab reaches header 0 | focus « Ajouter une référence » (search, sort, add precede the headers) |
Other readers of `editor.reference.add`/new ids: grep of src, tests, e2e incl. editor-equine found none left unlisted. editor-equine is not affected ("updated, not run": nothing to update).

## i18n (fr / en)
Added: `editor.references.add` Ajouter une référence / Add a reference; `add_help` Type et citation obligatoires. / Type and citation required.; `clear_search` Effacer la recherche / Clear the search; `sort_by` Trier par / Sort by; `sort.sheet|citation|count|type` Ordre de la fiche, Citation (A → Z), Nombre de citations, Type / Sheet order, Citation (A → Z), Number of citations, Type; `count_one|other` {count} référence(s) / reference(s); `count_of_one|other` {count} référence(s) sur {total} / {count} reference(s) of {total}; `reorder_hint` Pour réorganiser, affichez l'ordre de la fiche sans recherche. / To reorder, show the sheet order without a search.; `no_result` Aucune référence ne contient « {q} ». / No reference contains “{q}”.; `no_result_scope` La recherche porte sur la citation, le DOI et l'URL. / The search covers the citation, the DOI and the URL. (REVUE sentence split in two keys so the first half is bold).
Changed: none. Removed: none (`editor.references.no_match` kept, the panel's EmptyLine still uses it).
This commit is contained in:
bchanot committed 2026-11-12 21:18:56 +01:00
1 parent c21995b3fb
commit 3baac4dbb5
26 files changed
+1544 -219

No files matched your search

@@ -0,0 +1,11 @@
import type { ReferenceType } from '@faunosteo/core-wasm/types'
/** The reference types in business order (the « Type » sort and the pickers). */
export const REFERENCE_TYPES: readonly ReferenceType[] = [
'book',
'journal',
'standard',
'legal',
'web',
'manual',
]
+57
View File
@@ -0,0 +1,57 @@
import type { Reference } from '@faunosteo/core-wasm/types'
import { REFERENCE_TYPES } from './referenceTypes'
import type { Locale } from '@/i18n/types'
/** The four display orders of the Références tab; `sheet` is the stored order. */
export const REFERENCE_SORTS = ['sheet', 'citation', 'count', 'type'] as const
export type ReferenceSort = (typeof REFERENCE_SORTS)[number]
export interface SortContext {
locale: Locale
/** How many findings and families cite each reference id. */
citedCount: (id: string) => number
}
/** A type outside the list sorts after the listed ones. */
const typeRank = (reference: Reference) => {
const rank = REFERENCE_TYPES.indexOf(reference.type)
return rank < 0 ? REFERENCE_TYPES.length : rank
}
function comparator(
references: readonly Reference[],
sort: ReferenceSort,
context: SortContext,
): (a: number, b: number) => number {
const collator = new Intl.Collator(context.locale, {
sensitivity: 'base',
numeric: true,
})
const count = (at: number) => context.citedCount(references[at].id)
switch (sort) {
case 'citation':
return (a, b) =>
collator.compare(references[a].citation, references[b].citation)
case 'count':
return (a, b) => count(b) - count(a)
case 'type':
return (a, b) => typeRank(references[a]) - typeRank(references[b])
case 'sheet':
return () => 0
}
}
/**
* The positions (indexes into `references`, P31) in display order. Display only: the
* inputs are not touched and a new array is returned. Equal keys keep the stored order,
* so the result never depends on the order of `positions`.
*/
export function sortReferenceIds(
references: readonly Reference[],
positions: readonly number[],
sort: ReferenceSort,
context: SortContext,
): number[] {
const compare = comparator(references, sort, context)
return [...positions].sort((a, b) => compare(a, b) || a - b)
}
+38
View File
@@ -0,0 +1,38 @@
import type { Reference } from '@faunosteo/core-wasm/types'
import { referenceMatches } from './filter'
import { sortReferenceIds, type ReferenceSort, type SortContext } from './sort'
export interface ReferenceView {
query: string
sort: ReferenceSort
}
/** Stored order, no search: the only view where ↑ / ↓ mean something (A1). */
export const isSheetView = (view: ReferenceView) =>
view.sort === 'sheet' && view.query.trim() === ''
/**
* The tile in edit, kept in the shown set at `index` whatever the search or the sort
* (P23); only worth passing when the view is not the sheet view.
*/
export interface Pin {
position: number
index: number
}
/** The positions to show: the search, then the sort, then the pinned tile put back. */
export function shownPositions(
references: readonly Reference[],
view: ReferenceView,
context: SortContext,
pin: Pin | null,
): number[] {
const matching = references.flatMap((reference, position) =>
referenceMatches(reference, view.query) ? [position] : [],
)
const sorted = sortReferenceIds(references, matching, view.sort, context)
if (pin === null) return sorted
const rest = sorted.filter((position) => position !== pin.position)
rest.splice(Math.min(pin.index, rest.length), 0, pin.position)
return rest
}