Skip to content

Commit 08db147

Browse files
fix(tables): key filter UI by stable column id; show column name in delete confirm
1 parent 39418f9 commit 08db147

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
DropdownMenuTrigger,
1212
} from '@/components/emcn'
1313
import { 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'
1516
import { COMPARISON_OPERATORS, VALUELESS_OPERATORS } from '@/lib/table/query-builder/constants'
1617
import { filterRulesToFilter, filterToRules } from '@/lib/table/query-builder/converters'
1718

@@ -20,7 +21,7 @@ const OPERATOR_LABELS = Object.fromEntries(
2021
) as Record<string, string>
2122

2223
interface 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
}

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,9 @@ export function Table({
740740
<>
741741
Are you sure you want to delete{' '}
742742
<span className='font-medium text-[var(--text-primary)]'>
743-
{deletingColumns?.[0]}
743+
{(deletingColumns &&
744+
columns.find((c) => getColumnId(c) === deletingColumns[0])?.name) ??
745+
deletingColumns?.[0]}
744746
</span>
745747
?{' '}
746748
</>

0 commit comments

Comments
 (0)