Skip to content

Commit ee802cd

Browse files
gentslavaclaude
andcommitted
feat(domains): add enable/disable toggle for domains
Add an `enabled` flag (default true) so a domain can be switched off without deleting it, preserving its configuration. - schema: new `enabled` column + migration; added to apiUpdateDomain - traefik (applications): guard manageDomain so a disabled domain never exposes a router from any caller (create/update/forward-auth/toggle); applies instantly through the file provider - compose: skip disabled domains when generating docker labels, so the change applies on the next deployment - tRPC: new domain.toggleEnable procedure (permission-checked + audited), returns requiresRedeploy for compose domains - UI: switch on the domain card (host row, variant E) and a Status column in the table view; disabled cards are dimmed; reuses the compose redeploy hint for the toast Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 898af1f commit ee802cd

9 files changed

Lines changed: 8725 additions & 11 deletions

File tree

‎apps/dokploy/components/dashboard/application/domains/columns.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Link from "next/link";
1414
import { DialogAction } from "@/components/shared/dialog-action";
1515
import { Badge } from "@/components/ui/badge";
1616
import { Button } from "@/components/ui/button";
17+
import { Switch } from "@/components/ui/switch";
1718
import {
1819
Tooltip,
1920
TooltipContent,
@@ -35,7 +36,9 @@ interface ColumnsProps {
3536
validationStates: ValidationStates;
3637
handleValidateDomain: (host: string) => Promise<void>;
3738
handleDeleteDomain: (domainId: string) => Promise<void>;
39+
handleToggleEnable: (domainId: string) => Promise<void>;
3840
isDeleting: boolean;
41+
isToggling: boolean;
3942
serverIp?: string;
4043
canCreateDomain: boolean;
4144
canDeleteDomain: boolean;
@@ -47,7 +50,9 @@ export const createColumns = ({
4750
validationStates,
4851
handleValidateDomain,
4952
handleDeleteDomain,
53+
handleToggleEnable,
5054
isDeleting,
55+
isToggling,
5156
serverIp,
5257
canCreateDomain,
5358
canDeleteDomain,
@@ -247,6 +252,32 @@ export const createColumns = ({
247252
);
248253
},
249254
},
255+
{
256+
id: "status",
257+
header: "Status",
258+
cell: ({ row }) => {
259+
const domain = row.original;
260+
if (!canCreateDomain) {
261+
return (
262+
<Badge variant={domain.enabled ? "outline" : "secondary"}>
263+
{domain.enabled ? "Enabled" : "Disabled"}
264+
</Badge>
265+
);
266+
}
267+
return (
268+
<div className="flex items-center gap-2">
269+
<Switch
270+
checked={domain.enabled}
271+
onCheckedChange={() => handleToggleEnable(domain.domainId)}
272+
disabled={isToggling}
273+
/>
274+
<span className="text-sm text-muted-foreground">
275+
{domain.enabled ? "Enabled" : "Disabled"}
276+
</span>
277+
</div>
278+
);
279+
},
280+
},
250281
{
251282
id: "actions",
252283
header: "Actions",

‎apps/dokploy/components/dashboard/application/domains/show-domains.tsx‎

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
DropdownMenuTrigger,
4545
} from "@/components/ui/dropdown-menu";
4646
import { Input } from "@/components/ui/input";
47+
import { Switch } from "@/components/ui/switch";
4748
import {
4849
Table,
4950
TableBody,
@@ -58,6 +59,7 @@ import {
5859
TooltipProvider,
5960
TooltipTrigger,
6061
} from "@/components/ui/tooltip";
62+
import { cn } from "@/lib/utils";
6163
import { api } from "@/utils/api";
6264
import { createColumns } from "./columns";
6365
import { DnsHelperModal } from "./dns-helper-modal";
@@ -147,6 +149,23 @@ export const ShowDomains = ({ id, type }: Props) => {
147149
api.domain.validateDomain.useMutation();
148150
const { mutateAsync: deleteDomain, isPending: isRemoving } =
149151
api.domain.delete.useMutation();
152+
const { mutateAsync: toggleEnable, isPending: isToggling } =
153+
api.domain.toggleEnable.useMutation();
154+
155+
const handleToggleEnable = async (domainId: string) => {
156+
try {
157+
const result = await toggleEnable({ domainId });
158+
refetch();
159+
toast.success(
160+
result.enabled ? "Domain enabled" : "Domain disabled",
161+
result.requiresRedeploy
162+
? { description: COMPOSE_REDEPLOY_TOAST }
163+
: undefined,
164+
);
165+
} catch {
166+
toast.error("Error updating the domain");
167+
}
168+
};
150169

151170
const handleDeleteDomain = async (domainId: string) => {
152171
try {
@@ -206,7 +225,9 @@ export const ShowDomains = ({ id, type }: Props) => {
206225
validationStates,
207226
handleValidateDomain,
208227
handleDeleteDomain,
228+
handleToggleEnable,
209229
isDeleting: isRemoving,
230+
isToggling,
210231
serverIp: application?.server?.ipAddress?.toString() || ip?.toString(),
211232
canCreateDomain,
212233
canDeleteDomain,
@@ -424,7 +445,10 @@ export const ShowDomains = ({ id, type }: Props) => {
424445
return (
425446
<Card
426447
key={item.domainId}
427-
className="relative overflow-hidden w-full border transition-all hover:shadow-md bg-transparent h-fit"
448+
className={cn(
449+
"relative overflow-hidden w-full border transition-all hover:shadow-md bg-transparent h-fit",
450+
!item.enabled && "opacity-60",
451+
)}
428452
>
429453
<CardContent className="p-6">
430454
<div className="flex flex-col gap-4">
@@ -492,15 +516,44 @@ export const ShowDomains = ({ id, type }: Props) => {
492516
)}
493517
</div>
494518
</div>
495-
<div className="w-full break-all">
496-
<Link
497-
className="flex items-center gap-2 text-base font-medium hover:underline"
498-
target="_blank"
499-
href={`${item.https ? "https" : "http"}://${item.host}${item.path}`}
500-
>
501-
{item.host}
502-
<ExternalLink className="size-4 min-w-4" />
503-
</Link>
519+
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
520+
<div className="w-full break-all">
521+
<Link
522+
className="flex items-center gap-2 text-base font-medium hover:underline"
523+
target="_blank"
524+
href={`${item.https ? "https" : "http"}://${item.host}${item.path}`}
525+
>
526+
{item.host}
527+
<ExternalLink className="size-4 min-w-4" />
528+
</Link>
529+
</div>
530+
{canCreateDomain && (
531+
<TooltipProvider>
532+
<Tooltip>
533+
<TooltipTrigger asChild>
534+
<div className="flex items-center gap-2 shrink-0">
535+
<Switch
536+
checked={item.enabled}
537+
onCheckedChange={() =>
538+
handleToggleEnable(item.domainId)
539+
}
540+
disabled={isToggling}
541+
/>
542+
<span className="text-sm text-muted-foreground">
543+
{item.enabled ? "Enabled" : "Disabled"}
544+
</span>
545+
</div>
546+
</TooltipTrigger>
547+
<TooltipContent>
548+
<p>
549+
{item.enabled
550+
? "Domain is active. Toggle to disable routing without deleting it."
551+
: "Domain is disabled and not routed. Toggle to enable it again."}
552+
</p>
553+
</TooltipContent>
554+
</Tooltip>
555+
</TooltipProvider>
556+
)}
504557
</div>
505558

506559
{/* Domain Details */}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "domain" ADD COLUMN "enabled" boolean DEFAULT true NOT NULL;

0 commit comments

Comments
 (0)