diff --git a/client/src/components/Admin/PlaceContribLog.test.tsx b/client/src/components/Admin/PlaceContribLog.test.tsx index 608b37f85..a7fc689dc 100644 --- a/client/src/components/Admin/PlaceContribLog.test.tsx +++ b/client/src/components/Admin/PlaceContribLog.test.tsx @@ -1,4 +1,4 @@ -// FE-ADMIN-CONTRIB-LOG-001 to FE-ADMIN-CONTRIB-LOG-003 +// FE-ADMIN-CONTRIB-LOG-001 to FE-ADMIN-CONTRIB-LOG-004 import userEvent from '@testing-library/user-event'; import type { PlaceContribLogEntry } from '@trek/shared'; import { http, HttpResponse } from 'msw'; @@ -58,9 +58,23 @@ describe('PlaceContribLog', () => { it('FE-ADMIN-CONTRIB-LOG-003: pages through a long log', async () => { const queries = serve([ENTRY], 45); render(); + await userEvent.click(await screen.findByRole('button', { name: /common\.showMore/ })); expect(await screen.findByText('1 / 3')).toBeInTheDocument(); await userEvent.click(screen.getByRole('button', { name: 'admin.contribute.log.next' })); await waitFor(() => expect(queries[queries.length - 1]?.get('page')).toBe('2')); expect(queries[queries.length - 1]?.get('perPage')).toBe('20'); }); + + it('FE-ADMIN-CONTRIB-LOG-004: shows the newest five until the list is opened', async () => { + serve(Array.from({ length: 8 }, (_, i) => ({ ...ENTRY, id: i + 1, placeName: `Place ${i + 1}` }))); + render(); + expect(await screen.findByText('Place 5')).toBeInTheDocument(); + expect(screen.queryByText('Place 6')).not.toBeInTheDocument(); + const toggle = screen.getByRole('button', { name: 'common.showMore (3)' }); + expect(toggle).toHaveAttribute('aria-expanded', 'false'); + await userEvent.click(toggle); + expect(screen.getByText('Place 8')).toBeInTheDocument(); + await userEvent.click(screen.getByRole('button', { name: 'common.showLess' })); + expect(screen.queryByText('Place 8')).not.toBeInTheDocument(); + }); }); diff --git a/client/src/components/Admin/PlaceContribLog.tsx b/client/src/components/Admin/PlaceContribLog.tsx index 9ff67453e..fb77051e6 100644 --- a/client/src/components/Admin/PlaceContribLog.tsx +++ b/client/src/components/Admin/PlaceContribLog.tsx @@ -4,7 +4,7 @@ import { type PlaceContribLogResponse, type PlaceContribLogResult, } from '@trek/shared'; -import { ChevronLeft, ChevronRight } from 'lucide-react'; +import { ChevronDown, ChevronLeft, ChevronRight } from 'lucide-react'; import { useEffect, useState } from 'react'; import { useTranslation } from '../../i18n'; import { placeContribRepo } from '../../repo/placeContribRepo'; @@ -13,6 +13,8 @@ import { fs } from '../shared/DialogShell'; import { fieldLabel } from './placeContribModel'; const PER_PAGE = 20; +/** Rows shown before the list is opened; a busy log should not push the page down. */ +const FOLDED = 5; const RESULTS: PlaceContribLogResult[] = ['accepted', 'duplicate', 'rejected', 'withheld', 'retracted']; const RESULT_LOOK: Record = { accepted: 'bg-success-soft text-success', @@ -25,7 +27,7 @@ const RESULT_LOOK: Record = { /** * What this installation sent, newest first: the place, the field, a short * form of the value and what the service made of it. Read only while the fold - * is open, a page at a time. + * is open, a page at a time, and only the newest FOLDED rows until opened. */ export default function PlaceContribLog() { const { t, locale } = useTranslation(); @@ -33,6 +35,7 @@ export default function PlaceContribLog() { const [result, setResult] = useState('all'); const [field, setField] = useState('all'); const [data, setData] = useState(null); + const [open, setOpen] = useState(false); // The query that failed to load, so a new page or filter clears the message by itself. const query = `${page}|${result}|${field}`; const [failedQuery, setFailedQuery] = useState(null); @@ -57,6 +60,8 @@ export default function PlaceContribLog() { }, [page, result, field]); const pages = data ? Math.max(1, Math.ceil(data.total / PER_PAGE)) : 1; + const foldable = !!data && (data.entries.length > FOLDED || pages > 1); + const rows = data ? (open || !foldable ? data.entries : data.entries.slice(0, FOLDED)) : []; const day = new Intl.DateTimeFormat(locale, { day: 'numeric', month: 'short' }); return ( @@ -102,7 +107,7 @@ export default function PlaceContribLog() { )} {data && data.entries.length > 0 && (
    - {data.entries.map((e) => ( + {rows.map((e) => (
  • {day.format(new Date(`${e.day}T12:00:00`))} @@ -135,7 +140,24 @@ export default function PlaceContribLog() {
)} - {data && pages > 1 && ( + {foldable && ( + + )} + + {data && open && pages > 1 && (