Admin: logi — kolumna daty w dwóch liniach (dzien na gorze, godzina pod spodem), badge akcji zawija dluzszy opis, szczegoly renderowane jedna pozycja pod druga (detailsLines + fmtTime)
This commit is contained in:
@@ -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 '—';
|
||||
|
||||
@@ -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, unknown>): 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"
|
||||
>
|
||||
<td className="whitespace-nowrap px-4 py-3 font-display text-dim tabular-nums">
|
||||
{formatLogDate(log.createdAt)}
|
||||
<td className="px-4 py-3 align-top font-display text-dim tabular-nums">
|
||||
<div className="whitespace-nowrap">{fmtDate(log.createdAt)}</div>
|
||||
<div className="whitespace-nowrap text-[0.875rem]">
|
||||
{fmtTime(log.createdAt)}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<div className="font-semibold">{actorName(log)}</div>
|
||||
@@ -298,8 +306,13 @@ export default function Logs() {
|
||||
{log.actor.id}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<Badge color={actionColor(log.action)}>{actionLabel(log.action)}</Badge>
|
||||
<td className="px-4 py-3 align-top">
|
||||
<Badge
|
||||
color={actionColor(log.action)}
|
||||
className="h-auto max-w-[13rem] whitespace-normal"
|
||||
>
|
||||
{actionLabel(log.action)}
|
||||
</Badge>
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
<div>{tr(`entities.${log.entityType}`, { defaultValue: log.entityType })}</div>
|
||||
@@ -307,7 +320,17 @@ export default function Logs() {
|
||||
<div className="text-[0.875rem] text-dim">{entityName(log)}</div>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-dim">{detailsText(log) ?? '—'}</td>
|
||||
<td className="px-4 py-3 text-dim">
|
||||
{detailsLines(log).length > 0 ? (
|
||||
<div className="space-y-1">
|
||||
{detailsLines(log).map((line) => (
|
||||
<div key={line}>{line}</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
'—'
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user