Skip to content

Modern Docker Management, Designed for Everyone

fix: improve image list page

Kyle Mendella46e2493e990
diff --git a/src/lib/components/data-table.svelte b/src/lib/components/data-table.svelte
index dc0dac2bf..5e0b3a68a 100644
--- a/src/lib/components/data-table.svelte
+++ b/src/lib/components/data-table.svelte
@@ -1,17 +1,45 @@
<script lang="ts" generics="TData, TValue">
- import { type ColumnDef, getCoreRowModel } from "@tanstack/table-core";
+ 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; // Optional page size prop
};
- let { data, columns }: DataTableProps<TData, TValue> = $props();
+ 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() {
@@ -19,46 +47,94 @@
},
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="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}
+<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={header.column.columnDef.header}
- context={header.getContext()}
+ content={cell.column.columnDef.cell}
+ context={cell.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}
- </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>
+ <Pagination.Item>
+ <Pagination.NextButton />
+ </Pagination.Item>
+ </Pagination.Content>
+ {/snippet}
+ </Pagination.Root>
+ {/if}
</div>
diff --git a/src/lib/components/ui/checkbox/checkbox.svelte b/src/lib/components/ui/checkbox/checkbox.svelte
new file mode 100644
index 000000000..2395094c5
--- /dev/null
+++ b/src/lib/components/ui/checkbox/checkbox.svelte
@@ -0,0 +1,35 @@
+<script lang="ts">
+ import { Checkbox as CheckboxPrimitive, type WithoutChildrenOrChild } from "bits-ui";
+ import Check from "@lucide/svelte/icons/check";
+ import Minus from "@lucide/svelte/icons/minus";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ checked = $bindable(false),
+ indeterminate = $bindable(false),
+ class: className,
+ ...restProps
+ }: WithoutChildrenOrChild<CheckboxPrimitive.RootProps> = $props();
+</script>
+
+<CheckboxPrimitive.Root
+ bind:ref
+ class={cn(
+ "border-primary ring-offset-background focus-visible:ring-ring data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground peer box-content size-4 shrink-0 rounded-sm border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50",
+ className
+ )}
+ bind:checked
+ bind:indeterminate
+ {...restProps}
+>
+ {#snippet children({ checked, indeterminate })}
+ <div class="flex size-4 items-center justify-center text-current">
+ {#if indeterminate}
+ <Minus class="size-3.5" />
+ {:else}
+ <Check class={cn("size-3.5", !checked && "text-transparent")} />
+ {/if}
+ </div>
+ {/snippet}
+</CheckboxPrimitive.Root>
diff --git a/src/lib/components/ui/checkbox/index.ts b/src/lib/components/ui/checkbox/index.ts
new file mode 100644
index 000000000..6d92d9458
--- /dev/null
+++ b/src/lib/components/ui/checkbox/index.ts
@@ -0,0 +1,6 @@
+import Root from "./checkbox.svelte";
+export {
+ Root,
+ //
+ Root as Checkbox,
+};
diff --git a/src/lib/components/ui/data-table/flex-render.svelte b/src/lib/components/ui/data-table/flex-render.svelte
index de3563f0e..982ced55d 100644
--- a/src/lib/components/ui/data-table/flex-render.svelte
+++ b/src/lib/components/ui/data-table/flex-render.svelte
@@ -1,43 +1,50 @@
<script lang="ts" module>
- import type { CellContext, ColumnDefTemplate, HeaderContext } from "@tanstack/table-core";
+ import type {
+ CellContext,
+ ColumnDefTemplate,
+ HeaderContext,
+ } from "@tanstack/table-core";
- type TData = unknown;
- type TValue = unknown;
- type TContext = unknown;
+ type TData = unknown;
+ type TValue = unknown;
+ type TContext = unknown;
</script>
<script
- lang="ts"
- generics="TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>"
+ lang="ts"
+ generics="TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>"
>
- import { RenderComponentConfig, RenderSnippetConfig } from "./render-helpers.js";
- type Props = {
- /** The cell or header field of the current cell's column definition. */
- content?: TContext extends HeaderContext<TData, TValue>
- ? ColumnDefTemplate<HeaderContext<TData, TValue>>
- : TContext extends CellContext<TData, TValue>
- ? ColumnDefTemplate<CellContext<TData, TValue>>
- : never;
- /** The result of the `getContext()` function of the header or cell */
- context: TContext;
- };
+ import {
+ RenderComponentConfig,
+ RenderSnippetConfig,
+ } from "./render-helpers.js";
+ type Props = {
+ /** The cell or header field of the current cell's column definition. */
+ content?: TContext extends HeaderContext<TData, TValue>
+ ? ColumnDefTemplate<HeaderContext<TData, TValue>>
+ : TContext extends CellContext<TData, TValue>
+ ? ColumnDefTemplate<CellContext<TData, TValue>>
+ : never;
+ /** The result of the `getContext()` function of the header or cell */
+ context: TContext;
+ };
- let { content, context }: Props = $props();
+ let { content, context }: Props = $props();
</script>
{#if typeof content === "string"}
- {content}
+ {content}
{:else if content instanceof Function}
- <!-- It's unlikely that a CellContext will be passed to a Header -->
- <!-- eslint-disable-next-line @typescript-eslint/no-explicit-any -->
- {@const result = content(context as any)}
- {#if result instanceof RenderComponentConfig}
- {@const { component: Component, props } = result}
- <Component {...props} />
- {:else if result instanceof RenderSnippetConfig}
- {@const { snippet, params } = result}
- {@render snippet(params)}
- {:else}
- {result}
- {/if}
+ <!-- It's unlikely that a CellContext will be passed to a Header -->
+ <!-- eslint-disable-next-line @typescript-eslint/no-explicit-any -->
+ {@const result = content(context as any)}
+ {#if result instanceof RenderComponentConfig}
+ {@const { component: Component, props } = result}
+ <Component {...props} />
+ {:else if result instanceof RenderSnippetConfig}
+ {@const { snippet, params } = result}
+ {@render snippet(params)}
+ {:else}
+ {result}
+ {/if}
{/if}
diff --git a/src/lib/components/ui/pagination/index.ts b/src/lib/components/ui/pagination/index.ts
new file mode 100644
index 000000000..d83c7a948
--- /dev/null
+++ b/src/lib/components/ui/pagination/index.ts
@@ -0,0 +1,25 @@
+import Root from "./pagination.svelte";
+import Content from "./pagination-content.svelte";
+import Item from "./pagination-item.svelte";
+import Link from "./pagination-link.svelte";
+import PrevButton from "./pagination-prev-button.svelte";
+import NextButton from "./pagination-next-button.svelte";
+import Ellipsis from "./pagination-ellipsis.svelte";
+
+export {
+ Root,
+ Content,
+ Item,
+ Link,
+ PrevButton,
+ NextButton,
+ Ellipsis,
+ //
+ Root as Pagination,
+ Content as PaginationContent,
+ Item as PaginationItem,
+ Link as PaginationLink,
+ PrevButton as PaginationPrevButton,
+ NextButton as PaginationNextButton,
+ Ellipsis as PaginationEllipsis,
+};
diff --git a/src/lib/components/ui/pagination/pagination-content.svelte b/src/lib/components/ui/pagination/pagination-content.svelte
new file mode 100644
index 000000000..6ba3cd3d7
--- /dev/null
+++ b/src/lib/components/ui/pagination/pagination-content.svelte
@@ -0,0 +1,16 @@
+<script lang="ts">
+ import type { HTMLAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithElementRef<HTMLAttributes<HTMLUListElement>> = $props();
+</script>
+
+<ul bind:this={ref} class={cn("flex flex-row items-center gap-1", className)} {...restProps}>
+ {@render children?.()}
+</ul>
diff --git a/src/lib/components/ui/pagination/pagination-ellipsis.svelte b/src/lib/components/ui/pagination/pagination-ellipsis.svelte
new file mode 100644
index 000000000..e2155e151
--- /dev/null
+++ b/src/lib/components/ui/pagination/pagination-ellipsis.svelte
@@ -0,0 +1,22 @@
+<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}
+ aria-hidden="true"
+ class={cn("flex size-9 items-center justify-center", className)}
+ {...restProps}
+>
+ <Ellipsis class="size-4" />
+ <span class="sr-only">More pages</span>
+</span>
diff --git a/src/lib/components/ui/pagination/pagination-item.svelte b/src/lib/components/ui/pagination/pagination-item.svelte
new file mode 100644
index 000000000..09c10765c
--- /dev/null
+++ b/src/lib/components/ui/pagination/pagination-item.svelte
@@ -0,0 +1,14 @@
+<script lang="ts">
+ import type { HTMLLiAttributes } from "svelte/elements";
+ import type { WithElementRef } from "bits-ui";
+
+ let {
+ ref = $bindable(null),
+ children,
+ ...restProps
+ }: WithElementRef<HTMLLiAttributes> = $props();
+</script>
+
+<li bind:this={ref} {...restProps}>
+ {@render children?.()}
+</li>
diff --git a/src/lib/components/ui/pagination/pagination-link.svelte b/src/lib/components/ui/pagination/pagination-link.svelte
new file mode 100644
index 000000000..4a41b4786
--- /dev/null
+++ b/src/lib/components/ui/pagination/pagination-link.svelte
@@ -0,0 +1,36 @@
+<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";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ size = "icon",
+ isActive = false,
+ page,
+ children,
+ ...restProps
+ }: PaginationPrimitive.PageProps &
+ Props & {
+ isActive: boolean;
+ } = $props();
+</script>
+
+{#snippet Fallback()}
+ {page.value}
+{/snippet}
+
+<PaginationPrimitive.Page
+ 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
new file mode 100644
index 000000000..84eee90a0
--- /dev/null
+++ b/src/lib/components/ui/pagination/pagination-next-button.svelte
@@ -0,0 +1,31 @@
+<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";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: PaginationPrimitive.NextButtonProps = $props();
+</script>
+
+{#snippet Fallback()}
+ <span>Next</span>
+ <ChevronRight class="size-4" />
+{/snippet}
+
+<PaginationPrimitive.NextButton
+ 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
new file mode 100644
index 000000000..2b1a99166
--- /dev/null
+++ b/src/lib/components/ui/pagination/pagination-prev-button.svelte
@@ -0,0 +1,31 @@
+<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";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: PaginationPrimitive.PrevButtonProps = $props();
+</script>
+
+{#snippet Fallback()}
+ <ChevronLeft class="size-4" />
+ <span>Previous</span>
+{/snippet}
+
+<PaginationPrimitive.PrevButton
+ bind:ref
+ class={cn(
+ buttonVariants({
+ variant: "ghost",
+ class: "gap-1 pl-2.5",
+ }),
+ className
+ )}
+ children={children || Fallback}
+ {...restProps}
+/>
diff --git a/src/lib/components/ui/pagination/pagination.svelte b/src/lib/components/ui/pagination/pagination.svelte
new file mode 100644
index 000000000..4cdc9b1cf
--- /dev/null
+++ b/src/lib/components/ui/pagination/pagination.svelte
@@ -0,0 +1,25 @@
+<script lang="ts">
+ import { Pagination as PaginationPrimitive } from "bits-ui";
+
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ count = 0,
+ perPage = 10,
+ page = $bindable(1),
+ siblingCount = 1,
+ ...restProps
+ }: PaginationPrimitive.RootProps = $props();
+</script>
+
+<PaginationPrimitive.Root
+ bind:ref
+ class={cn("mx-auto flex w-full flex-col items-center", className)}
+ {count}
+ {perPage}
+ {siblingCount}
+ bind:page
+ {...restProps}
+/>
diff --git a/src/lib/components/ui/select/index.ts b/src/lib/components/ui/select/index.ts
new file mode 100644
index 000000000..f31b8aed3
--- /dev/null
+++ b/src/lib/components/ui/select/index.ts
@@ -0,0 +1,34 @@
+import { Select as SelectPrimitive } from "bits-ui";
+
+import GroupHeading from "./select-group-heading.svelte";
+import Item from "./select-item.svelte";
+import Content from "./select-content.svelte";
+import Trigger from "./select-trigger.svelte";
+import Separator from "./select-separator.svelte";
+import ScrollDownButton from "./select-scroll-down-button.svelte";
+import ScrollUpButton from "./select-scroll-up-button.svelte";
+
+const Root = SelectPrimitive.Root;
+const Group = SelectPrimitive.Group;
+
+export {
+ Root,
+ Group,
+ GroupHeading,
+ Item,
+ Content,
+ Trigger,
+ Separator,
+ ScrollDownButton,
+ ScrollUpButton,
+ //
+ Root as Select,
+ Group as SelectGroup,
+ GroupHeading as SelectGroupHeading,
+ Item as SelectItem,
+ Content as SelectContent,
+ Trigger as SelectTrigger,
+ Separator as SelectSeparator,
+ ScrollDownButton as SelectScrollDownButton,
+ ScrollUpButton as SelectScrollUpButton,
+};
diff --git a/src/lib/components/ui/select/select-content.svelte b/src/lib/components/ui/select/select-content.svelte
new file mode 100644
index 000000000..56916effe
--- /dev/null
+++ b/src/lib/components/ui/select/select-content.svelte
@@ -0,0 +1,39 @@
+<script lang="ts">
+ import { Select as SelectPrimitive, type WithoutChild } from "bits-ui";
+ import SelectScrollUpButton from "./select-scroll-up-button.svelte";
+ import SelectScrollDownButton from "./select-scroll-down-button.svelte";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ sideOffset = 4,
+ portalProps,
+ children,
+ ...restProps
+ }: WithoutChild<SelectPrimitive.ContentProps> & {
+ portalProps?: SelectPrimitive.PortalProps;
+ } = $props();
+</script>
+
+<SelectPrimitive.Portal {...portalProps}>
+ <SelectPrimitive.Content
+ bind:ref
+ {sideOffset}
+ class={cn(
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 bg-popover text-popover-foreground relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border shadow-md data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
+ className
+ )}
+ {...restProps}
+ >
+ <SelectScrollUpButton />
+ <SelectPrimitive.Viewport
+ class={cn(
+ "h-[var(--bits-select-anchor-height)] w-full min-w-[var(--bits-select-anchor-width)] p-1"
+ )}
+ >
+ {@render children?.()}
+ </SelectPrimitive.Viewport>
+ <SelectScrollDownButton />
+ </SelectPrimitive.Content>
+</SelectPrimitive.Portal>
diff --git a/src/lib/components/ui/select/select-group-heading.svelte b/src/lib/components/ui/select/select-group-heading.svelte
new file mode 100644
index 000000000..7984bef24
--- /dev/null
+++ b/src/lib/components/ui/select/select-group-heading.svelte
@@ -0,0 +1,16 @@
+<script lang="ts">
+ import { Select as SelectPrimitive } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ ...restProps
+ }: SelectPrimitive.GroupHeadingProps = $props();
+</script>
+
+<SelectPrimitive.GroupHeading
+ bind:ref
+ class={cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className)}
+ {...restProps}
+/>
diff --git a/src/lib/components/ui/select/select-item.svelte b/src/lib/components/ui/select/select-item.svelte
new file mode 100644
index 000000000..bc7a93056
--- /dev/null
+++ b/src/lib/components/ui/select/select-item.svelte
@@ -0,0 +1,37 @@
+<script lang="ts">
+ import Check from "@lucide/svelte/icons/check";
+ import { Select as SelectPrimitive, type WithoutChild } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ value,
+ label,
+ children: childrenProp,
+ ...restProps
+ }: WithoutChild<SelectPrimitive.ItemProps> = $props();
+</script>
+
+<SelectPrimitive.Item
+ bind:ref
+ {value}
+ class={cn(
+ "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
+ className
+ )}
+ {...restProps}
+>
+ {#snippet children({ selected, highlighted })}
+ <span class="absolute left-2 flex size-3.5 items-center justify-center">
+ {#if selected}
+ <Check class="size-4" />
+ {/if}
+ </span>
+ {#if childrenProp}
+ {@render childrenProp({ selected, highlighted })}
+ {:else}
+ {label || value}
+ {/if}
+ {/snippet}
+</SelectPrimitive.Item>
diff --git a/src/lib/components/ui/select/select-scroll-down-button.svelte b/src/lib/components/ui/select/select-scroll-down-button.svelte
new file mode 100644
index 000000000..c17d5d1d3
--- /dev/null
+++ b/src/lib/components/ui/select/select-scroll-down-button.svelte
@@ -0,0 +1,19 @@
+<script lang="ts">
+ import ChevronDown from "@lucide/svelte/icons/chevron-down";
+ import { Select as SelectPrimitive, type WithoutChildrenOrChild } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ ...restProps
+ }: WithoutChildrenOrChild<SelectPrimitive.ScrollDownButtonProps> = $props();
+</script>
+
+<SelectPrimitive.ScrollDownButton
+ bind:ref
+ class={cn("flex cursor-default items-center justify-center py-1", className)}
+ {...restProps}
+>
+ <ChevronDown class="size-4" />
+</SelectPrimitive.ScrollDownButton>
diff --git a/src/lib/components/ui/select/select-scroll-up-button.svelte b/src/lib/components/ui/select/select-scroll-up-button.svelte
new file mode 100644
index 000000000..8ba08c088
--- /dev/null
+++ b/src/lib/components/ui/select/select-scroll-up-button.svelte
@@ -0,0 +1,19 @@
+<script lang="ts">
+ import ChevronUp from "@lucide/svelte/icons/chevron-up";
+ import { Select as SelectPrimitive, type WithoutChildrenOrChild } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ ...restProps
+ }: WithoutChildrenOrChild<SelectPrimitive.ScrollUpButtonProps> = $props();
+</script>
+
+<SelectPrimitive.ScrollUpButton
+ bind:ref
+ class={cn("flex cursor-default items-center justify-center py-1", className)}
+ {...restProps}
+>
+ <ChevronUp class="size-4" />
+</SelectPrimitive.ScrollUpButton>
diff --git a/src/lib/components/ui/select/select-separator.svelte b/src/lib/components/ui/select/select-separator.svelte
new file mode 100644
index 000000000..38a3ab0bd
--- /dev/null
+++ b/src/lib/components/ui/select/select-separator.svelte
@@ -0,0 +1,13 @@
+<script lang="ts">
+ import type { Separator as SeparatorPrimitive } from "bits-ui";
+ import { Separator } from "$lib/components/ui/separator/index.js";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ ...restProps
+ }: SeparatorPrimitive.RootProps = $props();
+</script>
+
+<Separator bind:ref class={cn("bg-muted -mx-1 my-1 h-px", className)} {...restProps} />
diff --git a/src/lib/components/ui/select/select-trigger.svelte b/src/lib/components/ui/select/select-trigger.svelte
new file mode 100644
index 000000000..a8c0da2fc
--- /dev/null
+++ b/src/lib/components/ui/select/select-trigger.svelte
@@ -0,0 +1,24 @@
+<script lang="ts">
+ import { Select as SelectPrimitive, type WithoutChild } from "bits-ui";
+ import ChevronDown from "@lucide/svelte/icons/chevron-down";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ children,
+ ...restProps
+ }: WithoutChild<SelectPrimitive.TriggerProps> = $props();
+</script>
+
+<SelectPrimitive.Trigger
+ bind:ref
+ class={cn(
+ "border-input bg-background ring-offset-background data-[placeholder]:text-muted-foreground focus:ring-ring flex h-10 w-full items-center justify-between rounded-md border px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
+ className
+ )}
+ {...restProps}
+>
+ {@render children?.()}
+ <ChevronDown class="size-4 opacity-50" />
+</SelectPrimitive.Trigger>
diff --git a/src/lib/components/ui/separator/index.ts b/src/lib/components/ui/separator/index.ts
new file mode 100644
index 000000000..82442d2cd
--- /dev/null
+++ b/src/lib/components/ui/separator/index.ts
@@ -0,0 +1,7 @@
+import Root from "./separator.svelte";
+
+export {
+ Root,
+ //
+ Root as Separator,
+};
diff --git a/src/lib/components/ui/separator/separator.svelte b/src/lib/components/ui/separator/separator.svelte
new file mode 100644
index 000000000..839494d8b
--- /dev/null
+++ b/src/lib/components/ui/separator/separator.svelte
@@ -0,0 +1,22 @@
+<script lang="ts">
+ import { Separator as SeparatorPrimitive } from "bits-ui";
+ import { cn } from "$lib/utils.js";
+
+ let {
+ ref = $bindable(null),
+ class: className,
+ orientation = "horizontal",
+ ...restProps
+ }: SeparatorPrimitive.RootProps = $props();
+</script>
+
+<SeparatorPrimitive.Root
+ bind:ref
+ class={cn(
+ "bg-border shrink-0",
+ orientation === "horizontal" ? "h-[1px] w-full" : "min-h-full w-[1px]",
+ className
+ )}
+ {orientation}
+ {...restProps}
+/>
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index ac680b303..31dba72fc 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -2,5 +2,22 @@ import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
- return twMerge(clsx(inputs));
+ return twMerge(clsx(inputs));
+}
+
+export function debounced<T extends (...args: any[]) => void>(
+ func: T,
+ delay: number
+) {
+ let debounceTimeout: ReturnType<typeof setTimeout>;
+
+ return (...args: Parameters<T>) => {
+ if (debounceTimeout !== undefined) {
+ clearTimeout(debounceTimeout);
+ }
+
+ debounceTimeout = setTimeout(() => {
+ func(...args);
+ }, delay);
+ };
}
diff --git a/src/routes/images/+page.server.ts b/src/routes/images/+page.server.ts
index db05470f8..c195af72b 100644
--- a/src/routes/images/+page.server.ts
+++ b/src/routes/images/+page.server.ts
@@ -1,31 +1,23 @@
import type { PageServerLoad } from "./$types";
+import { listImages } from "$lib/services/docker-service";
+import type { ServiceImage } from "$lib/services/docker-service";
-// This will be replaced with actual Docker API calls later
-export const load: PageServerLoad = async ({ fetch }) => {
- // Mock data until API is ready
- const images = [
- {
- id: "sha256:abc123",
- repo: "nginx",
- tag: "latest",
- size: "133MB",
- created: "2 days ago",
- },
- {
- id: "sha256:def456",
- repo: "postgres",
- tag: "15",
- size: "350MB",
- created: "1 week ago",
- },
- {
- id: "sha256:ghi789",
- repo: "redis",
- tag: "alpine",
- size: "28MB",
- created: "3 days ago",
- },
- ];
+type ImageData = {
+ images: ServiceImage[];
+ error?: string;
+};
- return { images };
+export const load: PageServerLoad = async (): Promise<ImageData> => {
+ try {
+ const images = await listImages();
+ return {
+ images,
+ };
+ } catch (err: any) {
+ console.error("Failed to load images:", err);
+ return {
+ images: [],
+ error: err.message || "Failed to connect to Docker or list images.",
+ };
+ }
};
diff --git a/src/routes/images/+page.svelte b/src/routes/images/+page.svelte
index be87593ed..83296eb82 100644
--- a/src/routes/images/+page.svelte
+++ b/src/routes/images/+page.svelte
@@ -1,44 +1,41 @@
<script lang="ts">
- import * as Card from "$lib/components/ui/card/index.js";
+ import type { PageData } from "./$types";
+ import DataTable from "$lib/components/data-table.svelte";
+ import { columns } from "./columns"; // Import the column definitions
import { Button } from "$lib/components/ui/button/index.js";
- import { Image, Trash2, Download } from "@lucide/svelte";
- import ImageRow from "$lib/components/docker/ImageRow.svelte";
+ import { Download, AlertCircle } from "@lucide/svelte";
+ import * as Alert from "$lib/components/ui/alert/index.js";
- export let data;
- const { images } = data;
+ let { data }: { data: PageData } = $props();
+ const { images, error } = data;
+
+ function pullImage() {
+ // TODO: Implement pull image modal/logic
+ alert("Implement pull image functionality");
+ }
</script>
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold">Docker Images</h1>
- <Button variant="default">
+ <Button variant="default" onclick={pullImage}>
<Download class="w-4 h-4 mr-2" />
Pull Image
</Button>
</div>
-<Card.Root>
- <Card.Header>
- <Card.Title>Images</Card.Title>
- <Card.Description>Docker images available on this host</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">Repository</th>
- <th class="text-left py-2">Tag</th>
- <th class="text-left py-2">Image ID</th>
- <th class="text-left py-2">Size</th>
- <th class="text-left py-2">Actions</th>
- </tr>
- </thead>
- <tbody>
- {#each images as image}
- <ImageRow {image} />
- {/each}
- </tbody>
- </table>
- </div>
- </Card.Content>
-</Card.Root>
+{#if error}
+ <Alert.Root variant="destructive" class="mb-6">
+ <AlertCircle class="h-4 w-4" />
+ <Alert.Title>Error Loading Images</Alert.Title>
+ <Alert.Description>{error}</Alert.Description>
+ </Alert.Root>
+{/if}
+
+{#if images}
+ <DataTable data={images} {columns} />
+{:else if !error}
+ <!-- Show loading or no data state if needed, DataTable might handle empty state -->
+ <p class="text-center text-muted-foreground">
+ Loading images or no images found.
+ </p>
+{/if}
diff --git a/src/routes/images/ImageActions.svelte b/src/routes/images/ImageActions.svelte
new file mode 100644
index 000000000..0f353d092
--- /dev/null
+++ b/src/routes/images/ImageActions.svelte
@@ -0,0 +1,45 @@
+<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 { Trash2 } from "@lucide/svelte"; // Import Trash icon
+
+ // Accept image ID and potentially other relevant info
+ let { id, repoTag }: { id: string; repoTag?: string } = $props();
+
+ function removeImage() {
+ // TODO: Implement API call to remove image
+ console.log("Attempting to remove image:", id, repoTag);
+ alert(`Implement remove action for image ID: ${id.substring(0, 12)}`);
+ }
+</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.Label>Actions</DropdownMenu.Label>
+ <DropdownMenu.Separator />
+ <DropdownMenu.Item
+ onclick={removeImage}
+ class="text-destructive focus:text-destructive"
+ >
+ <Trash2 class="mr-2 h-4 w-4" />
+ Remove Image
+ </DropdownMenu.Item>
+ <!-- Add other actions if needed -->
+ </DropdownMenu.Group>
+ </DropdownMenu.Content>
+</DropdownMenu.Root>
diff --git a/src/routes/images/columns.ts b/src/routes/images/columns.ts
new file mode 100644
index 000000000..7fa534627
--- /dev/null
+++ b/src/routes/images/columns.ts
@@ -0,0 +1,68 @@
+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";
+
+// Helper to format bytes (keep as is)
+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]}`;
+}
+
+export const columns: ColumnDef<ServiceImage>[] = [
+ {
+ accessorKey: "repo",
+ header: "Repository",
+ cell: ({ row }) => {
+ // Return the plain repository name string
+ return row.original.repo;
+ // Note: Styling for '<none>' will be lost without a component
+ },
+ },
+ {
+ accessorKey: "tag",
+ header: "Tag",
+ cell: ({ row }) => {
+ // Return the plain tag string
+ return row.original.tag;
+ // Note: Styling for '<none>' will be lost without a component
+ },
+ },
+ {
+ accessorKey: "id",
+ header: "Image ID",
+ cell: ({ row }) => {
+ // Calculate and return the short ID string
+ const shortId =
+ row.original.id.split(":")[1]?.substring(0, 12) ||
+ row.original.id.substring(0, 12);
+ return shortId;
+ // Note: Monospace font styling will be lost without a component
+ },
+ enableSorting: false,
+ },
+ {
+ accessorKey: "size",
+ header: "Size",
+ cell: ({ row }) => {
+ // formatBytes already returns a string
+ return formatBytes(row.original.size);
+ },
+ },
+ {
+ id: "actions",
+ header: "Actions",
+ cell: ({ row }) => {
+ // Keep using renderComponent for the actions dropdown
+ return renderComponent(ImageActions, {
+ id: row.original.id,
+ repoTag: row.original.repoTags?.[0],
+ });
+ },
+ enableSorting: false,
+ },
+];