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 6cdf0a476..4b9d85eb9 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
@@ -88,12 +88,14 @@
on:click={() => {
selectedAttribute = attribute;
showOverview = true;
+ showDropdown[index] = false;
}}>Overview
{
selectedAttribute = attribute;
showCreateIndex = true;
+ showDropdown[index] = false;
}}>Create Index
- import { Modal } from '$lib/components';
- import { Button, InputText, FormList, InputSelect } from '$lib/elements/forms';
- import { collection } from '../store';
- import { onMount } from 'svelte';
- import { sdkForProject } from '$lib/stores/sdk';
- import { addNotification } from '$lib/stores/notifications';
+ import { goto, invalidate } from '$app/navigation';
+ import { base } from '$app/paths';
import { page } from '$app/stores';
- import type { Attributes } from '../store';
- import { invalidate } from '$app/navigation';
- import { Dependencies } from '$lib/constants';
- import Select from './select.svelte';
import { trackEvent } from '$lib/actions/analytics';
+ import { Modal } from '$lib/components';
+ import { Dependencies } from '$lib/constants';
+ import { Button, FormList, InputSelect, InputText } from '$lib/elements/forms';
import { remove } from '$lib/helpers/array';
+ import { addNotification } from '$lib/stores/notifications';
+ import { sdkForProject } from '$lib/stores/sdk';
+ import type { Attributes } from '../store';
+ import { collection } from '../store';
+ import Select from './select.svelte';
export let showCreateIndex = false;
export let externalAttribute: Attributes = null;
@@ -32,26 +32,31 @@
label: attribute.key
}));
let attributeList = [{ value: '', order: '' }];
+ let creating = false;
- $: addAttributeDisabled = !attributeList.at(-1)?.value || !attributeList.at(-1)?.order;
-
- onMount(() => {
- if (!externalAttribute) return;
- attributeList = [{ value: externalAttribute.key, order: 'ASC' }];
- });
-
- $: if (showCreateIndex) {
- attributeList = [{ value: '', order: '' }];
+ function initialize() {
+ attributeList = externalAttribute
+ ? [{ value: externalAttribute.key, order: 'ASC' }]
+ : [{ value: '', order: '' }];
selectedType = 'key';
key = null;
}
+ $: if (showCreateIndex) {
+ initialize();
+ }
+
+ $: addAttributeDisabled =
+ !attributeList.at(-1)?.value || !attributeList.at(-1)?.order || creating;
+
async function create() {
if (!(key && selectedType && !addAttributeDisabled)) {
error = 'All fields are required';
return;
}
+ creating = true;
+
try {
await sdkForProject.databases.createIndex(
databaseId,
@@ -61,7 +66,15 @@
attributeList.map((a) => a.value),
attributeList.map((a) => a.order)
);
- invalidate(Dependencies.COLLECTION);
+ await Promise.allSettled([
+ invalidate(Dependencies.COLLECTION),
+ invalidate(Dependencies.DATABASE)
+ ]);
+
+ goto(
+ `${base}/console/project-${$page.params.project}/databases/database-${databaseId}/collection-${$collection.$id}/indexes`
+ );
+
addNotification({
message: 'Index has been created',
type: 'success'
@@ -74,6 +87,7 @@
});
} finally {
showCreateIndex = false;
+ creating = false;
}
}
@@ -140,6 +154,6 @@
-
+