Skip to content

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

refactor: convert auth policy components into typescript

Joshen Lim9f0f35ba060e
diff --git a/studio/components/to-be-cleaned/Auth/policyHelpers.js b/studio/components/interfaces/Authentication/Policies/Policies.utils.ts
similarity index 90%
rename from studio/components/to-be-cleaned/Auth/policyHelpers.js
rename to studio/components/interfaces/Authentication/Policies/Policies.utils.ts
index 14f5717509b..c91cd30f9e1 100644
--- a/studio/components/to-be-cleaned/Auth/policyHelpers.js
+++ b/studio/components/interfaces/Authentication/Policies/Policies.utils.ts
@@ -5,7 +5,7 @@ import { has, isEmpty, isEqual } from 'lodash'
* @param {*} policyFormFields { name, using, check, command }
*/
-export const createSQLPolicy = (policyFormFields, originalPolicyFormFields = {}) => {
+export const createSQLPolicy = (policyFormFields: any, originalPolicyFormFields: any = {}) => {
const { definition, check } = policyFormFields
const formattedPolicyFormFields = {
...policyFormFields,
@@ -23,7 +23,7 @@ export const createSQLPolicy = (policyFormFields, originalPolicyFormFields = {})
}
// Extract out all the fields that updated
- const fieldsToUpdate = {}
+ const fieldsToUpdate: any = {}
if (!isEqual(formattedPolicyFormFields.name, originalPolicyFormFields.name)) {
fieldsToUpdate.name = formattedPolicyFormFields.name
}
@@ -41,7 +41,7 @@ export const createSQLPolicy = (policyFormFields, originalPolicyFormFields = {})
return { description: 'hello', statement: 'hello' }
}
-export const createSQLStatementForCreatePolicy = (policyFormFields) => {
+export const createSQLStatementForCreatePolicy = (policyFormFields: any) => {
const { name, definition, check, command, schema, table } = policyFormFields
const description = `Add policy for the ${command} operation under the policy "${name}"`
const statement =
@@ -55,7 +55,10 @@ export const createSQLStatementForCreatePolicy = (policyFormFields) => {
return { description, statement }
}
-export const createSQLStatementForUpdatePolicy = (policyFormFields = {}, fieldsToUpdate = {}) => {
+export const createSQLStatementForUpdatePolicy = (
+ policyFormFields: any = {},
+ fieldsToUpdate: any = {}
+) => {
const { name, schema, table } = policyFormFields
const definitionChanged = has(fieldsToUpdate, ['definition'])
@@ -94,7 +97,7 @@ export const createSQLStatementForUpdatePolicy = (policyFormFields = {}, fieldsT
return { description, statement }
}
-export const createPayloadForCreatePolicy = (policyFormFields = {}) => {
+export const createPayloadForCreatePolicy = (policyFormFields: any = {}) => {
const { definition, check } = policyFormFields
return {
...policyFormFields,
@@ -105,8 +108,8 @@ export const createPayloadForCreatePolicy = (policyFormFields = {}) => {
}
export const createPayloadForUpdatePolicy = (
- policyFormFields = {},
- originalPolicyFormFields = {}
+ policyFormFields: any = {},
+ originalPolicyFormFields: any = {}
) => {
const { definition, check } = policyFormFields
const formattedPolicyFormFields = {
@@ -115,7 +118,7 @@ export const createPayloadForUpdatePolicy = (
check: check ? check.replace(/\s+/g, ' ').trim() : check,
}
- const payload = { id: originalPolicyFormFields.id }
+ const payload: any = { id: originalPolicyFormFields.id }
if (!isEqual(formattedPolicyFormFields.name, originalPolicyFormFields.name)) {
payload.name = formattedPolicyFormFields.name
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyAllowedOperation.tsx b/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyAllowedOperation.tsx
new file mode 100644
index 00000000000..fc6adc8ac6e
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyAllowedOperation.tsx
@@ -0,0 +1,63 @@
+import { FC } from 'react'
+import { Radio } from '@supabase/ui'
+
+interface Props {
+ operation: string
+ onSelectOperation: (operation: string) => void
+}
+
+const PolicyAllowedOperation: FC<Props> = ({ operation = '', onSelectOperation }) => {
+ return (
+ <div className="flex justify-between space-x-12">
+ <div className="flex w-1/3 flex-col space-y-2">
+ <label className="text-scale-1100 text-base" htmlFor="allowed-operation">
+ Allowed operation
+ </label>
+ <p className="text-scale-900 text-sm">Selection an operation for this policy</p>
+ </div>
+ <div className="w-2/3">
+ <div className="flex items-center space-x-8">
+ <Radio.Group type="small-cards" id="allowed-operation">
+ <Radio
+ name="allowed-operation"
+ label="SELECT"
+ value="SELECT"
+ checked={operation === 'SELECT'}
+ onChange={(e) => onSelectOperation(e.target.value)}
+ />
+ <Radio
+ name="allowed-operation"
+ label="INSERT"
+ value="INSERT"
+ checked={operation === 'INSERT'}
+ onChange={(e) => onSelectOperation(e.target.value)}
+ />
+ <Radio
+ name="allowed-operation"
+ label="UPDATE"
+ value="UPDATE"
+ checked={operation === 'UPDATE'}
+ onChange={(e) => onSelectOperation(e.target.value)}
+ />
+ <Radio
+ name="allowed-operation"
+ label="DELETE"
+ value="DELETE"
+ checked={operation === 'DELETE'}
+ onChange={(e) => onSelectOperation(e.target.value)}
+ />
+ <Radio
+ name="allowed-operation"
+ label="ALL"
+ value="ALL"
+ checked={operation === 'ALL'}
+ onChange={(e) => onSelectOperation(e.target.value)}
+ />
+ </Radio.Group>
+ </div>
+ </div>
+ </div>
+ )
+}
+
+export default PolicyAllowedOperation
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyDefinition.tsx b/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyDefinition.tsx
new file mode 100644
index 00000000000..bb3e3033939
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyDefinition.tsx
@@ -0,0 +1,67 @@
+import { FC, useEffect } from 'react'
+import { usePrevious } from 'hooks'
+
+import SqlEditor from 'components/to-be-cleaned/SqlEditor'
+
+interface Props {
+ operation: string
+ definition: string
+ check: string
+ onUpdatePolicyUsing: (using: string | null) => void
+ onUpdatePolicyCheck: (check: string | null) => void
+}
+
+const PolicyDefinition: FC<Props> = ({
+ operation = '',
+ definition = '',
+ check = '',
+ onUpdatePolicyUsing,
+ onUpdatePolicyCheck,
+}) => {
+ const showUsing = (operation: string) =>
+ ['SELECT', 'UPDATE', 'DELETE', 'ALL'].includes(operation) || !operation
+ const showCheck = (operation: string) => ['INSERT', 'UPDATE', 'ALL'].includes(operation)
+
+ const previousOperation = usePrevious(operation) || ''
+ useEffect(() => {
+ if (showUsing(previousOperation) && !showUsing(operation)) onUpdatePolicyUsing(null)
+ if (showCheck(previousOperation) && !showCheck(operation)) onUpdatePolicyCheck(null)
+ }, [operation])
+
+ return (
+ <div className="space-y-4">
+ {showUsing(operation) && (
+ <div className="flex space-x-12">
+ <div className="flex w-1/3 flex-col space-y-2">
+ <label className="text-scale-1100 text-base" htmlFor="policy-name">
+ USING expression
+ </label>
+ <p className="text-scale-900 text-sm">
+ Provide a SQL conditional expression that returns a boolean.
+ </p>
+ </div>
+ <div className={`w-2/3 ${showCheck(operation) ? 'h-32' : 'h-56'}`}>
+ <SqlEditor defaultValue={definition} onInputChange={onUpdatePolicyUsing} />
+ </div>
+ </div>
+ )}
+ {showCheck(operation) && (
+ <div className="flex space-x-12">
+ <div className="flex w-1/3 flex-col space-y-2">
+ <label className="text-scale-1100 text-base" htmlFor="policy-name">
+ WITH CHECK expression
+ </label>
+ <p className="text-scale-900 text-sm">
+ Provide a SQL conditional expression that returns a boolean.
+ </p>
+ </div>
+ <div className={`w-2/3 ${showUsing(operation) ? 'h-32' : 'h-56'}`}>
+ <SqlEditor defaultValue={check} onInputChange={onUpdatePolicyCheck} />
+ </div>
+ </div>
+ )}
+ </div>
+ )
+}
+
+export default PolicyDefinition
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyEditorFooter.tsx b/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyEditorFooter.tsx
new file mode 100644
index 00000000000..40ddc535b7f
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyEditorFooter.tsx
@@ -0,0 +1,23 @@
+import { FC } from 'react'
+import { Button } from '@supabase/ui'
+
+interface Props {
+ showTemplates: boolean
+ onViewTemplates: () => void
+ onReviewPolicy: () => void
+}
+
+const PolicyEditorFooter: FC<Props> = ({ showTemplates, onViewTemplates, onReviewPolicy }) => (
+ <div className="dark:border-dark flex w-full items-center justify-end gap-2 border-t px-6 py-4">
+ {showTemplates && (
+ <Button type="default" onClick={onViewTemplates}>
+ View templates
+ </Button>
+ )}
+ <Button type="primary" onClick={onReviewPolicy}>
+ Review
+ </Button>
+ </div>
+)
+
+export default PolicyEditorFooter
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyName.tsx b/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyName.tsx
new file mode 100644
index 00000000000..ec447d1f8b5
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyEditor/PolicyName.tsx
@@ -0,0 +1,30 @@
+import { FC } from 'react'
+import { Input } from '@supabase/ui'
+
+interface Props {
+ name: string
+ onUpdatePolicyName: (name: string) => void
+}
+
+const PolicyName: FC<Props> = ({ name = '', onUpdatePolicyName }) => {
+ return (
+ <div className="flex space-x-12">
+ <div className="flex w-1/3 flex-col space-y-2">
+ <label className="text-scale-1100 text-base" htmlFor="policy-name">
+ Policy name
+ </label>
+ <p className="text-scale-900 text-sm">A descriptive name for your policy</p>
+ </div>
+ <div className="relative w-2/3">
+ <Input
+ id="policy-name"
+ value={name}
+ onChange={(e) => onUpdatePolicyName(e.target.value)}
+ actions={<span className="text-scale-900 mr-3 text-sm">{name.length}/63</span>}
+ />
+ </div>
+ </div>
+ )
+}
+
+export default PolicyName
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyEditor/index.tsx b/studio/components/interfaces/Authentication/Policies/PolicyEditor/index.tsx
new file mode 100644
index 00000000000..369f421741f
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyEditor/index.tsx
@@ -0,0 +1,71 @@
+import { FC } from 'react'
+import { Modal } from '@supabase/ui'
+import { get } from 'lodash'
+
+import PolicyName from './PolicyName'
+import PolicyDefinition from './PolicyDefinition'
+import PolicyAllowedOperation from './PolicyAllowedOperation'
+import PolicyEditorFooter from './PolicyEditorFooter'
+
+interface Props {
+ isNewPolicy: boolean
+ policyFormFields: any
+ onUpdatePolicyFormFields: (value: any) => void
+ onViewTemplates: () => void
+ onReviewPolicy: () => void
+}
+
+const PolicyEditor: FC<Props> = ({
+ isNewPolicy = true,
+ policyFormFields = {},
+ onUpdatePolicyFormFields = () => {},
+ onViewTemplates = () => {},
+ onReviewPolicy = () => {},
+}) => {
+ const operation = get(policyFormFields, ['command'], '')
+ const definition = get(policyFormFields, ['definition'], '') || ''
+ const check = get(policyFormFields, ['check'], '') || ''
+
+ return (
+ <div className="">
+ <div className="mb-8 space-y-8 py-8">
+ <Modal.Content>
+ <PolicyName
+ name={policyFormFields.name}
+ onUpdatePolicyName={(name) => onUpdatePolicyFormFields({ name })}
+ />
+ </Modal.Content>
+ <Modal.Seperator />
+ {isNewPolicy && (
+ <>
+ <Modal.Content>
+ <PolicyAllowedOperation
+ operation={operation}
+ onSelectOperation={(command) => onUpdatePolicyFormFields({ command })}
+ />
+ </Modal.Content>
+ <Modal.Seperator />
+ </>
+ )}
+ <Modal.Content>
+ <PolicyDefinition
+ operation={operation}
+ definition={definition}
+ check={check}
+ onUpdatePolicyUsing={(definition: string | null) =>
+ onUpdatePolicyFormFields({ definition })
+ }
+ onUpdatePolicyCheck={(check: string | null) => onUpdatePolicyFormFields({ check })}
+ />
+ </Modal.Content>
+ </div>
+ <PolicyEditorFooter
+ showTemplates={isNewPolicy}
+ onViewTemplates={onViewTemplates}
+ onReviewPolicy={onReviewPolicy}
+ />
+ </div>
+ )
+}
+
+export default PolicyEditor
diff --git a/studio/components/to-be-cleaned/Auth/PolicyEditorModal.constants.js b/studio/components/interfaces/Authentication/Policies/PolicyEditorModal/PolicyEditorModal.constants.ts
similarity index 97%
rename from studio/components/to-be-cleaned/Auth/PolicyEditorModal.constants.js
rename to studio/components/interfaces/Authentication/Policies/PolicyEditorModal/PolicyEditorModal.constants.ts
index a8ab19cf67f..2deaed5dded 100644
--- a/studio/components/to-be-cleaned/Auth/PolicyEditorModal.constants.js
+++ b/studio/components/interfaces/Authentication/Policies/PolicyEditorModal/PolicyEditorModal.constants.ts
@@ -13,7 +13,7 @@
* command: Operation to create policy for
*/
-export const getGeneralPolicyTemplates = (schema, table) => [
+export const getGeneralPolicyTemplates = (schema: string, table: string) => [
{
id: 'policy-1',
templateName: 'Enable read access to everyone',
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyEditorModal/PolicyEditorModalTitle.tsx b/studio/components/interfaces/Authentication/Policies/PolicyEditorModal/PolicyEditorModalTitle.tsx
new file mode 100644
index 00000000000..30a0b38f4dd
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyEditorModal/PolicyEditorModalTitle.tsx
@@ -0,0 +1,50 @@
+import { FC } from 'react'
+import { IconChevronLeft } from '@supabase/ui'
+import { POLICY_MODAL_VIEWS } from 'lib/constants'
+
+interface Props {
+ view: string
+ schema: string
+ table: string
+ isNewPolicy: boolean
+ onSelectBackFromTemplates: () => void
+}
+
+const PolicyEditorModalTitle: FC<Props> = ({
+ view,
+ schema,
+ table,
+ isNewPolicy,
+ onSelectBackFromTemplates = () => {},
+}) => {
+ const getTitle = () => {
+ if (view === POLICY_MODAL_VIEWS.EDITOR || view === POLICY_MODAL_VIEWS.SELECTION) {
+ return `${isNewPolicy ? 'Adding new policy to' : 'Editing policy from'} ${schema}.${table}`
+ }
+ if (view === POLICY_MODAL_VIEWS.REVIEW) {
+ return `Reviewing policy to be ${isNewPolicy ? 'created' : 'updated'} on ${schema}.${table}`
+ }
+ }
+ if (view === POLICY_MODAL_VIEWS.TEMPLATES) {
+ return (
+ <div className="">
+ <div className="flex items-center space-x-3">
+ <span
+ onClick={onSelectBackFromTemplates}
+ className="text-scale-900 hover:text-scale-1200 cursor-pointer transition-colors"
+ >
+ <IconChevronLeft strokeWidth={2} size={14} />
+ </span>
+ <h4 className="m-0 text-lg">Select a template to use for your new policy</h4>
+ </div>
+ </div>
+ )
+ }
+ return (
+ <div className="flex items-center space-x-3">
+ <h4 className="m-0 text-lg">{getTitle()}</h4>
+ </div>
+ )
+}
+
+export default PolicyEditorModalTitle
diff --git a/studio/components/to-be-cleaned/Auth/PolicyEditorModal.js b/studio/components/interfaces/Authentication/Policies/PolicyEditorModal/index.tsx
similarity index 75%
rename from studio/components/to-be-cleaned/Auth/PolicyEditorModal.js
rename to studio/components/interfaces/Authentication/Policies/PolicyEditorModal/index.tsx
index 8d63f803947..7c362ed956a 100644
--- a/studio/components/to-be-cleaned/Auth/PolicyEditorModal.js
+++ b/studio/components/interfaces/Authentication/Policies/PolicyEditorModal/index.tsx
@@ -1,5 +1,5 @@
-import { Modal, Typography, IconChevronLeft } from '@supabase/ui'
-import { useState, useEffect } from 'react'
+import { Modal } from '@supabase/ui'
+import { FC, useState, useEffect } from 'react'
import { isEmpty } from 'lodash'
import { POLICY_MODAL_VIEWS } from 'lib/constants'
@@ -8,56 +8,27 @@ import {
createSQLPolicy,
createPayloadForCreatePolicy,
createPayloadForUpdatePolicy,
-} from './policyHelpers'
+} from '../Policies.utils'
-import PolicySelection from './PolicySelection'
-import PolicyEditor from './PolicyEditor'
-import PolicyReview from './PolicyReview'
-import PolicyTemplates from './PolicyTemplates'
+import PolicyEditorModalTitle from './PolicyEditorModalTitle'
+import PolicySelection from '../PolicySelection'
+import PolicyEditor from '../PolicyEditor'
+import PolicyReview from '../PolicyReview'
+import PolicyTemplates from '../PolicyTemplates'
import { useStore } from 'hooks'
-const PolicyEditorModalTitle = ({
- view,
- schema,
- table,
- isNewPolicy,
- onSelectBackFromTemplates = () => {},
-}) => {
- const getTitle = () => {
- if (view === POLICY_MODAL_VIEWS.EDITOR || view === POLICY_MODAL_VIEWS.SELECTION) {
- return `${isNewPolicy ? 'Adding new policy to' : 'Editing policy from'} ${schema}.${table}`
- }
- if (view === POLICY_MODAL_VIEWS.REVIEW) {
- return `Reviewing policy to be ${isNewPolicy ? 'created' : 'updated'} on ${schema}.${table}`
- }
- }
- if (view === POLICY_MODAL_VIEWS.TEMPLATES) {
- return (
- <div className="">
- <div className="flex items-center space-x-3">
- <span
- onClick={onSelectBackFromTemplates}
- className="cursor-pointer text-scale-900 hover:text-scale-1200 transition-colors"
- >
- <IconChevronLeft strokeWidth={2} size={14} />
- </span>
- <Typography.Title level={4} className="m-0">
- Select a template to use for your new policy
- </Typography.Title>
- </div>
- </div>
- )
- }
- return (
- <div className="flex items-center space-x-3">
- <Typography.Title level={4} className="m-0">
- {getTitle()}
- </Typography.Title>
- </div>
- )
+interface Props {
+ visible: boolean
+ schema: string
+ table: string
+ selectedPolicyToEdit: any
+ onSelectCancel: () => void
+ onCreatePolicy: (payload: any) => boolean
+ onUpdatePolicy: (payload: any) => boolean
+ onSaveSuccess: () => void
}
-const PolicyEditorModal = ({
+const PolicyEditorModal: FC<Props> = ({
visible = false,
schema = '',
table = '',
@@ -85,7 +56,7 @@ const PolicyEditorModal = ({
const [view, setView] = useState(POLICY_MODAL_VIEWS.EDITOR)
const [policyFormFields, setPolicyFormFields] = useState(initializedPolicyFormFields)
- const [policyStatementForReview, setPolicyStatementForReview] = useState('')
+ const [policyStatementForReview, setPolicyStatementForReview] = useState<any>('')
useEffect(() => {
if (visible) {
@@ -109,7 +80,7 @@ const PolicyEditorModal = ({
const onReviewPolicy = () => setView(POLICY_MODAL_VIEWS.REVIEW)
const onSelectBackFromTemplates = () => setView(previousView)
- const onUseTemplate = (template) => {
+ const onUseTemplate = (template: any) => {
setPolicyFormFields({
...policyFormFields,
name: template.name,
@@ -120,7 +91,7 @@ const PolicyEditorModal = ({
onViewEditor()
}
- const onUpdatePolicyFormFields = (field) => {
+ const onUpdatePolicyFormFields = (field: any) => {
if (field.name && field.name.length > 63) return
setPolicyFormFields({ ...policyFormFields, ...field })
}
@@ -168,7 +139,7 @@ const PolicyEditorModal = ({
onSavePolicy(payload)
}
- const onSavePolicy = async (payload) => {
+ const onSavePolicy = async (payload: any) => {
const hasError = isNewPolicy ? await onCreatePolicy(payload) : await onUpdatePolicy(payload)
hasError ? onViewEditor() : onSaveSuccess()
}
@@ -212,7 +183,6 @@ const PolicyEditorModal = ({
<PolicyTemplates
templates={getGeneralPolicyTemplates(schema, table)}
templatesNote="* References a specific column in the table"
- onSelectBackFromTemplates={onSelectBackFromTemplates}
onUseTemplate={onUseTemplate}
/>
) : view === POLICY_MODAL_VIEWS.REVIEW ? (
diff --git a/studio/components/to-be-cleaned/Auth/PolicyReview.js b/studio/components/interfaces/Authentication/Policies/PolicyReview.tsx
similarity index 62%
rename from studio/components/to-be-cleaned/Auth/PolicyReview.js
rename to studio/components/interfaces/Authentication/Policies/PolicyReview.tsx
index d36bf94874f..e84fed3a385 100644
--- a/studio/components/to-be-cleaned/Auth/PolicyReview.js
+++ b/studio/components/interfaces/Authentication/Policies/PolicyReview.tsx
@@ -1,18 +1,19 @@
import { Button, Modal } from '@supabase/ui'
import { isEmpty } from 'lodash'
-import { useState } from 'react'
+import { FC, useState } from 'react'
+import SqlEditor from 'components/to-be-cleaned/SqlEditor'
-import SqlEditor from '../SqlEditor'
-
-const ReviewEmptyState = () => {
- return (
- <div className="flex items-center justify-center my-10 opacity-50 space-x-2">
- <p className="text-base text-scale-1100">There are no changes made to this policy</p>
- </div>
- )
+interface Props {
+ policy: any
+ onSelectBack: () => void
+ onSelectSave: () => void
}
-const PolicyReview = ({ policy = {}, onSelectBack = () => {}, onSelectSave = () => {} }) => {
+const PolicyReview: FC<Props> = ({
+ policy = {},
+ onSelectBack = () => {},
+ onSelectSave = () => {},
+}) => {
const [isSaving, setIsSaving] = useState(false)
const onSavePolicy = () => {
setIsSaving(true)
@@ -25,16 +26,20 @@ const PolicyReview = ({ policy = {}, onSelectBack = () => {}, onSelectSave = ()
<>
<Modal.Content>
<div className="space-y-6 py-8">
- <div className="space-y-8 flex items-center justify-between">
+ <div className="flex items-center justify-between space-y-8">
<div className="flex flex-col">
- <p className="text-sm text-scale-1100">
+ <p className="text-scale-1100 text-sm">
This is the SQL statement that will be used to create your policy.
</p>
</div>
</div>
<div className="space-y-4 overflow-y-auto" style={{ maxHeight: '25rem' }}>
{isEmpty(policy) ? (
- <ReviewEmptyState />
+ <div className="my-10 flex items-center justify-center space-x-2 opacity-50">
+ <p className="text-scale-1100 text-base">
+ There are no changes made to this policy
+ </p>
+ </div>
) : (
<div className="space-y-2">
<span>{policy.description}</span>
@@ -46,7 +51,7 @@ const PolicyReview = ({ policy = {}, onSelectBack = () => {}, onSelectSave = ()
</div>
</div>
</Modal.Content>
- <div className="px-6 py-4 w-full flex justify-end items-center gap-2 border-t dark:border-dark">
+ <div className="dark:border-dark flex w-full items-center justify-end gap-2 border-t px-6 py-4">
<Button type="default" onClick={onSelectBack}>
Back to edit
</Button>
diff --git a/studio/components/to-be-cleaned/Auth/PolicySelection.js b/studio/components/interfaces/Authentication/Policies/PolicySelection.tsx
similarity index 68%
rename from studio/components/to-be-cleaned/Auth/PolicySelection.js
rename to studio/components/interfaces/Authentication/Policies/PolicySelection.tsx
index dc50a96a99d..edac0beb8bd 100644
--- a/studio/components/to-be-cleaned/Auth/PolicySelection.js
+++ b/studio/components/interfaces/Authentication/Policies/PolicySelection.tsx
@@ -1,62 +1,63 @@
+import { FC } from 'react'
import { IconEdit, IconGrid, Modal } from '@supabase/ui'
import CardButton from 'components/ui/CardButton'
-const PolicySelection = ({
+interface Props {
+ description: string
+ onViewTemplates: () => void
+ onViewEditor: () => void
+}
+
+const PolicySelection: FC<Props> = ({
description = '',
onViewTemplates = () => {},
onViewEditor = () => {},
}) => {
return (
<Modal.Content>
- <div className="py-8 space-y-6">
+ <div className="space-y-6 py-8">
<div>
- <p className="text-sm text-scale-1100">{description}</p>
+ <p className="text-scale-1100 text-sm">{description}</p>
</div>
- <div className="grid grid-cols-1 lg:grid-cols-1 gap-2">
+ <div className="grid grid-cols-1 gap-2 lg:grid-cols-1">
<CardButton
- hoverable
- className="cursor-pointer py-4"
- onClick={onViewTemplates}
- // imgUrl={'/img/policy-template.svg'}
title="Get started quickly"
description="Create a policy from a template"
icon={
<div className="flex">
<div
className="
- w-8 h-8 bg-scale-1200 text-scale-100
- rounded
- flex items-center justify-center
+ bg-scale-1200 text-scale-100 flex h-8
+ w-8
+ items-center justify-center rounded
"
>
<IconGrid size={14} strokeWidth={2} />
</div>
</div>
}
+ onClick={onViewTemplates}
/>
-
<CardButton
- hoverable
- className="cursor-pointer py-4"
- onClick={onViewEditor}
title="For full customization"
description="Create a policy from scratch"
icon={
<div className="flex">
<div
className="
- w-8 h-8 bg-scale-1200 text-scale-100
- rounded
- flex items-center justify-center
+ bg-scale-1200 text-scale-100 flex h-8
+ w-8
+ items-center justify-center rounded
"
>
<IconEdit size={14} strokeWidth={2} />
</div>
</div>
}
+ onClick={onViewEditor}
/>
</div>
- <p className="text-sm text-scale-1100">
+ <p className="text-scale-1100 text-sm">
Not sure what policies are? Check out our resources{' '}
<a
target="_blank"
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyRow.tsx b/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyRow.tsx
new file mode 100644
index 00000000000..96773f1a4e2
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyRow.tsx
@@ -0,0 +1,69 @@
+import { FC } from 'react'
+import { Button, Dropdown, IconEdit, IconTrash, IconMoreVertical } from '@supabase/ui'
+import Panel from 'components/to-be-cleaned/Panel'
+
+interface Props {
+ policy: any
+ onSelectEditPolicy: (policy: any) => void
+ onSelectDeletePolicy: (policy: any) => void
+}
+
+const PolicyRow: FC<Props> = ({
+ policy = {},
+ onSelectEditPolicy = () => {},
+ onSelectDeletePolicy = () => {},
+}) => {
+ return (
+ <Panel.Content
+ className="
+ border-panel-border-light
+ dark:border-panel-border-dark flex
+ w-full
+ gap-2
+ border-b
+ py-4
+ lg:items-center
+ "
+ >
+ <div className="text-scale-900 font-mono text-xs">{policy.command}</div>
+ <div className="flex grow flex-col gap-2 truncate lg:flex-row">
+ <span className="text-scale-1200 max-w-xs truncate text-sm">{policy.name}</span>
+ <span className="text-scale-1100 truncate text-sm">
+ {policy.definition || policy.check}
+ </span>
+ </div>
+ <div className="">
+ <Dropdown
+ side="bottom"
+ align="end"
+ size="small"
+ overlay={
+ <>
+ <Dropdown.Item
+ icon={<IconEdit size={14} />}
+ onClick={() => onSelectEditPolicy(policy)}
+ >
+ Edit
+ </Dropdown.Item>
+ <Dropdown.Seperator />
+ <Dropdown.Item
+ icon={<IconTrash size={14} />}
+ onClick={() => onSelectDeletePolicy(policy)}
+ >
+ Delete
+ </Dropdown.Item>
+ </>
+ }
+ >
+ <Button
+ type="default"
+ style={{ paddingLeft: 4, paddingRight: 4 }}
+ icon={<IconMoreVertical />}
+ />
+ </Dropdown>
+ </div>
+ </Panel.Content>
+ )
+}
+
+export default PolicyRow
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyTableRowHeader.tsx b/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyTableRowHeader.tsx
new file mode 100644
index 00000000000..07d555878a4
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyTableRowHeader.tsx
@@ -0,0 +1,39 @@
+import { FC } from 'react'
+import { Badge, Button } from '@supabase/ui'
+
+interface Props {
+ table: any
+ onSelectToggleRLS: (table: any) => void
+ onSelectCreatePolicy: (table: any) => void
+}
+
+const PolicyTableRowHeader: FC<Props> = ({
+ table = {},
+ onSelectToggleRLS = () => {},
+ onSelectCreatePolicy = () => {},
+}) => {
+ return (
+ <div className="flex w-full items-center justify-between">
+ <div className="flex space-x-4 text-left">
+ <h4 className="m-0 text-lg">
+ <span>{table.name}</span>
+ </h4>
+ <Badge color={table.rls_enabled ? 'green' : 'yellow'}>
+ {table.rls_enabled ? 'RLS enabled' : 'RLS disabled'}
+ </Badge>
+ </div>
+ <div className="flex-1">
+ <div className="flex flex-row-reverse">
+ <Button type="outline" className="ml-2" onClick={() => onSelectCreatePolicy(table)}>
+ New Policy
+ </Button>
+ <Button type="default" onClick={() => onSelectToggleRLS(table)}>
+ {table.rls_enabled ? 'Disable RLS' : 'Enable RLS'}
+ </Button>
+ </div>
+ </div>
+ </div>
+ )
+}
+
+export default PolicyTableRowHeader
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyTableRow/index.tsx b/studio/components/interfaces/Authentication/Policies/PolicyTableRow/index.tsx
new file mode 100644
index 00000000000..2bd1284456d
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyTableRow/index.tsx
@@ -0,0 +1,50 @@
+import { FC } from 'react'
+
+import PolicyTableRowHeader from './PolicyTableRowHeader'
+import PolicyRow from './PolicyRow'
+import Panel from 'components/to-be-cleaned/Panel'
+
+interface Props {
+ table: any
+ onSelectToggleRLS: (table: any) => void
+ onSelectCreatePolicy: () => void
+ onSelectEditPolicy: (policy: any) => void
+ onSelectDeletePolicy: (policy: any) => void
+}
+
+const PolicyTableRow: FC<Props> = ({
+ table = {},
+ onSelectToggleRLS = () => {},
+ onSelectCreatePolicy = () => {},
+ onSelectEditPolicy = () => {},
+ onSelectDeletePolicy = () => {},
+}) => {
+ return (
+ <Panel
+ title={
+ <PolicyTableRowHeader
+ table={table}
+ onSelectToggleRLS={onSelectToggleRLS}
+ onSelectCreatePolicy={onSelectCreatePolicy}
+ />
+ }
+ >
+ {table.policies.length === 0 && (
+ <div className="p-4 px-6">
+ <p className="text-scale-900 text-sm">No policies created yet</p>
+ </div>
+ )}
+
+ {table.policies.map((policy: any) => (
+ <PolicyRow
+ key={policy.id}
+ policy={policy}
+ onSelectEditPolicy={onSelectEditPolicy}
+ onSelectDeletePolicy={onSelectDeletePolicy}
+ />
+ ))}
+ </Panel>
+ )
+}
+
+export default PolicyTableRow
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyTemplates/TemplatePreview.tsx b/studio/components/interfaces/Authentication/Policies/PolicyTemplates/TemplatePreview.tsx
new file mode 100644
index 00000000000..b882a6f84b8
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyTemplates/TemplatePreview.tsx
@@ -0,0 +1,35 @@
+import { FC } from 'react'
+import { isEmpty } from 'lodash'
+import SqlEditor from 'components/to-be-cleaned/SqlEditor'
+
+interface Props {
+ selectedTemplate: any
+}
+
+const TemplatePreview: FC<Props> = ({ selectedTemplate = {} }) => {
+ const { id, templateName, description, statement } = selectedTemplate
+ return (
+ <div className="space-y-8" style={{ width: '70%' }}>
+ {!isEmpty(selectedTemplate) && (
+ <div className="flex h-full flex-col justify-between">
+ <div className="my-5 h-full space-y-6 px-6">
+ <div className="space-y-2">
+ <div className="flex flex-col space-y-2">
+ <h3 className="text-scale-1200 text-base">{templateName}</h3>
+ <p className="text-scale-1100 text-sm">{description}</p>
+ </div>
+ </div>
+ <div className="space-y-2">
+ <label className="text-scale-1100 text-sm">Policy SQL template:</label>
+ <div className="h-64">
+ <SqlEditor readOnly queryId={id} defaultValue={statement} />
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
+ )
+}
+
+export default TemplatePreview
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyTemplates/TemplatesList.tsx b/studio/components/interfaces/Authentication/Policies/PolicyTemplates/TemplatesList.tsx
new file mode 100644
index 00000000000..268dfa8c030
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyTemplates/TemplatesList.tsx
@@ -0,0 +1,52 @@
+import { FC } from 'react'
+import { Menu } from '@supabase/ui'
+
+interface Props {
+ templates: any[]
+ templatesNote: string
+ selectedTemplate: any
+ setSelectedTemplate: (template: any) => void
+}
+
+const TemplatesList: FC<Props> = ({
+ templates = [],
+ templatesNote = '',
+ selectedTemplate = {},
+ setSelectedTemplate = () => {},
+}) => (
+ <div className="dark:border-dark flex flex-col justify-between border-r" style={{ width: '30%' }}>
+ <div
+ className="hide-scrollbar divide-border-primary space-y-0 divide-y divide-solid overflow-y-auto"
+ style={{ maxHeight: '24rem' }}
+ >
+ <Menu type="border">
+ {templates.map((template) => {
+ const active = selectedTemplate === template
+ return (
+ <div
+ className={
+ 'hover:bg-scale-400 border-scale-400 border-b ' +
+ (active ? 'bg-scale-300 dark:bg-scale-500' : '')
+ }
+ >
+ <Menu.Item
+ key={template.id}
+ active={active}
+ onClick={() => setSelectedTemplate(template)}
+ >
+ <div className="truncate py-2">{template.templateName}</div>
+ </Menu.Item>
+ </div>
+ )
+ })}
+ </Menu>
+ </div>
+ {templatesNote && (
+ <div className="px-4 py-2">
+ <p className="text-scale-900 text-xs">{templatesNote}</p>
+ </div>
+ )}
+ </div>
+)
+
+export default TemplatesList
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyTemplates/index.tsx b/studio/components/interfaces/Authentication/Policies/PolicyTemplates/index.tsx
new file mode 100644
index 00000000000..2c3748a66a1
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/PolicyTemplates/index.tsx
@@ -0,0 +1,47 @@
+import { Button } from '@supabase/ui'
+import { FC, useState } from 'react'
+import { isEmpty } from 'lodash'
+
+import TemplatesList from './TemplatesList'
+import TemplatePreview from './TemplatePreview'
+
+interface Props {
+ templates: any[]
+ templatesNote: string
+ onUseTemplate: (template: any) => void
+}
+
+const PolicyTemplates: FC<Props> = ({
+ templates = [],
+ templatesNote = '',
+ onUseTemplate = () => {},
+}) => {
+ const [selectedTemplate, setSelectedTemplate] = useState(templates[0])
+ return (
+ <div>
+ <div className="dark:border-dark flex justify-between border-t">
+ <TemplatesList
+ templatesNote={templatesNote}
+ templates={templates}
+ selectedTemplate={selectedTemplate}
+ setSelectedTemplate={setSelectedTemplate}
+ />
+ <TemplatePreview selectedTemplate={selectedTemplate} />
+ </div>
+ <div className="dark:border-dark flex w-full items-center justify-end gap-3 border-t px-6 py-4">
+ <span className="text-scale-900 text-sm">
+ This will override any existing code you've written
+ </span>
+ <Button
+ type="primary"
+ disabled={isEmpty(selectedTemplate)}
+ onClick={() => onUseTemplate(selectedTemplate)}
+ >
+ Use this template
+ </Button>
+ </div>
+ </div>
+ )
+}
+
+export default PolicyTemplates
diff --git a/studio/components/interfaces/Authentication/Policies/index.tsx b/studio/components/interfaces/Authentication/Policies/index.tsx
new file mode 100644
index 00000000000..0689bf7657c
--- /dev/null
+++ b/studio/components/interfaces/Authentication/Policies/index.tsx
@@ -0,0 +1,6 @@
+import PolicyEditorModal from './PolicyEditorModal'
+import PolicyTableRow from './PolicyTableRow'
+import PolicySelection from './PolicySelection'
+import PolicyTemplates from './PolicyTemplates'
+
+export { PolicyEditorModal, PolicyTableRow, PolicySelection, PolicyTemplates }
diff --git a/studio/components/to-be-cleaned/Auth/PolicyEditor.js b/studio/components/to-be-cleaned/Auth/PolicyEditor.js
deleted file mode 100644
index b45182a5d0d..00000000000
--- a/studio/components/to-be-cleaned/Auth/PolicyEditor.js
+++ /dev/null
@@ -1,206 +0,0 @@
-import { Button, Typography, Input, Radio, Modal } from '@supabase/ui'
-import { get } from 'lodash'
-import { useEffect } from 'react'
-
-import { usePrevious } from 'hooks'
-import SqlEditor from '../SqlEditor'
-
-const PolicyName = ({ name = '', onUpdatePolicyName = () => {} }) => {
- return (
- <div className="flex space-x-12">
- <div className="w-1/3 flex flex-col space-y-2">
- <label className="text-base text-scale-1100" htmlFor="policy-name">
- Policy name
- </label>
- <p className="text-sm text-scale-900">A descriptive name for your policy</p>
- </div>
- <div className="w-2/3 relative">
- <Input
- id="policy-name"
- value={name}
- rows={1}
- limit={63}
- onChange={(e) => onUpdatePolicyName(e.target.value)}
- actions={<span className="text-sm text-scale-900 mr-3">{name.length}/63</span>}
- />
- </div>
- </div>
- )
-}
-
-const PolicyDefinition = ({
- operation = '',
- definition = '',
- check = '',
- onUpdatePolicyUsing = () => {},
- onUpdatePolicyCheck = () => {},
-}) => {
- const showUsing = (operation) =>
- ['SELECT', 'UPDATE', 'DELETE', 'ALL'].includes(operation) || !operation
- const showCheck = (operation) => ['INSERT', 'UPDATE', 'ALL'].includes(operation)
-
- const previousOperation = usePrevious(operation)
- useEffect(() => {
- if (showUsing(previousOperation) && !showUsing(operation)) onUpdatePolicyUsing(null)
- if (showCheck(previousOperation) && !showCheck(operation)) onUpdatePolicyCheck(null)
- }, [operation])
-
- return (
- <div className="space-y-4">
- {showUsing(operation) && (
- <div className="flex space-x-12">
- <div className="w-1/3 flex flex-col space-y-2">
- <label className="text-base text-scale-1100" htmlFor="policy-name">
- USING expression
- </label>
- <p className="text-sm text-scale-900">
- Provide a SQL conditional expression that returns a boolean.
- </p>
- </div>
- <div className={`w-2/3 ${showCheck(operation) ? 'h-32' : 'h-56'}`}>
- <SqlEditor defaultValue={definition} onInputChange={onUpdatePolicyUsing} />
- </div>
- </div>
- )}
- {showCheck(operation) && (
- <div className="flex space-x-12">
- <div className="w-1/3 flex flex-col space-y-2">
- <label className="text-base text-scale-1100" htmlFor="policy-name">
- WITH CHECK expression
- </label>
- <p className="text-sm text-scale-900">
- Provide a SQL conditional expression that returns a boolean.
- </p>
- </div>
- <div className={`w-2/3 ${showUsing(operation) ? 'h-32' : 'h-56'}`}>
- <SqlEditor defaultValue={check} onInputChange={onUpdatePolicyCheck} />
- </div>
- </div>
- )}
- </div>
- )
-}
-
-const PolicyAllowedOperation = ({ operation = '', onSelectOperation = () => {} }) => {
- return (
- <div className="flex justify-between space-x-12">
- <div className="w-1/3 flex flex-col space-y-2">
- <label className="text-base text-scale-1100" htmlFor="allowed-operation">
- Allowed operation
- </label>
- <p className="text-sm text-scale-900">Selection an operation for this policy</p>
- </div>
- <div className="w-2/3">
- <div className="flex items-center space-x-8">
- <Radio.Group type="small-cards" id="allowed-operation">
- <Radio
- name="allowed-operation"
- label="SELECT"
- value="SELECT"
- checked={operation === 'SELECT'}
- onChange={(e) => onSelectOperation(e.target.value)}
- />
- <Radio
- name="allowed-operation"
- label="INSERT"
- value="INSERT"
- checked={operation === 'INSERT'}
- onChange={(e) => onSelectOperation(e.target.value)}
- />
- <Radio
- name="allowed-operation"
- label="UPDATE"
- value="UPDATE"
- checked={operation === 'UPDATE'}
- onChange={(e) => onSelectOperation(e.target.value)}
- />
- <Radio
- name="allowed-operation"
- label="DELETE"
- value="DELETE"
- checked={operation === 'DELETE'}
- onChange={(e) => onSelectOperation(e.target.value)}
- />
- <Radio
- name="allowed-operation"
- label="ALL"
- value="ALL"
- checked={operation === 'ALL'}
- onChange={(e) => onSelectOperation(e.target.value)}
- />
- </Radio.Group>
- </div>
- </div>
- </div>
- )
-}
-
-const PolicyEditorFooter = ({
- showTemplates,
- onViewTemplates = () => {},
- onReviewPolicy = () => {},
-}) => (
- <div className="px-6 py-4 w-full flex justify-end items-center gap-2 border-t dark:border-dark">
- {showTemplates && (
- <Button type="default" onClick={onViewTemplates}>
- View templates
- </Button>
- )}
- <Button type="primary" onClick={onReviewPolicy}>
- Review
- </Button>
- </div>
-)
-
-const PolicyEditor = ({
- isNewPolicy = true,
- policyFormFields = {},
- onUpdatePolicyFormFields = () => {},
- onViewTemplates = () => {},
- onReviewPolicy = () => {},
-}) => {
- const operation = get(policyFormFields, ['command'], '')
- const definition = get(policyFormFields, ['definition'], '') || ''
- const check = get(policyFormFields, ['check'], '') || ''
-
- return (
- <div className="">
- <div className="py-8 space-y-8 mb-8">
- <Modal.Content>
- <PolicyName
- name={policyFormFields.name}
- onUpdatePolicyName={(name) => onUpdatePolicyFormFields({ name })}
- />
- </Modal.Content>
- <Modal.Seperator />
- {isNewPolicy && (
- <>
- <Modal.Content>
- <PolicyAllowedOperation
- operation={operation}
- onSelectOperation={(command) => onUpdatePolicyFormFields({ command })}
- />
- </Modal.Content>
- <Modal.Seperator />
- </>
- )}
- <Modal.Content>
- <PolicyDefinition
- operation={operation}
- definition={definition}
- check={check}
- onUpdatePolicyUsing={(definition) => onUpdatePolicyFormFields({ definition })}
- onUpdatePolicyCheck={(check) => onUpdatePolicyFormFields({ check })}
- />
- </Modal.Content>
- </div>
- <PolicyEditorFooter
- showTemplates={isNewPolicy}
- onViewTemplates={onViewTemplates}
- onReviewPolicy={onReviewPolicy}
- />
- </div>
- )
-}
-
-export default PolicyEditor
diff --git a/studio/components/to-be-cleaned/Auth/PolicyTableRow.js b/studio/components/to-be-cleaned/Auth/PolicyTableRow.js
deleted file mode 100644
index 46645e344e7..00000000000
--- a/studio/components/to-be-cleaned/Auth/PolicyTableRow.js
+++ /dev/null
@@ -1,136 +0,0 @@
-import {
- Badge,
- Button,
- Dropdown,
- IconEdit,
- IconMoreVertical,
- IconTrash,
- Typography,
-} from '@supabase/ui'
-import Panel from '../Panel'
-
-const PolicyTableRowHeader = ({
- table = {},
- onSelectToggleRLS = () => {},
- onSelectCreatePolicy = () => {},
-}) => {
- return (
- <div className="flex items-center justify-between w-full">
- <div className="flex space-x-4 text-left">
- <Typography.Title level={4} className="m-0">
- <span>{table.name}</span>
- </Typography.Title>
- <Badge color={table.rls_enabled ? 'green' : 'yellow'}>
- {table.rls_enabled ? 'RLS enabled' : 'RLS disabled'}
- </Badge>
- </div>
- <div className="flex-1">
- <div className="flex flex-row-reverse">
- <Button type="outline" className="ml-2" onClick={() => onSelectCreatePolicy(table)}>
- New Policy
- </Button>
- <Button type="default" onClick={() => onSelectToggleRLS(table)}>
- {table.rls_enabled ? 'Disable RLS' : 'Enable RLS'}
- </Button>
- </div>
- </div>
- </div>
- )
-}
-
-const PolicyRow = ({
- policy = {},
- onSelectEditPolicy = () => {},
- onSelectDeletePolicy = () => {},
-}) => {
- return (
- <Panel.Content
- className="
- w-full
- flex gap-2
- lg:items-center
- py-4
- border-b
- border-panel-border-light
- dark:border-panel-border-dark
- "
- >
- <div className="font-mono text-xs text-scale-900">{policy.command}</div>
- <div className="flex flex-col lg:flex-row gap-2 truncate grow">
- <span className="text-sm text-scale-1200 truncate max-w-xs">{policy.name}</span>
- <span className="text-sm text-scale-1100 truncate">
- {policy.definition || policy.check}
- </span>
- </div>
- <div className="">
- <Dropdown
- side="bottom"
- align="end"
- size="small"
- overlay={
- <>
- <Dropdown.Item
- icon={<IconEdit size={14} />}
- type="outline"
- onClick={() => onSelectEditPolicy(policy)}
- >
- Edit
- </Dropdown.Item>
- <Dropdown.Seperator />
- <Dropdown.Item
- icon={<IconTrash size={14} />}
- type="outline"
- onClick={() => onSelectDeletePolicy(policy)}
- >
- Delete
- </Dropdown.Item>
- </>
- }
- >
- <Button
- type="default"
- style={{ paddingLeft: 4, paddingRight: 4 }}
- icon={<IconMoreVertical />}
- />
- </Dropdown>
- </div>
- </Panel.Content>
- )
-}
-
-const PolicyTableRow = ({
- table = {},
- onSelectToggleRLS = () => {},
- onSelectCreatePolicy = () => {},
- onSelectEditPolicy = () => {},
- onSelectDeletePolicy = () => {},
-}) => {
- return (
- <Panel
- title={
- <PolicyTableRowHeader
- table={table}
- onSelectToggleRLS={onSelectToggleRLS}
- onSelectCreatePolicy={onSelectCreatePolicy}
- />
- }
- >
- {table.policies.length === 0 && (
- <div className="p-4 px-6">
- <p className="text-sm text-scale-900">No policies created yet</p>
- </div>
- )}
-
- {table.policies.map((policy) => (
- <PolicyRow
- key={policy.id}
- policy={policy}
- onSelectEditPolicy={onSelectEditPolicy}
- onSelectDeletePolicy={onSelectDeletePolicy}
- />
- ))}
- </Panel>
- )
-}
-
-export default PolicyTableRow
diff --git a/studio/components/to-be-cleaned/Auth/PolicyTemplates.js b/studio/components/to-be-cleaned/Auth/PolicyTemplates.js
deleted file mode 100644
index c21bcf528f1..00000000000
--- a/studio/components/to-be-cleaned/Auth/PolicyTemplates.js
+++ /dev/null
@@ -1,102 +0,0 @@
-import { Button, Menu } from '@supabase/ui'
-import { useState } from 'react'
-import { isEmpty } from 'lodash'
-import SqlEditor from '../SqlEditor'
-
-const TemplatesList = ({
- templates = [],
- templatesNote = '',
- selectedTemplate = {},
- setSelectedTemplate = () => {},
-}) => (
- <div className="border-r dark:border-dark flex flex-col justify-between" style={{ width: '30%' }}>
- <div
- className="space-y-0 overflow-y-auto hide-scrollbar divide-y divide-solid divide-border-primary"
- style={{ maxHeight: '24rem' }}
- >
- <Menu type="border">
- {templates.map((template) => {
- const active = selectedTemplate === template
- return (
- <div
- className={
- 'hover:bg-scale-400 border-b border-scale-400 ' +
- (active ? 'bg-scale-300 dark:bg-scale-500' : '')
- }
- >
- <Menu.Item
- key={template.id}
- active={active}
- onClick={() => setSelectedTemplate(template)}
- >
- <div className="py-2 truncate">{template.templateName}</div>
- </Menu.Item>
- </div>
- )
- })}
- </Menu>
- </div>
- {templatesNote && (
- <div className="px-4 py-2">
- <p className="text-xs text-scale-900">{templatesNote}</p>
- </div>
- )}
- </div>
-)
-
-const TemplatePreview = ({ selectedTemplate = {} }) => {
- const { id, templateName, description, statement } = selectedTemplate
- return (
- <div className="space-y-8" style={{ width: '70%' }}>
- {!isEmpty(selectedTemplate) && (
- <div className="flex flex-col justify-between h-full">
- <div className="px-6 my-5 space-y-6 h-full">
- <div className="space-y-2">
- <div className="flex flex-col space-y-2">
- <h3 className="text-base text-scale-1200">{templateName}</h3>
- <p className="text-sm text-scale-1100">{description}</p>
- </div>
- </div>
- <div className="space-y-2">
- <label className="text-sm text-scale-1100">Policy SQL template:</label>
- <div className="h-64">
- <SqlEditor readOnly queryId={id} defaultValue={statement} />
- </div>
- </div>
- </div>
- </div>
- )}
- </div>
- )
-}
-
-const PolicyTemplates = ({ templates = [], templatesNote = '', onUseTemplate = () => {} }) => {
- const [selectedTemplate, setSelectedTemplate] = useState(templates[0])
- return (
- <div>
- <div className="flex justify-between border-t dark:border-dark">
- <TemplatesList
- templatesNote={templatesNote}
- templates={templates}
- selectedTemplate={selectedTemplate}
- setSelectedTemplate={setSelectedTemplate}
- />
- <TemplatePreview selectedTemplate={selectedTemplate} />
- </div>
- <div className="px-6 py-4 w-full flex justify-end items-center gap-3 border-t dark:border-dark">
- <span className="text-sm text-scale-900">
- This will override any existing code you've written
- </span>
- <Button
- type="primary"
- disabled={isEmpty(selectedTemplate)}
- onClick={() => onUseTemplate(selectedTemplate)}
- >
- Use this template
- </Button>
- </div>
- </div>
- )
-}
-
-export default PolicyTemplates
diff --git a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePolicies.js b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePolicies.js
index 8f11e26795e..d683476a028 100644
--- a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePolicies.js
+++ b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePolicies.js
@@ -11,7 +11,7 @@ import StoragePoliciesEditPolicyModal from './StoragePoliciesEditPolicyModal'
import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'
-import PolicyEditorModal from 'components/to-be-cleaned/Auth/PolicyEditorModal'
+import { PolicyEditorModal } from 'components/interfaces/Authentication/Policies'
const StoragePolicies = () => {
const { ui, meta } = useStore()
@@ -140,7 +140,7 @@ const StoragePolicies = () => {
}
return (
- <div className="flex flex-col w-full min-h-full">
+ <div className="flex min-h-full w-full flex-col">
<h4 className="text-xl">Storage policies</h4>
<p className="text-scale-1100">
Safeguard your files with policies that define the operations allowed for your users at the
@@ -148,11 +148,11 @@ const StoragePolicies = () => {
</p>
{!loaded ? (
- <div className="h-full flex items-center justify-center">
+ <div className="flex h-full items-center justify-center">
<IconLoader className="animate-spin" size={16} />
</div>
) : (
- <div className="space-y-4 mt-4">
+ <div className="mt-4 space-y-4">
{buckets.length === 0 && <StoragePoliciesPlaceholder />}
{/* Sections for policies grouped by buckets */}
@@ -176,7 +176,7 @@ const StoragePolicies = () => {
)
})}
- <div className="w-full border-b border-gray-600 !mb-4" />
+ <div className="!mb-4 w-full border-b border-gray-600" />
<Typography.Text className="opacity-50">
You may also write policies for the tables under the storage schema directly for greater
control
diff --git a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditPolicyModal.js b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditPolicyModal.js
index b9ff354117b..8a9537c3ff9 100644
--- a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditPolicyModal.js
+++ b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditPolicyModal.js
@@ -12,8 +12,7 @@ import {
applyBucketIdToTemplateDefinition,
} from '../Storage.utils'
-import PolicySelection from 'components/to-be-cleaned/Auth/PolicySelection'
-import PolicyTemplates from 'components/to-be-cleaned/Auth/PolicyTemplates'
+import { PolicySelection, PolicyTemplates } from 'components/interfaces/Authentication/Policies'
import StoragePoliciesEditor from './StoragePoliciesEditor'
import StoragePoliciesReview from './StoragePoliciesReview'
@@ -162,7 +161,7 @@ const StoragePoliciesEditPolicyModal = ({
<div className="flex items-center space-x-3">
<span
onClick={onSelectBackFromTemplates}
- className="cursor-pointer text-scale-900 hover:text-scale-1200 transition-colors"
+ className="text-scale-900 hover:text-scale-1200 cursor-pointer transition-colors"
>
<IconChevronLeft strokeWidth={2} size={14} />
</span>
diff --git a/studio/pages/project/[ref]/auth/policies.tsx b/studio/pages/project/[ref]/auth/policies.tsx
index a2d73e5b52a..331e99f8ef2 100644
--- a/studio/pages/project/[ref]/auth/policies.tsx
+++ b/studio/pages/project/[ref]/auth/policies.tsx
@@ -5,11 +5,11 @@ import { observer, useLocalObservable } from 'mobx-react-lite'
import { withAuth, useStore } from 'hooks'
import { AuthLayout } from 'components/layouts'
-import NoSearchResults from 'components/to-be-cleaned/NoSearchResults'
import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
-import PolicyTableRow from 'components/to-be-cleaned/Auth/PolicyTableRow'
-import PolicyEditorModal from 'components/to-be-cleaned/Auth/PolicyEditorModal'
import NoTableState from 'components/ui/States/NoTableState'
+import { PolicyEditorModal, PolicyTableRow } from 'components/interfaces/Authentication/Policies'
+
+import NoSearchResults from 'components/to-be-cleaned/NoSearchResults'
const PageContext = createContext(null)
@@ -84,7 +84,7 @@ const AuthPolicies = observer(() => {
return (
<>
<div className="mb-4">
- <div className="flex justify-between items-center">
+ <div className="flex items-center justify-between">
<div>
<Input
size="small"