Skip to content

Modern Docker Management, Designed for Everyone

feat: filter and sorting on all tables (#35)

Kyle Mendellf623d5bd6498
diff --git a/src/app.css b/src/app.css
index 7a52a4224..818dbed5b 100644
--- a/src/app.css
+++ b/src/app.css
@@ -73,3 +73,56 @@
@apply bg-background text-foreground;
}
}
+
+/* Dashboard tables styling */
+.dashboard-table-wrapper :global(.space-y-4) {
+ margin-top: 0 !important;
+ margin-bottom: 0 !important;
+}
+
+.dashboard-table-wrapper :global(.rounded-md.border) {
+ border: none !important;
+ border-radius: 0 !important;
+ overflow: hidden;
+}
+
+.dashboard-table-wrapper :global(table) {
+ margin: 0;
+}
+
+.dashboard-table-wrapper :global(th) {
+ background-color: transparent !important;
+ font-size: 0.75rem !important;
+ font-weight: 500 !important;
+ color: var(--muted-foreground) !important;
+ padding-left: 1.5rem !important;
+ padding-right: 1.5rem !important;
+ height: 2.5rem !important;
+ text-transform: uppercase !important;
+ letter-spacing: 0.04em !important;
+}
+
+.dashboard-table-wrapper :global(td) {
+ padding-left: 1.5rem !important;
+ padding-right: 1.5rem !important;
+ font-size: 0.875rem !important;
+}
+
+.dashboard-table-wrapper :global(tr:last-child td) {
+ border-bottom: none !important;
+}
+
+/* Hide the search/filter area */
+.dashboard-table-wrapper > :global(div) > :global(div:first-child) {
+ display: none !important;
+}
+
+/* Remove vertical spacing between elements */
+.dashboard-table-wrapper > :global(div.space-y-4) > :global(div) {
+ margin-top: 0 !important;
+}
+
+/* Hide pagination when not needed */
+.dashboard-table-wrapper > :global(div.space-y-4) > :global(div:last-child) {
+ display: none !important;
+}
diff --git a/src/lib/components/data-table.svelte b/src/lib/components/data-table.svelte
deleted file mode 100644
index 6bee3ca25..000000000
--- a/src/lib/components/data-table.svelte
+++ /dev/null
@@ -1,140 +0,0 @@
-<script lang="ts" generics="TData, TValue">
- import {
- type ColumnDef,
- getCoreRowModel,
- getPaginationRowModel, // Import pagination row model
- } from "@tanstack/table-core";
- import {
- createSvelteTable,
- FlexRender,
- } from "$lib/components/ui/data-table/index.js";
- import * as Table from "$lib/components/ui/table/index.js";
- import * as Pagination from "$lib/components/ui/pagination/index.js"; // Import Pagination components
-
- type DataTableProps<TData, TValue> = {
- columns: ColumnDef<TData, TValue>[];
- data: TData[];
- pageSize?: number;
- };
-
- let {
- data,
- columns,
- pageSize = 10,
- }: DataTableProps<TData, TValue> = $props();
-
- // Pagination state
- let pageIndex = $state(0);
- let currentPage = $state(1); // Use 1-based index for Pagination component
-
- // Sync state between table (0-based) and pagination component (1-based)
- $effect(() => {
- // When pagination component page changes, update table state
- pageIndex = currentPage - 1;
- });
-
- $effect(() => {
- // When table page index changes (e.g., due to filtering reducing pages), update pagination component
- const tablePageIndex = table.getState().pagination.pageIndex;
- if (tablePageIndex !== pageIndex) {
- currentPage = tablePageIndex + 1;
- }
- });
-
- const table = createSvelteTable({
- get data() {
- return data;
- },
- columns,
- getCoreRowModel: getCoreRowModel(),
- getPaginationRowModel: getPaginationRowModel(), // Enable pagination
- state: {
- // Manage pagination state within the table instance
- get pagination() {
- return {
- pageIndex,
- pageSize,
- };
- },
- },
- });
-
- const pageCount = $derived(table.getPageCount());
- const rowCount = $derived(table.getRowCount());
-</script>
-
-<div class="space-y-4">
- <div class="rounded-md border">
- <Table.Root>
- <Table.Header>
- {#each table.getHeaderGroups() as headerGroup (headerGroup.id)}
- <Table.Row>
- {#each headerGroup.headers as header (header.id)}
- <Table.Head>
- {#if !header.isPlaceholder}
- <FlexRender
- content={header.column.columnDef.header}
- context={header.getContext()}
- />
- {/if}
- </Table.Head>
- {/each}
- </Table.Row>
- {/each}
- </Table.Header>
- <Table.Body>
- {#each table.getRowModel().rows as row (row.id)}
- <Table.Row data-state={row.getIsSelected() && "selected"}>
- {#each row.getVisibleCells() as cell (cell.id)}
- <Table.Cell>
- <FlexRender
- content={cell.column.columnDef.cell}
- context={cell.getContext()}
- />
- </Table.Cell>
- {/each}
- </Table.Row>
- {:else}
- <Table.Row>
- <Table.Cell colspan={columns.length} class="h-24 text-center">
- No results.
- </Table.Cell>
- </Table.Row>
- {/each}
- </Table.Body>
- </Table.Root>
- </div>
-
- <!-- Add Pagination Component -->
- {#if pageCount > 1}
- <Pagination.Root
- count={rowCount}
- perPage={pageSize}
- bind:page={currentPage}
- >
- {#snippet children({ pages, currentPage })}
- <Pagination.Content>
- <Pagination.Item>
- <Pagination.PrevButton />
- </Pagination.Item>
- {#each pages as page (page.key)}
- {#if page.type === "ellipsis"}
- <Pagination.Item>
- <Pagination.Ellipsis />
- </Pagination.Item>
- {:else}
- <Pagination.Item>
- <Pagination.Link {page} isActive={currentPage === page.value}>
- {page.value}
- </Pagination.Link>
- </Pagination.Item>
- {/if}
- {/each}
- <Pagination.Item>
- <Pagination.NextButton />
- </Pagination.Item>
- </Pagination.Content>
- {/snippet}
- </Pagination.Root>
- {/if}
-</div>
diff --git a/src/lib/components/ui/pagination/pagination-link.svelte b/src/lib/components/ui/pagination/pagination-link.svelte
index 4a41b4786..4d7d04a7e 100644
--- a/src/lib/components/ui/pagination/pagination-link.svelte
+++ b/src/lib/components/ui/pagination/pagination-link.svelte
@@ -1,36 +1,39 @@
<script lang="ts">
- import { Pagination as PaginationPrimitive } from "bits-ui";
- import { cn } from "$lib/utils.js";
- import { type Props, buttonVariants } from "$lib/components/ui/button/index.js";
+ import { Pagination as PaginationPrimitive } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+ import {
+ type Props,
+ buttonVariants,
+ } from "$lib/components/ui/button/index.js";
- let {
- ref = $bindable(null),
- class: className,
- size = "icon",
- isActive = false,
- page,
- children,
- ...restProps
- }: PaginationPrimitive.PageProps &
- Props & {
- isActive: boolean;
- } = $props();
+ let {
+ ref = $bindable(null),
+ class: className,
+ size = "sm",
+ isActive = false,
+ page,
+ children,
+ ...restProps
+ }: PaginationPrimitive.PageProps &
+ Props & {
+ isActive: boolean;
+ } = $props();
</script>
{#snippet Fallback()}
- {page.value}
+ {page.value}
{/snippet}
<PaginationPrimitive.Page
- bind:ref
- {page}
- class={cn(
- buttonVariants({
- variant: isActive ? "outline" : "ghost",
- size,
- }),
- className
- )}
- children={children || Fallback}
- {...restProps}
+ bind:ref
+ {page}
+ class={cn(
+ buttonVariants({
+ variant: isActive ? "outline" : "ghost",
+ size,
+ }),
+ className
+ )}
+ children={children || Fallback}
+ {...restProps}
/>
diff --git a/src/lib/components/ui/pagination/pagination-next-button.svelte b/src/lib/components/ui/pagination/pagination-next-button.svelte
index 84eee90a0..f1d2cb863 100644
--- a/src/lib/components/ui/pagination/pagination-next-button.svelte
+++ b/src/lib/components/ui/pagination/pagination-next-button.svelte
@@ -1,31 +1,30 @@
<script lang="ts">
- import { Pagination as PaginationPrimitive } from "bits-ui";
- import ChevronRight from "@lucide/svelte/icons/chevron-right";
- import { buttonVariants } from "$lib/components/ui/button/index.js";
- import { cn } from "$lib/utils.js";
+ import { Pagination as PaginationPrimitive } from "bits-ui";
+ import ChevronRight from "@lucide/svelte/icons/chevron-right";
+ import { buttonVariants } from "$lib/components/ui/button/index.js";
+ import { cn } from "$lib/utils.js";
- let {
- ref = $bindable(null),
- class: className,
- children,
- ...restProps
- }: PaginationPrimitive.NextButtonProps = $props();
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: PaginationPrimitive.NextButtonProps = $props();
</script>
{#snippet Fallback()}
- <span>Next</span>
- <ChevronRight class="size-4" />
+ <ChevronRight class="h-4 w-4" />
{/snippet}
<PaginationPrimitive.NextButton
- bind:ref
- class={cn(
- buttonVariants({
- variant: "ghost",
- class: "gap-1 pr-2.5",
- }),
- className
- )}
- children={children || Fallback}
- {...restProps}
+ bind:ref
+ class={cn(
+ buttonVariants({
+ variant: "ghost",
+ class: "gap-1 pr-2.5",
+ }),
+ className
+ )}
+ children={children || Fallback}
+ {...restProps}
/>
diff --git a/src/lib/components/ui/pagination/pagination-prev-button.svelte b/src/lib/components/ui/pagination/pagination-prev-button.svelte
index 2b1a99166..981316e11 100644
--- a/src/lib/components/ui/pagination/pagination-prev-button.svelte
+++ b/src/lib/components/ui/pagination/pagination-prev-button.svelte
@@ -1,31 +1,30 @@
<script lang="ts">
- import { Pagination as PaginationPrimitive } from "bits-ui";
- import ChevronLeft from "@lucide/svelte/icons/chevron-left";
- import { buttonVariants } from "$lib/components/ui/button/index.js";
- import { cn } from "$lib/utils.js";
+ import { Pagination as PaginationPrimitive } from "bits-ui";
+ import ChevronLeft from "@lucide/svelte/icons/chevron-left";
+ import { buttonVariants } from "$lib/components/ui/button/index.js";
+ import { cn } from "$lib/utils.js";
- let {
- ref = $bindable(null),
- class: className,
- children,
- ...restProps
- }: PaginationPrimitive.PrevButtonProps = $props();
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: PaginationPrimitive.PrevButtonProps = $props();
</script>
{#snippet Fallback()}
- <ChevronLeft class="size-4" />
- <span>Previous</span>
+ <ChevronLeft class="h-4 w-4" />
{/snippet}
<PaginationPrimitive.PrevButton
- bind:ref
- class={cn(
- buttonVariants({
- variant: "ghost",
- class: "gap-1 pl-2.5",
- }),
- className
- )}
- children={children || Fallback}
- {...restProps}
+ bind:ref
+ class={cn(
+ buttonVariants({
+ variant: "ghost",
+ class: "gap-1 pl-2.5",
+ }),
+ className
+ )}
+ children={children || Fallback}
+ {...restProps}
/>
diff --git a/src/lib/components/universal-table.svelte b/src/lib/components/universal-table.svelte
new file mode 100644
index 000000000..8b9af9a27
--- /dev/null
+++ b/src/lib/components/universal-table.svelte
@@ -0,0 +1,338 @@
+<script lang="ts" generics="TData">
+ import {
+ getCoreRowModel,
+ getPaginationRowModel,
+ getSortedRowModel,
+ type SortingState,
+ getFilteredRowModel,
+ type ColumnFiltersState,
+ } from "@tanstack/table-core";
+ import {
+ createSvelteTable,
+ FlexRender,
+ } from "$lib/components/ui/data-table/index.js";
+ import * as Table from "$lib/components/ui/table/index.js";
+ import * as Pagination from "$lib/components/ui/pagination/index.js";
+ import * as Select from "$lib/components/ui/select/index.js";
+ import { Input } from "$lib/components/ui/input/index.js";
+ import { Button } from "$lib/components/ui/button/index.js";
+ import { debounced } from "$lib/utils";
+ import { Checkbox } from "$lib/components/ui/checkbox/index.js";
+ import { ChevronDown } from "@lucide/svelte";
+ import { cn } from "$lib/utils";
+ import type { UniversalTableProps } from "$lib/types/table-types";
+
+ let {
+ data,
+ columns,
+ features = {},
+ display = {},
+ pagination = {},
+ sort = {},
+ selectedIds = $bindable<string[]>([]),
+ }: UniversalTableProps<TData> = $props();
+
+ let {
+ sorting: enableSorting = true,
+ filtering: enableFiltering = true,
+ selection: enableSelection = true,
+ } = features;
+
+ let {
+ pageSize: initialPageSize = 10,
+ pageSizeOptions = [10, 20, 50, 100],
+ itemsPerPageLabel = "Items per page",
+ } = pagination;
+
+ let {
+ filterPlaceholder = "Search...",
+ noResultsMessage = "No results found",
+ isDashboardTable = false,
+ class: className = "",
+ } = display;
+
+ let { defaultSort = { id: "name", desc: false } } = sort;
+
+ // Pagination state
+ let pageSize = $state(initialPageSize);
+ let pageIndex = $state(0);
+ let currentPage = $state(1);
+
+ // Sorting state - Initialize with default sort
+ let sorting = $state<SortingState>(defaultSort ? [defaultSort] : []);
+
+ // Filtering state
+ let columnFilters = $state<ColumnFiltersState>([]);
+ let globalFilter = $state<string>("");
+ // Selection state
+ let selectedRowIds = $state<Record<string, boolean>>({});
+
+ $effect(() => {
+ // Update selected IDs array when row selection changes
+ selectedIds = Object.entries(selectedRowIds)
+ .filter(([_, selected]) => selected)
+ .map(([id]) => id);
+ });
+
+ // Sync pagination states
+ $effect(() => {
+ pageIndex = currentPage - 1;
+ });
+
+ $effect(() => {
+ const tablePageIndex = table.getState().pagination.pageIndex;
+ if (tablePageIndex !== pageIndex) {
+ currentPage = tablePageIndex + 1;
+ }
+ });
+
+ // Create table instance
+ const table = createSvelteTable({
+ get data() {
+ return data;
+ },
+ columns,
+ getCoreRowModel: getCoreRowModel(),
+ getPaginationRowModel: getPaginationRowModel(),
+ getSortedRowModel: enableSorting ? getSortedRowModel() : undefined,
+ getFilteredRowModel: enableFiltering ? getFilteredRowModel() : undefined,
+ state: {
+ get pagination() {
+ return {
+ pageIndex,
+ pageSize,
+ };
+ },
+ get sorting() {
+ return sorting;
+ },
+ get columnFilters() {
+ return columnFilters;
+ },
+ get globalFilter() {
+ return globalFilter;
+ },
+ get rowSelection() {
+ return selectedRowIds;
+ },
+ },
+ onSortingChange: (updater) => {
+ if (typeof updater === "function") {
+ sorting = updater(sorting);
+ } else {
+ sorting = updater;
+ }
+ },
+ onColumnFiltersChange: (updater) => {
+ if (typeof updater === "function") {
+ columnFilters = updater(columnFilters);
+ } else {
+ columnFilters = updater;
+ }
+ },
+ onGlobalFilterChange: (value) => {
+ globalFilter = value;
+ pageIndex = 0; // Reset to first page when filtering
+ currentPage = 1;
+ },
+ onRowSelectionChange: (updater) => {
+ if (typeof updater === "function") {
+ selectedRowIds = updater(selectedRowIds);
+ } else {
+ selectedRowIds = updater;
+ }
+ },
+ enableRowSelection: enableSelection,
+ });
+
+ const pageCount = $derived(table.getPageCount());
+ const filteredRowCount = $derived(table.getFilteredRowModel().rows.length);
+
+ // Handle global filtering with debounce
+ const handleFilterChange = debounced((value: string) => {
+ table.setGlobalFilter(value);
+ }, 300);
+
+ // Check if all rows on current page are selected
+ const allRowsSelected = $derived(
+ table.getIsAllPageRowsSelected() && table.getRowModel().rows.length > 0
+ );
+
+ // Handle page size change
+ function handlePageSizeChange(size: string | number) {
+ const sizeNumber = typeof size === "string" ? parseInt(size) : size;
+ pageSize = sizeNumber;
+ table.setPageSize(sizeNumber);
+ pageIndex = 0;
+ currentPage = 1;
+ }
+</script>
+
+<div class={cn("space-y-4", className, isDashboardTable && "dashboard-table")}>
+ {#if enableFiltering && !isDashboardTable}
+ <div class="flex items-center">
+ <Input
+ placeholder={filterPlaceholder}
+ value={globalFilter}
+ oninput={(e) => handleFilterChange(e.currentTarget.value)}
+ class="max-w-sm"
+ />
+ </div>
+ {/if}
+
+ <div
+ class={cn(
+ "rounded-md border",
+ isDashboardTable && "border-none rounded-none"
+ )}
+ >
+ <Table.Root>
+ <Table.Header>
+ {#each table.getHeaderGroups() as headerGroup (headerGroup.id)}
+ <Table.Row>
+ {#if enableSelection}
+ <Table.Head class="w-12">
+ <Checkbox
+ checked={allRowsSelected}
+ onCheckedChange={(checked) =>
+ table.toggleAllPageRowsSelected(!!checked)}
+ />
+ </Table.Head>
+ {/if}
+ {#each headerGroup.headers as header (header.id)}
+ <Table.Head>
+ {#if !header.isPlaceholder}
+ {#if header.column.getCanSort()}
+ <Button
+ variant="ghost"
+ class="flex items-center p-0 hover:bg-transparent"
+ onclick={() =>
+ header.column.toggleSorting(
+ header.column.getIsSorted() === "asc"
+ )}
+ >
+ <FlexRender
+ content={header.column.columnDef.header}
+ context={header.getContext()}
+ />
+ {#if header.column.getIsSorted()}
+ <ChevronDown
+ class={cn(
+ "ml-2 h-4 w-4",
+ header.column.getIsSorted() === "asc"
+ ? "rotate-180"
+ : ""
+ )}
+ />
+ {/if}
+ </Button>
+ {:else}
+ <FlexRender
+ content={header.column.columnDef.header}
+ context={header.getContext()}
+ />
+ {/if}
+ {/if}
+ </Table.Head>
+ {/each}
+ </Table.Row>
+ {/each}
+ </Table.Header>
+ <Table.Body>
+ {#if table.getRowModel().rows.length > 0}
+ {#each table.getRowModel().rows as row (row.id)}
+ <Table.Row data-state={row.getIsSelected() && "selected"}>
+ {#if enableSelection}
+ <Table.Cell class="w-12">
+ <Checkbox
+ checked={row.getIsSelected()}
+ onCheckedChange={(checked) => row.toggleSelected(!!checked)}
+ />
+ </Table.Cell>
+ {/if}
+ {#each row.getVisibleCells() as cell (cell.id)}
+ <Table.Cell>
+ <FlexRender
+ content={cell.column.columnDef.cell}
+ context={cell.getContext()}
+ />
+ </Table.Cell>
+ {/each}
+ </Table.Row>
+ {/each}
+ {:else}
+ <Table.Row>
+ <Table.Cell
+ colspan={enableSelection ? columns.length + 1 : columns.length}
+ class="h-24 text-center"
+ >
+ {noResultsMessage}
+ </Table.Cell>
+ </Table.Row>
+ {/if}
+ </Table.Body>
+ </Table.Root>
+ </div>
+
+ <!-- Pagination Controls -->
+ {#if (pageCount > 1 || pageSizeOptions.length > 1) && !isDashboardTable}
+ <div class="flex flex-col sm:flex-row items-center justify-between gap-4">
+ <div class="flex items-center gap-4">
+ <span class="text-sm my-auto">{itemsPerPageLabel}</span>
+ <Select.Root
+ type="single"
+ value={pageSize.toString()}
+ onValueChange={(value) => handlePageSizeChange(value)}
+ >
+ <Select.Trigger class="h-8 w-[70px]" id="pageSize">
+ <span>
+ {pageSize}
+ </span>
+ </Select.Trigger>
+ <Select.Content>
+ {#each pageSizeOptions as size}
+ <Select.Item value={size.toString()}>
+ {size}
+ </Select.Item>
+ {/each}
+ </Select.Content>
+ </Select.Root>
+ </div>
+
+ <div class="ml-auto">
+ <Pagination.Root
+ count={filteredRowCount}
+ perPage={pageSize}
+ bind:page={currentPage}
+ >
+ {#snippet children({ pages, currentPage })}
+ <Pagination.Content>
+ <Pagination.Item>
+ <Pagination.PrevButton />
+ </Pagination.Item>
+ {#each pages as page (page.key)}
+ {#if page.type === "ellipsis"}
+ <Pagination.Item>
+ <Pagination.Ellipsis />
+ </Pagination.Item>
+ {:else}
+ <Pagination.Item>
+ <Pagination.Link
+ {page}
+ isActive={currentPage === page.value}
+ >
+ {page.value}
+ </Pagination.Link>
+ </Pagination.Item>
+ {/if}
+ {/each}
+ <Pagination.Item>
+ <Pagination.NextButton />
+ </Pagination.Item>
+ </Pagination.Content>
+ {/snippet}
+ </Pagination.Root>
+ </div>
+ </div>
+ {/if}
+</div>
diff --git a/src/lib/types/table-types.ts b/src/lib/types/table-types.ts
new file mode 100644
index 000000000..691f677c9
--- /dev/null
+++ b/src/lib/types/table-types.ts
@@ -0,0 +1,34 @@
+import { type ColumnDef } from "@tanstack/table-core";
+
+export type FeatureFlags = {
+ sorting?: boolean;
+ filtering?: boolean;
+ selection?: boolean;
+};
+
+export type PaginationOptions = {
+ pageSize?: number;
+ pageSizeOptions?: number[];
+ itemsPerPageLabel?: string;
+};
+
+export type DisplayOptions = {
+ filterPlaceholder?: string;
+ noResultsMessage?: string;
+ isDashboardTable?: boolean;
+ class?: string;
+};
+
+export type SortOptions = {
+ defaultSort?: { id: string; desc: boolean };
+};
+
+export type UniversalTableProps<TData> = {
+ columns: ColumnDef<TData, any>[];
+ data: TData[];
+ features?: FeatureFlags;
+ display?: DisplayOptions;
+ pagination?: PaginationOptions;
+ sort?: SortOptions;
+ selectedIds?: string[];
+};
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 31dba72fc..c650cdecd 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -21,3 +21,12 @@ export function debounced<T extends (...args: any[]) => void>(
}, delay);
};
}
+
+export function formatBytes(bytes: number, decimals = 2): string {
+ if (!+bytes) return "0 Bytes";
+ const k = 1024;
+ const dm = decimals < 0 ? 0 : decimals;
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
+}
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 3eb7a2e23..e4b9388cf 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -3,26 +3,25 @@
import * as Card from "$lib/components/ui/card/index.js";
import { Button } from "$lib/components/ui/button/index.js";
import * as Table from "$lib/components/ui/table/index.js";
+ import UniversalTable from "$lib/components/universal-table.svelte";
import StatusBadge from "$lib/components/docker/StatusBadge.svelte";
+ import { dashboardContainerColumns, dashboardImageColumns } from "./columns";
import {
AlertCircle,
- Server,
Box,
HardDrive,
Cpu,
MemoryStick,
- Network,
ArrowRight,
- RefreshCw,
PlayCircle,
StopCircle,
Trash2,
} from "@lucide/svelte";
import * as Alert from "$lib/components/ui/alert/index.js";
- import { Separator } from "$lib/components/ui/separator/index.js";
import { Progress } from "$lib/components/ui/progress/index.js";
import { Badge } from "$lib/components/ui/badge/index.js";
import { invalidateAll } from "$app/navigation";
+ import { formatBytes } from "$lib/utils";
let { data }: { data: PageData } = $props();
const { dockerInfo, containers, images, error } = data;
@@ -37,25 +36,6 @@
const stoppedContainers = $derived(
containers?.filter((c) => c.state === "exited").length ?? 0
);
-
- // Helper to format bytes
- function formatBytes(bytes: number | undefined | null, decimals = 1): string {
- if (!bytes || !+bytes) return "0 Bytes";
- const k = 1024;
- const dm = decimals < 0 ? 0 : decimals;
- const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
- const i = Math.floor(Math.log(bytes) / Math.log(k));
- return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
- }
-
- // Function to refresh data
- async function refreshData() {
- isRefreshing = true;
- await invalidateAll();
- setTimeout(() => {
- isRefreshing = false;
- }, 500);
- }
</script>
<div class="space-y-8">
@@ -67,7 +47,8 @@
Overview of your Docker environment
</p>
</div>
- <Button
+ <!-- Dont remove this button -->
+ <!-- <Button
variant="outline"
size="sm"
class="h-9"
@@ -76,7 +57,7 @@
>
<RefreshCw class={`h-4 w-4 mr-2 ${isRefreshing ? "animate-spin" : ""}`} />
Refresh
- </Button>
+ </Button> -->
</div>
{#if error}
@@ -241,17 +222,13 @@
<h2 class="text-lg font-semibold tracking-tight mb-4">Resources</h2>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Containers List -->
- <Card.Root class="border shadow-sm">
+ <Card.Root class="border shadow-sm relative flex flex-col">
<Card.Header class="px-6">
<div class="flex items-center justify-between">
<div>
- <Card.Title>
- Containers
- <Badge variant="secondary" class="ml-2"
- >{containers?.length || 0}</Badge
- >
- </Card.Title>
- <Card.Description>Recent containers</Card.Description>
+ <Card.Title>Containers</Card.Title>
+ <Card.Description class="pb-3">Recent containers</Card.Description
+ >
</div>
<Button
variant="ghost"
@@ -264,41 +241,34 @@
</Button>
</div>
</Card.Header>
- <Card.Content class="p-0">
+ <Card.Content class="p-0 flex-1">
{#if containers?.length > 0}
- <Table.Root>
- <Table.Header>
- <Table.Row>
- <Table.Head class="pl-6 w-[30%]">Name</Table.Head>
- <Table.Head class="w-[40%]">Image</Table.Head>
- <Table.Head>State</Table.Head>
- <Table.Head class="pr-6">Status</Table.Head>
- </Table.Row>
- </Table.Header>
- <Table.Body>
- {#each containers.slice(0, 5) as c (c.id)}
- <Table.Row>
- <Table.Cell class="font-medium pl-6 truncate">
- <a href="/containers/{c.id}" class="hover:underline">
- {c.name}
- </a>
- </Table.Cell>
- <Table.Cell class="text-xs truncate max-w-[200px]">
- {c.image}
- </Table.Cell>
- <Table.Cell>
- <StatusBadge state={c.state} />
- </Table.Cell>
- <Table.Cell class="text-xs pr-6">{c.status}</Table.Cell>
- </Table.Row>
- {/each}
- </Table.Body>
- </Table.Root>
- {#if containers.length > 5}
- <div class="bg-muted/40 py-2 px-6 text-xs text-muted-foreground">
- Showing 5 of {containers.length} containers
+ <div class="flex flex-col h-full">
+ <div class="flex-1">
+ <UniversalTable
+ data={containers.slice(0, 5)}
+ columns={dashboardContainerColumns}
+ features={{
+ filtering: false,
+ selection: false,
+ }}
+ pagination={{
+ pageSize: 5,
+ pageSizeOptions: [5],
+ }}
+ display={{
+ isDashboardTable: true,
+ }}
+ />
</div>
- {/if}
+ {#if containers.length > 5}
+ <div
+ class="bg-muted/40 py-2 px-6 text-xs text-muted-foreground border-t"
+ >
+ Showing 5 of {containers.length} containers
+ </div>
+ {/if}
+ </div>
{:else if !error}
<div
class="flex flex-col items-center justify-center py-10 px-6 text-center"
@@ -314,17 +284,12 @@
</Card.Root>
<!-- Images List -->
- <Card.Root class="border shadow-sm">
+ <Card.Root class="border shadow-sm relative flex flex-col">
<Card.Header class="px-6">
<div class="flex items-center justify-between">
<div>
- <Card.Title>
- Images
- <Badge variant="secondary" class="ml-2"
- >{images?.length || 0}</Badge
- >
- </Card.Title>
- <Card.Description>Recent images</Card.Description>
+ <Card.Title>Images</Card.Title>
+ <Card.Description class="pb-3">Recent images</Card.Description>
</div>
<Button
variant="ghost"
@@ -337,34 +302,37 @@
</Button>
</div>
</Card.Header>
- <Card.Content class="p-0">
+ <Card.Content class="p-0 flex-1">
{#if images?.length > 0}
- <Table.Root>
- <Table.Header>
- <Table.Row>
- <Table.Head class="pl-6 w-[50%]">Repository</Table.Head>
- <Table.Head class="w-[20%]">Tag</Table.Head>
- <Table.Head class="pr-6">Size</Table.Head>
- </Table.Row>
- </Table.Header>
- <Table.Body>
- {#each images.slice(0, 5) as img (img.id)}
- <Table.Row>
- <Table.Cell class="font-medium truncate pl-6">
- {img.repo}
- </Table.Cell>
- <Table.Cell>{img.tag}</Table.Cell>
- <Table.Cell class="pr-6">{formatBytes(img.size)}</Table.Cell
- >
- </Table.Row>
- {/each}
- </Table.Body>
- </Table.Root>
- {#if images.length > 5}
- <div class="bg-muted/40 py-2 px-6 text-xs text-muted-foreground">
- Showing 5 of {images.length} images
+ <div class="flex flex-col h-full">
+ <div class="flex-1">
+ <UniversalTable
+ data={images.slice(0, 5)}
+ columns={dashboardImageColumns}
+ features={{
+ filtering: false,
+ selection: false,
+ }}
+ pagination={{
+ pageSize: 5,
+ pageSizeOptions: [5],
+ }}
+ display={{
+ isDashboardTable: true,
+ }}
+ sort={{
+ defaultSort: { id: "repo", desc: false },
+ }}
+ />
</div>
- {/if}
+ {#if images.length > 5}
+ <div
+ class="bg-muted/40 py-2 px-6 text-xs text-muted-foreground border-t"
+ >
+ Showing 5 of {images.length} images
+ </div>
+ {/if}
+ </div>
{:else if !error}
<div
class="flex flex-col items-center justify-center py-10 px-6 text-center"
diff --git a/src/routes/columns.ts b/src/routes/columns.ts
new file mode 100644
index 000000000..1df21da46
--- /dev/null
+++ b/src/routes/columns.ts
@@ -0,0 +1,53 @@
+import type { ColumnDef } from "@tanstack/table-core";
+import type {
+ ServiceContainer,
+ ServiceImage,
+} from "$lib/services/docker-service";
+import { formatBytes } from "$lib/utils";
+import StatusBadge from "$lib/components/docker/StatusBadge.svelte";
+import { renderComponent } from "$lib/components/ui/data-table/index.js";
+
+// Column definitions for the dashboard containers table
+export const dashboardContainerColumns: ColumnDef<ServiceContainer>[] = [
+ {
+ accessorKey: "name",
+ header: "Name",
+ cell: ({ row }) => row.original.name,
+ },
+ {
+ accessorKey: "image",
+ header: "Image",
+ cell: ({ row }) => row.original.image,
+ },
+ {
+ accessorKey: "state",
+ header: "State",
+ cell: ({ row }) => {
+ return renderComponent(StatusBadge, { state: row.original.state });
+ },
+ },
+ {
+ accessorKey: "status",
+ header: "Status",
+ cell: ({ row }) => row.original.status,
+ },
+];
+
+// Column definitions for the dashboard images table
+export const dashboardImageColumns: ColumnDef<ServiceImage>[] = [
+ {
+ accessorKey: "repo",
+ header: "Name",
+ cell: ({ row }) => row.original.repo,
+ },
+ {
+ accessorKey: "tag",
+ header: "Tag",
+ cell: ({ row }) => row.original.tag,
+ },
+ {
+ accessorKey: "size",
+ header: "Size",
+ cell: ({ row }) => formatBytes(row.original.size),
+ },
+];
diff --git a/src/routes/containers/+page.server.ts b/src/routes/containers/+page.server.ts
index 827886386..220e9a8e4 100644
--- a/src/routes/containers/+page.server.ts
+++ b/src/routes/containers/+page.server.ts
@@ -3,16 +3,12 @@ import { listContainers } from "$lib/services/docker-service"; // Import the ser
export const load: PageServerLoad = async () => {
try {
- // Call the listContainers function from your service
- const containers = await listContainers(true); // Get all containers (running and stopped)
-
- // The listContainers function already maps the data, so we can return it directly
+ const containers = await listContainers(true);
return {
containers,
};
} catch (error: any) {
console.error("Failed to load containers:", error);
- // Return an error state or an empty array so the page can handle it
return {
containers: [],
error: error.message || "Failed to connect to Docker or list containers.",
diff --git a/src/routes/containers/+page.svelte b/src/routes/containers/+page.svelte
index cfab5d645..df42fb590 100644
--- a/src/routes/containers/+page.svelte
+++ b/src/routes/containers/+page.svelte
@@ -1,16 +1,16 @@
<script lang="ts">
- import DataTable from "$lib/components/data-table.svelte";
import { Button } from "$lib/components/ui/button/index.js";
import * as Card from "$lib/components/ui/card/index.js";
- import { columns } from "./columns.js";
- import { Plus, Box, RefreshCw, Filter, ArrowUpDown } from "@lucide/svelte";
- import { Badge } from "$lib/components/ui/badge/index.js";
+ import { columns } from "./columns";
+ import { Plus, Box, RefreshCw } from "@lucide/svelte";
+ import UniversalTable from "$lib/components/universal-table.svelte";
import { invalidateAll } from "$app/navigation";
let { data } = $props();
const { containers } = data;
let isRefreshing = $state(false);
+ let selectedIds = $state([]);
// Calculate running containers
const runningContainers = $derived(
@@ -44,19 +44,7 @@
</p>
</div>
<div class="flex gap-2">
- <Button
- variant="outline"
- size="sm"
- onclick={refreshData}
- disabled={isRefreshing}
- >
- <RefreshCw class={`h-4 w-4 ${isRefreshing ? "animate-spin" : ""}`} />
- Refresh
- </Button>
- <Button variant="outline" size="sm">
- <Plus class="w-4 h-4" />
- Create Container
- </Button>
+ <!-- put buttons here -->
</div>
</div>
@@ -104,28 +92,29 @@
<Card.Header class="px-6">
<div class="flex items-center justify-between">
<div>
- <Card.Title>
- Container List
- <Badge variant="secondary" class="ml-2">{totalContainers}</Badge>
- </Card.Title>
+ <Card.Title>Container List</Card.Title>
<Card.Description
>View and manage your Docker containers</Card.Description
>
</div>
<div class="flex items-center gap-2">
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <Filter class="h-4 w-4 mr-2" />
- Filter
- </Button>
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <ArrowUpDown class="h-4 w-4 mr-2" />
- Sort
+ <Button variant="outline" size="sm">
+ <Plus class="w-4 h-4" />
+ Create Container
</Button>
</div>
</div>
</Card.Header>
<Card.Content>
- <DataTable data={containers} {columns} />
+ <UniversalTable
+ data={containers}
+ {columns}
+ display={{
+ filterPlaceholder: "Search containers...",
+ noResultsMessage: "No containers found",
+ }}
+ bind:selectedIds
+ />
</Card.Content>
</Card.Root>
diff --git a/src/routes/containers/ContainerActions.svelte b/src/routes/containers/ContainerActions.svelte
new file mode 100644
index 000000000..7f521db9d
--- /dev/null
+++ b/src/routes/containers/ContainerActions.svelte
@@ -0,0 +1,82 @@
+<script lang="ts">
+ import Ellipsis from "@lucide/svelte/icons/ellipsis";
+ import { Button } from "$lib/components/ui/button/index.js";
+ import * as DropdownMenu from "$lib/components/ui/dropdown-menu/index.js";
+ import { goto } from "$app/navigation";
+ import { Eye, Play, RotateCcw, StopCircle, Trash2 } from "@lucide/svelte";
+
+ let { id, state }: { id: string; state: string } = $props();
+
+ function viewContainer() {
+ goto(`/containers/${id}`);
+ }
+
+ function performContainerAction(action: string) {
+ // Log the action for now - will be replaced with API call later
+ console.log(`Container ${id}: Performing action: ${action}`);
+
+ /*
+ try {
+ // Will implement fetch call to backend API endpoint
+ // await fetch(`/api/containers/${id}/${action}`, {
+ // method: 'POST'
+ // });
+ console.log(`Successfully performed ${action} on container ${id}`);
+ } catch (error) {
+ console.error(`Failed to ${action} container ${id}:`, error);
+ }
+ */
+ }
+
+ // Determine if container is running
+ const isRunning = $derived(state === "running");
+</script>
+
+<DropdownMenu.Root>
+ <DropdownMenu.Trigger>
+ {#snippet child({ props })}
+ <Button
+ {...props}
+ variant="ghost"
+ size="icon"
+ class="relative size-8 p-0"
+ >
+ <span class="sr-only">Open menu</span>
+ <Ellipsis />
+ </Button>
+ {/snippet}
+ </DropdownMenu.Trigger>
+ <DropdownMenu.Content>
+ <DropdownMenu.Group>
+ <DropdownMenu.Item onclick={() => viewContainer()}>
+ <Eye class="w-4 h-4" />
+ View
+ </DropdownMenu.Item>
+
+ {#if !isRunning}
+ <DropdownMenu.Item onclick={() => performContainerAction("start")}>
+ <Play class="w-4 h-4" />
+ Start
+ </DropdownMenu.Item>
+ {:else}
+ <DropdownMenu.Item onclick={() => performContainerAction("restart")}>
+ <RotateCcw class="w-4 h-4" />
+ Restart
+ </DropdownMenu.Item>
+
+ <DropdownMenu.Item onclick={() => performContainerAction("stop")}>
+ <StopCircle class="w-4 h-4" />
+ Stop
+ </DropdownMenu.Item>
+ {/if}
+
+ <DropdownMenu.Item
+ class="text-red-500 focus:!text-red-700"
+ onclick={() => performContainerAction("remove")}
+ >
+ <Trash2 class="w-4 h-4" />
+ Remove
+ </DropdownMenu.Item>
+ </DropdownMenu.Group>
+ </DropdownMenu.Content>
+</DropdownMenu.Root>
diff --git a/src/routes/containers/columns.ts b/src/routes/containers/columns.ts
index 3458566ca..2c81090de 100644
--- a/src/routes/containers/columns.ts
+++ b/src/routes/containers/columns.ts
@@ -1,7 +1,7 @@
import type { ServiceContainer } from "$lib/services/docker-service";
import type { ColumnDef } from "@tanstack/table-core";
import { renderComponent } from "$lib/components/ui/data-table/index.js";
-import DataTableActions from "./data-table-actions.svelte";
+import DataTableActions from "./ContainerActions.svelte";
import StatusBadge from "$lib/components/docker/StatusBadge.svelte";
import IdCell from "./IdCell.svelte";
@@ -35,7 +35,7 @@ export const columns: ColumnDef<ServiceContainer>[] = [
},
{
id: "actions",
- header: "Actions",
+ header: "",
cell: ({ row }) => {
return renderComponent(DataTableActions, {
id: row.original.id,
diff --git a/src/routes/containers/data-table-actions.svelte b/src/routes/containers/data-table-actions.svelte
deleted file mode 100644
index 310abea14..000000000
--- a/src/routes/containers/data-table-actions.svelte
+++ /dev/null
@@ -1,37 +0,0 @@
-<script lang="ts">
- import Ellipsis from "@lucide/svelte/icons/ellipsis";
- import { Button } from "$lib/components/ui/button/index.js";
- import * as DropdownMenu from "$lib/components/ui/dropdown-menu/index.js";
- import { goto } from "$app/navigation";
-
- let { id }: { id: string } = $props();
-
- function viewContainer() {
- goto(`/containers/${id}`);
- }
-</script>
-
-<DropdownMenu.Root>
- <DropdownMenu.Trigger>
- {#snippet child({ props })}
- <Button
- {...props}
- variant="ghost"
- size="icon"
- class="relative size-8 p-0"
- >
- <span class="sr-only">Open menu</span>
- <Ellipsis />
- </Button>
- {/snippet}
- </DropdownMenu.Trigger>
- <DropdownMenu.Content>
- <DropdownMenu.Group>
- <DropdownMenu.GroupHeading>Actions</DropdownMenu.GroupHeading>
- <DropdownMenu.Separator />
- <DropdownMenu.Item onclick={() => viewContainer()}
- >View Container</DropdownMenu.Item
- >
- </DropdownMenu.Group>
- </DropdownMenu.Content>
-</DropdownMenu.Root>
diff --git a/src/routes/images/+page.svelte b/src/routes/images/+page.svelte
index 9755838aa..3358f5383 100644
--- a/src/routes/images/+page.svelte
+++ b/src/routes/images/+page.svelte
@@ -1,25 +1,19 @@
<script lang="ts">
import type { PageData } from "./$types";
- import DataTable from "$lib/components/data-table.svelte";
+ import UniversalTable from "$lib/components/universal-table.svelte";
import { columns } from "./columns";
import { Button } from "$lib/components/ui/button/index.js";
- import {
- Download,
- AlertCircle,
- RefreshCw,
- Filter,
- ArrowUpDown,
- HardDrive,
- } from "@lucide/svelte";
+ import { Download, AlertCircle, RefreshCw, HardDrive } from "@lucide/svelte";
import * as Alert from "$lib/components/ui/alert/index.js";
import * as Card from "$lib/components/ui/card/index.js";
- import { Badge } from "$lib/components/ui/badge/index.js";
import { invalidateAll } from "$app/navigation";
import { toast } from "svelte-sonner";
import PullImageDialog from "./pull-image-dialog.svelte";
+ import { formatBytes } from "$lib/utils";
let { data }: { data: PageData } = $props();
const { images, error } = data;
+ let selectedIds = $state([]);
let isRefreshing = $state(false);
let isPullDialogOpen = $state(false);
@@ -98,15 +92,6 @@
function openPullDialog() {
isPullDialogOpen = true;
}
-
- function formatBytes(bytes: number | undefined | null, decimals = 1): string {
- if (!bytes || !+bytes) return "0 Bytes";
- const k = 1024;
- const dm = decimals < 0 ? 0 : decimals;
- const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
- const i = Math.floor(Math.log(bytes) / Math.log(k));
- return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
- }
</script>
<div class="space-y-6">
@@ -119,19 +104,7 @@
</p>
</div>
<div class="flex gap-2">
- <Button
- variant="outline"
- size="sm"
- onclick={refreshData}
- disabled={isRefreshing}
- >
- <RefreshCw class={`h-4 w-4 ${isRefreshing ? "animate-spin" : ""}`} />
- Refresh
- </Button>
- <Button variant="outline" size="sm" onclick={openPullDialog}>
- <Download class="w-4 h-4" />
- Pull Image
- </Button>
+ <!-- put buttons here -->
</div>
</div>
@@ -176,28 +149,32 @@
<Card.Header class="px-6">
<div class="flex items-center justify-between">
<div>
- <Card.Title>
- Image List
- <Badge variant="secondary" class="ml-2">{totalImages}</Badge>
- </Card.Title>
+ <Card.Title>Image List</Card.Title>
<Card.Description
>View and manage your Docker images</Card.Description
>
</div>
<div class="flex items-center gap-2">
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <Filter class="h-4 w-4 mr-2" />
- Filter
- </Button>
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <ArrowUpDown class="h-4 w-4 mr-2" />
- Sort
+ <Button variant="outline" size="sm" onclick={openPullDialog}>
+ <Download class="w-4 h-4" />
+ Pull Image
</Button>
</div>
</div>
</Card.Header>
<Card.Content>
- <DataTable data={images} {columns} />
+ <UniversalTable
+ data={images}
+ {columns}
+ display={{
+ filterPlaceholder: "Search images...",
+ noResultsMessage: "No images found",
+ }}
+ sort={{
+ defaultSort: { id: "repo", desc: false },
+ }}
+ bind:selectedIds
+ />
</Card.Content>
</Card.Root>
{:else if !error}
diff --git a/src/routes/images/columns.ts b/src/routes/images/columns.ts
index e2e43685e..b72bfe9e9 100644
--- a/src/routes/images/columns.ts
+++ b/src/routes/images/columns.ts
@@ -2,20 +2,12 @@ import type { ServiceImage } from "$lib/services/docker-service";
import type { ColumnDef } from "@tanstack/table-core";
import { renderComponent } from "$lib/components/ui/data-table/index.js";
import ImageActions from "./ImageActions.svelte";
-
-function formatBytes(bytes: number, decimals = 2): string {
- if (!+bytes) return "0 Bytes";
- const k = 1024;
- const dm = decimals < 0 ? 0 : decimals;
- const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
- const i = Math.floor(Math.log(bytes) / Math.log(k));
- return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
-}
+import { formatBytes } from "$lib/utils";
export const columns: ColumnDef<ServiceImage>[] = [
{
accessorKey: "repo",
- header: "Repository",
+ header: "Name",
cell: ({ row }) => {
return row.original.repo;
},
@@ -24,7 +16,6 @@ export const columns: ColumnDef<ServiceImage>[] = [
accessorKey: "tag",
header: "Tag",
cell: ({ row }) => {
- // Return the plain tag string
return row.original.tag;
},
},
@@ -48,7 +39,7 @@ export const columns: ColumnDef<ServiceImage>[] = [
},
{
id: "actions",
- header: "Actions",
+ header: "",
cell: ({ row }) => {
return renderComponent(ImageActions, {
id: row.original.id,
diff --git a/src/routes/networks/+page.svelte b/src/routes/networks/+page.svelte
index a85ecf9a1..912de015c 100644
--- a/src/routes/networks/+page.svelte
+++ b/src/routes/networks/+page.svelte
@@ -9,15 +9,15 @@
Filter,
ArrowUpDown,
} from "@lucide/svelte";
- import DataTable from "$lib/components/data-table.svelte";
+ import UniversalTable from "$lib/components/universal-table.svelte";
import { columns } from "./columns";
import type { PageData } from "./$types";
import * as Alert from "$lib/components/ui/alert/index.js";
- import { Badge } from "$lib/components/ui/badge/index.js";
import { invalidateAll } from "$app/navigation";
let { data }: { data: PageData } = $props();
const { networks, error } = data;
+ let selectedIds = $state([]);
let isRefreshing = $state(false);
@@ -53,19 +53,7 @@
</p>
</div>
<div class="flex gap-2">
- <Button
- variant="outline"
- size="sm"
- onclick={refreshData}
- disabled={isRefreshing}
- >
- <RefreshCw class={`h-4 w-4 ${isRefreshing ? "animate-spin" : ""}`} />
- Refresh
- </Button>
- <Button variant="outline" size="sm" onclick={createNetwork}>
- <Plus class="w-4 h-4" />
- Create Network
- </Button>
+ <!-- Put buttons here -->
</div>
</div>
@@ -127,28 +115,28 @@
<Card.Header class="px-6">
<div class="flex items-center justify-between">
<div>
- <Card.Title>
- Network List
- <Badge variant="secondary" class="ml-2">{totalNetworks}</Badge>
- </Card.Title>
+ <Card.Title>Network List</Card.Title>
<Card.Description>Manage container communication</Card.Description>
</div>
<div class="flex items-center gap-2">
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <Filter class="h-4 w-4 mr-2" />
- Filter
- </Button>
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <ArrowUpDown class="h-4 w-4 mr-2" />
- Sort
+ <Button variant="outline" size="sm" onclick={createNetwork}>
+ <Plus class="w-4 h-4" />
+ Create Network
</Button>
</div>
</div>
</Card.Header>
- <!-- Fixed padding for the table container -->
<Card.Content>
{#if networks && networks.length > 0}
- <DataTable data={networks} {columns} />
+ <UniversalTable
+ data={networks}
+ {columns}
+ display={{
+ filterPlaceholder: "Search networks...",
+ noResultsMessage: "No networks found",
+ }}
+ bind:selectedIds
+ />
{:else if !error}
<div
class="flex flex-col items-center justify-center py-12 px-6 text-center"
diff --git a/src/routes/networks/columns.ts b/src/routes/networks/columns.ts
index e40af8c71..a30d0dc89 100644
--- a/src/routes/networks/columns.ts
+++ b/src/routes/networks/columns.ts
@@ -41,7 +41,7 @@ export const columns: ColumnDef<NetworkInfo>[] = [
// },
{
id: "actions",
- header: "Actions",
+ header: "",
cell: ({ row }) => {
return renderComponent(NetworkActions, {
id: row.original.id, // Pass the actual ID
diff --git a/src/routes/stacks/+page.svelte b/src/routes/stacks/+page.svelte
index 18a531e5a..996181f0e 100644
--- a/src/routes/stacks/+page.svelte
+++ b/src/routes/stacks/+page.svelte
@@ -12,14 +12,14 @@
Upload,
FileStack,
} from "@lucide/svelte";
- import DataTable from "$lib/components/data-table.svelte";
+ import UniversalTable from "$lib/components/universal-table.svelte";
import { columns } from "./columns";
import * as Alert from "$lib/components/ui/alert/index.js";
- import { Badge } from "$lib/components/ui/badge/index.js";
import { invalidateAll } from "$app/navigation";
let { data }: { data: PageData } = $props();
const { stacks, error } = data;
+ let selectedIds = $state([]);
let isRefreshing = $state(false);
@@ -60,23 +60,7 @@
</p>
</div>
<div class="flex gap-2">
- <Button
- variant="outline"
- size="sm"
- onclick={refreshData}
- disabled={isRefreshing}
- >
- <RefreshCw class={`h-4 w-4 ${isRefreshing ? "animate-spin" : ""}`} />
- Refresh
- </Button>
- <Button variant="outline" size="sm" onclick={importStack}>
- <Upload class="w-4 h-4" />
- Import
- </Button>
- <Button variant="outline" size="sm" onclick={createStack}>
- <Plus class="w-4 h-4" />
- Create Stack
- </Button>
+ <!-- put buttons here -->
</div>
</div>
@@ -134,27 +118,32 @@
<Card.Header class="px-6">
<div class="flex items-center justify-between">
<div>
- <Card.Title>
- Stack List
- <Badge variant="secondary" class="ml-2">{totalStacks}</Badge>
- </Card.Title>
+ <Card.Title>Stack List</Card.Title>
<Card.Description>Manage Docker Compose stacks</Card.Description>
</div>
<div class="flex items-center gap-2">
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <Filter class="h-4 w-4 mr-2" />
- Filter
+ <Button variant="outline" size="sm" onclick={importStack}>
+ <Upload class="w-4 h-4" />
+ Import
</Button>
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <ArrowUpDown class="h-4 w-4 mr-2" />
- Sort
+ <Button variant="outline" size="sm" onclick={createStack}>
+ <Plus class="w-4 h-4" />
+ Create Stack
</Button>
</div>
</div>
</Card.Header>
<Card.Content>
{#if stacks && stacks.length > 0}
- <DataTable data={stacks} {columns} />
+ <UniversalTable
+ data={stacks}
+ {columns}
+ display={{
+ filterPlaceholder: "Search stacks...",
+ noResultsMessage: "No stacks found",
+ }}
+ bind:selectedIds
+ />
{:else if !error}
<div
class="flex flex-col items-center justify-center py-12 px-6 text-center"
@@ -165,16 +154,6 @@
Create a new stack using the "Create Stack" button above or import
an existing compose file
</p>
- <div class="flex gap-3 mt-4">
- <Button variant="outline" size="sm" onclick={refreshData}>
- <RefreshCw class="h-4 w-4" />
- Refresh
- </Button>
- <Button variant="outline" size="sm" onclick={createStack}>
- <Plus class="h-4 w-4" />
- Create Stack
- </Button>
- </div>
</div>
{/if}
</Card.Content>
diff --git a/src/routes/stacks/columns.ts b/src/routes/stacks/columns.ts
index c00173e7b..a1ce92ff8 100644
--- a/src/routes/stacks/columns.ts
+++ b/src/routes/stacks/columns.ts
@@ -39,7 +39,7 @@ export const columns: ColumnDef<Stack>[] = [
},
{
id: "actions",
- header: "Actions",
+ header: "",
cell: ({ row }) => {
return renderComponent(StackActions, {
id: row.original.id,
diff --git a/src/routes/volumes/+page.svelte b/src/routes/volumes/+page.svelte
index cd1947f7a..bbc50340c 100644
--- a/src/routes/volumes/+page.svelte
+++ b/src/routes/volumes/+page.svelte
@@ -12,17 +12,17 @@
Database,
Loader2,
} from "@lucide/svelte";
- import DataTable from "$lib/components/data-table.svelte";
+ import UniversalTable from "$lib/components/universal-table.svelte";
import { columns } from "./columns";
import type { PageData } from "./$types";
import * as Alert from "$lib/components/ui/alert/index.js";
- import { Badge } from "$lib/components/ui/badge/index.js";
import { invalidateAll } from "$app/navigation";
import CreateVolumeDialog from "./create-volume-dialog.svelte";
let { data }: { data: PageData } = $props();
let { error } = data;
let volumes = $state(data.volumes);
+ let selectedIds = $state([]);
let isRefreshing = $state(false);
let isCreateDialogOpen = $state(false);
@@ -102,23 +102,7 @@
</p>
</div>
<div class="flex gap-2">
- <Button
- variant="outline"
- size="sm"
- onclick={refreshData}
- disabled={isRefreshing || isCreatingVolume}
- >
- {#if isRefreshing}
- <Loader2 class="h-4 w-4 animate-spin" />
- {:else}
- <RefreshCw class="h-4 w-4" />
- {/if}
- Refresh
- </Button>
- <Button variant="outline" size="sm" onclick={openCreateDialog}>
- <Plus class="w-4 h-4" />
- Create Volume
- </Button>
+ <!-- put buttons here -->
</div>
</div>
@@ -160,27 +144,28 @@
<Card.Header class="px-6">
<div class="flex items-center justify-between">
<div>
- <Card.Title>
- Volume List
- <Badge variant="secondary" class="ml-2">{totalVolumes}</Badge>
- </Card.Title>
+ <Card.Title>Volume List</Card.Title>
<Card.Description>Manage persistent data storage</Card.Description>
</div>
<div class="flex items-center gap-2">
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <Filter class="h-4 w-4 mr-2" />
- Filter
- </Button>
- <Button variant="outline" size="sm" class="hidden sm:flex">
- <ArrowUpDown class="h-4 w-4 mr-2" />
- Sort
+ <Button variant="outline" size="sm" onclick={openCreateDialog}>
+ <Plus class="w-4 h-4" />
+ Create Volume
</Button>
</div>
</div>
</Card.Header>
<Card.Content>
{#if volumes && volumes.length > 0}
- <DataTable data={volumes} {columns} />
+ <UniversalTable
+ data={volumes}
+ {columns}
+ display={{
+ filterPlaceholder: "Search volumes...",
+ noResultsMessage: "No volumes found",
+ }}
+ bind:selectedIds
+ />
{:else if !error}
<div
class="flex flex-col items-center justify-center py-12 px-6 text-center"
@@ -191,16 +176,6 @@
Create a new volume using the "Create Volume" button above or use
the Docker CLI
</p>
- <div class="flex gap-3 mt-4">
- <Button variant="outline" size="default" onclick={refreshData}>
- <RefreshCw class="h-4 w-4 mr-2" />
- Refresh
- </Button>
- <Button variant="default" size="default" onclick={openCreateDialog}>
- <Plus class="h-4 w-4 mr-2" />
- Create Volume
- </Button>
- </div>
</div>
{/if}
</Card.Content>
diff --git a/src/routes/volumes/columns.ts b/src/routes/volumes/columns.ts
index 4d03af8da..b2de40cdd 100644
--- a/src/routes/volumes/columns.ts
+++ b/src/routes/volumes/columns.ts
@@ -31,7 +31,7 @@ export const columns: ColumnDef<VolumeInfo>[] = [
},
{
id: "actions",
- header: "Actions",
+ header: "",
cell: ({ row }) => {
return renderComponent(VolumeActions, {
name: row.original.name,