diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/CustomExpiryModal.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/CustomExpiryModal.tsx index 26fbbd8c066..7c054875a92 100644 --- a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/CustomExpiryModal.tsx +++ b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/CustomExpiryModal.tsx @@ -4,10 +4,7 @@ import { Button, Form, Input, Listbox, Modal } from 'ui' import { DATETIME_FORMAT } from 'lib/constants' import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore' - -export interface CustomExpiryModalProps { - onCopyUrl: (name: string, url: string) => void -} +import { useCopyUrl } from './useCopyUrl' const unitMap = { days: 3600 * 24, @@ -16,8 +13,9 @@ const unitMap = { years: 3600 * 24 * 365, } -const CustomExpiryModal = ({ onCopyUrl }: CustomExpiryModalProps) => { +const CustomExpiryModal = () => { const storageExplorerStore = useStorageStore() + const { onCopyUrl } = useCopyUrl(storageExplorerStore.projectRef) const { getFileUrl, selectedFileCustomExpiry, setSelectedFileCustomExpiry } = storageExplorerStore const visible = selectedFileCustomExpiry !== undefined @@ -38,9 +36,9 @@ const CustomExpiryModal = ({ onCopyUrl }: CustomExpiryModalProps) => { initialValues={{ expiresIn: '', units: 'days' }} onSubmit={async (values: any, { setSubmitting }: any) => { setSubmitting(true) - onCopyUrl( + await onCopyUrl( selectedFileCustomExpiry!.name, - await getFileUrl( + getFileUrl( selectedFileCustomExpiry!, values.expiresIn * unitMap[values.units as 'days' | 'weeks' | 'months' | 'years'] ) diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.tsx index 1993b1695f1..85135c5b0ec 100644 --- a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.tsx +++ b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.tsx @@ -20,7 +20,6 @@ export interface FileExplorerProps { onSelectAllItemsInColumn: (index: number) => void onSelectColumnEmptySpace: (index: number) => void onColumnLoadMore: (index: number, column: StorageColumn) => void - onCopyUrl: (name: string, url: string) => void } const FileExplorer = ({ @@ -34,7 +33,6 @@ const FileExplorer = ({ onSelectAllItemsInColumn = noop, onSelectColumnEmptySpace = noop, onColumnLoadMore = noop, - onCopyUrl = noop, }: FileExplorerProps) => { const fileExplorerRef = useRef(null) @@ -53,7 +51,7 @@ const FileExplorer = ({ className="file-explorer flex flex-grow overflow-x-auto justify-between h-full w-full" > - + {view === STORAGE_VIEWS.COLUMNS ? (
@@ -71,7 +69,6 @@ const FileExplorer = ({ onSelectAllItemsInColumn={onSelectAllItemsInColumn} onSelectColumnEmptySpace={onSelectColumnEmptySpace} onColumnLoadMore={onColumnLoadMore} - onCopyUrl={onCopyUrl} /> ))}
@@ -90,7 +87,6 @@ const FileExplorer = ({ onSelectAllItemsInColumn={onSelectAllItemsInColumn} onSelectColumnEmptySpace={onSelectColumnEmptySpace} onColumnLoadMore={onColumnLoadMore} - onCopyUrl={onCopyUrl} /> )} diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.tsx index e4b559a1c53..29d3e83ac51 100644 --- a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.tsx +++ b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.tsx @@ -66,7 +66,6 @@ export interface FileExplorerColumnProps { onSelectAllItemsInColumn: (index: number) => void onSelectColumnEmptySpace: (index: number) => void onColumnLoadMore: (index: number, column: StorageColumn) => void - onCopyUrl: (name: string, url: string) => void } const FileExplorerColumn = ({ @@ -82,7 +81,6 @@ const FileExplorerColumn = ({ onSelectAllItemsInColumn = noop, onSelectColumnEmptySpace = noop, onColumnLoadMore = noop, - onCopyUrl = noop, }: FileExplorerColumnProps) => { const [isDraggedOver, setIsDraggedOver] = useState(false) const fileExplorerColumnRef = useRef(null) @@ -224,7 +222,6 @@ const FileExplorerColumn = ({ selectedItems, openedFolders, selectedFilePreview, - onCopyUrl, }} ItemComponent={FileExplorerRow} getItemSize={(index) => (index !== 0 && index === columnItems.length ? 85 : 37)} diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx index e6100d4f1b7..23979d4149b 100644 --- a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx +++ b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx @@ -43,6 +43,7 @@ import { import { StorageItem, StorageItemWithColumn } from '../Storage.types' import FileExplorerRowEditing from './FileExplorerRowEditing' import { copyPathToFolder } from './StorageExplorer.utils' +import { useCopyUrl } from './useCopyUrl' export const RowIcon = ({ view, @@ -97,7 +98,6 @@ export interface FileExplorerRowProps { selectedItems: StorageItemWithColumn[] openedFolders: StorageItem[] selectedFilePreview: (StorageItemWithColumn & { previewUrl: string | undefined }) | null - onCopyUrl: (name: string, url: string) => void } const FileExplorerRow: ItemRenderer = ({ @@ -108,7 +108,6 @@ const FileExplorerRow: ItemRenderer = ({ selectedItems = [], openedFolders = [], selectedFilePreview, - onCopyUrl, }) => { const storageExplorerStore = useStorageStore() const { @@ -130,6 +129,7 @@ const FileExplorerRow: ItemRenderer = ({ downloadFolder, selectRangeItems, } = storageExplorerStore + const { onCopyUrl } = useCopyUrl(storageExplorerStore.projectRef) const isPublic = selectedBucket.public const itemWithColumnIndex = { ...item, columnIndex } @@ -213,11 +213,8 @@ const FileExplorerRow: ItemRenderer = ({ { name: 'Get URL', icon: , - onClick: async () => - onCopyUrl( - itemWithColumnIndex.name, - await getFileUrl(itemWithColumnIndex) - ), + onClick: () => + onCopyUrl(itemWithColumnIndex.name, getFileUrl(itemWithColumnIndex)), }, ] : [ @@ -227,26 +224,26 @@ const FileExplorerRow: ItemRenderer = ({ children: [ { name: 'Expire in 1 week', - onClick: async () => + onClick: () => onCopyUrl( itemWithColumnIndex.name, - await getFileUrl(itemWithColumnIndex, URL_EXPIRY_DURATION.WEEK) + getFileUrl(itemWithColumnIndex, URL_EXPIRY_DURATION.WEEK) ), }, { name: 'Expire in 1 month', - onClick: async () => + onClick: () => onCopyUrl( itemWithColumnIndex.name, - await getFileUrl(itemWithColumnIndex, URL_EXPIRY_DURATION.MONTH) + getFileUrl(itemWithColumnIndex, URL_EXPIRY_DURATION.MONTH) ), }, { name: 'Expire in 1 year', - onClick: async () => + onClick: () => onCopyUrl( itemWithColumnIndex.name, - await getFileUrl(itemWithColumnIndex, URL_EXPIRY_DURATION.YEAR) + getFileUrl(itemWithColumnIndex, URL_EXPIRY_DURATION.YEAR) ), }, { diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.tsx index 4d85b0afdac..a556a9e6b45 100644 --- a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.tsx +++ b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.tsx @@ -1,5 +1,4 @@ import { PermissionAction } from '@supabase/shared-types/out/constants' -import { noop } from 'lodash' import { observer } from 'mobx-react-lite' import { Item, Menu, Separator, Submenu } from 'react-contexify' import 'react-contexify/dist/ReactContexify.css' @@ -9,13 +8,13 @@ import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStor import { IconChevronRight, IconClipboard, IconDownload, IconEdit, IconMove, IconTrash2 } from 'ui' import { URL_EXPIRY_DURATION } from '../Storage.constants' import { StorageItemWithColumn } from '../Storage.types' +import { useCopyUrl } from './useCopyUrl' interface ItemContextMenuProps { id: string - onCopyUrl: (name: string, url: string) => void } -const ItemContextMenu = ({ id = '', onCopyUrl = noop }: ItemContextMenuProps) => { +const ItemContextMenu = ({ id = '' }: ItemContextMenuProps) => { const storageExplorerStore = useStorageStore() const { getFileUrl, @@ -26,6 +25,7 @@ const ItemContextMenu = ({ id = '', onCopyUrl = noop }: ItemContextMenuProps) => setSelectedItemsToMove, setSelectedFileCustomExpiry, } = storageExplorerStore + const { onCopyUrl } = useCopyUrl(storageExplorerStore.projectRef) const isPublic = selectedBucket.public const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*') @@ -34,7 +34,7 @@ const ItemContextMenu = ({ id = '', onCopyUrl = noop }: ItemContextMenuProps) => switch (event) { case 'copy': if (expiresIn !== undefined && expiresIn < 0) return setSelectedFileCustomExpiry(item) - else return onCopyUrl(item.name, await getFileUrl(item, expiresIn)) + else return onCopyUrl(item.name, getFileUrl(item, expiresIn)) case 'rename': return setSelectedItemToRename(item) case 'move': diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx index 46e54d136e6..b3f335694cb 100644 --- a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx +++ b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx @@ -23,6 +23,7 @@ import { IconX, } from 'ui' import { URL_EXPIRY_DURATION } from '../Storage.constants' +import { useCopyUrl } from './useCopyUrl' const PreviewFile = ({ mimeType, previewUrl }: { mimeType?: string; previewUrl?: string }) => { if (!mimeType || !previewUrl) { @@ -99,11 +100,7 @@ const PreviewFile = ({ mimeType, previewUrl }: { mimeType?: string; previewUrl?: ) } -export interface PreviewPaneProps { - onCopyUrl: (name: string, url: string) => void -} - -const PreviewPane = ({ onCopyUrl }: PreviewPaneProps) => { +const PreviewPane = () => { const storageExplorerStore = useStorageStore() const { getFileUrl, @@ -114,6 +111,7 @@ const PreviewPane = ({ onCopyUrl }: PreviewPaneProps) => { setSelectedItemsToDelete, setSelectedFileCustomExpiry, } = storageExplorerStore + const { onCopyUrl } = useCopyUrl(storageExplorerStore.projectRef) const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*') @@ -208,7 +206,7 @@ const PreviewPane = ({ onCopyUrl }: PreviewPaneProps) => {