feat(app): Administration home lists the latest modified sheets
Board 29 B: five latest sheets with badges, detail line and date; footer link shows the total from two sheets. R-24: no existing assertion removed or rewritten; seven cases added.
This commit is contained in:
1 parent
856667d070
commit
de2424f519
4 files changed
+210
-22
No files matched your search
@@ -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<typeof useT>
|
||||
/** 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 (
|
||||
<li className="space-y-2 py-3 first:pt-0 last:pb-0">
|
||||
@@ -62,6 +80,12 @@ function SheetItem({
|
||||
</Link>
|
||||
<SheetBadges sheet={sheet} />
|
||||
</div>
|
||||
<p className="text-[var(--color-ink-muted)]">
|
||||
{sheetDetails(t, sheet, species, locale)}
|
||||
</p>
|
||||
<p className="text-[var(--color-ink-muted)]">
|
||||
<ModifiedDate iso={sheet.last_modified_at} />
|
||||
</p>
|
||||
{/* The working copy action (W1): editors only, on the historical sheet. */}
|
||||
{sheet.historical && editor && (
|
||||
<WorkingCopyAction
|
||||
@@ -74,15 +98,56 @@ function SheetItem({
|
||||
)
|
||||
}
|
||||
|
||||
/** The five latest modified sheets (board 29 B), under their sub-heading. */
|
||||
function LatestSheets({
|
||||
sheets,
|
||||
species,
|
||||
editor,
|
||||
}: {
|
||||
sheets: OfficialSheetAdminSummary[]
|
||||
species: CatalogSpecies[]
|
||||
editor: boolean
|
||||
}) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const latest = sortSheets(sheets, 'modified', locale).slice(0, CARD_SHEETS)
|
||||
if (latest.length === 0) return null
|
||||
return (
|
||||
<>
|
||||
<h3 className={SUBHEADING}>{t('admin.home.latest')}</h3>
|
||||
<ul className="divide-y divide-[var(--color-border)] text-sm">
|
||||
{latest.map((sheet) => (
|
||||
<SheetItem
|
||||
key={sheet.sheet_id}
|
||||
sheet={sheet}
|
||||
species={species}
|
||||
editor={editor}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/** « 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 (
|
||||
<Link to="/app/admin/sheets" className={LINK}>
|
||||
{label}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
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 (
|
||||
<Card
|
||||
as="section"
|
||||
@@ -111,22 +176,16 @@ function SheetsCard({ editor }: { editor: boolean }) {
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{state.status === 'ready' && state.data.length === 0 && (
|
||||
{state.status === 'ready' && state.data.sheets.length === 0 && (
|
||||
<p className="text-sm text-[var(--color-ink)]">
|
||||
{t('admin.sheets.empty')}
|
||||
</p>
|
||||
)}
|
||||
{shown.length > 0 && (
|
||||
<ul className="divide-y divide-[var(--color-border)] text-sm">
|
||||
{shown.map((sheet) => (
|
||||
<SheetItem key={sheet.sheet_id} sheet={sheet} editor={editor} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{state.status === 'ready' && (
|
||||
<Link to="/app/admin/sheets" className={LINK}>
|
||||
{t('admin.home.all_sheets')}
|
||||
</Link>
|
||||
<>
|
||||
<LatestSheets {...state.data} editor={editor} />
|
||||
<SeeAllLink total={state.data.sheets.length} />
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
)
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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' }))
|
||||
|
||||
|
||||
Reference in new issue
Block a user