@@ -8,7 +8,12 @@ import { usePlacedMarkersQuery } from "@/app/map/[id]/hooks/usePlacedMarkers";
88import { useTable } from "@/app/map/[id]/hooks/useTable" ;
99import { useTurfsQuery } from "@/app/map/[id]/hooks/useTurfsQuery" ;
1010import MultiDropdownMenu from "@/components/MultiDropdownMenu" ;
11- import { FilterOperator , FilterType } from "@/server/models/MapView" ;
11+ import { FilterTypeLabels } from "@/labels" ;
12+ import {
13+ FilterOperator ,
14+ FilterType ,
15+ columnFilterTypes ,
16+ } from "@/server/models/MapView" ;
1217import { useTRPC } from "@/services/trpc/react" ;
1318import { Button } from "@/shadcn/ui/button" ;
1419import {
@@ -353,27 +358,37 @@ function ChildFilter({ filter, setFilter }: TableFilterProps) {
353358 </ span >
354359 < select
355360 aria-label = "Filter type"
356- value = { filter . type === FilterType . EXACT ? "is" : "contains" }
357- onChange = { ( e ) =>
361+ value = { filter . type }
362+ onChange = { ( e ) => {
363+ const newType = e . target . value as FilterType ;
364+ const needsSearch =
365+ newType !== FilterType . EMPTY && newType !== FilterType . NOT_EMPTY ;
358366 updateFilter ( {
359- type : e . target . value === "is" ? FilterType . EXACT : FilterType . TEXT ,
360- } )
361- }
367+ type : newType ,
368+ search : needsSearch ? filter . search : undefined ,
369+ } ) ;
370+ } }
362371 className = "bg-neutral-100 text-sm cursor-pointer border-0 border-l text-center font-medium"
363372 >
364- < option value = "contains" > contains</ option >
365- < option value = "is" > is</ option >
373+ { columnFilterTypes . map ( ( type ) => (
374+ < option key = { type } value = { type } >
375+ { FilterTypeLabels [ type ] }
376+ </ option >
377+ ) ) }
366378 </ select >
367- < Input
368- type = "text"
369- placeholder = "Search"
370- value = { localSearch }
371- onChange = { ( e ) => onSearchChange ( e . target . value ) }
372- style = { { width : `${ Math . max ( 5 , localSearch . length + 1 ) } ch` } }
373- className = "min-w-20 h-7 p-2 text-sm border-y-0 border-r-0 rounded-none bg-neutral-100 font-medium text-center"
374- ref = { inputRef }
375- required
376- />
379+ { filter . type !== FilterType . EMPTY &&
380+ filter . type !== FilterType . NOT_EMPTY && (
381+ < Input
382+ type = "text"
383+ placeholder = "Search"
384+ value = { localSearch }
385+ onChange = { ( e ) => onSearchChange ( e . target . value ) }
386+ style = { { width : `${ Math . max ( 5 , localSearch . length + 1 ) } ch` } }
387+ className = "min-w-20 h-7 p-2 text-sm border-y-0 border-r-0 rounded-none bg-neutral-100 font-medium text-center"
388+ ref = { inputRef }
389+ required
390+ />
391+ ) }
377392 </ div >
378393 ) ;
379394}
0 commit comments