mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: new components, custom pagination
This commit is contained in:
1 parent
24bab9b938
commit
42c1b4602e
11 files changed
+224
-29
No files matched your search
@@ -0,0 +1,51 @@
|
||||
<script lang="ts">
|
||||
import { goto, invalidate } from '$app/navigation';
|
||||
import type { Dependencies } from '$lib/constants';
|
||||
import { InputSelect } from '$lib/elements/forms';
|
||||
import { customPageLimit } from '$lib/stores/layout';
|
||||
import { Pagination } from '.';
|
||||
export let total: number;
|
||||
export let offset: number;
|
||||
export let limit: number;
|
||||
export let path: string;
|
||||
export let name: string = 'Items';
|
||||
export let dependencies: Dependencies[];
|
||||
|
||||
const options = [
|
||||
{ label: '6', value: 6 },
|
||||
{ label: '12', value: 12 },
|
||||
{ label: '24', value: 24 },
|
||||
{ label: '48', value: 48 },
|
||||
{ label: '96', value: 96 },
|
||||
{ label: '192', value: 192 }
|
||||
];
|
||||
|
||||
async function limitChange() {
|
||||
const currentPage = Math.floor(offset / $customPageLimit + 1);
|
||||
const newPage = Math.floor((offset + 1) / limit);
|
||||
$customPageLimit = limit;
|
||||
|
||||
await Promise.allSettled([
|
||||
dependencies.forEach((dependency) => {
|
||||
invalidate(dependency);
|
||||
})
|
||||
]);
|
||||
if (currentPage !== newPage) {
|
||||
await goto(path + (newPage > 1 ? `/${newPage}` : ``), { replaceState: true });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<div class="u-flex u-gap-12 u-cross-center">
|
||||
<InputSelect
|
||||
id="rows"
|
||||
label="Rows per page"
|
||||
showLabel={false}
|
||||
bind:value={limit}
|
||||
{options}
|
||||
on:change={limitChange} />
|
||||
<p class="text">{name} per page. Total results: {total}</p>
|
||||
</div>
|
||||
<Pagination {offset} {limit} sum={total} {path} />
|
||||
</div>
|
||||
@@ -47,3 +47,5 @@ export { default as Status } from './status.svelte';
|
||||
export { default as Heading } from './heading.svelte';
|
||||
export { default as Output } from './output.svelte';
|
||||
export { default as ViewSelector } from './viewSelector.svelte';
|
||||
export { default as LabelCard } from './labelCard.svelte';
|
||||
export { default as CustomPagination } from './customPagination.svelte';
|
||||
@@ -0,0 +1,23 @@
|
||||
<script lang="ts">
|
||||
export let name: string;
|
||||
export let group: string;
|
||||
export let value: unknown;
|
||||
export let disabled = false;
|
||||
export let padding: number = 1;
|
||||
export let icon: string = null;
|
||||
</script>
|
||||
|
||||
<label class="card is-allow-focus u-cursor-pointer" 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">
|
||||
<h4 class="body-text-2"><slot name="title" /></h4>
|
||||
<p class="u-color-text-gray">
|
||||
<slot />
|
||||
</p>
|
||||
</div>
|
||||
{#if icon}
|
||||
<span class={`icon-${icon} u-margin-inline-start-auto`} aria-hidden="true" />
|
||||
{/if}
|
||||
</div>
|
||||
</label>
|
||||
@@ -15,6 +15,7 @@ export { default as InputDateTime } from './inputDateTime.svelte';
|
||||
export { default as InputSearch } from './inputSearch.svelte';
|
||||
export { default as InputRadio } from './inputRadio.svelte';
|
||||
export { default as InputSelect } from './inputSelect.svelte';
|
||||
export { default as InputSelectSearch } from './inputSelectSearch.svelte';
|
||||
export { default as InputCheckbox } from './inputCheckbox.svelte';
|
||||
export { default as InputChoice } from './inputChoice.svelte';
|
||||
export { default as InputPhone } from './inputPhone.svelte';
|
||||
|
||||
@@ -52,7 +52,8 @@
|
||||
{disabled}
|
||||
bind:this={element}
|
||||
bind:value
|
||||
on:invalid={handleInvalid}>
|
||||
on:invalid={handleInvalid}
|
||||
on:change>
|
||||
{#if placeholder}
|
||||
<option value={null} disabled selected hidden>{placeholder}</option>
|
||||
{/if}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<script lang="ts">
|
||||
import { DropList } from '$lib/components';
|
||||
import { onMount } from 'svelte';
|
||||
import { FormItem, Label } from '.';
|
||||
|
||||
export let id: string;
|
||||
export let label: string;
|
||||
export let optionalText: string | undefined = undefined;
|
||||
export let showLabel = true;
|
||||
export let value: string | number | boolean;
|
||||
export let search: string = null;
|
||||
export let placeholder = '';
|
||||
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;
|
||||
}[];
|
||||
|
||||
let element: HTMLInputElement;
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
let hasFocus = false;
|
||||
|
||||
onMount(() => {
|
||||
if (element && autofocus) {
|
||||
element.focus();
|
||||
}
|
||||
});
|
||||
|
||||
const valueChange = (event: Event) => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
const target = event.target as HTMLInputElement;
|
||||
search = target.value;
|
||||
}, debounce);
|
||||
};
|
||||
</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>
|
||||
|
||||
<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>
|
||||
@@ -15,7 +15,6 @@ export const load: PageLoad = async ({ params, parent, depends }) => {
|
||||
const limit = get(prefs)?.preferredView === 'list' ? get(customPageLimit) : CARD_LIMIT;
|
||||
|
||||
const offset = pageToOffset(page, limit);
|
||||
console.log(offset);
|
||||
|
||||
return {
|
||||
offset,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/stores';
|
||||
import { CardContainer, Copy, GridItem1, Pagination } from '$lib/components';
|
||||
import { CARD_LIMIT } from '$lib/constants';
|
||||
import { CardContainer, Copy, CustomPagination, GridItem1 } from '$lib/components';
|
||||
import { CARD_LIMIT, Dependencies } from '$lib/constants';
|
||||
import { Pill } from '$lib/elements';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
const project = $page.params.project;
|
||||
</script>
|
||||
|
||||
<CardContainer total={data.databases.total} on:click={() => (showCreate = true)} event="database">
|
||||
<CardContainer
|
||||
offset={data.offset}
|
||||
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="title">{database.name}</svelte:fragment>
|
||||
@@ -27,11 +31,10 @@
|
||||
</svelte:fragment>
|
||||
</CardContainer>
|
||||
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {data.databases.total}</p>
|
||||
<Pagination
|
||||
limit={CARD_LIMIT}
|
||||
path={`/console/project-${$page.params.project}/databases`}
|
||||
offset={data.offset}
|
||||
sum={data.databases.total} />
|
||||
</div>
|
||||
<CustomPagination
|
||||
limit={CARD_LIMIT}
|
||||
name="Databases"
|
||||
path={`/console/project-${$page.params.project}/databases`}
|
||||
offset={data.offset}
|
||||
total={data.databases.total}
|
||||
dependencies={[Dependencies.DATABASES]} />
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/stores';
|
||||
import { Copy, Pagination } from '$lib/components';
|
||||
import { PAGE_LIMIT } from '$lib/constants';
|
||||
import { Copy, CustomPagination } from '$lib/components';
|
||||
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
|
||||
import { Pill } from '$lib/elements';
|
||||
import {
|
||||
TableBody,
|
||||
@@ -69,11 +69,10 @@
|
||||
</TableBody>
|
||||
</TableScroll>
|
||||
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {data.databases.total}</p>
|
||||
<Pagination
|
||||
offset={data.offset}
|
||||
limit={PAGE_LIMIT}
|
||||
sum={data.databases.total}
|
||||
path={`/console/project-${$page.params.project}/databases`} />
|
||||
</div>
|
||||
<CustomPagination
|
||||
limit={PAGE_LIMIT}
|
||||
name="Databases"
|
||||
path={`/console/project-${$page.params.project}/databases`}
|
||||
offset={data.offset}
|
||||
total={data.databases.total}
|
||||
dependencies={[Dependencies.DATABASES]} />
|
||||
+41
-4
@@ -1,5 +1,5 @@
|
||||
<script context="module" lang="ts">
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { Query, type Models } from '@aw-labs/appwrite-console';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
|
||||
export async function submitRelationship(
|
||||
@@ -21,10 +21,10 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { InputText, InputSelect, Button } from '$lib/elements/forms';
|
||||
import { InputText, InputSelect, Button, InputSelectSearch } from '$lib/elements/forms';
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { Box } from '$lib/components';
|
||||
import { Box, LabelCard } from '$lib/components';
|
||||
import { collection } from '../store';
|
||||
|
||||
export let selectedAttribute: Models.AttributeString;
|
||||
@@ -46,6 +46,7 @@
|
||||
{ value: 'manyOne', label: 'Many to one' },
|
||||
{ value: 'manyMany', label: 'Many to many' }
|
||||
];
|
||||
let search: string = null;
|
||||
let collections: Models.Collection[] = [];
|
||||
let isOneWay = true;
|
||||
|
||||
@@ -56,7 +57,20 @@
|
||||
});
|
||||
|
||||
async function getCollections() {
|
||||
return await sdkForProject.databases.listCollections(databaseId);
|
||||
if (search) {
|
||||
const collections = await sdkForProject.databases.listCollections(databaseId, [
|
||||
Query.startsWith(search),
|
||||
Query.orderDesc('$createdAt')
|
||||
]);
|
||||
return collections;
|
||||
} else {
|
||||
const collections = await sdkForProject.databases.listCollections(databaseId);
|
||||
return collections;
|
||||
}
|
||||
}
|
||||
|
||||
$: if (search) {
|
||||
getCollections();
|
||||
}
|
||||
|
||||
$: if (selectedAttribute) {
|
||||
@@ -72,9 +86,32 @@
|
||||
}
|
||||
</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>
|
||||
|
||||
<Button secondary on:click={() => (isOneWay = true)} disabled={isOneWay}>One</Button>
|
||||
<Button secondary on:click={() => (isOneWay = false)} disabled={!isOneWay}>Two</Button>
|
||||
|
||||
<InputSelectSearch
|
||||
id="related"
|
||||
label="Related Collection"
|
||||
bind:search
|
||||
bind:value={data.related}
|
||||
required
|
||||
placeholder="Select a collection"
|
||||
options={collections?.map((n) => ({ value: n.$id, label: n.name }))} />
|
||||
<InputSelect
|
||||
id="related"
|
||||
label="Related Collection"
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@
|
||||
async function submit() {
|
||||
try {
|
||||
await $option.func(databaseId, collectionId, key, data);
|
||||
invalidate(Dependencies.COLLECTION);
|
||||
await Promise.allSettled([invalidate(Dependencies.COLLECTION)]);
|
||||
if (!$page.url.pathname.includes('attributes')) {
|
||||
goto(
|
||||
await goto(
|
||||
`${base}/console/project-${$page.params.project}/databases/database-${databaseId}/collection-${collectionId}/attributes`
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user