Skip to content

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

chore: update Modals in Auth Policies

Jonathan Summers-Muir49590cd0649e
diff --git a/studio/components/to-be-cleaned/Auth/PolicyEditor.js b/studio/components/to-be-cleaned/Auth/PolicyEditor.js
index a6e8c4182be..b45182a5d0d 100644
--- a/studio/components/to-be-cleaned/Auth/PolicyEditor.js
+++ b/studio/components/to-be-cleaned/Auth/PolicyEditor.js
@@ -1,4 +1,4 @@
-import { Button, Typography, Input, Radio } from '@supabase/ui'
+import { Button, Typography, Input, Radio, Modal } from '@supabase/ui'
import { get } from 'lodash'
import { useEffect } from 'react'
@@ -9,19 +9,20 @@ const PolicyName = ({ name = '', onUpdatePolicyName = () => {} }) => {
return (
<div className="flex space-x-12">
<div className="w-1/3 flex flex-col space-y-2">
- <Typography.Text>Policy name</Typography.Text>
- <Typography.Text type="secondary">A descriptive name for your policy.</Typography.Text>
+ <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 className="absolute top-2 right-4">
- <Typography.Text>{name.length}/63</Typography.Text>
- </div>
</div>
</div>
)
@@ -49,10 +50,12 @@ const PolicyDefinition = ({
{showUsing(operation) && (
<div className="flex space-x-12">
<div className="w-1/3 flex flex-col space-y-2">
- <Typography.Text>USING expression</Typography.Text>
- <Typography.Text type="secondary">
+ <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.
- </Typography.Text>
+ </p>
</div>
<div className={`w-2/3 ${showCheck(operation) ? 'h-32' : 'h-56'}`}>
<SqlEditor defaultValue={definition} onInputChange={onUpdatePolicyUsing} />
@@ -62,10 +65,12 @@ const PolicyDefinition = ({
{showCheck(operation) && (
<div className="flex space-x-12">
<div className="w-1/3 flex flex-col space-y-2">
- <Typography.Text>WITH CHECK expression</Typography.Text>
- <Typography.Text type="secondary">
+ <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.
- </Typography.Text>
+ </p>
</div>
<div className={`w-2/3 ${showUsing(operation) ? 'h-32' : 'h-56'}`}>
<SqlEditor defaultValue={check} onInputChange={onUpdatePolicyCheck} />
@@ -80,46 +85,50 @@ const PolicyAllowedOperation = ({ operation = '', onSelectOperation = () => {} }
return (
<div className="flex justify-between space-x-12">
<div className="w-1/3 flex flex-col space-y-2">
- <Typography.Text>Allowed operation</Typography.Text>
- <Typography.Text type="secondary">Selection an operation for this policy</Typography.Text>
+ <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
- 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 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>
@@ -131,9 +140,9 @@ const PolicyEditorFooter = ({
onViewTemplates = () => {},
onReviewPolicy = () => {},
}) => (
- <div className="px-6 py-3 w-full flex justify-end items-center space-x-4 border-t dark:border-dark">
+ <div className="px-6 py-4 w-full flex justify-end items-center gap-2 border-t dark:border-dark">
{showTemplates && (
- <Button type="secondary" onClick={onViewTemplates}>
+ <Button type="default" onClick={onViewTemplates}>
View templates
</Button>
)}
@@ -156,24 +165,34 @@ const PolicyEditor = ({
return (
<div className="">
- <div className="px-6 space-y-8 mb-8">
- <PolicyName
- name={policyFormFields.name}
- onUpdatePolicyName={(name) => onUpdatePolicyFormFields({ name })}
- />
+ <div className="py-8 space-y-8 mb-8">
+ <Modal.Content>
+ <PolicyName
+ name={policyFormFields.name}
+ onUpdatePolicyName={(name) => onUpdatePolicyFormFields({ name })}
+ />
+ </Modal.Content>
+ <Modal.Seperator />
{isNewPolicy && (
- <PolicyAllowedOperation
+ <>
+ <Modal.Content>
+ <PolicyAllowedOperation
+ operation={operation}
+ onSelectOperation={(command) => onUpdatePolicyFormFields({ command })}
+ />
+ </Modal.Content>
+ <Modal.Seperator />
+ </>
+ )}
+ <Modal.Content>
+ <PolicyDefinition
operation={operation}
- onSelectOperation={(command) => onUpdatePolicyFormFields({ command })}
+ definition={definition}
+ check={check}
+ onUpdatePolicyUsing={(definition) => onUpdatePolicyFormFields({ definition })}
+ onUpdatePolicyCheck={(check) => onUpdatePolicyFormFields({ check })}
/>
- )}
- <PolicyDefinition
- operation={operation}
- definition={definition}
- check={check}
- onUpdatePolicyUsing={(definition) => onUpdatePolicyFormFields({ definition })}
- onUpdatePolicyCheck={(check) => onUpdatePolicyFormFields({ check })}
- />
+ </Modal.Content>
</div>
<PolicyEditorFooter
showTemplates={isNewPolicy}
diff --git a/studio/components/to-be-cleaned/Auth/PolicyEditorModal.js b/studio/components/to-be-cleaned/Auth/PolicyEditorModal.js
index b25aca5f392..8d63f803947 100644
--- a/studio/components/to-be-cleaned/Auth/PolicyEditorModal.js
+++ b/studio/components/to-be-cleaned/Auth/PolicyEditorModal.js
@@ -33,13 +33,14 @@ const PolicyEditorModalTitle = ({
}
if (view === POLICY_MODAL_VIEWS.TEMPLATES) {
return (
- <div className="px-6 pt-5">
+ <div className="">
<div className="flex items-center space-x-3">
- <Typography.Text type="secondary">
- <div className="cursor-pointer" onClick={onSelectBackFromTemplates}>
- <IconChevronLeft />
- </div>
- </Typography.Text>
+ <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>
@@ -48,7 +49,7 @@ const PolicyEditorModalTitle = ({
)
}
return (
- <div className="flex items-center space-x-3 px-6 pt-5">
+ <div className="flex items-center space-x-3">
<Typography.Title level={4} className="m-0">
{getTitle()}
</Typography.Title>
@@ -174,11 +175,12 @@ const PolicyEditorModal = ({
return (
<Modal
+ size={view === POLICY_MODAL_VIEWS.SELECTION ? 'medium' : 'xxlarge'}
closable
hideFooter
visible={visible}
contentStyle={{ padding: 0 }}
- title={[
+ header={[
<PolicyEditorModalTitle
key="0"
view={view}
@@ -188,10 +190,10 @@ const PolicyEditorModal = ({
onSelectBackFromTemplates={onSelectBackFromTemplates}
/>,
]}
- style={{ maxWidth: 'none', width: '60rem' }}
+ // style={{ maxWidth: 'none', width: '60rem' }}
onCancel={onSelectCancel}
>
- <div className="w-full">
+ <div className="">
{view === POLICY_MODAL_VIEWS.SELECTION ? (
<PolicySelection
description="Write rules with PostgreSQL's policies to fit your unique business needs."
diff --git a/studio/components/to-be-cleaned/Auth/PolicyReview.js b/studio/components/to-be-cleaned/Auth/PolicyReview.js
index 9c71de47604..d36bf94874f 100644
--- a/studio/components/to-be-cleaned/Auth/PolicyReview.js
+++ b/studio/components/to-be-cleaned/Auth/PolicyReview.js
@@ -1,12 +1,13 @@
-import { Button, Typography } from '@supabase/ui'
+import { Button, Modal } from '@supabase/ui'
import { isEmpty } from 'lodash'
import { useState } from 'react'
+
import SqlEditor from '../SqlEditor'
const ReviewEmptyState = () => {
return (
<div className="flex items-center justify-center my-10 opacity-50 space-x-2">
- <Typography.Text>There are no changes made to this policy</Typography.Text>
+ <p className="text-base text-scale-1100">There are no changes made to this policy</p>
</div>
)
}
@@ -21,35 +22,39 @@ const PolicyReview = ({ policy = {}, onSelectBack = () => {}, onSelectSave = ()
let formattedSQLStatement = policy.statement || ''
return (
- <div className="space-y-6">
- <div className="px-6 space-y-8 flex items-center justify-between space-x-4">
- <div className="flex flex-col">
- <Typography.Text>
- This is the SQL statement that will be used to create your policy.
- </Typography.Text>
- </div>
- </div>
- <div className="px-6 space-y-4 overflow-y-auto" style={{ maxHeight: '25rem' }}>
- {isEmpty(policy) ? (
- <ReviewEmptyState />
- ) : (
- <div className="space-y-2">
- <Typography.Text>{policy.description}</Typography.Text>
- <div className="h-40">
- <SqlEditor readOnly defaultValue={formattedSQLStatement} />
+ <>
+ <Modal.Content>
+ <div className="space-y-6 py-8">
+ <div className="space-y-8 flex items-center justify-between">
+ <div className="flex flex-col">
+ <p className="text-sm text-scale-1100">
+ This is the SQL statement that will be used to create your policy.
+ </p>
</div>
</div>
- )}
- </div>
- <div className="px-6 py-3 w-full flex justify-end items-center space-x-4 border-t dark:border-dark">
- <Button type="secondary" onClick={onSelectBack}>
+ <div className="space-y-4 overflow-y-auto" style={{ maxHeight: '25rem' }}>
+ {isEmpty(policy) ? (
+ <ReviewEmptyState />
+ ) : (
+ <div className="space-y-2">
+ <span>{policy.description}</span>
+ <div className="h-40">
+ <SqlEditor readOnly defaultValue={formattedSQLStatement} />
+ </div>
+ </div>
+ )}
+ </div>
+ </div>
+ </Modal.Content>
+ <div className="px-6 py-4 w-full flex justify-end items-center gap-2 border-t dark:border-dark">
+ <Button type="default" onClick={onSelectBack}>
Back to edit
</Button>
<Button type="primary" disabled={isEmpty(policy)} onClick={onSavePolicy} loading={isSaving}>
Save policy
</Button>
</div>
- </div>
+ </>
)
}
diff --git a/studio/components/to-be-cleaned/Auth/PolicySelection.js b/studio/components/to-be-cleaned/Auth/PolicySelection.js
index e79bd3780cb..76b82d89097 100644
--- a/studio/components/to-be-cleaned/Auth/PolicySelection.js
+++ b/studio/components/to-be-cleaned/Auth/PolicySelection.js
@@ -1,4 +1,5 @@
-import { Card, Typography } from '@supabase/ui'
+import { Card, IconEdit, IconGrid, Modal, Typography } from '@supabase/ui'
+import CardButton from 'components/ui/CardButton'
import SVG from 'react-inlinesvg'
const PolicySelection = ({
@@ -7,64 +8,68 @@ const PolicySelection = ({
onViewEditor = () => {},
}) => {
return (
- <div className="px-6">
- <div className="flex items-center justify-between space-x-4">
- <div className="flex flex-col w-3/4">
- <Typography.Text>{description}</Typography.Text>
+ <Modal.Content>
+ <div className="py-8 space-y-6">
+ <div>
+ <p className="text-sm text-scale-1100">{description}</p>
</div>
- </div>
- <div className="my-8">
- <div className="flex items-center justify-center space-x-8">
- <div onClick={onViewTemplates}>
- <Card hoverable className="cursor-pointer py-4">
- <div className="flex items-center justify-between">
- <div className="w-1/2">
- <Typography.Text>Get started quickly</Typography.Text>
- <Typography.Title level={3}>Create a policy from a template</Typography.Title>
+ <div className="grid grid-cols-1 lg:grid-cols-1 gap-2">
+ <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
+ "
+ >
+ <IconGrid size={14} strokeWidth={2} />
</div>
- <SVG
- src={'/img/policy-template.svg'}
- alt={'policy-template'}
- preProcessor={(code) =>
- code.replace(/svg/, 'svg class="w-24 h-24 text-color-inherit opacity-75"')
- }
- />
</div>
- </Card>
- </div>
- <div onClick={onViewEditor}>
- <Card hoverable className="cursor-pointer py-4">
- <div className="flex items-center justify-between">
- <div className="w-1/2">
- <Typography.Text>For full customization</Typography.Text>
- <Typography.Title level={3}>Create a policy from scratch</Typography.Title>
+ }
+ />
+
+ <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
+ "
+ >
+ <IconEdit size={14} strokeWidth={2} />
</div>
- <SVG
- src={'/img/policy-new.svg'}
- alt={'policy-new'}
- preProcessor={(code) =>
- code.replace(/svg/, 'svg class="w-24 h-24 text-color-inherit opacity-75"')
- }
- />
</div>
- </Card>
- </div>
- </div>
- <div className="mt-10 mx-auto text-center">
- <Typography.Text>
- Not sure what policies are? Check out our resources{' '}
- <a
- target="_blank"
- className="text-green-400"
- href="https://supabase.com/docs/guides/auth#policies"
- >
- here
- </a>
- .
- </Typography.Text>
+ }
+ />
</div>
+ <p className="text-sm text-scale-1100">
+ Not sure what policies are? Check out our resources{' '}
+ <a
+ target="_blank"
+ className="text-brand-900 hover:text-brand-1200 transition-colors"
+ href="https://supabase.com/docs/guides/auth#policies"
+ >
+ here
+ </a>
+ .
+ </p>
</div>
- </div>
+ </Modal.Content>
)
}
diff --git a/studio/components/to-be-cleaned/Auth/PolicyTemplates.js b/studio/components/to-be-cleaned/Auth/PolicyTemplates.js
index 908a7261203..c21bcf528f1 100644
--- a/studio/components/to-be-cleaned/Auth/PolicyTemplates.js
+++ b/studio/components/to-be-cleaned/Auth/PolicyTemplates.js
@@ -1,4 +1,4 @@
-import { Button, Typography, Menu } from '@supabase/ui'
+import { Button, Menu } from '@supabase/ui'
import { useState } from 'react'
import { isEmpty } from 'lodash'
import SqlEditor from '../SqlEditor'
@@ -14,29 +14,31 @@ const TemplatesList = ({
className="space-y-0 overflow-y-auto hide-scrollbar divide-y divide-solid divide-border-primary"
style={{ maxHeight: '24rem' }}
>
- <Menu className="dark:divide-gray-600">
- {templates.map((template) => (
- <div
- key={template.id}
- onClick={() => setSelectedTemplate(template)}
- className="divide-gray-900"
- >
- <Menu.Item
- className="cursor-pointer"
- showActiveBar
- active={selectedTemplate === template}
+ <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' : '')
+ }
>
- <div className="space-y-2 py-2">
- <Typography.Text>{template.templateName}</Typography.Text>
- </div>
- </Menu.Item>
- </div>
- ))}
+ <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">
- <Typography.Text small>{templatesNote}</Typography.Text>
+ <p className="text-xs text-scale-900">{templatesNote}</p>
</div>
)}
</div>
@@ -51,12 +53,12 @@ const TemplatePreview = ({ selectedTemplate = {} }) => {
<div className="px-6 my-5 space-y-6 h-full">
<div className="space-y-2">
<div className="flex flex-col space-y-2">
- <Typography.Title level={6}>{templateName}</Typography.Title>
- <Typography.Text>{description}</Typography.Text>
+ <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">
- <Typography.Text>Policy SQL template:</Typography.Text>
+ <label className="text-sm text-scale-1100">Policy SQL template:</label>
<div className="h-64">
<SqlEditor readOnly queryId={id} defaultValue={statement} />
</div>
@@ -81,10 +83,10 @@ const PolicyTemplates = ({ templates = [], templatesNote = '', onUseTemplate = (
/>
<TemplatePreview selectedTemplate={selectedTemplate} />
</div>
- <div className="px-6 py-2 w-full flex justify-end items-center space-x-4 border-t dark:border-dark">
- <Typography.Text type="secondary">
+ <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
- </Typography.Text>
+ </span>
<Button
type="primary"
disabled={isEmpty(selectedTemplate)}
diff --git a/studio/components/ui/CardButton.tsx b/studio/components/ui/CardButton.tsx
index 4742c429d45..5b33bfeb093 100644
--- a/studio/components/ui/CardButton.tsx
+++ b/studio/components/ui/CardButton.tsx
@@ -12,6 +12,7 @@ interface Props {
imgUrl?: string
imgAlt?: string
onClick?: () => void
+ icon?: React.ReactNode
}
const CardButton: FC<Props> = ({
@@ -24,6 +25,7 @@ const CardButton: FC<Props> = ({
imgUrl,
imgAlt,
onClick,
+ icon,
}) => {
const LinkContainer = ({ children }: { children: React.ReactNode }) => (
<Link href={linkHref}>{children}</Link>
@@ -54,10 +56,14 @@ const CardButton: FC<Props> = ({
]
}
+ const ImageContainer = ({ children }: { children: React.ReactNode }) => {
+ return <div className="flex flex-col mr-4">{children}</div>
+ }
+
const contents = (
<div className={containerClasses.join(' ')}>
{imgUrl && (
- <div className="flex flex-col mr-4">
+ <ImageContainer>
<img
className="
transition-all
@@ -67,11 +73,12 @@ const CardButton: FC<Props> = ({
alt={`${imgAlt}`}
width="26"
/>
- </div>
+ </ImageContainer>
)}
+ {icon && <ImageContainer>{icon}</ImageContainer>}
<div className="flex flex-col space-y-2 w-full h-full">
<h5 className="text-scale-1200">{title}</h5>
- <div className="flex flex-1 w-full">
+ <div className="flex flex-col flex-1 w-full">
<p className="text-scale-1100 text-sm">{description}</p>
<div className="w-full">{children && children}</div>
</div>
diff --git a/studio/components/ui/Dialogs/ConfirmDialog.js b/studio/components/ui/Dialogs/ConfirmDialog.js
index b34fb282d2c..8cfd3461ed5 100644
--- a/studio/components/ui/Dialogs/ConfirmDialog.js
+++ b/studio/components/ui/Dialogs/ConfirmDialog.js
@@ -41,7 +41,7 @@ const ConfirmModal = ({
<Form
initialValues={{}}
validateOnBlur
- onSubmit={(values, { setSubmitting }) => {
+ onSubmit={() => {
onConfirm()
}}
validate={() => {