feat: columns save in prefs, select search component

This commit is contained in:
Arman committed 2023-03-06 13:29:55 +01:00
1 parent 42c1b4602e
commit 6bd79b8d65
11 files changed
+123 -95

No files matched your search

+8 -2
View File
@@ -10,6 +10,8 @@
export let noArrow = false;
export let placement: Placement = 'bottom-start';
export let childStart = false;
export let noStyle = false;
export let fullWidth = false;
let element: HTMLDivElement;
let tooltip: HTMLDivElement;
@@ -67,11 +69,15 @@
<svelte:window on:click={onBlur} />
<div class="drop-wrapper" class:u-cross-child-start={childStart} bind:this={element}>
<div class:drop-wrapper={!noStyle} class:u-cross-child-start={childStart} bind:this={element}>
<slot />
</div>
<div class="drop-tooltip" bind:this={tooltip} style="z-index: 10">
<div
class="drop-tooltip"
class:u-width-full-line={fullWidth}
bind:this={tooltip}
style="z-index: 10">
<div class="drop-arrow" class:u-hide={!show || (show && noArrow)} bind:this={arrow} />
{#if show}
<slot name="list" />
+7 -5
View File
@@ -7,18 +7,20 @@
export let scrollable = false;
export let childStart = false;
export let noArrow = false;
export let noStyle = false;
export let width: string = null;
export let fullWidth = false;
export let position: 'relative' | 'static' = 'relative';
</script>
<Drop bind:show {placement} {childStart} {noArrow}>
<Drop bind:show {placement} {childStart} {noArrow} {noStyle} {fullWidth}>
<slot />
<svelte:fragment slot="list">
<div
class="drop is-no-arrow"
style={`${
width
? `--drop-width-size-desktop:${width}rem; position:relative`
: ' position:relative'
class:u-max-width-100-percent={fullWidth}
style={`${width ? `--drop-width-size-desktop:${width}rem; ` : ''} ${
position === 'static' ? 'position:static' : 'position:relative'
}`}>
{#if $$slots.list}
<section
+5 -1
View File
@@ -5,9 +5,13 @@
export let disabled = false;
export let padding: number = 1;
export let icon: string = null;
export let fullHeight = true;
</script>
<label class="card is-allow-focus u-cursor-pointer" style={`--card-padding:${padding}rem`}>
<label
class="card is-allow-focus u-cursor-pointer"
class:u-height-100-percent={fullHeight}
style={`--card-padding:${padding}rem`}>
<div class="u-flex u-gap-16">
<input type="radio" {name} disabled bind:group bind:value />
<div class="u-flex u-flex-vertical u-gap-4">
+25 -3
View File
@@ -2,6 +2,9 @@
import { Button, InputChoice } from '$lib/elements/forms';
import { DropList } from '.';
import { prefs } from '$lib/stores/user';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import type { Writable } from 'svelte/store';
type Column = {
id: string;
@@ -10,15 +13,34 @@
width?: number;
};
export let columns: Writable<Column[]>;
const pathname = $page.url.pathname;
let showSelectColumns = false;
export let columns: Column[];
$: selectedColumnsNumber = columns.reduce((acc, column) => {
onMount(() => {
updateColumns();
});
function updateColumns() {
if ($prefs?.[pathname]) {
$columns.forEach((column, i) => {
column.show = $prefs[pathname][i];
});
$columns = $columns;
}
}
$: selectedColumnsNumber = $columns.reduce((acc, column) => {
if (column.show) {
acc++;
}
return acc;
}, 0);
columns.subscribe((columns) => {
const columnsArray = columns.map((column) => column.show);
prefs.updatePrefs({ ...$prefs, [pathname]: columnsArray });
});
</script>
{#if $prefs?.preferredView === 'list'}
@@ -29,7 +51,7 @@
<span class="inline-tag">{selectedColumnsNumber}</span>
</Button>
<svelte:fragment slot="list">
{#each columns as column}
{#each $columns as column}
<InputChoice
id={column.id}
label={column.name}
+41 -38
View File
@@ -38,42 +38,45 @@
};
</script>
<DropList bind:show={hasFocus} noArrow scrollable placement={'bottom-end'}>
<form class="form u-width-full-line u-max-width-500">
<ul class="form-list">
<FormItem>
<Label {required} {optionalText} hide={!showLabel} for={id}>
{label}
</Label>
<li class="u-position-relative form-item">
<DropList
bind:show={hasFocus}
noStyle
noArrow
scrollable
placement="bottom-end"
position="static"
fullWidth={true}>
<Label {required} {optionalText} hide={!showLabel} for={id}>
{label}
</Label>
<div class="custom-select">
<div class="select u-width-full-line">
<input
type="text"
class="input-text"
{placeholder}
{disabled}
{required}
bind:value={search}
bind:this={element}
on:focus={() => (hasFocus = true)}
on:input={valueChange} />
<span class="icon-cheveron-down" aria-hidden="true" />
</div>
</div>
</FormItem>
</ul>
</form>
<svelte:fragment slot="list">
{#each options as option}
<li class="drop-list-item">
<button
class="drop-button"
type="button"
on:click|preventDefault={() => (value = option.value)}>
<span class="text">{option.label}</span>
</button>
</li>
{/each}
</svelte:fragment>
</DropList>
<div class="custom-select">
<div class="select u-width-full-line">
<input
type="text"
class="input-text"
{placeholder}
{disabled}
{required}
bind:value={search}
bind:this={element}
on:focus={() => (hasFocus = true)}
on:input={valueChange} />
<span class="icon-cheveron-down" aria-hidden="true" />
</div>
</div>
<svelte:fragment slot="list">
{#each options as option}
<li class="drop-list-item">
<button
class="drop-button"
type="button"
on:click|preventDefault={() => (value = option.value)}>
<span class="text">{option.label}</span>
</button>
</li>
{/each}
</svelte:fragment>
</DropList>
</li>
+1 -1
View File
@@ -73,7 +73,7 @@
<div class="pulse-notification" />
</div>
{/if}
<DropList width="28" bind:show={showFeedback} scrollable={true}>
<DropList fullWidth="28" bind:show={showFeedback} scrollable={true}>
<button class="button is-small is-text" on:click={toggleFeedback}>
<span class="text">Feedback</span>
</button>
@@ -12,17 +12,12 @@
import TableView from './tableView.svelte';
import { prefs } from '$lib/stores/user';
import { Dependencies } from '$lib/constants';
import { columns } from './store';
export let data: PageData;
const project = $page.params.project;
let showCreate = false;
let columns = [
{ id: '$id', name: 'Database ID', show: true, width: 50 },
{ id: 'name', name: 'Name', show: true, width: 120 },
{ id: '$createdAt', name: 'Created', show: true, width: 120 },
{ id: '$updatedAt', name: 'Updated', show: true, width: 120 }
];
async function handleCreate(event: CustomEvent<Models.Database>) {
showCreate = false;
@@ -41,7 +36,7 @@
<Heading tag="h2" size="5">Databases</Heading>
<div class="u-flex u-gap-16">
<ViewSelector bind:columns />
<ViewSelector {columns} />
<Button on:click={() => (showCreate = true)} event="create_database">
<span class="icon-plus" aria-hidden="true" />
@@ -14,21 +14,18 @@
TableScroll
} from '$lib/elements/table';
import { toLocaleDateTime } from '$lib/helpers/date';
import type { Writable } from 'svelte/store';
import type { PageData } from './$types';
import type { Column } from './store';
export let data: PageData;
export let columns: {
id: string;
name: string;
width: number;
show: boolean;
}[];
export let columns: Writable<Column[]>;
const project = $page.params.project;
</script>
<TableScroll>
<TableHeader>
{#each columns as column}
{#each $columns as column}
{#if column.show}
<TableCellHead width={column.width}>{column.name}</TableCellHead>
{/if}
@@ -38,7 +35,7 @@
{#each data.databases.databases as database}
<TableRowLink
href={`${base}/console/project-${project}/databases/database-${database.$id}`}>
{#each columns as column}
{#each $columns as column}
{#if column.show}
{#if column.id === '$id'}
<TableCell title={column.name}>
@@ -11,6 +11,7 @@
import GridView from './gridView.svelte';
import TableView from './tableView.svelte';
import { prefs } from '$lib/stores/user';
import { columns } from '../../[[page]]/store';
export let data: PageData;
let showCreate = false;
@@ -18,13 +19,6 @@
const project = $page.params.project;
const databaseId = $page.params.database;
let columns = [
{ id: '$id', name: 'Collection ID', show: true, width: 50 },
{ id: 'name', name: 'Name', show: true, width: 120 },
{ id: '$createdAt', name: 'Created', show: true, width: 120 },
{ id: '$updatedAt', name: 'Updated', show: true, width: 120 }
];
async function handleCreate(event: CustomEvent<Models.Collection>) {
showCreate = false;
await goto(
@@ -38,7 +32,7 @@
<Heading tag="h2" size="5">Collections</Heading>
<div class="u-flex u-gap-16">
<ViewSelector bind:columns />
<ViewSelector {columns} />
<Button on:click={() => (showCreate = true)} event="create_collection">
<span class="icon-plus" aria-hidden="true" />
@@ -14,22 +14,25 @@
TableScroll
} from '$lib/elements/table';
import { toLocaleDateTime } from '$lib/helpers/date';
import type { Writable } from 'svelte/store';
import type { PageData } from './$types';
export let data: PageData;
export let columns: {
id: string;
name: string;
width: number;
show: boolean;
}[];
export let columns: Writable<
{
id: string;
name: string;
width: number;
show: boolean;
}[]
>;
const project = $page.params.project;
const databaseId = $page.params.database;
</script>
<TableScroll>
<TableHeader>
{#each columns as column}
{#each $columns as column}
{#if column.show}
<TableCellHead width={column.width}>{column.name}</TableCellHead>
{/if}
@@ -39,7 +42,7 @@
{#each data.collections.collections as collection}
<TableRowLink
href={`${base}/console/project-${project}/databases/database-${databaseId}/collection-${collection.$id}`}>
{#each columns as column}
{#each $columns as column}
{#if column.show}
{#if column.id === '$id'}
<TableCell title={column.name}>
@@ -86,20 +86,22 @@
}
</script>
<ul class="grid-box" style="--p-grid-item-size:16em; --p-grid-item-size-small-screens:16rem;">
<li>
<LabelCard name="relationship" group="relationship" value="one">
<svelte:fragment slot="title">One-way relationship</svelte:fragment>
One Relation attribute within this collection
</LabelCard>
</li>
<li>
<LabelCard name="relationship" group="relationship" value="two">
<svelte:fragment slot="title">Two-way relationship</svelte:fragment>
One Relation attribute within this collection and another within the related collection
</LabelCard>
</li>
</ul>
<li>
<ul class="grid-box" style="--p-grid-item-size:16em; --p-grid-item-size-small-screens:16rem;">
<li>
<LabelCard name="relationship" group="relationship" value="one">
<svelte:fragment slot="title">One-way relationship</svelte:fragment>
One Relation attribute within this collection
</LabelCard>
</li>
<li>
<LabelCard name="relationship" group="relationship" value="two">
<svelte:fragment slot="title">Two-way relationship</svelte:fragment>
One Relation attribute within this collection and another within the related collection
</LabelCard>
</li>
</ul>
</li>
<Button secondary on:click={() => (isOneWay = true)} disabled={isOneWay}>One</Button>
<Button secondary on:click={() => (isOneWay = false)} disabled={!isOneWay}>Two</Button>