Files
supabase/apps/studio/components/interfaces/TableGridEditor/EmptyState.tsx
Joshen Lim d8a57c1c7e Add settings for queues: toggle expose through postgrest + permissions via table privileges (#30564)
* Add settings for queues: toggle expose through postgrest + permissions via table privileges

* Ensure appropriate grants are granted when toggling, and revoked when disabling

* Update to use queues_public schema

* Update queue schema to pgmq_public and add/remove from data api when enabling/disabling

* Fix query for retrieving toggle state

* Add schema invalidation

* Remove hard code

* Use QueuesSettings from Queues folder, remove from NewQueues

* Update SQL for toggling exposure + support RLS enabling

* Support toggling RLS for a queue

* Update admonition copy in queues for enabling/disable postgrest exposure

* Add custom RLS policy for queue

* Minor style fixes

* Fix

* Remove hard code

* Update RLS to add message regarding relevancy only if exposure to PostgREST is enabled

* Update message in exposing queues to postgREST

* Address feedback

* Address feedback

* Don't revoke postgres role stuff

* Remove hard code

* Update copy

* Update

* Address Oli's feedback, ensure that queues ALL have RLS enabled prior to allowing exposure to PostgREST

* Address remaining feedback

* Remove hardcode

* Update

* Address feedback
2024-11-27 12:10:33 +08:00

67 lines
2.4 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
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 } from 'hooks/misc/useCheckPermissions'
import { useLocalStorage } from 'hooks/misc/useLocalStorage'
import { useQuerySchemaState } from 'hooks/misc/useSchemaQueryState'
import { PROTECTED_SCHEMAS } from 'lib/constants/schemas'
import { useTableEditorStateSnapshot } from 'state/table-editor'
export interface EmptyStateProps {}
const EmptyState = ({}: EmptyStateProps) => {
const snap = useTableEditorStateSnapshot()
const { selectedSchema } = useQuerySchemaState()
const isProtectedSchema = PROTECTED_SCHEMAS.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,
schemas: [selectedSchema],
sort,
})
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 ? snap.onAddTable : undefined}
>
<p className="text-sm text-foreground-light">
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 ? snap.onAddTable : undefined}
>
<p className="text-sm text-foreground-light">
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 EmptyState