Skip to content

Commit

Permalink
WIP: Ensure related document shows in Console
Browse files Browse the repository at this point in the history
  • Loading branch information
stnguyen90 committed May 18, 2023
1 parent 30f0a3d commit 6b54427
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,39 @@
});
async function getDocuments(search: string = null) {
const documentList = {
total: 0,
documents: []
};
if (value) {
if (isRelationshipToMany(attribute)) {
documentList.documents.concat($doc[attribute.key]);
documentList.total += $doc[attribute.key].length;
} else {
documentList.documents.push($doc[attribute.key]);
documentList.total += 1;
}
}
if (search) {
const documents = await sdk.forProject.databases.listDocuments(
databaseId,
attribute.relatedCollection,
[Query.search('$id', search), Query.orderDesc('$createdAt')]
[`startsWith("$id", "${search}")`, Query.orderDesc('$createdAt')]
);
return documents;
documentList.documents.concat(documents.documents);
documentList.total += documents.total;
} else {
const documents = await sdk.forProject.databases.listDocuments(
databaseId,
attribute.relatedCollection
);
return documents;
documentList.documents.concat(documents.documents);
documentList.total += documents.total;
}
return documentList;
}
//Reactive statements
Expand All @@ -84,14 +103,14 @@
: [];
$: total = relatedList?.length ?? 0;
$: options =
documentList?.documents?.map((n) => {
(documentList?.documents?.map((n) => {
const data = displayNames.filter((name) => name !== '$id').map((name) => n?.[name]);
return {
value: n.$id,
label: n.$id,
data
};
}) ?? [];
}) ?? []).concat([]);
</script>

{#if isRelationshipToMany(attribute)}
Expand Down

0 comments on commit 6b54427

Please sign in to comment.