Skip to content

Commit 1c44141

Browse files
committed
feat: enhance container dashboard with new features
- Added a "Ports" column to display container port information with sorting functionality. - Implemented a dropdown menu item to copy the Container ID to the clipboard with a success toast notification. - Introduced a state filter dropdown to filter containers by their current state, with options for all defined states. - Added a refresh button to allow manual refreshing of the container list.
1 parent 93b7942 commit 1c44141

2 files changed

Lines changed: 102 additions & 9 deletions

File tree

‎apps/dokploy/components/dashboard/docker/show/columns.tsx‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import type { ColumnDef } from "@tanstack/react-table";
2+
import copy from "copy-to-clipboard";
23
import { ArrowUpDown, MoreHorizontal } from "lucide-react";
4+
import { toast } from "sonner";
35
import { Badge } from "@/components/ui/badge";
46
import { Button } from "@/components/ui/button";
57
import {
68
DropdownMenu,
79
DropdownMenuContent,
10+
DropdownMenuItem,
811
DropdownMenuLabel,
912
DropdownMenuTrigger,
1013
} from "@/components/ui/dropdown-menu";
@@ -37,6 +40,7 @@ export const columns: ColumnDef<Container>[] = [
3740
},
3841
{
3942
accessorKey: "state",
43+
filterFn: "equals",
4044
header: ({ column }) => {
4145
return (
4246
<Button
@@ -56,7 +60,7 @@ export const columns: ColumnDef<Container>[] = [
5660
variant={
5761
value === "running"
5862
? "default"
59-
: value === "failed"
63+
: value === "exited" || value === "dead"
6064
? "destructive"
6165
: "secondary"
6266
}
@@ -99,6 +103,28 @@ export const columns: ColumnDef<Container>[] = [
99103
},
100104
cell: ({ row }) => <div className="lowercase">{row.getValue("image")}</div>,
101105
},
106+
{
107+
accessorKey: "ports",
108+
header: ({ column }) => {
109+
return (
110+
<Button
111+
variant="ghost"
112+
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
113+
>
114+
Ports
115+
<ArrowUpDown className="ml-2 h-4 w-4" />
116+
</Button>
117+
);
118+
},
119+
cell: ({ row }) => {
120+
const value = row.getValue("ports") as string;
121+
return (
122+
<div className="max-w-[16rem] truncate lowercase" title={value}>
123+
{value}
124+
</div>
125+
);
126+
},
127+
},
102128
{
103129
id: "actions",
104130
enableHiding: false,
@@ -115,6 +141,14 @@ export const columns: ColumnDef<Container>[] = [
115141
</DropdownMenuTrigger>
116142
<DropdownMenuContent align="end">
117143
<DropdownMenuLabel>Actions</DropdownMenuLabel>
144+
<DropdownMenuItem
145+
onClick={() => {
146+
copy(container.containerId);
147+
toast.success("Container ID copied to clipboard");
148+
}}
149+
>
150+
Copy Container ID
151+
</DropdownMenuItem>
118152
<ShowDockerModalLogs
119153
containerId={container.containerId}
120154
serverId={container.serverId}

‎apps/dokploy/components/dashboard/docker/show/show-containers.tsx‎

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
useReactTable,
1010
type VisibilityState,
1111
} from "@tanstack/react-table";
12-
import { ChevronDown, Container } from "lucide-react";
12+
import { ChevronDown, Container, RefreshCw } from "lucide-react";
1313
import * as React from "react";
1414
import { Button } from "@/components/ui/button";
1515
import {
@@ -26,6 +26,13 @@ import {
2626
DropdownMenuTrigger,
2727
} from "@/components/ui/dropdown-menu";
2828
import { Input } from "@/components/ui/input";
29+
import {
30+
Select,
31+
SelectContent,
32+
SelectItem,
33+
SelectTrigger,
34+
SelectValue,
35+
} from "@/components/ui/select";
2936
import {
3037
Table,
3138
TableBody,
@@ -44,10 +51,26 @@ interface Props {
4451
serverId?: string;
4552
}
4653

54+
const CONTAINER_STATES = [
55+
"running",
56+
"exited",
57+
"paused",
58+
"restarting",
59+
"created",
60+
"removing",
61+
"dead",
62+
];
63+
4764
export const ShowContainers = ({ serverId }: Props) => {
48-
const { data, isPending } = api.docker.getContainers.useQuery({
49-
serverId,
50-
});
65+
const { data, isPending, refetch, isRefetching } =
66+
api.docker.getContainers.useQuery(
67+
{
68+
serverId,
69+
},
70+
{
71+
refetchInterval: 10_000,
72+
},
73+
);
5174

5275
const [sorting, setSorting] = React.useState<SortingState>([]);
5376
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
@@ -106,12 +129,48 @@ export const ShowContainers = ({ serverId }: Props) => {
106129
}
107130
className="md:max-w-sm"
108131
/>
132+
<Select
133+
value={
134+
(table.getColumn("state")?.getFilterValue() as string) ??
135+
"all"
136+
}
137+
onValueChange={(value) =>
138+
table
139+
.getColumn("state")
140+
?.setFilterValue(value === "all" ? undefined : value)
141+
}
142+
>
143+
<SelectTrigger className="w-40 max-sm:w-full capitalize">
144+
<SelectValue placeholder="Filter by state" />
145+
</SelectTrigger>
146+
<SelectContent>
147+
<SelectItem value="all">All states</SelectItem>
148+
{CONTAINER_STATES.map((state) => (
149+
<SelectItem
150+
key={state}
151+
value={state}
152+
className="capitalize"
153+
>
154+
{state}
155+
</SelectItem>
156+
))}
157+
</SelectContent>
158+
</Select>
159+
<Button
160+
variant="outline"
161+
size="icon"
162+
className="shrink-0 sm:ml-auto"
163+
onClick={() => refetch()}
164+
disabled={isRefetching}
165+
>
166+
<RefreshCw
167+
className={`h-4 w-4 ${isRefetching ? "animate-spin" : ""}`}
168+
/>
169+
<span className="sr-only">Refresh</span>
170+
</Button>
109171
<DropdownMenu>
110172
<DropdownMenuTrigger asChild>
111-
<Button
112-
variant="outline"
113-
className="sm:ml-auto max-sm:w-full"
114-
>
173+
<Button variant="outline" className="max-sm:w-full">
115174
Columns <ChevronDown className="ml-2 h-4 w-4" />
116175
</Button>
117176
</DropdownMenuTrigger>

0 commit comments

Comments
 (0)