diff --git a/apps/app/src/app/routes/app/admin/AdminHomeRoute.tsx b/apps/app/src/app/routes/app/admin/AdminHomeRoute.tsx index 04ef50bb..cc5b5731 100644 --- a/apps/app/src/app/routes/app/admin/AdminHomeRoute.tsx +++ b/apps/app/src/app/routes/app/admin/AdminHomeRoute.tsx @@ -1,9 +1,13 @@ import { useRef } from 'react' import { Link } from 'react-router-dom' import { + listCatalogSpecies, listOfficialSheetsAdmin, + type CatalogSpecies, + type FaunosteoClient, type OfficialSheetAdminSummary, } from '@faunosteo/supabase' +import ModifiedDate from '@/components/admin/ModifiedDate' import SheetBadges from '@/components/admin/SheetBadges' import WorkingCopyAction from '@/components/admin/WorkingCopyAction' import PermissionsUnavailable from '@/components/shell/PermissionsUnavailable' @@ -11,7 +15,8 @@ import Button from '@/components/ui/Button' import ButtonLink from '@/components/ui/ButtonLink' import Card from '@/components/ui/Card' import Notice from '@/components/ui/Notice' -import { failureMessage, localized } from '@/admin/labels' +import { failureMessage, localized, sheetDetails } from '@/admin/labels' +import { sortSheets } from '@/admin/sheetList' import { useAdminPermissions, type AdminPermissions } from '@/admin/permissions' import { isRightsRefusal, useAdminQuery } from '@/admin/useAdminQuery' import { usePageHeading } from '@/app/usePageHeading' @@ -24,6 +29,9 @@ type Translate = ReturnType /** At most this many sheets on the card; the full list is one link away. */ const CARD_SHEETS = 5 +const SUBHEADING = + 'text-xs font-semibold uppercase tracking-wide text-[var(--color-ink-muted)]' + const LINK = 'inline-flex min-h-11 items-center text-sm font-medium text-[var(--color-accent-strong)] underline underline-offset-2' @@ -43,13 +51,23 @@ function permissionsLine(t: Translate, permissions: AdminPermissions): string { return `${parts.join(' · ')}.` } -function SheetItem({ - sheet, - editor, -}: { +/** The list and the species names; a species read that fails leaves the ids as labels. */ +async function loadCard(client: FaunosteoClient) { + const [sheets, species] = await Promise.all([ + listOfficialSheetsAdmin(client), + listCatalogSpecies(client).catch(() => []), + ]) + return { sheets, species } +} + +interface SheetItemProps { sheet: OfficialSheetAdminSummary + species: CatalogSpecies[] editor: boolean -}) { +} + +function SheetItem({ sheet, species, editor }: SheetItemProps) { + const t = useT() const locale = useLocaleStore((s) => s.locale) return (
  • @@ -62,6 +80,12 @@ function SheetItem({ +

    + {sheetDetails(t, sheet, species, locale)} +

    +

    + +

    {/* The working copy action (W1): editors only, on the historical sheet. */} {sheet.historical && editor && ( s.locale) + const latest = sortSheets(sheets, 'modified', locale).slice(0, CARD_SHEETS) + if (latest.length === 0) return null + return ( + <> +

    {t('admin.home.latest')}

    +
      + {latest.map((sheet) => ( + + ))} +
    + + ) +} + +/** « Voir les {n} fiches » from two sheets; the plain link for none or one (D6). */ +function SeeAllLink({ total }: { total: number }) { + const t = useT() + const label = + total < 2 + ? t('admin.home.all_sheets') + : t('admin.home.see_all').replace('{count}', () => String(total)) + return ( + + {label} + + ) +} + function SheetsCard({ editor }: { editor: boolean }) { const t = useT() - const { state, refresh } = useAdminQuery( - 'admin-sheets', - listOfficialSheetsAdmin, - ) + const { state, refresh } = useAdminQuery('admin-sheets', loadCard) // Without a capability the server refuses the list: the card is not this account's. if (state.status === 'error' && isRightsRefusal(state.failure)) return null - const shown = state.status === 'ready' ? state.data.slice(0, CARD_SHEETS) : [] return ( )} - {state.status === 'ready' && state.data.length === 0 && ( + {state.status === 'ready' && state.data.sheets.length === 0 && (

    {t('admin.sheets.empty')}

    )} - {shown.length > 0 && ( -
      - {shown.map((sheet) => ( - - ))} -
    - )} {state.status === 'ready' && ( - - {t('admin.home.all_sheets')} - + <> + + + )}
    ) diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts index 1a34adae..4a5329cb 100644 --- a/apps/app/src/i18n/en.ts +++ b/apps/app/src/i18n/en.ts @@ -934,6 +934,8 @@ export const en: Dict = { 'admin.home.access_body': 'Catalogue access and permissions: grant, expiry, revocation.', 'admin.home.open': 'Open', 'admin.home.all_sheets': 'All official sheets', + 'admin.home.latest': 'Latest changes', + 'admin.home.see_all': 'See the {count} sheets', 'admin.badge.historical': 'Historical sheet', 'admin.badge.working_copy': 'Working copy', 'admin.badge.to_review': '{count} awaiting review', diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts index 88a5441c..34333016 100644 --- a/apps/app/src/i18n/fr.ts +++ b/apps/app/src/i18n/fr.ts @@ -965,6 +965,8 @@ export const fr: Dict = { 'admin.home.access_body': 'Accès au catalogue et habilitations : attribution, échéance, révocation.', 'admin.home.open': 'Ouvrir', 'admin.home.all_sheets': 'Toutes les fiches officielles', + 'admin.home.latest': 'Dernières modifications', + 'admin.home.see_all': 'Voir les {count} fiches', 'admin.badge.historical': 'Fiche historique', 'admin.badge.working_copy': 'Copie de travail', 'admin.badge.to_review': '{count} à relire', diff --git a/apps/app/tests/unit/routes.admin.test.tsx b/apps/app/tests/unit/routes.admin.test.tsx index ee01eb05..856d546b 100644 --- a/apps/app/tests/unit/routes.admin.test.tsx +++ b/apps/app/tests/unit/routes.admin.test.tsx @@ -310,6 +310,131 @@ describe('Administration page (board 10)', () => { }) }) +/** Seven sheets named « Fiche n », modified on n Nov 2026 (Paris 11:00), unsorted. */ +function sevenSheets() { + return [3, 7, 1, 5, 2, 6, 4].map((n) => + summary({ + sheet_id: `00000000-0000-4000-8000-00000000000${n}`, + slug: `fiche-${n}`, + name: { fr: `Fiche ${n}`, en: `Sheet ${n}` }, + last_modified_at: `2026-11-0${n}T10:00:00.000000+00:00`, + }), + ) +} + +describe('Administration home card: latest modified sheets (board 29 B)', () => { + const cardItems = async () => + within(await screen.findByRole('list')).getAllByRole('listitem') + const historicalAt = (day: string) => ({ + ...historical(), + last_modified_at: `2026-${day}T10:00:00.000000+00:00`, + }) + const COPY = { name: 'Créer une copie de travail' } + + it('seven sheets: five items, newest first, then « Voir les 7 fiches »', async () => { + fake.rpcResults.list_official_sheets_admin = { data: sevenSheets() } + mount('/app/admin', [grant('sheet_editor')]) + const items = await cardItems() + expect(items).toHaveLength(5) + expect( + items.map((li) => within(li).getAllByRole('link')[0].textContent), + ).toEqual(['Fiche 7', 'Fiche 6', 'Fiche 5', 'Fiche 4', 'Fiche 3']) + expect( + screen.getByRole('heading', { name: 'Dernières modifications' }), + ).toBeInTheDocument() + expect( + screen.getByRole('link', { name: 'Voir les 7 fiches' }), + ).toHaveAttribute('href', '/app/admin/sheets') + expect(screen.queryByText('Toutes les fiches officielles')).toBeNull() + }) + + it('one sheet: the sub-heading, the item and « Toutes les fiches officielles »', async () => { + fake.rpcResults.list_official_sheets_admin = { data: [summary()] } + mount('/app/admin', [grant('sheet_editor')]) + expect(await cardItems()).toHaveLength(1) + expect( + screen.getByRole('heading', { name: 'Dernières modifications' }), + ).toBeInTheDocument() + expect( + screen.getByRole('link', { name: 'Toutes les fiches officielles' }), + ).toHaveAttribute('href', '/app/admin/sheets') + }) + + it('no sheet: the empty sentence, no sub-heading, the same link', async () => { + fake.rpcResults.list_official_sheets_admin = { data: [] } + mount('/app/admin', [grant('sheet_editor')]) + expect(await screen.findByText(fr['admin.sheets.empty'])).toBeInTheDocument() + expect( + screen.queryByRole('heading', { name: 'Dernières modifications' }), + ).toBeNull() + expect(screen.queryByRole('list')).toBeNull() + expect( + screen.getByRole('link', { name: 'Toutes les fiches officielles' }), + ).toBeInTheDocument() + }) + + it('the historical sheet keeps its action inside the five, for an editor only', async () => { + // Newest of all: inside the five. + fake.rpcResults.list_official_sheets_admin = { + data: [historicalAt('11-09'), ...sevenSheets()], + } + mount('/app/admin', [grant('sheet_editor')]) + await cardItems() + expect(screen.getByRole('button', COPY)).toBeInTheDocument() + cleanup() + // Inside the five, but the account is a reviewer. + mount('/app/admin', [grant('sheet_reviewer')]) + await cardItems() + expect(screen.queryByRole('button', COPY)).toBeNull() + cleanup() + // Oldest of all: outside the five. + fake.rpcResults.list_official_sheets_admin = { + data: [historicalAt('10-01'), ...sevenSheets()], + } + mount('/app/admin', [grant('sheet_editor')]) + await cardItems() + expect(screen.queryByRole('link', { name: 'Cheval' })).toBeNull() + expect(screen.queryByRole('button', COPY)).toBeNull() + }) + + it('the detail line and the date are those of the list', async () => { + mount('/app/admin', [grant('sheet_editor')]) + const [item] = await cardItems() + const detail = within(item).getByText(/^Cheval · /).textContent ?? '' + const date = within(item).getByText(/^Modifiée le /).textContent ?? '' + expect(date).toBe('Modifiée le 1 nov. 2026, 11:00') + cleanup() + mount('/app/admin/sheets', [grant('sheet_editor')]) + const row = (await screen.findAllByRole('listitem'))[0] + expect(within(row).getByText(detail)).toBeInTheDocument() + expect(within(row).getByText(date)).toBeInTheDocument() + }) + + it('a refused species read: the card still shows, the id in the detail line', async () => { + fake.rpcResults.list_catalog_species = refusal('rights.capability') + mount('/app/admin', [grant('sheet_editor')]) + const [item] = await cardItems() + expect(within(item).getByText(/^equine · /)).toBeInTheDocument() + expect(screen.queryByRole('alert')).toBeNull() + }) + + it('English texts', async () => { + useLocaleStore.setState({ locale: 'en' }) + fake.rpcResults.list_official_sheets_admin = { data: sevenSheets() } + mount('/app/admin', [grant('sheet_editor')]) + await cardItems() + expect( + screen.getByRole('heading', { name: 'Latest changes' }), + ).toBeInTheDocument() + expect( + screen.getByRole('link', { name: 'See the 7 sheets' }), + ).toBeInTheDocument() + expect( + screen.getByText('Modified on 7 Nov 2026, 11:00'), + ).toBeInTheDocument() + }) +}) + describe('Species (S1, matrix §5.4)', () => { const rows = () => within(screen.getByRole('list', { name: 'Espèces' }))