diff --git a/src/lib/components/backupRestoreBox.svelte b/src/lib/components/backupRestoreBox.svelte index c48b5802e..20555ea30 100644 --- a/src/lib/components/backupRestoreBox.svelte +++ b/src/lib/components/backupRestoreBox.svelte @@ -6,7 +6,10 @@ import { organization } from '$lib/stores/organization'; import { BillingPlan, Dependencies } from '$lib/constants'; import type { BackupArchive, BackupRestoration } from '$lib/sdk/backups'; - import { invalidate } from '$app/navigation'; + import { goto, invalidate } from '$app/navigation'; + import { page } from '$app/stores'; + import { addNotification } from '$lib/stores/notifications'; + import { base } from '$app/paths'; let backupRestoreItems: { archives: Map; @@ -16,9 +19,37 @@ restorations: new Map() }; + let openStates = { + archives: true, + restorations: true + }; + $: showBackupRestoreBox = backupRestoreItems.archives.size > 0 || backupRestoreItems.restorations.size > 0; + let lastDatabaseRestorationId = null; + + const showRestoreNotification = (newDatabaseId: string, newDatabaseName: string) => { + if (newDatabaseId && newDatabaseName && lastDatabaseRestorationId !== newDatabaseId) { + const project = $page.params.project; + lastDatabaseRestorationId = newDatabaseId; + + addNotification({ + type: 'success', + isHtml: true, + message: `Restoration complete. ${newDatabaseName} has been created.`, + buttons: [ + { + name: 'View restored data', + method: () => { + goto(`${base}/project-${project}/databases/database-${newDatabaseId}`); + } + } + ] + }); + } + }; + const fetchBackupRestores = async () => { try { const query = [ @@ -54,7 +85,16 @@ if (collectionMap.has($id)) { collectionMap.get($id).status = status; - if (status === 'completed') invalidate(Dependencies.BACKUPS); + if (status === 'completed') { + invalidate(Dependencies.BACKUPS); + + if ($collection === 'restorations') { + const { newId, newName } = + collectionMap.get($id).options?.['databases']?.['database'][0] || {}; + + showRestoreNotification(newId, newName); + } + } } else if (status === 'pending' || status === 'processing' || status === 'uploading') { collectionMap.set($id, payload); } @@ -78,8 +118,20 @@ } }; + const text = (status: string, key: string) => { + const service = key === 'archives' ? 'backup' : 'restore'; + if (status === 'completed') { + return `Database ${service} complete`; + } else if (status === 'failed') { + return `Database ${service} failed`; + } else { + return 'Preparing database...'; + } + }; + const handleClose = (which: string) => { backupRestoreItems[which] = new Map(); + if (which === 'restorations') lastDatabaseRestorationId = null; }; // TODO: `startedAt` is probably not correct here. need more info. @@ -117,6 +169,15 @@

{titleText}

+