/* eslint-disable @typescript-eslint/no-explicit-any */ import React from "react"; import { VaultHostListSection } from "./VaultHostListSection"; import { VaultHeaderSearch, VaultPageHeader, vaultHeaderIconButtonClass, vaultHeaderSecondaryButtonClass, } from "./VaultPageHeader"; type VaultViewLayoutContext = Record; export function VaultViewLayout({ ctx }: { ctx: VaultViewLayoutContext }) { const { Activity, allGroupPaths, allTags, AppLogo, Array, Badge, BookMarked, Boolean, Button, CheckSquare, ChevronDown, clearHostSelection, ClipboardCopy, Clock, cn, connectionLogs, connectSelectedHosts, ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger, Copy, currentSection, customGroups, deleteGroupPath, deleteGroupWithHosts, deleteSelectedHosts, deleteTargetPath, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, displayedGroups, displayedHosts, DistroAvatar, Download, Dropdown, DropdownContent, DropdownTrigger, Edit2, editingGroupPath, editingHost, editingHostGroupDefaults, FileCode, FileSymlink, FolderPlus, FolderTree, getDropTargetClasses, getEffectiveHostDistro, Globe, groupConfigs, GroupDetailsPanel, groupedDisplayHosts, handleConnectClick, handleCopyCredentials, handleDeleteTag, handleDuplicateHost, handleEditGroupConfig, handleEditHost, handleEditTag, handleExportHosts, handleHostConnect, handleImportFileSelected, handleNewHost, handleProtocolSelect, handleQuickConnect, handleQuickConnectSaveHost, handleSaveGroupConfig, handleSearchKeyDown, handleUnmanageGroup, handleSidebarWidthCommit, hasHostsSidePanel, HostDetailsPanel, hostListScrollRef, hosts, HostTreeView, hotkeyScheme, identities, ImportVaultDialog, Input, isDeleteGroupOpen, isGroupPanelOpen, isHostPanelOpen, isHostsSectionActive, isImportOpen, isMultiSelectMode, isNewFolderOpen, isQuickConnectOpen, isRenameGroupOpen, isSearchQuickConnect, isSerialModalOpen, Key, keyBindings, KeychainManager, keys, knownHostsManagerElement, Label, lastPinnedId, LayoutGrid, LazyConnectionLogsManager, LazyProtocolSelectDialog, List, managedGroupPaths, managedSources, moveGroup, moveHostToGroup, Network, newFolderName, newHostGroupPath, onClearUnsavedConnectionLogs, onConnectSerial, onCreateLocalTerminal, onDeleteConnectionLog, onDeleteHost, onImportOrReuseKey, onOpenLogView, onOpenSettings, onRunSnippet, onToggleConnectionLogSaved, onUpdateCustomGroups, onUpdateGroupConfigs, onUpdateHosts, onUpdateIdentities, onUpdateKeys, onUpdateProxyProfiles, onUpdateSnippetPackages, onUpdateSnippets, Pin, pinnedHosts, pinnedRecentIds, Plug, Plus, PortForwarding, protocolSelectHost, proxyProfiles, ProxyProfilesManager, quickConnectTarget, quickConnectWarnings, QuickConnectWizard, recentHosts, renameGroupError, renameGroupName, renameTargetPath, RippleButton, rootRef, sanitizeHost, search, selectedGroupPath, selectedHostIds, selectedTags, SerialConnectModal, SerialHostDetailsPanel, sessionCount, Set, setCurrentSection, setDeleteGroupWithHosts, setDeleteTargetPath, setDragOverDropTarget, setEditingGroupPath, setEditingHost, setGroupDragOverDropTarget, setIsDeleteGroupOpen, setIsGroupPanelOpen, setIsHostPanelOpen, setIsImportOpen, setIsMultiSelectMode, setIsNewFolderOpen, setIsQuickConnectOpen, setIsRenameGroupOpen, setIsSerialModalOpen, setLastPinnedId, setNewFolderName, setNewHostGroupPath, setProtocolSelectHost, setQuickConnectTarget, setQuickConnectWarnings, setRenameGroupError, setRenameGroupName, setRenameTargetPath, setSearch, setSelectedGroupPath, setSelectedHostIds, setSelectedTags, setSidebarCollapsed, setSidebarWidth, setSortMode, setTargetParentPath, Settings, setViewMode, shellHistory, shouldHideEmptyRootHostsSection, showRecentHosts, sidebarCollapsed, sidebarWidth, snippetPackages, snippets, SnippetsManager, SortDropdown, sortMode, splitViewGridStyle, Square, Star, submitNewFolder, submitRenameGroup, Suspense, t, TagFilterDropdown, targetParentPath, terminalFontSize, terminalSettings, TerminalSquare, terminalThemeId, toggleHostPinned, toggleHostSelection, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, Trash2, treeExpandedState, treeViewGroupTree, treeViewHosts, Upload, upsertHostById, Usb, viewMode, visibleDisplayedHosts, X, Zap } = ctx; const [isSidebarResizing, setIsSidebarResizing] = React.useState(false); const sidebarMinWidth = 56; const sidebarMaxWidth = 320; const effectiveSidebarWidth = Math.max( sidebarMinWidth, Math.min(sidebarMaxWidth, Number(sidebarWidth) || 208), ); const handleSidebarResizeStart = React.useCallback((event: React.PointerEvent) => { event.preventDefault(); event.stopPropagation(); const startX = event.clientX; const startWidth = effectiveSidebarWidth; const previousCursor = document.body.style.cursor; const previousUserSelect = document.body.style.userSelect; setIsSidebarResizing(true); document.body.style.cursor = "col-resize"; document.body.style.userSelect = "none"; const clampWidth = (value: number) => Math.max(sidebarMinWidth, Math.min(sidebarMaxWidth, value)); const handlePointerMove = (moveEvent: PointerEvent) => { setSidebarWidth(clampWidth(startWidth + moveEvent.clientX - startX)); }; const handlePointerUp = (upEvent: PointerEvent) => { const nextWidth = clampWidth(startWidth + upEvent.clientX - startX); setSidebarWidth(nextWidth); handleSidebarWidthCommit(nextWidth); setIsSidebarResizing(false); document.body.style.cursor = previousCursor; document.body.style.userSelect = previousUserSelect; window.removeEventListener("pointermove", handlePointerMove); window.removeEventListener("pointerup", handlePointerUp); window.removeEventListener("pointercancel", handlePointerUp); }; window.addEventListener("pointermove", handlePointerMove); window.addEventListener("pointerup", handlePointerUp); window.addEventListener("pointercancel", handlePointerUp); }, [effectiveSidebarWidth, handleSidebarWidthCommit, setSidebarWidth]); return (
{/* Sidebar */}
{sidebarCollapsed ? t("vault.sidebar.expand") : t("vault.sidebar.collapse")}
{ setCurrentSection("hosts"); setSelectedGroupPath(null); }} > {!sidebarCollapsed && t("vault.nav.hosts")} {sidebarCollapsed && {t("vault.nav.hosts")}} { setCurrentSection("keys"); }} > {!sidebarCollapsed && t("vault.nav.keychain")} {sidebarCollapsed && {t("vault.nav.keychain")}} { setCurrentSection("proxies"); }} > {!sidebarCollapsed && t("vault.nav.proxies")} {sidebarCollapsed && {t("vault.nav.proxies")}} setCurrentSection("port")} > {!sidebarCollapsed && t("vault.nav.portForwarding")} {sidebarCollapsed && {t("vault.nav.portForwarding")}} { setCurrentSection("snippets"); }} > {!sidebarCollapsed && t("vault.nav.snippets")} {sidebarCollapsed && {t("vault.nav.snippets")}} setCurrentSection("knownhosts")} > {!sidebarCollapsed && t("vault.nav.knownHosts")} {sidebarCollapsed && {t("vault.nav.knownHosts")}} setCurrentSection("logs")} > {!sidebarCollapsed && t("vault.nav.logs")} {sidebarCollapsed && {t("vault.nav.logs")}}
{sidebarCollapsed && {t("common.settings")}}
{/* Main Area */}
setSearch(e.target.value)} onKeyDown={handleSearchKeyDown} rightAdornment={ isSearchQuickConnect ? ( ) : null } /> {/* View mode, tag filter, and sort controls */}
{t("vault.hosts.multiSelect")}
{/* New Host split button — collapses with an animation when the host details / new-host aside panel is open, since the button would be a no-op in that state. */}
{/* Terminal + Serial — collapse together with an animation when the host details / new-host aside panel is open, freeing horizontal space for the panel. */}
{isMultiSelectMode && isHostsSectionActive && (
{t("vault.hosts.selected", { count: selectedHostIds.size })}
)} {/* Keep hosts mounted so switching sections does not reset scroll or remount the list. */} {currentSection === "snippets" && ( onUpdateSnippets( snippets.find((ex) => ex.id === s.id) ? snippets.map((ex) => (ex.id === s.id ? s : ex)) : [...snippets, s], ) } onBulkSave={onUpdateSnippets} onDelete={(id) => onUpdateSnippets(snippets.filter((s) => s.id !== id)) } onRunSnippet={onRunSnippet} availableKeys={keys} proxyProfiles={proxyProfiles} managedSources={managedSources} onSaveHost={(host) => onUpdateHosts([...hosts, host])} onCreateGroup={(groupPath) => onUpdateCustomGroups( Array.from(new Set([...customGroups, groupPath])), ) } /> )} {currentSection === "keys" && ( onUpdateKeys([...keys, k])} onUpdate={(k) => onUpdateKeys( keys.map((existing) => (existing.id === k.id ? k : existing)), ) } onDelete={(id) => onUpdateKeys(keys.filter((k) => k.id !== id))} onSaveIdentity={(identity) => onUpdateIdentities( identities.find((ex) => ex.id === identity.id) ? identities.map((ex) => ex.id === identity.id ? identity : ex, ) : [...identities, identity], ) } onDeleteIdentity={(id) => onUpdateIdentities(identities.filter((i) => i.id !== id)) } onSaveHost={(host) => { // Update existing host or add new one const existingIndex = hosts.findIndex((h) => h.id === host.id); if (existingIndex >= 0) { onUpdateHosts(hosts.map((h) => (h.id === host.id ? host : h))); } else { onUpdateHosts([...hosts, host]); } }} onCreateGroup={(groupPath) => onUpdateCustomGroups( Array.from(new Set([...customGroups, groupPath])), ) } /> )} {currentSection === "proxies" && ( )} {currentSection === "port" && ( onUpdateHosts([...hosts, host])} onCreateGroup={(groupPath) => onUpdateCustomGroups( Array.from(new Set([...customGroups, groupPath])), ) } terminalSettings={terminalSettings} /> )} {/* Always render KnownHostsManager but hide with CSS to prevent unmounting */}
{knownHostsManagerElement}
{/* Connection Logs */} {currentSection === "logs" && ( Loading...
}> )}
{/* Group Details Panel */} {currentSection === "hosts" && isGroupPanelOpen && editingGroupPath && ( c.path === editingGroupPath)} availableKeys={keys} identities={identities} proxyProfiles={proxyProfiles} allHosts={hosts} groups={allGroupPaths} terminalThemeId={terminalThemeId} groupConfigs={groupConfigs} terminalFontSize={terminalFontSize} onSave={handleSaveGroupConfig} onCancel={() => { setIsGroupPanelOpen(false); setEditingGroupPath(null); }} layout="inline" /> )} {/* Host Details Panel */} {currentSection === "hosts" && isHostPanelOpen && editingHost?.protocol !== 'serial' && ( { onUpdateHosts(upsertHostById(hosts, host)); setIsHostPanelOpen(false); setEditingHost(null); setNewHostGroupPath(null); }} onCancel={() => { setIsHostPanelOpen(false); setEditingHost(null); setNewHostGroupPath(null); }} onCreateGroup={(groupPath) => { onUpdateCustomGroups( Array.from(new Set([...customGroups, groupPath])), ); }} layout="inline" /> )} {/* Serial Host Details Panel - for editing serial port hosts */} {currentSection === "hosts" && isHostPanelOpen && editingHost?.protocol === 'serial' && ( { onUpdateHosts(upsertHostById(hosts, host)); setIsHostPanelOpen(false); setEditingHost(null); setNewHostGroupPath(null); }} onCancel={() => { setIsHostPanelOpen(false); setEditingHost(null); setNewHostGroupPath(null); }} layout="inline" /> )}
{ setIsNewFolderOpen(open); if (!open) { setNewFolderName(""); setTargetParentPath(null); } }}> {targetParentPath ? t("vault.groups.createSubfolder") : t("vault.groups.createRoot")} {t("vault.groups.createDialog.desc")}
setNewFolderName(e.target.value)} placeholder={t("vault.groups.placeholder.example")} autoFocus onKeyDown={(e) => e.key === "Enter" && submitNewFolder()} /> {targetParentPath && (

{t("vault.groups.parentLabel")}:{" "} {targetParentPath}

)}
{ setIsRenameGroupOpen(open); if (!open) { setRenameTargetPath(null); setRenameGroupName(""); setRenameGroupError(null); } }} > {t("vault.groups.renameDialogTitle")} {t("vault.groups.renameDialog.desc")}
{ setRenameGroupName(e.target.value); setRenameGroupError(null); }} placeholder={t("vault.groups.placeholder.example")} autoFocus onKeyDown={(e) => e.key === "Enter" && submitRenameGroup()} /> {renameTargetPath && (

{t("vault.groups.pathLabel")}:{" "} {renameTargetPath}

)} {renameGroupError && (

{renameGroupError}

)}
{ setIsDeleteGroupOpen(open); if (!open) { setDeleteTargetPath(null); setDeleteGroupWithHosts(false); } }} > {t("vault.groups.deleteDialogTitle")} {deleteTargetPath && managedGroupPaths.has(deleteTargetPath) ? t("vault.groups.deleteDialog.managedDesc") : t("vault.groups.deleteDialog.desc")}
{deleteTargetPath && ( <>

{t("vault.groups.pathLabel")}:{" "} {deleteTargetPath}

{!managedGroupPaths.has(deleteTargetPath) && ( )} )}
{/* Quick Connect Wizard */} {isQuickConnectOpen && quickConnectTarget && ( { setIsQuickConnectOpen(false); setQuickConnectTarget(null); setQuickConnectWarnings([]); }} warnings={quickConnectWarnings} /> )} {/* Protocol Select Dialog */} {protocolSelectHost && ( setProtocolSelectHost(null)} /> )} {/* Serial Connect Modal */} setIsSerialModalOpen(false)} onConnect={(config, options) => { if (onConnectSerial) { onConnectSerial(config, options); } }} onSaveHost={(host) => { onUpdateHosts([...hosts, host]); }} />
); }