From fc9dba96f984afc9c21042205756da9be40a776e Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 21 Jul 2022 17:43:05 +0200 Subject: [PATCH] feat: attributes and indexes pages --- .../[collection]/_createIndex.svelte | 196 ++++++++++++++++++ .../[collection]/_deleteIndex.svelte | 41 ++++ .../collection/[collection]/attributes.svelte | 15 +- .../collection/[collection]/indexes.svelte | 176 ++++++++++++++-- .../collection/[collection]/store.ts | 17 +- 5 files changed, 421 insertions(+), 24 deletions(-) create mode 100644 src/routes/console/[project]/databases/database/[database]/collection/[collection]/_createIndex.svelte create mode 100644 src/routes/console/[project]/databases/database/[database]/collection/[collection]/_deleteIndex.svelte diff --git a/src/routes/console/[project]/databases/database/[database]/collection/[collection]/_createIndex.svelte b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/_createIndex.svelte new file mode 100644 index 000000000..681491f0e --- /dev/null +++ b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/_createIndex.svelte @@ -0,0 +1,196 @@ + + +
+ + Create Index + + + + + {#if attributeList?.length} + {#each attributeList as index, i} +
  • +
    + +
    + +
    +
    +
    + +
    + +
    +
    + +
    + +
    +
  • + {/each} + {/if} + {#if !attributeList?.length || newAttr} +
  • +
    + +
    + +
    +
    +
    + +
    + +
    +
    + +
    + +
    +
  • + {/if} + +
    + + + + +
    +
    diff --git a/src/routes/console/[project]/databases/database/[database]/collection/[collection]/_deleteIndex.svelte b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/_deleteIndex.svelte new file mode 100644 index 000000000..0c618483f --- /dev/null +++ b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/_deleteIndex.svelte @@ -0,0 +1,41 @@ + + +
    + + Delete Index + +

    + Are you sure you want to delete '{selectedIndex.key}' from {$collection.name}? +

    + + + + +
    +
    diff --git a/src/routes/console/[project]/databases/database/[database]/collection/[collection]/attributes.svelte b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/attributes.svelte index 2e9bac995..523ceb45b 100644 --- a/src/routes/console/[project]/databases/database/[database]/collection/[collection]/attributes.svelte +++ b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/attributes.svelte @@ -17,6 +17,7 @@ import { onMount } from 'svelte'; import { page } from '$app/stores'; import Create from './_createAttribute.svelte'; + import CreateIndex from './_createIndex.svelte'; import Delete from './_deleteAttribute.svelte'; import Overview from './_overview.svelte'; @@ -27,6 +28,7 @@ let showCreate = false; let showDelete = false; let showOverview = false; + let showCreateIndex = false; onMount(async () => { await collection.load($page.params.collection); @@ -74,7 +76,7 @@ {attribute.default ? attribute.default : '-'} - + Overview - Create Index + { + e.preventDefault(); + selectedAttribute = attribute; + showCreateIndex = true; + }}>Create Index { @@ -106,7 +114,7 @@ }}>Delete - + {/each} @@ -138,4 +146,5 @@ {#if selectedAttribute} + {/if} diff --git a/src/routes/console/[project]/databases/database/[database]/collection/[collection]/indexes.svelte b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/indexes.svelte index 87fd32715..8609ddaff 100644 --- a/src/routes/console/[project]/databases/database/[database]/collection/[collection]/indexes.svelte +++ b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/indexes.svelte @@ -1,50 +1,186 @@ -

    Indexes

    - - {#if $collection.indexes.length} + + + + + + {#if $indexList?.total} - Status Key Type Attributes - + Asc/Desc + - {#each $collection.indexes as index} + {#each $indexList.indexes as index, i} - {index.status} - {index.key} + + {index.key} + {index.type} - {#each index.attributes as attribute, i} - {attribute} ({index.orders[i]}) - {/each} + {index.attributes} - Delete + + {index.orders} + + + + + + { + e.preventDefault(); + selectedIndex = index; + showOverview = true; + }}>Overview + + { + e.preventDefault(); + selectedIndex = index; + showDelete = true; + }}>Delete + + + {/each}
    - {:else} +
    +

    Total results: {$indexList?.total}

    + +
    + {:else if search} - No Indexes Found - Add your first index to get started. +
    + Sorry, we couldn’t find ‘{search}’ +
    +

    There are no indexes that match your search.

    +
    +
    + +
    +
    +
    +
    +

    Total results: {$indexList?.total}

    + +
    + {:else if $collection.indexes?.length} + +
    +
    + +
    +
    +

    Create your first attribute to get started

    +
    +
    + +
    +
    +
    + {:else} + +
    +
    + +
    +
    +

    Create your first index to get started

    +
    +
    + +
    +
    {/if}
    + + +{#if selectedIndex} + +{/if} diff --git a/src/routes/console/[project]/databases/database/[database]/collection/[collection]/store.ts b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/store.ts index cd7f28747..b41da1f46 100644 --- a/src/routes/console/[project]/databases/database/[database]/collection/[collection]/store.ts +++ b/src/routes/console/[project]/databases/database/[database]/collection/[collection]/store.ts @@ -54,7 +54,7 @@ function createCollection() { function createDocumentListStore() { const { subscribe, set } = writable>( - browser ? JSON.parse(sessionStorage.getItem('documents')) : null + browser ? JSON.parse(sessionStorage.getItem('documentList')) : null ); return { subscribe, @@ -70,11 +70,26 @@ function createDocumentListStore() { } }; } +function createIndexListStore() { + const { subscribe, set } = writable( + browser ? JSON.parse(sessionStorage.getItem('indexList')) : null + ); + return { + subscribe, + set, + load: async (collectionId: string) => { + const response = await sdkForProject.databases.listIndexes(collectionId); + set(response); + } + }; +} export const collection = createCollection(); export const documentList = createDocumentListStore(); +export const indexList = createIndexListStore(); if (browser) { collection.subscribe((n) => sessionStorage?.setItem('collection', JSON.stringify(n ?? ''))); documentList.subscribe((n) => sessionStorage?.setItem('documentList', JSON.stringify(n ?? ''))); + indexList.subscribe((n) => sessionStorage?.setItem('indexList', JSON.stringify(n ?? ''))); }