Skip to content

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

Fix view policies from table editor (#20100)

Joshen Lim32c0205288c4
diff --git a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
index 800d249fa89..f463721e03f 100644
--- a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
@@ -235,7 +235,7 @@ const EntityListItem = ({ id, projectRef, item: entity, isLocked }: EntityListIt
<DropdownMenuItem key="delete-table" className="space-x-2" asChild>
<Link
key="view-policies"
- href={`/project/${projectRef}/auth/policies?search=${entity.id}`}
+ href={`/project/${projectRef}/auth/policies?schema=${snap.selectedSchemaName}&search=${entity.id}`}
>
<IconLock size="tiny" />
<p>View Policies</p>
diff --git a/apps/studio/pages/project/[ref]/auth/policies.tsx b/apps/studio/pages/project/[ref]/auth/policies.tsx
index 8b889f108f4..f3cc4c7e0ca 100644
--- a/apps/studio/pages/project/[ref]/auth/policies.tsx
+++ b/apps/studio/pages/project/[ref]/auth/policies.tsx
@@ -59,7 +59,7 @@ const onFilterTables = (
}
const AuthPoliciesPage: NextPageWithLayout = () => {
- const { search } = useParams()
+ const { search, schema } = useParams()
const { project } = useProjectContext()
const snap = useTableEditorStateSnapshot()
const [searchString, setSearchString] = useState<string>('')
@@ -72,6 +72,10 @@ const AuthPoliciesPage: NextPageWithLayout = () => {
if (search) setSearchString(search)
}, [search])
+ useEffect(() => {
+ if (schema) snap.setSelectedSchemaName(schema)
+ }, [schema])
+
const { data: schemas } = useSchemasQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
@@ -79,8 +83,8 @@ const AuthPoliciesPage: NextPageWithLayout = () => {
const [protectedSchemas] = partition(schemas, (schema) =>
EXCLUDED_SCHEMAS.includes(schema?.name ?? '')
)
- const schema = schemas?.find((schema) => schema.name === snap.selectedSchemaName)
- const isLocked = protectedSchemas.some((s) => s.id === schema?.id)
+ const selectedSchema = schemas?.find((schema) => schema.name === snap.selectedSchemaName)
+ const isLocked = protectedSchemas.some((s) => s.id === selectedSchema?.id)
const { data: policies } = useDatabasePoliciesQuery({
projectRef: project?.ref,