Add filter controls to admin tables
Pokemon (type), Evolutions (trigger), Games (region/generation), and Runs (status/game) now have dropdown filters alongside search. Server-side filtering for paginated tables, client-side for small datasets. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,11 +15,20 @@ import type { EvolutionAdmin, CreateEvolutionInput, UpdateEvolutionInput } from
|
||||
|
||||
const PAGE_SIZE = 50
|
||||
|
||||
const EVOLUTION_TRIGGERS = [
|
||||
{ value: 'level-up', label: 'Level Up' },
|
||||
{ value: 'trade', label: 'Trade' },
|
||||
{ value: 'use-item', label: 'Use Item' },
|
||||
{ value: 'shed', label: 'Shed' },
|
||||
{ value: 'other', label: 'Other' },
|
||||
]
|
||||
|
||||
export function AdminEvolutions() {
|
||||
const [search, setSearch] = useState('')
|
||||
const [triggerFilter, setTriggerFilter] = useState('')
|
||||
const [page, setPage] = useState(0)
|
||||
const offset = page * PAGE_SIZE
|
||||
const { data, isLoading } = useEvolutionList(search || undefined, PAGE_SIZE, offset)
|
||||
const { data, isLoading } = useEvolutionList(search || undefined, PAGE_SIZE, offset, triggerFilter || undefined)
|
||||
const evolutions = data?.items ?? []
|
||||
const total = data?.total ?? 0
|
||||
const totalPages = Math.ceil(total / PAGE_SIZE)
|
||||
@@ -101,7 +110,28 @@ export function AdminEvolutions() {
|
||||
placeholder="Search by pokemon name, trigger, or item..."
|
||||
className="w-full max-w-sm px-3 py-2 border rounded-md dark:bg-gray-700 dark:border-gray-600"
|
||||
/>
|
||||
<span className="text-sm text-gray-500 dark:text-gray-400">
|
||||
<select
|
||||
value={triggerFilter}
|
||||
onChange={(e) => {
|
||||
setTriggerFilter(e.target.value)
|
||||
setPage(0)
|
||||
}}
|
||||
className="px-3 py-2 border rounded-md dark:bg-gray-700 dark:border-gray-600"
|
||||
>
|
||||
<option value="">All triggers</option>
|
||||
{EVOLUTION_TRIGGERS.map((t) => (
|
||||
<option key={t.value} value={t.value}>{t.label}</option>
|
||||
))}
|
||||
</select>
|
||||
{(search || triggerFilter) && (
|
||||
<button
|
||||
onClick={() => { setSearch(''); setTriggerFilter(''); setPage(0) }}
|
||||
className="text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
|
||||
>
|
||||
Clear filters
|
||||
</button>
|
||||
)}
|
||||
<span className="text-sm text-gray-500 dark:text-gray-400 whitespace-nowrap">
|
||||
{total} evolutions
|
||||
</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user