@@ -11,7 +11,8 @@ import {
1111 DropdownMenuTrigger ,
1212} from '@/components/emcn'
1313import { ChevronDown , Plus } from '@/components/emcn/icons'
14- import type { Filter , FilterRule } from '@/lib/table'
14+ import type { ColumnDefinition , Filter , FilterRule } from '@/lib/table'
15+ import { getColumnId } from '@/lib/table'
1516import { COMPARISON_OPERATORS , VALUELESS_OPERATORS } from '@/lib/table/query-builder/constants'
1617import { filterRulesToFilter , filterToRules } from '@/lib/table/query-builder/converters'
1718
@@ -20,7 +21,7 @@ const OPERATOR_LABELS = Object.fromEntries(
2021) as Record < string , string >
2122
2223interface TableFilterProps {
23- columns : Array < { name : string ; type : string } >
24+ columns : ColumnDefinition [ ]
2425 filter : Filter | null
2526 onApply : ( filter : Filter | null ) => void
2627 onClose : ( ) => void
@@ -35,8 +36,9 @@ export function TableFilter({ columns, filter, onApply, onClose }: TableFilterPr
3536 const rulesRef = useRef ( rules )
3637 rulesRef . current = rules
3738
39+ // `value` is the filter field key (column id); `label` is what the user sees.
3840 const columnOptions = useMemo (
39- ( ) => columns . map ( ( col ) => ( { value : col . name , label : col . name } ) ) ,
41+ ( ) => columns . map ( ( col ) => ( { value : getColumnId ( col ) , label : col . name } ) ) ,
4042 [ columns ]
4143 )
4244
@@ -164,7 +166,9 @@ const FilterRuleRow = memo(function FilterRuleRow({
164166 < DropdownMenu >
165167 < DropdownMenuTrigger asChild >
166168 < button className = 'flex h-[28px] min-w-[100px] items-center justify-between rounded-[5px] border border-[var(--border)] bg-transparent px-2 text-[var(--text-secondary)] text-xs outline-none hover-hover:border-[var(--border-1)]' >
167- < span className = 'truncate' > { rule . column || 'Column' } </ span >
169+ < span className = 'truncate' >
170+ { columns . find ( ( col ) => col . value === rule . column ) ?. label || rule . column || 'Column' }
171+ </ span >
168172 < ChevronDown className = 'ml-1 size-[10px] shrink-0 text-[var(--text-icon)]' />
169173 </ button >
170174 </ DropdownMenuTrigger >
@@ -224,11 +228,11 @@ const FilterRuleRow = memo(function FilterRuleRow({
224228 )
225229} )
226230
227- function createRule ( columns : Array < { name : string } > ) : FilterRule {
231+ function createRule ( columns : ColumnDefinition [ ] ) : FilterRule {
228232 return {
229233 id : generateShortId ( ) ,
230234 logicalOperator : 'and' ,
231- column : columns [ 0 ] ?. name ?? '' ,
235+ column : columns [ 0 ] ? getColumnId ( columns [ 0 ] ) : '' ,
232236 operator : 'eq' ,
233237 value : '' ,
234238 }
0 commit comments