Skip to content

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

Fix storage policy modals

Joshen Lim8e3377492de0
diff --git a/studio/components/to-be-cleaned/Auth/PolicySelection.js b/studio/components/to-be-cleaned/Auth/PolicySelection.js
index 76b82d89097..dc50a96a99d 100644
--- a/studio/components/to-be-cleaned/Auth/PolicySelection.js
+++ b/studio/components/to-be-cleaned/Auth/PolicySelection.js
@@ -1,6 +1,5 @@
-import { Card, IconEdit, IconGrid, Modal, Typography } from '@supabase/ui'
+import { IconEdit, IconGrid, Modal } from '@supabase/ui'
import CardButton from 'components/ui/CardButton'
-import SVG from 'react-inlinesvg'
const PolicySelection = ({
description = '',
diff --git a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditPolicyModal.js b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditPolicyModal.js
index 1a88fba63b1..b9ff354117b 100644
--- a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditPolicyModal.js
+++ b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditPolicyModal.js
@@ -142,51 +142,61 @@ const StoragePoliciesEditPolicyModal = ({
}
/* Misc components */
- const StoragePolicyTemplatesTitle = () => (
- <div className="px-6 pt-5">
- <div className="flex items-center space-x-3">
- <Typography.Text type="secondary">
- <div className="cursor-pointer" onClick={onSelectBackFromTemplates}>
- <IconChevronLeft />
+
+ const StoragePolicyEditorModalTitle = ({
+ view,
+ bucketName,
+ onSelectBackFromTemplates = () => {},
+ }) => {
+ const getTitle = () => {
+ if (view === POLICY_MODAL_VIEWS.EDITOR || view === POLICY_MODAL_VIEWS.SELECTION) {
+ return `Adding new policy to ${bucketName}`
+ }
+ if (view === POLICY_MODAL_VIEWS.REVIEW) {
+ return `Reviewing policies to be created for ${bucketName}`
+ }
+ }
+ 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>
- </Typography.Text>
+ </div>
+ )
+ }
+ return (
+ <div className="flex items-center space-x-3">
<Typography.Title level={4} className="m-0">
- Select a template to use for your new policy
+ {getTitle()}
</Typography.Title>
</div>
- </div>
- )
-
- const StoragePolicyReviewTitle = ({ bucketName = '' }) => (
- <div className="flex items-center space-x-3 px-6 pt-5">
- <Typography.Title level={4} className="m-0">
- Reviewing policies to be added for {bucketName}
- </Typography.Title>
- </div>
- )
-
- const StoragePolicyTitle = ({ bucketName = '' }) => (
- <div className="flex items-center space-x-3 px-6 pt-5">
- <Typography.Title level={4} className="m-0">
- Adding new policy to ${bucketName}
- </Typography.Title>
- </div>
- )
+ )
+ }
return (
<Modal
+ size={view === POLICY_MODAL_VIEWS.SELECTION ? 'medium' : 'xxlarge'}
closable
hideFooter
visible={visible}
contentStyle={{ padding: 0 }}
- title={
- view === POLICY_MODAL_VIEWS.TEMPLATES
- ? [<StoragePolicyTemplatesTitle key="0" />]
- : view === POLICY_MODAL_VIEWS.REVIEW
- ? [<StoragePolicyReviewTitle key="1" bucketName={bucketName} />]
- : [<StoragePolicyTitle key="2" bucketName={bucketName} />]
- }
- style={{ maxWidth: 'none', width: '60rem' }}
+ header={[
+ <StoragePolicyEditorModalTitle
+ key="0"
+ view={view}
+ bucketName={bucketName}
+ onSelectBackFromTemplates={onSelectBackFromTemplates}
+ />,
+ ]}
onCancel={onSelectCancel}
>
<div className="w-full">
diff --git a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditor.js b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditor.js
index f3f360345cf..1dc41d7b7c5 100644
--- a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditor.js
+++ b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesEditor.js
@@ -1,4 +1,4 @@
-import { Badge, Button, Checkbox, Input, Typography } from '@supabase/ui'
+import { Badge, Button, Checkbox, Input, Radio, Modal } from '@supabase/ui'
import { get } from 'lodash'
import { STORAGE_CLIENT_LIBRARY_MAPPINGS } from '../Storage.constants'
@@ -9,8 +9,10 @@ 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
@@ -18,10 +20,8 @@ const PolicyName = ({ name = '', onUpdatePolicyName = () => {} }) => {
rows={1}
limit={50}
onChange={(e) => onUpdatePolicyName(e.target.value)}
+ actions={<span className="text-sm text-scale-900 mr-3">{name.length}/50</span>}
/>
- <div className="absolute top-2 right-4">
- <Typography.Text>{name.length}/50</Typography.Text>
- </div>
</div>
</div>
)
@@ -31,10 +31,12 @@ const PolicyDefinition = ({ definition = '', onUpdatePolicyDefinition = () => {}
return (
<div className="flex space-x-12">
<div className="w-1/3 flex flex-col space-y-2">
- <Typography.Text>Policy definition</Typography.Text>
- <Typography.Text type="secondary">
+ <label className="text-base text-scale-1100" htmlFor="policy-name">
+ Policy definition
+ </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 h-56">
<SqlEditor defaultValue={definition} onInputChange={onUpdatePolicyDefinition} />
@@ -48,11 +50,13 @@ const PolicyAllowedOperations = ({ allowedOperations = [], onToggleOperation = (
return (
<div className="flex justify-between space-x-12">
<div className="w-1/3 flex flex-col space-y-2">
- <Typography.Text>Allowed operations</Typography.Text>
- <Typography.Text type="secondary">
+ <label className="text-base text-scale-1100" htmlFor="allowed-operation">
+ Allowed operation
+ </label>
+ <p className="text-sm text-scale-900">
Based on the operations you have selected, you can use any of the highlighted functions in
the supabase-js Javascript library
- </Typography.Text>
+ </p>
</div>
<div className="w-2/3">
<div className="flex items-center space-x-8">
@@ -93,7 +97,7 @@ const PolicyAllowedOperations = ({ allowedOperations = [], onToggleOperation = (
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">
- <Button type="secondary" onClick={onViewTemplates}>
+ <Button type="default" onClick={onViewTemplates}>
View templates
</Button>
<Button type="primary" onClick={onReviewPolicy}>
@@ -114,16 +118,24 @@ const StoragePoliciesEditor = ({
return (
<div className="">
- <div className="px-6 space-y-8 mb-8">
- <PolicyName name={policyFormFields.name} onUpdatePolicyName={onUpdatePolicyName} />
- <PolicyAllowedOperations
- allowedOperations={policyFormFields.allowedOperations}
- onToggleOperation={onToggleOperation}
- />
- <PolicyDefinition
- definition={definition}
- onUpdatePolicyDefinition={onUpdatePolicyDefinition}
- />
+ <div className="py-6 space-y-8 mb-8">
+ <Modal.Content>
+ <PolicyName name={policyFormFields.name} onUpdatePolicyName={onUpdatePolicyName} />
+ </Modal.Content>
+ <Modal.Seperator />
+ <Modal.Content>
+ <PolicyAllowedOperations
+ allowedOperations={policyFormFields.allowedOperations}
+ onToggleOperation={onToggleOperation}
+ />
+ </Modal.Content>
+ <Modal.Seperator />
+ <Modal.Content>
+ <PolicyDefinition
+ definition={definition}
+ onUpdatePolicyDefinition={onUpdatePolicyDefinition}
+ />
+ </Modal.Content>
</div>
<PolicyEditorFooter onViewTemplates={onViewTemplates} onReviewPolicy={onReviewPolicy} />
</div>
diff --git a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesReview.js b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesReview.js
index 22e0b252e23..5ca3adcc526 100644
--- a/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesReview.js
+++ b/studio/components/to-be-cleaned/Storage/StoragePolicies/StoragePoliciesReview.js
@@ -1,4 +1,4 @@
-import { Button, Typography } from '@supabase/ui'
+import { Button, Typography, Modal } from '@supabase/ui'
import { useState } from 'react'
import SqlEditor from 'components/to-be-cleaned/SqlEditor'
@@ -22,33 +22,36 @@ const StoragePoliciesReview = ({
}
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>
- These are the SQL statements that will be used to create your policies. The suffix
- appended to the end of your policy name (
- <Typography.Text code>[hashString]_[number]</Typography.Text>) just functions as a
- unique identifier for each of your policies.
- </Typography.Text>
- </div>
- </div>
- <div className="px-6 space-y-4 overflow-y-auto" style={{ maxHeight: '25rem' }}>
- {policyStatements.length === 0 && <ReviewEmptyState />}
- {policyStatements.map((policy, idx) => {
- let formattedSQLStatement = policy.statement || ''
- return (
- <div key={`policy_${idx}`} className="space-y-2">
- <Typography.Text>{policy.description}</Typography.Text>
- <div className="h-40">
- <SqlEditor readOnly defaultValue={formattedSQLStatement} />
- </div>
+ <>
+ <Modal.Content>
+ <div className="space-y-6 py-8">
+ <div className="space-y-8 flex items-center justify-between space-x-4">
+ <div className="flex flex-col">
+ <p className="text-sm text-scale-1100">
+ These are the SQL statements that will be used to create your policies. The suffix
+ appended to the end of your policy name (<code>[hashString]_[number]</code>) just
+ functions as a unique identifier for each of your policies.
+ </p>
</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>
+ <div className="space-y-4 overflow-y-auto" style={{ maxHeight: '25rem' }}>
+ {policyStatements.length === 0 && <ReviewEmptyState />}
+ {policyStatements.map((policy, idx) => {
+ let formattedSQLStatement = policy.statement || ''
+ return (
+ <div key={`policy_${idx}`} 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>
{policyStatements.length > 0 && (
@@ -57,7 +60,7 @@ const StoragePoliciesReview = ({
</Button>
)}
</div>
- </div>
+ </>
)
}