Skip to content

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

fix: table editor empty state

Alaister Young33455382d1c2
diff --git a/studio/components/interfaces/TableGridEditor/EmptyState.tsx b/studio/components/interfaces/TableGridEditor/EmptyState.tsx
index 5b2b3b1d644..3667bf1e4ef 100644
--- a/studio/components/interfaces/TableGridEditor/EmptyState.tsx
+++ b/studio/components/interfaces/TableGridEditor/EmptyState.tsx
@@ -1,9 +1,10 @@
import { FC } from 'react'
import { observer } from 'mobx-react-lite'
-import type { PostgresTable } from '@supabase/postgres-meta'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { checkPermissions, useStore } from 'hooks'
+import { checkPermissions, useLocalStorage, useStore } from 'hooks'
+import { useEntityTypesQuery } from 'data/entity-types/entity-types-infinite-query'
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
interface Props {
selectedSchema: string
@@ -12,14 +13,33 @@ interface Props {
const EmptyState: FC<Props> = ({ selectedSchema, onAddTable }) => {
const { meta } = useStore()
- const tables = meta.tables.list((table: PostgresTable) => table.schema === selectedSchema)
const isProtectedSchema = meta.excludedSchemas.includes(selectedSchema)
const canCreateTables =
!isProtectedSchema && checkPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'tables')
+ const [sort] = useLocalStorage<'alphabetical' | 'grouped-alphabetical'>(
+ 'table-editor-sort',
+ 'alphabetical'
+ )
+
+ const { project } = useProjectContext()
+ const { data } = useEntityTypesQuery(
+ {
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ schema: selectedSchema,
+ sort,
+ },
+ {
+ keepPreviousData: true,
+ }
+ )
+
+ const totalCount = data?.pages?.[0].data.count ?? 0
+
return (
<div className="w-full h-full flex items-center justify-center">
- {tables.length === 0 ? (
+ {totalCount === 0 ? (
<ProductEmptyState
title="Table Editor"
ctaButtonLabel={canCreateTables ? 'Create a new table' : undefined}