Skip to content

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

fix empty states of table editor

Joshen Lim97bc98aa21b5
diff --git a/studio/components/grid/SupabaseGrid.tsx b/studio/components/grid/SupabaseGrid.tsx
index ba327db1e2b..daea832730d 100644
--- a/studio/components/grid/SupabaseGrid.tsx
+++ b/studio/components/grid/SupabaseGrid.tsx
@@ -65,7 +65,7 @@ const SupabaseGridLayout = forwardRef<SupabaseGridRef, SupabaseGridProps>(
const filters = formatFilterURLParams(filter as string[])
const { project } = useProjectContext()
- const { data, isLoading, isRefetching } = useTableRowsQuery(
+ const { data, error, isSuccess, isError, isLoading, isRefetching } = useTableRowsQuery(
{
queryKey: [props.table.schema, props.table.name],
projectRef: project?.ref,
@@ -187,7 +187,14 @@ const SupabaseGridLayout = forwardRef<SupabaseGridRef, SupabaseGridProps>(
ref={gridRef}
{...gridProps}
rows={data?.rows ?? []}
+ error={error}
+ isLoading={isLoading}
+ isSuccess={isSuccess}
+ isError={isError}
+ filters={filters}
updateRow={updateTableRow}
+ onAddRow={onAddRow}
+ onImportData={onImportData}
onEditForeignKeyColumnValue={onEditForeignKeyColumnValue}
/>
<Footer isLoading={isLoading || isRefetching} />
diff --git a/studio/components/grid/components/grid/Grid.tsx b/studio/components/grid/components/grid/Grid.tsx
index 3d28e84c4ad..0ceec407f85 100644
--- a/studio/components/grid/components/grid/Grid.tsx
+++ b/studio/components/grid/components/grid/Grid.tsx
@@ -9,9 +9,11 @@ import { ForeignRowSelectorProps } from 'components/interfaces/TableGridEditor/S
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { useForeignKeyConstraintsQuery } from 'data/database/foreign-key-constraints-query'
import { useDispatch, useTrackedState } from '../../store'
-import { GridProps, SupaRow } from '../../types'
+import { Filter, GridProps, SupaRow } from '../../types'
import RowRenderer from './RowRenderer'
import { Button } from 'ui'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import AlertError from 'components/ui/AlertError'
const rowKeyGetter = (row: SupaRow) => {
return row?.idx ?? -1
@@ -27,6 +29,11 @@ const updateColumnResizeDebounced = AwesomeDebouncePromise(updateColumnResize, 5
interface IGrid extends GridProps {
rows: any[]
+ error: any
+ isLoading: boolean
+ isSuccess: boolean
+ isError: boolean
+ filters: Filter[]
updateRow: (previousRow: any, updatedData: any) => void
onAddRow?: () => void
onImportData?: () => void
@@ -48,6 +55,11 @@ export const Grid = memo(
gridClass,
rowClass,
rows,
+ error,
+ isLoading,
+ isSuccess,
+ isError,
+ filters,
updateRow,
onAddRow,
onImportData,
@@ -142,26 +154,55 @@ export const Grid = memo(
rowClass={rowClass}
style={{ height: '100%' }}
noRowsFallback={
- <div
- style={{ height: `calc(100% - 35px)` }}
- className="flex flex-col items-center justify-center"
- >
- <p className="text-base">This table is empty</p>
- {onAddRow !== undefined && onImportData !== undefined && (
+ <>
+ {isLoading && (
+ <div className="p-2">
+ <GenericSkeletonLoader />
+ </div>
+ )}
+ {isError && (
+ <div className="p-2">
+ <AlertError error={error} subject="Failed to retrieve rows from table" />
+ </div>
+ )}
+ {isSuccess && (
<>
- <p className="text-sm text-light mt-1">Add or generate rows to get started.</p>
- <div className="flex items-center space-x-2 mt-4">
- {/* [Joshen] Leaving this as a placeholder */}
- {/* <Button type="outline">Generate random data</Button> */}
- {onAddRow !== undefined && onImportData !== undefined && (
- <Button type="default" onClick={onImportData}>
- Import data via CSV
- </Button>
- )}
- </div>
+ {(filters ?? []).length === 0 ? (
+ <div
+ style={{ height: `calc(100% - 35px)` }}
+ className="flex flex-col items-center justify-center"
+ >
+ <p className="text-sm text">This table is empty</p>
+ {onAddRow !== undefined && onImportData !== undefined && (
+ <>
+ <p className="text-sm text-light mt-1">
+ Add or generate rows to get started.
+ </p>
+ <div className="flex items-center space-x-2 mt-4">
+ {/* [Joshen] Leaving this as a placeholder */}
+ {/* <Button type="outline">Generate random data</Button> */}
+ {onAddRow !== undefined && onImportData !== undefined && (
+ <Button type="default" onClick={onImportData}>
+ Import data via CSV
+ </Button>
+ )}
+ </div>
+ </>
+ )}
+ </div>
+ ) : (
+ <div
+ style={{ height: `calc(100% - 35px)` }}
+ className="flex flex-col items-center justify-center"
+ >
+ <p className="text-sm text-light">
+ The filters applied has returned no results from this table
+ </p>
+ </div>
+ )}
</>
)}
- </div>
+ </>
}
/>
</div>