mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
add: multiSelectTable to function executions.
This commit is contained in:
1 parent
e210612d19
commit
8a8513f7e8
2 files changed
+89
-137
No files matched your search
+83
-125
@@ -1,16 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { Confirm, Id } from '$lib/components';
|
||||
import { type DeleteOperationState, Id, MultiSelectionTable } from '$lib/components';
|
||||
import { toLocaleDateTime } from '$lib/helpers/date';
|
||||
import type { Column } from '$lib/helpers/types';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import {
|
||||
Badge,
|
||||
FloatingActionBar,
|
||||
Status,
|
||||
Table,
|
||||
Tooltip,
|
||||
Typography
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import { Badge, Status, Table, Tooltip, Typography } from '@appwrite.io/pink-svelte';
|
||||
import Sheet from './sheet.svelte';
|
||||
import { capitalize } from '$lib/helpers/string';
|
||||
import { calculateTime } from '$lib/helpers/timeConversion';
|
||||
@@ -21,146 +14,111 @@
|
||||
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 { Button } from '$lib/elements/forms';
|
||||
import { timer } from '$lib/actions/timer';
|
||||
|
||||
export let columns: Column[];
|
||||
export let executions: Models.ExecutionList;
|
||||
let {
|
||||
columns,
|
||||
executions
|
||||
}: {
|
||||
columns: Column[];
|
||||
executions: Models.ExecutionList;
|
||||
} = $props();
|
||||
|
||||
let open = false;
|
||||
let selectedLogId: string = null;
|
||||
|
||||
let selectedRows = [];
|
||||
let showBatchDeletion = false;
|
||||
|
||||
async function deleteExecutions() {
|
||||
showBatchDeletion = false;
|
||||
let open = $state(false);
|
||||
let selectedLogId: string | null = $state(null);
|
||||
|
||||
async function deleteExecutions(selectedRows: string[]): Promise<DeleteOperationState> {
|
||||
const promises = selectedRows.map((executionId) =>
|
||||
sdk.forProject(page.params.region, page.params.project).functions.deleteExecution({
|
||||
functionId: page.params.function,
|
||||
executionId
|
||||
})
|
||||
);
|
||||
|
||||
try {
|
||||
await Promise.all(promises);
|
||||
await invalidate(Dependencies.EXECUTIONS);
|
||||
|
||||
trackEvent(Submit.ExecutionDelete);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${selectedRows.length} execution${selectedRows.length > 1 ? 's' : ''} deleted`
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
trackError(error, Submit.ExecutionDelete);
|
||||
} finally {
|
||||
selectedRows = [];
|
||||
showBatchDeletion = false;
|
||||
invalidate(Dependencies.EXECUTIONS);
|
||||
return error.message;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Table.Root let:root {columns} allowSelection bind:selectedRows>
|
||||
<svelte:fragment slot="header" let:root>
|
||||
<MultiSelectionTable {columns} confirmDeletion resource="execution" onDelete={deleteExecutions}>
|
||||
{#snippet header(root)}
|
||||
{#each columns as { id, title }}
|
||||
<Table.Header.Cell column={id} {root}>{title}</Table.Header.Cell>
|
||||
{/each}
|
||||
</svelte:fragment>
|
||||
{#each executions.executions as log (log.$id)}
|
||||
<Table.Row.Button
|
||||
{root}
|
||||
id={log.$id}
|
||||
on:click={(e) => {
|
||||
e.stopPropagation();
|
||||
open = true;
|
||||
selectedLogId = log.$id;
|
||||
}}>
|
||||
{#each columns as column}
|
||||
<Table.Cell column={column.id} {root}>
|
||||
{#if column.id === '$id'}
|
||||
{#key column.id}
|
||||
<Id value={log.$id}>{log.$id}</Id>
|
||||
{/key}
|
||||
{:else if column.id === 'deploymentId'}
|
||||
<Id value={log.deploymentId}>{log.deploymentId}</Id>
|
||||
{:else if column.id === '$createdAt'}
|
||||
<DualTimeView time={log.$createdAt} />
|
||||
{:else if column.id === 'requestPath'}
|
||||
<Typography.Code size="m">
|
||||
{log.requestPath}
|
||||
</Typography.Code>
|
||||
{:else if column.id === 'responseStatusCode'}
|
||||
<Badge
|
||||
variant="secondary"
|
||||
type={getBadgeTypeFromStatusCode(log.responseStatusCode)}
|
||||
content={log.responseStatusCode.toString()} />
|
||||
{:else if column.id === 'requestMethod'}
|
||||
<Typography.Code size="m">
|
||||
{log.requestMethod}
|
||||
</Typography.Code>
|
||||
{:else if column.id === 'trigger'}
|
||||
{capitalize(log.trigger)}
|
||||
{:else if column.id === 'status'}
|
||||
{@const status = log.status}
|
||||
<Tooltip
|
||||
disabled={!log?.scheduledAt || status !== 'scheduled'}
|
||||
maxWidth="400px">
|
||||
<div>
|
||||
<Status
|
||||
status={logStatusConverter(status)}
|
||||
label={capitalize(status)}>
|
||||
</Status>
|
||||
</div>
|
||||
<span slot="tooltip">
|
||||
{`Scheduled to execute on ${toLocaleDateTime(log.scheduledAt)}`}
|
||||
</span>
|
||||
</Tooltip>
|
||||
{:else if column.id === 'duration'}
|
||||
{#if ['processing', 'waiting'].includes(log.status)}
|
||||
<span use:timer={{ start: log.$createdAt }}></span>
|
||||
{:else}
|
||||
{calculateTime(log.duration)}
|
||||
{/snippet}
|
||||
|
||||
{#snippet children(root)}
|
||||
{#each executions.executions as log (log.$id)}
|
||||
<Table.Row.Button
|
||||
{root}
|
||||
id={log.$id}
|
||||
on:click={(e) => {
|
||||
e.stopPropagation();
|
||||
open = true;
|
||||
selectedLogId = log.$id;
|
||||
}}>
|
||||
{#each columns as column}
|
||||
<Table.Cell column={column.id} {root}>
|
||||
{#if column.id === '$id'}
|
||||
{#key column.id}
|
||||
<Id value={log.$id}>{log.$id}</Id>
|
||||
{/key}
|
||||
{:else if column.id === 'deploymentId'}
|
||||
<Id value={log.deploymentId}>{log.deploymentId}</Id>
|
||||
{:else if column.id === '$createdAt'}
|
||||
<DualTimeView time={log.$createdAt} />
|
||||
{:else if column.id === 'requestPath'}
|
||||
<Typography.Code size="m">
|
||||
{log.requestPath}
|
||||
</Typography.Code>
|
||||
{:else if column.id === 'responseStatusCode'}
|
||||
<Badge
|
||||
variant="secondary"
|
||||
type={getBadgeTypeFromStatusCode(log.responseStatusCode)}
|
||||
content={log.responseStatusCode.toString()} />
|
||||
{:else if column.id === 'requestMethod'}
|
||||
<Typography.Code size="m">
|
||||
{log.requestMethod}
|
||||
</Typography.Code>
|
||||
{:else if column.id === 'trigger'}
|
||||
{capitalize(log.trigger)}
|
||||
{:else if column.id === 'status'}
|
||||
{@const status = log.status}
|
||||
<Tooltip
|
||||
disabled={!log?.scheduledAt || status !== 'scheduled'}
|
||||
maxWidth="400px">
|
||||
<div>
|
||||
<Status
|
||||
status={logStatusConverter(status)}
|
||||
label={capitalize(status)}>
|
||||
</Status>
|
||||
</div>
|
||||
<span slot="tooltip">
|
||||
{`Scheduled to execute on ${toLocaleDateTime(log.scheduledAt)}`}
|
||||
</span>
|
||||
</Tooltip>
|
||||
{:else if column.id === 'duration'}
|
||||
{#if ['processing', 'waiting'].includes(log.status)}
|
||||
<span use:timer={{ start: log.$createdAt }}></span>
|
||||
{:else}
|
||||
{calculateTime(log.duration)}
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
{/each}
|
||||
</Table.Row.Button>
|
||||
{/each}
|
||||
</Table.Root>
|
||||
</Table.Cell>
|
||||
{/each}
|
||||
</Table.Row.Button>
|
||||
{/each}
|
||||
{/snippet}
|
||||
</MultiSelectionTable>
|
||||
|
||||
<Sheet bind:open bind:selectedLogId logs={executions.executions} logging={$func.logging} />
|
||||
|
||||
{#if selectedRows.length > 0}
|
||||
<FloatingActionBar>
|
||||
<svelte:fragment slot="start">
|
||||
<Badge content={selectedRows.length.toString()} />
|
||||
<span>
|
||||
{selectedRows.length > 1 ? 'executions' : 'execution'}
|
||||
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 executions"
|
||||
confirmDeletion
|
||||
onSubmit={deleteExecutions}
|
||||
bind:open={showBatchDeletion}>
|
||||
<p>
|
||||
Are you sure you want to delete <strong>{selectedRows.length}</strong>
|
||||
{selectedRows.length > 1 ? 'executions' : 'execution'}?
|
||||
</p>
|
||||
|
||||
<p class="u-bold">This action is irreversible.</p>
|
||||
</Confirm>
|
||||
+6
-12
@@ -14,13 +14,7 @@
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import Cancel from './(modals)/cancelDeploymentModal.svelte';
|
||||
import { base } from '$app/paths';
|
||||
import {
|
||||
ActionMenu,
|
||||
Icon,
|
||||
Status,
|
||||
Table,
|
||||
Tooltip
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import { ActionMenu, Icon, Status, Table, Tooltip } from '@appwrite.io/pink-svelte';
|
||||
import { Click, Submit, trackError, trackEvent } from '$lib/actions/analytics';
|
||||
import {
|
||||
IconDotsHorizontal,
|
||||
@@ -40,12 +34,12 @@
|
||||
|
||||
let {
|
||||
data,
|
||||
columns,
|
||||
columns
|
||||
}: {
|
||||
data: PageData,
|
||||
columns: Column[]
|
||||
} = $props()
|
||||
|
||||
data: PageData;
|
||||
columns: Column[];
|
||||
} = $props();
|
||||
|
||||
let showDelete = $state(false);
|
||||
let showCancel = $state(false);
|
||||
let showActivate = $state(false);
|
||||
|
||||
Reference in new issue
Block a user