diff --git a/apps/app/src/admin/labels.ts b/apps/app/src/admin/labels.ts index 646958b5..5fe43009 100644 --- a/apps/app/src/admin/labels.ts +++ b/apps/app/src/admin/labels.ts @@ -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 diff --git a/apps/app/src/app/routes/app/admin/AdminSheetsRoute.tsx b/apps/app/src/app/routes/app/admin/AdminSheetsRoute.tsx index 6ec5477c..4d637e6f 100644 --- a/apps/app/src/app/routes/app/admin/AdminSheetsRoute.tsx +++ b/apps/app/src/app/routes/app/admin/AdminSheetsRoute.tsx @@ -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 +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(NO_FILTER) + const [query, setQuery] = useState('') + const [sort, setSort] = useState('modified') + const searchRef = useRef(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 function SheetRow({ sheet, species, - t, }: { - sheet: OfficialSheetAdminSummary + sheet: Sheet species: CatalogSpecies[] - t: Translate }) { + const t = useT() const locale = useLocaleStore((s) => s.locale) return (
  • - - + + {localized(sheet.name, locale)} - - {[ - speciesLabel(sheet.species_id, species, locale), - ...details(t, sheet), - ].join(' · ')} + + {sheetDetails(t, sheet, species, locale)} + + +
  • ) } +// 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 ( +
    + setQuery(event.target.value)} + onKeyDown={escape} + className="pr-11 max-sm:h-11 [&::-webkit-search-cancel-button]:appearance-none" + /> + {query !== '' && ( + + )} +
    + ) +} + +/** « Trier par »: a native select, « Dernière modification » by default, or « Nom ». */ +function SortSelect({ view }: { view: ListView }) { + const t = useT() + return ( +
    + + +
    + ) +} + 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 (