Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: container status sorting incorrect (#242)
Kyle Mendell64faad3479b5
diff --git a/src/lib/utils/string.utils.ts b/src/lib/utils/string.utils.tsindex 082cbbdd9..a8b940c23 100644--- a/src/lib/utils/string.utils.ts+++ b/src/lib/utils/string.utils.ts@@ -35,3 +35,47 @@ export function formatLogLine(line: string): string {}return line;}++export function parseStatusTime(status: string): number {+ // Extract time information from status strings like "Up 2 days" or "Exited (0) 12 hours ago"+ const timeRegex = /(\d+)\s+(second|minute|hour|day|week|month|year)s?\s*(ago)?/i;+ const match = status.match(timeRegex);++ if (!match) {+ // If no time found, treat as 0 (just started)+ return 0;+ }++ const value = parseInt(match[1]);+ const unit = match[2].toLowerCase();+ const isAgo = !!match[3]; // "ago" means it's been stopped for that time++ // Convert everything to hours for comparison+ let hours = 0;+ switch (unit) {+ case 'second':+ hours = value / 3600;+ break;+ case 'minute':+ hours = value / 60;+ break;+ case 'hour':+ hours = value;+ break;+ case 'day':+ hours = value * 24;+ break;+ case 'week':+ hours = value * 24 * 7;+ break;+ case 'month':+ hours = value * 24 * 30;+ break;+ case 'year':+ hours = value * 24 * 365;+ break;+ }++ // For "ago" times (stopped containers), make them negative so they sort after running ones+ return isAgo ? -hours : hours;+}diff --git a/src/routes/+page.svelte b/src/routes/+page.svelteindex 41093601e..3416743a9 100644--- a/src/routes/+page.svelte+++ b/src/routes/+page.svelte@@ -6,7 +6,7 @@import { AlertCircle, Box, HardDrive, Cpu, MemoryStick, ArrowRight, PlayCircle, StopCircle, Trash2, Settings, RefreshCw, Loader2, Monitor } from '@lucide/svelte';import * as Alert from '$lib/components/ui/alert/index.js';import { Progress } from '$lib/components/ui/progress/index.js';- import { capitalizeFirstLetter, truncateString, shortId } from '$lib/utils/string.utils';+ import { capitalizeFirstLetter, truncateString, shortId, parseStatusTime } from '$lib/utils/string.utils';import { formatBytes } from '$lib/utils/bytes.util';import StatusBadge from '$lib/components/badges/status-badge.svelte';import { invalidateAll } from '$app/navigation';@@ -371,12 +371,12 @@<div class="flex flex-col h-full"><div class="flex-1"><UniversalTable- data={dashboardStates.containers.slice(0, 5).map((c) => ({ ...c, displayName: getContainerDisplayName(c) }))}+ data={dashboardStates.containers.slice(0, 5).map((c) => ({ ...c, displayName: getContainerDisplayName(c), statusSortValue: parseStatusTime(c.Status) }))}columns={[{ accessorKey: 'displayName', header: 'Name' },{ accessorKey: 'Image', header: 'Image' },{ accessorKey: 'State', header: 'State' },- { accessorKey: 'Status', header: 'Status' }+ { accessorKey: 'statusSortValue', header: 'Status' }]}features={{filtering: false,diff --git a/src/routes/containers/+page.svelte b/src/routes/containers/+page.svelteindex 7fbf8e403..d014062af 100644--- a/src/routes/containers/+page.svelte+++ b/src/routes/containers/+page.svelte@@ -21,6 +21,7 @@import ArcaneButton from '$lib/components/arcane-button.svelte';import { tablePersistence } from '$lib/stores/table-store';import StatCard from '$lib/components/stat-card.svelte';+ import { parseStatusTime } from '$lib/utils/string.utils';const containerApi = new ContainerAPIService();@@ -172,13 +173,17 @@</Card.Header><Card.Content><UniversalTable- data={containers.map((c) => ({ ...c, displayName: getContainerDisplayName(c) }))}+ data={containers.map((c) => ({+ ...c,+ displayName: getContainerDisplayName(c),+ statusSortValue: parseStatusTime(c.Status)+ }))}columns={[{ accessorKey: 'displayName', header: 'Name' },{ accessorKey: 'Id', header: 'ID' },{ accessorKey: 'Image', header: 'Image' },{ accessorKey: 'State', header: 'State' },- { accessorKey: 'Status', header: 'Status' },+ { accessorKey: 'statusSortValue', header: 'Status' },{ accessorKey: 'actions', header: ' ', enableSorting: false }]}features={{@@ -199,13 +204,14 @@}}bind:selectedIds>- {#snippet rows({ item }: { item: ContainerInfo & { displayName: string } })}+ {#snippet rows({ item }: { item: ContainerInfo & { displayName: string; statusSortValue: number } })}{@const stateVariant = statusVariantMap[item.State.toLowerCase()]}<Table.Cell><a class="font-medium hover:underline" href="/containers/{item.Id}/">{item.displayName}</a></Table.Cell><Table.Cell>{shortId(item.Id)}</Table.Cell><Table.Cell>{item.Image}</Table.Cell><Table.Cell><StatusBadge variant={stateVariant} text={capitalizeFirstLetter(item.State)} /></Table.Cell><Table.Cell>{item.Status}</Table.Cell>+ <!-- Still displays the original status text --><Table.Cell><DropdownMenu.Root><DropdownMenu.Trigger>