Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Chore/contextual errors for table editor (#39004)

Joshen Limb9945663c93e
diff --git a/apps/studio/components/grid/SupabaseGrid.tsx b/apps/studio/components/grid/SupabaseGrid.tsx
index 3bf86dd9ee2..b468f085d19 100644
--- a/apps/studio/components/grid/SupabaseGrid.tsx
+++ b/apps/studio/components/grid/SupabaseGrid.tsx
@@ -60,17 +60,10 @@ export const SupabaseGrid = ({
},
{
keepPreviousData: true,
- retryDelay: (retryAttempt, error: any) => {
+ retry: (_, error: any) => {
const doesNotExistError = error && error.message?.includes('does not exist')
- const tooManyRequestsError = error.message?.includes('Too Many Requests')
- const vaultError = error.message?.includes('query vault failed')
-
if (doesNotExistError) onApplySorts([])
-
- if (retryAttempt > 3 || doesNotExistError || tooManyRequestsError || vaultError) {
- return Infinity
- }
- return 5000
+ return false
},
}
)
diff --git a/apps/studio/components/grid/components/common/DropdownControl.tsx b/apps/studio/components/grid/components/common/DropdownControl.tsx
index 502f688651a..a5f9fe0913e 100644
--- a/apps/studio/components/grid/components/common/DropdownControl.tsx
+++ b/apps/studio/components/grid/components/common/DropdownControl.tsx
@@ -1,5 +1,6 @@
+import { DropdownMenuItemTooltip } from 'components/ui/DropdownMenuItemTooltip'
import { PropsWithChildren } from 'react'
-import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from 'ui'
+import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from 'ui'
interface DropdownControlProps {
options: {
@@ -7,6 +8,8 @@ interface DropdownControlProps {
label: string
postLabel?: string
preLabel?: string
+ disabled?: boolean
+ tooltip?: string
}[]
onSelect: (value: string | number) => void
side?: 'bottom' | 'left' | 'top' | 'right' | undefined
@@ -30,13 +33,18 @@ export const DropdownControl = ({
{options.length === 0 && <p className="dropdown-control__empty-text">No more items</p>}
{options.map((x) => {
return (
- <DropdownMenuItem key={x.value} onClick={() => onSelect(x.value)}>
+ <DropdownMenuItemTooltip
+ key={x.value}
+ disabled={x.disabled}
+ tooltip={{ content: { side: 'right', text: x.tooltip } }}
+ onClick={() => onSelect(x.value)}
+ >
<div className="flex items-center gap-2">
{x.preLabel && <span className="grow text-foreground-lighter">{x.preLabel}</span>}
<span>{x.label}</span>
{x.postLabel && <span className="text-foreground-lighter">{x.postLabel}</span>}
</div>
- </DropdownMenuItem>
+ </DropdownMenuItemTooltip>
)
})}
</div>
diff --git a/apps/studio/components/grid/components/grid/Grid.tsx b/apps/studio/components/grid/components/grid/Grid.tsx
index 4b5e9142a7e..5608e5b97ca 100644
--- a/apps/studio/components/grid/components/grid/Grid.tsx
+++ b/apps/studio/components/grid/components/grid/Grid.tsx
@@ -4,8 +4,6 @@ import { ref as valtioRef } from 'valtio'
import { handleCopyCell } from 'components/grid/SupabaseGrid.utils'
import { formatForeignKeys } from 'components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.utils'
-import AlertError from 'components/ui/AlertError'
-import { InlineLink } from 'components/ui/InlineLink'
import { useForeignKeyConstraintsQuery } from 'data/database/foreign-key-constraints-query'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
@@ -15,10 +13,10 @@ import { useCsvFileDrop } from 'hooks/ui/useCsvFileDrop'
import { useTableEditorStateSnapshot } from 'state/table-editor'
import { useTableEditorTableStateSnapshot } from 'state/table-editor-table'
import { Button, cn } from 'ui'
-import { Admonition } from 'ui-patterns'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import type { Filter, GridProps, SupaRow } from '../../types'
import { useOnRowsChange } from './Grid.utils'
+import { GridError } from './GridError'
import RowRenderer from './RowRenderer'
const rowKeyGetter = (row: SupaRow) => {
@@ -60,7 +58,6 @@ export const Grid = memo(
const { data: org } = useSelectedOrganizationQuery()
const { data: project } = useSelectedProjectQuery()
- const isBranch = project?.parent_project_ref !== undefined
const onRowsChange = useOnRowsChange(rows)
@@ -80,9 +77,6 @@ export const Grid = memo(
const isForeignTable = tableEntityType === ENTITY_TYPE.FOREIGN_TABLE
const isTableEmpty = (rows ?? []).length === 0
- const isForeignTableMissingVaultKeyError =
- isForeignTable && isError && error.message.includes('query vault failed')
-
const { mutate: sendEvent } = useSendEventMutation()
const { isDraggedOver, onDragOver, onFileDrop } = useCsvFileDrop({
@@ -155,51 +149,9 @@ export const Grid = memo(
className="absolute top-9 p-2 w-full z-[1] pointer-events-none"
>
{isLoading && <GenericSkeletonLoader />}
- {isError ? (
- isForeignTableMissingVaultKeyError ? (
- <Admonition
- type="warning"
- className="pointer-events-auto"
- title="Failed to retrieve rows from foreign table"
- >
- <p>
- The key that's used to retrieve data from your foreign table is either
- incorrect or missing. Verify the key in your{' '}
- <InlineLink href={`/project/${project?.ref}/integrations?category=wrapper`}>
- wrapper's settings
- </InlineLink>{' '}
- or in{' '}
- <InlineLink href={`/project/${project?.ref}/integrations/vault/overview`}>
- Vault
- </InlineLink>
- .
- </p>
- {isBranch && (
- <p>
- Note: Vault keys from the main project do not sync to branches. You may add
- them manually into{' '}
- <InlineLink href={`/project/${project?.ref}/integrations/vault/overview`}>
- Vault
- </InlineLink>{' '}
- if you want to query foreign tables while on a branch.
- </p>
- )}
- </Admonition>
- ) : (
- <AlertError
- className="pointer-events-auto"
- error={error}
- subject="Failed to retrieve rows from table"
- >
- {filters.length > 0 && (
- <p>
- Verify that the filter values are correct, as the error may stem from an
- incorrectly applied filter
- </p>
- )}
- </AlertError>
- )
- ) : null}
+
+ {isError && <GridError error={error} />}
+
{isSuccess && (
<>
{(filters ?? []).length === 0 ? (
diff --git a/apps/studio/components/grid/components/grid/GridError.tsx b/apps/studio/components/grid/components/grid/GridError.tsx
new file mode 100644
index 00000000000..9999466ef57
--- /dev/null
+++ b/apps/studio/components/grid/components/grid/GridError.tsx
@@ -0,0 +1,147 @@
+import { useParams } from 'common'
+import { useTableFilter } from 'components/grid/hooks/useTableFilter'
+import { useTableSort } from 'components/grid/hooks/useTableSort'
+import AlertError from 'components/ui/AlertError'
+import { InlineLink } from 'components/ui/InlineLink'
+import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { useTableEditorTableStateSnapshot } from 'state/table-editor-table'
+import { Button } from 'ui'
+import { Admonition } from 'ui-patterns'
+
+export const GridError = ({ error }: { error?: any }) => {
+ const { filters } = useTableFilter()
+ const { sorts } = useTableSort()
+ const snap = useTableEditorTableStateSnapshot()
+
+ const tableEntityType = snap.originalTable?.entity_type
+ const isForeignTable = tableEntityType === ENTITY_TYPE.FOREIGN_TABLE
+
+ const isForeignTableMissingVaultKeyError =
+ isForeignTable && error?.message?.includes('query vault failed')
+
+ const isInvalidSyntaxError =
+ filters.length > 0 && error?.message?.includes('invalid input syntax')
+
+ const isInvalidOrderingOperatorError =
+ sorts.length > 0 && error?.message?.includes('identify an ordering operator')
+
+ if (isForeignTableMissingVaultKeyError) {
+ return <ForeignTableMissingVaultKeyError />
+ } else if (isInvalidSyntaxError) {
+ return <InvalidSyntaxError error={error} />
+ } else if (isInvalidOrderingOperatorError) {
+ return <InvalidOrderingOperatorError error={error} />
+ }
+
+ return <GeneralError error={error} />
+}
+
+const ForeignTableMissingVaultKeyError = () => {
+ const { ref } = useParams()
+ const { data: project } = useSelectedProjectQuery()
+ const isBranch = project?.parent_project_ref !== undefined
+
+ return (
+ <Admonition
+ type="warning"
+ className="pointer-events-auto"
+ title="Failed to retrieve rows from foreign table"
+ >
+ <p>
+ The key that's used to retrieve data from your foreign table is either incorrect or missing.
+ Verify the key in your{' '}
+ <InlineLink href={`/project/${ref}/integrations?category=wrapper`}>
+ wrapper's settings
+ </InlineLink>{' '}
+ or in <InlineLink href={`/project/${ref}/integrations/vault/overview`}>Vault</InlineLink>.
+ </p>
+ {isBranch && (
+ <p>
+ Note: Vault keys from the main project do not sync to branches. You may add them manually
+ into <InlineLink href={`/project/${ref}/integrations/vault/overview`}>Vault</InlineLink>{' '}
+ if you want to query foreign tables while on a branch.
+ </p>
+ )}
+ </Admonition>
+ )
+}
+
+const InvalidSyntaxError = ({ error }: { error?: any }) => {
+ const { onApplyFilters } = useTableFilter()
+
+ return (
+ <Admonition
+ type="warning"
+ className="pointer-events-auto"
+ title="Invalid input syntax provided in filter value(s)"
+ >
+ <p className="!mb-0">
+ Unable to retrieve results as the provided value in your filter(s) doesn't match it's column
+ data type.
+ </p>
+ <p className="!mb-2">
+ Verify that your filter values are correct before applying the filters again.
+ </p>
+ <p className="text-sm text-foreground-lighter prose max-w-full !mb-4">
+ Error: <code className="text-xs">{error.message}</code>
+ </p>
+
+ <Button type="default" onClick={() => onApplyFilters([])}>
+ Remove filters
+ </Button>
+ </Admonition>
+ )
+}
+
+const InvalidOrderingOperatorError = ({ error }: { error: any }) => {
+ const { sorts, onApplySorts } = useTableSort()
+ const invalidDataType = (error?.message ?? '').split('type ').pop()
+ const formattedInvalidDataType = invalidDataType.includes('json')
+ ? invalidDataType.toUpperCase()
+ : invalidDataType
+
+ return (
+ <Admonition
+ type="warning"
+ className="pointer-events-auto"
+ title={`Sorting is not supporting on ${sorts.length > 1 ? 'one of the selected columns' : 'the selected column'}`}
+ >
+ <p className="!mb-0">
+ Unable to retrieve results as sorting is not supported on{' '}
+ {sorts.length > 1 ? 'one of the selected columns' : 'the selected column'} due to its data
+ type. ({formattedInvalidDataType})
+ </p>
+ <p className="!mb-2">
+ Remove any sorts on columns with the data type {formattedInvalidDataType} applying the sorts
+ again.
+ </p>
+ <p className="text-sm text-foreground-lighter prose max-w-full !mb-4">
+ Error: <code className="text-xs">{error.message}</code>
+ </p>
+
+ <Button type="default" onClick={() => onApplySorts([])}>
+ Remove sorts
+ </Button>
+ </Admonition>
+ )
+}
+
+const GeneralError = ({ error }: { error: any }) => {
+ const { filters } = useTableFilter()
+
+ return (
+ <AlertError
+ className="pointer-events-auto"
+ error={error}
+ subject="Failed to retrieve rows from table"
+ >
+ {filters.length > 0 && (
+ <p>
+ Verify that the filter values are correct, as the error may stem from an incorrectly
+ applied filter
+ </p>
+ )}
+ </AlertError>
+ )
+}
diff --git a/apps/studio/components/grid/components/header/filter/FilterPopoverPrimitive.tsx b/apps/studio/components/grid/components/header/filter/FilterPopoverPrimitive.tsx
index a36027b4610..868b2e2715e 100644
--- a/apps/studio/components/grid/components/header/filter/FilterPopoverPrimitive.tsx
+++ b/apps/studio/components/grid/components/header/filter/FilterPopoverPrimitive.tsx
@@ -109,7 +109,7 @@ export const FilterPopoverPrimitive = ({
))}
{localFilters.length == 0 && (
<div className="space-y-1 px-3">
- <h5 className="text-foreground-light">No filters applied to this view</h5>
+ <h5 className="text-xs text-foreground-light">No filters applied to this view</h5>
<p className="text-xs text-foreground-lighter">
Add a column below to filter the view
</p>
@@ -118,7 +118,7 @@ export const FilterPopoverPrimitive = ({
</div>
<PopoverSeparator_Shadcn_ />
<div className="px-3 flex flex-row justify-between">
- <Button icon={<Plus />} type="text" onClick={onAddFilter}>
+ <Button icon={<Plus />} type="dashed" onClick={onAddFilter}>
Add filter
</Button>
<Button
diff --git a/apps/studio/components/grid/components/header/sort/SortPopoverPrimitive.tsx b/apps/studio/components/grid/components/header/sort/SortPopoverPrimitive.tsx
index 943f60aaf25..3a5f1d9510c 100644
--- a/apps/studio/components/grid/components/header/sort/SortPopoverPrimitive.tsx
+++ b/apps/studio/components/grid/components/header/sort/SortPopoverPrimitive.tsx
@@ -74,7 +74,6 @@ export const SortPopoverPrimitive = ({
const columns = useMemo(() => {
if (!snap?.table?.columns) return []
return snap.table.columns.filter((x) => {
- if (x.dataType === 'json' || x.dataType === 'jsonb') return false
const found = localSorts.find((y) => y.column == x.name)
return !found
})
@@ -82,7 +81,18 @@ export const SortPopoverPrimitive = ({
// Format the columns for the dropdown
const dropdownOptions = useMemo(() => {
- return columns?.map((x) => ({ value: x.name, label: x.name })) || []
+ return (
+ columns?.map((x) => ({
+ value: x.name,
+ label: x.name,
+ postLabel: x.dataType,
+ disabled: x.dataType === 'json' || x.dataType === 'jsonb',
+ tooltip:
+ x.dataType === 'json' || x.dataType === 'jsonb'
+ ? 'Sorting on JSON-based columns is currently not supported'
+ : '',
+ })) || []
+ )
}, [columns])
// Add a new sort
@@ -185,7 +195,7 @@ export const SortPopoverPrimitive = ({
))}
{localSorts.length === 0 && (
<div className="space-y-1 px-3">
- <h5 className="text-foreground-light">No sorts applied to this view</h5>
+ <h5 className="text-xs text-foreground-light">No sorts applied to this view</h5>
<p className="text-xs text-foreground-lighter">Add a column below to sort the view</p>
</div>
)}
@@ -201,7 +211,7 @@ export const SortPopoverPrimitive = ({
>
<Button
asChild
- type="text"
+ type="dashed"
iconRight={<ChevronDown size="14" className="text-foreground-light" />}
className="sb-grid-dropdown__item-trigger"
data-testid="table-editor-pick-column-to-sort-button"
diff --git a/apps/studio/components/grid/components/header/sort/SortRow.tsx b/apps/studio/components/grid/components/header/sort/SortRow.tsx
index e4ab58617d3..e13ca434808 100644
--- a/apps/studio/components/grid/components/header/sort/SortRow.tsx
+++ b/apps/studio/components/grid/components/header/sort/SortRow.tsx
@@ -5,7 +5,7 @@ import { useDrag, useDrop } from 'react-dnd'
import type { DragItem, Sort } from 'components/grid/types'
import { useTableEditorTableStateSnapshot } from 'state/table-editor-table'
-import { Button, Toggle } from 'ui'
+import { Button, Switch } from 'ui'
export interface SortRowProps {
index: number
@@ -113,17 +113,14 @@ const SortRow = ({ index, columnName, sort, onDelete, onToggle, onDrag }: SortRo
<span className="text-xs text-foreground-lighter">
{index > 0 ? 'then by' : 'sort by'}
</span>
- {column.name}
+ <span className="text-xs">{column.name}</span>
</span>
</div>
- <div className="flex items-center gap-1">
+ <div className="flex items-center gap-x-1.5">
<label className="text-xs text-foreground-lighter">ascending:</label>
- <Toggle
- size="tiny"
- layout="flex"
+ <Switch
defaultChecked={sort.ascending}
- // @ts-ignore
- onChange={(e: boolean) => onToggle(columnName, e)}
+ onCheckedChange={(e: boolean) => onToggle(columnName, e)}
/>
</div>
<Button
diff --git a/apps/studio/data/table-rows/table-rows-query.ts b/apps/studio/data/table-rows/table-rows-query.ts
index 6f66c6be909..7ccbe21fe40 100644
--- a/apps/studio/data/table-rows/table-rows-query.ts
+++ b/apps/studio/data/table-rows/table-rows-query.ts
@@ -237,9 +237,7 @@ export async function getTableRows(
return { rows }
} catch (error) {
- throw new Error(
- `Error fetching table rows: ${error instanceof Error ? error.message : 'Unknown error'}`
- )
+ throw new Error(error instanceof Error ? error.message : 'Unknown error')
}
}