feat: realationship modal

This commit is contained in:
Arman committed 2023-03-13 18:14:42 +01:00
1 parent 446c9c1963
commit 18ca162a81
5 files changed
+109 -16

No files matched your search

+1 -1
View File
@@ -47,7 +47,7 @@
{#if $prefs?.preferredView === 'list'}
<DropList bind:show={showSelectColumns} scrollable={true}>
<Button secondary on:click={() => (showSelectColumns = true)}>
<span class="icon-view-board" aria-hidden="true" aria-label="columns" />
<span class="icon-view-boards u-opacity-50 " aria-hidden="true" aria-label="columns" />
<span class="text">Columns</span>
<span class="inline-tag">{selectedColumnsNumber}</span>
</Button>
@@ -22,9 +22,14 @@
import { tooltip } from '$lib/actions/tooltip';
import { columns } from './store';
import { onMount } from 'svelte';
import RelationshipsModal from './relationshipsModal.svelte';
export let data: PageData;
const projectId = $page.params.project;
const databaseId = $page.params.database;
let showCreateAttribute = false;
let showRelationships = false;
let selectedRelationship: string[] = null;
function openWizard() {
wizard.start(Create);
@@ -35,6 +40,7 @@
...$collection.attributes.map((attribute) => ({
id: attribute.key,
title: attribute.key,
type: attribute.type,
show: true
}))
]);
@@ -56,7 +62,6 @@
}
function formatColumn(column: unknown) {
console.log(column);
let formattedColumn: string;
if (typeof column === 'string') {
@@ -109,7 +114,7 @@
<TableBody>
{#each data.documents.documents as document}
<TableRowLink
href={`${base}/console/project-${$page.params.project}/databases/database-${$page.params.database}/collection-${$collection.$id}/document-${document.$id}`}>
href={`${base}/console/project-${projectId}/databases/database-${databaseId}/collection-${$collection.$id}/document-${document.$id}`}>
<TableCell width={230}>
<Copy value={document.$id}>
<Pill button>
@@ -118,18 +123,39 @@
</Pill>
</Copy>
</TableCell>
{#each $columns as column}
{#if column.show}
{@const formatted = formatColumn(document[column.id])}
<TableCell>
<div
use:tooltip={{
content: formatted.whole,
disabled: !formatted.truncated
}}>
{formatted.value}
</div>
</TableCell>
{#if column.type === 'relationship'}
{#if column.direction === 'one'}
<TableCell title={column.title}>
{document[column.id]}
</TableCell>
{:else}
<TableCell>
{@const itemsNum = column?.data?.lenght}
<Button
on:click={() => {
showRelationships = true;
selectedRelationship = document;
}}
disabled={!itemsNum}>
Items <span class="inline-tag">{itemsNum}</span>
</Button>
</TableCell>
{/if}
{:else}
{@const formatted = formatColumn(document[column.id])}
<TableCell>
<div
use:tooltip={{
content: formatted.whole,
disabled: !formatted.truncated
}}>
{formatted.value}
</div>
</TableCell>
{/if}
{/if}
{/each}
</TableRowLink>
@@ -161,3 +187,4 @@
</Container>
<CreateAttribute bind:showCreate={showCreateAttribute} />
<RelationshipsModal bind:show={showRelationships} {selectedRelationship} />
@@ -0,0 +1,24 @@
<script lang="ts">
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';
export let showCreate = false;
export let selectedRelationship: string = null;
$: if (!showCreate) {
selectedRelationship = null;
}
</script>
<Modal size="big" bind:show={showCreate} icon="relationship">
<svelte:fragment slot="header">
{selectedRelationship}
</svelte:fragment>
<svelte:fragment slot="footer">
<Button secondary disabled={!selectedRelationship} on:click={() => (showCreate = false)}>
Prev
</Button>
<Button secondary disabled={!selectedRelationship}>Next</Button>
</svelte:fragment>
</Modal>
@@ -4,6 +4,8 @@ export type Column = {
id: string;
title: string;
show: boolean;
type?: string;
direction?: string;
width?: number;
};
@@ -1,6 +1,8 @@
<script lang="ts">
import { Button, InputSelectSearch } from '$lib/elements/forms';
import type { Models } from '@aw-labs/appwrite-console';
import { sdkForProject } from '$lib/stores/sdk';
import { Query, type Models } from '@aw-labs/appwrite-console';
import { onMount } from 'svelte';
export let id: string;
export let label: string;
@@ -9,10 +11,39 @@
export let optionalText: string | undefined = undefined;
let addRelationship = false;
let search: string = null;
let collectionList: Models.CollectionList;
onMount(async () => {
collectionList = await getCollections();
});
async function getCollections(search: string = null) {
if (search) {
const collections = await sdkForProject.databases.listCollections(
attribute.related,
[Query.orderDesc('$createdAt')],
search
);
return collections;
} else {
const collections = await sdkForProject.databases.listCollections(attribute.related);
return collections;
}
}
// Reactive statements
$: getCollections(search).then((res) => (collectionList = res));
</script>
{#if attribute.direction === 'one'}
<InputSelectSearch {id} {label} {optionalText} required={attribute.required} bind:value />
<InputSelectSearch
{id}
{label}
{optionalText}
required={attribute.required}
bind:value
options={collectionList?.collections?.map((n) => ({ value: n.$id, label: n.name })) ??
[]} />
{:else if attribute.direction === 'many'}
<div class="u-width-full-line u-max-width-600" />
@@ -33,7 +64,16 @@
<ul class="u-flex-vertical u-gap-4 u-margin-block-start-4">
{#if addRelationship === false}
<InputSelectSearch {id} {label} {optionalText} required bind:value />
<InputSelectSearch
{id}
{label}
{optionalText}
required
bind:value
options={collectionList?.collections?.map((n) => ({
value: n.$id,
label: n.name
})) ?? []} />
{/if}
{#each attribute?.relationships as relationship}
<li class="u-flex u-gap-16">