mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
fixes for feedback
This commit is contained in:
1 parent
eb3e1c9232
commit
9bfccb5bf7
6 files changed
+25
-40
No files matched your search
@@ -222,14 +222,14 @@ const RowHeader = ({ table, sorts, filters }: RowHeaderProps) => {
|
||||
try {
|
||||
if (filters.length === 0) {
|
||||
await truncateRows({
|
||||
projectRef: project?.ref,
|
||||
connectionString: project?.connectionString,
|
||||
projectRef: project.ref,
|
||||
connectionString: project.connectionString,
|
||||
table,
|
||||
})
|
||||
} else {
|
||||
await deleteAllRows({
|
||||
projectRef: project?.ref,
|
||||
connectionString: project?.connectionString,
|
||||
projectRef: project.ref,
|
||||
connectionString: project.connectionString,
|
||||
table,
|
||||
filters,
|
||||
})
|
||||
|
||||
@@ -28,13 +28,12 @@ const RowContextMenu = ({ table }: RowContextMenuProps) => {
|
||||
const { props } = p
|
||||
const { rowIdx } = props
|
||||
const row = state.rows[rowIdx]
|
||||
if (!row) return
|
||||
if (!project) return
|
||||
if (!row || !project) return
|
||||
|
||||
try {
|
||||
await deleteRows({
|
||||
projectRef: project?.ref,
|
||||
connectionString: project?.connectionString,
|
||||
projectRef: project.ref,
|
||||
connectionString: project.connectionString,
|
||||
table,
|
||||
rows: [row],
|
||||
})
|
||||
|
||||
@@ -67,8 +67,7 @@ const SidePanelEditor: FC<Props> = ({
|
||||
onComplete: Function
|
||||
) => {
|
||||
if (!project || selectedTable === undefined) {
|
||||
// TODO(alaister): should we have an error state here?
|
||||
return
|
||||
return console.error('no project or table selected')
|
||||
}
|
||||
|
||||
let saveRowError = false
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
||||
import { Query, ServiceError, SupaRow, SupaTable } from 'components/grid'
|
||||
import { ERROR_PRIMARY_KEY_NOTFOUND } from 'components/grid/constants'
|
||||
import { Query, SupaRow, SupaTable } from 'components/grid'
|
||||
import { executeSql } from 'data/sql/execute-sql-query'
|
||||
import { sqlKeys } from 'data/sql/keys'
|
||||
import { getPrimaryKeys } from './utils'
|
||||
|
||||
export type TableRowDeleteVariables = {
|
||||
projectRef: string
|
||||
@@ -68,14 +68,3 @@ export const useTableRowDeleteMutation = ({
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function getPrimaryKeys({ table }: { table: SupaTable }): {
|
||||
primaryKeys?: string[]
|
||||
error?: ServiceError
|
||||
} {
|
||||
const pkColumns = table.columns.filter((x) => x.isPrimaryKey)
|
||||
if (!pkColumns || pkColumns.length == 0) {
|
||||
return { error: { message: ERROR_PRIMARY_KEY_NOTFOUND } }
|
||||
}
|
||||
return { primaryKeys: pkColumns.map((x) => x.name) }
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { QueryKey, UseQueryOptions } from '@tanstack/react-query'
|
||||
import { Filter, Query, SupaRow, SupaTable } from 'components/grid'
|
||||
import { isNumericalColumn } from 'components/grid/utils'
|
||||
import { Filter, Query, SupaTable } from 'components/grid'
|
||||
import { ExecuteSqlData, useExecuteSqlPrefetch, useExecuteSqlQuery } from '../sql/execute-sql-query'
|
||||
import { formatFilterValue } from './utils'
|
||||
|
||||
type GetTableRowsCountArgs = {
|
||||
table?: SupaTable
|
||||
@@ -83,17 +83,3 @@ export const useTableRowsCountPrefetch = ({
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* temporary fix until we implement a better filter UI
|
||||
* which validate input value base on the column type
|
||||
*/
|
||||
function formatFilterValue(table: SupaTable, 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)) return filter.value
|
||||
else return Number(filter.value)
|
||||
}
|
||||
return filter.value
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Filter, SupaTable } from 'components/grid'
|
||||
import { Filter, ServiceError, SupaTable } from 'components/grid'
|
||||
import { ERROR_PRIMARY_KEY_NOTFOUND } from 'components/grid/constants'
|
||||
import { isNumericalColumn } from 'components/grid/utils'
|
||||
|
||||
/**
|
||||
@@ -14,3 +15,14 @@ export function formatFilterValue(table: SupaTable, filter: Filter) {
|
||||
}
|
||||
return filter.value
|
||||
}
|
||||
|
||||
export function getPrimaryKeys({ table }: { table: SupaTable }): {
|
||||
primaryKeys?: string[]
|
||||
error?: ServiceError
|
||||
} {
|
||||
const pkColumns = table.columns.filter((x) => x.isPrimaryKey)
|
||||
if (!pkColumns || pkColumns.length == 0) {
|
||||
return { error: { message: ERROR_PRIMARY_KEY_NOTFOUND } }
|
||||
}
|
||||
return { primaryKeys: pkColumns.map((x) => x.name) }
|
||||
}
|
||||
Reference in new issue
Block a user