Skip to content

Modern Docker Management, Designed for Everyone

chore: improve container details page

Kyle Mendelld7d5d510c9d5
diff --git a/src/lib/components/docker/StatusBadge.svelte b/src/lib/components/docker/StatusBadge.svelte
new file mode 100644
index 000000000..41250cd43
--- /dev/null
+++ b/src/lib/components/docker/StatusBadge.svelte
@@ -0,0 +1,39 @@
+<script lang="ts">
+ import { Badge } from "$lib/components/ui/badge/index.js"; // Assuming you use shadcn-svelte Badge
+
+ type ContainerState =
+ | "created"
+ | "running"
+ | "paused"
+ | "restarting"
+ | "removing"
+ | "exited"
+ | "dead"
+ | string; // Allow other potential states
+
+ let { state }: { state: ContainerState } = $props();
+
+ // Determine badge variant and text based on state
+ let variant: "default" | "secondary" | "destructive" | "outline" =
+ $derived.by(() => {
+ switch (state) {
+ case "running":
+ return "default"; // Typically green/primary in shadcn
+ case "exited":
+ case "dead":
+ return "destructive"; // Red
+ case "paused":
+ case "restarting":
+ case "created":
+ return "secondary"; // Gray/Yellowish
+ default:
+ return "outline"; // Default outline for unknown states
+ }
+ });
+
+ let text = $derived(state.charAt(0).toUpperCase() + state.slice(1)); // Capitalize state
+</script>
+
+<Badge {variant} class="capitalize">
+ {text}
+</Badge>
diff --git a/src/lib/components/ui/badge/badge.svelte b/src/lib/components/ui/badge/badge.svelte
new file mode 100644
index 000000000..da261046f
--- /dev/null
+++ b/src/lib/components/ui/badge/badge.svelte
@@ -0,0 +1,50 @@
+<script lang="ts" module>
+ import { type VariantProps, tv } from "tailwind-variants";
+
+ export const badgeVariants = tv({
+ base: "focus:ring-ring inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2",
+ variants: {
+ variant: {
+ default:
+ "bg-primary text-primary-foreground hover:bg-primary/80 border-transparent",
+ secondary:
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80 border-transparent",
+ destructive:
+ "bg-destructive text-destructive-foreground hover:bg-destructive/80 border-transparent",
+ outline: "text-foreground",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ },
+ });
+
+ export type BadgeVariant = VariantProps<typeof badgeVariants>["variant"];
+</script>
+
+<script lang="ts">
+ import type { WithElementRef } from "bits-ui";
+ import type { HTMLAnchorAttributes } from "svelte/elements";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ href,
+ class: className,
+ variant = "default",
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAnchorAttributes> & {
+ variant?: BadgeVariant;
+ } = $props();
+</script>
+
+<svelte:element
+ this={href ? "a" : "span"}
+ bind:this={ref}
+ {href}
+ class={cn(badgeVariants({ variant }), className)}
+ {...restProps}
+>
+ {@render children?.()}
+</svelte:element>
diff --git a/src/lib/components/ui/badge/index.ts b/src/lib/components/ui/badge/index.ts
new file mode 100644
index 000000000..64e0aa9b0
--- /dev/null
+++ b/src/lib/components/ui/badge/index.ts
@@ -0,0 +1,2 @@
+export { default as Badge } from "./badge.svelte";
+export { badgeVariants, type BadgeVariant } from "./badge.svelte";
diff --git a/src/lib/components/ui/breadcrumb/breadcrumb-ellipsis.svelte b/src/lib/components/ui/breadcrumb/breadcrumb-ellipsis.svelte
new file mode 100644
index 000000000..1f649dccd
--- /dev/null
+++ b/src/lib/components/ui/breadcrumb/breadcrumb-ellipsis.svelte
@@ -0,0 +1,23 @@
+<script lang="ts">
+ import Ellipsis from "@lucide/svelte/icons/ellipsis";
+ import type { WithElementRef, WithoutChildren } from "bits-ui";
+ import type { HTMLAttributes } from "svelte/elements";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ ...restProps
+ }: WithoutChildren<WithElementRef<HTMLAttributes<HTMLSpanElement>>> = $props();
+</script>
+
+<span
+ bind:this={ref}
+ role="presentation"
+ aria-hidden="true"
+ class={cn("flex size-9 items-center justify-center", className)}
+ {...restProps}
+>
+ <Ellipsis class="size-4" />
+ <span class="sr-only">More</span>
+</span>
diff --git a/src/lib/components/ui/breadcrumb/breadcrumb-item.svelte b/src/lib/components/ui/breadcrumb/breadcrumb-item.svelte
new file mode 100644
index 000000000..4e2a3ed86
--- /dev/null
+++ b/src/lib/components/ui/breadcrumb/breadcrumb-item.svelte
@@ -0,0 +1,16 @@
+<script lang="ts">
+ import type { WithElementRef } from "bits-ui";
+ import type { HTMLLiAttributes } from "svelte/elements";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLLiAttributes> = $props();
+</script>
+
+<li bind:this={ref} class={cn("inline-flex items-center gap-1.5", className)} {...restProps}>
+ {@render children?.()}
+</li>
diff --git a/src/lib/components/ui/breadcrumb/breadcrumb-link.svelte b/src/lib/components/ui/breadcrumb/breadcrumb-link.svelte
new file mode 100644
index 000000000..c6b10194b
--- /dev/null
+++ b/src/lib/components/ui/breadcrumb/breadcrumb-link.svelte
@@ -0,0 +1,31 @@
+<script lang="ts">
+ import type { HTMLAnchorAttributes } from "svelte/elements";
+ import type { Snippet } from "svelte";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ href = undefined,
+ child,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAnchorAttributes> & {
+ child?: Snippet<[{ props: HTMLAnchorAttributes }]>;
+ } = $props();
+
+ const attrs = $derived({
+ class: cn("hover:text-foreground transition-colors", className),
+ href,
+ ...restProps,
+ });
+</script>
+
+{#if child}
+ {@render child({ props: attrs })}
+{:else}
+ <a bind:this={ref} {...attrs}>
+ {@render children?.()}
+ </a>
+{/if}
diff --git a/src/lib/components/ui/breadcrumb/breadcrumb-list.svelte b/src/lib/components/ui/breadcrumb/breadcrumb-list.svelte
new file mode 100644
index 000000000..77c4e327f
--- /dev/null
+++ b/src/lib/components/ui/breadcrumb/breadcrumb-list.svelte
@@ -0,0 +1,23 @@
+<script lang="ts">
+ import type { WithElementRef } from "bits-ui";
+ import type { HTMLOlAttributes } from "svelte/elements";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLOlAttributes> = $props();
+</script>
+
+<ol
+ bind:this={ref}
+ class={cn(
+ "text-muted-foreground flex flex-wrap items-center gap-1.5 break-words text-sm sm:gap-2.5",
+ className
+ )}
+ {...restProps}
+>
+ {@render children?.()}
+</ol>
diff --git a/src/lib/components/ui/breadcrumb/breadcrumb-page.svelte b/src/lib/components/ui/breadcrumb/breadcrumb-page.svelte
new file mode 100644
index 000000000..1db5a0573
--- /dev/null
+++ b/src/lib/components/ui/breadcrumb/breadcrumb-page.svelte
@@ -0,0 +1,23 @@
+<script lang="ts">
+ import type { WithElementRef } from "bits-ui";
+ import type { HTMLAttributes } from "svelte/elements";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLSpanElement>> = $props();
+</script>
+
+<span
+ bind:this={ref}
+ role="link"
+ aria-disabled="true"
+ aria-current="page"
+ class={cn("text-foreground font-normal", className)}
+ {...restProps}
+>
+ {@render children?.()}
+</span>
diff --git a/src/lib/components/ui/breadcrumb/breadcrumb-separator.svelte b/src/lib/components/ui/breadcrumb/breadcrumb-separator.svelte
new file mode 100644
index 000000000..afd6f6010
--- /dev/null
+++ b/src/lib/components/ui/breadcrumb/breadcrumb-separator.svelte
@@ -0,0 +1,27 @@
+<script lang="ts">
+ import ChevronRight from "@lucide/svelte/icons/chevron-right";
+ import type { WithElementRef } from "bits-ui";
+ import type { HTMLLiAttributes } from "svelte/elements";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLLiAttributes> = $props();
+</script>
+
+<li
+ role="presentation"
+ aria-hidden="true"
+ class={cn("[&>svg]:size-3.5", className)}
+ bind:this={ref}
+ {...restProps}
+>
+ {#if children}
+ {@render children?.()}
+ {:else}
+ <ChevronRight />
+ {/if}
+</li>
diff --git a/src/lib/components/ui/breadcrumb/breadcrumb.svelte b/src/lib/components/ui/breadcrumb/breadcrumb.svelte
new file mode 100644
index 000000000..70be14df4
--- /dev/null
+++ b/src/lib/components/ui/breadcrumb/breadcrumb.svelte
@@ -0,0 +1,15 @@
+<script lang="ts">
+ import type { WithElementRef } from "bits-ui";
+ import type { HTMLAttributes } from "svelte/elements";
+
+ let {
+ ref = $bindable(),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLElement>> = $props();
+</script>
+
+<nav bind:this={ref} class={className} aria-label="breadcrumb" {...restProps}>
+ {@render children?.()}
+</nav>
diff --git a/src/lib/components/ui/breadcrumb/index.ts b/src/lib/components/ui/breadcrumb/index.ts
new file mode 100644
index 000000000..dc914ec34
--- /dev/null
+++ b/src/lib/components/ui/breadcrumb/index.ts
@@ -0,0 +1,25 @@
+import Root from "./breadcrumb.svelte";
+import Ellipsis from "./breadcrumb-ellipsis.svelte";
+import Item from "./breadcrumb-item.svelte";
+import Separator from "./breadcrumb-separator.svelte";
+import Link from "./breadcrumb-link.svelte";
+import List from "./breadcrumb-list.svelte";
+import Page from "./breadcrumb-page.svelte";
+
+export {
+ Root,
+ Ellipsis,
+ Item,
+ Separator,
+ Link,
+ List,
+ Page,
+ //
+ Root as Breadcrumb,
+ Ellipsis as BreadcrumbEllipsis,
+ Item as BreadcrumbItem,
+ Separator as BreadcrumbSeparator,
+ Link as BreadcrumbLink,
+ List as BreadcrumbList,
+ Page as BreadcrumbPage,
+};
diff --git a/src/routes/containers/IdCell.svelte b/src/routes/containers/IdCell.svelte
new file mode 100644
index 000000000..9ea4ebb64
--- /dev/null
+++ b/src/routes/containers/IdCell.svelte
@@ -0,0 +1,6 @@
+<script lang="ts">
+ let { id }: { id: string } = $props();
+ let shortId = $derived(id.substring(0, 12));
+</script>
+
+<span class="font-mono text-xs">{shortId}</span>
diff --git a/src/routes/containers/[id]/+page.server.ts b/src/routes/containers/[id]/+page.server.ts
new file mode 100644
index 000000000..d7b97acb7
--- /dev/null
+++ b/src/routes/containers/[id]/+page.server.ts
@@ -0,0 +1,27 @@
+import type { PageServerLoad } from "./$types";
+import { getContainer } from "$lib/services/docker-service";
+import { error } from "@sveltejs/kit";
+
+export const load: PageServerLoad = async ({ params }) => {
+ const containerId = params.id;
+
+ try {
+ const container = await getContainer(containerId);
+
+ if (!container) {
+ error(404, {
+ message: `Container with ID "${containerId}" not found.`,
+ });
+ }
+
+ return {
+ container,
+ };
+ } catch (err: any) {
+ console.error(`Failed to load container ${containerId}:`, err);
+ error(500, {
+ message:
+ err.message || `Failed to load container details for "${containerId}".`,
+ });
+ }
+};