From 6a3fe2848e036d06b794f43b795df71ed676facd Mon Sep 17 00:00:00 2001 From: Darshan Date: Mon, 28 Jul 2025 13:05:35 +0530 Subject: [PATCH] add: nice seekbar component, fake data logic, multi attribute deletion. --- package.json | 1 + pnpm-lock.yaml | 9 + src/lib/elements/forms/index.ts | 1 + .../collection-[collection]/+layout.svelte | 73 +++- .../collection-[collection]/+page.svelte | 13 +- .../attributes/+page.svelte | 381 +++++++++--------- .../attributes/deleteAttribute.svelte | 94 +++-- .../layout/emptySheet.svelte | 17 +- .../spreadsheet.svelte | 9 +- .../collection-[collection]/store.ts | 5 + 10 files changed, 372 insertions(+), 231 deletions(-) diff --git a/package.json b/package.json index 159ca6d58..56a30dfd7 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@appwrite.io/pink-icons-svelte": "^2.0.0-RC.1", "@appwrite.io/pink-legacy": "^1.0.3", "@appwrite.io/pink-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@99ee9f5", + "@faker-js/faker": "^9.9.0", "@popperjs/core": "^2.11.8", "@sentry/sveltekit": "^8.38.0", "@stripe/stripe-js": "^3.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 46009bacb..ce06ce83d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: '@appwrite.io/pink-svelte': specifier: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@99ee9f5 version: https://pkg.vc/-/@appwrite/@appwrite.io/pink-svelte@99ee9f5(svelte@5.25.3) + '@faker-js/faker': + specifier: ^9.9.0 + version: 9.9.0 '@popperjs/core': specifier: ^2.11.8 version: 2.11.8 @@ -586,6 +589,10 @@ packages: resolution: {integrity: sha512-1+WqvgNMhmlAambTvT3KPtCl/Ibr68VldY2XY40SL1CE0ZXiakFR/cbTspaF5HsnpDMvcYYoJHfl4980NBjGag==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@faker-js/faker@9.9.0': + resolution: {integrity: sha512-OEl393iCOoo/z8bMezRlJu+GlRGlsKbUAN7jKB6LhnKoqKve5DXRpalbItIIcwnCjs1k/FOPjFzcA6Qn+H+YbA==} + engines: {node: '>=18.0.0', npm: '>=9.0.0'} + '@floating-ui/core@1.6.9': resolution: {integrity: sha512-uMXCuQ3BItDUbAMhIXw7UPXRfAlOAvZzdK9BWpE60MCn+Svt3aLn9jsPTi/WNGlRUu2uI0v5S7JiIUsbsvh3fw==} @@ -3950,6 +3957,8 @@ snapshots: '@eslint/core': 0.15.1 levn: 0.4.1 + '@faker-js/faker@9.9.0': {} + '@floating-ui/core@1.6.9': dependencies: '@floating-ui/utils': 0.2.9 diff --git a/src/lib/elements/forms/index.ts b/src/lib/elements/forms/index.ts index 938532339..20b970669 100644 --- a/src/lib/elements/forms/index.ts +++ b/src/lib/elements/forms/index.ts @@ -30,3 +30,4 @@ export { default as InputTime } from './inputTime.svelte'; export { default as InputDigits } from './inputDigits.svelte'; export { default as InputSelectCheckbox } from './inputSelectCheckbox.svelte'; export { default as InputFilePicker } from './inputFilePicker.svelte'; +export { default as Seekbar } from './Seekbar.svelte'; diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+layout.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+layout.svelte index ef5301415..41eb50853 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+layout.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+layout.svelte @@ -1,4 +1,6 @@ @@ -263,3 +312,21 @@ }}> + + + + + Select how many random records to generate for testing. This won't delete or replace + your existing records. + + + + + + + + + + + + diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+page.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+page.svelte index 5daaacd32..431133cb3 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+page.svelte @@ -15,7 +15,8 @@ isCsvImportInProgress, showRecordsCreateSheet, showCreateAttributeSheet, - type Attributes + type Attributes, + randomDataModalState } from './store'; import SpreadSheet from './spreadsheet.svelte'; import { writable } from 'svelte/store'; @@ -190,6 +191,11 @@ onClick: () => { $showRecordsCreateSheet.show = true; } + }, + random: { + onClick: () => { + $randomDataModalState.show = true; + } } }} /> {/if} @@ -204,6 +210,11 @@ onClick: async () => { $showCreateAttributeSheet.show = true; } + }, + random: { + onClick: () => { + $randomDataModalState.show = true; + } } }} /> {/if} diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/attributes/+page.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/attributes/+page.svelte index 61a319aa5..dfcab5bbb 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/attributes/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/attributes/+page.svelte @@ -5,6 +5,7 @@ import { ActionMenu, Badge, + FloatingActionBar, Icon, Layout, Link, @@ -46,7 +47,6 @@ import { isSmallViewport } from '$lib/stores/viewport'; import SideSheet from '../layout/sidesheet.svelte'; import SpreadsheetContainer from '../layout/spreadsheet.svelte'; - import EmptySheet from '../layout/emptySheet.svelte'; import { showCreateAttributeSheet } from '../store'; import { type Models } from '@appwrite.io/console'; import { preferences } from '$lib/stores/preferences'; @@ -100,6 +100,7 @@ let showDropdown = $state([]); let showFailed = $state(false); let showDelete = $state(false); + let selectedAttributes = $state([]); let showCreateIndex = $state(false); let selectedAttribute: Attributes = $state(null); @@ -161,205 +162,213 @@
- {#if updatedAttributes.length} - - - - Column name - Indexed - Default value - - + + + + Column name + Indexed + Default value + + - {#each updatedAttributes as attribute, index} - {@const option = attributeOptions.find( - (option) => option.type === attribute.type - )} - - - - {#if isRelationship(attribute)} - - {:else if 'format' in attribute && attribute.format} - {@const icon = attributeFormatIcon[attribute?.format]} - - {:else if attribute.key === '$id'} - - {:else} - - {/if} + {#each updatedAttributes as attribute, index} + {@const option = attributeOptions.find((option) => option.type === attribute.type)} + {@const isSelectable = + attribute['system'] || attribute.type === 'relationship' ? 'disabled' : true} + + + + {#if isRelationship(attribute)} + + {:else if 'format' in attribute && attribute.format} + {@const icon = attributeFormatIcon[attribute?.format]} + + {:else if attribute.key === '$id'} + + {:else} + + {/if} - - - - {#if attribute.key === '$id' || attribute.key === '$createdAt' || attribute.key === '$updatedAt'} - {attribute['name']} - {#if attribute.key === '$id'} - - {/if} - {:else} - {attribute.key} + + + + {#if attribute.key === '$id' || attribute.key === '$createdAt' || attribute.key === '$updatedAt'} + {attribute['name']} + {#if attribute.key === '$id'} + {/if} - - {#if isString(attribute) && attribute.encrypt} - - -
Encrypted
-
+ {:else} + {attribute.key} {/if} -
- {#if attribute.status !== 'available'} - - {#if attribute.error} - { - e.preventDefault(); - error = attribute.error; - showFailed = true; - }}>Details - {/if} - {:else if attribute.required} - +
+ {#if isString(attribute) && attribute.encrypt} + + +
Encrypted
+
{/if}
+ {#if attribute.status !== 'available'} + + {#if attribute.error} + { + e.preventDefault(); + error = attribute.error; + showFailed = true; + }}>Details + {/if} + {:else if attribute.required} + + {/if}
-
- - {@const isIndexed = $indexes.some((index) => - index.attributes.includes(attribute.key) - )} - - - - {@const _default = - attribute?.default !== null && attribute?.default !== undefined - ? attribute?.default - : null} +
+
+ + {@const isIndexed = $indexes.some((index) => + index.attributes.includes(attribute.key) + )} + + + + {@const _default = + attribute?.default !== null && attribute?.default !== undefined + ? attribute?.default + : null} - {#if _default === null} - - {:else} - {_default} - {/if} - - - {#if $isCsvImportInProgress} - - - - {:else} - - - - - {#if !attribute['system']} - { - toggle(event); - showEdit = true; - selectedAttribute = attribute; - showDropdown[index] = false; - }}> - Update - - {/if} - {#if !isRelationship(attribute)} - { - toggle(event); - selectedAttribute = attribute; - showCreateIndex = true; - showDropdown[index] = false; - }}> - Create index - - {/if} - {#if attribute.status !== 'processing' && !attribute['system']} - { - toggle(event); - showDelete = true; - showDropdown[index] = false; - selectedAttribute = attribute; - trackEvent(Click.DatabaseAttributeDelete); - }}> - Delete - - {/if} - - - {/if} - -
- {/each} + {#if _default === null} + + {:else} + {_default} + {/if} + + + {#if $isCsvImportInProgress} + + + + {:else} + + + + + {#if !attribute['system']} + { + toggle(event); + showEdit = true; + selectedAttribute = attribute; + showDropdown[index] = false; + }}> + Update + + {/if} + {#if !isRelationship(attribute)} + { + toggle(event); + selectedAttribute = attribute; + showCreateIndex = true; + showDropdown[index] = false; + }}> + Create index + + {/if} + {#if attribute.status !== 'processing' && !attribute['system']} + { + toggle(event); + showDelete = true; + showDropdown[index] = false; + selectedAttribute = attribute; + trackEvent(Click.DatabaseAttributeDelete); + }}> + Delete + + {/if} + + + {/if} + + + {/each} - - - - {updatedAttributes.length} columns - - + + + + {updatedAttributes.length} columns + + + +
+
+ + {#if selectedAttributes.length > 0} +
+ + +
+ + + + {selectedAttributes.length > 1 ? 'attributes' : 'attribute'} + selected + + +
- - - {:else} - ($showCreateAttributeSheet.show = true) - } - }} /> + + + + +
+
{/if}
-{#if showDelete} +{#if selectedAttribute} +{:else if selectedAttributes && selectedAttributes.length} + {/if} - import { goto } from '$app/navigation'; - import { base } from '$app/paths'; + import { invalidate } from '$app/navigation'; import { page } from '$app/state'; import { InputChoice } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; @@ -10,38 +9,65 @@ import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; import { isRelationship } from '../document-[document]/attributes/store'; import Confirm from '$lib/components/confirm.svelte'; + import { Layout } from '@appwrite.io/pink-svelte'; + import { Dependencies } from '$lib/constants'; - export let showDelete = false; - export let selectedAttribute: Attributes; - const databaseId = page.params.database; + let { + showDelete = $bindable(false), + selectedAttribute = $bindable(null) + }: { + showDelete: boolean; + selectedAttribute: Attributes | string[]; + } = $props(); - let error: string; - let checked = false; + let checked = $state(false); + let error = $state(null); + + const selectedAttributes = $derived( + Array.isArray(selectedAttribute) ? selectedAttribute : [selectedAttribute] + ); + + const selectedKeys = $derived(getKeys(selectedAttribute)); + + const requiresTwoWayConfirm = $derived( + selectedAttributes.some((attr: string | Attributes) => { + typeof attr === 'string' ? false : isRelationship(attr) && attr.twoWay; + }) + ); + + const isDeleteBtnDisabled = $derived(requiresTwoWayConfirm && !checked); + + function getKeys(selected: Attributes | string[]): string[] { + return Array.isArray(selected) ? selected : [selected.key]; + } - // TODO: sync the columnsOrder here as well. async function handleDelete() { try { - await sdk - .forProject(page.params.region, page.params.project) - .databases.deleteAttribute(databaseId, $collection.$id, selectedAttribute.key); + const client = sdk.forProject(page.params.region, page.params.project); - showDelete = false; + await Promise.all( + selectedAttributes.map((key) => + client.databases.deleteAttribute(page.params.database, $collection.$id, key) + ) + ); + + trackEvent(Submit.AttributeDelete); + invalidate(Dependencies.COLLECTION); addNotification({ type: 'success', - message: `Attribute has been deleted` + message: + selectedAttributes.length === 1 + ? 'Attribute has been deleted' + : `${selectedAttributes.length} attributes have been deleted` }); - trackEvent(Submit.AttributeDelete); - await goto( - `${base}/project-${page.params.region}-${page.params.project}/databases/database-${databaseId}/collection-${page.params.collection}/attributes` - ); + + showDelete = false; + selectedAttribute = []; } catch (e) { error = e.message; trackError(e, Submit.AttributeDelete); } } - - $: isDeleteBtnDisabled = - isRelationship(selectedAttribute) && selectedAttribute?.twoWay && !checked; -

- Are you sure you want to delete {selectedAttribute?.key} from - {$collection?.name}? -

- {#if isRelationship(selectedAttribute) && selectedAttribute?.twoWay} -
+ {#if selectedAttributes.length === 1} +

+ Are you sure you want to delete {selectedKeys[0]} from + {$collection?.name}? +

+ {:else} +

+ Are you sure you want to delete {selectedKeys.join(', ')} from + {$collection?.name}? +

+ {/if} + + {#if requiresTwoWayConfirm} + + {@const attribute = selectedAttribute[0]} +

This is a two way relationship and the corresponding relationship will also be deleted. @@ -63,10 +99,10 @@

This action is irreversible.

    - Delete relationship between {selectedAttribute.key} to - {selectedAttribute.twoWayKey} + Delete relationship between {attribute.key} to + {attribute.twoWayKey}
-
+ {/if}
diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/layout/emptySheet.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/layout/emptySheet.svelte index e390a87b1..d72b92730 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/layout/emptySheet.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/layout/emptySheet.svelte @@ -167,16 +167,13 @@ {#if mode === 'records'} - - - {actions?.random?.text ?? `Generate random data`} - - Yet to be added - + + {actions?.random?.text ?? `Generate random data`} + {/if} {/if} diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/spreadsheet.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/spreadsheet.svelte index b41eea823..0ddf827fe 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/spreadsheet.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/spreadsheet.svelte @@ -27,7 +27,8 @@ showCreateAttributeSheet, reorderItems, columnsOrder, - columnsWidth + columnsWidth, + randomDataModalState } from './store'; import RelationshipsModal from './relationshipsModal.svelte'; import type { Column, ColumnType } from '$lib/helpers/types'; @@ -649,7 +650,11 @@
- Generate random data + { + $randomDataModalState.show = true; + }}>Generate random data
diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/store.ts b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/store.ts index 070f93f78..af837998b 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/store.ts +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/store.ts @@ -117,3 +117,8 @@ export function reorderItems( ...items.filter((item) => !orderSet.has(getItemId(item))) ]; } + +export const randomDataModalState = writable({ + show: false, + value: 25 // initial value! +});