From 7f3d3fc135f97073e825a93b04e5a5e48815e4dc Mon Sep 17 00:00:00 2001 From: tisachi Date: Sat, 17 Oct 2026 04:27:39 +0200 Subject: [PATCH] Admin: topbar z menu kontekstowym 1:1 jak w aplikacji (dolna pigulka, plywajacy tytul, animacje grup, MonthPickerCore z wariantem allowAll) --- admin/index.html | 5 +- admin/src/pages/Logs.tsx | 20 +- admin/src/pages/users/UserBodyParameters.tsx | 24 +- admin/src/pages/users/UserHistory.tsx | 15 +- admin/src/styles.css | 19 ++ admin/src/topbar/GroupButton.tsx | 15 +- admin/src/topbar/MonthPicker.tsx | 229 ++++++++++---- admin/src/topbar/Topbar.tsx | 313 ++++++++++++------- admin/src/topbar/index.ts | 1 + admin/src/topbar/store.ts | 3 + admin/test/Logs.test.tsx | 8 +- 11 files changed, 447 insertions(+), 205 deletions(-) diff --git a/admin/index.html b/admin/index.html index 84fef80..146c20b 100644 --- a/admin/index.html +++ b/admin/index.html @@ -2,7 +2,10 @@ - + + FitOS Admin diff --git a/admin/src/pages/Logs.tsx b/admin/src/pages/Logs.tsx index 08bd72d..ea96fed 100644 --- a/admin/src/pages/Logs.tsx +++ b/admin/src/pages/Logs.tsx @@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { ScrollText } from 'lucide-react'; import { useTopbar } from '../topbar'; -import { MonthPicker } from '../topbar/MonthPicker'; +import { MonthPickerCore } from '../topbar/MonthPicker'; import { api } from '../api/client'; import type { ActivityLog, ActivityLogPage } from '../api/types'; import { Badge, EmptyState, ErrorText, Loading, Select, type BadgeColor } from '../components/ui'; @@ -146,10 +146,11 @@ export default function Logs() { }, }); - // lata do panelu selektora: z załadowanych logów + bieżący rok (nowe → stare) - const years = useMemo(() => { - const set = new Set((data?.logs ?? []).map((l) => l.createdAt.slice(0, 4))); - set.add(String(new Date().getFullYear())); + // miesiące do panelu selektora: z załadowanych logów + bieżący (chip lata) + const availableMonths = useMemo(() => { + const d = new Date(); + const current = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`; + const set = new Set([...(data?.logs ?? []).map((l) => l.createdAt.slice(0, 7)), current]); return [...set].sort().reverse(); }, [data?.logs]); @@ -157,13 +158,14 @@ export default function Logs() { title: 'Logi', search: 'logs', dateFilter: ( - { + { setMonth(m); setLimit(PAGE_SIZE); }} - years={years} + availableMonths={availableMonths} + allowAll /> ), filters: [ diff --git a/admin/src/pages/users/UserBodyParameters.tsx b/admin/src/pages/users/UserBodyParameters.tsx index cd2966b..aec9180 100644 --- a/admin/src/pages/users/UserBodyParameters.tsx +++ b/admin/src/pages/users/UserBodyParameters.tsx @@ -11,7 +11,7 @@ import { CartesianGrid, } from 'recharts'; import { useTopbar } from '../../topbar'; -import { MonthPicker } from '../../topbar/MonthPicker'; +import { MonthPickerCore } from '../../topbar/MonthPicker'; import { BackButton, Button, @@ -170,8 +170,12 @@ export default function UserBodyParameters() { const { data: bp, isLoading: bpLoading, error: bpError } = useUserBodyParameters(id); const [visible, setVisible] = useState>({}); - // miesiąc w topmenu: '' = wszystkie; dostępność i lata liczone z danych - const [month, setMonth] = useState(''); + // miesiąc w topmenu: zawsze wybrany (domyślnie bieżący), jak w aplikacji; + // strzałki i siatka skaczą tylko po miesiącach z danymi + const [month, setMonth] = useState(() => { + const d = new Date(); + return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`; + }); // miesiące z danymi (nowe → stare) — do selektora w topmenu const monthKeys = [ @@ -179,15 +183,13 @@ export default function UserBodyParameters() { ...(bp?.circumferences ?? []).flatMap((s) => s.points.map((p) => p.date.slice(0, 7))), ]; const availableMonths = [...new Set(monthKeys)].sort().reverse(); - const monthYears = - availableMonths.length > 0 - ? [...new Set(availableMonths.map((m) => m.slice(0, 4)))].sort().reverse() - : [String(new Date().getFullYear())]; useTopbar({ title: 'Parametry ciała', back: id ? `/users/${id}` : '/users', - dateFilter: , + dateFilter: ( + + ), filterActive: month !== '', }); @@ -198,13 +200,13 @@ export default function UserBodyParameters() { // wybrany miesiąc bez danych → najnowszy miesiąc z danymi useEffect(() => { - if (availableMonths.length > 0 && month !== '' && !availableMonths.includes(month)) { + if (availableMonths.length > 0 && !availableMonths.includes(month)) { setMonth(availableMonths[0]); } }, [availableMonths.join(','), month]); // zakres: wybrany w topmenu miesiąc (YYYY-MM) - const inMonth = (date: string) => month === '' || date.startsWith(month); + const inMonth = (date: string) => date.startsWith(month); const weightPoints = [...(bp?.weight ?? [])] .filter((w) => inMonth(w.date)) @@ -319,7 +321,7 @@ export default function UserBodyParameters() { {circGroups.length === 0 && ( -

Brak pomiarów{month ? ' w wybranym miesiącu' : ''}.

+

Brak pomiarów w wybranym miesiącu.

)} {circGroups.map((g) => { diff --git a/admin/src/pages/users/UserHistory.tsx b/admin/src/pages/users/UserHistory.tsx index 4802c4f..d20f803 100644 --- a/admin/src/pages/users/UserHistory.tsx +++ b/admin/src/pages/users/UserHistory.tsx @@ -2,7 +2,7 @@ import { useState } from 'react'; import { useParams, useSearchParams } from 'react-router-dom'; import { History } from 'lucide-react'; import { useTopbar } from '../../topbar'; -import { MonthPicker } from '../../topbar/MonthPicker'; +import { MonthPickerCore } from '../../topbar/MonthPicker'; import { BackButton, Card, EmptyState, ErrorText, PageHeader, Skeleton } from '../../components/ui'; import { useUserHistory } from './user-queries'; import HistoryTable from '../../components/HistoryTable'; @@ -26,15 +26,18 @@ export default function UserHistory() { ] .sort() .reverse(); - const years = - availableMonths.length > 0 - ? [...new Set(availableMonths.map((m) => m.slice(0, 4)))].sort().reverse() - : [String(new Date().getFullYear())]; useTopbar({ title: 'Historia treningów', back: id ? `/users/${id}` : '/users', - dateFilter: , + dateFilter: ( + + ), filterActive: month !== '', }); diff --git a/admin/src/styles.css b/admin/src/styles.css index d974488..cacef11 100644 --- a/admin/src/styles.css +++ b/admin/src/styles.css @@ -299,6 +299,25 @@ } } +/* PWA (standalone) na iOS/Android: pływający tytuł i dolny pasek menu muszą + „dopełniać” pola safe-area (notch, home-indicator) — w przeglądarkowej + wersji robi to UI paska (theme-color), więc w media nie ma = zero kosztu */ +@media (display-mode: standalone) { + .safe-pad-top { + padding-top: env(safe-area-inset-top); + background-color: var(--bg); + } +} + +/* dolny pasek menu istnieje tylko na telefonie ( typeof window !== 'undefined' && @@ -71,7 +71,15 @@ export function GroupButton({ if (e.key === 'Escape') onToggle(); }; const onClickOutside = (e: MouseEvent) => { - if (ref.current && !ref.current.contains(e.target as Node)) onToggle(); + if (ref.current && !ref.current.contains(e.target as Node)) { + const el = e.target as HTMLElement; + // telefon: panel grupy żyje w pigułce Topbar (poza tym refem) — klik + // w jego akcje nie może zamknąć menu przed dojściem click do przycisku + if (el.closest('[data-topbar-panel]')) return; + // klik w inną ikonę grupy: jej click otworzy własną grupę (przełączenie) + if (el.closest('[aria-haspopup="true"]')) return; + onToggle(); + } }; document.addEventListener('keydown', onKey); document.addEventListener('mousedown', onClickOutside); @@ -94,7 +102,8 @@ export function GroupButton({ alwaysInlineFromMd ? 'md:flex' : 'lg:flex', flat ? 'max-md:static max-md:flex-row max-md:items-center max-md:gap-2' - : 'max-md:absolute max-md:inset-x-0 max-md:bottom-full max-md:z-50 max-md:flex-col max-md:items-stretch max-md:gap-1.5 max-md:rounded-t-xl max-md:border-t max-md:border-line max-md:bg-card max-md:p-2.5 max-md:shadow-card max-md:animate-none', + : // telefon: panel grupy renderuje Topbar (w pigułce na dole) — ten nie żyje {children} diff --git a/admin/src/topbar/MonthPicker.tsx b/admin/src/topbar/MonthPicker.tsx index abb3ca1..af1dd45 100644 --- a/admin/src/topbar/MonthPicker.tsx +++ b/admin/src/topbar/MonthPicker.tsx @@ -18,7 +18,20 @@ export const MONTH_NAMES = [ ]; /** Krótkie nazwy do siatki miesięcy w panelu selektora. */ -export const MONTH_SHORT = ['Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sie', 'Wrz', 'Paź', 'Lis', 'Gru']; +export const MONTH_SHORT = [ + 'Sty', + 'Lut', + 'Mar', + 'Kwi', + 'Maj', + 'Cze', + 'Lip', + 'Sie', + 'Wrz', + 'Paź', + 'Lis', + 'Gru', +]; /** `2026-08` → `Sierpień 2026`. */ export function formatMonth(month: string): string { @@ -26,31 +39,61 @@ export function formatMonth(month: string): string { return `${MONTH_NAMES[m - 1]} ${y}`; } +function currentMonthStr(): string { + const d = new Date(); + return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`; +} + +/** Przesuwa miesiąc o `delta` (kalendarzowo, bez sprawdzania danych). */ function shiftMonth(month: string, delta: number): string { const [y, m] = month.split('-').map(Number); const d = new Date(y, m - 1 + delta, 1); return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`; } -interface MonthPickerProps { - /** `YYYY-MM` albo `''` (brak filtra). */ - value: string; - onChange: (month: string) => void; - /** Lata pokazywane w panelu (nowe → stare). */ - years: string[]; +export interface MonthPickerCoreProps { + /** Wybrany miesiąc (YYYY-MM); pusty = „Wszystkie” (tylko gdy `allowAll`). */ + month: string; + setMonth: (month: string) => void; + /** Miesiące z danymi (YYYY-MM, najnowsze pierwsze). */ + availableMonths: string[]; + /** + * „Wszystkie” (miesiąc '') + strzałki/siatka kalendarzowe (bez „z danymi”). + * Bez `allowAll`: strzałki skaczą między miesiącami z danymi, siatka gasi puste. + */ + allowAll?: boolean; } /** * Selektor miesiąca (YYYY-MM) — widget top menu. - * ◀/▶ przeklikują do poprzedniego/następnego miesiąca, panel: lata + siatka 12 miesięcy. + * Wariant domyślny (parametry ciała): tylko miesiące z danymi. + * Wariant `allowAll` (historia): „Wszystkie” + pełna siatka kalendarzowa. */ -export function MonthPicker({ value, onChange, years }: MonthPickerProps) { +export function MonthPickerCore({ + month, + setMonth, + availableMonths, + allowAll = false, +}: MonthPickerCoreProps) { const [open, setOpen] = useState(false); const [panelYear, setPanelYear] = useState(null); - const now = new Date(); - const base = value || `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`; - const prevMonth = shiftMonth(base, -1); - const nextMonth = shiftMonth(base, 1); + + // allowAll: strzałki = sąsiedni miesiąc kalendarzowy (przy „Wszystkie” nieaktywne); + // inaczej: poprzedni/następny miesiąc Z danymi (skaczą puste) + const prevMonth = allowAll + ? month + ? shiftMonth(month, -1) + : null + : ([...availableMonths].reverse().find((m) => m < month) ?? null); + const nextMonth = allowAll + ? month + ? shiftMonth(month, 1) + : null + : (availableMonths.find((m) => m > month) ?? null); + + // lata do filtra: z danych; bez danych (allowAll) — bieżący rok + const years = [...new Set(availableMonths.map((m) => m.slice(0, 4)))].sort().reverse(); + const yearOptions = years.length > 0 ? years : [Number(currentMonthStr().slice(0, 4))]; return (
@@ -58,33 +101,36 @@ export function MonthPicker({ value, onChange, years }: MonthPickerProps) { @@ -92,48 +138,117 @@ export function MonthPicker({ value, onChange, years }: MonthPickerProps) { {open && ( <>
setOpen(false)} /> -
- {/* filtr po roku */} -
- {years.map((y) => ( + {/* telefon: panel filtrów jest nad dolnym paskiem — dropdown rozwija się w górę + (top-full wypadałby poza viewport); md+ (topbar u góry) — w dół. + Na mobilce center + overflow-widoczny: pigułka menu przycina w poziomie + tylko w czasie animacji rozwijania */} +
+ {allowAll ? ( + <> + {/* „Wszystkie” — pełna historia */} - ))} -
- {/* siatka 12 miesięcy wybranego roku */} -
- {Array.from({ length: 12 }, (_, i) => { - const m = `${panelYear ?? base.slice(0, 4)}-${String(i + 1).padStart(2, '0')}`; - const selected = m === value; - return ( - - ); - })} -
+ {/* filtr po roku: lata z danymi (nowe → stare) */} +
+ {yearOptions.map((y) => ( + + ))} +
+ {/* siatka 12 miesięcy wybranego roku — wszystkie aktywne */} +
+ {Array.from({ length: 12 }, (_, i) => { + const m = `${panelYear ?? Number(currentMonthStr().slice(0, 4))}-${String(i + 1).padStart(2, '0')}`; + return ( + + ); + })} +
+ + ) : availableMonths.length === 0 ? ( +

Brak danych

+ ) : ( + <> + {/* filtr po roku: lata z danymi (nowe → stare) */} +
+ {years.map((y) => ( + + ))} +
+ {/* siatka 12 miesięcy wybranego roku: z danymi = aktywne, bez = przygaszone */} +
+ {Array.from({ length: 12 }, (_, i) => { + const m = `${panelYear ?? month.slice(0, 4)}-${String(i + 1).padStart(2, '0')}`; + const hasData = availableMonths.includes(m); + return ( + + ); + })} +
+ + )}
)} diff --git a/admin/src/topbar/Topbar.tsx b/admin/src/topbar/Topbar.tsx index 91839db..5945cdc 100644 --- a/admin/src/topbar/Topbar.tsx +++ b/admin/src/topbar/Topbar.tsx @@ -5,7 +5,7 @@ import { useTopbarStore } from './store'; import { useListSearch, type SearchableSection } from '../store/list-search'; import { Button, Input } from '../components/ui'; import { cn } from '../lib/utils'; -import { GroupButton } from './GroupButton'; +import { GroupButton, useIsMobile } from './GroupButton'; import type { TopbarAction } from './types'; const SEARCH_LABELS: Record = { @@ -93,7 +93,11 @@ export function Topbar({ onMenuOpen }: { onMenuOpen?: () => void }) { const config = useTopbarStore((s) => s.config); const openGroup = useTopbarStore((s) => s.openGroup); const setOpenGroup = useTopbarStore((s) => s.setOpenGroup); + const toggleGroup = useTopbarStore((s) => s.toggleGroup); const navigate = useNavigate(); + // telefon: panel grupy renderowany przez Topbar tylko na void }) { const plusActions = actions.filter((a) => a.icon?.displayName === 'Plus'); const otherActions = actions.filter((a) => a.icon?.displayName !== 'Plus'); const hasFilters = config?.dateFilter != null || (config?.filters?.length ?? 0) > 0; - const toggle = (group: string) => setOpenGroup(openGroup === group ? null : group); + const toggle = (group: string) => toggleGroup(group); // X tylko gdy otwarta grupa naprawdę istnieje na tej stronie (stare id z innej // strony nie może pokazywać zamknięcia „nierozwiniętego” menu) @@ -114,130 +118,211 @@ export function Topbar({ onMenuOpen }: { onMenuOpen?: () => void }) { if (plusActions.length > 0) presentGroups.add('add'); if (otherActions.length > 0) presentGroups.add('actions'); if (config?.search) presentGroups.add('search'); - const menuOpen = openGroup != null && presentGroups.has(openGroup); + const menuOpen = isMobile && openGroup != null && presentGroups.has(openGroup); + + // Telefon: dolny pasek tylko gdy strona ma w nim coś do pokazania + // (nawigacja „Wstecz” też liczy się jako zawartość). + const mobileBarEmpty = + !config?.back && + !hasFilters && + (config?.groups?.length ?? 0) === 0 && + actions.length === 0 && + !config?.search && + config?.navWidget == null; return ( -
-
- {onMenuOpen && ( - - )} -

- {config?.title} -

- {/* akcje kontekstowe: md+ inline w nagłówku; telefon = pasek na dole ekranu */} -
0 ? { bottom: vvBottom } : undefined} - > - {/* nawigacja (np. Kalendarz) zawsze widoczna, nie jest grupą */} - {config?.navWidget} - {/* telefon: „<” = wróć do strony-rodzica zadeklarowanej przez podstronę */} - {config?.back && ( +
+ {/* telefon: header rozbity (contents) — tytuł jako pływająca pigułka z shadow; + akcje kontekstowe i tak żyją w dolnym pasku */} +
+ {/* md+: stała wysokość paska (kontrolki mieszczą się w nim i nie rozpychają + layoutu — pasek wygląda identycznie z akcjami i bez nich) */} +
+ {/* telefon: otoczka tytułu na szerokość napisu, przylega do prawej (przy hamburgerze) */} +

+ {config?.title} +

+ {/* telefon: hamburger pływający po prawej (ta sama wysokość co tytuł); + md+: sidebar ma własny */} + {onMenuOpen && ( )} - {hasFilters && ( - toggle('filters')} - > - {config?.dateFilter} - {config?.filters?.map((filter, i) => ( -
{filter}
- ))} -
- )} - {/* własne grupy tematyczne strony (np. Edycja/Galeria/Urządzenia) */} - {(config?.groups ?? []).map((g) => ( - toggle(`grp:${g.id}`)} - > - {g.actions.map((action) => ( - - ))} - - ))} - {plusActions.length > 0 && ( - toggle('add')} - > - {plusActions.map((action) => ( - - ))} - - )} - {otherActions.length > 0 && ( - toggle('actions')} - flatOnMobile={config?.flatActionsMobile} - alwaysInlineFromMd={config?.alwaysInlineActions} - > - {otherActions.map((action) => ( - - ))} - - )} - {/* wyszukiwarka zawsze maksymalnie z prawej */} - {config?.search && ( - toggle('search')} - > -
- -
-
- )} - {/* telefon: X zamykający otwarte menu, skrajny prawy róg; szerokość - animowana, więc reszta elementów płynnie się przesuwa */} + {/* akcje kontekstowe: md+ inline w nagłówku; telefon = pływająca pigułka. + Dwie warstwy: zewnętrzna = pełnej szerokości, przezroczysty „tor” + (centruje i animuje odstęp od dołu), wewnętrzna = właściwa pigułka + na szerokość treści (flex na osi pionowej → szerokość z treści), otwarta + grupa rozpycha ją w dół i płynnie poszerza (max-width) */}
0 ? { bottom: vvBottom + 4 } : undefined} > - + {/* panel otwartej grupy (akordeon) — wewnątrz pigułki nad ikonami; animacja + max-width poszerza też rząd ikon (rozszerzane rodzeństwo w kolumnie); + overflow-x: clip tnie w poziomie, w pionie widać (monthpicker nad paskiem) */} +
+ {menuOpen ? ( +
+ {openGroup === 'filters' && ( + <> + {config?.dateFilter} + {config?.filters?.map((filter, i) => ( +
{filter}
+ ))} + + )} + {openGroup === 'add' && + plusActions.map((action) => ( + + ))} + {openGroup === 'actions' && + otherActions.map((action) => ( + + ))} + {openGroup?.startsWith('grp:') && + (config?.groups ?? []) + .find((g) => `grp:${g.id}` === openGroup) + ?.actions.map((action) => ( + + ))} + {openGroup === 'search' && config?.search && ( + + )} +
+ ) : null} +
+ {/* rząd ikon: na md+ pojedynczy flex w nagłówku (contents rodzica), + na telefonie rząd wewnątrz pigułki */} +
+ {/* telefon: „<” = wróć do strony-rodzica zadeklarowanej przez podstronę */} + {config?.back && ( + + )} + {/* nawigacja (np. Kalendarz) zawsze widoczna, nie jest grupą */} + {config?.navWidget} + {hasFilters && ( + toggle('filters')} + > + {/* telefon: treść renderuje panel w pigułce (Topbar) — children to md+ */} + {config?.dateFilter} + {config?.filters?.map((filter, i) => ( +
{filter}
+ ))} +
+ )} + {/* własne grupy tematyczne strony (np. Edycja/Galeria/Urządzenia) */} + {(config?.groups ?? []).map((g) => ( + toggle(`grp:${g.id}`)} + > + {g.actions.map((action) => ( + + ))} + + ))} + {plusActions.length > 0 && ( + toggle('add')} + > + {plusActions.map((action) => ( + + ))} + + )} + {otherActions.length > 0 && ( + toggle('actions')} + flatOnMobile={config?.flatActionsMobile} + alwaysInlineFromMd={config?.alwaysInlineActions} + > + {otherActions.map((action) => ( + + ))} + + )} + {/* wyszukiwarka zawsze maksymalnie z prawej */} + {config?.search && ( + toggle('search')} + > +
+ +
+
+ )} + {/* telefon: X zamykający otwarte menu; renderowany tylko gdy menu otwarte + (zamknięty nie zostawia śladu w rządzie — inaczej jego gap psuje + wyśrodkowanie samych ikon) */} + {menuOpen && ( + + )} +
+
diff --git a/admin/src/topbar/index.ts b/admin/src/topbar/index.ts index 8db0c78..8c4ef17 100644 --- a/admin/src/topbar/index.ts +++ b/admin/src/topbar/index.ts @@ -1,4 +1,5 @@ export { Topbar } from './Topbar'; +export { MonthPickerCore } from './MonthPicker'; export { useTopbar } from './useTopbar'; export { useTopbarStore } from './store'; export type { TopbarAction, TopbarConfig, TopbarCustomGroup, TopbarGroup } from './types'; diff --git a/admin/src/topbar/store.ts b/admin/src/topbar/store.ts index 436d4c1..18a78f2 100644 --- a/admin/src/topbar/store.ts +++ b/admin/src/topbar/store.ts @@ -11,6 +11,8 @@ interface TopbarState { /** Rejestracja strony (mount): ustawia konfigurację i resetuje grupę (null = czyszczenie). */ registerPage: (config: TopbarConfig | null) => void; setOpenGroup: (group: string | null) => void; + /** Przełączenie grupy na aktualnym stanie (odporne na wyścig mousedown+click). */ + toggleGroup: (group: string) => void; } export const useTopbarStore = create((set) => ({ @@ -20,4 +22,5 @@ export const useTopbarStore = create((set) => ({ registerPage: (config) => set({ config, openGroup: config ? (config.defaultOpenGroup ?? null) : null }), setOpenGroup: (group) => set({ openGroup: group }), + toggleGroup: (group) => set((s) => ({ openGroup: s.openGroup === group ? null : group })), })); diff --git a/admin/test/Logs.test.tsx b/admin/test/Logs.test.tsx index 1d0032a..8dc3e60 100644 --- a/admin/test/Logs.test.tsx +++ b/admin/test/Logs.test.tsx @@ -129,7 +129,7 @@ describe('admin Logs page', () => { await screen.findByText('Jan Kowalski'); // otwieramy grupę „Filtry”, potem panel selektora miesiąca i wybieramy sierpień bieżącego roku await userEvent.click(screen.getByRole('button', { name: 'Filtry' })); - await userEvent.click(screen.getByRole('button', { name: 'Miesiąc' })); + await userEvent.click(screen.getByRole('button', { name: 'Wszystkie' })); await userEvent.click(screen.getByRole('button', { name: 'Sie' })); // refetch z nowym queryKey — czekamy na drugi wywołany fetch await vi.waitFor(() => expect(calls.length).toBe(2)); @@ -138,14 +138,14 @@ describe('admin Logs page', () => { expect(url.searchParams.get('to')).toBe('2026-08-31'); // etykieta przycisku pokazuje wybrany miesiąc expect(screen.getByRole('button', { name: 'Sierpień 2026' })).toBeInTheDocument(); - // ponowne kliknięcie zaznaczonego miesiąca odznacza filtr (brak from/to) + // ponowne otwarcie panelu i wybór „Wszystkie” cofa filtr miesiąca (brak from/to) await userEvent.click(screen.getByRole('button', { name: 'Sierpień 2026' })); - await userEvent.click(screen.getByRole('button', { name: 'Sie' })); + await userEvent.click(screen.getByRole('button', { name: 'Wszystkie' })); await vi.waitFor(() => expect(calls.length).toBe(3)); const url2 = new URL(calls.at(-1)!.url, 'http://localhost'); expect(url2.searchParams.get('from')).toBeNull(); expect(url2.searchParams.get('to')).toBeNull(); - expect(screen.getByRole('button', { name: 'Miesiąc' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Wszystkie' })).toBeInTheDocument(); }); it('filters the loaded page by the header search box', async () => {