diff --git a/admin/src/lib/format.ts b/admin/src/lib/format.ts index 1c73bfc..bafb231 100644 --- a/admin/src/lib/format.ts +++ b/admin/src/lib/format.ts @@ -42,6 +42,12 @@ export function fmtDateTime(iso: string | null | undefined): string { }); } +/** Godzina „HH:MM" wg języka (do drugiej linii kolumny daty). */ +export function fmtTime(iso: string | null | undefined): string { + if (!iso) return '—'; + return new Date(iso).toLocaleTimeString(currentTag(), { hour: '2-digit', minute: '2-digit' }); +} + /** Czas względny: „przed chwilą”, „5 min temu”, „wczoraj”, potem data. */ export function timeAgo(iso: string | null | undefined): string { if (!iso) return '—'; diff --git a/admin/src/pages/Logs.tsx b/admin/src/pages/Logs.tsx index bee12dd..f51f53a 100644 --- a/admin/src/pages/Logs.tsx +++ b/admin/src/pages/Logs.tsx @@ -9,7 +9,7 @@ import type { ActivityLog, ActivityLogPage } from '../api/types'; import { Badge, EmptyState, ErrorText, Loading, Select, type BadgeColor } from '../components/ui'; import { useListSearch } from '../store/list-search'; import i18n from '../i18n'; -import { fmtDateTime } from '../lib/format'; +import { fmtDate, fmtDateTime, fmtTime } from '../lib/format'; const t = (key: string, options?: Record): string => String(i18n.t(`logs:${key}`, options as never)); @@ -143,13 +143,18 @@ function formatDetailValue(log: ActivityLog, key: string, value: unknown): strin return text; } -/** Szczegóły wpisu jako naturalny tekst: `start: 2026-08-24 · wartość: 82.5 kg`. */ -export function detailsText(log: ActivityLog) { +/** Szczegóły wpisu jako linie: `start: 2026-08-24`, `wartość: 82.5 kg` — jedna pod drugą. */ +export function detailsLines(log: ActivityLog): string[] { const d = log.details; - if (!d) return null; - const parts = Object.entries(d) + if (!d) return []; + return Object.entries(d) .filter(([k]) => !HIDDEN_DETAIL_KEYS.has(k)) .map(([k, v]) => `${t(`details.${k}`, { defaultValue: k })}: ${formatDetailValue(log, k, v)}`); +} + +/** Szczegóły jako jeden tekst: `start: 2026-08-24 · wartość: 82.5 kg`. */ +export function detailsText(log: ActivityLog) { + const parts = detailsLines(log); return parts.length > 0 ? parts.join(' · ') : null; } @@ -288,8 +293,11 @@ export default function Logs() { key={log.id} className="border-b border-line/60 transition-colors last:border-b-0 hover:bg-line/20" > - - {formatLogDate(log.createdAt)} + +
{fmtDate(log.createdAt)}
+
+ {fmtTime(log.createdAt)} +
{actorName(log)}
@@ -298,8 +306,13 @@ export default function Logs() { {log.actor.id} - - {actionLabel(log.action)} + + + {actionLabel(log.action)} +
{tr(`entities.${log.entityType}`, { defaultValue: log.entityType })}
@@ -307,7 +320,17 @@ export default function Logs() {
{entityName(log)}
)} - {detailsText(log) ?? '—'} + + {detailsLines(log).length > 0 ? ( +
+ {detailsLines(log).map((line) => ( +
{line}
+ ))} +
+ ) : ( + '—' + )} + ))} diff --git a/admin/test/Logs.test.tsx b/admin/test/Logs.test.tsx index 6fd6483..749dcd5 100644 --- a/admin/test/Logs.test.tsx +++ b/admin/test/Logs.test.tsx @@ -89,6 +89,8 @@ describe('admin Logs page', () => { // Jan Kowalski w dwóch wierszach (plan.activated + weight.removed) expect((await screen.findAllByText('Jan Kowalski')).length).toBe(2); expect(await screen.findByText('Plan na masę')).toBeInTheDocument(); + // kolumna daty: dzień na górze, godzina pod spodem + expect(await screen.findByText('20.08.2026')).toBeInTheDocument(); // szczegóły jako naturalny tekst (tytuł i actorId są w innych kolumnach) expect(await screen.findByText('start: 2026-08-24')).toBeInTheDocument(); // ID aktora pod e-mailem w kolumnie „Użytkownik" @@ -112,7 +114,10 @@ describe('admin Logs page', () => { await screen.findByText('Jan Kowalski'); // filtr akcji jest w grupie lejka (ikona „Filtry” w nagłówku) await userEvent.click(screen.getByRole('button', { name: 'Filtry' })); - await userEvent.selectOptions(screen.getByRole('combobox', { name: 'Filtruj po akcji' }), 'session.completed'); + await userEvent.selectOptions( + screen.getByRole('combobox', { name: 'Filtruj po akcji' }), + 'session.completed', + ); // refetch z nowym queryKey — czekamy na drugi wywołany fetch await vi.waitFor(() => expect(calls.length).toBe(2)); expect(calls.at(-1)?.url).toContain('action=session.completed'); @@ -160,7 +165,9 @@ describe('admin Logs page', () => { }); it('shows an error when the logs request fails', async () => { - mockFetchSequence(jsonResponse(500, { error: { code: 'INTERNAL', message: 'Błąd wewnętrzny' } })); + mockFetchSequence( + jsonResponse(500, { error: { code: 'INTERNAL', message: 'Błąd wewnętrzny' } }), + ); renderLogs(); expect(await screen.findByText(/Błąd: Błąd wewnętrzny/)).toBeInTheDocument(); });