Skip to content

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

Table Editor: Shift loading, error and empty states outside of DataGrid (#35031)

Joshen Lim8f64345725b2
diff --git a/apps/studio/components/grid/components/grid/Grid.tsx b/apps/studio/components/grid/components/grid/Grid.tsx
index c363d695812..3fa50b0992e 100644
--- a/apps/studio/components/grid/components/grid/Grid.tsx
+++ b/apps/studio/components/grid/components/grid/Grid.tsx
@@ -2,7 +2,6 @@ import { forwardRef, memo, useRef } from 'react'
import DataGrid, { CalculatedColumn, DataGridHandle } from 'react-data-grid'
import { handleCopyCell } from 'components/grid/SupabaseGrid.utils'
-import { TableGridInnerLoadingState } from 'components/interfaces/TableGridEditor/LoadingState'
import { formatForeignKeys } from 'components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.utils'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import AlertError from 'components/ui/AlertError'
@@ -12,6 +11,7 @@ import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useTableEditorStateSnapshot } from 'state/table-editor'
import { useTableEditorTableStateSnapshot } from 'state/table-editor-table'
import { Button, cn } from 'ui'
+import { GenericSkeletonLoader } from 'ui-patterns'
import type { Filter, GridProps, SupaRow } from '../../types'
import { useOnRowsChange } from './Grid.utils'
import RowRenderer from './RowRenderer'
@@ -112,87 +112,79 @@ export const Grid = memo(
return (
<div
- className={cn(`flex flex-col`, containerClass)}
+ className={cn(`flex flex-col relative`, containerClass)}
style={{ width: width || '100%', height: height || '50vh' }}
>
+ {/* Render no rows fallback outside of the DataGrid */}
+ {(rows ?? []).length === 0 && (
+ <div
+ style={{ height: `calc(100% - 35px)` }}
+ className="absolute top-9 z-[2] p-2 w-full"
+ >
+ {isLoading && <GenericSkeletonLoader />}
+ {isError && (
+ <AlertError 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>
+ )}
+ {isSuccess && (
+ <>
+ {(filters ?? []).length === 0 ? (
+ <div className="flex flex-col items-center justify-center col-span-full h-full">
+ <p className="text-sm text-light">This table is empty</p>
+ <p className="text-sm text-light mt-1">
+ Add rows to your table to get started.
+ </p>
+ <div className="flex items-center space-x-2 mt-4">
+ {
+ <Button
+ type="default"
+ onClick={() => {
+ tableEditorSnap.onImportData()
+ sendEvent({
+ action: 'import_data_button_clicked',
+ properties: { tableType: 'Existing Table' },
+ groups: {
+ project: project?.ref ?? 'Unknown',
+ organization: org?.slug ?? 'Unknown',
+ },
+ })
+ }}
+ >
+ Import data from CSV
+ </Button>
+ }
+ </div>
+ </div>
+ ) : (
+ <div className="flex flex-col items-center justify-center col-span-full">
+ <p className="text-sm text-light">
+ The filters applied have returned no results from this table
+ </p>
+ <div className="flex items-center space-x-2 mt-4">
+ <Button type="default" onClick={() => removeAllFilters()}>
+ Remove all filters
+ </Button>
+ </div>
+ </div>
+ )}
+ </>
+ )}
+ </div>
+ )}
+
<DataGrid
ref={ref}
className={`${gridClass} flex-grow`}
rowClass={rowClass}
columns={snap.gridColumns as CalculatedColumn<any, any>[]}
rows={rows ?? []}
- renderers={{
- renderRow: RowRenderer,
- noRowsFallback: (
- // [Joshen] Temp fix with magic numbers till we find a better solution
- // RDG used to use flex, but with v7 they've moved to CSS grid and the
- // in built no rows fallback only takes the width of the CSS grid itself
- <div style={{ width: `calc(100vw - 255px - 55px)` }}>
- {isLoading && <TableGridInnerLoadingState />}
- {isError && (
- <div className="p-2 col-span-full">
- <AlertError 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>
- </div>
- )}
- {isSuccess && (
- <>
- {(filters ?? []).length === 0 ? (
- <div
- style={{ height: `calc(100% - 35px)` }}
- className="flex flex-col items-center justify-center col-span-full"
- >
- <p className="text-sm text-light">This table is empty</p>
- <p className="text-sm text-light mt-1">
- Add rows to your table to get started.
- </p>
- <div className="flex items-center space-x-2 mt-4">
- {
- <Button
- type="default"
- onClick={() => {
- tableEditorSnap.onImportData()
- sendEvent({
- action: 'import_data_button_clicked',
- properties: { tableType: 'Existing Table' },
- groups: {
- project: project?.ref ?? 'Unknown',
- organization: org?.slug ?? 'Unknown',
- },
- })
- }}
- >
- Import data from CSV
- </Button>
- }
- </div>
- </div>
- ) : (
- <div
- style={{ height: `calc(100% - 35px)` }}
- className="flex flex-col items-center justify-center col-span-full"
- >
- <p className="text-sm text-light">
- The filters applied have returned no results from this table
- </p>
- <div className="flex items-center space-x-2 mt-4">
- <Button type="default" onClick={() => removeAllFilters()}>
- Remove all filters
- </Button>
- </div>
- </div>
- )}
- </>
- )}
- </div>
- ),
- }}
+ renderers={{ renderRow: RowRenderer }}
rowKeyGetter={rowKeyGetter}
selectedRows={snap.selectedRows}
onColumnResize={snap.updateColumnSize}
diff --git a/apps/studio/components/interfaces/TableGridEditor/LoadingState.tsx b/apps/studio/components/interfaces/TableGridEditor/LoadingState.tsx
deleted file mode 100644
index 1543b6ee06b..00000000000
--- a/apps/studio/components/interfaces/TableGridEditor/LoadingState.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
-import { Button, Skeleton } from 'ui'
-
-export const TableGridInnerLoadingState = () => {
- return (
- <div className="p-2 col-span-full">
- <GenericSkeletonLoader />
- </div>
- )
-}
-
-export const TableGridSkeletonLoader = () => {
- return (
- <div className="flex flex-col">
- <div className="h-10 bg-dash-sidebar dark:bg-surface-100" />
- <div className="h-9 border-y" />
- <TableGridInnerLoadingState />
- </div>
- )
-}
diff --git a/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
index 2393b40235b..7530dea458d 100644
--- a/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
@@ -18,7 +18,7 @@ import { useUrlState } from 'hooks/ui/useUrlState'
import { PROTECTED_SCHEMAS } from 'lib/constants/schemas'
import { TableEditorTableStateContextProvider } from 'state/table-editor-table'
import { makeActiveTabPermanent } from 'state/tabs'
-import { TableGridSkeletonLoader } from './LoadingState'
+import { GenericSkeletonLoader } from 'ui-patterns'
import NotFoundState from './NotFoundState'
import SidePanelEditor from './SidePanelEditor/SidePanelEditor'
import TableDefinition from './TableDefinition'
@@ -56,7 +56,15 @@ const TableGridEditor = ({
// NOTE: DO NOT PUT HOOKS AFTER THIS LINE
if (isLoadingSelectedTable || !projectRef) {
- return <TableGridSkeletonLoader />
+ return (
+ <div className="flex flex-col">
+ <div className="h-10 bg-dash-sidebar dark:bg-surface-100" />
+ <div className="h-9 border-y" />
+ <div className="p-2 col-span-full">
+ <GenericSkeletonLoader />
+ </div>
+ </div>
+ )
}
if (isUndefined(selectedTable)) {