feat(app): search, sort, count and date on the official sheet list
Boards 28 and 29 A: name search with clear button and Escape, « Trier par » (last modification by default, or name), a polite count line, « Modifiée le … » on each row in a <time>, and the search no-result block. The detail line moves to labels.ts as sheetDetails. R-24: no existing assertion removed or rewritten; six tests added.
This commit is contained in:
1 parent
a950e403c2
commit
423125c18f
6 files changed
+534
-133
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type {
|
||||
CatalogSpecies,
|
||||
OfficialSheetAdminSummary,
|
||||
SheetAdminPerson,
|
||||
SheetAdminRound,
|
||||
SheetFailureKind,
|
||||
@@ -125,6 +126,49 @@ export function formatShortParisDateTime(iso: string, locale: Locale): string {
|
||||
return SHORT_DATE_TIME[locale].format(new Date(iso))
|
||||
}
|
||||
|
||||
type SheetSummary = OfficialSheetAdminSummary
|
||||
|
||||
/** « version publiée 3 » or « aucune version publiée », then « brouillon version 4 » if any. */
|
||||
function versionParts(t: Translate, sheet: SheetSummary): string[] {
|
||||
const number = (key: string, value: number) =>
|
||||
t(key).replace('{number}', String(value))
|
||||
const current = sheet.current_version
|
||||
? number(
|
||||
'admin.sheets.current_version',
|
||||
sheet.current_version.version_number,
|
||||
)
|
||||
: t('admin.sheets.no_published')
|
||||
const draft = sheet.draft_version
|
||||
? [number('admin.sheets.draft', sheet.draft_version.version_number)]
|
||||
: []
|
||||
return [current, ...draft]
|
||||
}
|
||||
|
||||
/** « revue n° 2 : À relire » when the sheet has a round. */
|
||||
function roundPart(t: Translate, sheet: SheetSummary): string[] {
|
||||
if (!sheet.latest_round) return []
|
||||
return [
|
||||
t('admin.sheets.latest_round')
|
||||
.replace('{round}', String(sheet.latest_round.round))
|
||||
.replace('{status}', roundLabel(t, sheet.latest_round).title),
|
||||
]
|
||||
}
|
||||
|
||||
/** The detail line of a sheet row: « Cheval · Active · version publiée 3 · … » (board 28). */
|
||||
export function sheetDetails(
|
||||
t: Translate,
|
||||
sheet: SheetSummary,
|
||||
species: readonly CatalogSpecies[],
|
||||
locale: Locale,
|
||||
): string {
|
||||
return [
|
||||
speciesLabel(sheet.species_id, species, locale),
|
||||
t(`admin.sheet_status.${sheet.status}`),
|
||||
...versionParts(t, sheet),
|
||||
...roundPart(t, sheet),
|
||||
].join(' · ')
|
||||
}
|
||||
|
||||
/**
|
||||
* The round's state (§3). A failed verification names its cause only when
|
||||
* the server recorded one (`failure_outcome`, BDR-095): the title of that
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react'
|
||||
import { useRef, useState, type KeyboardEvent } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import {
|
||||
listCatalogSpecies,
|
||||
@@ -7,17 +7,21 @@ import {
|
||||
type FaunosteoClient,
|
||||
type OfficialSheetAdminSummary,
|
||||
} from '@faunosteo/supabase'
|
||||
import ModifiedDate from '@/components/admin/ModifiedDate'
|
||||
import SheetBadges from '@/components/admin/SheetBadges'
|
||||
import AccessDenied from '@/components/shell/AccessDenied'
|
||||
import Button from '@/components/ui/Button'
|
||||
import ButtonLink from '@/components/ui/ButtonLink'
|
||||
import FormField from '@/components/ui/FormField'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import Input from '@/components/ui/Input'
|
||||
import Label from '@/components/ui/Label'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import Select from '@/components/ui/Select'
|
||||
import {
|
||||
failureMessage,
|
||||
localized,
|
||||
roundLabel,
|
||||
sheetDetails,
|
||||
speciesLabel,
|
||||
} from '@/admin/labels'
|
||||
import {
|
||||
@@ -28,13 +32,20 @@ import {
|
||||
filterSheets,
|
||||
type SheetFilters,
|
||||
} from '@/admin/filters'
|
||||
import {
|
||||
SHEET_SORTS,
|
||||
searchSheets,
|
||||
sortSheets,
|
||||
type SheetSort,
|
||||
} from '@/admin/sheetList'
|
||||
import { useAdminPermissions } from '@/admin/permissions'
|
||||
import { isRightsRefusal, useAdminQuery } from '@/admin/useAdminQuery'
|
||||
import { usePageHeading } from '@/app/usePageHeading'
|
||||
import { usePlural } from '@/editor/plural'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
type Translate = ReturnType<typeof useT>
|
||||
type Sheet = OfficialSheetAdminSummary
|
||||
|
||||
/** The list and the species names, in one read: both are capability reads at aal2. */
|
||||
async function loadSheets(client: FaunosteoClient) {
|
||||
@@ -45,82 +56,144 @@ async function loadSheets(client: FaunosteoClient) {
|
||||
return { sheets, species }
|
||||
}
|
||||
|
||||
function details(t: Translate, sheet: OfficialSheetAdminSummary): string[] {
|
||||
return [
|
||||
t(`admin.sheet_status.${sheet.status}`),
|
||||
sheet.current_version
|
||||
? t('admin.sheets.current_version').replace(
|
||||
'{number}',
|
||||
String(sheet.current_version.version_number),
|
||||
)
|
||||
: t('admin.sheets.no_published'),
|
||||
...(sheet.draft_version
|
||||
? [
|
||||
t('admin.sheets.draft').replace(
|
||||
'{number}',
|
||||
String(sheet.draft_version.version_number),
|
||||
),
|
||||
]
|
||||
: []),
|
||||
...(sheet.latest_round
|
||||
? [
|
||||
t('admin.sheets.latest_round')
|
||||
.replace('{round}', String(sheet.latest_round.round))
|
||||
.replace('{status}', roundLabel(t, sheet.latest_round).title),
|
||||
]
|
||||
: []),
|
||||
]
|
||||
/** What the page shows of the loaded list: the four filters, the search and the sort. */
|
||||
function useListView() {
|
||||
const [filters, setFilters] = useState<SheetFilters>(NO_FILTER)
|
||||
const [query, setQuery] = useState('')
|
||||
const [sort, setSort] = useState<SheetSort>('modified')
|
||||
const searchRef = useRef<HTMLInputElement>(null)
|
||||
/** Every way of clearing (« × », Escape, the no-result button) gives the field the focus back. */
|
||||
const clearSearch = () => {
|
||||
setQuery('')
|
||||
searchRef.current?.focus()
|
||||
}
|
||||
return {
|
||||
filters,
|
||||
setFilters,
|
||||
query,
|
||||
setQuery,
|
||||
sort,
|
||||
setSort,
|
||||
searchRef,
|
||||
clearSearch,
|
||||
}
|
||||
}
|
||||
type ListView = ReturnType<typeof useListView>
|
||||
|
||||
function SheetRow({
|
||||
sheet,
|
||||
species,
|
||||
t,
|
||||
}: {
|
||||
sheet: OfficialSheetAdminSummary
|
||||
sheet: Sheet
|
||||
species: CatalogSpecies[]
|
||||
t: Translate
|
||||
}) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
return (
|
||||
<li>
|
||||
<Link
|
||||
to={`/app/admin/sheets/${sheet.sheet_id}`}
|
||||
className="flex min-h-11 flex-col gap-1 rounded-xl px-4 py-3 hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||
className="flex min-h-11 flex-col gap-1 rounded-xl px-4 py-3 hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] sm:grid sm:grid-cols-[minmax(0,1fr)_auto] sm:gap-x-4"
|
||||
>
|
||||
<span className="flex flex-wrap items-center gap-2">
|
||||
<span className="min-w-0 font-medium text-[var(--color-ink)]">
|
||||
<span className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<span className="min-w-0 font-medium text-[var(--color-ink)] [overflow-wrap:anywhere]">
|
||||
{localized(sheet.name, locale)}
|
||||
</span>
|
||||
<SheetBadges sheet={sheet} />
|
||||
</span>
|
||||
<span className="text-sm text-[var(--color-ink-muted)]">
|
||||
{[
|
||||
speciesLabel(sheet.species_id, species, locale),
|
||||
...details(t, sheet),
|
||||
].join(' · ')}
|
||||
<span className="text-sm text-[var(--color-ink-muted)] sm:col-start-1">
|
||||
{sheetDetails(t, sheet, species, locale)}
|
||||
</span>
|
||||
<span className="text-sm text-[var(--color-ink-muted)] sm:col-start-2 sm:row-start-1 sm:whitespace-nowrap sm:text-right">
|
||||
<ModifiedDate iso={sheet.last_modified_at} />
|
||||
</span>
|
||||
</Link>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
// shortcut: same markup as ReferenceToolbar's search (R2, closed and validated, not
|
||||
// reopened here); fold both onto one component when the editor is next opened.
|
||||
function SearchField({ view }: { view: ListView }) {
|
||||
const t = useT()
|
||||
const { query, setQuery, searchRef, clearSearch } = view
|
||||
// REVUE point 4: the field keeps Escape while it holds text; an empty one lets it go.
|
||||
const escape = (event: KeyboardEvent) => {
|
||||
if (event.key !== 'Escape' || query === '') return
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
clearSearch()
|
||||
}
|
||||
return (
|
||||
<div className="relative flex-1 sm:max-w-sm">
|
||||
<Input
|
||||
ref={searchRef}
|
||||
type="search"
|
||||
aria-label={t('admin.sheets.search')}
|
||||
placeholder={t('admin.sheets.search')}
|
||||
maxLength={100}
|
||||
autoComplete="off"
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
onKeyDown={escape}
|
||||
className="pr-11 max-sm:h-11 [&::-webkit-search-cancel-button]:appearance-none"
|
||||
/>
|
||||
{query !== '' && (
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t('admin.sheets.clear_search')}
|
||||
onClick={clearSearch}
|
||||
className="absolute right-0 top-0 flex size-10 max-sm:size-11 items-center justify-center rounded-lg text-[var(--color-ink-muted)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||
>
|
||||
<Icon name="close" size={16} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** « Trier par »: a native select, « Dernière modification » by default, or « Nom ». */
|
||||
function SortSelect({ view }: { view: ListView }) {
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="flex flex-col gap-1 sm:flex-row sm:items-center sm:gap-2">
|
||||
<Label htmlFor="admin-sheets-sort" className="sm:whitespace-nowrap">
|
||||
{t('admin.sheets.sort_by')}
|
||||
</Label>
|
||||
<Select
|
||||
id="admin-sheets-sort"
|
||||
value={view.sort}
|
||||
onChange={(event) => view.setSort(event.target.value as SheetSort)}
|
||||
className="max-sm:h-11 sm:w-56"
|
||||
>
|
||||
{SHEET_SORTS.map((value) => (
|
||||
<option key={value} value={value}>
|
||||
{t(`admin.sheets.sort.${value}`)}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface FilterProps {
|
||||
id: keyof SheetFilters
|
||||
label: string
|
||||
value: string
|
||||
options: readonly { value: string; label: string }[]
|
||||
onChange: (value: string) => void
|
||||
view: ListView
|
||||
}
|
||||
|
||||
function Filter({ id, label, value, options, onChange }: FilterProps) {
|
||||
function Filter({ id, label, options, view }: FilterProps) {
|
||||
const t = useT()
|
||||
const onChange = (value: string) =>
|
||||
view.setFilters((f) => ({ ...f, [id]: value }))
|
||||
return (
|
||||
<FormField id={`filter-${id}`} label={label}>
|
||||
<Select
|
||||
id={`filter-${id}`}
|
||||
value={value}
|
||||
value={view.filters[id]}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="max-sm:h-11"
|
||||
>
|
||||
<option value="">{t('admin.sheets.filter.all')}</option>
|
||||
{options.map((option) => (
|
||||
@@ -133,81 +206,194 @@ function Filter({ id, label, value, options, onChange }: FilterProps) {
|
||||
)
|
||||
}
|
||||
|
||||
/** /app/admin/sheets (§11.1): every official sheet with its badges and the four filters. */
|
||||
export default function AdminSheetsRoute() {
|
||||
/** The three status filters: their id, label key and the dictionary of their values. */
|
||||
const STATUS_FILTERS = [
|
||||
{
|
||||
id: 'sheetStatus',
|
||||
label: 'sheet_status',
|
||||
prefix: 'admin.sheet_status',
|
||||
values: SHEET_STATUSES,
|
||||
},
|
||||
{
|
||||
id: 'versionStatus',
|
||||
label: 'version_status',
|
||||
prefix: 'admin.version_status',
|
||||
values: VERSION_STATUSES,
|
||||
},
|
||||
{
|
||||
id: 'roundStatus',
|
||||
label: 'round_status',
|
||||
prefix: 'admin.round_status',
|
||||
values: ROUND_STATUSES,
|
||||
},
|
||||
] as const
|
||||
|
||||
/** The four filters of §11.1, unchanged; species offered are those of the loaded list. */
|
||||
function Filters({ sheets, species, view }: ResultsProps) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const speciesOptions = [...new Set(sheets.map((s) => s.species_id))].map(
|
||||
(id) => ({ value: id, label: speciesLabel(id, species, locale) }),
|
||||
)
|
||||
return (
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<Filter
|
||||
id="species"
|
||||
label={t('admin.sheets.filter.species')}
|
||||
options={speciesOptions}
|
||||
view={view}
|
||||
/>
|
||||
{STATUS_FILTERS.map(({ id, label, prefix, values }) => (
|
||||
<Filter
|
||||
key={id}
|
||||
id={id}
|
||||
label={t(`admin.sheets.filter.${label}`)}
|
||||
options={values.map((value) => ({
|
||||
value,
|
||||
label: t(`${prefix}.${value}`),
|
||||
}))}
|
||||
view={view}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** « {n} fiches » when everything is shown, « {n} fiches sur {total} » otherwise. */
|
||||
function CountLine({ shown, total }: { shown: number; total: number }) {
|
||||
const plural = usePlural()
|
||||
const key = shown === total ? 'count' : 'count_of'
|
||||
return (
|
||||
<p aria-live="polite" className="text-sm text-[var(--color-ink-muted)]">
|
||||
{plural(`admin.sheets.${key}`, shown).replace('{total}', () =>
|
||||
String(total),
|
||||
)}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyLine({ text }: { text: string }) {
|
||||
return (
|
||||
<p
|
||||
role="status"
|
||||
className="rounded-2xl border border-dashed border-[var(--color-border)] p-6 text-center text-[var(--color-ink)]"
|
||||
>
|
||||
{text}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A search alone found nothing: the sentence names it, with a way to clear it.
|
||||
* Not a live region: the count line already announces the empty result.
|
||||
*/
|
||||
function SearchNoResult({ view }: { view: ListView }) {
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="space-y-2 rounded-lg border border-[var(--color-border)] bg-[var(--color-surface-strong)] p-3 text-sm">
|
||||
<p className="[overflow-wrap:anywhere]">
|
||||
<strong>
|
||||
{t('admin.sheets.no_result').replace('{q}', () => view.query.trim())}
|
||||
</strong>
|
||||
</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={view.clearSearch}
|
||||
>
|
||||
<Icon name="close" size={14} className="mr-1" />
|
||||
{t('admin.sheets.clear_search')}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface ResultsProps {
|
||||
sheets: Sheet[]
|
||||
species: CatalogSpecies[]
|
||||
view: ListView
|
||||
}
|
||||
|
||||
/** The count line and the rows, or the empty state that fits (board 28 note). */
|
||||
function Results({ sheets, species, view }: ResultsProps) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
if (sheets.length === 0) return <EmptyLine text={t('admin.sheets.empty')} />
|
||||
const filtered = filterSheets(sheets, view.filters)
|
||||
const shown = sortSheets(
|
||||
searchSheets(filtered, view.query),
|
||||
view.sort,
|
||||
locale,
|
||||
)
|
||||
const filtering = Object.values(view.filters).some(Boolean)
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<CountLine shown={shown.length} total={sheets.length} />
|
||||
{shown.length === 0 &&
|
||||
(filtering ? (
|
||||
<EmptyLine text={t('admin.sheets.no_match')} />
|
||||
) : (
|
||||
<SearchNoResult view={view} />
|
||||
))}
|
||||
{shown.length > 0 && (
|
||||
<ul
|
||||
aria-label={t('admin.sheets.results_label')}
|
||||
className="divide-y divide-[var(--color-border)] rounded-2xl border border-[var(--color-border)] bg-[var(--color-surface)]"
|
||||
>
|
||||
{shown.map((sheet) => (
|
||||
<SheetRow key={sheet.sheet_id} sheet={sheet} species={species} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetsHeader() {
|
||||
const t = useT()
|
||||
const heading = usePageHeading()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const { editor } = useAdminPermissions()
|
||||
return (
|
||||
<header className="flex flex-wrap items-center justify-between gap-3">
|
||||
<h1
|
||||
ref={heading}
|
||||
tabIndex={-1}
|
||||
className="outline-none font-serif text-2xl text-[var(--color-ink)] sm:text-3xl"
|
||||
>
|
||||
{t('admin.sheets.title')}
|
||||
</h1>
|
||||
{editor && (
|
||||
<ButtonLink to="/app/admin/sheets/new" className="min-h-11">
|
||||
{t('admin.sheets.new')}
|
||||
</ButtonLink>
|
||||
)}
|
||||
</header>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* /app/admin/sheets (§11.1, boards 28 and 29 A): every official sheet with its badges
|
||||
* and last modification, searched by name, sorted, and narrowed by the four filters.
|
||||
*/
|
||||
export default function AdminSheetsRoute() {
|
||||
const t = useT()
|
||||
const { state, refresh } = useAdminQuery('admin-sheets-page', loadSheets)
|
||||
const [filters, setFilters] = useState<SheetFilters>(NO_FILTER)
|
||||
const view = useListView()
|
||||
|
||||
if (state.status === 'error' && isRightsRefusal(state.failure))
|
||||
return <AccessDenied />
|
||||
|
||||
const set = (key: keyof SheetFilters) => (value: string) =>
|
||||
setFilters((f) => ({ ...f, [key]: value }))
|
||||
const species = state.status === 'ready' ? state.data.species : []
|
||||
const shown =
|
||||
state.status === 'ready' ? filterSheets(state.data.sheets, filters) : []
|
||||
const options = (prefix: string, values: readonly string[]) =>
|
||||
values.map((value) => ({ value, label: t(`${prefix}.${value}`) }))
|
||||
const speciesOptions = [
|
||||
...new Set(
|
||||
state.status === 'ready'
|
||||
? state.data.sheets.map((s) => s.species_id)
|
||||
: [],
|
||||
),
|
||||
].map((id) => ({ value: id, label: speciesLabel(id, species, locale) }))
|
||||
|
||||
const data =
|
||||
state.status === 'ready' ? state.data : { sheets: [], species: [] }
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<header className="flex flex-wrap items-center justify-between gap-3">
|
||||
<h1
|
||||
ref={heading}
|
||||
tabIndex={-1}
|
||||
className="outline-none font-serif text-2xl text-[var(--color-ink)] sm:text-3xl"
|
||||
>
|
||||
{t('admin.sheets.title')}
|
||||
</h1>
|
||||
{editor && (
|
||||
<ButtonLink to="/app/admin/sheets/new" className="min-h-11">
|
||||
{t('admin.sheets.new')}
|
||||
</ButtonLink>
|
||||
)}
|
||||
</header>
|
||||
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<Filter
|
||||
id="species"
|
||||
label={t('admin.sheets.filter.species')}
|
||||
value={filters.species}
|
||||
options={speciesOptions}
|
||||
onChange={set('species')}
|
||||
/>
|
||||
<Filter
|
||||
id="sheetStatus"
|
||||
label={t('admin.sheets.filter.sheet_status')}
|
||||
value={filters.sheetStatus}
|
||||
options={options('admin.sheet_status', SHEET_STATUSES)}
|
||||
onChange={set('sheetStatus')}
|
||||
/>
|
||||
<Filter
|
||||
id="versionStatus"
|
||||
label={t('admin.sheets.filter.version_status')}
|
||||
value={filters.versionStatus}
|
||||
options={options('admin.version_status', VERSION_STATUSES)}
|
||||
onChange={set('versionStatus')}
|
||||
/>
|
||||
<Filter
|
||||
id="roundStatus"
|
||||
label={t('admin.sheets.filter.round_status')}
|
||||
value={filters.roundStatus}
|
||||
options={options('admin.round_status', ROUND_STATUSES)}
|
||||
onChange={set('roundStatus')}
|
||||
/>
|
||||
<SheetsHeader />
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
|
||||
<SearchField view={view} />
|
||||
<SortSelect view={view} />
|
||||
</div>
|
||||
|
||||
<Filters sheets={data.sheets} species={data.species} view={view} />
|
||||
{state.status === 'loading' && (
|
||||
<p role="status" className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('admin.sheets.loading')}
|
||||
@@ -221,32 +407,8 @@ export default function AdminSheetsRoute() {
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{state.status === 'ready' && shown.length === 0 && (
|
||||
<p
|
||||
role="status"
|
||||
className="rounded-2xl border border-dashed border-[var(--color-border)] p-6 text-center text-[var(--color-ink)]"
|
||||
>
|
||||
{t(
|
||||
state.data.sheets.length === 0
|
||||
? 'admin.sheets.empty'
|
||||
: 'admin.sheets.no_match',
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{shown.length > 0 && (
|
||||
<ul
|
||||
aria-label={t('admin.sheets.results_label')}
|
||||
className="divide-y divide-[var(--color-border)] rounded-2xl border border-[var(--color-border)] bg-[var(--color-surface)]"
|
||||
>
|
||||
{shown.map((sheet) => (
|
||||
<SheetRow
|
||||
key={sheet.sheet_id}
|
||||
sheet={sheet}
|
||||
species={species}
|
||||
t={t}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
{state.status === 'ready' && (
|
||||
<Results sheets={data.sheets} species={data.species} view={view} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { formatShortParisDateTime } from '@/admin/labels'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
|
||||
/**
|
||||
* « Modifiée le 9 nov. 2026, 12:06 » (A8, Paris time), the whole phrase in a
|
||||
* `<time>`: its value is re-serialised because a valid HTML time carries at
|
||||
* most three fraction digits and the server sends six.
|
||||
*/
|
||||
export default function ModifiedDate({ iso }: { iso: string }) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
return (
|
||||
<time dateTime={new Date(iso).toISOString()}>
|
||||
{t('admin.sheets.modified').replace('{date}', () =>
|
||||
formatShortParisDateTime(iso, locale),
|
||||
)}
|
||||
</time>
|
||||
)
|
||||
}
|
||||
@@ -1026,6 +1026,17 @@ export const en: Dict = {
|
||||
'admin.sheets.no_published': 'no published version',
|
||||
'admin.sheets.draft': 'draft version {number}',
|
||||
'admin.sheets.latest_round': 'review no. {round}: {status}',
|
||||
'admin.sheets.search': 'Search a sheet by name',
|
||||
'admin.sheets.clear_search': 'Clear the search',
|
||||
'admin.sheets.sort_by': 'Sort by',
|
||||
'admin.sheets.sort.modified': 'Last modified',
|
||||
'admin.sheets.sort.name': 'Name',
|
||||
'admin.sheets.count_one': '{count} sheet',
|
||||
'admin.sheets.count_other': '{count} sheets',
|
||||
'admin.sheets.count_of_one': '{count} sheet of {total}',
|
||||
'admin.sheets.count_of_other': '{count} sheets of {total}',
|
||||
'admin.sheets.modified': 'Modified on {date}',
|
||||
'admin.sheets.no_result': 'No sheet name contains “{q}”.',
|
||||
'admin.sheet_form.lede': 'The sheet starts empty: views, annotations and findings are entered later in the editor.',
|
||||
'admin.sheet_form.species': 'Species',
|
||||
'admin.sheet_form.species_hint': 'Active or not. Creating a sheet does not activate the species.',
|
||||
|
||||
@@ -1057,6 +1057,17 @@ export const fr: Dict = {
|
||||
'admin.sheets.no_published': 'aucune version publiée',
|
||||
'admin.sheets.draft': 'brouillon version {number}',
|
||||
'admin.sheets.latest_round': 'revue n° {round} : {status}',
|
||||
'admin.sheets.search': 'Rechercher une fiche par son nom',
|
||||
'admin.sheets.clear_search': 'Effacer la recherche',
|
||||
'admin.sheets.sort_by': 'Trier par',
|
||||
'admin.sheets.sort.modified': 'Dernière modification',
|
||||
'admin.sheets.sort.name': 'Nom',
|
||||
'admin.sheets.count_one': '{count} fiche',
|
||||
'admin.sheets.count_other': '{count} fiches',
|
||||
'admin.sheets.count_of_one': '{count} fiche sur {total}',
|
||||
'admin.sheets.count_of_other': '{count} fiches sur {total}',
|
||||
'admin.sheets.modified': 'Modifiée le {date}',
|
||||
'admin.sheets.no_result': 'Aucune fiche ne contient « {q} » dans son nom.',
|
||||
'admin.sheet_form.lede': "La fiche démarre vide : vues, annotations et constats se saisissent ensuite dans l'éditeur.",
|
||||
'admin.sheet_form.species': 'Espèce',
|
||||
'admin.sheet_form.species_hint': "Active ou non. Créer une fiche n'active pas l'espèce.",
|
||||
|
||||
@@ -642,6 +642,159 @@ describe('Official sheets list (H1)', () => {
|
||||
await screen.findByRole('list', { name: 'Liste des fiches officielles' })
|
||||
expect(screen.queryByRole('link', { name: 'Nouvelle fiche' })).toBeNull()
|
||||
})
|
||||
// R3 (boards 28, 29 A): search, sort, count line and date over three sheets.
|
||||
const HORSE = 'Cheval, squelette et rachis'
|
||||
const DOG = 'Chien, squelette et rachis'
|
||||
const DONKEY = 'Âne, squelette et rachis'
|
||||
const threeSheets = () => [
|
||||
summary({ last_modified_at: '2026-11-09T11:06:00.123456+00:00' }),
|
||||
summary({
|
||||
sheet_id: '55555555-5555-4555-8555-555555555555',
|
||||
slug: 'chien-squelette',
|
||||
name: { fr: DOG, en: 'Dog, skeleton and spine' },
|
||||
last_modified_at: '2026-11-08T16:41:00+00:00',
|
||||
}),
|
||||
summary({
|
||||
sheet_id: '66666666-6666-4666-8666-666666666666',
|
||||
slug: 'ane-squelette',
|
||||
name: { fr: DONKEY, en: 'Donkey, skeleton and spine' },
|
||||
last_modified_at: '2026-11-03T10:02:00+00:00',
|
||||
}),
|
||||
]
|
||||
const ALL_NAMES = [HORSE, DOG, DONKEY]
|
||||
async function mountThree() {
|
||||
fake.rpcResults.list_official_sheets_admin = { data: threeSheets() }
|
||||
mount('/app/admin/sheets', [grant('sheet_editor')])
|
||||
return within(
|
||||
await screen.findByRole('list', { name: 'Liste des fiches officielles' }),
|
||||
)
|
||||
}
|
||||
const rowNames = (list: ReturnType<typeof within>) =>
|
||||
list
|
||||
.getAllByRole('link')
|
||||
.map((row: HTMLElement) => ALL_NAMES.find((n) => row.textContent?.startsWith(n)))
|
||||
const searchField = () =>
|
||||
screen.getByRole('searchbox', { name: 'Rechercher une fiche par son nom' })
|
||||
|
||||
it('orders by last modification, newest first, and dates each row', async () => {
|
||||
const list = await mountThree()
|
||||
expect(rowNames(list)).toEqual([HORSE, DOG, DONKEY])
|
||||
const date = list.getByText('Modifiée le 9 nov. 2026, 12:06')
|
||||
expect(date.tagName).toBe('TIME')
|
||||
expect(date).toHaveAttribute('datetime', '2026-11-09T11:06:00.123Z')
|
||||
expect(screen.getByText('3 fiches')).toHaveAttribute('aria-live', 'polite')
|
||||
expect(screen.getByLabelText('Trier par')).toHaveValue('modified')
|
||||
})
|
||||
|
||||
it('narrows the list by name as the user types and counts « 1 fiche sur 3 »', async () => {
|
||||
const user = userEvent.setup()
|
||||
const list = await mountThree()
|
||||
expect(searchField()).toHaveAttribute('maxlength', '100')
|
||||
expect(searchField()).toHaveAttribute('autocomplete', 'off')
|
||||
await user.type(searchField(), 'chev')
|
||||
expect(rowNames(list)).toEqual([HORSE])
|
||||
expect(screen.getByText('1 fiche sur 3')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('clears the search by « × » or Escape and gives the focus back to the field', async () => {
|
||||
const user = userEvent.setup()
|
||||
await mountThree()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Effacer la recherche' }),
|
||||
).toBeNull()
|
||||
await user.type(searchField(), 'chev')
|
||||
await user.click(screen.getByRole('button', { name: 'Effacer la recherche' }))
|
||||
expect(searchField()).toHaveValue('')
|
||||
expect(screen.getByText('3 fiches')).toBeInTheDocument()
|
||||
expect(searchField()).toHaveFocus()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Effacer la recherche' }),
|
||||
).toBeNull()
|
||||
|
||||
const reached: string[] = []
|
||||
const listen = (event: KeyboardEvent) => reached.push(event.key)
|
||||
window.addEventListener('keydown', listen)
|
||||
try {
|
||||
await user.type(searchField(), 'chien')
|
||||
expect(screen.getByText('1 fiche sur 3')).toBeInTheDocument()
|
||||
reached.length = 0
|
||||
await user.keyboard('{Escape}')
|
||||
expect(searchField()).toHaveValue('')
|
||||
expect(screen.getByText('3 fiches')).toBeInTheDocument()
|
||||
expect(searchField()).toHaveFocus()
|
||||
expect(reached).toEqual([])
|
||||
await user.keyboard('{Escape}')
|
||||
expect(searchField()).toHaveValue('')
|
||||
expect(screen.getByText('3 fiches')).toBeInTheDocument()
|
||||
expect(reached).toEqual(['Escape'])
|
||||
} finally {
|
||||
window.removeEventListener('keydown', listen)
|
||||
}
|
||||
})
|
||||
|
||||
it('reorders the rows by name with « Nom »', async () => {
|
||||
const user = userEvent.setup()
|
||||
const list = await mountThree()
|
||||
await user.selectOptions(screen.getByLabelText('Trier par'), 'name')
|
||||
expect(rowNames(list)).toEqual([DONKEY, HORSE, DOG])
|
||||
})
|
||||
|
||||
it('tells the three empty states apart; the search text is shown as typed', async () => {
|
||||
const user = userEvent.setup()
|
||||
fake.rpcResults.list_official_sheets_admin = { data: [] }
|
||||
const view = mount('/app/admin/sheets', [grant('sheet_editor')])
|
||||
expect(
|
||||
await screen.findByText('Aucune fiche officielle pour le moment.'),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByText(/^0 fiche/)).toBeNull()
|
||||
view.unmount()
|
||||
|
||||
await mountThree()
|
||||
await user.type(searchField(), ' mulet ')
|
||||
expect(screen.getByText('0 fiche sur 3')).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByText('Aucune fiche ne contient « mulet » dans son nom.'),
|
||||
).toBeInTheDocument()
|
||||
const clears = screen.getAllByRole('button', {
|
||||
name: 'Effacer la recherche',
|
||||
})
|
||||
expect(clears).toHaveLength(2)
|
||||
await user.click(clears[1])
|
||||
expect(searchField()).toHaveValue('')
|
||||
expect(searchField()).toHaveFocus()
|
||||
expect(screen.getByText('3 fiches')).toBeInTheDocument()
|
||||
|
||||
await user.type(searchField(), '$&')
|
||||
expect(
|
||||
screen.getByText('Aucune fiche ne contient « $& » dans son nom.'),
|
||||
).toBeInTheDocument()
|
||||
|
||||
await user.selectOptions(
|
||||
screen.getByLabelText('Statut de version'),
|
||||
'published',
|
||||
)
|
||||
expect(
|
||||
screen.getByText('Aucune fiche ne correspond à ces filtres.'),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByText(/Aucune fiche ne contient/)).toBeNull()
|
||||
})
|
||||
|
||||
it('reads in English: count, date and sort label', async () => {
|
||||
useLocaleStore.setState({ locale: 'en' })
|
||||
const user = userEvent.setup()
|
||||
fake.rpcResults.list_official_sheets_admin = { data: threeSheets() }
|
||||
mount('/app/admin/sheets', [grant('sheet_editor')])
|
||||
const list = within(
|
||||
await screen.findByRole('list', { name: 'Official sheet list' }),
|
||||
)
|
||||
expect(list.getByText('Modified on 9 Nov 2026, 12:06')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Sort by')).toBeInTheDocument()
|
||||
await user.type(
|
||||
screen.getByRole('searchbox', { name: 'Search a sheet by name' }),
|
||||
'horse',
|
||||
)
|
||||
expect(screen.getByText('1 sheet of 3')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Sheet creation (A1)', () => {
|
||||
|
||||
Reference in new issue
Block a user