mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
add: batch deletions to site logs.
This commit is contained in:
1 parent
2ca6d00d58
commit
c6f5586b16
4 files changed
+73
-9
No files matched your search
@@ -314,6 +314,7 @@ export enum Submit {
|
||||
VariableDelete = 'submit_variable_delete',
|
||||
VariableUpdate = 'submit_variable_update',
|
||||
VariableEditor = 'submit_variable_editor',
|
||||
LogDelete = 'submit_log_delete',
|
||||
|
||||
KeyCreate = 'submit_key_create',
|
||||
KeyDelete = 'submit_key_delete',
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
|
||||
export let data;
|
||||
|
||||
// const logs = getServiceLimit('logs');
|
||||
|
||||
onMount(() => {
|
||||
return sdk.forConsole.client.subscribe('console', (response) => {
|
||||
if (response.events.includes('sites.*.executions.*')) {
|
||||
|
||||
@@ -65,6 +65,7 @@ export const columns = writable<Column[]>([
|
||||
{
|
||||
id: 'duration',
|
||||
title: 'Duration',
|
||||
width: { min: 80, max: 200 },
|
||||
type: 'integer',
|
||||
format: 'integer',
|
||||
elements: [
|
||||
@@ -80,9 +81,7 @@ export const columns = writable<Column[]>([
|
||||
value: 30,
|
||||
label: 'more than 30 seconds'
|
||||
}
|
||||
],
|
||||
filter: false,
|
||||
exclude: true
|
||||
]
|
||||
},
|
||||
{
|
||||
id: '$createdAt',
|
||||
|
||||
+70
-4
@@ -1,10 +1,18 @@
|
||||
<script lang="ts">
|
||||
import { Id } from '$lib/components';
|
||||
import { Confirm, Id } from '$lib/components';
|
||||
import type { Column } from '$lib/helpers/types';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { Badge, Table, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { Badge, FloatingActionBar, Table, Typography } from '@appwrite.io/pink-svelte';
|
||||
import Sheet from './sheet.svelte';
|
||||
import DualTimeView from '$lib/components/dualTimeView.svelte';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { page } from '$app/state';
|
||||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { formatTimeDetailed } from '$lib/helpers/timeConversion';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
|
||||
export let columns: Column[];
|
||||
export let logs: Models.ExecutionList;
|
||||
@@ -13,17 +21,48 @@
|
||||
let selectedLogId: string = null;
|
||||
|
||||
$: filteredColumns = columns.filter((c) => !c.exclude);
|
||||
|
||||
let selectedRows = [];
|
||||
let showBatchDeletion = false;
|
||||
|
||||
async function deleteLogs() {
|
||||
showBatchDeletion = false;
|
||||
|
||||
const promises = selectedRows.map((logId) =>
|
||||
sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.sites.deleteLog(page.params.site, logId)
|
||||
);
|
||||
try {
|
||||
await Promise.all(promises);
|
||||
trackEvent(Submit.LogDelete);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${selectedRows.length} log${selectedRows.length > 1 ? 's' : ''} deleted`
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
trackError(error, Submit.LogDelete);
|
||||
} finally {
|
||||
selectedRows = [];
|
||||
invalidate(Dependencies.EXECUTIONS);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Table.Root columns={filteredColumns} let:root>
|
||||
<Table.Root let:root allowSelection bind:selectedRows columns={filteredColumns}>
|
||||
<svelte:fragment slot="header" let:root>
|
||||
{#each filteredColumns as { id, title }}
|
||||
<Table.Header.Cell column={id} {root}>{title}</Table.Header.Cell>
|
||||
{/each}
|
||||
</svelte:fragment>
|
||||
{#each logs.executions as log}
|
||||
{#each logs.executions as log (log.$id)}
|
||||
<Table.Row.Button
|
||||
{root}
|
||||
id={log.$id}
|
||||
on:click={(e) => {
|
||||
e.stopPropagation();
|
||||
openSheet = true;
|
||||
@@ -39,6 +78,8 @@
|
||||
<Typography.Code size="m">
|
||||
{log.requestMethod}
|
||||
</Typography.Code>
|
||||
{:else if column.id === 'duration'}
|
||||
{formatTimeDetailed(log.duration)}
|
||||
{:else if column.id === 'responseStatusCode'}
|
||||
<div>
|
||||
<Badge
|
||||
@@ -60,3 +101,28 @@
|
||||
</Table.Root>
|
||||
|
||||
<Sheet bind:open={openSheet} bind:selectedLogId logs={logs.executions} />
|
||||
|
||||
{#if selectedRows.length > 0}
|
||||
<FloatingActionBar>
|
||||
<svelte:fragment slot="start">
|
||||
<Badge content={selectedRows.length.toString()} />
|
||||
<span>
|
||||
{selectedRows.length > 1 ? 'logs' : 'log'}
|
||||
selected
|
||||
</span>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="end">
|
||||
<Button text on:click={() => (selectedRows = [])}>Cancel</Button>
|
||||
<Button secondary on:click={() => (showBatchDeletion = true)}>Delete</Button>
|
||||
</svelte:fragment>
|
||||
</FloatingActionBar>
|
||||
{/if}
|
||||
|
||||
<Confirm title="Delete logs" confirmDeletion onSubmit={deleteLogs} bind:open={showBatchDeletion}>
|
||||
<p>
|
||||
Are you sure you want to delete <b>{selectedRows.length}</b>
|
||||
{selectedRows.length > 1 ? 'logs' : 'log'}?
|
||||
</p>
|
||||
|
||||
<p class="u-bold">This action is irreversible.</p>
|
||||
</Confirm>
|
||||
Reference in new issue
Block a user