feat(domains): enhance domain table with service name and entrypoint columns, and implement view mode persistence in local storage

This commit is contained in:
Mauricio Siu
2026-04-03 20:47:44 -06:00
parent c5f804421c
commit 96d1abb4b6
2 changed files with 107 additions and 56 deletions
@@ -6,6 +6,7 @@ import {
Loader2, Loader2,
PenBoxIcon, PenBoxIcon,
RefreshCw, RefreshCw,
Server,
Trash2, Trash2,
XCircle, XCircle,
} from "lucide-react"; } from "lucide-react";
@@ -36,6 +37,8 @@ interface ColumnsProps {
handleDeleteDomain: (domainId: string) => Promise<void>; handleDeleteDomain: (domainId: string) => Promise<void>;
isDeleting: boolean; isDeleting: boolean;
serverIp?: string; serverIp?: string;
canCreateDomain: boolean;
canDeleteDomain: boolean;
} }
export const createColumns = ({ export const createColumns = ({
@@ -46,7 +49,27 @@ export const createColumns = ({
handleDeleteDomain, handleDeleteDomain,
isDeleting, isDeleting,
serverIp, serverIp,
canCreateDomain,
canDeleteDomain,
}: ColumnsProps): ColumnDef<Domain>[] => [ }: ColumnsProps): ColumnDef<Domain>[] => [
...(type === "compose"
? [
{
accessorKey: "serviceName",
header: "Service",
cell: ({ row }: { row: { getValue: (key: string) => unknown } }) => {
const serviceName = row.getValue("serviceName") as string | null;
if (!serviceName) return null;
return (
<Badge variant="outline">
<Server className="size-3 mr-1" />
{serviceName}
</Badge>
);
},
} satisfies ColumnDef<Domain>,
]
: []),
{ {
accessorKey: "host", accessorKey: "host",
header: ({ column }) => { header: ({ column }) => {
@@ -63,19 +86,14 @@ export const createColumns = ({
cell: ({ row }) => { cell: ({ row }) => {
const domain = row.original; const domain = row.original;
return ( return (
<AddDomain id={id} type={type} domainId={domain.domainId}> <Link
<Button variant="link" className="p-0 h-auto font-medium"> className="flex items-center gap-2 font-medium hover:underline"
<Link target="_blank"
className="flex items-center gap-2 hover:underline" href={`${domain.https ? "https" : "http"}://${domain.host}${domain.path}`}
target="_blank" >
href={`${domain.https ? "https" : "http"}://${domain.host}${domain.path}`} {domain.host}
onClick={(e) => e.stopPropagation()} <ExternalLink className="size-3" />
> </Link>
{domain.host}
<ExternalLink className="size-3" />
</Link>
</Button>
</AddDomain>
); );
}, },
}, },
@@ -115,26 +133,24 @@ export const createColumns = ({
return <Badge variant="secondary">{port}</Badge>; return <Badge variant="secondary">{port}</Badge>;
}, },
}, },
{
accessorKey: "customEntrypoint",
header: "Entrypoint",
cell: ({ row }) => {
const entrypoint = row.getValue("customEntrypoint") as string | null;
if (!entrypoint) return <span className="text-muted-foreground">-</span>;
return <div className="font-mono text-sm">{entrypoint}</div>;
},
},
{ {
accessorKey: "https", accessorKey: "https",
header: "Protocol", header: "Protocol",
cell: ({ row }) => { cell: ({ row }) => {
const https = row.getValue("https") as boolean; const https = row.getValue("https") as boolean;
return ( return (
<TooltipProvider> <Badge variant={https ? "outline" : "secondary"}>
<Tooltip> {https ? "HTTPS" : "HTTP"}
<TooltipTrigger asChild> </Badge>
<Badge variant={https ? "outline" : "secondary"}>
{https ? "HTTPS" : "HTTP"}
</Badge>
</TooltipTrigger>
<TooltipContent>
<p>
{https ? "Secure HTTPS connection" : "Standard HTTP connection"}
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
); );
}, },
}, },
@@ -209,6 +225,28 @@ export const createColumns = ({
); );
}, },
}, },
{
accessorKey: "createdAt",
header: ({ column }) => {
return (
<Button
variant="ghost"
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
>
Created
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
);
},
cell: ({ row }) => {
const createdAt = row.getValue("createdAt") as string;
return (
<div className="text-sm text-muted-foreground">
{new Date(createdAt).toLocaleDateString()}
</div>
);
},
},
{ {
id: "actions", id: "actions",
header: "Actions", header: "Actions",
@@ -228,32 +266,36 @@ export const createColumns = ({
serverIp={serverIp} serverIp={serverIp}
/> />
)} )}
<AddDomain id={id} type={type} domainId={domain.domainId}> {canCreateDomain && (
<Button <AddDomain id={id} type={type} domainId={domain.domainId}>
variant="ghost" <Button
size="icon" variant="ghost"
className="group hover:bg-blue-500/10 h-8 w-8" size="icon"
className="group hover:bg-blue-500/10 h-8 w-8"
>
<PenBoxIcon className="size-3.5 text-primary group-hover:text-blue-500" />
</Button>
</AddDomain>
)}
{canDeleteDomain && (
<DialogAction
title="Delete Domain"
description="Are you sure you want to delete this domain?"
type="destructive"
onClick={async () => {
await handleDeleteDomain(domain.domainId);
}}
> >
<PenBoxIcon className="size-3.5 text-primary group-hover:text-blue-500" /> <Button
</Button> variant="ghost"
</AddDomain> size="icon"
<DialogAction className="group hover:bg-red-500/10 h-8 w-8"
title="Delete Domain" isLoading={isDeleting}
description="Are you sure you want to delete this domain?" >
type="destructive" <Trash2 className="size-4 text-primary group-hover:text-red-500" />
onClick={async () => { </Button>
await handleDeleteDomain(domain.domainId); </DialogAction>
}} )}
>
<Button
variant="ghost"
size="icon"
className="group hover:bg-red-500/10 h-8 w-8"
isLoading={isDeleting}
>
<Trash2 className="size-4 text-primary group-hover:text-red-500" />
</Button>
</DialogAction>
</div> </div>
); );
}, },
@@ -104,7 +104,12 @@ export const ShowDomains = ({ id, type }: Props) => {
const [validationStates, setValidationStates] = useState<ValidationStates>( const [validationStates, setValidationStates] = useState<ValidationStates>(
{}, {},
); );
const [viewMode, setViewMode] = useState<"grid" | "table">("grid"); const [viewMode, setViewMode] = useState<"grid" | "table">(() => {
if (typeof window !== "undefined") {
return (localStorage.getItem("domains-view-mode") as "grid" | "table") ?? "grid";
}
return "grid";
});
const [sorting, setSorting] = useState<SortingState>([]); const [sorting, setSorting] = useState<SortingState>([]);
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]); const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({}); const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
@@ -193,6 +198,8 @@ export const ShowDomains = ({ id, type }: Props) => {
handleDeleteDomain, handleDeleteDomain,
isDeleting: isRemoving, isDeleting: isRemoving,
serverIp: application?.server?.ipAddress?.toString() || ip?.toString(), serverIp: application?.server?.ipAddress?.toString() || ip?.toString(),
canCreateDomain,
canDeleteDomain,
}); });
const table = useReactTable({ const table = useReactTable({
@@ -231,9 +238,11 @@ export const ShowDomains = ({ id, type }: Props) => {
<Button <Button
variant="outline" variant="outline"
size="icon" size="icon"
onClick={() => onClick={() => {
setViewMode(viewMode === "grid" ? "table" : "grid") const next = viewMode === "grid" ? "table" : "grid";
} localStorage.setItem("domains-view-mode", next);
setViewMode(next);
}}
> >
{viewMode === "grid" ? ( {viewMode === "grid" ? (
<LayoutList className="size-4" /> <LayoutList className="size-4" />