Podopieczni: sortowanie jako przycisk Sortuj + select w topmenu (kompaktowy zamiast szerokich chipow)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Flame, Plus, Users } from 'lucide-react';
|
||||
import { ChevronDown, Flame, Plus, Users } from 'lucide-react';
|
||||
import {
|
||||
sendInvitation,
|
||||
useIsTrainer,
|
||||
@@ -30,6 +30,14 @@ import { useToast } from '../../components/toast';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import { useTopbar } from '../../topbar';
|
||||
|
||||
const SORT_OPTIONS = [
|
||||
{ id: 'flags', label: 'Flagi' },
|
||||
{ id: 'killstreak', label: 'Killstreak' },
|
||||
{ id: 'name', label: 'Nazwa' },
|
||||
{ id: 'lastSession', label: 'Ostatnia sesja' },
|
||||
] as const;
|
||||
type SortKey = (typeof SORT_OPTIONS)[number]['id'];
|
||||
|
||||
/* Wiersz podopiecznego: avatar + nazwa + siłownie + killstreak,
|
||||
aktywny plan (pasek), ostatnia sesja + flagi. Cały wiersz to przycisk. */
|
||||
function TraineeCard({ trainee, onOpen }: { trainee: Trainee; onOpen: () => void }) {
|
||||
@@ -100,7 +108,8 @@ export default function Trainees() {
|
||||
const trainerGyms = (meData?.memberships ?? []).filter((m) => m.roles.includes('TRAINER'));
|
||||
|
||||
const [gymId, setGymId] = useState<string>('');
|
||||
const [sortKey, setSortKey] = useState<'flags' | 'killstreak' | 'name' | 'lastSession'>('flags');
|
||||
const [sortKey, setSortKey] = useState<SortKey>('flags');
|
||||
const [sortOpen, setSortOpen] = useState(false);
|
||||
const [firstName, setFirstName] = useState('');
|
||||
const [lastName, setLastName] = useState('');
|
||||
const [searching, setSearching] = useState(false);
|
||||
@@ -110,29 +119,42 @@ export default function Trainees() {
|
||||
title: 'Podopieczni',
|
||||
search: 'trainees',
|
||||
filters: [
|
||||
<div key="sort" role="group" aria-label="Sortuj podopiecznych" className="flex flex-wrap gap-1.5">
|
||||
{(
|
||||
[
|
||||
{ id: 'flags', label: 'Flagi' },
|
||||
{ id: 'killstreak', label: 'Killstreak' },
|
||||
{ id: 'name', label: 'Nazwa' },
|
||||
{ id: 'lastSession', label: 'Ostatnia sesja' },
|
||||
] as const
|
||||
).map((s) => (
|
||||
<button
|
||||
key={s.id}
|
||||
type="button"
|
||||
aria-pressed={sortKey === s.id}
|
||||
onClick={() => setSortKey(s.id)}
|
||||
className={`cursor-pointer rounded-full border px-3 py-1 text-[0.8125rem] font-semibold transition-colors ${
|
||||
sortKey === s.id
|
||||
? 'border-accent/55 bg-accent/11 text-accent-text'
|
||||
: 'border-line bg-card text-dim hover:text-ink'
|
||||
}`}
|
||||
>
|
||||
{s.label}
|
||||
</button>
|
||||
))}
|
||||
/* sortowanie: przycisk „Sortuj” + rozwijany select (kompaktowo w grupie filtrów) */
|
||||
<div key="sort" className="relative flex items-center gap-2">
|
||||
<span className="text-[0.85rem] font-semibold text-dim">Sortuj</span>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() => setSortOpen((o) => !o)}
|
||||
aria-haspopup="true"
|
||||
aria-expanded={sortOpen}
|
||||
aria-label="Sortuj podopiecznych"
|
||||
>
|
||||
{SORT_OPTIONS.find((s) => s.id === sortKey)?.label}
|
||||
<ChevronDown className="w-4 h-4" />
|
||||
</Button>
|
||||
{sortOpen && (
|
||||
<>
|
||||
<div className="fixed inset-0 z-40" onClick={() => setSortOpen(false)} />
|
||||
<div className="absolute right-0 top-full z-50 mt-2 w-44 rounded-xl border border-line bg-card p-1 shadow-lg">
|
||||
{SORT_OPTIONS.map((s) => (
|
||||
<button
|
||||
key={s.id}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setSortKey(s.id);
|
||||
setSortOpen(false);
|
||||
}}
|
||||
className={`w-full cursor-pointer rounded-lg px-2.5 py-1.5 text-left text-[0.85rem] font-semibold ${
|
||||
sortKey === s.id ? 'bg-accent/15 text-accent-text' : 'text-ink hover:bg-line/30'
|
||||
}`}
|
||||
>
|
||||
{s.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>,
|
||||
],
|
||||
filterActive: sortKey !== 'flags',
|
||||
|
||||
@@ -353,7 +353,7 @@ describe('Trainees — lista i szczegóły', () => {
|
||||
expect(screen.getByText('Anna Nowak')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('chipy sortowania zmieniają kolejność listy (flagi/killstreak/nazwa/ostatnia sesja)', async () => {
|
||||
it('select sortowania w topmenu zmienia kolejność listy (flagi/killstreak/nazwa/ostatnia sesja)', async () => {
|
||||
mockApi();
|
||||
const user = userEvent.setup();
|
||||
renderApp();
|
||||
@@ -366,20 +366,25 @@ describe('Trainees — lista i szczegóły', () => {
|
||||
Array.from(document.querySelectorAll('button'))
|
||||
.filter((b) => NAMES.some((n) => b.textContent?.includes(n)))
|
||||
.map((b) => NAMES.find((n) => b.textContent!.includes(n))!);
|
||||
// wybór opcji sortowania: otwórz dropdown „Sortuj” i kliknij opcję
|
||||
const pickSort = async (option: string) => {
|
||||
await user.click(screen.getByRole('button', { name: 'Sortuj podopiecznych' }));
|
||||
await user.click(await screen.findByRole('button', { name: option }));
|
||||
};
|
||||
|
||||
// domyślnie: najpierw flagi (Anna 1 > Piotr/Zofia 0; remis po nazwie)
|
||||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska']);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Killstreak' }));
|
||||
await pickSort('Killstreak');
|
||||
expect(rowOrder()).toEqual(['Zofia Wiśniewska', 'Anna Nowak', 'Piotr Kowal']);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Nazwa' }));
|
||||
await pickSort('Nazwa');
|
||||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska']);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Ostatnia sesja' }));
|
||||
await pickSort('Ostatnia sesja');
|
||||
expect(rowOrder()).toEqual(['Zofia Wiśniewska', 'Anna Nowak', 'Piotr Kowal']);
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Flagi' }));
|
||||
await pickSort('Flagi');
|
||||
expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska']);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user