@@ -4,6 +4,7 @@ import type { FilterState, FilterCondition, FilterOperator, FilterType, Localiza
44
55type ColumnFilterOptions = NonNullable < Localization [ 'filter' ] > ;
66import { emptyFilterState , isFilterActive } from '../hooks/useColumnFilter' ;
7+ import FilterIcon from '../icons/FilterIcon' ;
78
89type OperatorOption = { value : FilterOperator ; label : string ; noInput ?: boolean ; twoInputs ?: boolean } ;
910
@@ -39,13 +40,14 @@ const DEFAULT_DATE_OPERATORS: OperatorOption[] = [
3940 { value : 'notBlank' , label : 'Not blank' , noInput : true } ,
4041] ;
4142
43+ function baseOperators ( filterType : FilterType ) : OperatorOption [ ] {
44+ if ( filterType === 'number' ) return DEFAULT_NUMBER_OPERATORS ;
45+ if ( filterType === 'date' || filterType === 'datetime' || filterType === 'time' ) return DEFAULT_DATE_OPERATORS ;
46+ return DEFAULT_TEXT_OPERATORS ;
47+ }
48+
4249function operatorsFor ( filterType : FilterType , overrides ?: ColumnFilterOptions [ 'operators' ] ) : OperatorOption [ ] {
43- const base =
44- filterType === 'number'
45- ? DEFAULT_NUMBER_OPERATORS
46- : filterType === 'date' || filterType === 'datetime' || filterType === 'time'
47- ? DEFAULT_DATE_OPERATORS
48- : DEFAULT_TEXT_OPERATORS ;
50+ const base = baseOperators ( filterType ) ;
4951 if ( ! overrides ) return base ;
5052 return base . map ( op => ( overrides [ op . value ] ? { ...op , label : overrides [ op . value ] ! } : op ) ) ;
5153}
@@ -54,6 +56,14 @@ function defaultOperator(filterType: FilterType): FilterOperator {
5456 return filterType === 'text' ? 'contains' : 'equals' ;
5557}
5658
59+ function inputTypeFor ( filterType : FilterType ) : string {
60+ if ( filterType === 'number' ) return 'number' ;
61+ if ( filterType === 'date' ) return 'date' ;
62+ if ( filterType === 'datetime' ) return 'datetime-local' ;
63+ if ( filterType === 'time' ) return 'time' ;
64+ return 'text' ;
65+ }
66+
5767function emptyCondition ( filterType : FilterType ) : FilterCondition {
5868 return { operator : defaultOperator ( filterType ) } ;
5969}
@@ -75,16 +85,7 @@ type ConditionRowProps = {
7585function ConditionRow ( { condition, filterType, options, onChange, onRemove } : ConditionRowProps ) : JSX . Element {
7686 const operators = operatorsFor ( filterType , options . operators ) ;
7787 const selected = operators . find ( o => o . value === condition . operator ) ?? operators [ 0 ] ;
78- const inputType =
79- filterType === 'number'
80- ? 'number'
81- : filterType === 'date'
82- ? 'date'
83- : filterType === 'datetime'
84- ? 'datetime-local'
85- : filterType === 'time'
86- ? 'time'
87- : 'text' ;
88+ const inputType = inputTypeFor ( filterType ) ;
8889 // Time inputs default to minute precision; step=1 exposes a seconds field so
8990 // logs can be filtered to the second.
9091 const inputStep = filterType === 'time' ? 1 : undefined ;
@@ -301,9 +302,7 @@ export default function ColumnFilter({
301302 toggleOpen ( ) ;
302303 } }
303304 >
304- < svg viewBox = "0 0 24 24" width = "14" height = "14" fill = "currentColor" aria-hidden = "true" >
305- < path d = "M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z" />
306- </ svg >
305+ < FilterIcon />
307306 { isActive && < span className = "rdt_filterDot" /> }
308307 </ button >
309308
0 commit comments