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:
@@ -21,6 +21,7 @@ router = APIRouter()
|
||||
@router.get("/evolutions", response_model=PaginatedEvolutionResponse)
|
||||
async def list_evolutions(
|
||||
search: str | None = Query(None),
|
||||
trigger: str | None = Query(None),
|
||||
limit: int = Query(50, ge=1, le=500),
|
||||
offset: int = Query(0, ge=0),
|
||||
session: AsyncSession = Depends(get_session),
|
||||
@@ -44,6 +45,8 @@ async def list_evolutions(
|
||||
func.lower(Evolution.item).contains(search_lower),
|
||||
)
|
||||
)
|
||||
if trigger:
|
||||
base_query = base_query.where(Evolution.trigger == trigger)
|
||||
|
||||
# Count total (without eager loads)
|
||||
count_base = select(Evolution)
|
||||
@@ -60,6 +63,8 @@ async def list_evolutions(
|
||||
func.lower(Evolution.item).contains(search_lower),
|
||||
)
|
||||
)
|
||||
if trigger:
|
||||
count_base = count_base.where(Evolution.trigger == trigger)
|
||||
count_query = select(func.count()).select_from(count_base.subquery())
|
||||
total = (await session.execute(count_query)).scalar() or 0
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ router = APIRouter()
|
||||
@router.get("/pokemon", response_model=PaginatedPokemonResponse)
|
||||
async def list_pokemon(
|
||||
search: str | None = Query(None),
|
||||
type: str | None = Query(None),
|
||||
limit: int = Query(50, ge=1, le=500),
|
||||
offset: int = Query(0, ge=0),
|
||||
session: AsyncSession = Depends(get_session),
|
||||
@@ -42,6 +43,8 @@ async def list_pokemon(
|
||||
base_query = base_query.where(
|
||||
func.lower(Pokemon.name).contains(search.lower())
|
||||
)
|
||||
if type:
|
||||
base_query = base_query.where(Pokemon.types.any(type))
|
||||
|
||||
# Get total count
|
||||
count_query = select(func.count()).select_from(base_query.subquery())
|
||||
|
||||
Reference in New Issue
Block a user