- {#if $$slots.default && customOutput && selectedOption}
-
(hasFocus = true)}
- on:click={() => (hasFocus = true)}
- on:input={handleInput}
- on:keydown={handleKeydown} />
+ {#if $$slots.output && selectedOption}
+
(hasFocus = true)}
+ on:click={() => (hasFocus = true)}
+ on:input={handleInput}
+ on:keydown={handleKeydown} />
+
{#if showClearBtn}
@@ -145,7 +144,7 @@
diff --git a/src/lib/helpers/array.ts b/src/lib/helpers/array.ts
index 4527291b4..096d65d6f 100644
--- a/src/lib/helpers/array.ts
+++ b/src/lib/helpers/array.ts
@@ -5,6 +5,9 @@ export function intersection(arr1: unknown[], arr2: unknown[]) {
}
export function difference(arr1: unknown[], arr2: unknown[]) {
+ if (!Array.isArray(arr1) || !Array.isArray(arr2)) {
+ return Array.isArray(arr1) ? arr1 : Array.isArray(arr2) ? arr2 : [];
+ }
const set = new Set(arr2);
const difference = new Set(arr1.filter((elem) => !set.has(elem)));
return Array.from(difference);
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 0e97e2a55..54c648925 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
@@ -141,6 +141,7 @@
bind:search
bind:value={data.relatedCollection}
required
+ interactiveOutput
placeholder="Select a collection"
disabled={editing}
options={collections?.map((n) => ({ value: n.$id, label: n.$id, data: [n.name] })) ?? []}
@@ -149,6 +150,13 @@
{o.label}
+
+
+
{#if data?.relatedCollection}
diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/relationship.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/relationship.svelte
index 1e99f0e05..f4a44ed70 100644
--- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/relationship.svelte
+++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/relationship.svelte
@@ -74,7 +74,12 @@
value = singleRel;
}
- $: paginatedItems = relatedList.slice(offset, offset + limit);
+ $: paginatedItems = editing
+ ? relatedList
+ .slice()
+ .reverse()
+ .slice(offset, offset + limit)
+ : [];
$: total = relatedList?.length;
$: options =
documentList?.documents?.map((n) => {
@@ -87,25 +92,65 @@
}) ?? [];
-{#if editing && isRelationshipToMany(attribute) && total > 0}
-
+{#if isRelationshipToMany(attribute)}
+
-
+ {#if editing || total === 0}
+
+ {/if}
+
+ {#if !editing}
+ {#each relatedList as item, i}
+ -
+
+
+ {o.label}
+
+
+
+
+
+
+
+ {/each}
+ {/if}
+
{#if showInput}
-
{o.label}
+
+
+
{/if}
- {#if paginatedItems}
- {#each relatedList as item, i}
+ {#if paginatedItems && editing}
+ {#each paginatedItems as item, i}
-
{o.label}
+
+
+
-{:else if isRelationshipToMany(attribute)}
-
-
-
-
+ {#if editing}
+
+
Total results: {total}
+
- {#if total === 0}
-
- {/if}
-
-
-
- {#each relatedList as doc, i}
- -
-
-
- {o.label}
-
-
-
-
- {/each}
-
- {#if showInput}
- -
- !relatedList.includes(n.value))}
- on:select={() => {
- showInput = false;
- }}
- let:option={o}>
-
- {o.label}
-
-
-
-
- {/if}
-
-
- {#if total > 0}
+ {/if}
+ {#if total > 0 && !editing}