From 4fff9bbc9521e4ad75c7687cfbfccb9298f8a0c4 Mon Sep 17 00:00:00 2001 From: ItzNotABug Date: Mon, 19 Aug 2024 17:01:49 +0530 Subject: [PATCH] address comments: max dialog height, load collections on demand. --- .../database-[database]/delete.svelte | 199 +++++++++++------- 1 file changed, 120 insertions(+), 79 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 c8fba4eed..93db8bc3f 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/delete.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/delete.svelte @@ -7,7 +7,7 @@ import { Button, FormList, InputText } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import { sdk } from '$lib/stores/sdk'; - import { database, collections } from './store'; + import { database } from './store'; import { TableBody, TableCellHead, @@ -17,7 +17,7 @@ TableScroll } from '$lib/elements/table'; import { toLocaleDateTime } from '$lib/helpers/date'; - import { Query } from '@appwrite.io/console'; + import { type Models, Query } from '@appwrite.io/console'; const databaseId = $page.params.database; export let showDelete = false; @@ -26,12 +26,34 @@ let databaseName: string = null; let isLoadingDocumentsCount = false; + $: collectionItems = []; + let collections: Models.CollectionList = null; + + function buildQueries(): string[] { + const queries = [ + Query.limit(3), + Query.orderDesc('$updatedAt'), + ]; + + if (collectionItems.length > 0) { + queries.push(Query.offset(collectionItems.length)); + } + + return queries; + } + async function listCollections() { + // let's just wait... + if (isLoadingDocumentsCount) return; + isLoadingDocumentsCount = true; try { - /* can we improve this? */ - const collectionPromises = $collections.collections.map(async (collection) => { + const queries = buildQueries(); + + collections = await sdk.forProject.databases.listCollections(databaseId, queries); + + const collectionPromises = collections.collections.map(async (collection) => { const { total: totalDocuments } = await sdk.forProject.databases.listDocuments( databaseId, collection.$id, @@ -46,8 +68,8 @@ }; }); - return await Promise.all(collectionPromises); - } catch { + collectionItems = [...collectionItems, ...await Promise.all(collectionPromises)]; + } catch (err) { error = true; } finally { isLoadingDocumentsCount = false; @@ -72,81 +94,106 @@ trackError(error, Submit.DatabaseDelete); } }; + + /* reset data on modal close */ + $: if (!showDelete) { + collections = null; + collectionItems = []; + } - - {#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. -

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

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

+ {:else if collectionItems.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} - - +
+ + + Collection + # of Documents + Last Updated + + + {#each collectionItems as collection} + + {collection.name} + {collection.count} + {toLocaleDateTime(collection.updatedAt)} + + {/each} + + - - - - {:else} -

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

- {/if} - {/await} + {#if collectionItems.length < collections.total} +
+ - - - - - + {#if isLoadingDocumentsCount} +
+ {/if} +
+ {/if} +
+ + + + + {:else} +

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

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