Skip to content

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

Chore/show impersonator in views (#21401)

Terry Suttonbdd3ad76ad18
diff --git a/apps/studio/components/interfaces/ProjectAPIDocs/Content/Entity.tsx b/apps/studio/components/interfaces/ProjectAPIDocs/Content/Entity.tsx
index b9a82d656eb..a497204147b 100644
--- a/apps/studio/components/interfaces/ProjectAPIDocs/Content/Entity.tsx
+++ b/apps/studio/components/interfaces/ProjectAPIDocs/Content/Entity.tsx
@@ -42,7 +42,7 @@ const Entity = ({ language, apikey = '', endpoint = '' }: ContentProps) => {
? Object.entries(definition.properties).map(([id, val]: any) => ({
...val,
id,
- required: definition.required.includes(id),
+ required: (definition?.required ?? []).includes(id),
}))
: []
diff --git a/apps/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.tsx b/apps/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.tsx
index 49675cbd624..6143c0de31e 100644
--- a/apps/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.tsx
+++ b/apps/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.tsx
@@ -62,7 +62,7 @@ const ProjectAPIDocs = () => {
onCancel={() => snap.setShowProjectApiDocs(false)}
>
<div className="flex items-start h-full">
- <div className="w-64 border-r h-full">
+ <div className="w-72 border-r h-full">
<div className="border-b px-4 py-2 flex items-center justify-between">
<h4>API Docs</h4>
<div className="flex items-center space-x-1">
diff --git a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
index f5339c43d4c..21bdb447fc8 100644
--- a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
@@ -19,21 +19,22 @@ import {
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import APIDocsButton from 'components/ui/APIDocsButton'
import ConfirmationModal from 'components/ui/ConfirmationModal'
+import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
import { useDatabasePoliciesQuery } from 'data/database-policies/database-policies-query'
import { useDatabasePublicationsQuery } from 'data/database-publications/database-publications-query'
import { useDatabasePublicationUpdateMutation } from 'data/database-publications/database-publications-update-mutation'
+import { useTableUpdateMutation } from 'data/tables/table-update-mutation'
import { useCheckPermissions, useIsFeatureEnabled } from 'hooks'
import { RoleImpersonationPopover } from '../RoleImpersonationSelector'
-import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
-
-import { useTableUpdateMutation } from 'data/tables/table-update-mutation'
-
export interface GridHeaderActionsProps {
table: PostgresTable
+ canEditViaTableEditor: boolean
+ isViewSelected: boolean
+ isTableSelected: boolean
}
-const GridHeaderActions = ({ table }: GridHeaderActionsProps) => {
+const GridHeaderActions = ({ table, isViewSelected, isTableSelected }: GridHeaderActionsProps) => {
const { ref } = useParams()
const { project } = useProjectContext()
const realtimeEnabled = useIsFeatureEnabled('realtime:all')
@@ -152,96 +153,99 @@ const GridHeaderActions = ({ table }: GridHeaderActionsProps) => {
</Tooltip.Portal>
</Tooltip.Root>
)}
- {table.rls_enabled ? (
- <div className="flex items-center gap-1">
- {policies.length < 1 ? (
- <Tooltip.Root delayDuration={0}>
- <Tooltip.Trigger className="w-full">
- <Link passHref href={`/project/${projectRef}/auth/policies?search=${table.id}`}>
- <Button
- type="default"
- className="group !h-[28px] !py-0"
- icon={<IconPlusCircle size={12} />}
- >
- Add RLS policy
- </Button>
- </Link>
- </Tooltip.Trigger>
- <Tooltip.Portal>
- <Tooltip.Content side="bottom">
- <Tooltip.Arrow className="radix-tooltip-arrow" />
- <div
- className={[
- 'rounded bg-alternative py-1 px-2 leading-none shadow',
- 'border border-background',
- ].join(' ')}
- >
- <div className="text-xs text-foreground p-1 leading-relaxed">
- <p>RLS is enabled for this table, but no policies are set. </p>
- <p>
- Select queries will return an <u>empty array</u> of results.
- </p>
+
+ {isTableSelected ? (
+ table.rls_enabled ? (
+ <div className="flex items-center gap-1">
+ {policies.length < 1 ? (
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger className="w-full">
+ <Link passHref href={`/project/${projectRef}/auth/policies?search=${table.id}`}>
+ <Button
+ type="default"
+ className="group !h-[28px] !py-0"
+ icon={<IconPlusCircle size={12} />}
+ >
+ Add RLS policy
+ </Button>
+ </Link>
+ </Tooltip.Trigger>
+ <Tooltip.Portal>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-alternative py-1 px-2 leading-none shadow',
+ 'border border-background',
+ ].join(' ')}
+ >
+ <div className="text-xs text-foreground p-1 leading-relaxed">
+ <p>RLS is enabled for this table, but no policies are set. </p>
+ <p>
+ Select queries will return an <u>empty array</u> of results.
+ </p>
+ </div>
</div>
- </div>
- </Tooltip.Content>
- </Tooltip.Portal>
- </Tooltip.Root>
- ) : (
- <Link passHref href={`/project/${projectRef}/auth/policies?search=${table.id}`}>
- <Button
- type={policies.length < 1 ? 'warning' : 'default'}
- className="group !h-[28px] !py-0"
- icon={
- policies.length > 0 ? (
- <span className="text-right text-xs rounded-xl px-[6px] bg-foreground-lighter/30 text-brand-1100">
- {policies.length}
- </span>
- ) : (
- <IconPlusCircle size={12} />
- )
- }
- >
- Auth {policies.length > 1 ? 'policies' : 'policy'}
- </Button>
- </Link>
- )}
- </div>
- ) : (
- <Popover_Shadcn_ open={open} onOpenChange={() => setOpen(!open)} modal={false}>
- <PopoverTrigger_Shadcn_ asChild>
- <Button type="warning" icon={<IconLock size={15} />}>
- RLS disabled
- </Button>
- </PopoverTrigger_Shadcn_>
- <PopoverContent_Shadcn_ className="min-w-[395px] text-sm" align="end">
- <h3 className="flex items-center gap-2">
- <IconLock size={14} /> Row Level Security (RLS)
- </h3>
- <div className="grid gap-2 mt-4">
- <p>
- You can restrict and control who can read, write and update data in this table
- using Row Level Security.
- </p>
- <p>
- With RLS enabled, anonymous users will not be able to read/write data in the
- table.
- </p>
- <div className="mt-2">
+ </Tooltip.Content>
+ </Tooltip.Portal>
+ </Tooltip.Root>
+ ) : (
+ <Link passHref href={`/project/${projectRef}/auth/policies?search=${table.id}`}>
<Button
- type="default"
- onClick={() => setRlsConfirmModalOpen(!rlsConfirmModalOpen)}
+ type={policies.length < 1 ? 'warning' : 'default'}
+ className="group !h-[28px] !py-0"
+ icon={
+ policies.length > 0 ? (
+ <span className="text-right text-xs rounded-xl px-[6px] bg-foreground-lighter/30 text-brand-1100">
+ {policies.length}
+ </span>
+ ) : (
+ <IconPlusCircle size={12} />
+ )
+ }
>
- Enable RLS for this table
+ Auth {policies.length > 1 ? 'policies' : 'policy'}
</Button>
+ </Link>
+ )}
+ </div>
+ ) : (
+ <Popover_Shadcn_ open={open} onOpenChange={() => setOpen(!open)} modal={false}>
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button type="warning" icon={<IconLock size={15} />}>
+ RLS disabled
+ </Button>
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_ className="min-w-[395px] text-sm" align="end">
+ <h3 className="flex items-center gap-2">
+ <IconLock size={14} /> Row Level Security (RLS)
+ </h3>
+ <div className="grid gap-2 mt-4">
+ <p>
+ You can restrict and control who can read, write and update data in this table
+ using Row Level Security.
+ </p>
+ <p>
+ With RLS enabled, anonymous users will not be able to read/write data in the
+ table.
+ </p>
+ <div className="mt-2">
+ <Button
+ type="default"
+ onClick={() => setRlsConfirmModalOpen(!rlsConfirmModalOpen)}
+ >
+ Enable RLS for this table
+ </Button>
+ </div>
</div>
- </div>
- </PopoverContent_Shadcn_>
- </Popover_Shadcn_>
- )}
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
+ )
+ ) : null}
<RoleImpersonationPopover serviceRoleLabel="postgres" />
- {realtimeEnabled && (
+ {realtimeEnabled && !isViewSelected && (
<Button
type="default"
icon={
diff --git a/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
index 9ae8ac23b8d..841b33afc06 100644
--- a/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
@@ -283,11 +283,12 @@ const TableGridEditor = ({
table={gridTable}
headerActions={
isTableSelected || isViewSelected || canEditViaTableEditor ? (
- <>
- {canEditViaTableEditor && (
- <GridHeaderActions table={selectedTable as PostgresTable} />
- )}
- </>
+ <GridHeaderActions
+ table={selectedTable as PostgresTable}
+ canEditViaTableEditor={canEditViaTableEditor}
+ isViewSelected={isViewSelected}
+ isTableSelected={isTableSelected}
+ />
) : null
}
onAddColumn={snap.onAddColumn}