Skip to content

Modern Docker Management, Designed for Everyone

fix: add loading indicators to metric cards, fix some styling on the dashboard

Kyle Mendelld9be7cc5d809
diff --git a/frontend/src/lib/components/meter-metric.svelte b/frontend/src/lib/components/meter-metric.svelte
index a25ef324c..ba0095075 100644
--- a/frontend/src/lib/components/meter-metric.svelte
+++ b/frontend/src/lib/components/meter-metric.svelte
@@ -1,20 +1,17 @@
<script lang="ts">
import Meter from '$lib/components/ui/meter/meter.svelte';
- import type { icons, Icon as IconType } from '@lucide/svelte';
-
- interface MetricDataPoint {
- date: Date;
- value: number;
- }
+ import type { Icon as IconType } from '@lucide/svelte';
+ import { Loader2 } from '@lucide/svelte';
interface Props {
title: string;
description?: string;
- currentValue: number;
+ currentValue?: number;
unit?: string;
formatValue?: (value: number) => string;
maxValue?: number;
icon: typeof IconType;
+ loading?: boolean;
}
let {
@@ -24,10 +21,13 @@
unit = '',
formatValue = (v) => `${v.toFixed(1)}${unit}`,
maxValue = 100,
- icon
+ icon,
+ loading = false
}: Props = $props();
- const percentage = $derived((currentValue / maxValue) * 100);
+ const percentage = $derived(
+ currentValue !== undefined && !loading ? (currentValue / maxValue) * 100 : 0
+ );
const Icon = icon;
</script>
@@ -42,9 +42,13 @@
<div
class="flex h-10 w-10 items-center justify-center rounded-full bg-gradient-to-br from-primary to-primary/80 shadow-lg shadow-primary/25"
>
- <Icon />
+ {#if loading}
+ <Loader2 class="size-5 animate-spin text-white" />
+ {:else}
+ <Icon class="size-5 text-white" />
+ {/if}
</div>
- <div>
+ <div class="flex-1 min-w-0">
<div class="text-sm font-semibold text-gray-900 dark:text-gray-100">{title}</div>
{#if description}
<div class="text-xs text-gray-700/80 dark:text-gray-300/80">{description}</div>
@@ -57,21 +61,35 @@
<div class="bg-white/90 p-4 dark:bg-gray-950/90">
<div class="space-y-3">
<div class="text-center">
- <div class="text-2xl font-bold text-gray-900 dark:text-gray-100">
- {formatValue(currentValue)}
- </div>
+ {#if loading}
+ <div class="h-8 w-16 bg-muted animate-pulse rounded mx-auto"></div>
+ {:else}
+ <div class="text-2xl font-bold text-gray-900 dark:text-gray-100">
+ {currentValue !== undefined ? formatValue(currentValue) : '--'}
+ </div>
+ {/if}
</div>
<div class="flex justify-center">
<div class="w-full max-w-[120px]">
- <Meter value={percentage} class="h-2 bg-gray-200 dark:bg-gray-800" />
+ {#if loading}
+ <div class="h-2 w-full bg-muted animate-pulse rounded"></div>
+ {:else}
+ <Meter value={percentage} class="h-2 bg-gray-200 dark:bg-gray-800" />
+ {/if}
</div>
</div>
<div class="rounded-lg bg-primary/10 p-3 dark:bg-primary/20">
- <div class="text-xs text-center font-medium leading-relaxed text-primary dark:text-primary">
- {percentage.toFixed(1)}% of maximum capacity
- </div>
+ {#if loading}
+ <div class="h-3 w-20 bg-muted animate-pulse rounded mx-auto"></div>
+ {:else}
+ <div
+ class="text-xs text-center font-medium leading-relaxed text-primary dark:text-primary"
+ >
+ {percentage.toFixed(1)}% of resources being used
+ </div>
+ {/if}
</div>
</div>
</div>
diff --git a/frontend/src/routes/dashboard/+page.svelte b/frontend/src/routes/dashboard/+page.svelte
index 044d3b920..04d885d22 100644
--- a/frontend/src/routes/dashboard/+page.svelte
+++ b/frontend/src/routes/dashboard/+page.svelte
@@ -221,6 +221,11 @@
if (isLoading.refreshing) return;
isLoading.refreshing = true;
+ // Set all loading states to true at start
+ isLoading.loadingDockerInfo = true;
+ isLoading.loadingContainers = true;
+ isLoading.loadingImages = true;
+
const [dockerInfoResult, containersResult, imagesResult, settingsResult] =
await Promise.allSettled([
tryCatch(systemAPI.getDockerInfo()),
@@ -243,9 +248,11 @@
tryCatch(settingsAPI.getSettings())
]);
+ // Handle results and clear individual loading states
if (dockerInfoResult.status === 'fulfilled' && !dockerInfoResult.value.error) {
dashboardStates.dockerInfo = dockerInfoResult.value.data;
}
+ isLoading.loadingDockerInfo = false;
if (containersResult.status === 'fulfilled' && !containersResult.value.error) {
const containerData = containersResult.value.data;
@@ -253,11 +260,13 @@
? containerData
: containerData?.data || [];
}
+ isLoading.loadingContainers = false;
if (imagesResult.status === 'fulfilled' && !imagesResult.value.error) {
const imageData = imagesResult.value.data;
dashboardStates.images = Array.isArray(imageData) ? imageData : imageData?.data || [];
}
+ isLoading.loadingImages = false;
if (settingsResult.status === 'fulfilled' && !settingsResult.value.error) {
dashboardStates.settings = settingsResult.value.data;
@@ -493,61 +502,81 @@
title="Running Containers"
icon={Container}
description="Active containers"
- currentValue={runningContainers}
+ currentValue={isLoading.loadingContainers ? undefined : runningContainers}
formatValue={(v) => v.toString()}
maxValue={dashboardStates.containers?.length || 10}
unit="containers"
+ loading={isLoading.loadingContainers}
/>
- {#if currentStats?.cpuUsage !== undefined}
- <MeterMetric
- title="CPU Usage"
- icon={Cpu}
- description="Processor utilization"
- currentValue={currentStats.cpuUsage}
- unit="%"
- maxValue={100}
- />
- {/if}
-
- {#if currentStats?.memoryUsage !== undefined && currentStats?.memoryTotal !== undefined}
- <MeterMetric
- title="Memory Usage"
- icon={MemoryStick}
- description="RAM utilization"
- currentValue={(currentStats.memoryUsage / currentStats.memoryTotal) * 100}
- unit="%"
- formatValue={(v) => `${v.toFixed(1)}`}
- maxValue={100}
- />
- {/if}
-
- {#if currentStats?.diskUsage !== undefined && currentStats?.diskTotal !== undefined}
- <MeterMetric
- icon={HardDrive}
- title="Disk Usage"
- description="Storage utilization"
- currentValue={(currentStats.diskUsage / currentStats.diskTotal) * 100}
- unit="%"
- formatValue={(v) => `${v.toFixed(1)}`}
- maxValue={100}
- />
- {/if}
+ <MeterMetric
+ title="CPU Usage"
+ icon={Cpu}
+ description="Processor utilization"
+ currentValue={isLoading.loadingStats || !hasInitialStatsLoaded
+ ? undefined
+ : currentStats?.cpuUsage}
+ unit="%"
+ maxValue={100}
+ loading={isLoading.loadingStats || !hasInitialStatsLoaded}
+ />
+
+ <MeterMetric
+ title="Memory Usage"
+ icon={MemoryStick}
+ description="RAM utilization"
+ currentValue={isLoading.loadingStats || !hasInitialStatsLoaded
+ ? undefined
+ : currentStats?.memoryUsage !== undefined && currentStats?.memoryTotal !== undefined
+ ? (currentStats.memoryUsage / currentStats.memoryTotal) * 100
+ : undefined}
+ unit="%"
+ formatValue={(v) => `${v.toFixed(1)}`}
+ maxValue={100}
+ loading={isLoading.loadingStats || !hasInitialStatsLoaded}
+ />
+
+ <MeterMetric
+ icon={HardDrive}
+ title="Disk Usage"
+ description="Storage utilization"
+ currentValue={isLoading.loadingStats || !hasInitialStatsLoaded
+ ? undefined
+ : currentStats?.diskUsage !== undefined && currentStats?.diskTotal !== undefined
+ ? (currentStats.diskUsage / currentStats.diskTotal) * 100
+ : undefined}
+ unit="%"
+ formatValue={(v) => `${v.toFixed(1)}`}
+ maxValue={100}
+ loading={isLoading.loadingStats || !hasInitialStatsLoaded}
+ />
</div>
+ <!-- Always show these cards but with loading states -->
<div class="mt-6 grid grid-cols-1 gap-4 md:grid-cols-3">
<Card.Root>
<Card.Content class="p-4">
<div class="flex items-center gap-3">
<div class="rounded-lg bg-blue-500/10 p-2">
- <DockerIcon class="size-5 text-blue-500" />
+ {#if isLoading.loadingDockerInfo}
+ <Loader2 class="size-5 text-blue-500 animate-spin" />
+ {:else}
+ <DockerIcon class="size-5 text-blue-500" />
+ {/if}
</div>
- <div>
- <p class="text-sm font-medium">Docker Engine</p>
- <p class="text-xs text-muted-foreground">
- {dashboardStates.dockerInfo?.version || 'Unknown'} •
- {dashboardStates.dockerInfo?.os || 'Unknown'}
- </p>
+ <div class="flex-1 min-w-0">
+ {#if isLoading.loadingDockerInfo}
+ <div class="space-y-2">
+ <div class="h-4 w-24 bg-muted animate-pulse rounded"></div>
+ <div class="h-3 w-32 bg-muted animate-pulse rounded"></div>
+ </div>
+ {:else}
+ <p class="text-sm font-medium">Docker Engine</p>
+ <p class="text-xs text-muted-foreground">
+ {dashboardStates.dockerInfo?.version || 'Unknown'} •
+ {dashboardStates.dockerInfo?.os || 'Unknown'}
+ </p>
+ {/if}
</div>
</div>
</Card.Content>
@@ -557,14 +586,25 @@
<Card.Content class="p-4">
<div class="flex items-center gap-3">
<div class="rounded-lg bg-green-500/10 p-2">
- <Box class="size-5 text-green-500" />
+ {#if isLoading.loadingContainers}
+ <Loader2 class="size-5 text-green-500 animate-spin" />
+ {:else}
+ <Box class="size-5 text-green-500" />
+ {/if}
</div>
- <div>
- <p class="text-sm font-medium">Total Containers</p>
- <p class="text-xs text-muted-foreground">
- {dashboardStates.containers?.length || 0} total •
- {stoppedContainers} stopped
- </p>
+ <div class="flex-1 min-w-0">
+ {#if isLoading.loadingContainers}
+ <div class="space-y-2">
+ <div class="h-4 w-28 bg-muted animate-pulse rounded"></div>
+ <div class="h-3 w-20 bg-muted animate-pulse rounded"></div>
+ </div>
+ {:else}
+ <p class="text-sm font-medium">Total Containers</p>
+ <p class="text-xs text-muted-foreground">
+ {dashboardStates.containers?.length || 0} total •
+ {stoppedContainers} stopped
+ </p>
+ {/if}
</div>
</div>
</Card.Content>
@@ -574,14 +614,25 @@
<Card.Content class="p-4">
<div class="flex items-center gap-3">
<div class="rounded-lg bg-purple-500/10 p-2">
- <HardDrive class="size-5 text-purple-500" />
+ {#if isLoading.loadingImages}
+ <Loader2 class="size-5 text-purple-500 animate-spin" />
+ {:else}
+ <HardDrive class="size-5 text-purple-500" />
+ {/if}
</div>
- <div>
- <p class="text-sm font-medium">Docker Images</p>
- <p class="text-xs text-muted-foreground">
- {dashboardStates.dockerInfo?.images || 0} images •
- {formatBytes(totalImageSize)}
- </p>
+ <div class="flex-1 min-w-0">
+ {#if isLoading.loadingImages}
+ <div class="space-y-2">
+ <div class="h-4 w-24 bg-muted animate-pulse rounded"></div>
+ <div class="h-3 w-28 bg-muted animate-pulse rounded"></div>
+ </div>
+ {:else}
+ <p class="text-sm font-medium">Docker Images</p>
+ <p class="text-xs text-muted-foreground">
+ {dashboardStates.dockerInfo?.images || 0} images •
+ {formatBytes(totalImageSize)}
+ </p>
+ {/if}
</div>
</div>
</Card.Content>
diff --git a/frontend/src/routes/dashboard/dash-container-table.svelte b/frontend/src/routes/dashboard/dash-container-table.svelte
index f21c7dd82..b0211dfd7 100644
--- a/frontend/src/routes/dashboard/dash-container-table.svelte
+++ b/frontend/src/routes/dashboard/dash-container-table.svelte
@@ -86,7 +86,7 @@
noResultsMessage="No containers found"
>
{#snippet rows({ item })}
- {@const stateVariant = statusVariantMap[item.State?.toLowerCase()] || 'secondary'}
+ {@const stateVariant = statusVariantMap[item.State?.toLowerCase()] || 'red'}
<Table.Cell>
<a class="font-medium hover:underline" href="/containers/{item.Id}/">
{getContainerDisplayName(item)}