Files
Joshen Lim b1a9e072ec Update table editor ilike related comparators to implicitly wrap filter string with % if not provided (#50394)
### Context

For table editor - the `ilike` related comparators expect users to input
a `%` in the filter string, which for non-developers might not be
intuitive.

Hence opting to implicitly wrap the filter string with `%` in the query
when filtering if non provided
<img width="1182" height="755" alt="image"
src="https://github.com/user-attachments/assets/819c39f5-fcbf-4213-95b3-3ad1ee901f47"
/>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved pattern-match filters so bare text values perform contains
matching by automatically wrapping them with wildcards.
* Preserved explicit wildcard patterns using `%` or `_` without adding
additional wildcards.
* Improved handling of empty values for non-text filters while retaining
existing numeric filter validation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-16 14:32:19 +08:00

48 lines
1.4 KiB
TypeScript

import { formatPatternMatchFilterValue } from '@supabase/pg-meta/src/query/table-row-query'
import type { Filter, ServiceError } from '@/components/grid/types'
import { isNumericalColumn } from '@/components/grid/utils/types'
import { Entity, isTableLike } from '@/data/table-editor/table-editor-types'
/**
* temporary fix until we implement a better filter UI
* which validate input value base on the column type
*/
export function formatFilterValue(
table: {
columns: {
name: string
format: string
}[]
},
filter: Filter
) {
const column = table.columns.find((x) => x.name == filter.column)
if (column && isNumericalColumn(column.format)) {
const numberValue = Number(filter.value)
if (Number.isNaN(numberValue) || Math.abs(numberValue) > Number.MAX_SAFE_INTEGER)
return filter.value
else return numberValue
}
return formatPatternMatchFilterValue(filter.value, filter.operator)
}
export function getPrimaryKeys({ table }: { table: Entity }): {
primaryKeys?: string[]
error?: ServiceError
} {
if (!isTableLike(table)) {
return {
error: { message: 'Only table rows can be updated or deleted' },
}
}
const pkColumns = table.primary_keys
if (!pkColumns || pkColumns.length == 0) {
return {
error: { message: 'Please add a primary key column to your table to update or delete rows' },
}
}
return { primaryKeys: pkColumns.map((x) => x.name) }
}