feat: implement clone host functionality

This commit is contained in:
ZacharyZcR
2026-05-13 16:19:59 +08:00
committed by ZacharyZcR
parent ebed4a6d2e
commit 6a98e3db7a
+42 -3
View File
@@ -336,6 +336,7 @@ function HostRow({
onToggleSelect, onToggleSelect,
onEdit, onEdit,
onDelete, onDelete,
onClone,
onDragStart, onDragStart,
onDragEnd, onDragEnd,
depth = 0, depth = 0,
@@ -349,6 +350,7 @@ function HostRow({
onToggleSelect: () => void; onToggleSelect: () => void;
onEdit: () => void; onEdit: () => void;
onDelete: () => void; onDelete: () => void;
onClone: () => void;
onDragStart?: () => void; onDragStart?: () => void;
onDragEnd?: () => void; onDragEnd?: () => void;
depth?: number; depth?: number;
@@ -649,9 +651,7 @@ function HostRow({
</button> </button>
</DropdownMenuTrigger> </DropdownMenuTrigger>
<DropdownMenuContent align="end" className="text-xs"> <DropdownMenuContent align="end" className="text-xs">
<DropdownMenuItem <DropdownMenuItem onClick={() => onClone()}>
onClick={() => toast.success(t("hosts.hostCloned"))}
>
<Copy className="size-3.5 mr-2" /> <Copy className="size-3.5 mr-2" />
{t("hosts.cloneHostAction")} {t("hosts.cloneHostAction")}
</DropdownMenuItem> </DropdownMenuItem>
@@ -5442,6 +5442,19 @@ export function HostManager({
}, },
}); });
}} }}
onClone={async () => {
try {
const cloned = await createSSHHost({
...host,
name: `${host.name || host.ip} (Copy)`,
pin: false,
} as any);
setHosts((prev) => [...prev, cloned]);
toast.success(`Cloned ${host.name}`);
} catch {
toast.error("Failed to clone host");
}
}}
onDragStart={() => setDraggedHost(host)} onDragStart={() => setDraggedHost(host)}
onDragEnd={() => setDraggedHost(null)} onDragEnd={() => setDraggedHost(null)}
/> />
@@ -5892,6 +5905,19 @@ export function HostManager({
}, },
}); });
}} }}
onClone={async () => {
try {
const cloned = await createSSHHost({
...host,
name: `${host.name || host.ip} (Copy)`,
pin: false,
} as any);
setHosts((prev) => [...prev, cloned]);
toast.success(`Cloned ${host.name}`);
} catch {
toast.error("Failed to clone host");
}
}}
/> />
))} ))}
</div> </div>
@@ -5943,6 +5969,19 @@ export function HostManager({
}, },
}); });
}} }}
onClone={async () => {
try {
const cloned = await createSSHHost({
...host,
name: `${host.name || host.ip} (Copy)`,
pin: false,
} as any);
setHosts((prev) => [...prev, cloned]);
toast.success(`Cloned ${host.name}`);
} catch {
toast.error("Failed to clone host");
}
}}
onDragStart={() => setDraggedHost(host)} onDragStart={() => setDraggedHost(host)}
onDragEnd={() => setDraggedHost(null)} onDragEnd={() => setDraggedHost(null)}
/> />