mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: table view update
This commit is contained in:
1 parent
3ffa758f41
commit
e6cbc89cc3
10 files changed
+139
-64
No files matched your search
@@ -1,9 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { Empty } from '$lib/components';
|
||||
import { cardLimit } from '$lib/stores/layout';
|
||||
import { CARD_LIMIT } from '$lib/constants';
|
||||
|
||||
export let offset = 0;
|
||||
export let limit = $cardLimit;
|
||||
export let total = 0;
|
||||
export let event: string = null;
|
||||
</script>
|
||||
@@ -13,7 +12,7 @@
|
||||
style={`--grid-gap:1.5rem; --grid-item-size:${total > 3 ? '22rem' : '25rem'};`}>
|
||||
<slot />
|
||||
|
||||
{#if total > 3 ? total < limit + offset : total % 2 !== 0}
|
||||
{#if total > 3 ? total < CARD_LIMIT + offset : total % 2 !== 0}
|
||||
<Empty on:click target={event}>
|
||||
<slot name="empty" />
|
||||
</Empty>
|
||||
|
||||
@@ -1,18 +1,40 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { Button, InputChoice } from '$lib/elements/forms';
|
||||
import { DropList } from '.';
|
||||
import { preferredView } from '$lib/stores/layout';
|
||||
|
||||
type Column = {
|
||||
id: string;
|
||||
name: string;
|
||||
show: boolean;
|
||||
width?: number;
|
||||
};
|
||||
|
||||
let showSelectColumns = false;
|
||||
export let columns: Column[];
|
||||
|
||||
$: selectedColumnsNumber = columns.reduce((acc, column) => {
|
||||
if (column.show) {
|
||||
acc++;
|
||||
}
|
||||
return acc;
|
||||
}, 0);
|
||||
</script>
|
||||
|
||||
<DropList bind:show={showSelectColumns} scrollable={true}>
|
||||
<Button secondary on:click={() => (showSelectColumns = true)}>
|
||||
<span class="icon-view-board" />
|
||||
<span class="text">Columns</span>
|
||||
<span class="text">{selectedColumnsNumber}</span>
|
||||
</Button>
|
||||
<svelte:fragment slot="other">
|
||||
<slot />
|
||||
<svelte:fragment slot="list">
|
||||
{#each columns as column}
|
||||
<InputChoice
|
||||
id={column.id}
|
||||
label={column.name}
|
||||
bind:value={column.show}
|
||||
disabled={selectedColumnsNumber <= 1 && column.show} />
|
||||
{/each}
|
||||
</svelte:fragment>
|
||||
</DropList>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { writable, readable } from 'svelte/store';
|
||||
import type { SvelteComponent } from 'svelte';
|
||||
import { browser } from '$app/environment';
|
||||
import { PAGE_LIMIT } from '$lib/constants';
|
||||
|
||||
export type Tab = {
|
||||
href: string;
|
||||
@@ -27,13 +28,22 @@ export function updateLayout(args: updateLayoutArguments) {
|
||||
breadcrumb.set(args.breadcrumb ?? null);
|
||||
}
|
||||
|
||||
export const pageLimit = readable(12); // default page limit
|
||||
export const cardLimit = readable(6); // default card limit
|
||||
export const customPageLimit = writable<number>(
|
||||
browser
|
||||
? sessionStorage.getItem('customPageLimit')?.length
|
||||
? parseInt(sessionStorage.getItem('customPageLimit'))
|
||||
: PAGE_LIMIT
|
||||
: PAGE_LIMIT
|
||||
);
|
||||
|
||||
export const preferredView = writable<View>(
|
||||
browser ? (sessionStorage.getItem('prefferedView') as View) : 'grid'
|
||||
);
|
||||
|
||||
if (browser) {
|
||||
console.log(sessionStorage.getItem('customPageLimit'));
|
||||
preferredView.subscribe((u) => sessionStorage.setItem('prefferedView', u ?? 'grid'));
|
||||
customPageLimit.subscribe((u) =>
|
||||
sessionStorage.setItem('customPageLimit', u.toString() ?? PAGE_LIMIT.toString())
|
||||
);
|
||||
}
|
||||
@@ -14,16 +14,24 @@
|
||||
import { Dependencies } from '$lib/constants';
|
||||
|
||||
export let data: PageData;
|
||||
const project = $page.params.project;
|
||||
|
||||
let showCreate = false;
|
||||
const project = $page.params.project;
|
||||
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;
|
||||
await goto(`${base}/console/project-${project}/databases/database-${event.detail.$id}`);
|
||||
}
|
||||
|
||||
$: preferredView.subscribe(() => {
|
||||
$: preferredView.subscribe((n) => {
|
||||
console.log(n);
|
||||
invalidate(Dependencies.DATABASE);
|
||||
invalidate(Dependencies.COLLECTION);
|
||||
});
|
||||
</script>
|
||||
@@ -33,7 +41,7 @@
|
||||
<Heading tag="h2" size="5">Databases</Heading>
|
||||
|
||||
<div class="u-flex u-gap-16">
|
||||
<ViewSelector>test</ViewSelector>
|
||||
<ViewSelector bind:columns />
|
||||
|
||||
<Button on:click={() => (showCreate = true)} event="create_database">
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
@@ -44,7 +52,7 @@
|
||||
|
||||
{#if data.databases.total}
|
||||
{#if $preferredView === 'list'}
|
||||
<TableView {data} />
|
||||
<TableView {data} {columns} />
|
||||
{:else}
|
||||
<GridView {data} bind:showCreate />
|
||||
{/if}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import { Query } from '@aw-labs/appwrite-console';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { pageToOffset } from '$lib/helpers/load';
|
||||
import { CARD_LIMIT, PAGE_LIMIT } from '$lib/constants';
|
||||
import { CARD_LIMIT } from '$lib/constants';
|
||||
import type { PageLoad } from './$types';
|
||||
import { preferredView } from '$lib/stores/layout';
|
||||
import { customPageLimit, preferredView } from '$lib/stores/layout';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export const load: PageLoad = async ({ params, parent }) => {
|
||||
await parent();
|
||||
const page = Number(params.page);
|
||||
const limit = get(preferredView) === 'list' ? PAGE_LIMIT : CARD_LIMIT;
|
||||
console.log(get(preferredView));
|
||||
const limit = get(preferredView) === 'list' ? get(customPageLimit) : CARD_LIMIT;
|
||||
|
||||
const offset = pageToOffset(page, limit);
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
<CardContainer total={data.databases.total} on:click={() => (showCreate = true)} event="database">
|
||||
{#each data.databases.databases as database}
|
||||
<GridItem1 href={`${base}/console/project-${project}/databases/database-${database.$id}`}>
|
||||
<!-- <svelte:fragment slot="eyebrow">X Collections</svelte:fragment> -->
|
||||
<svelte:fragment slot="title">{database.name}</svelte:fragment>
|
||||
|
||||
<Copy value={database.$id}>
|
||||
@@ -24,7 +23,7 @@
|
||||
</GridItem1>
|
||||
{/each}
|
||||
<svelte:fragment slot="empty">
|
||||
<p>Create a new database</p>
|
||||
<p class="text">Create a new database</p>
|
||||
</svelte:fragment>
|
||||
</CardContainer>
|
||||
|
||||
|
||||
@@ -17,37 +17,53 @@
|
||||
import type { PageData } from './$types';
|
||||
|
||||
export let data: PageData;
|
||||
export let columns: {
|
||||
id: string;
|
||||
name: string;
|
||||
width: number;
|
||||
show: boolean;
|
||||
}[];
|
||||
const project = $page.params.project;
|
||||
</script>
|
||||
|
||||
<TableScroll>
|
||||
<TableHeader>
|
||||
<TableCellHead width={45}>Database ID</TableCellHead>
|
||||
<TableCellHead width={100}>Name</TableCellHead>
|
||||
<TableCellHead width={100}>Updated At</TableCellHead>
|
||||
<TableCellHead width={100}>Created At</TableCellHead>
|
||||
{#each columns as column}
|
||||
{#if column.show}
|
||||
<TableCellHead width={column.width}>{column.name}</TableCellHead>
|
||||
{/if}
|
||||
{/each}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each data.databases.databases as database}
|
||||
<TableRowLink
|
||||
href={`${base}/console/project-${project}/databases/database-${database.$id}`}>
|
||||
<TableCell title="Deployment ID">
|
||||
<Copy value={database.$id}>
|
||||
<Pill button trim>
|
||||
<span class="icon-duplicate" aria-hidden="true" />
|
||||
<span class="text u-trim">{database.$id}</span>
|
||||
</Pill>
|
||||
</Copy>
|
||||
</TableCell>
|
||||
<TableCellText title="Name">
|
||||
{database.name}
|
||||
</TableCellText>
|
||||
<TableCellText title="Updated">
|
||||
{toLocaleDateTime(database.$updatedAt)}
|
||||
</TableCellText>
|
||||
<TableCellText title="Created">
|
||||
{toLocaleDateTime(database.$createdAt)}
|
||||
</TableCellText>
|
||||
{#each columns as column}
|
||||
{#if column.show}
|
||||
{#if column.id === '$id'}
|
||||
<TableCell title={column.name}>
|
||||
<Copy value={database.$id}>
|
||||
<Pill button trim>
|
||||
<span class="icon-duplicate" aria-hidden="true" />
|
||||
<span class="text u-trim">{database.$id}</span>
|
||||
</Pill>
|
||||
</Copy>
|
||||
</TableCell>
|
||||
{:else if column.id === 'name'}
|
||||
<TableCellText title={column.name}>
|
||||
{database.name}
|
||||
</TableCellText>
|
||||
{:else if column.id === '$updatedAt'}
|
||||
<TableCellText title={column.name}>
|
||||
{toLocaleDateTime(database.$updatedAt)}
|
||||
</TableCellText>
|
||||
{:else if column.id === '$createdAt'}
|
||||
<TableCellText title={column.name}>
|
||||
{toLocaleDateTime(database.$createdAt)}
|
||||
</TableCellText>
|
||||
{/if}
|
||||
{/if}
|
||||
{/each}
|
||||
</TableRowLink>
|
||||
{/each}
|
||||
</TableBody>
|
||||
|
||||
+9
-2
@@ -19,6 +19,13 @@
|
||||
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(
|
||||
@@ -36,7 +43,7 @@
|
||||
<Heading tag="h2" size="5">Collections</Heading>
|
||||
|
||||
<div class="u-flex u-gap-16">
|
||||
<ViewSelector>test</ViewSelector>
|
||||
<ViewSelector bind:columns />
|
||||
|
||||
<Button on:click={() => (showCreate = true)} event="create_collection">
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
@@ -47,7 +54,7 @@
|
||||
|
||||
{#if data.collections.total}
|
||||
{#if $preferredView === 'list'}
|
||||
<TableView {data} />
|
||||
<TableView {data} {columns} />
|
||||
{:else}
|
||||
<GridView {data} bind:showCreate />
|
||||
{/if}
|
||||
|
||||
+1
-2
@@ -6,14 +6,13 @@
|
||||
import { Pill } from '$lib/elements';
|
||||
import { createPersistentPagination } from '$lib/stores/pagination';
|
||||
import type { PageData } from './$types';
|
||||
import { cardLimit } from '$lib/stores/layout';
|
||||
|
||||
export let data: PageData;
|
||||
export let showCreate = false;
|
||||
|
||||
const databaseId = $page.params.database;
|
||||
const project = $page.params.project;
|
||||
const offset = createPersistentPagination($cardLimit);
|
||||
const offset = createPersistentPagination(CARD_LIMIT);
|
||||
</script>
|
||||
|
||||
<CardContainer
|
||||
|
||||
+37
-21
@@ -17,38 +17,54 @@
|
||||
import type { PageData } from './$types';
|
||||
|
||||
export let data: PageData;
|
||||
export let columns: {
|
||||
id: string;
|
||||
name: string;
|
||||
width: number;
|
||||
show: boolean;
|
||||
}[];
|
||||
const project = $page.params.project;
|
||||
const databaseId = $page.params.database;
|
||||
</script>
|
||||
|
||||
<TableScroll>
|
||||
<TableHeader>
|
||||
<TableCellHead width={45}>Collection ID</TableCellHead>
|
||||
<TableCellHead width={100}>Name</TableCellHead>
|
||||
<TableCellHead width={100}>Updated At</TableCellHead>
|
||||
<TableCellHead width={100}>Created At</TableCellHead>
|
||||
{#each columns as column}
|
||||
{#if column.show}
|
||||
<TableCellHead width={column.width}>{column.name}</TableCellHead>
|
||||
{/if}
|
||||
{/each}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each data.collections.collections as collection}
|
||||
<TableRowLink
|
||||
href={`${base}/console/project-${project}/databases/database-${databaseId}/collection-${collection.$id}`}>
|
||||
<TableCell title="Deployment ID">
|
||||
<Copy value={collection.$id}>
|
||||
<Pill button trim>
|
||||
<span class="icon-duplicate" aria-hidden="true" />
|
||||
<span class="text u-trim">{collection.$id}</span>
|
||||
</Pill>
|
||||
</Copy>
|
||||
</TableCell>
|
||||
<TableCellText title="Name">
|
||||
{collection.name}
|
||||
</TableCellText>
|
||||
<TableCellText title="Updated">
|
||||
{toLocaleDateTime(collection.$updatedAt)}
|
||||
</TableCellText>
|
||||
<TableCellText title="Created">
|
||||
{toLocaleDateTime(collection.$createdAt)}
|
||||
</TableCellText>
|
||||
{#each columns as column}
|
||||
{#if column.show}
|
||||
{#if column.id === '$id'}
|
||||
<TableCell title={column.name}>
|
||||
<Copy value={collection.$id}>
|
||||
<Pill button trim>
|
||||
<span class="icon-duplicate" aria-hidden="true" />
|
||||
<span class="text u-trim">{collection.$id}</span>
|
||||
</Pill>
|
||||
</Copy>
|
||||
</TableCell>
|
||||
{:else if column.id === 'name'}
|
||||
<TableCellText title={column.name}>
|
||||
{collection.name}
|
||||
</TableCellText>
|
||||
{:else if column.id === '$updatedAt'}
|
||||
<TableCellText title={column.name}>
|
||||
{toLocaleDateTime(collection.$updatedAt)}
|
||||
</TableCellText>
|
||||
{:else if column.id === '$createdAt'}
|
||||
<TableCellText title={column.name}>
|
||||
{toLocaleDateTime(collection.$createdAt)}
|
||||
</TableCellText>
|
||||
{/if}
|
||||
{/if}
|
||||
{/each}
|
||||
</TableRowLink>
|
||||
{/each}
|
||||
</TableBody>
|
||||
|
||||
Reference in new issue
Block a user