mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
bulk db deletion
This commit is contained in:
1 parent
263e328fe8
commit
92af191e5a
5 files changed
+126
-4
No files matched your search
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { portal } from '$lib/actions/portal';
|
||||
import { fly } from 'svelte/transition';
|
||||
|
||||
export let show = false;
|
||||
</script>
|
||||
|
||||
{#if show}
|
||||
<div class="floating-action-bar" transition:fly={{ y: '6rem' }} use:portal>
|
||||
<slot />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style lang="scss">
|
||||
.floating-action-bar {
|
||||
position: fixed;
|
||||
bottom: 2rem;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
z-index: 100;
|
||||
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
:global(.theme-dark) .floating-action-bar {
|
||||
border: 1px solid hsl(var(--color-neutral-200));
|
||||
background: hsl(var(--color-neutral-300));
|
||||
box-shadow: 0px 6px 16px 8px #14141f;
|
||||
}
|
||||
|
||||
:global(.theme-light) .floating-action-bar {
|
||||
border: 1px solid hsl(var(--color-neutral-30));
|
||||
background: hsl(var(--color-neutral-0));
|
||||
box-shadow: 0px 6px 16px 0px rgba(55, 59, 77, 0.14);
|
||||
}
|
||||
</style>
|
||||
@@ -57,5 +57,5 @@ export { default as ClickableListItem } from './clickableListItem.svelte';
|
||||
export { default as Id } from './id.svelte';
|
||||
export { default as EyebrowHeading } from './eyebrowHeading.svelte';
|
||||
export { default as SvgIcon } from './svgIcon.svelte';
|
||||
|
||||
export { default as MigrationBox } from './migrationBox.svelte';
|
||||
export { default as FloatingActionBar } from './floatingActionBar.svelte';
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { Writable } from 'svelte/store';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export type DeepKeys<T extends Record<string, any>> = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-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;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { CARD_LIMIT } from '$lib/constants';
|
||||
import { CARD_LIMIT, Dependencies } from '$lib/constants';
|
||||
import { getLimit, getPage, getView, pageToOffset, View } from '$lib/helpers/load';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
export const load: PageLoad = async ({ url, route }) => {
|
||||
export const load: PageLoad = async ({ url, route, depends }) => {
|
||||
depends(Dependencies.DATABASES);
|
||||
const page = getPage(url);
|
||||
const limit = getLimit(url, route, CARD_LIMIT);
|
||||
const view = getView(url, route, View.Grid);
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/stores';
|
||||
import { Id } from '$lib/components';
|
||||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
|
||||
import { Id, Modal } from '$lib/components';
|
||||
import FloatingActionBar from '$lib/components/floatingActionBar.svelte';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import Button from '$lib/elements/forms/button.svelte';
|
||||
import InputCheckbox from '$lib/elements/forms/inputCheckbox.svelte';
|
||||
import {
|
||||
TableBody,
|
||||
@@ -15,6 +20,8 @@
|
||||
import { toggle } from '$lib/helpers/array';
|
||||
import { toLocaleDateTime } from '$lib/helpers/date';
|
||||
import { isHTMLInputElement } from '$lib/helpers/types';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import type { PageData } from './$types';
|
||||
import { columns } from './store';
|
||||
|
||||
@@ -22,6 +29,32 @@
|
||||
const projectId = $page.params.project;
|
||||
|
||||
let selected: string[] = [];
|
||||
let showDelete = false;
|
||||
let deleting = false;
|
||||
|
||||
async function handleDelete() {
|
||||
showDelete = false;
|
||||
|
||||
const promises = selected.map((databaseId) => sdk.forProject.databases.delete(databaseId));
|
||||
try {
|
||||
await Promise.all(promises);
|
||||
trackEvent(Submit.DatabaseDelete);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${selected.length} database${selected.length > 1 ? 's' : ''} deleted`
|
||||
});
|
||||
invalidate(Dependencies.DATABASES);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
trackError(error, Submit.DatabaseDelete);
|
||||
} finally {
|
||||
selected = [];
|
||||
showDelete = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<TableScroll>
|
||||
@@ -92,3 +125,52 @@
|
||||
{/each}
|
||||
</TableBody>
|
||||
</TableScroll>
|
||||
|
||||
<FloatingActionBar show={selected.length > 0}>
|
||||
<div class="u-flex u-cross-center u-main-space-between actions">
|
||||
<div class="u-flex u-cross-center u-gap-8">
|
||||
<span class="indicator body-text-2 u-bold">{selected.length}</span>
|
||||
<span>
|
||||
{selected.length > 1 ? 'databases' : 'database'} selected
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="u-flex u-cross-center u-gap-8">
|
||||
<Button text on:click={() => (selected = [])}>Cancel</Button>
|
||||
<Button secondary on:click={() => (showDelete = true)}>Delete selection</Button>
|
||||
</div>
|
||||
</div>
|
||||
</FloatingActionBar>
|
||||
|
||||
<Modal
|
||||
icon="exclamation"
|
||||
state="warning"
|
||||
bind:show={showDelete}
|
||||
onSubmit={handleDelete}
|
||||
headerDivider={false}
|
||||
closable={!deleting}>
|
||||
<svelte:fragment slot="header">Delete Database</svelte:fragment>
|
||||
<p class="text" data-private>
|
||||
Are you sure you want to delete <b>{selected.length}</b>
|
||||
{selected.length > 1 ? 'databases' : 'database'}?
|
||||
</p>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button text on:click={() => (showDelete = false)} disabled={deleting}>Cancel</Button>
|
||||
<Button secondary submit disabled={deleting}>Delete</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
|
||||
<style lang="scss">
|
||||
.actions {
|
||||
width: 31.25rem;
|
||||
|
||||
.indicator {
|
||||
border-radius: 0.25rem;
|
||||
background: hsl(var(--color-information-100));
|
||||
color: hsl(var(--color-neutral-0));
|
||||
|
||||
padding: 0rem 0.375rem;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user