Skip to content

Modern Docker Management, Designed for Everyone

refactor: consolidate frontend logic / components (#2757)

Kyle Mendell538465a2ce51
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index 2d91be8fb..82490a840 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -146,6 +146,8 @@
"common_standby": "Standby",
"common_offline": "Offline",
"common_copy": "Copy",
+ "common_copied": "Copied to clipboard",
+ "common_copy_failed": "Failed to copy",
"common_copy_json": "Copy JSON",
"common_close": "Close",
"common_invalid_email": "Must be a valid email",
@@ -288,8 +290,10 @@
"common_redeploy_success": "{type} Redeployed Successfully",
"common_bulk_remove_success": "Successfully removed {count} {resource}",
"common_bulk_remove_failed": "Failed to remove {count} {resource}",
+ "common_bulk_remove_partial": "Removed {success} of {total} {resource}. {failed} failed.",
"common_bulk_delete_success": "Successfully deleted {count} {resource}",
"common_bulk_delete_failed": "Failed to delete {count} {resource}",
+ "common_bulk_delete_partial": "Deleted {success} of {total} {resource}. {failed} failed.",
"_comment_common_confirmations": "=== COMMON - CONFIRMATION DIALOGS ===",
"common_delete_title": "Delete {resource}",
"common_delete_confirm": "Are you sure you want to delete {resource}? This action cannot be undone.",
diff --git a/frontend/src/lib/components/arcane-table/arcane-table.svelte b/frontend/src/lib/components/arcane-table/arcane-table.svelte
index ad57bc327..f6b96f5ef 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table.svelte
@@ -33,7 +33,7 @@
type BulkAction
} from './arcane-table.types.svelte';
import type { Component } from 'svelte';
- import { extractPersistedPreferences, filterMapsEqual, toFilterMap } from './arcane-table.utils';
+ import { extractPersistedPreferences, filterMapsEqual, fromFilterMap, toFilterMap } from './arcane-table.utils';
import ArcaneTablePagination from './arcane-table-pagination.svelte';
import ArcaneTableHeader from './arcane-table-header.svelte';
import ArcaneTableCell from './arcane-table-cell.svelte';
@@ -607,6 +607,19 @@
}
});
+ // Reflect externally-set requestOptions.filters (e.g. a clickable stat card applying
+ // a filter) back into the facet UI so the displayed filters match the active query.
+ // Only mutates local columnFilters — never triggers onRefresh — so it can't loop with
+ // the forward onColumnFiltersChange path.
+ $effect(() => {
+ const incoming = requestOptions?.filters;
+ const currentMap = untrack(() => toFilterMap(columnFilters));
+ if (filterMapsEqual(incoming, currentMap)) return;
+ untrack(() => {
+ columnFilters = fromFilterMap(incoming);
+ });
+ });
+
// Track last persisted settings to prevent infinite loops
let lastPersistedSettings: string | null = null;
let persistTimeout: ReturnType<typeof setTimeout> | null = null;
diff --git a/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts b/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts
index fa5606fa6..1c8c12801 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts
+++ b/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts
@@ -130,7 +130,7 @@ export function buildMobileVisibility(fields: FieldSpec[], persisted?: string[])
export type BulkAction = {
id: string;
label: string;
- action: 'base' | 'start' | 'stop' | 'restart' | 'remove' | 'deploy' | 'redeploy' | 'up' | 'down';
+ action: 'base' | 'start' | 'stop' | 'restart' | 'remove' | 'deploy' | 'redeploy' | 'up' | 'down' | 'prune';
onClick: (ids: string[]) => void;
disabled?: boolean;
disabledReason?: string;
diff --git a/frontend/src/lib/components/arcane-table/arcane-table.utils.ts b/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
index eb26ef09b..c7ee3fd66 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
+++ b/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
@@ -34,6 +34,23 @@ export function toFilterMap(filters: ColumnFiltersState): FilterMap {
return out;
}
+/**
+ * Inverse of {@link toFilterMap}: rebuilds tanstack `ColumnFiltersState` from a
+ * request `FilterMap`. Used to reflect externally-set `requestOptions.filters`
+ * (e.g. a clickable stat card) back into the faceted-filter UI. Values are kept
+ * as-is so they match the facet option `value` types (array, boolean, string).
+ */
+export function fromFilterMap(map?: FilterMap): ColumnFiltersState {
+ if (!map) return [];
+ const out: ColumnFiltersState = [];
+ for (const [id, value] of Object.entries(map)) {
+ if (value === undefined || value === null) continue;
+ if (Array.isArray(value) && value.length === 0) continue;
+ out.push({ id, value });
+ }
+ return out;
+}
+
export function filterMapsEqual(a?: FilterMap, b?: FilterMap): boolean {
const keysA = Object.keys(a ?? {});
const keysB = Object.keys(b ?? {});
diff --git a/frontend/src/lib/components/copy-button.svelte b/frontend/src/lib/components/copy-button.svelte
new file mode 100644
index 000000000..9d3efc81f
--- /dev/null
+++ b/frontend/src/lib/components/copy-button.svelte
@@ -0,0 +1,61 @@
+<script lang="ts">
+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';
+ import type { ArcaneButtonSize, ArcaneButtonTone } from '$lib/components/arcane-button';
+ import { CopyIcon, CheckIcon } from '$lib/icons';
+ import { UseClipboard } from '$lib/hooks/use-clipboard.svelte';
+ import { toast } from 'svelte-sonner';
+ import { m } from '$lib/paraglide/messages';
+ import type { ClassValue } from 'svelte/elements';
+
+ interface Props {
+ /** The text copied to the clipboard when the button is pressed. */
+ text: string;
+ /** Accessible label / tooltip. Defaults to "Copy". */
+ label?: string;
+ /** Show a toast on a successful copy. Defaults to true. */
+ toastOnCopy?: boolean;
+ /** Custom success toast message. Defaults to "Copied to clipboard". */
+ successMessage?: string;
+ size?: ArcaneButtonSize;
+ tone?: ArcaneButtonTone;
+ disabled?: boolean;
+ class?: ClassValue;
+ }
+
+ let {
+ text,
+ label = m.common_copy(),
+ toastOnCopy = true,
+ successMessage,
+ size = 'icon',
+ tone = 'ghost',
+ disabled = false,
+ class: className
+ }: Props = $props();
+
+ const clipboard = new UseClipboard();
+
+ async function handleCopy() {
+ const status = await clipboard.copy(text);
+ if (status === 'success') {
+ if (toastOnCopy) toast.success(successMessage ?? m.common_copied());
+ } else if (typeof window !== 'undefined' && !window.isSecureContext) {
+ toast.error(m.common_copy_https_required());
+ } else {
+ toast.error(m.common_copy_failed());
+ }
+ }
+</script>
+
+<ArcaneButton
+ action="base"
+ {tone}
+ {size}
+ {disabled}
+ onclick={handleCopy}
+ title={label}
+ customLabel={label}
+ showLabel={size !== 'icon'}
+ icon={clipboard.copied ? CheckIcon : CopyIcon}
+ class={className}
+/>
diff --git a/frontend/src/lib/components/stat-card.svelte b/frontend/src/lib/components/stat-card.svelte
index 9c1a465ec..bbed1bf49 100644
--- a/frontend/src/lib/components/stat-card.svelte
+++ b/frontend/src/lib/components/stat-card.svelte
@@ -12,6 +12,10 @@
subtitle?: string;
class?: ClassValue;
variant?: 'default' | 'mini';
+ /** When provided (mini variant), the card becomes a button — e.g. to apply a table filter. */
+ onclick?: () => void;
+ /** Highlights the mini card as the currently-applied filter. */
+ active?: boolean;
}
let {
@@ -22,22 +26,43 @@
bgColor = 'bg-primary/10',
subtitle,
class: className,
- variant = 'default'
+ variant = 'default',
+ onclick,
+ active = false
}: Props = $props();
</script>
+{#snippet miniContent()}
+ <Icon class={cn('size-3.5 opacity-80', iconColor)} />
+ <div class="flex items-baseline gap-1">
+ <span class="text-sm leading-none font-semibold tabular-nums">
+ {value}
+ </span>
+ <span class="text-muted-foreground text-[10px] leading-none font-medium tracking-wider whitespace-nowrap uppercase">
+ {title}
+ </span>
+ </div>
+{/snippet}
+
{#if variant === 'mini'}
- <div class={cn('flex items-center gap-1.5 px-1', className)}>
- <Icon class={cn('size-3.5 opacity-80', iconColor)} />
- <div class="flex items-baseline gap-1">
- <span class="text-sm leading-none font-semibold tabular-nums">
- {value}
- </span>
- <span class="text-muted-foreground text-[10px] leading-none font-medium tracking-wider whitespace-nowrap uppercase">
- {title}
- </span>
+ {#if onclick}
+ <button
+ type="button"
+ {onclick}
+ aria-pressed={active}
+ class={cn(
+ 'hover:bg-foreground/5 focus-visible:ring-primary/40 -mx-0.5 flex cursor-pointer items-center gap-1.5 rounded-md px-1.5 py-0.5 transition-colors focus-visible:ring-2 focus-visible:outline-none',
+ active && 'bg-primary/10 ring-primary/30 ring-1',
+ className
+ )}
+ >
+ {@render miniContent()}
+ </button>
+ {:else}
+ <div class={cn('flex items-center gap-1.5 px-1', className)}>
+ {@render miniContent()}
</div>
- </div>
+ {/if}
{:else}
<div
class={cn(
diff --git a/frontend/src/lib/components/states/empty-state.svelte b/frontend/src/lib/components/states/empty-state.svelte
new file mode 100644
index 000000000..1c7aff7b4
--- /dev/null
+++ b/frontend/src/lib/components/states/empty-state.svelte
@@ -0,0 +1,50 @@
+<script lang="ts">
+ import * as Empty from '$lib/components/ui/empty/index.js';
+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';
+ import type { IconType } from '$lib/icons';
+ import type { Snippet } from 'svelte';
+ import type { ClassValue } from 'svelte/elements';
+
+ interface Props {
+ /** Optional icon rendered in the muted media box. */
+ icon?: IconType;
+ title: string;
+ description?: string;
+ /** Renders a single primary action button when provided. */
+ actionLabel?: string;
+ onAction?: () => void;
+ actionHref?: string;
+ class?: ClassValue;
+ /** Custom action content; overrides the actionLabel button when present. */
+ children?: Snippet;
+ }
+
+ let { icon: Icon, title, description, actionLabel, onAction, actionHref, class: className, children }: Props = $props();
+</script>
+
+<Empty.Root class={className}>
+ <Empty.Header>
+ {#if Icon}
+ <Empty.Media variant="icon">
+ <Icon class="text-muted-foreground size-8" aria-hidden="true" />
+ </Empty.Media>
+ {/if}
+ <Empty.Title>{title}</Empty.Title>
+ {#if description}
+ <Empty.Description>{description}</Empty.Description>
+ {/if}
+ </Empty.Header>
+ {#if children}
+ <Empty.Content>
+ {@render children()}
+ </Empty.Content>
+ {:else if actionLabel}
+ <Empty.Content>
+ {#if actionHref}
+ <ArcaneButton action="base" customLabel={actionLabel} href={actionHref} />
+ {:else}
+ <ArcaneButton action="base" customLabel={actionLabel} onclick={onAction} />
+ {/if}
+ </Empty.Content>
+ {/if}
+</Empty.Root>
diff --git a/frontend/src/lib/components/states/index.ts b/frontend/src/lib/components/states/index.ts
new file mode 100644
index 000000000..03fa3b00f
--- /dev/null
+++ b/frontend/src/lib/components/states/index.ts
@@ -0,0 +1,2 @@
+export { default as EmptyState } from './empty-state.svelte';
+export { default as InlineError } from './inline-error.svelte';
diff --git a/frontend/src/lib/components/states/inline-error.svelte b/frontend/src/lib/components/states/inline-error.svelte
new file mode 100644
index 000000000..1703f926f
--- /dev/null
+++ b/frontend/src/lib/components/states/inline-error.svelte
@@ -0,0 +1,42 @@
+<script lang="ts">
+ import { AlertIcon, RefreshIcon } from '$lib/icons';
+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';
+ import { m } from '$lib/paraglide/messages';
+ import { cn } from '$lib/utils';
+ import type { ClassValue } from 'svelte/elements';
+
+ interface Props {
+ message: string;
+ title?: string;
+ /** When provided, renders a retry button. */
+ onRetry?: () => void;
+ retryLabel?: string;
+ class?: ClassValue;
+ }
+
+ let { message, title, onRetry, retryLabel = m.common_retry(), class: className }: Props = $props();
+</script>
+
+<div
+ role="alert"
+ class={cn('border-destructive/30 bg-destructive/5 flex items-start gap-3 rounded-lg border p-4 text-sm', className)}
+>
+ <AlertIcon class="text-destructive mt-0.5 size-4 shrink-0" aria-hidden="true" />
+ <div class="min-w-0 flex-1 space-y-1">
+ {#if title}
+ <p class="font-medium">{title}</p>
+ {/if}
+ <p class="text-muted-foreground break-words">{message}</p>
+ </div>
+ {#if onRetry}
+ <ArcaneButton
+ action="base"
+ tone="outline"
+ size="sm"
+ icon={RefreshIcon}
+ customLabel={retryLabel}
+ onclick={onRetry}
+ class="shrink-0"
+ />
+ {/if}
+</div>
diff --git a/frontend/src/lib/layouts/resource-page-layout.svelte b/frontend/src/lib/layouts/resource-page-layout.svelte
index 0c41528fb..2b60e1034 100644
--- a/frontend/src/lib/layouts/resource-page-layout.svelte
+++ b/frontend/src/lib/layouts/resource-page-layout.svelte
@@ -10,6 +10,10 @@
iconColor?: string;
bgColor?: string;
class?: string;
+ /** When provided, the mini stat card becomes a clickable filter trigger. */
+ onclick?: () => void;
+ /** Highlights the mini stat card as the currently-applied filter. */
+ active?: boolean;
}
</script>
@@ -76,6 +80,8 @@
icon={card.icon}
iconColor={card.iconColor}
class={card.class}
+ onclick={card.onclick}
+ active={card.active}
/>
{/each}
</div>
diff --git a/frontend/src/lib/utils/bulk-actions.ts b/frontend/src/lib/utils/bulk-actions.ts
new file mode 100644
index 000000000..679bd8bb0
--- /dev/null
+++ b/frontend/src/lib/utils/bulk-actions.ts
@@ -0,0 +1,156 @@
+import { toast } from 'svelte-sonner';
+import { openConfirmDialog } from '$lib/components/confirm-dialog';
+import { tryCatch, type Result } from '$lib/utils/api';
+import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
+
+/**
+ * Shared helpers for table bulk operations (start/stop/remove/prune/…). These
+ * consolidate the iterate-tally-toast-refresh-clear loop that was copy-pasted
+ * across every `*-table.svelte`.
+ */
+
+export interface BulkOperationMessages {
+ /** Toast shown when every item succeeded. Receives the number that succeeded. */
+ success: (count: number) => string;
+ /** Toast shown when some items succeeded and some failed. */
+ partial: (success: number, total: number, failed: number) => string;
+ /** Toast shown when every item failed. */
+ failure: () => string;
+}
+
+export interface BulkOperationResult {
+ total: number;
+ success: number;
+ failed: number;
+}
+
+export interface RunBulkOperationOptions<T> {
+ /** The ids to operate on. A no-op when empty. */
+ ids: string[];
+ /** Runs the operation for a single id. May throw — failures are tallied. */
+ run: (id: string) => Promise<T>;
+ messages: BulkOperationMessages;
+ /** Toggle a loading flag around the whole run. */
+ setLoading?: (loading: boolean) => void;
+ /** Called once after the run (and toast), regardless of outcome — e.g. to refresh data. */
+ onComplete?: (result: BulkOperationResult) => void | Promise<unknown>;
+ /** Clears the table selection after completion. Always called when there were ids. */
+ clearSelection?: () => void;
+ /** Run operations one at a time instead of concurrently. Defaults to concurrent. */
+ sequential?: boolean;
+}
+
+/**
+ * Runs `run` for each id, tallies successes/failures, emits a single summary
+ * toast (success / partial / failure), then refreshes and clears the selection.
+ * The success toast links to the first resulting activity when one is present.
+ */
+export async function runBulkOperation<T>({
+ ids,
+ run,
+ messages,
+ setLoading,
+ onComplete,
+ clearSelection,
+ sequential = false
+}: RunBulkOperationOptions<T>): Promise<BulkOperationResult> {
+ const total = ids?.length ?? 0;
+ const result: BulkOperationResult = { total, success: 0, failed: 0 };
+ if (total === 0) return result;
+
+ let firstActivityId: string | undefined;
+ const tally = (outcome: Result<T>) => {
+ if (outcome.error) {
+ result.failed += 1;
+ } else {
+ result.success += 1;
+ if (!firstActivityId) firstActivityId = extractActivityId(outcome.data);
+ }
+ };
+
+ setLoading?.(true);
+ try {
+ if (sequential) {
+ for (const id of ids) {
+ tally(await tryCatch(run(id)));
+ }
+ } else {
+ const outcomes = await Promise.all(ids.map((id) => tryCatch(run(id))));
+ for (const outcome of outcomes) tally(outcome);
+ }
+ } finally {
+ setLoading?.(false);
+ }
+
+ if (result.failed === 0) {
+ toast.success(messages.success(result.success), activityToastOptions(firstActivityId));
+ } else if (result.success > 0) {
+ toast.warning(messages.partial(result.success, total, result.failed));
+ } else {
+ toast.error(messages.failure());
+ }
+
+ await onComplete?.(result);
+ clearSelection?.();
+
+ return result;
+}
+
+export interface BulkConfirmCheckbox {
+ id: string;
+ label: string;
+ initialState?: boolean;
+}
+
+export interface BulkConfirmAndRunOptions<T> extends Omit<RunBulkOperationOptions<T>, 'run'> {
+ title: string;
+ message: string;
+ confirmLabel: string;
+ destructive?: boolean;
+ /** Optional confirm-dialog checkboxes (e.g. force / remove volumes). */
+ checkboxes?: BulkConfirmCheckbox[];
+ /** Runs the operation for a single id, given the resolved checkbox states. */
+ run: (id: string, checkboxStates: Record<string, boolean>) => Promise<T>;
+}
+
+/**
+ * Opens a confirm dialog (with optional checkboxes) and, on confirm, runs the
+ * bulk operation via {@link runBulkOperation}. A no-op when `ids` is empty.
+ */
+export function bulkConfirmAndRun<T>({
+ ids,
+ title,
+ message,
+ confirmLabel,
+ destructive = false,
+ checkboxes,
+ run,
+ messages,
+ setLoading,
+ onComplete,
+ clearSelection,
+ sequential
+}: BulkConfirmAndRunOptions<T>): void {
+ if (!ids || ids.length === 0) return;
+
+ openConfirmDialog({
+ title,
+ message,
+ checkboxes,
+ confirm: {
+ label: confirmLabel,
+ destructive,
+ action: async (checkboxStates) => {
+ await runBulkOperation({
+ ids,
+ run: (id) => run(id, checkboxStates),
+ messages,
+ setLoading,
+ onComplete,
+ clearSelection,
+ sequential
+ });
+ }
+ }
+ });
+}
diff --git a/frontend/src/routes/(app)/containers/[containerId]/+error.svelte b/frontend/src/routes/(app)/containers/[containerId]/+error.svelte
new file mode 100644
index 000000000..5b4c41d44
--- /dev/null
+++ b/frontend/src/routes/(app)/containers/[containerId]/+error.svelte
@@ -0,0 +1,36 @@
+<script lang="ts">
+ import { page } from '$app/state';
+ import { goto } from '$app/navigation';
+ import * as Empty from '$lib/components/ui/empty/index.js';
+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';
+ import { AlertIcon } from '$lib/icons';
+ import { m } from '$lib/paraglide/messages';
+
+ const status = $derived(page.status ?? 500);
+ const message = $derived(page.error?.message ?? m.error_generic());
+</script>
+
+<div class="flex h-full flex-1 flex-col items-center justify-center p-8">
+ <Empty.Root>
+ <Empty.Header>
+ <Empty.Media variant="icon">
+ <AlertIcon class="text-destructive size-16" aria-hidden="true" />
+ </Empty.Media>
+ <Empty.Title>
+ {status === 404 ? m.error_not_found() : m.error_generic()}
+ </Empty.Title>
+ <Empty.Description>
+ {message}
+ </Empty.Description>
+ </Empty.Header>
+ <Empty.Content>
+ <div class="flex flex-col items-center gap-3">
+ <ArcaneButton
+ action="base"
+ customLabel={m.common_back_to({ resource: m.containers_title() })}
+ onclick={() => goto('/containers')}
+ />
+ </div>
+ </Empty.Content>
+ </Empty.Root>
+</div>
diff --git a/frontend/src/routes/(app)/containers/container-table.actions.ts b/frontend/src/routes/(app)/containers/container-table.actions.ts
index 6c40b304f..f21132ca7 100644
--- a/frontend/src/routes/(app)/containers/container-table.actions.ts
+++ b/frontend/src/routes/(app)/containers/container-table.actions.ts
@@ -5,6 +5,7 @@ import type { ContainerSummaryDto } from '$lib/types/docker';
import { handleApiResultWithCallbacks } from '$lib/utils/api';
import { tryCatch } from '$lib/utils/api';
import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
+import { bulkConfirmAndRun } from '$lib/utils/bulk-actions';
import { toast } from 'svelte-sonner';
import { getContainerDisplayName, type ActionStatus } from './container-table.helpers';
@@ -210,37 +211,24 @@ export function createContainerActions({
});
}
- async function runBulkAction(ids: string[], config: BulkActionConfig) {
- if (!ids || ids.length === 0) return;
-
- openConfirmDialog({
+ function runBulkAction(ids: string[], config: BulkActionConfig) {
+ bulkConfirmAndRun({
+ ids,
title: config.title(ids.length),
message: config.message(ids.length),
- confirm: {
- label: config.label,
- destructive: config.destructive ?? false,
- action: async () => {
- isBulkLoading[config.loadingKey] = true;
-
- const results = await Promise.allSettled(ids.map((id) => config.run(id)));
-
- const successCount = results.filter((result) => result.status === 'fulfilled').length;
- const failureCount = results.length - successCount;
-
- isBulkLoading[config.loadingKey] = false;
-
- if (successCount === ids.length) {
- toast.success(config.success(successCount));
- } else if (successCount > 0) {
- toast.warning(config.partial(successCount, ids.length, failureCount));
- } else {
- toast.error(config.failure());
- }
-
- await reloadContainers();
- setSelectedIds([]);
- }
- }
+ confirmLabel: config.label,
+ destructive: config.destructive ?? false,
+ run: (id) => config.run(id),
+ messages: {
+ success: config.success,
+ partial: config.partial,
+ failure: config.failure
+ },
+ setLoading: (loading) => {
+ isBulkLoading[config.loadingKey] = loading;
+ },
+ onComplete: () => reloadContainers(),
+ clearSelection: () => setSelectedIds([])
});
}
@@ -283,51 +271,29 @@ export function createContainerActions({
});
}
- async function handleBulkRemove(ids: string[]) {
- if (!ids || ids.length === 0) return;
-
- openConfirmDialog({
+ function handleBulkRemove(ids: string[]) {
+ bulkConfirmAndRun({
+ ids,
title: m.containers_bulk_remove_confirm_title({ count: ids.length }),
message: m.containers_bulk_remove_confirm_message({ count: ids.length }),
+ confirmLabel: m.common_remove(),
+ destructive: true,
checkboxes: [
- {
- id: 'force',
- label: m.containers_remove_force_label(),
- initialState: false
- },
- {
- id: 'volumes',
- label: m.containers_remove_volumes_label(),
- initialState: false
- }
+ { id: 'force', label: m.containers_remove_force_label(), initialState: false },
+ { id: 'volumes', label: m.containers_remove_volumes_label(), initialState: false }
],
- confirm: {
- label: m.common_remove(),
- destructive: true,
- action: async (checkboxStates) => {
- const force = !!checkboxStates['force'];
- const volumes = !!checkboxStates['volumes'];
- isBulkLoading.remove = true;
-
- const results = await Promise.allSettled(ids.map((id) => containerService.deleteContainer(id, { force, volumes })));
-
- const successCount = results.filter((result) => result.status === 'fulfilled').length;
- const failureCount = results.length - successCount;
-
- isBulkLoading.remove = false;
-
- if (successCount === ids.length) {
- toast.success(m.containers_bulk_remove_success({ count: successCount }));
- } else if (successCount > 0) {
- toast.warning(m.containers_bulk_remove_partial({ success: successCount, total: ids.length, failed: failureCount }));
- } else {
- toast.error(m.containers_remove_failed());
- }
-
- await reloadContainers();
- setSelectedIds([]);
- }
- }
+ run: (id, checkboxStates) =>
+ containerService.deleteContainer(id, { force: !!checkboxStates['force'], volumes: !!checkboxStates['volumes'] }),
+ messages: {
+ success: (count) => m.containers_bulk_remove_success({ count }),
+ partial: (success, total, failed) => m.containers_bulk_remove_partial({ success, total, failed }),
+ failure: () => m.containers_remove_failed()
+ },
+ setLoading: (loading) => {
+ isBulkLoading.remove = loading;
+ },
+ onComplete: () => reloadContainers(),
+ clearSelection: () => setSelectedIds([])
});
}
diff --git a/frontend/src/routes/(app)/images/[imageId]/+error.svelte b/frontend/src/routes/(app)/images/[imageId]/+error.svelte
new file mode 100644
index 000000000..e952991cc
--- /dev/null
+++ b/frontend/src/routes/(app)/images/[imageId]/+error.svelte
@@ -0,0 +1,36 @@
+<script lang="ts">
+ import { page } from '$app/state';
+ import { goto } from '$app/navigation';
+ import * as Empty from '$lib/components/ui/empty/index.js';
+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';
+ import { AlertIcon } from '$lib/icons';
+ import { m } from '$lib/paraglide/messages';
+
+ const status = $derived(page.status ?? 500);
+ const message = $derived(page.error?.message ?? m.error_generic());
+</script>
+
+<div class="flex h-full flex-1 flex-col items-center justify-center p-8">
+ <Empty.Root>
+ <Empty.Header>
+ <Empty.Media variant="icon">
+ <AlertIcon class="text-destructive size-16" aria-hidden="true" />
+ </Empty.Media>
+ <Empty.Title>
+ {status === 404 ? m.error_not_found() : m.error_generic()}
+ </Empty.Title>
+ <Empty.Description>
+ {message}
+ </Empty.Description>
+ </Empty.Header>
+ <Empty.Content>
+ <div class="flex flex-col items-center gap-3">
+ <ArcaneButton
+ action="base"
+ customLabel={m.common_back_to({ resource: m.images_title() })}
+ onclick={() => goto('/images')}
+ />
+ </div>
+ </Empty.Content>
+ </Empty.Root>
+</div>
diff --git a/frontend/src/routes/(app)/images/image-table.svelte b/frontend/src/routes/(app)/images/image-table.svelte
index 32fe28f8e..0ef76791e 100644
--- a/frontend/src/routes/(app)/images/image-table.svelte
+++ b/frontend/src/routes/(app)/images/image-table.svelte
@@ -28,6 +28,7 @@
import { environmentStore } from '$lib/stores/environment.store.svelte';
import { hasPermission } from '$lib/utils/auth';
import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
+ import { bulkConfirmAndRun } from '$lib/utils/bulk-actions';
import {
DownloadIcon,
@@ -81,57 +82,25 @@
images = await imageService.getImages(options);
}
- async function handleDeleteSelected(ids: string[]) {
- if (!ids || ids.length === 0) return;
-
- openConfirmDialog({
+ function handleDeleteSelected(ids: string[]) {
+ bulkConfirmAndRun({
+ ids,
title: m.images_remove_selected_title({ count: ids.length }),
message: m.images_remove_selected_message({ count: ids.length }),
- checkboxes: [
- {
- id: 'force',
- label: m.images_remove_force_label(),
- initialState: false
- }
- ],
- confirm: {
- label: m.common_remove(),
- destructive: true,
- action: async (checkboxStates) => {
- const force = !!checkboxStates['force'];
- isLoading.removing = true;
- let successCount = 0;
- let failureCount = 0;
-
- for (const id of ids) {
- const result = await tryCatch(imageService.deleteImage(id, { force }));
- handleApiResultWithCallbacks({
- result,
- message: m.images_remove_failed(),
- setLoadingState: () => {},
- onSuccess: () => {
- successCount++;
- }
- });
- if (result.error) failureCount++;
- }
-
- isLoading.removing = false;
-
- if (successCount > 0) {
- const msg =
- successCount === 1 ? m.images_remove_success_one() : m.images_remove_success_many({ count: successCount });
- toast.success(msg);
- await refreshImages();
- }
- if (failureCount > 0) {
- const msg = failureCount === 1 ? m.images_remove_failed_one() : m.images_remove_failed_many({ count: failureCount });
- toast.error(msg);
- }
-
- selectedIds = [];
- }
- }
+ confirmLabel: m.common_remove(),
+ destructive: true,
+ checkboxes: [{ id: 'force', label: m.images_remove_force_label(), initialState: false }],
+ run: (id, checkboxStates) => imageService.deleteImage(id, { force: !!checkboxStates['force'] }),
+ messages: {
+ success: (count) => (count === 1 ? m.images_remove_success_one() : m.images_remove_success_many({ count })),
+ partial: (success, total, failed) => m.common_bulk_remove_partial({ success, total, failed, resource: m.images_title() }),
+ failure: () => (ids.length === 1 ? m.images_remove_failed_one() : m.images_remove_failed_many({ count: ids.length }))
+ },
+ setLoading: (loading) => (isLoading.removing = loading),
+ onComplete: async (result) => {
+ if (result.success > 0) await refreshImages();
+ },
+ clearSelection: () => (selectedIds = [])
});
}
diff --git a/frontend/src/routes/(app)/networks/[networkId]/+error.svelte b/frontend/src/routes/(app)/networks/[networkId]/+error.svelte
new file mode 100644
index 000000000..07b158eff
--- /dev/null
+++ b/frontend/src/routes/(app)/networks/[networkId]/+error.svelte
@@ -0,0 +1,36 @@
+<script lang="ts">
+ import { page } from '$app/state';
+ import { goto } from '$app/navigation';
+ import * as Empty from '$lib/components/ui/empty/index.js';
+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';
+ import { AlertIcon } from '$lib/icons';
+ import { m } from '$lib/paraglide/messages';
+
+ const status = $derived(page.status ?? 500);
+ const message = $derived(page.error?.message ?? m.error_generic());
+</script>
+
+<div class="flex h-full flex-1 flex-col items-center justify-center p-8">
+ <Empty.Root>
+ <Empty.Header>
+ <Empty.Media variant="icon">
+ <AlertIcon class="text-destructive size-16" aria-hidden="true" />
+ </Empty.Media>
+ <Empty.Title>
+ {status === 404 ? m.error_not_found() : m.error_generic()}
+ </Empty.Title>
+ <Empty.Description>
+ {message}
+ </Empty.Description>
+ </Empty.Header>
+ <Empty.Content>
+ <div class="flex flex-col items-center gap-3">
+ <ArcaneButton
+ action="base"
+ customLabel={m.common_back_to({ resource: m.networks_title() })}
+ onclick={() => goto('/networks')}
+ />
+ </div>
+ </Empty.Content>
+ </Empty.Root>
+</div>
diff --git a/frontend/src/routes/(app)/networks/network-table.svelte b/frontend/src/routes/(app)/networks/network-table.svelte
index fe58e506b..277d3e21d 100644
--- a/frontend/src/routes/(app)/networks/network-table.svelte
+++ b/frontend/src/routes/(app)/networks/network-table.svelte
@@ -18,6 +18,7 @@
import { networkService } from '$lib/services/network-service';
import { NetworksIcon, GlobeIcon, InspectIcon, TrashIcon, EllipsisIcon } from '$lib/icons';
import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
+ import { bulkConfirmAndRun } from '$lib/utils/bulk-actions';
type FieldVisibility = Record<string, boolean>;
@@ -81,7 +82,7 @@
});
}
- async function handleDeleteSelectedNetworks(ids: string[]) {
+ function handleDeleteSelectedNetworks(ids: string[]) {
const selectedNetworkList = networks.data.filter((n) => ids.includes(n.id));
const defaultNetworks = selectedNetworkList.filter((n) => n.isDefault);
@@ -91,46 +92,24 @@
return;
}
- openConfirmDialog({
+ bulkConfirmAndRun({
+ ids,
title: m.networks_delete_selected_title({ count: ids.length }),
message: m.networks_delete_selected_message({ count: ids.length }),
- confirm: {
- label: m.common_delete(),
- destructive: true,
- action: async () => {
- isLoading.remove = true;
- let successCount = 0;
- let failureCount = 0;
-
- for (const networkId of ids) {
- const network = networks.data.find((n) => n.id === networkId);
- if (!network) continue;
-
- const result = await tryCatch(networkService.deleteNetwork(networkId));
- if (result.error) {
- failureCount++;
- toast.error(
- m.common_delete_failed({ resource: `${m.resource_network()} "${network.name ?? m.common_unknown()}"` })
- );
- } else {
- successCount++;
- toast.success(
- m.common_delete_success({
- resource: `${m.resource_network()} "${network.name ?? m.common_unknown()}"`
- }),
- activityToastOptions(extractActivityId(result.data))
- );
- }
- }
-
- isLoading.remove = false;
-
- if (successCount > 0) {
- await refreshNetworks();
- }
- selectedIds = [];
- }
- }
+ confirmLabel: m.common_delete(),
+ destructive: true,
+ run: (id) => networkService.deleteNetwork(id),
+ messages: {
+ success: (count) => m.common_bulk_delete_success({ count, resource: m.networks_title() }),
+ partial: (success, total, failed) =>
+ m.common_bulk_delete_partial({ success, total, failed, resource: m.networks_title() }),
+ failure: () => m.common_bulk_delete_failed({ count: ids.length, resource: m.networks_title() })
+ },
+ setLoading: (loading) => (isLoading.remove = loading),
+ onComplete: async (result) => {
+ if (result.success > 0) await refreshNetworks();
+ },
+ clearSelection: () => (selectedIds = [])
});
}
diff --git a/frontend/src/routes/(app)/settings/+page.svelte b/frontend/src/routes/(app)/settings/+page.svelte
index df11fe8f5..d284212fe 100644
--- a/frontend/src/routes/(app)/settings/+page.svelte
+++ b/frontend/src/routes/(app)/settings/+page.svelte
@@ -28,6 +28,7 @@
import * as InputGroup from '$lib/components/ui/input-group/index.js';
import { getSettingsSubpageUrlsInNavOrder } from '$lib/config/navigation-config';
import HeaderCard from '$lib/components/header-card.svelte';
+ import { Spinner } from '$lib/components/ui/spinner/index.js';
let {}: PageProps = $props();
@@ -219,9 +220,7 @@
{#if isSearching}
<div class="py-8 text-center sm:py-12">
- <div
- class="border-primary mx-auto mb-3 size-8 animate-spin rounded-full border-4 border-t-transparent sm:mb-4 sm:size-12"
- ></div>
+ <Spinner class="text-primary mx-auto mb-3 size-8 sm:mb-4 sm:size-12" />
<p class="text-muted-foreground text-sm sm:text-base">{m.settings_searching()}</p>
</div>
{:else if searchResults.length === 0}
diff --git a/frontend/src/routes/(app)/volumes/[volumeName]/+error.svelte b/frontend/src/routes/(app)/volumes/[volumeName]/+error.svelte
new file mode 100644
index 000000000..abd3e52a3
--- /dev/null
+++ b/frontend/src/routes/(app)/volumes/[volumeName]/+error.svelte
@@ -0,0 +1,36 @@
+<script lang="ts">
+ import { page } from '$app/state';
+ import { goto } from '$app/navigation';
+ import * as Empty from '$lib/components/ui/empty/index.js';
+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';
+ import { AlertIcon } from '$lib/icons';
+ import { m } from '$lib/paraglide/messages';
+
+ const status = $derived(page.status ?? 500);
+ const message = $derived(page.error?.message ?? m.error_generic());
+</script>
+
+<div class="flex h-full flex-1 flex-col items-center justify-center p-8">
+ <Empty.Root>
+ <Empty.Header>
+ <Empty.Media variant="icon">
+ <AlertIcon class="text-destructive size-16" aria-hidden="true" />
+ </Empty.Media>
+ <Empty.Title>
+ {status === 404 ? m.error_not_found() : m.error_generic()}
+ </Empty.Title>
+ <Empty.Description>
+ {message}
+ </Empty.Description>
+ </Empty.Header>
+ <Empty.Content>
+ <div class="flex flex-col items-center gap-3">
+ <ArcaneButton
+ action="base"
+ customLabel={m.common_back_to({ resource: m.volumes_title() })}
+ onclick={() => goto('/volumes')}
+ />
+ </div>
+ </Empty.Content>
+ </Empty.Root>
+</div>
diff --git a/frontend/src/routes/(app)/volumes/volume-table.svelte b/frontend/src/routes/(app)/volumes/volume-table.svelte
index e763c41c5..65ee33dd3 100644
--- a/frontend/src/routes/(app)/volumes/volume-table.svelte
+++ b/frontend/src/routes/(app)/volumes/volume-table.svelte
@@ -25,6 +25,7 @@
import { environmentStore } from '$lib/stores/environment.store.svelte';
import { hasPermission } from '$lib/utils/auth';
import { activityToastOptions, extractActivityId } from '$lib/utils/activity-toast';
+ import { bulkConfirmAndRun } from '$lib/utils/bulk-actions';
let {
volumes = $bindable(),
@@ -128,56 +129,28 @@
});
}
- async function handleDeleteSelected(ids: string[]) {
- if (!ids?.length) return;
-
- openConfirmDialog({
- title: m.volumes_remove_selected_title({ count: ids.length }),
- message: m.volumes_remove_selected_message({ count: ids.length }),
- confirm: {
- label: m.common_remove(),
- destructive: true,
- action: async () => {
- isLoading.removing = true;
- let successCount = 0;
- let failureCount = 0;
-
- const idToName = new Map(volumes.data.map((v) => [v.id, v.name] as const));
- const idsToDelete = ids.filter((id) => !isBackupVolumeName(idToName.get(id)));
- if (!idsToDelete.length) {
- isLoading.removing = false;
- selectedIds = [];
- return;
- }
-
- for (const id of idsToDelete) {
- const name = idToName.get(id);
- const safeName = name?.trim() || m.common_unknown();
- const result = await tryCatch(volumeService.deleteVolume(safeName));
- handleApiResultWithCallbacks({
- result,
- message: m.common_remove_failed({ resource: `${m.resource_volume()} "${safeName}"` }),
- setLoadingState: () => {},
- onSuccess: (_data) => {
- successCount += 1;
- }
- });
- if (result.error) failureCount += 1;
- }
-
- isLoading.removing = false;
- if (successCount > 0) {
- const successMsg = m.common_bulk_remove_success({ count: successCount, resource: m.volumes_title() });
- toast.success(successMsg);
- await refreshVolumes();
- }
- if (failureCount > 0) {
- const failureMsg = m.common_bulk_remove_failed({ count: failureCount, resource: m.volumes_title() });
- toast.error(failureMsg);
- }
- selectedIds = [];
- }
- }
+ function handleDeleteSelected(ids: string[]) {
+ const idToName = new Map(volumes.data.map((v) => [v.id, v.name] as const));
+ const idsToDelete = ids.filter((id) => !isBackupVolumeName(idToName.get(id)));
+
+ bulkConfirmAndRun({
+ ids: idsToDelete,
+ title: m.volumes_remove_selected_title({ count: idsToDelete.length }),
+ message: m.volumes_remove_selected_message({ count: idsToDelete.length }),
+ confirmLabel: m.common_remove(),
+ destructive: true,
+ run: (id) => volumeService.deleteVolume(idToName.get(id)?.trim() || m.common_unknown()),
+ messages: {
+ success: (count) => m.common_bulk_remove_success({ count, resource: m.volumes_title() }),
+ partial: (success, total, failed) =>
+ m.common_bulk_remove_partial({ success, total, failed, resource: m.volumes_title() }),
+ failure: () => m.common_bulk_remove_failed({ count: idsToDelete.length, resource: m.volumes_title() })
+ },
+ setLoading: (loading) => (isLoading.removing = loading),
+ onComplete: async (result) => {
+ if (result.success > 0) await refreshVolumes();
+ },
+ clearSelection: () => (selectedIds = [])
});
}