Merge branch feat-databases-v2 into refactor/input-select-search-hiding-x

This commit is contained in:
tglide committed 2023-03-30 16:36:36 +01:00
commit b375b2aa46
12 files changed
+177 -98

No files matched your search

+4 -4
View File
@@ -8,7 +8,7 @@
"dependencies": {
"@analytics/google-analytics": "^1.0.5",
"@appwrite.io/console": "0.1.0-preview-0.1",
"@appwrite.io/pink": "^0.0.6-rc.6",
"@appwrite.io/pink": "^0.0.6-rc.7",
"@popperjs/core": "^2.11.6",
"@sentry/svelte": "^7.44.2",
"@sentry/tracing": "^7.44.2",
@@ -155,9 +155,9 @@
}
},
"node_modules/@appwrite.io/pink": {
"version": "0.0.6-rc.6",
"resolved": "https://registry.npmjs.org/@appwrite.io/pink/-/pink-0.0.6-rc.6.tgz",
"integrity": "sha512-mSOUI2UxRqO3MS4ZXz9bdyAt0VFGRhOwWYGXw+oFfYPjmu6GSKnLEQwjF37DeuArEGRNriTiOFrKqXO0HW0odA==",
"version": "0.0.6-rc.7",
"resolved": "https://registry.npmjs.org/@appwrite.io/pink/-/pink-0.0.6-rc.7.tgz",
"integrity": "sha512-3I+DG4HiysIRJF9ksr+aWMmazUtZ6KrivISu3k+pIX7MjyDhN5la6LVNKgU3d8WWstbHCHoEq5+FYyjsYWWIpA==",
"dependencies": {
"@appwrite.io/pink-icons": "*",
"normalize.css": "^8.0.1",
+1 -1
View File
@@ -20,7 +20,7 @@
"dependencies": {
"@analytics/google-analytics": "^1.0.5",
"@appwrite.io/console": "0.1.0-preview-0.1",
"@appwrite.io/pink": "^0.0.6-rc.6",
"@appwrite.io/pink": "^0.0.6-rc.7",
"@popperjs/core": "^2.11.6",
"@sentry/svelte": "^7.44.2",
"@sentry/tracing": "^7.44.2",
+3
View File
@@ -0,0 +1,3 @@
<ul class="clickable-list">
<slot />
</ul>
@@ -0,0 +1,14 @@
<script lang="ts">
export let href: string;
</script>
<li class="clickable-list-item">
<a {href} class="clickable-list-button" on:click>
<h5 class="clickable-list-title u-trim-1">
<slot />
</h5>
<div class="clickable-list-desc">
<p class="text u-margin-block-start-8"><slot name="desc" /></p>
</div>
</a>
</li>
+2
View File
@@ -51,3 +51,5 @@ export { default as ViewSelector } from './viewSelector.svelte';
export { default as LabelCard } from './labelCard.svelte';
export { default as Limit } from './limit.svelte';
export { default as PaginationWithLimit } from './paginationWithLimit.svelte';
export { default as ClickableList } from './clickableList.svelte';
export { default as ClickableListItem } from './clickableListItem.svelte';
+52 -38
View File
@@ -3,6 +3,14 @@
import { onMount } from 'svelte';
import { Label } from '.';
type Option = $$Generic<{
value: string | boolean | number | Record<string, unknown>;
label: string;
data?: string[];
}>;
type OptionArray = Option[];
export let options: OptionArray;
export let id: string;
export let label: string;
export let name = 'elements';
@@ -12,18 +20,13 @@
export let required = false;
export let disabled = false;
export let autofocus = false;
export let debounce = 250;
export let options: {
value: string | boolean | number;
label: string;
}[];
// Input value
export let search: string = null;
export let search = '';
// The actual selected value
export let value: string | number | boolean;
export let value: Option['value'];
$: selectedOption = options.find((option) => option.value === value);
let element: HTMLInputElement;
let timer: ReturnType<typeof setTimeout>;
let hasFocus = false;
let selected: number = null;
@@ -37,13 +40,8 @@
}
});
function handleInput(event: Event) {
function handleInput() {
hasFocus = true;
clearTimeout(timer);
timer = setTimeout(() => {
const target = event.target as HTMLInputElement;
search = target.value;
}, debounce);
}
function handleKeydown(event: KeyboardEvent) {
@@ -70,14 +68,27 @@
case 'Enter':
if (selected !== null) {
event.preventDefault();
value = options[selected].value;
search = options[selected].label;
hasFocus = false;
selectOption(options[selected]);
}
break;
}
}
function selectOption(option: Option) {
value = option.value;
search = option.label;
// It's not working without this line.
element.value = search;
hasFocus = false;
}
function clearOption() {
value = null;
search = '';
element.value = search;
hasFocus = false;
}
$: showClearBtn = (hasFocus && search) || value;
</script>
@@ -96,19 +107,25 @@
</Label>
<div class="custom-select">
<div class="input-text-wrapper" style:--amount-of-buttons={showClearBtn ? 2 : 1}>
<input
type="text"
class="input-text"
{placeholder}
{disabled}
{required}
bind:value={search}
bind:this={element}
on:focus={() => (hasFocus = true)}
on:click={() => (hasFocus = true)}
on:input={handleInput}
on:keydown={handleKeydown} />
<div class="input-text-wrapper" style="--amount-of-buttons:2">
{#if $$slots.default && selectedOption}
<output class="input-text is-read-only">
<slot option={selectedOption} />
</output>
{:else}
<input
type="text"
class="input-text"
{placeholder}
{disabled}
{required}
bind:value={search}
bind:this={element}
on:focus={() => (hasFocus = true)}
on:click={() => (hasFocus = true)}
on:input={handleInput}
on:keydown={handleKeydown} />
{/if}
<div class="options-list">
{#if showClearBtn}
@@ -116,10 +133,7 @@
class="options-list-button"
aria-label="clear field"
type="button"
on:click|preventDefault={() => {
search = '';
value = null;
}}>
on:click|preventDefault={clearOption}>
<span class="icon-x" aria-hidden="true" />
</button>
{/if}
@@ -140,11 +154,11 @@
class:is-selected={selected === i}
type="button"
on:click|preventDefault={() => {
value = option.value;
search = option.label;
hasFocus = false;
selectOption(option);
}}>
<span class="text">{option.label}</span>
<slot {option}>
<span class="text">{option.label}</span>
</slot>
</button>
</li>
{:else}
+1
View File
@@ -1 +1,2 @@
export { default as Pill } from './pill.svelte';
export { default as SelectSearchItem } from './selectSearchItem.svelte';
+26
View File
@@ -0,0 +1,26 @@
<script lang="ts">
import { tooltip } from '$lib/actions/tooltip';
export let data: string[] = [];
</script>
<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">
<slot />
</span>
{#if data.length}
<span
class="u-flex u-trim-1 u-gap-4"
use:tooltip={{
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}</span>
{/each}
</span>
{/if}
</div>
@@ -44,6 +44,7 @@
import arrowOne from './arrow-one.svg';
import arrowTwo from './arrow-two.svg';
import { camelize } from '$lib/helpers/string';
import { SelectSearchItem } from '$lib/elements';
// Props
export let data: Partial<Models.AttributeRelationship>;
@@ -141,7 +142,12 @@
required
placeholder="Select a collection"
disabled={editing}
options={collections?.map((n) => ({ value: n.$id, label: n.name })) ?? []} />
options={collections?.map((n) => ({ value: n.$id, label: n.$id, data: [n.name] })) ?? []}
let:option={o}>
<SelectSearchItem data={o.data}>
{o.label}
</SelectSearchItem>
</InputSelectSearch>
{#if data?.relatedCollection}
<div>
@@ -1,5 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';
import { SelectSearchItem } from '$lib/elements';
import { Button, InputSelectSearch, Label } from '$lib/elements/forms';
import { organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
@@ -33,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 {
@@ -55,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}
@@ -83,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
@@ -107,6 +102,7 @@
</Button>
</li>
{/each}
{#if showInput}
<li class="u-flex u-gap-16">
<InputSelectSearch
@@ -116,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
@@ -153,8 +160,17 @@
placeholder={`Select ${attribute.key}`}
bind:search
bind:value
options={documentList?.documents?.map((n) => ({
value: n.$id,
label: n?.[displayNames[0]]
})) ?? []} />
options={documentList?.documents?.map((n) => {
const data = displayNames.filter((name) => name !== '$id').map((name) => n?.[name]);
return {
value: n.$id,
label: n.$id,
data
};
}) ?? []}
let:option={o}>
<SelectSearchItem data={o.data}>
{o.label}
</SelectSearchItem>
</InputSelectSearch>
{/if}
@@ -1,18 +1,16 @@
<script lang="ts">
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Modal, PaginationInline } from '$lib/components';
import { TableCell, TableList, TableRowLink } from '$lib/elements/table';
import { ClickableList, ClickableListItem, Modal, Paginator } from '$lib/components';
import { teamPrefs } from '$lib/stores/team';
import type { Models } from '@appwrite.io/console';
export let show = false;
export let data: Models.Document[];
export let data: [];
export let selectedRelationship: Models.AttributeRelationship = null;
const projectId = $page.params.project;
const databaseId = $page.params.database;
const limit = 10;
let offset = 0;
$: args = $teamPrefs?.displayNames?.[selectedRelationship?.relatedCollection];
@@ -26,31 +24,25 @@
<svelte:fragment slot="header">
{selectedRelationship.key}
</svelte:fragment>
<TableList>
{#each data as doc, i}
{#if i >= offset && i < offset + limit}
<TableRowLink
<Paginator items={data} {limit} let:paginatedItems>
<ClickableList>
{#each paginatedItems as doc}
<ClickableListItem
href={`${base}/console/project-${projectId}/databases/database-${databaseId}/collection-${selectedRelationship.relatedCollection}`}
on:click={() => (show = false)}>
<TableCell title={doc.$id}>
<div class="u-flex u-gap-8">
{#each args as arg, i}
{#if i}
<span class="u-color-text-gray">|</span>
{/if}
<span>{doc[arg]}</span>
{/each}
</div>
<span class="u-color-text-gray u-small">{doc.$id}</span>
</TableCell>
</TableRowLink>
{/if}
{/each}
</TableList>
<div class="u-flex u-margin-block-start-32 u-main-space-between">
<p class="text">Total results: {data?.length ?? 0}</p>
<PaginationInline {limit} bind:offset sum={data?.length ?? 0} hidePages />
</div>
{#each args as arg, i}
{#if i}
<span class="clickable-list-title-sep">|</span>
{/if}
<span>{doc[arg]}</span>
{/each}
<svelte:fragment slot="desc">
{doc.$id}
</svelte:fragment>
</ClickableListItem>
{/each}
</ClickableList>
</Paginator>
<svelte:fragment slot="footer" />
</Modal>
@@ -18,6 +18,7 @@
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import type { PageData } from './$types';
import type Attribute from './document-[document]/attribute.svelte';
import RelationshipsModal from './relationshipsModal.svelte';
import { attributes, collection, columns } from './store';
@@ -27,7 +28,7 @@
const databaseId = $page.params.database;
let showRelationships = false;
let selectedRelationship: Models.AttributeRelationship = null;
let relationshipData: Models.Document;
let relationshipData: [];
onMount(() => {
teamPrefs.load($organization.$id);
@@ -78,6 +79,10 @@
whole: formattedColumn
};
}
function isRelationship(attr: Partial<Attribute>): attr is Models.AttributeRelationship {
return attr?.type === 'relationship';
}
</script>
<TableScroll isSticky>
@@ -104,12 +109,11 @@
{#each $columns as column}
{#if column.show}
{#if column.type === 'relationship'}
{@const attr = $attributes.find((n) => n.key === column.id)}
{@const attr = $attributes.find((n) => n.key === column.id)}
{#if isRelationship(attr)}
{@const args = $teamPrefs?.displayNames?.[attr.relatedCollection] ?? [
'$id'
]}
{#if attr?.relationType === 'oneToOne' || attr?.relationType === 'manyToOne'}
<TableCell title={column.title}>
<button
@@ -122,8 +126,9 @@
{#each args as arg, i}
{#if arg !== undefined}
{i ? '|' : ''}
<span class="text"
>{document[column.id]?.[arg]}</span>
<span class="text">
{document[column.id]?.[arg]}
</span>
{/if}
{/each}
</button>