mirror of
https://github.com/supabase/supabase.git
synced 2026-05-23 01:39:34 +08:00
* init * update Popovers to use new hooks * Update Header.tsx * made primitive components for filter and sorts * Delete FilterPopoverWrapper.tsx * Delete SortPopoverWrapper.tsx * remove * Create README.md * Update README.md * fix sort popover issues * Update SupabaseGrid.tsx * move DeleteConfirmationDialogs into context * fix issue with * more stuff for alaister * fix ts and tables pages * First round of clean up * Update README.md * Smol fix * Fix issues identified * Smol fix * Fix updating table name in database/tables not invalidating * Improve SQL editor invalidation logic * Add fix to reopen last opened table when landing on table editor * Smol fix --------- Co-authored-by: Alaister Young <a@alaisteryoung.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
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)
|
|
// Supports BigInt filter values
|
|
if (Number.isNaN(numberValue) || numberValue > Number.MAX_SAFE_INTEGER) return filter.value
|
|
else return Number(filter.value)
|
|
}
|
|
return filter.value
|
|
}
|
|
|
|
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) }
|
|
}
|