diff --git a/package-lock.json b/package-lock.json index 6a9af1276..b3b286ef6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "name": "@appwrite/console", "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@appwrite.io/console": "0.1.0-preview-0.0", + "@appwrite.io/console": "0.1.0-preview-0.1", "@appwrite.io/pink": "^0.0.6-rc.5", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.44.2", @@ -146,9 +146,9 @@ "integrity": "sha512-1Yw7u/COtxx06BfwlI+kVhsa/upKYzmCNrT4c8QDeCY2KMYlnijkUjtHiPU08HxyTIVB5j6d75O0YWVIHwQS8g==" }, "node_modules/@appwrite.io/console": { - "version": "0.1.0-preview-0.0", - "resolved": "https://registry.npmjs.org/@appwrite.io/console/-/console-0.1.0-preview-0.0.tgz", - "integrity": "sha512-ROCZICle2N/76UMXRm40fIDhjPrxplqa8SCuiCSDu68P4x54lybOw/8ecpwHspq/yIxlQ5LYsyJ4U8Fw76JyIg==", + "version": "0.1.0-preview-0.1", + "resolved": "https://registry.npmjs.org/@appwrite.io/console/-/console-0.1.0-preview-0.1.tgz", + "integrity": "sha512-908URjvRoQ87zLJXW7UD0zOgy9DvShgs/YKQBgA9mdNbNmFIzls1XwtbUeNWWLBnx0EVTMjyWiaSou+QIZnXfA==", "dependencies": { "cross-fetch": "3.1.5", "isomorphic-form-data": "2.0.0" diff --git a/package.json b/package.json index 01cc145fd..0f5caea48 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@appwrite.io/console": "0.1.0-preview-0.0", + "@appwrite.io/console": "0.1.0-preview-0.1", "@appwrite.io/pink": "^0.0.6-rc.5", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.44.2", diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/+page.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/+page.svelte index 669f5ad63..e5410eec5 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/+page.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/+page.svelte @@ -54,7 +54,19 @@
-
{attribute.key}
@@ -75,7 +87,9 @@ {`${attribute.type}${attribute.array ? '[]' : ''}`} - {attribute.default !== null ? attribute.default : '-'} + {attribute?.default !== null && attribute?.default !== undefined + ? attribute?.default + : '-'} ) { - await sdk.forProject.databases.createBooleanAttribute( + await sdk.forProject.databases.updateBooleanAttribute( databaseId, collectionId, data.key, data.required, - data.default ? data.default : undefined, - data.array + data.default ? data.default : undefined ); } diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/datetime.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/datetime.svelte index 90f158ff9..93dd9ac0e 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/datetime.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/datetime.svelte @@ -23,13 +23,12 @@ collectionId: string, data: Partial ) { - await sdk.forProject.databases.createDatetimeAttribute( + await sdk.forProject.databases.updateDatetimeAttribute( databaseId, collectionId, data.key, data.required, - data.default ? data.default : undefined, - data.array + data.default ? data.default : undefined ); } diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/deleteAttribute.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/deleteAttribute.svelte index 845bb70c7..4bab7294f 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/deleteAttribute.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/deleteAttribute.svelte @@ -43,7 +43,12 @@ }; - + Delete Attribute

Are you sure you want to delete '{selectedAttribute?.key}' from {$collection?.name}? diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/edit.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/edit.svelte index 2ead13a58..2b2ac9116 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/edit.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/edit.svelte @@ -12,29 +12,19 @@ export let showEdit = false; export let selectedAttribute: Attributes; + const databaseId = $page.params.database; const collectionId = $page.params.collection; + let updateButtonDisabled = true; + let error: string; + let currentAttr: string; - $: attr = selectedAttribute as { - type?: string; - size?: string; - format?: string; - array?: boolean; - required?: boolean; - status?: string; - key?: string; - min?: string; - max?: string; - default: string; - elements?: string[]; - }; - - $: option = options.find((option) => option?.type === attr?.type) as Option; + $: option = options.find((option) => option?.type === selectedAttribute?.type) as Option; async function submit() { try { - await option.update(databaseId, collectionId, attr); + await option.update(databaseId, collectionId, selectedAttribute); await Promise.allSettled([invalidate(Dependencies.COLLECTION)]); if (!$page.url.pathname.includes('attributes')) { await goto( @@ -43,42 +33,44 @@ } addNotification({ type: 'success', - message: `Attribute ${attr.key} has been created` + message: `Attribute ${selectedAttribute.key} has been created` }); showEdit = false; trackEvent(Submit.AttributeUpdate); - } catch (error) { - addNotification({ - type: 'error', - message: error.message - }); - trackError(error, Submit.AttributeUpdate); + } catch (e) { + error = e.message; + trackError(e, Submit.AttributeUpdate); } } - $: if (JSON.stringify(attr) !== JSON.stringify(selectedAttribute)) { - updateButtonDisabled = false; - } else updateButtonDisabled = true; + $: updateButtonDisabled = JSON.stringify(selectedAttribute) === currentAttr; + + $: if (showEdit) { + currentAttr ??= JSON.stringify(selectedAttribute); + error = null; + } - - - {attr?.type} - {#if attr?.type === 'Relationship'} -

- Beta +{#if selectedAttribute} + + +
+ {option?.name} + {#if option.type === 'relationship'} +
+ Beta +
+ {/if}
- {/if} -
- - {#if selectedAttribute} - {#if option.name !== 'Relationship'} + + + {#if selectedAttribute?.type !== 'relationship'}
@@ -94,13 +86,13 @@ {/if} (option = null)} /> - {/if} - - - - - - + + + + + + +{/if} diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/email.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/email.svelte index 0a20d635f..67449b34e 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/email.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/email.svelte @@ -24,13 +24,12 @@ collectionId: string, data: Partial ) { - await sdk.forProject.databases.createEmailAttribute( + await sdk.forProject.databases.updateEmailAttribute( databaseId, collectionId, data.key, data.required, - data.default ? data.default : undefined, - data.array + data.default ? data.default : undefined ); } diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/enum.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/enum.svelte index 0e166cb6c..02a56a19f 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/enum.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/enum.svelte @@ -24,14 +24,13 @@ collectionId: string, data: Partial ) { - await sdk.forProject.databases.createEnumAttribute( + await sdk.forProject.databases.updateEnumAttribute( databaseId, collectionId, data.key, data.elements, data.required, - data.default ? data.default : undefined, - data.array + data.default ? data.default : undefined ); } diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/float.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/float.svelte index ce5fd9522..8dcbe2e5a 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/float.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/float.svelte @@ -25,15 +25,14 @@ collectionId: string, data: Partial ) { - await sdk.forProject.databases.createFloatAttribute( + await sdk.forProject.databases.updateFloatAttribute( databaseId, collectionId, data.key, data.required, data.min, data.max, - typeof data.default === 'number' ? data.default : undefined, - data.array + typeof data.default === 'number' ? data.default : undefined ); } diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/integer.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/integer.svelte index 4c0dee1d4..eeee48f51 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/integer.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/integer.svelte @@ -25,15 +25,14 @@ collectionId: string, data: Partial ) { - await sdk.forProject.databases.createIntegerAttribute( + await sdk.forProject.databases.updateIntegerAttribute( databaseId, collectionId, data.key, data.required, data.min, data.max, - typeof data.default === 'number' ? data.default : undefined, - data.array + typeof data.default === 'number' ? data.default : undefined ); } diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/ip.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/ip.svelte index 81c5b2da2..1209da703 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/ip.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/ip.svelte @@ -22,13 +22,12 @@ collectionId: string, data: Partial ) { - await sdk.forProject.databases.createIpAttribute( + await sdk.forProject.databases.updateIpAttribute( databaseId, collectionId, data.key, data.required, - data.default ? data.default : undefined, - data.array + data.default ? data.default : undefined ); } diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/relationship.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/relationship.svelte index e4df57b8e..1cab73547 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/relationship.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/relationship.svelte @@ -5,33 +5,32 @@ export async function submitRelationship( databaseId: string, collectionId: string, - key: string, - data: Partial + _: string, + data: Partial ) { await sdk.forProject.databases.createRelationshipAttribute( databaseId, collectionId, - key, - data.size, - data.required, - data.default ? (data.default as string) : undefined, - data.array + data.relatedCollection, + data.relationType, + data.twoWay, + data.key, + data.twoWayKey, + data.onDelete ); } export async function updateRelationship( databaseId: string, collectionId: string, - data: Partial + data: Partial ) { await sdk.forProject.databases.updateRelationshipAttribute( databaseId, collectionId, data.key, - data.size, - data.required, - data.default ? (data.default as string) : undefined, - data.array + data.twoWay, + data.onDelete ); } @@ -47,39 +46,24 @@ import { camelize } from '$lib/helpers/string'; // Props - export let selectedAttribute: Models.AttributeString; - - type Data = Partial & { - relation: 'one' | 'many'; - related?: string | number | boolean; - keyRelated?: string; - del?: string | number | boolean; - }; - - export let data: Data = { - required: false, - size: 0, - default: null, - array: false, - relation: 'one' - }; + export let data: Partial; + export let editing = false; // Constants const databaseId = $page.params.database; const oneWay = [ - { value: 'one', label: 'One to one' }, - { value: 'many', label: 'One to many' } + { value: 'onetoone', label: 'One to one' }, + { value: 'onetomany', label: 'One to many' } ]; const twoWay = [ - { value: 'one', label: 'One to one' }, - { value: 'many', label: 'One to many' }, - { value: 'manyOne', label: 'Many to one' }, - { value: 'manyMany', label: 'Many to many' } + ...oneWay, + { value: 'manytoone', label: 'Many to one' }, + { value: 'manytomany', label: 'Many to many' } ]; const deleteOptions = [ + { value: 'setnull', label: 'Null' }, { value: 'cascade', label: 'Cascade' }, - { value: 'null', label: 'Null' }, { value: 'restrict', label: 'Restrict' } ]; @@ -105,34 +89,30 @@ onMount(async () => { collectionList = await getCollections(); + + if (editing) { + way = data.twoWay ? 'two' : 'one'; + search = data.relatedCollection; + } }); // Reactive statements + $: getCollections(search).then((res) => (collectionList = res)); $: collections = collectionList?.collections?.filter((n) => n.$id !== $collection.$id) ?? []; - $: if (selectedAttribute) { - data = { - ...data, - required: selectedAttribute.required, - array: selectedAttribute.array, - size: selectedAttribute.size, - default: selectedAttribute.default - }; - } - - $: if (data.required || data.array) { - data.default = null; - } - - $: console.log(data.related); - - $: if (data.related && !data.key) { - const collection = collectionList.collections.find((n) => n.$id === data.related); + $: if (data?.relatedCollection && !data.key) { + const collection = collectionList.collections.find((n) => n.$id === data.relatedCollection); data.key = camelize(collection.name); } - $: if (way === 'two' && !data.keyRelated) { - data.keyRelated = camelize($collection.name); + $: if (way === 'two' && !data.twoWayKey) { + data.twoWayKey = camelize($collection.name); + } + + $: if (way === 'two') { + data.twoWay = true; + } else { + // data.twoWay = false; } @@ -160,12 +140,13 @@ label="Related Collection" name="collections" bind:search - bind:value={data.related} + bind:value={data.relatedCollection} required placeholder="Select a collection" + disabled={editing} options={collections?.map((n) => ({ value: n.$id, label: n.name })) ?? []} /> -{#if data?.related} +{#if data?.relatedCollection}
+ bind:value={data.twoWayKey} + required + disabled={editing} />
+ options={data?.twoWay ? oneWay : twoWay} + disabled={editing} />
@@ -224,14 +207,14 @@

- {camelize($collection.name)} has {data.relation === 'one' ? 'one' : 'many'} + {camelize($collection.name)} has {way === 'one' ? 'one' : 'many'} {data.key}

diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/string.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/string.svelte index b811b360e..ec11ce57f 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/string.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/string.svelte @@ -23,14 +23,12 @@ collectionId: string, data: Partial ) { - await sdk.forProject.databases.createStringAttribute( + await sdk.forProject.databases.updateStringAttribute( databaseId, collectionId, data.key, - data.size, data.required, - data.default ? (data.default as string) : undefined, - data.array + data.default ? (data.default as string) : undefined ); } diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/url.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/url.svelte index 830dbc2d6..29f34328c 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/url.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/url.svelte @@ -23,13 +23,12 @@ collectionId: string, data: Partial ) { - await sdk.forProject.databases.createUrlAttribute( + await sdk.forProject.databases.updateUrlAttribute( databaseId, collectionId, data.key, data.required, - data.default ? data.default : undefined, - data.array + data.default ? data.default : undefined ); } diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/createAttribute.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/createAttribute.svelte index 7aa36f499..a7742895c 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/createAttribute.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/createAttribute.svelte @@ -12,6 +12,8 @@ export let showCreate = false; export let selectedOption: string = null; + const databaseId = $page.params.database; + const collectionId = $page.params.collection; let key: string = null; let data: Partial = { @@ -19,8 +21,7 @@ array: false, default: null }; - const databaseId = $page.params.database; - const collectionId = $page.params.collection; + let error: string; async function submit() { try { @@ -33,16 +34,13 @@ } addNotification({ type: 'success', - message: `Attribute ${key} has been created` + message: `Attribute ${key ?? data?.key} has been created` }); showCreate = false; trackEvent(Submit.AttributeCreate); - } catch (error) { - addNotification({ - type: 'error', - message: error.message - }); - trackError(error, Submit.AttributeCreate); + } catch (e) { + error = e.message; + trackError(e, Submit.AttributeCreate); } } @@ -51,6 +49,7 @@ } $: if (!showCreate) { + error = null; key = null; selectedOption = null; $option = null; @@ -62,7 +61,7 @@ } - + {#if selectedOption === 'Relationship'} diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/store.ts b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/store.ts index 9e3a614d5..dacab7451 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/store.ts +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/store.ts @@ -1,5 +1,4 @@ import { page } from '$app/stores'; -import type { Column } from '$lib/components/viewSelector.svelte'; import type { Models } from '@appwrite.io/console'; import { derived, writable } from 'svelte/store'; @@ -11,7 +10,8 @@ export type Attributes = | Models.AttributeInteger | Models.AttributeIp | Models.AttributeString - | Models.AttributeUrl; + | Models.AttributeUrl + | Models.AttributeRelationship; type Collection = Omit & { attributes: Array; @@ -21,7 +21,7 @@ export type Column = { title: string; show: boolean; type?: string; - direction?: string; + twoWay?: string; width?: number; }; diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/table.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/table.svelte index 8f685b2fd..7156dc72b 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/table.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/table.svelte @@ -77,7 +77,7 @@ - Document ID + Document ID {#each $columns.filter((n) => n.show) as column} {#if column.show} {column.title} @@ -100,7 +100,7 @@ {#each $columns as column} {#if column.show} {#if column.type === 'relationship'} - {#if column.direction === 'one'} + {#if !column.twoWay} {document[column.id]}