Skip to content

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

Update Storage to show corrupted files or files that are still uploading based on if metadata is missing and the created_at timestamp

Joshen Limdab7b75ed1f7
diff --git a/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyRow.tsx b/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyRow.tsx
index d1d9634c4d3..ec4bca7b382 100644
--- a/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyRow.tsx
+++ b/studio/components/interfaces/Authentication/Policies/PolicyTableRow/PolicyRow.tsx
@@ -14,7 +14,6 @@ const PolicyRow: FC<Props> = ({
onSelectEditPolicy = () => {},
onSelectDeletePolicy = () => {},
}) => {
- console.log('Policy', policy)
return (
<Panel.Content
className={[
diff --git a/studio/components/layouts/StorageLayout/StorageMenu.tsx b/studio/components/layouts/StorageLayout/StorageMenu.tsx
index ae782fa79f7..d4f2cd777f4 100644
--- a/studio/components/layouts/StorageLayout/StorageMenu.tsx
+++ b/studio/components/layouts/StorageLayout/StorageMenu.tsx
@@ -61,7 +61,7 @@ const StorageMenu: FC<Props> = () => {
<div>
<Menu.Group title="All buckets" />
{!loaded ? (
- <div className="py-2 px-4 flex items-center space-x-2">
+ <div className="py-2 px-2 flex items-center space-x-2">
<IconLoader className="animate-spin" size={14} strokeWidth={2} />
<span className="text-sm">Loading buckets</span>
</div>
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/ConfirmDeleteModal.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/ConfirmDeleteModal.js
index 9afd9176cac..c960fca85cd 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/ConfirmDeleteModal.js
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/ConfirmDeleteModal.js
@@ -36,7 +36,7 @@ const ConfirmDeleteModal = ({
<Modal
visible={visible}
header={<span className="break-words">{title}</span>}
- size="small"
+ size="medium"
onCancel={onSelectCancel}
customFooter={
<div className="flex items-center gap-2">
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js
index 727e53c17a4..ee32fb3ecd8 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js
@@ -151,7 +151,7 @@ const FileExplorerColumn = ({
{/* Checkbox selection for select all */}
{view === STORAGE_VIEWS.COLUMNS && (
<div
- className={`bg-table-header-light dark:bg-table-header-dark sticky top-0 z-10 flex items-center px-4 mb-0 ${
+ className={`bg-table-header-light dark:bg-table-header-dark sticky top-0 z-10 flex items-center px-2.5 mb-0 ${
haveSelectedItems > 0 ? 'opacity-100 py-3 h-10' : 'opacity-0 py-0 h-0'
} transition-all duration-200`}
onClick={(event) => event.stopPropagation()}
@@ -172,7 +172,7 @@ const FileExplorerColumn = ({
<div
className="
bg-panel-footer-light dark:bg-panel-footer-dark
- px-4 py-2 flex items-center min-w-min sticky top-0 z-10
+ px-2.5 py-2 flex items-center min-w-min sticky top-0 z-10
border-b border-panel-border-light dark:border-panel-border-dark
"
>
@@ -264,7 +264,7 @@ const FileExplorerColumn = ({
<div
className="
bg-panel-footer-light dark:bg-panel-footer-dark
- px-4 py-2 flex items-center min-w-min sticky bottom-0 z-10
+ px-2.5 py-2 flex items-center min-w-min sticky bottom-0 z-10
"
>
<p className="text-sm">
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.js
index 8209a9efc95..3c00b2a7943 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.js
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.js
@@ -372,7 +372,7 @@ const FileExplorerHeader = ({
disabled={breadcrumbs.length === 0}
onClick={onSelectUpload}
>
- Upload file
+ Upload files
</Button>
<Button
icon={<IconFolderPlus size={16} strokeWidth={2} />}
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.js
index 7c4380f8fe1..d1097abad96 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.js
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.js
@@ -9,6 +9,7 @@ import {
IconMusic,
IconFilm,
IconFile,
+ IconAlertCircle,
} from '@supabase/ui'
import SVG from 'react-inlinesvg'
import { useContextMenu } from 'react-contexify'
@@ -106,7 +107,7 @@ const FileExplorerRow = ({
return (
<div className="storage-row flex items-center justify-between rounded bg-gray-500">
- <div className="flex flex-grow items-center h-full px-4">
+ <div className="flex flex-grow items-center h-full px-2.5">
<div className="">
<RowIcon
view={view}
@@ -142,10 +143,14 @@ const FileExplorerRow = ({
{ name: 'Delete', onClick: () => onSelectItemDelete(itemWithColumnIndex) },
]
: [
- { name: 'Copy URL', onClick: () => onCopyFileURL(itemWithColumnIndex) },
- { name: 'Rename', onClick: () => onSelectItemRename(itemWithColumnIndex) },
- { name: 'Move', onClick: () => onSelectItemMove(itemWithColumnIndex) },
- { name: 'Download', onClick: () => onDownloadFile(itemWithColumnIndex) },
+ ...(!item.isCorrupted
+ ? [
+ { name: 'Copy URL', onClick: () => onCopyFileURL(itemWithColumnIndex) },
+ { name: 'Rename', onClick: () => onSelectItemRename(itemWithColumnIndex) },
+ { name: 'Move', onClick: () => onSelectItemMove(itemWithColumnIndex) },
+ { name: 'Download', onClick: () => onDownloadFile(itemWithColumnIndex) },
+ ]
+ : []),
{ name: 'Delete', onClick: () => onSelectItemDelete(itemWithColumnIndex) },
]
@@ -179,7 +184,7 @@ const FileExplorerRow = ({
>
<div
className={`
- storage-row px-4 flex items-center justify-between hover:bg-panel-footer-light dark:hover:bg-panel-footer-dark
+ storage-row px-2.5 flex items-center justify-between hover:bg-panel-footer-light dark:hover:bg-panel-footer-dark
${isOpened ? 'bg-scale-400' : ''} ${
isPreviewed ? 'bg-green-500 hover:bg-green-500 dark:hover:bg-green-500' : ''
} ${view === STORAGE_VIEWS.LIST ? 'min-w-min' : ''}
@@ -190,7 +195,7 @@ const FileExplorerRow = ({
{/* Row Checkbox / Row Icon */}
<div
className="relative group"
- style={{ width: view === STORAGE_VIEWS.COLUMNS ? '15%' : 'auto' }}
+ style={{ minWidth: view === STORAGE_VIEWS.COLUMNS ? '10%' : 'auto' }}
onClick={(event) => event.stopPropagation()}
>
{!isSelected && (
@@ -233,7 +238,12 @@ const FileExplorerRow = ({
}}
>
{view === STORAGE_VIEWS.COLUMNS ? (
- <p className="text-sm w-full truncate">{item.name}</p>
+ <div className="flex items-center space-x-1 w-full">
+ <p className="text-sm w-full truncate">{item.name}</p>
+ {item.isCorrupted && (
+ <IconAlertCircle size={18} strokeWidth={2} className="text-scale-1000" />
+ )}
+ </div>
) : (
<>
<p className="text-sm truncate w-[30%] min-w-[250px]">{item.name}</p>
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.js
index 241f4ae668e..993fd661b14 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.js
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/ItemContextMenu.js
@@ -10,12 +10,32 @@ const ItemContextMenu = ({
onSelectItemDelete = () => {},
}) => {
return (
- <Menu id={id} animation="fade">
- <Item onClick={({ props }) => onCopyFileURL(props.item)}>Copy URL</Item>
- <Item onClick={({ props }) => onSelectItemRename(props.item)}>Rename</Item>
- <Item onClick={({ props }) => onSelectItemMove(props.item)}>Move</Item>
- <Item onClick={({ props }) => onDownloadFile(props.item)}>Download</Item>
- <Item onClick={({ props }) => onSelectItemDelete(props.item)}>Delete</Item>
+ <Menu id={id} animation="fade" className="!bg-scale-300 border border-scale-500">
+ <Item
+ onClick={({ props }) => (!props.item.isCorrupted ? onCopyFileURL(props.item) : () => {})}
+ >
+ <span className="text-xs">Copy URL</span>
+ </Item>
+ <Item
+ onClick={({ props }) =>
+ !props.item.isCorrupted ? onSelectItemRename(props.item) : () => {}
+ }
+ >
+ <span className="text-xs">Rename</span>
+ </Item>
+ <Item
+ onClick={({ props }) => (!props.item.isCorrupted ? onSelectItemMove(props.item) : () => {})}
+ >
+ <span className="text-xs">Move</span>
+ </Item>
+ <Item
+ onClick={({ props }) => (!props.item.isCorrupted ? onDownloadFile(props.item) : () => {})}
+ >
+ <span className="text-xs">Download</span>
+ </Item>
+ <Item onClick={({ props }) => onSelectItemDelete(props.item)}>
+ <span className="text-xs">Delete</span>
+ </Item>
</Menu>
)
}
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.js
index d9fc37a3b40..203296f90cf 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.js
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.js
@@ -1,4 +1,12 @@
-import { Button, IconX, IconLoader, IconClipboard, IconDownload, IconTrash2 } from '@supabase/ui'
+import {
+ Button,
+ IconX,
+ IconLoader,
+ IconClipboard,
+ IconDownload,
+ IconTrash2,
+ IconAlertCircle,
+} from '@supabase/ui'
import SVG from 'react-inlinesvg'
import { formatBytes } from 'lib/helpers'
import { Transition } from '@headlessui/react'
@@ -130,6 +138,14 @@ const PreviewPane = ({
{/* Preview Information */}
<div className="space-y-1">
<h5 className="text-scale-1200 break-words text-base">{file.name}</h5>
+ {file.isCorrupted && (
+ <div className="flex items-center space-x-2">
+ <IconAlertCircle size={14} strokeWidth={2} className="text-scale-1100" />
+ <p className="text-sm text-scale-1100">
+ File is corrupted, please delete and reupload this file again
+ </p>
+ </div>
+ )}
{mimeType && (
<p className="text-sm text-scale-1100">
{mimeType}
@@ -156,6 +172,7 @@ const PreviewPane = ({
type="default"
icon={<IconDownload size={16} strokeWidth={2} />}
onClick={() => onDownloadFile(file)}
+ disabled={file.isCorrupted}
>
Download
</Button>
@@ -163,6 +180,7 @@ const PreviewPane = ({
type="outline"
icon={<IconClipboard size={16} strokeWidth={2} />}
onClick={() => onCopyFileURL(file)}
+ disabled={file.isCorrupted}
>
Copy URL
</Button>
diff --git a/studio/components/to-be-cleaned/Storage/StorageSidebar.js b/studio/components/to-be-cleaned/Storage/StorageSidebar.js
deleted file mode 100644
index 1623eed2074..00000000000
--- a/studio/components/to-be-cleaned/Storage/StorageSidebar.js
+++ /dev/null
@@ -1,191 +0,0 @@
-import {
- Badge,
- Button,
- Dropdown,
- Space,
- Menu,
- IconLoader,
- IconPlus,
- IconMoreVertical,
- Typography,
-} from '@supabase/ui'
-import Link from 'next/link'
-import { useRouter } from 'next/router'
-import { STORAGE_ROW_STATUS } from './Storage.constants'
-import Flag from 'components/ui/Flag/Flag'
-
-// [Joshen] I think this file is no longer in use, double check before removing (replaced by StorageMenu.tsx)
-
-const BucketRow = ({
- bucket = {},
- projectRef = '',
- isSelected = false,
- onSelectBucket = () => {},
- onSelectDeleteBucket = () => {},
- onSelectToggleBucketPublic = () => {},
-}) => {
- const bucketOptions = [
- {
- name: 'Delete bucket',
- onClick: () => onSelectDeleteBucket(bucket),
- },
- {
- name: bucket.public ? 'Make private' : 'Make public',
- onClick: () => onSelectToggleBucketPublic(bucket),
- },
- ]
- return (
- <div className="group">
- <Menu.Item rounded active={isSelected} onClick={() => onSelectBucket(bucket)}>
- <div className="flex items-center justify-between">
- {/* Need to investigate, why links here are reopning the entire page */}
- <Link href={`/project/${projectRef}/storage/buckets/${bucket.id}`}>
- <a className="w-full">
- <div className="flex items-center space-x-2">
- <Typography.Text>{bucket.name}</Typography.Text>
- {bucket.public && <Badge color="yellow">Public</Badge>}
- </div>
- </a>
- </Link>
-
- {bucket.status === STORAGE_ROW_STATUS.LOADING && (
- <IconLoader className="animate-spin" size={16} strokeWidth={2} />
- )}
- {bucket.status === STORAGE_ROW_STATUS.READY && (
- <Dropdown
- side="bottom"
- align="end"
- overlay={[
- bucketOptions.map((option) => (
- <Dropdown.Item key={option.name} onClick={option.onClick}>
- {option.name}
- </Dropdown.Item>
- )),
- ]}
- >
- <Typography.Text>
- <IconMoreVertical
- className="opacity-0 group-hover:opacity-100"
- size="tiny"
- strokeWidth={2}
- />
- </Typography.Text>
- </Dropdown>
- )}
- </div>
- </Menu.Item>
- </div>
- )
-}
-
-const StorageSidebar = ({
- loaded = false,
- buckets = [],
- onSelectCreateBucket = () => {},
- onSelectDeleteBucket = () => {},
- onSelectToggleBucketPublic = () => {},
-}) => {
- const router = useRouter()
- const { ref, bucketId } = router.query
-
- return (
- <Space direction={'vertical'} className="mt-4" size={8}>
- <Menu>
- <div className="my-2 px-3">
- <Menu.Misc>
- <Button
- block
- className="mx-1"
- icon={<IconPlus />}
- type="text"
- style={{ justifyContent: 'start' }}
- onClick={onSelectCreateBucket}
- >
- New bucket
- </Button>
- </Menu.Misc>
- </div>
- <div className="my-2 px-3">
- <Menu.Group title="All Buckets" />
- <div className="space-y-1">
- {!loaded ? (
- <div className="flex items-center px-4 space-x-2">
- <Typography.Text>
- <IconLoader className="animate-spin" size="tiny" strokeWidth={2} />
- </Typography.Text>
- <span className="text-xs">Loading buckets</span>
- </div>
- ) : (
- <>
- {buckets.length === 0 && (
- <Typography.Text type="secondary">
- <p className="mx-4 my-2 text-sm">No buckets available</p>
- </Typography.Text>
- )}
- {buckets.map((bucket, idx) => {
- const isSelected = bucketId === bucket.id
- return (
- <BucketRow
- key={`${idx}_${bucket.id}`}
- bucket={bucket}
- projectRef={ref}
- isSelected={isSelected}
- onSelectDeleteBucket={onSelectDeleteBucket}
- onSelectToggleBucketPublic={onSelectToggleBucketPublic}
- />
- )
- })}
- </>
- )}
- </div>
- </div>
- <div className="my-4 px-3">
- <Menu.Group title="Configuration" />
- <div className="space-y-1">
- <div>
- <Link href={`/project/${ref}/storage/settings`}>
- <a>
- <Menu.Item
- key="settings"
- rounded
- active={router.pathname === '/project/[ref]/storage/settings'}
- >
- <Typography.Text>Settings</Typography.Text>
- </Menu.Item>
- </a>
- </Link>
- </div>
- <div>
- <Link href={`/project/${ref}/storage/policies`}>
- <a>
- <Menu.Item
- key="policies"
- rounded
- active={router.pathname === '/project/[ref]/storage/policies'}
- >
- <Typography.Text>Policies</Typography.Text>
- </Menu.Item>
- </a>
- </Link>
- </div>
- <div>
- <Link href={`/project/${ref}/storage/usage`}>
- <a>
- <Menu.Item
- key="usage"
- rounded
- active={router.pathname === '/project/[ref]/storage/usage'}
- >
- <Typography.Text>Usage</Typography.Text>
- </Menu.Item>
- </a>
- </Link>
- </div>
- </div>
- </div>
- </Menu>
- </Space>
- )
-}
-
-export default StorageSidebar
diff --git a/studio/components/to-be-cleaned/Storage/index.js b/studio/components/to-be-cleaned/Storage/index.js
index e903df9cd68..538c6ff0f6c 100644
--- a/studio/components/to-be-cleaned/Storage/index.js
+++ b/studio/components/to-be-cleaned/Storage/index.js
@@ -2,7 +2,6 @@ import StorageExplorer from './StorageExplorer/StorageExplorer'
import StoragePolicies from './StoragePolicies/StoragePolicies'
import StorageSettings from './StorageSettings/StorageSettings'
import StorageUsage from './StorageUsage/StorageUsage'
-import StorageSidebar from './StorageSidebar'
import CreateBucketModal from './CreateBucketModal'
import DeleteBucketModal from './DeleteBucketModal'
@@ -13,7 +12,6 @@ export {
StoragePolicies,
StorageSettings,
StorageUsage,
- StorageSidebar,
CreateBucketModal,
DeleteBucketModal,
ToggleBucketPublicModal,
diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.js
index 8131fe8770f..aca09a1ba00 100644
--- a/studio/localStores/storageExplorer/StorageExplorerStore.js
+++ b/studio/localStores/storageExplorer/StorageExplorerStore.js
@@ -43,6 +43,7 @@ export const useStorageExplorerStore = () => {
return useContext(StorageExplorerContext)
}
+const CORRUPTED_THRESHOLD_MS = 15 * 60 * 1000 // 15 minutes
const LIMIT = 200
const OFFSET = 0
const DEFAULT_EXPIRY = 10 * 365 * 24 * 60 * 60 // in seconds, default to 1 year
@@ -1344,11 +1345,22 @@ class StorageExplorerStore {
items
?.filter((item) => item.name !== EMPTY_FOLDER_PLACEHOLDER_FILE_NAME)
.map((item) => {
- const itemObj = {
- ...item,
- type: item.id ? STORAGE_ROW_TYPES.FILE : STORAGE_ROW_TYPES.FOLDER,
- status: STORAGE_ROW_STATUS.READY,
- }
+ const type = item.id ? STORAGE_ROW_TYPES.FILE : STORAGE_ROW_TYPES.FOLDER
+
+ const durationSinceCreated = Number(new Date()) - Number(new Date(item.created_at))
+ const isCorrupted =
+ type === STORAGE_ROW_TYPES.FILE &&
+ !item.metadata &&
+ durationSinceCreated >= CORRUPTED_THRESHOLD_MS
+
+ const status =
+ type === STORAGE_ROW_TYPES.FILE &&
+ !item.metadata &&
+ durationSinceCreated <= CORRUPTED_THRESHOLD_MS
+ ? STORAGE_ROW_STATUS.LOADING
+ : STORAGE_ROW_STATUS.READY
+
+ const itemObj = { ...item, type, status, isCorrupted }
return itemObj
}) ?? []
return formattedItems