mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
basic db selection
This commit is contained in:
1 parent
1fdd2fce65
commit
263e328fe8
5 files changed
+67
-5
No files matched your search
@@ -1,11 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { FormItem, Helper, Label } from '.';
|
||||
|
||||
export let label: string;
|
||||
export let label: string | undefined = undefined;
|
||||
export let optionalText: string | undefined = undefined;
|
||||
export let showLabel = true;
|
||||
export let id: string;
|
||||
export let value = false;
|
||||
export let indeterminate = false;
|
||||
export let required = false;
|
||||
export let disabled = false;
|
||||
|
||||
@@ -27,19 +28,23 @@
|
||||
</script>
|
||||
|
||||
<FormItem>
|
||||
<Label {required} {optionalText} hide={!showLabel} for={id}>
|
||||
{label}
|
||||
</Label>
|
||||
{#if label}
|
||||
<Label {required} {optionalText} hide={!showLabel} for={id}>
|
||||
{label}
|
||||
</Label>
|
||||
{/if}
|
||||
|
||||
<div class="input-text-wrapper">
|
||||
<input
|
||||
{id}
|
||||
{disabled}
|
||||
{required}
|
||||
{indeterminate}
|
||||
type="checkbox"
|
||||
bind:this={element}
|
||||
bind:checked={value}
|
||||
on:invalid={handleInvalid} />
|
||||
on:invalid={handleInvalid}
|
||||
on:click />
|
||||
</div>
|
||||
{#if error}
|
||||
<Helper type="warning">{error}</Helper>
|
||||
|
||||
@@ -88,3 +88,11 @@ export function excludeArray<T, E extends T>(
|
||||
export function includesAll<T>(arr1: T[], arr2: T[]): boolean {
|
||||
return arr2.every((elem) => arr1.includes(elem));
|
||||
}
|
||||
|
||||
export function toggle<T>(arr: T[], elem: T): T[] {
|
||||
if (arr.includes(elem)) {
|
||||
return arr.filter((e) => e !== elem);
|
||||
}
|
||||
arr.push(elem);
|
||||
return arr;
|
||||
}
|
||||
@@ -4,3 +4,11 @@ export type DeepKeys<T extends Record<string, any>> = {
|
||||
[K in keyof T]: T[K] extends Record<string, any> ? `${K}.${DeepKeys<T[K]>}` : K;
|
||||
}[keyof T];
|
||||
export type WritableValue<T> = T extends Writable<infer U> ? U : never;
|
||||
|
||||
export function isHTMLElement(el: unknown): el is HTMLElement {
|
||||
return el instanceof HTMLElement;
|
||||
}
|
||||
|
||||
export function isHTMLInputElement(el: unknown): el is HTMLInputElement {
|
||||
return el instanceof HTMLInputElement;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/stores';
|
||||
import { Id } from '$lib/components';
|
||||
import InputCheckbox from '$lib/elements/forms/inputCheckbox.svelte';
|
||||
import {
|
||||
TableBody,
|
||||
TableCell,
|
||||
@@ -11,16 +12,32 @@
|
||||
TableRowLink,
|
||||
TableScroll
|
||||
} from '$lib/elements/table';
|
||||
import { toggle } from '$lib/helpers/array';
|
||||
import { toLocaleDateTime } from '$lib/helpers/date';
|
||||
import { isHTMLInputElement } from '$lib/helpers/types';
|
||||
import type { PageData } from './$types';
|
||||
import { columns } from './store';
|
||||
|
||||
export let data: PageData;
|
||||
const projectId = $page.params.project;
|
||||
|
||||
let selected: string[] = [];
|
||||
</script>
|
||||
|
||||
<TableScroll>
|
||||
<TableHeader>
|
||||
<TableCellHead width={10}>
|
||||
<InputCheckbox
|
||||
id="select-all"
|
||||
indeterminate={selected.length > 0 && selected.length < data.databases.total}
|
||||
value={selected.length === data.databases.total}
|
||||
on:click={(e) => {
|
||||
if (!isHTMLInputElement(e.target)) return;
|
||||
selected = e.target.checked
|
||||
? data.databases.databases.map((database) => database.$id)
|
||||
: [];
|
||||
}} />
|
||||
</TableCellHead>
|
||||
{#each $columns as column}
|
||||
{#if column.show}
|
||||
<TableCellHead width={column.width}>{column.title}</TableCellHead>
|
||||
@@ -31,6 +48,25 @@
|
||||
{#each data.databases.databases as database}
|
||||
<TableRowLink
|
||||
href={`${base}/console/project-${projectId}/databases/database-${database.$id}`}>
|
||||
<TableCell>
|
||||
<InputCheckbox
|
||||
id="select-{database.$id}"
|
||||
value={selected.includes(database.$id)}
|
||||
on:click={(e) => {
|
||||
// Prevent the link from being followed
|
||||
e.preventDefault();
|
||||
const el = e.currentTarget;
|
||||
if (!isHTMLInputElement(el)) return;
|
||||
|
||||
selected = toggle(selected, database.$id);
|
||||
|
||||
// Hack to make sure the checkbox is checked, independent of the
|
||||
// preventDefault() call above
|
||||
window.setTimeout(() => {
|
||||
el.checked = selected.includes(database.$id);
|
||||
});
|
||||
}} />
|
||||
</TableCell>
|
||||
{#each $columns as column}
|
||||
{#if column.show}
|
||||
{#if column.id === '$id'}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<script lang="ts">
|
||||
export let id;
|
||||
</script>
|
||||
|
||||
<input type="checkbox" {id} on:click />
|
||||
Reference in new issue
Block a user