diff --git a/components/SyncStatusButton.tsx b/components/SyncStatusButton.tsx index 0fb5b217c..365ac070e 100644 --- a/components/SyncStatusButton.tsx +++ b/components/SyncStatusButton.tsx @@ -170,7 +170,7 @@ export const SyncStatusButton: React.FC = ({ diff --git a/components/VaultView.tsx b/components/VaultView.tsx index 41121dcae..4799723c6 100644 --- a/components/VaultView.tsx +++ b/components/VaultView.tsx @@ -139,6 +139,10 @@ const VaultViewInner: React.FC = ({ const [isNewFolderOpen, setIsNewFolderOpen] = useState(false); const [newFolderName, setNewFolderName] = useState(""); const [targetParentPath, setTargetParentPath] = useState(null); + const [isRenameGroupOpen, setIsRenameGroupOpen] = useState(false); + const [renameTargetPath, setRenameTargetPath] = useState(null); + const [renameGroupName, setRenameGroupName] = useState(""); + const [renameGroupError, setRenameGroupError] = useState(null); // Handle external navigation requests useEffect(() => { @@ -471,6 +475,58 @@ const VaultViewInner: React.FC = ({ setIsNewFolderOpen(false); }; + const submitRenameGroup = () => { + if (!renameTargetPath) return; + + const nextName = renameGroupName.trim(); + if (!nextName) { + setRenameGroupError("Group name is required."); + return; + } + if (nextName.includes("/") || nextName.includes("\\")) { + setRenameGroupError("Group name cannot include '/' or '\\'."); + return; + } + + const segments = renameTargetPath.split("/").filter(Boolean); + const parent = segments.slice(0, -1).join("/"); + const nextPath = parent ? `${parent}/${nextName}` : nextName; + if (nextPath === renameTargetPath) { + setIsRenameGroupOpen(false); + return; + } + + const updatedGroups = customGroups.map((g) => { + if (g === renameTargetPath) return nextPath; + if (g.startsWith(renameTargetPath + "/")) + return nextPath + g.slice(renameTargetPath.length); + return g; + }); + const updatedHosts = hosts.map((h) => { + const g = h.group || ""; + if (g === renameTargetPath) return { ...h, group: nextPath }; + if (g.startsWith(renameTargetPath + "/")) + return { ...h, group: nextPath + g.slice(renameTargetPath.length) }; + return h; + }); + + onUpdateCustomGroups(Array.from(new Set(updatedGroups))); + onUpdateHosts(updatedHosts); + if ( + selectedGroupPath && + (selectedGroupPath === renameTargetPath || + selectedGroupPath.startsWith(renameTargetPath + "/")) + ) { + const suffix = + selectedGroupPath === renameTargetPath + ? "" + : selectedGroupPath.slice(renameTargetPath.length); + setSelectedGroupPath(nextPath + suffix); + } + + setIsRenameGroupOpen(false); + }; + const deleteGroupPath = (path: string) => { const keepGroups = customGroups.filter( (g) => !(g === path || g.startsWith(path + "/")), @@ -892,6 +948,16 @@ const VaultViewInner: React.FC = ({ New Subgroup + { + setRenameTargetPath(node.path); + setRenameGroupName(node.name); + setRenameGroupError(null); + setIsRenameGroupOpen(true); + }} + > + Rename Group + deleteGroupPath(node.path)} @@ -1177,6 +1243,54 @@ const VaultViewInner: React.FC = ({ + { + setIsRenameGroupOpen(open); + if (!open) { + setRenameTargetPath(null); + setRenameGroupName(""); + setRenameGroupError(null); + } + }} + > + + + Rename Group + + Rename an existing group. + + +
+ + { + setRenameGroupName(e.target.value); + setRenameGroupError(null); + }} + placeholder="e.g. Production" + autoFocus + onKeyDown={(e) => e.key === "Enter" && submitRenameGroup()} + /> + {renameTargetPath && ( +

+ Path: {renameTargetPath} +

+ )} + {renameGroupError && ( +

{renameGroupError}

+ )} +
+ + + + +
+
+ {/* Quick Connect Wizard */} {isQuickConnectOpen && quickConnectTarget && (