refactor(networks): enhance network display and management interface

- Updated the ShowNetworks component to improve the layout and user experience.
- Introduced a new Pencil icon for editing networks and added a Badge component for displaying network drivers.
- Refactored loading and empty state handling for better visual feedback.
- Modified the API query to include server details for each network, enhancing the data returned for better context.
This commit is contained in:
Mauricio Siu
2026-07-21 19:10:51 -06:00
parent 99e483c1a1
commit f4bcc2e8a8
2 changed files with 105 additions and 86 deletions
@@ -1,10 +1,12 @@
"use client"; "use client";
import { Loader2, Network } from "lucide-react"; import { Loader2, Network, Pencil } from "lucide-react";
import { HandleNetwork } from "@/components/dashboard/networks/handle-network"; import { HandleNetwork } from "@/components/dashboard/networks/handle-network";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { import {
Card, Card,
CardAction,
CardContent, CardContent,
CardDescription, CardDescription,
CardHeader, CardHeader,
@@ -27,7 +29,6 @@ export const ShowNetworks = () => {
<div className="w-full"> <div className="w-full">
<Card className="h-full bg-sidebar p-2.5 rounded-xl"> <Card className="h-full bg-sidebar p-2.5 rounded-xl">
<div className="rounded-xl bg-background shadow-md "> <div className="rounded-xl bg-background shadow-md ">
<div className="flex flex-row justify-between items-center">
<CardHeader className=""> <CardHeader className="">
<CardTitle className="text-xl flex flex-row gap-2"> <CardTitle className="text-xl flex flex-row gap-2">
<Network className="size-6 text-muted-foreground self-center" /> <Network className="size-6 text-muted-foreground self-center" />
@@ -37,35 +38,36 @@ export const ShowNetworks = () => {
Manage Docker networks for your organization. Networks can be Manage Docker networks for your organization. Networks can be
scoped to a server (optional). scoped to a server (optional).
</CardDescription> </CardDescription>
{networks && networks.length > 0 && (
<CardAction className="self-center">
<HandleNetwork />
</CardAction>
)}
</CardHeader> </CardHeader>
{networks && networks?.length > 0 && <HandleNetwork />}
</div>
<CardContent className="space-y-2 py-8 border-t"> <CardContent className="space-y-2 py-8 border-t">
<div className="gap-4 pb-20 w-full">
<div className="flex flex-col gap-4 w-full overflow-auto">
<div className="rounded-md border">
{isLoading ? ( {isLoading ? (
<div className="flex flex-row gap-2 items-center justify-center text-sm text-muted-foreground h-[55vh]"> <div className="flex flex-row gap-2 items-center justify-center text-sm text-muted-foreground min-h-[45vh]">
<span>Loading...</span> <span>Loading...</span>
<Loader2 className="animate-spin size-4" /> <Loader2 className="animate-spin size-4" />
</div> </div>
) : !networks?.length ? ( ) : !networks?.length ? (
<div className="flex min-h-[55vh] w-full flex-col items-center justify-center gap-4 rounded-lg border border-dashed p-8"> <div className="flex min-h-[45vh] w-full flex-col items-center justify-center gap-4 rounded-lg border border-dashed p-8">
<div className="rounded-full bg-muted p-4"> <div className="rounded-full bg-muted p-4">
<Network className="size-10 text-muted-foreground" /> <Network className="size-10 text-muted-foreground" />
</div> </div>
<div className="space-y-1 text-center"> <div className="space-y-1 text-center">
<p className="text-sm font-medium">No networks yet</p> <p className="text-sm font-medium">No networks yet</p>
<p className="max-w-sm text-sm text-muted-foreground"> <p className="max-w-sm text-sm text-muted-foreground">
Create Docker networks for your organization and Create Docker networks for your organization and optionally
optionally attach them to a server. Add your first attach them to a server. Add your first network to get
network to get started. started.
</p> </p>
</div> </div>
<HandleNetwork /> <HandleNetwork />
</div> </div>
) : ( ) : (
<div className="rounded-md border overflow-x-auto">
<Table> <Table>
<TableHeader> <TableHeader>
<TableRow> <TableRow>
@@ -76,29 +78,41 @@ export const ShowNetworks = () => {
<TableHead>Attachable</TableHead> <TableHead>Attachable</TableHead>
<TableHead>Server</TableHead> <TableHead>Server</TableHead>
<TableHead>Created</TableHead> <TableHead>Created</TableHead>
<TableHead className="w-[80px]">Actions</TableHead> <TableHead className="w-[80px] text-right">
Actions
</TableHead>
</TableRow> </TableRow>
</TableHeader> </TableHeader>
<TableBody> <TableBody>
{networks.map((n) => ( {networks.map((n) => (
<TableRow key={n.networkId}> <TableRow key={n.networkId}>
<TableCell className="font-medium"> <TableCell className="font-medium">{n.name}</TableCell>
{n.name}
</TableCell>
<TableCell>{n.driver}</TableCell>
<TableCell>{n.scope ?? "—"}</TableCell>
<TableCell>{n.internal ? "Yes" : "No"}</TableCell>
<TableCell>{n.attachable ? "Yes" : "No"}</TableCell>
<TableCell> <TableCell>
{n.serverId ?? "Dokploy server"} <Badge variant="outline">{n.driver}</Badge>
</TableCell>
<TableCell className="text-muted-foreground">
{n.scope ?? "—"}
</TableCell>
<TableCell className="text-muted-foreground">
{n.internal ? "Yes" : "No"}
</TableCell>
<TableCell className="text-muted-foreground">
{n.attachable ? "Yes" : "No"}
</TableCell>
<TableCell>
{n.server?.name ?? "Dokploy Server"}
</TableCell> </TableCell>
<TableCell className="text-muted-foreground"> <TableCell className="text-muted-foreground">
{new Date(n.createdAt).toLocaleDateString()} {new Date(n.createdAt).toLocaleDateString()}
</TableCell> </TableCell>
<TableCell> <TableCell className="text-right">
<HandleNetwork networkId={n.networkId}> <HandleNetwork networkId={n.networkId}>
<Button variant="ghost" size="sm"> <Button
Edit variant="ghost"
size="icon-xs"
aria-label="Edit network"
>
<Pencil className="size-4" />
</Button> </Button>
</HandleNetwork> </HandleNetwork>
</TableCell> </TableCell>
@@ -106,10 +120,8 @@ export const ShowNetworks = () => {
))} ))}
</TableBody> </TableBody>
</Table> </Table>
</div>
)} )}
</div>
</div>
</div>
</CardContent> </CardContent>
</div> </div>
</Card> </Card>
+12 -5
View File
@@ -18,11 +18,18 @@ import {
export const networkRouter = createTRPCRouter({ export const networkRouter = createTRPCRouter({
all: protectedProcedure.query(async ({ ctx }) => { all: protectedProcedure.query(async ({ ctx }) => {
const rows = await db const rows = await db.query.network.findMany({
.select() where: eq(networkTable.organizationId, ctx.session.activeOrganizationId),
.from(networkTable) with: {
.where(eq(networkTable.organizationId, ctx.session.activeOrganizationId)) server: {
.orderBy(desc(networkTable.createdAt)); columns: {
serverId: true,
name: true,
},
},
},
orderBy: desc(networkTable.createdAt),
});
return rows; return rows;
}), }),