The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add check permissions across storage explorer components and refactor some files to tsx
Joshen Lime63970b45170
diff --git a/studio/components/interfaces/Organization/TeamSettings/MemberActions.tsx b/studio/components/interfaces/Organization/TeamSettings/MemberActions.tsxindex a920d38809e..9bd55624df0 100644--- a/studio/components/interfaces/Organization/TeamSettings/MemberActions.tsx+++ b/studio/components/interfaces/Organization/TeamSettings/MemberActions.tsx@@ -15,12 +15,11 @@ import { isInviteExpired } from '../Organization.utils'import { getRolesManagementPermissions } from './TeamSettings.utils'interface Props {- members: Member[]member: Memberroles: Role[]}-const MemberActions: FC<Props> = ({ members, member, roles }) => {+const MemberActions: FC<Props> = ({ member, roles }) => {const { ui } = useStore()const { slug } = useParams()const { rolesRemovable } = getRolesManagementPermissions(roles)diff --git a/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx b/studio/components/interfaces/Organization/TeamSettings/MembersView.tsxindex c54088028ed..87099434d46 100644--- a/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx+++ b/studio/components/interfaces/Organization/TeamSettings/MembersView.tsx@@ -232,9 +232,7 @@ const MembersView: FC<Props> = ({ searchString, roles, members }) => {)}</Table.td><Table.td>- {!memberIsUser && (- <MemberActions members={members} member={x} roles={roles} />- )}+ {!memberIsUser && <MemberActions member={x} roles={roles} />}</Table.td></Table.tr></Fragment>diff --git a/studio/components/layouts/ProjectLayout/ConnectingState.tsx b/studio/components/layouts/ProjectLayout/ConnectingState.tsxindex a4124474256..d26e4043bea 100644--- a/studio/components/layouts/ProjectLayout/ConnectingState.tsx+++ b/studio/components/layouts/ProjectLayout/ConnectingState.tsx@@ -40,6 +40,7 @@ const ConnectingState: FC<Props> = ({ project }) => {const result = await pingPostgrest(project.restUrl!, project.ref, {kpsVersion: project.kpsVersion,})+ console.log('testProjectConnection', result)if (result) {clearInterval(checkProjectConnectionIntervalRef.current)app.onProjectPostgrestStatusUpdated(project.id, 'ONLINE')diff --git a/studio/components/layouts/StorageLayout/StorageLayout.tsx b/studio/components/layouts/StorageLayout/StorageLayout.tsxindex 53432b6461c..cb46bbb60d2 100644--- a/studio/components/layouts/StorageLayout/StorageLayout.tsx+++ b/studio/components/layouts/StorageLayout/StorageLayout.tsx@@ -40,11 +40,8 @@ const StorageLayout: FC<Props> = ({ title, children }) => {buckets,} = storageExplorerStore || {}- // [Joshen] At the moment, without the service key, we won't be able to pull any data from storageconst { data: settings, isLoading } = useProjectApiQuery({ projectRef })const apiService = settings?.autoApiService- const serviceKey = find(apiService?.service_api_keys ?? [], (key) => key.tags === 'service_role')- const canAccessStorage = !isLoading && apiService && serviceKeyuseEffect(() => {if (!isLoading && apiService) initializeStorageStore(apiService)@@ -52,15 +49,13 @@ const StorageLayout: FC<Props> = ({ title, children }) => {const initializeStorageStore = async (apiService: AutoApiService) => {if (apiService.endpoint) {- if (serviceKey) {- storageExplorerStore.initStore(- projectRef,- apiService.endpoint,- apiService.serviceApiKey,- apiService.protocol- )- await storageExplorerStore.fetchBuckets()- }+ storageExplorerStore.initStore(+ projectRef,+ apiService.endpoint,+ apiService.serviceApiKey,+ apiService.protocol+ )+ await storageExplorerStore.fetchBuckets()} else {ui.setNotification({category: 'error',@@ -100,15 +95,15 @@ const StorageLayout: FC<Props> = ({ title, children }) => {}}- if (!isLoading && !canAccessStorage) {- return (- <BaseLayout>- <main style={{ maxHeight: '100vh' }} className="flex-1 overflow-y-auto">- <NoPermission isFullPage resourceText="access your project's storage" />- </main>- </BaseLayout>- )- }+ // if (!isLoading && !canAccessStorage) {+ // return (+ // <BaseLayout>+ // <main style={{ maxHeight: '100vh' }} className="flex-1 overflow-y-auto">+ // <NoPermission isFullPage resourceText="access your project's storage" />+ // </main>+ // </BaseLayout>+ // )+ // }return (<ProjectLayout title={title || 'Storage'} product="Storage" productMenu={<StorageMenu />}>diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/ColumnContextMenu.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/ColumnContextMenu.jsdeleted file mode 100644index 45d5cb5ba0d..00000000000--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/ColumnContextMenu.js+++ /dev/null@@ -1,49 +0,0 @@-import { Menu, Item, Separator, Submenu } from 'react-contexify'-import 'react-contexify/dist/ReactContexify.css'--import { STORAGE_VIEWS, STORAGE_SORT_BY, STORAGE_SORT_BY_ORDER } from '../Storage.constants'--const ColumnContextMenu = ({- id = '',- onCreateNewFolder = () => {},- onSelectAllItems = () => {},- onSelectView = () => {},- onSelectSort = () => {},- onSelectSortByOrder = () => {},-}) => {- return (- <Menu id={id} animation="fade">- <Item- onClick={({ props }) => {- onCreateNewFolder(props.index)- }}- >- New folder- </Item>- <Separator />- <Item- onClick={({ props }) => {- onSelectAllItems(props.index)- }}- >- Select all items- </Item>- <Submenu label="View">- <Item onClick={() => onSelectView(STORAGE_VIEWS.COLUMNS)}>As columns</Item>- <Item onClick={() => onSelectView(STORAGE_VIEWS.LIST)}>As list</Item>- </Submenu>- <Submenu label="Sort by">- <Item onClick={() => onSelectSort(STORAGE_SORT_BY.NAME)}>Name</Item>- <Item onClick={() => onSelectSort(STORAGE_SORT_BY.CREATED_AT)}>Last created</Item>- <Item onClick={() => onSelectSort(STORAGE_SORT_BY.UPDATED_AT)}>Last modified</Item>- <Item onClick={() => onSelectSort(STORAGE_SORT_BY.LAST_ACCESSED_AT)}>Last accessed</Item>- </Submenu>- <Submenu label="Sort by order">- <Item onClick={() => onSelectSortByOrder(STORAGE_SORT_BY_ORDER.ASC)}>Ascending</Item>- <Item onClick={() => onSelectSortByOrder(STORAGE_SORT_BY_ORDER.DESC)}>Descending</Item>- </Submenu>- </Menu>- )-}--export default ColumnContextMenudiff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/ColumnContextMenu.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/ColumnContextMenu.tsxnew file mode 100644index 00000000000..4f13edbf96b--- /dev/null+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/ColumnContextMenu.tsx@@ -0,0 +1,121 @@+import { FC } from 'react'+import { compact, uniqBy } from 'lodash'+import { Menu, Item, Separator, Submenu } from 'react-contexify'+import 'react-contexify/dist/ReactContexify.css'++import {+ STORAGE_VIEWS,+ STORAGE_SORT_BY,+ STORAGE_SORT_BY_ORDER,+ STORAGE_ROW_TYPES,+} from '../Storage.constants'+import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'+import { IconFolderPlus } from 'ui'++interface Props {+ id: string+}++const ColumnContextMenu: FC<Props> = ({ id = '' }) => {+ const storageExplorerStore = useStorageStore()+ const {+ columns,+ selectedItems,+ setSelectedItems,+ setView,+ setSortBy,+ setSortByOrder,+ addNewFolderPlaceholder,+ } = storageExplorerStore++ const onSelectCreateFolder = (columnIndex = -1) => {+ addNewFolderPlaceholder(columnIndex)+ }++ const onSelectAllItemsInColumn = (columnIndex: number) => {+ const columnFiles = columns[columnIndex].items+ .filter((item: any) => item.type === STORAGE_ROW_TYPES.FILE)+ .map((item: any) => {+ return { ...item, columnIndex }+ })+ const columnFilesId = compact(columnFiles.map((item: any) => item.id))+ const selectedItemsFromColumn = selectedItems.filter((item: any) =>+ columnFilesId.includes(item.id)+ )++ if (selectedItemsFromColumn.length === columnFiles.length) {+ // Deselect all items from column+ const updatedSelectedItems = selectedItems.filter(+ (item: any) => !columnFilesId.includes(item.id)+ )+ setSelectedItems(updatedSelectedItems)+ } else {+ // Select all items from column+ const updatedSelectedItems = uniqBy(selectedItems.concat(columnFiles), 'id')+ setSelectedItems(updatedSelectedItems)+ }+ }++ return (+ <Menu id={id} animation="fade" className="!bg-scale-300 border border-scale-500">+ <Item onClick={({ props }) => onSelectCreateFolder(props.index)}>+ <IconFolderPlus size="tiny" />+ <span className="ml-2 text-xs">New folder</span>+ </Item>+ <Separator />+ <Item onClick={({ props }) => onSelectAllItemsInColumn(props.index)}>+ <span className="ml-2 text-xs">Select all items</span>+ </Item>+ <Submenu+ label={+ <div>+ <span className="ml-2 text-xs">View</span>+ </div>+ }+ >+ <Item onClick={() => setView(STORAGE_VIEWS.COLUMNS)}>+ <span className="ml-2 text-xs">As columns</span>+ </Item>+ <Item onClick={() => setView(STORAGE_VIEWS.LIST)}>+ <span className="ml-2 text-xs">As list</span>+ </Item>+ </Submenu>+ <Submenu+ label={+ <div>+ <span className="ml-2 text-xs">Sort by</span>+ </div>+ }+ >+ <Item onClick={() => setSortBy(STORAGE_SORT_BY.NAME)}>+ <span className="ml-2 text-xs">Name</span>+ </Item>+ <Item onClick={() => setSortBy(STORAGE_SORT_BY.CREATED_AT)}>+ <span className="ml-2 text-xs">Last created</span>+ </Item>+ <Item onClick={() => setSortBy(STORAGE_SORT_BY.UPDATED_AT)}>+ <span className="ml-2 text-xs">Last modified</span>+ </Item>+ <Item onClick={() => setSortBy(STORAGE_SORT_BY.LAST_ACCESSED_AT)}>+ <span className="ml-2 text-xs">Last accessed</span>+ </Item>+ </Submenu>+ <Submenu+ label={+ <div>+ <span className="ml-2 text-xs">Sort by order</span>+ </div>+ }+ >+ <Item onClick={() => setSortByOrder(STORAGE_SORT_BY_ORDER.ASC)}>+ <span className="ml-2 text-xs">Ascending</span>+ </Item>+ <Item onClick={() => setSortByOrder(STORAGE_SORT_BY_ORDER.DESC)}>+ <span className="ml-2 text-xs">Descending</span>+ </Item>+ </Submenu>+ </Menu>+ )+}++export default ColumnContextMenudiff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.jsindex 69e9a354f06..2b41ffda51a 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.js+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.js@@ -1,4 +1,4 @@-import React, { useEffect, useRef } from 'react'+import { useEffect, useRef } from 'react'import { observer } from 'mobx-react-lite'import { STORAGE_VIEWS, CONTEXT_MENU_KEYS } from '../Storage.constants'@@ -6,7 +6,6 @@ import ItemContextMenu from './ItemContextMenu'import FolderContextMenu from './FolderContextMenu'import ColumnContextMenu from './ColumnContextMenu'import FileExplorerColumn from './FileExplorerColumn'-import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'const FileExplorer = ({view = STORAGE_VIEWS.COLUMNS,@@ -17,16 +16,9 @@ const FileExplorer = ({onFilesUpload = () => {},onSelectAllItemsInColumn = () => {},onSelectColumnEmptySpace = () => {},- onSelectCreateFolder = () => {},- onChangeView = () => {},- onChangeSortBy = () => {},- onChangeSortByOrder = () => {},onColumnLoadMore = () => {},}) => {const fileExplorerRef = useRef(null)- const storageExplorerStore = useStorageStore()-- const { setSelectedItemToRename, setSelectedItemsToDelete } = storageExplorerStoreuseEffect(() => {if (fileExplorerRef) {@@ -42,20 +34,9 @@ const FileExplorer = ({ref={fileExplorerRef}className="file-explorer flex flex-grow overflow-x-auto justify-between h-full w-full">- <ColumnContextMenu- id={CONTEXT_MENU_KEYS.STORAGE_COLUMN}- onCreateNewFolder={onSelectCreateFolder}- onSelectAllItems={onSelectAllItemsInColumn}- onSelectView={onChangeView}- onSelectSort={onChangeSortBy}- onSelectSortByOrder={onChangeSortByOrder}- />+ <ColumnContextMenu id={CONTEXT_MENU_KEYS.STORAGE_COLUMN} /><ItemContextMenu id={CONTEXT_MENU_KEYS.STORAGE_ITEM} />- <FolderContextMenu- id={CONTEXT_MENU_KEYS.STORAGE_FOLDER}- onRenameFolder={(folder) => setSelectedItemToRename(folder)}- onDeleteFolder={(folder) => setSelectedItemsToDelete([folder])}- />+ <FolderContextMenu id={CONTEXT_MENU_KEYS.STORAGE_FOLDER} />{view === STORAGE_VIEWS.COLUMNS ? (<div className="flex">{columns.map((column, index) => (diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsxindex e4ab9f3e40e..d3b10ab5108 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx@@ -18,6 +18,10 @@ import {IconChevronsUp,IconList,} from 'ui'+import * as Tooltip from '@radix-ui/react-tooltip'+import { PermissionAction } from '@supabase/shared-types/out/constants'++import { checkPermissions } from 'hooks'import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'import { STORAGE_VIEWS, STORAGE_SORT_BY, STORAGE_SORT_BY_ORDER } from '../Storage.constants'@@ -137,6 +141,7 @@ const FileExplorerHeader: FC<Props> = ({const breadcrumbs = columns.map((column: any) => column.name)const backDisabled = columns.length <= 1+ const canUpdateStorage = checkPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')useEffect(() => {if (itemSearchString) setSearchString(itemSearchString)@@ -392,22 +397,60 @@ const FileExplorerHeader: FC<Props> = ({{/* @ts-ignore */}<input ref={uploadButtonRef} type="file" multiple onChange={onFilesUpload} /></div>- <Button- icon={<IconUpload size={16} strokeWidth={2} />}- type="text"- disabled={breadcrumbs.length === 0}- onClick={onSelectUpload}- >- Upload files- </Button>- <Button- icon={<IconFolderPlus size={16} strokeWidth={2} />}- type="text"- disabled={breadcrumbs.length === 0}- onClick={() => addNewFolderPlaceholder(-1)}- >- Create folder- </Button>+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger className="w-full">+ <Button+ icon={<IconUpload size={16} strokeWidth={2} />}+ type="text"+ disabled={!canUpdateStorage || breadcrumbs.length === 0}+ onClick={onSelectUpload}+ >+ Upload files+ </Button>+ </Tooltip.Trigger>+ {!canUpdateStorage && (+ <Tooltip.Content side="bottom">+ <Tooltip.Arrow className="radix-tooltip-arrow" />+ <div+ className={[+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',+ 'border border-scale-200',+ ].join(' ')}+ >+ <span className="text-xs text-scale-1200">+ You need additional permissions to upload files+ </span>+ </div>+ </Tooltip.Content>+ )}+ </Tooltip.Root>+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger className="w-full">+ <Button+ icon={<IconFolderPlus size={16} strokeWidth={2} />}+ type="text"+ disabled={!canUpdateStorage || breadcrumbs.length === 0}+ onClick={() => addNewFolderPlaceholder(-1)}+ >+ Create folder+ </Button>+ </Tooltip.Trigger>+ {!canUpdateStorage && (+ <Tooltip.Content side="bottom">+ <Tooltip.Arrow className="radix-tooltip-arrow" />+ <div+ className={[+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',+ 'border border-scale-200',+ ].join(' ')}+ >+ <span className="text-xs text-scale-1200">+ You need additional permissions to create folders+ </span>+ </div>+ </Tooltip.Content>+ )}+ </Tooltip.Root></div>{/* Search: Disabled for now */}diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsxindex b5bd5982c23..55437aba869 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx@@ -20,6 +20,9 @@ import {import SVG from 'react-inlinesvg'import * as Tooltip from '@radix-ui/react-tooltip'import { useContextMenu } from 'react-contexify'+import { PermissionAction } from '@supabase/shared-types/out/constants'++import { checkPermissions } from 'hooks'import {STORAGE_VIEWS,STORAGE_ROW_TYPES,@@ -95,6 +98,7 @@ const FileExplorerRow: FC<Props> = ({addNewFolder,renameFolder,renameFile,+ selectedBucket,setSelectedItems,setSelectedItemsToDelete,setSelectedItemToRename,@@ -106,11 +110,13 @@ const FileExplorerRow: FC<Props> = ({copyFileURLToClipboard,} = storageExplorerStore+ const isPublic = selectedBucket.publicconst itemWithColumnIndex = { ...item, columnIndex }const isSelected = find(selectedItems, item) !== undefinedconst isOpened =openedFolders.length > columnIndex ? isEqual(openedFolders[columnIndex], item) : falseconst isPreviewed = !isEmpty(selectedFilePreview) && isEqual(selectedFilePreview.id, item.id)+ const canUpdateFiles = checkPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')const onSelectFile = async (columnIndex: number, file: any) => {popColumnAtIndex(columnIndex)@@ -187,77 +193,109 @@ const FileExplorerRow: FC<Props> = ({const rowOptions =item.type === STORAGE_ROW_TYPES.FOLDER? [- {- name: 'Rename',- icon: <IconEdit size="tiny" />,- onClick: () => setSelectedItemToRename(itemWithColumnIndex),- },+ ...(canUpdateFiles+ ? [+ {+ name: 'Rename',+ icon: <IconEdit size="tiny" />,+ onClick: () => setSelectedItemToRename(itemWithColumnIndex),+ },+ ]+ : []),{name: 'Download',icon: <IconDownload size="tiny" />,onClick: () => downloadFolder(itemWithColumnIndex),},- { name: 'Separator', icon: undefined, onClick: undefined },- {- name: 'Delete',- icon: <IconTrash2 size="tiny" />,- onClick: () => setSelectedItemsToDelete([itemWithColumnIndex]),- },+ ...(canUpdateFiles+ ? [+ { name: 'Separator', icon: undefined, onClick: undefined },+ {+ name: 'Delete',+ icon: <IconTrash2 size="tiny" />,+ onClick: () => setSelectedItemsToDelete([itemWithColumnIndex]),+ },+ ]+ : []),]: [...(!item.isCorrupted+ ? [+ ...(isPublic+ ? [+ {+ name: 'Get URL',+ icon: <IconClipboard size="tiny" />,+ onClick: async () => await copyFileURLToClipboard(itemWithColumnIndex),+ },+ ]+ : [+ {+ name: 'Get URL',+ icon: <IconClipboard size="tiny" />,+ children: [+ {+ name: 'Expire in 1 week',+ onClick: async () =>+ await copyFileURLToClipboard(+ itemWithColumnIndex,+ URL_EXPIRY_DURATION.WEEK+ ),+ },+ {+ name: 'Expire in 1 month',+ onClick: async () =>+ await copyFileURLToClipboard(+ itemWithColumnIndex,+ URL_EXPIRY_DURATION.MONTH+ ),+ },+ {+ name: 'Expire in 1 year',+ onClick: async () =>+ await copyFileURLToClipboard(+ itemWithColumnIndex,+ URL_EXPIRY_DURATION.YEAR+ ),+ },+ {+ name: 'Custom expiry',+ onClick: async () => setSelectedFileCustomExpiry(itemWithColumnIndex),+ },+ ],+ },+ ]),+ ...(canUpdateFiles+ ? [+ {+ name: 'Rename',+ icon: <IconEdit size="tiny" />,+ onClick: () => setSelectedItemToRename(itemWithColumnIndex),+ },+ {+ name: 'Move',+ icon: <IconMove size="tiny" />,+ onClick: () => setSelectedItemsToMove([itemWithColumnIndex]),+ },+ {+ name: 'Download',+ icon: <IconDownload size="tiny" />,+ onClick: async () => await downloadFile(itemWithColumnIndex),+ },+ { name: 'Separator', icon: undefined, onClick: undefined },+ ]+ : []),+ ]+ : []),+ ...(canUpdateFiles? [{- name: 'Get URL',- icon: <IconClipboard size="tiny" />,- children: [- {- name: 'Expire in 1 week',- onClick: async () =>- await copyFileURLToClipboard(itemWithColumnIndex, URL_EXPIRY_DURATION.WEEK),- },- {- name: 'Expire in 1 month',- onClick: async () =>- await copyFileURLToClipboard(- itemWithColumnIndex,- URL_EXPIRY_DURATION.MONTH- ),- },- {- name: 'Expire in 1 year',- onClick: async () =>- await copyFileURLToClipboard(itemWithColumnIndex, URL_EXPIRY_DURATION.YEAR),- },- {- name: 'Custom expiry',- onClick: async () => setSelectedFileCustomExpiry(itemWithColumnIndex),- },- ],- },- {- name: 'Rename',- icon: <IconEdit size="tiny" />,- onClick: () => setSelectedItemToRename(itemWithColumnIndex),- },- {- name: 'Move',- icon: <IconMove size="tiny" />,- onClick: () => setSelectedItemsToMove([itemWithColumnIndex]),- },- {- name: 'Download',- icon: <IconDownload size="tiny" />,- onClick: async () => await downloadFile(itemWithColumnIndex),+ name: 'Delete',+ icon: <IconTrash2 size="tiny" />,+ onClick: () => setSelectedItemsToDelete([itemWithColumnIndex]),},- { name: 'Separator', icon: undefined, onClick: undefined },]: []),- {- name: 'Delete',- icon: <IconTrash2 size="tiny" />,- onClick: () => setSelectedItemsToDelete([itemWithColumnIndex]),- },]const size = item.metadata ? formatBytes(item.metadata.size) : '-'diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FolderContextMenu.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/FolderContextMenu.jsdeleted file mode 100644index 15ecfd3e311..00000000000--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FolderContextMenu.js+++ /dev/null@@ -1,29 +0,0 @@-import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'-import { Menu, Item, Separator } from 'react-contexify'-import 'react-contexify/dist/ReactContexify.css'-import { IconEdit, IconDownload, IconTrash2 } from 'ui'--const FolderContextMenu = ({ id = '', onRenameFolder = () => {}, onDeleteFolder = () => {} }) => {- const storageExplorerStore = useStorageStore()- const { downloadFolder } = storageExplorerStore-- return (- <Menu id={id} animation="fade" className="!bg-scale-300 border border-scale-500">- <Item onClick={({ props }) => onRenameFolder(props.item)}>- <IconEdit size="tiny" />- <span className="ml-2 text-xs">Rename</span>- </Item>- <Item onClick={({ props }) => downloadFolder(props.item)}>- <IconDownload size="tiny" />- <span className="ml-2 text-xs">Download</span>- </Item>- <Separator />- <Item onClick={({ props }) => onDeleteFolder(props.item)}>- <IconTrash2 size="tiny" />- <span className="ml-2 text-xs">Delete</span>- </Item>- </Menu>- )-}--export default FolderContextMenudiff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FolderContextMenu.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/FolderContextMenu.tsxnew file mode 100644index 00000000000..aedfa8e5c55--- /dev/null+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FolderContextMenu.tsx@@ -0,0 +1,44 @@+import { FC } from 'react'+import { Menu, Item, Separator } from 'react-contexify'+import 'react-contexify/dist/ReactContexify.css'+import { IconEdit, IconDownload, IconTrash2 } from 'ui'+import { PermissionAction } from '@supabase/shared-types/out/constants'++import { checkPermissions } from 'hooks'+import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'++interface Props {+ id: string+}++const FolderContextMenu: FC<Props> = ({ id = '' }) => {+ const storageExplorerStore = useStorageStore()+ const { downloadFolder, setSelectedItemToRename, setSelectedItemsToDelete } = storageExplorerStore+ const canUpdateFiles = checkPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')++ return (+ <Menu id={id} animation="fade" className="!bg-scale-300 border border-scale-500">+ {canUpdateFiles && (+ <Item onClick={({ props }) => setSelectedItemToRename(props.item)}>+ <IconEdit size="tiny" />+ <span className="ml-2 text-xs">Rename</span>+ </Item>+ )}+ <Item onClick={({ props }) => downloadFolder(props.item)}>+ <IconDownload size="tiny" />+ <span className="ml-2 text-xs">Download</span>+ </Item>+ {canUpdateFiles && (+ <>+ <Separator />+ <Item onClick={({ props }) => setSelectedItemsToDelete([props.item])}>+ <IconTrash2 size="tiny" />+ <span className="ml-2 text-xs">Delete</span>+ </Item>+ </>+ )}+ </Menu>+ )+}++export default FolderContextMenudiff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.tsxsimilarity index 66%rename from studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.jsrename to studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.tsxindex eb48047e271..e42be48fe5f 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.js+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.tsx@@ -1,12 +1,19 @@+import { FC } from 'react'import { observer } from 'mobx-react-lite'import { Menu, Item, Separator, Submenu } from 'react-contexify'import 'react-contexify/dist/ReactContexify.css'+import { PermissionAction } from '@supabase/shared-types/out/constants'import { IconClipboard, IconEdit, IconMove, IconDownload, IconTrash2, IconChevronRight } from 'ui'+import { checkPermissions } from 'hooks'import { URL_EXPIRY_DURATION } from '../Storage.constants'import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'-const ItemContextMenu = ({ id = '' }) => {+interface Props {+ id: string+}++const ItemContextMenu: FC<Props> = ({ id = '' }) => {const storageExplorerStore = useStorageStore()const {downloadFile,@@ -18,12 +25,13 @@ const ItemContextMenu = ({ id = '' }) => {copyFileURLToClipboard,} = storageExplorerStoreconst isPublic = selectedBucket.public+ const canUpdateFiles = checkPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')- const onHandleClick = async (event, item, expiresIn) => {+ const onHandleClick = async (event: any, item: any, expiresIn?: number) => {if (item.isCorrupted) returnswitch (event) {case 'copy':- if (expiresIn < 0) return setSelectedFileCustomExpiry(item)+ if (expiresIn !== undefined && expiresIn < 0) return setSelectedFileCustomExpiry(item)else return await copyFileURLToClipboard(item, expiresIn)case 'rename':return setSelectedItemToRename(item)@@ -73,23 +81,27 @@ const ItemContextMenu = ({ id = '' }) => {</Item></Submenu>)}- <Item onClick={({ props }) => onHandleClick('rename', props.item)}>- <IconEdit size="tiny" />- <span className="ml-2 text-xs">Rename</span>- </Item>- <Item onClick={({ props }) => onHandleClick('move', props.item)}>- <IconMove size="tiny" />- <span className="ml-2 text-xs">Move</span>- </Item>- <Item onClick={({ props }) => onHandleClick('download', props.item)}>- <IconDownload size="tiny" />- <span className="ml-2 text-xs">Download</span>- </Item>- <Separator />- <Item onClick={({ props }) => setSelectedItemsToDelete([props.item])}>- <IconTrash2 size="tiny" />- <span className="ml-2 text-xs">Delete</span>- </Item>+ {canUpdateFiles && (+ <>+ <Item onClick={({ props }) => onHandleClick('rename', props.item)}>+ <IconEdit size="tiny" />+ <span className="ml-2 text-xs">Rename</span>+ </Item>+ <Item onClick={({ props }) => onHandleClick('move', props.item)}>+ <IconMove size="tiny" />+ <span className="ml-2 text-xs">Move</span>+ </Item>+ <Item onClick={({ props }) => onHandleClick('download', props.item)}>+ <IconDownload size="tiny" />+ <span className="ml-2 text-xs">Download</span>+ </Item>+ <Separator />+ <Item onClick={({ props }) => setSelectedItemsToDelete([props.item])}>+ <IconTrash2 size="tiny" />+ <span className="ml-2 text-xs">Delete</span>+ </Item>+ </>+ )}</Menu>)}diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/MoveItemsModal.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/MoveItemsModal.tsxsimilarity index 83%rename from studio/components/to-be-cleaned/Storage/StorageExplorer/MoveItemsModal.jsrename to studio/components/to-be-cleaned/Storage/StorageExplorer/MoveItemsModal.tsxindex 0f85cf1fae2..709b4c5bcaf 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/MoveItemsModal.js+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/MoveItemsModal.tsx@@ -1,7 +1,15 @@-import { useEffect, useState } from 'react'-import { Modal, Button, Input, Space } from 'ui'+import { FC, useEffect, useState } from 'react'+import { Modal, Button, Input } from 'ui'-const MoveItemsModal = ({+interface Props {+ bucketName: string+ visible: boolean+ selectedItemsToMove: any[]+ onSelectCancel: () => void+ onSelectMove: (path: string) => void+}++const MoveItemsModal: FC<Props> = ({bucketName = '',visible = false,selectedItemsToMove = [],@@ -21,14 +29,14 @@ const MoveItemsModal = ({const title = multipleFiles? `Moving ${selectedItemsToMove.length} items within ${bucketName}`: selectedItemsToMove.length === 1- ? `Moving ${selectedItemsToMove[0].name} within ${bucketName}`+ ? `Moving ${selectedItemsToMove[0]?.name} within ${bucketName}`: ``const description = `Enter the path to where you'd like to move the file${multipleFiles ? 's' : ''} to.`- const onConfirmMove = (event) => {+ const onConfirmMove = (event: any) => {if (event) {event.preventDefault()}diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsxindex 205e6fbbba6..b23ba4f5a64 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx@@ -14,6 +14,10 @@ import {import SVG from 'react-inlinesvg'import { formatBytes } from 'lib/helpers'import { Transition } from '@headlessui/react'+import * as Tooltip from '@radix-ui/react-tooltip'+import { PermissionAction } from '@supabase/shared-types/out/constants'++import { checkPermissions } from 'hooks'import { URL_EXPIRY_DURATION } from '../Storage.constants'import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'@@ -107,6 +111,7 @@ const PreviewPane = () => {const mimeType = file.metadata ? file.metadata.mimetype : nullconst createdAt = file.created_at ? new Date(file.created_at).toLocaleString() : 'Unknown'const updatedAt = file.updated_at ? new Date(file.updated_at).toLocaleString() : 'Unknown'+ const canUpdateFiles = checkPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')return (<>@@ -238,15 +243,35 @@ const PreviewPane = () => {</Dropdown>)}</div>- <Button- type="outline"- shadow={false}- size="tiny"- icon={<IconTrash2 size={16} strokeWidth={2} />}- onClick={() => setSelectedItemsToDelete([file])}- >- Delete file- </Button>+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger>+ <Button+ type="outline"+ disabled={!canUpdateFiles}+ shadow={false}+ size="tiny"+ icon={<IconTrash2 size={16} strokeWidth={2} />}+ onClick={() => setSelectedItemsToDelete([file])}+ >+ Delete file+ </Button>+ </Tooltip.Trigger>+ {!canUpdateFiles && (+ <Tooltip.Content side="bottom">+ <Tooltip.Arrow className="radix-tooltip-arrow" />+ <div+ className={[+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',+ 'border border-scale-200',+ ].join(' ')}+ >+ <span className="text-xs text-scale-1200">+ You need additional permissions to delete this file+ </span>+ </div>+ </Tooltip.Content>+ )}+ </Tooltip.Root></div></div></Transition>diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.jsindex b19374ff0ba..b31a2d8f792 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js@@ -30,14 +30,10 @@ const StorageExplorer = observer(({ bucket }) => {selectedItemsToMove,clearSelectedItemsToMove,view,- setView,- setSortBy,- setSortByOrder,currentBucketName,openBucket,loadExplorerPreferences,- addNewFolderPlaceholder,fetchFolderContents,fetchMoreFolderContents,deleteFolder,@@ -116,10 +112,6 @@ const StorageExplorer = observer(({ bucket }) => {/** File manipulation methods */- const onSelectCreateFolder = (columnIndex = -1) => {- addNewFolderPlaceholder(columnIndex)- }-const onFilesUpload = async (event, columnIndex = -1) => {event.persist()const items = event.target.files || event.dataTransfer.items@@ -158,12 +150,6 @@ const StorageExplorer = observer(({ bucket }) => {clearSelectedItems()}- const onChangeView = (view) => setView(view)-- const onChangeSortBy = (sortBy) => setSortBy(sortBy)-- const onChangeSortByOrder = (sortByOrder) => setSortByOrder(sortByOrder)-return (<divref={storageExplorerRef}@@ -191,10 +177,6 @@ const StorageExplorer = observer(({ bucket }) => {onFilesUpload={onFilesUpload}onSelectAllItemsInColumn={onSelectAllItemsInColumn}onSelectColumnEmptySpace={onSelectColumnEmptySpace}- onSelectCreateFolder={onSelectCreateFolder}- onChangeView={onChangeView}- onChangeSortBy={onChangeSortBy}- onChangeSortByOrder={onChangeSortByOrder}onColumnLoadMore={(index, column) =>fetchMoreFolderContents(index, column, itemSearchString)}diff --git a/studio/lib/pingPostgrest.ts b/studio/lib/pingPostgrest.tsindex 623775327d8..ab1ee170d0a 100644--- a/studio/lib/pingPostgrest.ts+++ b/studio/lib/pingPostgrest.ts@@ -46,6 +46,7 @@ const getApiKey = async (timeout = DEFAULT_TIMEOUT_MILLISECONDS): Promise<string | undefined> => {const response = await getWithTimeout(`${API_URL}/props/project/${projectRef}/api`, { timeout })+ console.log('getApiKey', response)if (response.error || response.autoApiService.service_api_keys.length === 0) return undefinedreturn response.autoApiService.defaultApiKey}diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.jsindex 6f3f71576f2..79ca97307fd 100644--- a/studio/localStores/storageExplorer/StorageExplorerStore.js+++ b/studio/localStores/storageExplorer/StorageExplorerStore.js@@ -103,7 +103,7 @@ class StorageExplorerStore {initStore(projectRef, url, serviceKey, protocol = PROJECT_ENDPOINT_PROTOCOL) {this.projectRef = projectRefthis.endpoint = `${API_URL}/storage/${projectRef}`- this.initializeSupabaseClient(serviceKey, url, protocol)+ if (serviceKey !== undefined) this.initializeSupabaseClient(serviceKey, url, protocol)}/* Methods which are commonly used + For better readability */