Skip to content

Commit a53ad76

Browse files
committed
Add progress percentage indication for deleting files and improve toast loader for storage upload and delete files
1 parent afc27a9 commit a53ad76

File tree

8 files changed

+62
-32
lines changed

8 files changed

+62
-32
lines changed

studio/components/interfaces/App/PortalToast.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const PortalToast = () => (
1515
position="top-right"
1616
toastOptions={{
1717
className:
18-
'bg-bg-primary-light dark:bg-bg-primary-dark text-typography-body-strong-light dark:text-typography-body-strong-dark border dark:border-dark',
18+
'bg-bg-primary-light dark:bg-bg-primary-dark text-typography-body-strong-light dark:text-typography-body-strong-dark border dark:border-dark !max-w-[380px]',
1919
style: {
2020
padding: '8px',
2121
paddingLeft: '16px',

studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ProjectDropdown from './ProjectDropdown'
1010
import FeedbackDropdown from './FeedbackDropdown'
1111
import HelpPopover from './HelpPopover'
1212
import NotificationsPopover from './NotificationsPopover'
13-
import { Badge } from 'ui'
13+
import { Badge, Button } from 'ui'
1414
import { getResourcesExceededLimits } from 'components/ui/OveragesBanner/OveragesBanner.utils'
1515

1616
const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder = true }: any) => {
@@ -91,6 +91,18 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder =
9191
</div>
9292
<div className="flex items-center space-x-2">
9393
{customHeaderComponents && customHeaderComponents}
94+
<Button
95+
onClick={() =>
96+
ui.setNotification({
97+
category: 'loading',
98+
message: 'Uploading 24 files...',
99+
description: "Please do not close the browser until it's completed",
100+
progress: 50,
101+
})
102+
}
103+
>
104+
Click
105+
</Button>
94106
{IS_PLATFORM && <HelpPopover />}
95107
{IS_PLATFORM && <FeedbackDropdown />}
96108
{IS_PLATFORM && <NotificationsPopover />}

studio/components/to-be-cleaned/Storage/StorageExplorer/ConfirmDeleteModal.js renamed to studio/components/to-be-cleaned/Storage/StorageExplorer/ConfirmDeleteModal.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { useEffect, useState } from 'react'
1+
import { FC, useEffect, useState } from 'react'
22
import { Modal, Button, Alert } from 'ui'
33

4-
const ConfirmDeleteModal = ({
4+
interface Props {
5+
visible: boolean
6+
selectedItemsToDelete: any[]
7+
onSelectCancel: () => void
8+
onSelectDelete: () => void
9+
}
10+
11+
const ConfirmDeleteModal: FC<Props> = ({
512
visible = false,
613
selectedItemsToDelete = [],
714
onSelectCancel = () => {},

studio/hooks/misc/useStore.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const StoreProvider: FC<StoreProvider> = ({ children, rootStore }) => {
4949

5050
autorun(() => {
5151
if (ui.notification) {
52-
const { id, category, error, message, progress, duration } = ui.notification
52+
const { id, category, error, message, description, progress, duration } = ui.notification
5353
const toastDuration = duration || 4000
5454
switch (category) {
5555
case 'info':
@@ -60,20 +60,20 @@ export const StoreProvider: FC<StoreProvider> = ({ children, rootStore }) => {
6060
console.error('Error:', { error, message })
6161
return toast.error(message, { id, duration: duration || Infinity })
6262
case 'loading':
63-
if (progress) {
63+
if (progress !== undefined) {
6464
return toast.loading(
65-
<div
66-
className="flex flex-col space-y-1"
67-
style={{ minWidth: '200px', maxWidth: '267px' }}
68-
>
65+
<div className="flex flex-col space-y-2" style={{ minWidth: '220px' }}>
6966
<SparkBar
7067
value={progress}
7168
max={100}
7269
type="horizontal"
73-
barClass="bg-green-500"
70+
barClass="bg-brand-900"
7471
labelBottom={message}
7572
labelTop={`${progress.toFixed(2)}%`}
7673
/>
74+
{description !== undefined && (
75+
<p className="text-xs text-scale-1100">{description}</p>
76+
)}
7777
</div>,
7878
{ id }
7979
)

studio/localStores/storageExplorer/StorageExplorerStore.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ const LIMIT = 200
5050
const OFFSET = 0
5151
const DEFAULT_EXPIRY = 10 * 365 * 24 * 60 * 60 // in seconds, default to 1 year
5252
const PREVIEW_SIZE_LIMIT = 10000000 // 10MB
53-
const BATCH_SIZE = 10
53+
// const BATCH_SIZE = 10
54+
const BATCH_SIZE = 2
5455
const EMPTY_FOLDER_PLACEHOLDER_FILE_NAME = '.emptyFolderPlaceholder'
56+
const STORAGE_PROGRESS_INFO_TEXT = "Please do not close the browser until it's completed"
5557

5658
class StorageExplorerStore {
5759
projectRef = ''
@@ -646,14 +648,14 @@ class StorageExplorerStore {
646648
.map((folder) => folder.name)
647649
.join('/')
648650

649-
const infoToastId = toast('Please do not close the browser until the upload is completed', {
650-
duration: Infinity,
651-
})
652-
const toastId = toast.loading(
653-
`Uploading ${formattedFilesToUpload.length} file${
651+
const toastId = this.ui.setNotification({
652+
category: 'loading',
653+
message: `Uploading ${formattedFilesToUpload.length} file${
654654
formattedFilesToUpload.length > 1 ? 's' : ''
655-
}`
656-
)
655+
}...`,
656+
description: STORAGE_PROGRESS_INFO_TEXT,
657+
progress: 0,
658+
})
657659

658660
// Upload files in batches
659661
const promises = formattedFilesToUpload.map((file) => {
@@ -722,12 +724,15 @@ class StorageExplorerStore {
722724
await batchedPromises.reduce(async (previousPromise, nextBatch) => {
723725
await previousPromise
724726
await Promise.allSettled(nextBatch.map((batch) => batch()))
725-
toast.loading(
726-
`Uploading ${formattedFilesToUpload.length} file${
727+
this.ui.setNotification({
728+
id: toastId,
729+
category: 'loading',
730+
message: `Uploading ${formattedFilesToUpload.length} file${
727731
formattedFilesToUpload.length > 1 ? 's' : ''
728-
}... (${(this.uploadProgress * 100).toFixed(2)}%)`,
729-
{ id: toastId }
730-
)
732+
}...`,
733+
description: STORAGE_PROGRESS_INFO_TEXT,
734+
progress: this.uploadProgress * 100,
735+
})
731736
}, Promise.resolve())
732737

733738
if (numberOfFilesUploadedSuccess > 0) {
@@ -767,7 +772,6 @@ class StorageExplorerStore {
767772
category: 'error',
768773
})
769774
}
770-
toast.dismiss(infoToastId)
771775

772776
const t2 = new Date()
773777
console.log(
@@ -865,9 +869,7 @@ class StorageExplorerStore {
865869

866870
deleteFiles = async (files, isDeleteFolder = false) => {
867871
this.closeFilePreview()
868-
const infoToastId = toast('Please do not close the browser until the delete is completed', {
869-
duration: Infinity,
870-
})
872+
let progress = 0
871873

872874
// If every file has the 'prefix' property, then just construct the prefix
873875
// directly (from delete folder). Otherwise go by the opened folders.
@@ -887,18 +889,28 @@ class StorageExplorerStore {
887889

888890
const toastId = this.ui.setNotification({
889891
category: 'loading',
890-
message: `Deleting ${prefixes.length} file(s)`,
892+
message: `Deleting ${prefixes.length} file(s)...`,
893+
description: STORAGE_PROGRESS_INFO_TEXT,
894+
progress: 0,
891895
})
892896

893897
// batch BATCH_SIZE prefixes per request
894898
const batches = chunk(prefixes, BATCH_SIZE).map((batch) => () => {
899+
progress = progress + batch.length / prefixes.length
895900
return this.supabaseClient.storage.from(this.selectedBucket.name).remove(batch)
896901
})
897902

898903
// make BATCH_SIZE requests at the same time
899904
await chunk(batches, BATCH_SIZE).reduce(async (previousPromise, nextBatch) => {
900905
await previousPromise
901906
await Promise.all(nextBatch.map((batch) => batch()))
907+
this.ui.setNotification({
908+
id: toastId,
909+
category: 'loading',
910+
message: `Deleting ${prefixes.length} file(s)...`,
911+
description: STORAGE_PROGRESS_INFO_TEXT,
912+
progress: progress * 100,
913+
})
902914
}, Promise.resolve())
903915

904916
// Clear file preview cache if deleted files exist in cache
@@ -929,8 +941,6 @@ class StorageExplorerStore {
929941
} else {
930942
toast.dismiss(toastId)
931943
}
932-
933-
toast.dismiss(infoToastId)
934944
}
935945

936946
downloadSelectedFiles = async () => {

studio/styles/toast.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@
553553
}
554554

555555
.toast-message {
556-
max-width: 258px;
556+
max-width: 350px;
557557
div[role='status'] {
558558
@apply justify-start w-full break-words;
559559
word-break: break-word;

studio/types/ui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface Notification {
22
category: 'info' | 'error' | 'success' | 'loading'
33
message: string // Readable message for users to understand
4+
description?: string
45
id?: string
56
error?: any // Optional: Any other errors that needs to be logged out in the console
67
progress?: number // Optional: For loading messages to show a progress bar (Out of 100)

0 commit comments

Comments
 (0)