mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { observer } from 'mobx-react-lite'
|
|
|
|
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
|
|
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
|
|
import { useEntityTypesQuery } from 'data/entity-types/entity-types-infinite-query'
|
|
import { useCheckPermissions, useLocalStorage, useStore } from 'hooks'
|
|
|
|
interface EmptyStateProps {
|
|
selectedSchema: string
|
|
onAddTable: () => void
|
|
}
|
|
|
|
const EmptyState = ({ selectedSchema, onAddTable }: EmptyStateProps) => {
|
|
const { meta } = useStore()
|
|
const isProtectedSchema = meta.excludedSchemas.includes(selectedSchema)
|
|
const canCreateTables =
|
|
useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'tables') && !isProtectedSchema
|
|
|
|
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">
|
|
{totalCount === 0 ? (
|
|
<ProductEmptyState
|
|
title="Table Editor"
|
|
ctaButtonLabel={canCreateTables ? 'Create a new table' : undefined}
|
|
onClickCta={canCreateTables ? onAddTable : undefined}
|
|
>
|
|
<p className="text-sm text-scale-1100">There are no tables available in this schema.</p>
|
|
</ProductEmptyState>
|
|
) : (
|
|
<div className="flex flex-col items-center space-y-4">
|
|
<ProductEmptyState
|
|
title="Table Editor"
|
|
ctaButtonLabel={canCreateTables ? 'Create a new table' : undefined}
|
|
onClickCta={canCreateTables ? onAddTable : undefined}
|
|
>
|
|
<p className="text-sm text-scale-1100">
|
|
Select a table from the navigation panel on the left to view its data
|
|
{canCreateTables && ', or create a new one.'}
|
|
</p>
|
|
</ProductEmptyState>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default observer(EmptyState)
|