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',
|
||||
|
||||
Reference in new issue
Block a user