Skip to content

Modern Docker Management, Designed for Everyone

fix: ensure we are using consistant data tables

Kyle Mendell2e5ec48bfb4c
diff --git a/src/lib/components/data-table.svelte b/src/lib/components/data-table.svelte
index 5e0b3a68a..6bee3ca25 100644
--- a/src/lib/components/data-table.svelte
+++ b/src/lib/components/data-table.svelte
@@ -14,7 +14,7 @@
type DataTableProps<TData, TValue> = {
columns: ColumnDef<TData, TValue>[];
data: TData[];
- pageSize?: number; // Optional page size prop
+ pageSize?: number;
};
let {
diff --git a/src/lib/services/docker-service.ts b/src/lib/services/docker-service.ts
index cf74cf071..a87ddb174 100644
--- a/src/lib/services/docker-service.ts
+++ b/src/lib/services/docker-service.ts
@@ -201,4 +201,72 @@ export async function listImages(): Promise<ServiceImage[]> {
}
}
+// Define and export the type returned by listNetworks
+export type ServiceNetwork = {
+ id: string;
+ name: string;
+ driver: string;
+ scope: string;
+ subnet: string | null; // Extract the first subnet if available
+ gateway: string | null; // Extract the first gateway if available
+ created: string; // Dockerode returns date as string
+};
+
+/**
+ * Lists Docker networks.
+ */
+export async function listNetworks(): Promise<ServiceNetwork[]> {
+ try {
+ const networks = await defaultDocker.listNetworks();
+ return networks.map(
+ (net): ServiceNetwork => ({
+ id: net.Id,
+ name: net.Name,
+ driver: net.Driver,
+ scope: net.Scope,
+ // Safely access the first IPAM config and its subnet/gateway
+ subnet: net.IPAM?.Config?.[0]?.Subnet ?? null,
+ gateway: net.IPAM?.Config?.[0]?.Gateway ?? null,
+ created: net.Created, // Keep as string or parse if needed
+ })
+ );
+ } catch (error: any) {
+ console.error("Error listing networks:", error);
+ throw new Error("Failed to list Docker networks.");
+ }
+}
+
+// Define and export the type returned by listVolumes
+export type ServiceVolume = {
+ name: string;
+ driver: string;
+ scope: string; // Usually 'local' or 'global'
+ mountpoint: string;
+ labels: { [label: string]: string } | null;
+};
+
+/**
+ * Lists Docker volumes.
+ */
+export async function listVolumes(): Promise<ServiceVolume[]> {
+ try {
+ // The listVolumes response structure is slightly different
+ const volumeResponse = await defaultDocker.listVolumes();
+ const volumes = volumeResponse.Volumes || []; // Access the Volumes array
+
+ return volumes.map(
+ (vol): ServiceVolume => ({
+ name: vol.Name,
+ driver: vol.Driver,
+ scope: vol.Scope,
+ mountpoint: vol.Mountpoint,
+ labels: vol.Labels,
+ })
+ );
+ } catch (error: any) {
+ console.error("Error listing volumes:", error);
+ throw new Error("Failed to list Docker volumes.");
+ }
+}
+
export default defaultDocker;
diff --git a/src/routes/networks/+page.server.ts b/src/routes/networks/+page.server.ts
index e0a932f4a..00f30b8ac 100644
--- a/src/routes/networks/+page.server.ts
+++ b/src/routes/networks/+page.server.ts
@@ -1,27 +1,26 @@
import type { PageServerLoad } from "./$types";
+import { listNetworks } from "$lib/services/docker-service";
+import type { ServiceNetwork } from "$lib/services/docker-service";
-export const load: PageServerLoad = async ({ fetch }) => {
- // Mock data until API is ready
- const networks = [
- {
- name: "bridge",
- driver: "bridge",
- scope: "local",
- subnet: "172.17.0.0/16",
- },
- {
- name: "host",
- driver: "host",
- scope: "local",
- subnet: null,
- },
- {
- name: "web_backend",
- driver: "bridge",
- scope: "local",
- subnet: "172.18.0.0/16",
- },
- ];
+// Define the shape of the data returned by the load function
+type NetworkPageData = {
+ networks: ServiceNetwork[];
+ error?: string;
+};
- return { networks };
+export const load: PageServerLoad = async (): Promise<NetworkPageData> => {
+ try {
+ // Actually call the function to list networks
+ const networks = await listNetworks();
+ return {
+ networks,
+ };
+ } catch (err: any) {
+ console.error("Failed to load networks:", err);
+ // Return an empty array and the error message
+ return {
+ networks: [],
+ error: err.message || "Failed to connect to Docker or list networks.",
+ };
+ }
};
diff --git a/src/routes/networks/+page.svelte b/src/routes/networks/+page.svelte
index 9e21fc4c1..627f999d4 100644
--- a/src/routes/networks/+page.svelte
+++ b/src/routes/networks/+page.svelte
@@ -1,53 +1,46 @@
<script lang="ts">
import * as Card from "$lib/components/ui/card/index.js";
import { Button } from "$lib/components/ui/button/index.js";
- import { Network, Plus, Trash2 } from "@lucide/svelte";
+ import { Plus, AlertCircle } from "@lucide/svelte";
+ import DataTable from "$lib/components/data-table.svelte";
+ import { columns } from "./columns";
+ import type { PageData } from "./$types";
+ import * as Alert from "$lib/components/ui/alert/index.js";
- export let data;
- const { networks } = data;
+ let { data }: { data: PageData } = $props();
+ const { networks, error } = data;
+
+ function createNetwork() {
+ alert("Implement create network functionality");
+ }
</script>
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold">Networks</h1>
- <Button variant="default">
+ <Button variant="default" onclick={createNetwork}>
<Plus class="w-4 h-4 mr-2" />
Create Network
</Button>
</div>
+{#if error}
+ <Alert.Root variant="destructive" class="mb-6">
+ <AlertCircle class="h-4 w-4" />
+ <Alert.Title>Error Loading Networks</Alert.Title>
+ <Alert.Description>{error}</Alert.Description>
+ </Alert.Root>
+{/if}
+
<Card.Root>
<Card.Header>
<Card.Title>Docker Networks</Card.Title>
<Card.Description>Manage container communication</Card.Description>
</Card.Header>
<Card.Content>
- <div class="overflow-x-auto">
- <table class="w-full">
- <thead>
- <tr class="border-b">
- <th class="text-left py-2">Name</th>
- <th class="text-left py-2">Driver</th>
- <th class="text-left py-2">Scope</th>
- <th class="text-left py-2">Subnet</th>
- <th class="text-left py-2">Actions</th>
- </tr>
- </thead>
- <tbody>
- {#each networks as network}
- <tr class="border-b">
- <td class="py-2 font-medium">{network.name}</td>
- <td>{network.driver}</td>
- <td>{network.scope}</td>
- <td class="font-mono text-xs">{network.subnet || "N/A"}</td>
- <td class="py-2">
- <Button variant="destructive" size="sm">
- <Trash2 class="w-4 h-4" />
- </Button>
- </td>
- </tr>
- {/each}
- </tbody>
- </table>
- </div>
+ {#if networks && networks.length > 0}
+ <DataTable data={networks} {columns} />
+ {:else if !error}
+ <p class="text-center text-muted-foreground py-4">No networks found.</p>
+ {/if}
</Card.Content>
</Card.Root>
diff --git a/src/routes/networks/NetworkActions.svelte b/src/routes/networks/NetworkActions.svelte
new file mode 100644
index 000000000..a639e6f15
--- /dev/null
+++ b/src/routes/networks/NetworkActions.svelte
@@ -0,0 +1,26 @@
+<script lang="ts">
+ import { Button } from "$lib/components/ui/button/index.js";
+ import { Trash2 } from "@lucide/svelte";
+
+ interface Props {
+ id: string | undefined;
+ name: string;
+ }
+
+ let { id, name }: Props = $props();
+
+ function deleteNetwork() {
+ // TODO: Implement network deletion logic
+ alert(`Implement deletion for network: ${name} (ID: ${id ?? "N/A"})`);
+ }
+</script>
+
+<Button
+ variant="destructive"
+ size="sm"
+ onclick={deleteNetwork}
+ title="Delete Network"
+>
+ <Trash2 class="w-4 h-4" />
+</Button>
+<!-- Add other actions like inspect if needed -->
diff --git a/src/routes/networks/SubnetCell.svelte b/src/routes/networks/SubnetCell.svelte
new file mode 100644
index 000000000..b9651aefd
--- /dev/null
+++ b/src/routes/networks/SubnetCell.svelte
@@ -0,0 +1,10 @@
+<!-- filepath: /Users/kylemendell/dev/ofkm/arcane/src/routes/networks/SubnetCell.svelte -->
+<script lang="ts">
+ export let subnet: string | null;
+</script>
+
+{#if subnet}
+ <span class="font-mono text-xs">{subnet}</span>
+{:else}
+ <span>N/A</span>
+{/if}
diff --git a/src/routes/networks/columns.ts b/src/routes/networks/columns.ts
new file mode 100644
index 000000000..e40af8c71
--- /dev/null
+++ b/src/routes/networks/columns.ts
@@ -0,0 +1,53 @@
+import type { ColumnDef } from "@tanstack/table-core";
+import { renderComponent } from "$lib/components/ui/data-table/index.js";
+import NetworkActions from "./NetworkActions.svelte";
+import SubnetCell from "./SubnetCell.svelte";
+import type { ServiceNetwork } from "$lib/services/docker-service"; // Import the correct type
+
+// Use the ServiceNetwork type directly
+export type NetworkInfo = ServiceNetwork;
+
+export const columns: ColumnDef<NetworkInfo>[] = [
+ {
+ accessorKey: "name",
+ header: "Name",
+ },
+ {
+ accessorKey: "driver",
+ header: "Driver",
+ },
+ {
+ accessorKey: "scope",
+ header: "Scope",
+ },
+ {
+ accessorKey: "subnet",
+ header: "Subnet",
+ cell: ({ row }) => {
+ return renderComponent(SubnetCell, { subnet: row.original.subnet });
+ },
+ },
+ // Optional: Add Gateway column if needed
+ // {
+ // accessorKey: "gateway",
+ // header: "Gateway",
+ // cell: ({ row }) => row.original.gateway ?? 'N/A'
+ // },
+ // Optional: Add Created column if needed
+ // {
+ // accessorKey: "created",
+ // header: "Created",
+ // cell: ({ row }) => new Date(row.original.created).toLocaleString() // Format date
+ // },
+ {
+ id: "actions",
+ header: "Actions",
+ cell: ({ row }) => {
+ return renderComponent(NetworkActions, {
+ id: row.original.id, // Pass the actual ID
+ name: row.original.name,
+ });
+ },
+ enableSorting: false,
+ },
+];
diff --git a/src/routes/volumes/+page.server.ts b/src/routes/volumes/+page.server.ts
index 38e7332e0..fef398ed0 100644
--- a/src/routes/volumes/+page.server.ts
+++ b/src/routes/volumes/+page.server.ts
@@ -1,24 +1,23 @@
import type { PageServerLoad } from "./$types";
+import { listVolumes } from "$lib/services/docker-service";
+import type { ServiceVolume } from "$lib/services/docker-service";
-export const load: PageServerLoad = async ({ fetch }) => {
- // Mock data until API is ready
- const volumes = [
- {
- name: "postgres_data",
- driver: "local",
- mountpoint: "/var/lib/docker/volumes/postgres_data/_data",
- },
- {
- name: "nginx_config",
- driver: "local",
- mountpoint: "/var/lib/docker/volumes/nginx_config/_data",
- },
- {
- name: "redis_data",
- driver: "local",
- mountpoint: "/var/lib/docker/volumes/redis_data/_data",
- },
- ];
+type VolumePageData = {
+ volumes: ServiceVolume[];
+ error?: string;
+};
- return { volumes };
+export const load: PageServerLoad = async (): Promise<VolumePageData> => {
+ try {
+ const volumes = await listVolumes();
+ return {
+ volumes,
+ };
+ } catch (err: any) {
+ console.error("Failed to load volumes:", err);
+ return {
+ volumes: [],
+ error: err.message || "Failed to connect to Docker or list volumes.",
+ };
+ }
};
diff --git a/src/routes/volumes/+page.svelte b/src/routes/volumes/+page.svelte
index 080f34ccd..0e7d8ad4b 100644
--- a/src/routes/volumes/+page.svelte
+++ b/src/routes/volumes/+page.svelte
@@ -1,51 +1,47 @@
<script lang="ts">
import * as Card from "$lib/components/ui/card/index.js";
import { Button } from "$lib/components/ui/button/index.js";
- import { HardDrive, Plus, Trash2 } from "@lucide/svelte";
+ import { Plus, AlertCircle } from "@lucide/svelte";
+ import DataTable from "$lib/components/data-table.svelte";
+ import { columns } from "./columns";
+ import type { PageData } from "./$types";
+ import * as Alert from "$lib/components/ui/alert/index.js";
- export let data;
- const { volumes } = data;
+ let { data }: { data: PageData } = $props();
+ const { volumes, error } = data;
+
+ function createVolume() {
+ // TODO: Implement create volume functionality
+ alert("Implement create volume functionality");
+ }
</script>
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold">Volumes</h1>
- <Button variant="default">
+ <Button variant="default" onclick={createVolume}>
<Plus class="w-4 h-4 mr-2" />
Create Volume
</Button>
</div>
+{#if error}
+ <Alert.Root variant="destructive" class="mb-6">
+ <AlertCircle class="h-4 w-4" />
+ <Alert.Title>Error Loading Volumes</Alert.Title>
+ <Alert.Description>{error}</Alert.Description>
+ </Alert.Root>
+{/if}
+
<Card.Root>
<Card.Header>
<Card.Title>Docker Volumes</Card.Title>
<Card.Description>Manage persistent data storage</Card.Description>
</Card.Header>
<Card.Content>
- <div class="overflow-x-auto">
- <table class="w-full">
- <thead>
- <tr class="border-b">
- <th class="text-left py-2">Name</th>
- <th class="text-left py-2">Driver</th>
- <th class="text-left py-2">Mount Point</th>
- <th class="text-left py-2">Actions</th>
- </tr>
- </thead>
- <tbody>
- {#each volumes as volume}
- <tr class="border-b">
- <td class="py-2 font-medium">{volume.name}</td>
- <td>{volume.driver}</td>
- <td class="font-mono text-xs">{volume.mountpoint}</td>
- <td class="py-2">
- <Button variant="destructive" size="sm">
- <Trash2 class="w-4 h-4" />
- </Button>
- </td>
- </tr>
- {/each}
- </tbody>
- </table>
- </div>
+ {#if volumes && volumes.length > 0}
+ <DataTable data={volumes} {columns} />
+ {:else if !error}
+ <p class="text-center text-muted-foreground py-4">No volumes found.</p>
+ {/if}
</Card.Content>
</Card.Root>
diff --git a/src/routes/volumes/MountpointCell.svelte b/src/routes/volumes/MountpointCell.svelte
new file mode 100644
index 000000000..e86761cac
--- /dev/null
+++ b/src/routes/volumes/MountpointCell.svelte
@@ -0,0 +1,18 @@
+<script lang="ts">
+ interface Props {
+ mountpoint: string;
+ }
+
+ let { mountpoint }: Props = $props();
+
+ const MAX_LENGTH = 50;
+ let displayValue = $derived(
+ mountpoint.length > MAX_LENGTH
+ ? mountpoint.substring(0, MAX_LENGTH - 3) + "..."
+ : mountpoint
+ );
+</script>
+
+<span class="font-mono text-xs" title={mountpoint}>
+ {displayValue}
+</span>
diff --git a/src/routes/volumes/VolumeActions.svelte b/src/routes/volumes/VolumeActions.svelte
new file mode 100644
index 000000000..36a58cb8e
--- /dev/null
+++ b/src/routes/volumes/VolumeActions.svelte
@@ -0,0 +1,22 @@
+<!-- filepath: /Users/kylemendell/dev/ofkm/arcane/src/routes/volumes/VolumeActions.svelte -->
+<script lang="ts">
+ import { Button } from "$lib/components/ui/button/index.js";
+ import { Trash2 } from "@lucide/svelte";
+
+ export let name: string;
+
+ function deleteVolume() {
+ // TODO: Implement volume deletion logic
+ alert(`Implement deletion for volume: ${name}`);
+ }
+</script>
+
+<Button
+ variant="destructive"
+ size="sm"
+ onclick={deleteVolume}
+ title="Delete Volume"
+>
+ <Trash2 class="w-4 h-4" />
+</Button>
+<!-- Add other actions like inspect if needed -->
diff --git a/src/routes/volumes/columns.ts b/src/routes/volumes/columns.ts
new file mode 100644
index 000000000..37314ff03
--- /dev/null
+++ b/src/routes/volumes/columns.ts
@@ -0,0 +1,43 @@
+// filepath: /Users/kylemendell/dev/ofkm/arcane/src/routes/volumes/columns.ts
+import type { ColumnDef } from "@tanstack/table-core";
+import { renderComponent } from "$lib/components/ui/data-table/index.js";
+import VolumeActions from "./VolumeActions.svelte";
+import MountpointCell from "./MountpointCell.svelte"; // Import the new component
+import type { ServiceVolume } from "$lib/services/docker-service";
+
+export type VolumeInfo = ServiceVolume;
+
+export const columns: ColumnDef<VolumeInfo>[] = [
+ {
+ accessorKey: "name",
+ header: "Name",
+ },
+ {
+ accessorKey: "driver",
+ header: "Driver",
+ },
+ {
+ accessorKey: "scope",
+ header: "Scope",
+ },
+ {
+ accessorKey: "mountpoint",
+ header: "Mountpoint",
+ cell: ({ row }) => {
+ // Use renderComponent with the new MountpointCell
+ return renderComponent(MountpointCell, {
+ mountpoint: row.original.mountpoint,
+ });
+ },
+ },
+ {
+ id: "actions",
+ header: "Actions",
+ cell: ({ row }) => {
+ return renderComponent(VolumeActions, {
+ name: row.original.name,
+ });
+ },
+ enableSorting: false,
+ },
+];