mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
fix: relationship
This commit is contained in:
1 parent
0a307dfa86
commit
b890aa3309
5 files changed
+30
-29
No files matched your search
@@ -4,7 +4,7 @@
|
||||
import { Label } from '.';
|
||||
|
||||
type Option = $$Generic<{
|
||||
value: string | boolean | number;
|
||||
value: string | boolean | number | Record<string, unknown>;
|
||||
label: string;
|
||||
data?: string[];
|
||||
}>;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
import { tooltip } from '$lib/actions/tooltip';
|
||||
|
||||
export let data: string[] = [];
|
||||
|
||||
console.log(data);
|
||||
</script>
|
||||
|
||||
<div class="u-flex u-cross-baseline u-gap-12">
|
||||
@@ -15,13 +13,13 @@
|
||||
<span
|
||||
class="u-flex u-trim-1 u-gap-4"
|
||||
use:tooltip={{
|
||||
content: data.map((e) => e ?? 'n/a').join(' | ')
|
||||
content: data.map((e) => e ?? e?.toString()).join(' | ')
|
||||
}}>
|
||||
{#each data as item, i}
|
||||
{#if i}
|
||||
<span class="u-text-color-gray">|</span>
|
||||
{/if}
|
||||
<span class="text">{item ?? 'n/a'}</span>
|
||||
<span class="text">{item}</span>
|
||||
{/each}
|
||||
</span>
|
||||
{/if}
|
||||
|
||||
+22
-16
@@ -34,10 +34,11 @@
|
||||
|
||||
async function getDocuments(search: string = null) {
|
||||
if (search) {
|
||||
const query = displayNames.map((name) => Query.search(name, search));
|
||||
const documents = await sdk.forProject.databases.listDocuments(
|
||||
databaseId,
|
||||
attribute.relatedCollection,
|
||||
[Query.search(displayNames[0], search), Query.orderDesc('$createdAt')]
|
||||
[...query, Query.orderDesc('$createdAt')]
|
||||
);
|
||||
return documents;
|
||||
} else {
|
||||
@@ -56,7 +57,7 @@
|
||||
// Reactive statements
|
||||
$: getDocuments(search).then((res) => (documentList = res));
|
||||
|
||||
$: if (isArray) value = relatedList;
|
||||
$: if (isArray) value = relatedList.map((doc) => doc.label);
|
||||
</script>
|
||||
|
||||
{#if isArray}
|
||||
@@ -84,16 +85,9 @@
|
||||
<li class="u-flex u-gap-16">
|
||||
<output class="input-text is-read-only">
|
||||
<div class="u-flex u-cross-baseline u-gap-12">
|
||||
<span
|
||||
class="u-flex-basis-140 u-flex-shrink-0 u-text-start u-trim-start u-x-small u-color-text-gray">
|
||||
{doc}
|
||||
<!-- {doc.label} -->
|
||||
</span>
|
||||
<span class="u-flex-1 u-trim-1">
|
||||
<!-- {#each doc.data as info}
|
||||
{info}
|
||||
{/each} -->
|
||||
</span>
|
||||
<SelectSearchItem data={doc.data}>
|
||||
{doc.label}
|
||||
</SelectSearchItem>
|
||||
</div>
|
||||
</output>
|
||||
<Button
|
||||
@@ -108,6 +102,7 @@
|
||||
</Button>
|
||||
</li>
|
||||
{/each}
|
||||
|
||||
{#if showInput}
|
||||
<li class="u-flex u-gap-16">
|
||||
<InputSelectSearch
|
||||
@@ -117,10 +112,21 @@
|
||||
required
|
||||
bind:search
|
||||
bind:value={relatedList[relatedList.length]}
|
||||
options={documentList?.documents?.map((n) => ({
|
||||
value: n.$id,
|
||||
label: n.$id
|
||||
})) ?? []} />
|
||||
options={documentList?.documents?.map((n) => {
|
||||
const data = displayNames
|
||||
.filter((name) => name !== '$id')
|
||||
.map((name) => n?.[name]);
|
||||
return {
|
||||
value: { label: n.$id, data },
|
||||
label: n.$id,
|
||||
data
|
||||
};
|
||||
}) ?? []}
|
||||
let:option={o}>
|
||||
<SelectSearchItem data={o.data}>
|
||||
{o.label}
|
||||
</SelectSearchItem>
|
||||
</InputSelectSearch>
|
||||
<Button
|
||||
text
|
||||
noMargin
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@
|
||||
{#if i}
|
||||
<span class="clickable-list-title-sep">|</span>
|
||||
{/if}
|
||||
<span>{doc[arg] ?? 'n/a'}</span>
|
||||
<span>{doc[arg]}</span>
|
||||
{/each}
|
||||
<svelte:fragment slot="desc">
|
||||
{doc.$id}
|
||||
|
||||
+4
-7
@@ -80,11 +80,8 @@
|
||||
};
|
||||
}
|
||||
|
||||
function isRelationship(
|
||||
column: (typeof $columns)[0],
|
||||
attr: Partial<Attribute>
|
||||
): attr is Models.AttributeRelationship {
|
||||
return column.type === 'relationship';
|
||||
function isRelationship(attr: Partial<Attribute>): attr is Models.AttributeRelationship {
|
||||
return attr?.type === 'relationship';
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -113,7 +110,7 @@
|
||||
{#each $columns as column}
|
||||
{#if column.show}
|
||||
{@const attr = $attributes.find((n) => n.key === column.id)}
|
||||
{#if isRelationship(column, attr)}
|
||||
{#if isRelationship(attr)}
|
||||
{@const args = $teamPrefs?.displayNames?.[attr.relatedCollection] ?? [
|
||||
'$id'
|
||||
]}
|
||||
@@ -130,7 +127,7 @@
|
||||
{#if arg !== undefined}
|
||||
{i ? '|' : ''}
|
||||
<span class="text">
|
||||
{document[column.id]?.[arg] ?? 'n/a'}
|
||||
{document[column.id]?.[arg]}
|
||||
</span>
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
Reference in new issue
Block a user