From c8a87350d24258ffbe84db5a62ed1d84bc5deee0 Mon Sep 17 00:00:00 2001 From: ItzNotABug Date: Wed, 14 Aug 2024 14:27:19 +0530 Subject: [PATCH] update: new deletion flow modal. --- .../database-[database]/delete.svelte | 128 +++++++++++++++++- 1 file changed, 122 insertions(+), 6 deletions(-) diff --git a/src/routes/console/project-[project]/databases/database-[database]/delete.svelte b/src/routes/console/project-[project]/databases/database-[database]/delete.svelte index 4a4c7d2e1..3fee494c9 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/delete.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/delete.svelte @@ -4,14 +4,57 @@ import { page } from '$app/stores'; import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; import { Modal } from '$lib/components'; - import { Button } from '$lib/elements/forms'; + import { Button, FormList, InputText } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdk } from '$lib/stores/sdk'; - import { database } from './store'; + import { database, collections } from './store'; + import { + TableBody, + TableCellHead, + TableHeader, + TableCell, + TableRow, + TableScroll + } from '$lib/elements/table'; + import { toLocaleDateTime } from '$lib/helpers/date'; + import { Query } from '@appwrite.io/console'; const databaseId = $page.params.database; export let showDelete = false; + let error = null; + let databaseName: string = null; + let isLoadingDocumentsCount = false; + + async function listCollections() { + isLoadingDocumentsCount = true; + + try { + /* can we improve this? */ + const collectionPromises = $collections.collections.map(async (collection) => { + const { total: totalDocuments } = await sdk.forProject.databases.listDocuments( + databaseId, collection.$id, + [ + Query.limit(1) + ] + ); + + return { + id: collection.$id, + name: collection.name, + count: totalDocuments, + updatedAt: collection.$updatedAt + }; + }); + + return await Promise.all(collectionPromises); + } catch { + error = true; + } finally { + isLoadingDocumentsCount = false; + } + } + const handleDelete = async () => { try { await sdk.forProject.databases.delete(databaseId); @@ -39,11 +82,84 @@ bind:show={showDelete} onSubmit={handleDelete} headerDivider={false}> -

- Are you sure you want to delete {$database.name}? -

+ {#await listCollections()} +
+
+
+ {:then collections} + {#if error} +

+ Are you sure you want to delete {$database.name}? +

+ {:else if collections.length > 0} +

+ The following collections and all data associated with {$database.name} will + be permanently deleted. + This action is irreversible. +

+ + + + Collection + # of Documents + Last Updated + + + {#each collections as collection} + + {collection.name} + {collection.count} + {toLocaleDateTime(collection.updatedAt)} + + {/each} + + + + + + + {:else} +

+ Are you sure you want to delete {$database.name}? +

+ {/if} + {/await} + - + + +