From e04ac9c22ae3d088e0667b61a56d77e8c1931b6f Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Tue, 9 Dec 2025 02:11:23 +0800 Subject: [PATCH] Refactor VaultView component: reorganize sections for hosts and groups, improve drag-and-drop functionality, and enhance context menu options for groups. --- components/KeyManager.tsx | 2 +- components/PortForwardingNew.tsx | 1870 +++++++++++++++--------------- components/VaultView.tsx | 286 ++--- 3 files changed, 1079 insertions(+), 1079 deletions(-) diff --git a/components/KeyManager.tsx b/components/KeyManager.tsx index 324a3294f..bd4861e4d 100755 --- a/components/KeyManager.tsx +++ b/components/KeyManager.tsx @@ -172,7 +172,7 @@ const KeyManager: React.FC = ({ keys, onSave, onDelete }) => { )} -
+
{filteredKeys.map((key) => ( void; + hosts: Host[]; + customGroups: string[]; + onNewHost?: () => void; } const TYPE_LABELS: Record = { - local: 'Local Forwarding', - remote: 'Remote Forwarding', - dynamic: 'Dynamic Forwarding', + local: 'Local Forwarding', + remote: 'Remote Forwarding', + dynamic: 'Dynamic Forwarding', }; const TYPE_DESCRIPTIONS: Record = { - local: 'Local forwarding lets you access a remote server\'s listening port as though it were local.', - remote: 'Remote forwarding opens a port on the remote machine and forwards connections to the local (current) host.', - dynamic: 'This port will be open on the local (current) device, and it will receive the traffic.', + local: 'Local forwarding lets you access a remote server\'s listening port as though it were local.', + remote: 'Remote forwarding opens a port on the remote machine and forwards connections to the local (current) host.', + dynamic: 'This port will be open on the local (current) device, and it will receive the traffic.', }; const TYPE_ICONS: Record = { - local: , - remote: , - dynamic: , + local: , + remote: , + dynamic: , }; const SORT_LABELS: Record = { - az: { label: 'A-z', icon: }, - za: { label: 'Z-a', icon: }, - newest: { label: 'Newest to oldest', icon: }, - oldest: { label: 'Oldest to newest', icon: }, + az: { label: 'A-z', icon: }, + za: { label: 'Z-a', icon: }, + newest: { label: 'Newest to oldest', icon: }, + oldest: { label: 'Oldest to newest', icon: }, }; const PortForwarding: React.FC = ({ hosts, customGroups, onNewHost }) => { - const { - rules, - selectedRuleId, - viewMode, - sortMode, - search, - setSelectedRuleId, - setViewMode, - setSortMode, - setSearch, - addRule, - updateRule, - deleteRule, - duplicateRule, - setRuleStatus, - filteredRules, - selectedRule, - } = usePortForwardingState(); + const { + rules, + selectedRuleId, + viewMode, + sortMode, + search, + setSelectedRuleId, + setViewMode, + setSortMode, + setSearch, + addRule, + updateRule, + deleteRule, + duplicateRule, + setRuleStatus, + filteredRules, + selectedRule, + } = usePortForwardingState(); - // Wizard state - const [showWizard, setShowWizard] = useState(false); - const [wizardStep, setWizardStep] = useState('type'); - const [wizardType, setWizardType] = useState('local'); - const [draftRule, setDraftRule] = useState>({ - label: '', - type: 'local', - localPort: undefined, - bindAddress: '127.0.0.1', - remoteHost: '', - remotePort: undefined, - hostId: undefined, - }); - const [isEditing, setIsEditing] = useState(false); - const [hostSearchQuery, setHostSearchQuery] = useState(''); - const [showHostSelector, setShowHostSelector] = useState(false); - const [hostSelectorPath, setHostSelectorPath] = useState(null); - - // New forwarding menu - const [showNewMenu, setShowNewMenu] = useState(false); - - // Build group tree for host selection - const buildGroupTree = useMemo>(() => { - const root: Record = {}; - const insertPath = (path: string, host?: Host) => { - const parts = path.split('/').filter(Boolean); - let currentLevel = root; - let currentPath = ''; - parts.forEach((part, index) => { - currentPath = currentPath ? `${currentPath}/${part}` : part; - if (!currentLevel[part]) { - currentLevel[part] = { name: part, path: currentPath, children: {}, hosts: [] }; - } - if (host && index === parts.length - 1) currentLevel[part].hosts.push(host); - currentLevel = currentLevel[part].children; - }); - }; - customGroups.forEach(path => insertPath(path)); - hosts.forEach(host => insertPath(host.group || 'General', host)); - return root; - }, [hosts, customGroups]); - - // Flat list of groups with host counts - filtered by current path - const groupsWithCounts = useMemo(() => { - const result: { path: string; name: string; count: number }[] = []; - const traverse = (nodes: Record, parentPath: string = '') => { - Object.values(nodes).forEach(node => { - // Only show direct children of current path - if (hostSelectorPath === null) { - // At root, show only top-level groups - if (!node.path.includes('/')) { - result.push({ path: node.path, name: node.name, count: node.hosts.length }); - } - } else { - // Show direct children of the selected path - const isDirectChild = node.path.startsWith(hostSelectorPath + '/') && - node.path.substring(hostSelectorPath.length + 1).indexOf('/') === -1; - if (isDirectChild) { - result.push({ path: node.path, name: node.name, count: node.hosts.length }); - } - } - traverse(node.children, node.path); - }); - }; - traverse(buildGroupTree); - return result; - }, [buildGroupTree, hostSelectorPath]); - - // Filter hosts by search and current path - const filteredHosts = useMemo(() => { - let result = hosts; - - // Filter by current path - if (hostSelectorPath !== null) { - result = result.filter(h => h.group === hostSelectorPath); - } else { - // At root level, show hosts without group - result = result.filter(h => !h.group || h.group === ''); - } - - // Filter by search query - if (hostSearchQuery.trim()) { - const q = hostSearchQuery.toLowerCase(); - result = result.filter(h => - h.label.toLowerCase().includes(q) || - h.hostname.toLowerCase().includes(q) || - h.username.toLowerCase().includes(q) - ); - } - - return result; - }, [hosts, hostSearchQuery, hostSelectorPath]); - - // Ungrouped hosts - const ungroupedHosts = useMemo(() => { - return filteredHosts.filter(h => !h.group || h.group === ''); - }, [filteredHosts]); - - // Reset wizard - const resetWizard = () => { - setWizardStep('type'); - setWizardType('local'); - setDraftRule({ - label: '', - type: 'local', - localPort: undefined, - bindAddress: '127.0.0.1', - remoteHost: '', - remotePort: undefined, - hostId: undefined, + // Wizard state + const [showWizard, setShowWizard] = useState(false); + const [wizardStep, setWizardStep] = useState('type'); + const [wizardType, setWizardType] = useState('local'); + const [draftRule, setDraftRule] = useState>({ + label: '', + type: 'local', + localPort: undefined, + bindAddress: '127.0.0.1', + remoteHost: '', + remotePort: undefined, + hostId: undefined, }); - setIsEditing(false); - setHostSearchQuery(''); - }; + const [isEditing, setIsEditing] = useState(false); + const [hostSearchQuery, setHostSearchQuery] = useState(''); + const [showHostSelector, setShowHostSelector] = useState(false); + const [hostSelectorPath, setHostSelectorPath] = useState(null); - // Start new rule wizard - const startNewRule = (type: PortForwardingType) => { - resetWizard(); - setWizardType(type); - setDraftRule(prev => ({ ...prev, type })); - setShowWizard(true); - setShowNewMenu(false); - - // Go to appropriate first config step - if (type === 'dynamic') { - setWizardStep('local-config'); - } else { - setWizardStep('type'); - } - }; + // New forwarding menu + const [showNewMenu, setShowNewMenu] = useState(false); - // Edit existing rule - const startEditRule = (rule: PortForwardingRule) => { - setDraftRule({ ...rule }); - setWizardType(rule.type); - setIsEditing(true); - setShowWizard(true); - setWizardStep('type'); - }; + // Build group tree for host selection + const buildGroupTree = useMemo>(() => { + const root: Record = {}; + const insertPath = (path: string, host?: Host) => { + const parts = path.split('/').filter(Boolean); + let currentLevel = root; + let currentPath = ''; + parts.forEach((part, index) => { + currentPath = currentPath ? `${currentPath}/${part}` : part; + if (!currentLevel[part]) { + currentLevel[part] = { name: part, path: currentPath, children: {}, hosts: [] }; + } + if (host && index === parts.length - 1) currentLevel[part].hosts.push(host); + currentLevel = currentLevel[part].children; + }); + }; + customGroups.forEach(path => insertPath(path)); + hosts.forEach(host => insertPath(host.group || 'General', host)); + return root; + }, [hosts, customGroups]); - // Handle wizard navigation - const getNextStep = (): WizardStep | null => { - switch (wizardStep) { - case 'type': - if (wizardType === 'dynamic') return 'local-config'; - if (wizardType === 'local') return 'destination'; - if (wizardType === 'remote') return 'remote-config'; - return null; - case 'local-config': - return null; // Dynamic is done after local config - case 'remote-config': - return 'destination'; - case 'destination': - return null; - default: - return null; - } - }; + // Flat list of groups with host counts - filtered by current path + const groupsWithCounts = useMemo(() => { + const result: { path: string; name: string; count: number }[] = []; + const traverse = (nodes: Record, parentPath: string = '') => { + Object.values(nodes).forEach(node => { + // Only show direct children of current path + if (hostSelectorPath === null) { + // At root, show only top-level groups + if (!node.path.includes('/')) { + result.push({ path: node.path, name: node.name, count: node.hosts.length }); + } + } else { + // Show direct children of the selected path + const isDirectChild = node.path.startsWith(hostSelectorPath + '/') && + node.path.substring(hostSelectorPath.length + 1).indexOf('/') === -1; + if (isDirectChild) { + result.push({ path: node.path, name: node.name, count: node.hosts.length }); + } + } + traverse(node.children, node.path); + }); + }; + traverse(buildGroupTree); + return result; + }, [buildGroupTree, hostSelectorPath]); - const getPrevStep = (): WizardStep | null => { - switch (wizardStep) { - case 'type': - return null; - case 'local-config': - return 'type'; - case 'remote-config': - return 'type'; - case 'destination': - if (wizardType === 'local') return 'type'; - if (wizardType === 'remote') return 'remote-config'; - return null; - default: - return null; - } - }; + // Filter hosts by search and current path + const filteredHosts = useMemo(() => { + let result = hosts; - const canProceed = (): boolean => { - switch (wizardStep) { - case 'type': - return !!draftRule.hostId; // Need host selected - case 'local-config': - return !!(draftRule.localPort && draftRule.localPort > 0 && draftRule.localPort < 65536); - case 'remote-config': - return !!(draftRule.localPort && draftRule.localPort > 0 && draftRule.localPort < 65536); - case 'destination': - return !!(draftRule.remoteHost && draftRule.remotePort && draftRule.remotePort > 0); - default: - return false; - } - }; + // Filter by current path + if (hostSelectorPath !== null) { + result = result.filter(h => h.group === hostSelectorPath); + } else { + // At root level, show hosts without group + result = result.filter(h => !h.group || h.group === ''); + } - const isLastStep = (): boolean => { - return getNextStep() === null; - }; + // Filter by search query + if (hostSearchQuery.trim()) { + const q = hostSearchQuery.toLowerCase(); + result = result.filter(h => + h.label.toLowerCase().includes(q) || + h.hostname.toLowerCase().includes(q) || + h.username.toLowerCase().includes(q) + ); + } - // Save rule - const saveRule = () => { - // Generate label if not provided - const label = draftRule.label?.trim() || generateRuleLabel(); - - if (isEditing && draftRule.id) { - updateRule(draftRule.id, { ...draftRule, label }); - } else { - addRule({ - label, - type: wizardType, - localPort: draftRule.localPort!, - bindAddress: draftRule.bindAddress || '127.0.0.1', - remoteHost: draftRule.remoteHost, - remotePort: draftRule.remotePort, - hostId: draftRule.hostId, - }); - } - - setShowWizard(false); - resetWizard(); - }; + return result; + }, [hosts, hostSearchQuery, hostSelectorPath]); - const generateRuleLabel = (): string => { - const host = hosts.find(h => h.id === draftRule.hostId); - const hostLabel = host?.label || 'Unknown'; - - switch (wizardType) { - case 'local': - return `Local:${draftRule.localPort} → ${draftRule.remoteHost}:${draftRule.remotePort}`; - case 'remote': - return `Remote:${draftRule.localPort} → ${draftRule.remoteHost}:${draftRule.remotePort}`; - case 'dynamic': - return `SOCKS:${draftRule.localPort}`; - default: - return 'New Rule'; - } - }; + // Ungrouped hosts + const ungroupedHosts = useMemo(() => { + return filteredHosts.filter(h => !h.group || h.group === ''); + }, [filteredHosts]); - // Handle skip wizard (just save with defaults) - const skipWizard = () => { - setShowWizard(false); - resetWizard(); - }; - - // Render rule card - const renderRuleCard = (rule: PortForwardingRule) => { - const isSelected = selectedRuleId === rule.id; - const host = hosts.find(h => h.id === rule.hostId); - const statusColors = { - inactive: 'bg-muted-foreground/20 text-muted-foreground', - connecting: 'bg-yellow-500/20 text-yellow-500', - active: 'bg-emerald-500/20 text-emerald-500', - error: 'bg-destructive/20 text-destructive', + // Reset wizard + const resetWizard = () => { + setWizardStep('type'); + setWizardType('local'); + setDraftRule({ + label: '', + type: 'local', + localPort: undefined, + bindAddress: '127.0.0.1', + remoteHost: '', + remotePort: undefined, + hostId: undefined, + }); + setIsEditing(false); + setHostSearchQuery(''); }; + // Start new rule wizard + const startNewRule = (type: PortForwardingType) => { + resetWizard(); + setWizardType(type); + setDraftRule(prev => ({ ...prev, type })); + setShowWizard(true); + setShowNewMenu(false); + + // Go to appropriate first config step + if (type === 'dynamic') { + setWizardStep('local-config'); + } else { + setWizardStep('type'); + } + }; + + // Edit existing rule + const startEditRule = (rule: PortForwardingRule) => { + setDraftRule({ ...rule }); + setWizardType(rule.type); + setIsEditing(true); + setShowWizard(true); + setWizardStep('type'); + }; + + // Handle wizard navigation + const getNextStep = (): WizardStep | null => { + switch (wizardStep) { + case 'type': + if (wizardType === 'dynamic') return 'local-config'; + if (wizardType === 'local') return 'destination'; + if (wizardType === 'remote') return 'remote-config'; + return null; + case 'local-config': + return null; // Dynamic is done after local config + case 'remote-config': + return 'destination'; + case 'destination': + return null; + default: + return null; + } + }; + + const getPrevStep = (): WizardStep | null => { + switch (wizardStep) { + case 'type': + return null; + case 'local-config': + return 'type'; + case 'remote-config': + return 'type'; + case 'destination': + if (wizardType === 'local') return 'type'; + if (wizardType === 'remote') return 'remote-config'; + return null; + default: + return null; + } + }; + + const canProceed = (): boolean => { + switch (wizardStep) { + case 'type': + return !!draftRule.hostId; // Need host selected + case 'local-config': + return !!(draftRule.localPort && draftRule.localPort > 0 && draftRule.localPort < 65536); + case 'remote-config': + return !!(draftRule.localPort && draftRule.localPort > 0 && draftRule.localPort < 65536); + case 'destination': + return !!(draftRule.remoteHost && draftRule.remotePort && draftRule.remotePort > 0); + default: + return false; + } + }; + + const isLastStep = (): boolean => { + return getNextStep() === null; + }; + + // Save rule + const saveRule = () => { + // Generate label if not provided + const label = draftRule.label?.trim() || generateRuleLabel(); + + if (isEditing && draftRule.id) { + updateRule(draftRule.id, { ...draftRule, label }); + } else { + addRule({ + label, + type: wizardType, + localPort: draftRule.localPort!, + bindAddress: draftRule.bindAddress || '127.0.0.1', + remoteHost: draftRule.remoteHost, + remotePort: draftRule.remotePort, + hostId: draftRule.hostId, + }); + } + + setShowWizard(false); + resetWizard(); + }; + + const generateRuleLabel = (): string => { + const host = hosts.find(h => h.id === draftRule.hostId); + const hostLabel = host?.label || 'Unknown'; + + switch (wizardType) { + case 'local': + return `Local:${draftRule.localPort} → ${draftRule.remoteHost}:${draftRule.remotePort}`; + case 'remote': + return `Remote:${draftRule.localPort} → ${draftRule.remoteHost}:${draftRule.remotePort}`; + case 'dynamic': + return `SOCKS:${draftRule.localPort}`; + default: + return 'New Rule'; + } + }; + + // Handle skip wizard (just save with defaults) + const skipWizard = () => { + setShowWizard(false); + resetWizard(); + }; + + // Render rule card + const renderRuleCard = (rule: PortForwardingRule) => { + const isSelected = selectedRuleId === rule.id; + const host = hosts.find(h => h.id === rule.hostId); + const statusColors = { + inactive: 'bg-muted-foreground/20 text-muted-foreground', + connecting: 'bg-yellow-500/20 text-yellow-500', + active: 'bg-emerald-500/20 text-emerald-500', + error: 'bg-destructive/20 text-destructive', + }; + + return ( + + + { + setSelectedRuleId(rule.id); + startEditRule(rule); + }} + > + +
+ {rule.type[0].toUpperCase()} +
+
+
{rule.label}
+
+ + {rule.type === 'dynamic' + ? `SOCKS on ${rule.bindAddress}:${rule.localPort}` + : `${rule.bindAddress}:${rule.localPort} → ${rule.remoteHost}:${rule.remotePort}` + } + +
+
+
+ + {rule.status} + +
+ {rule.status === 'inactive' ? ( + + ) : rule.status === 'active' || rule.status === 'connecting' ? ( + + ) : null} +
+
+
+
+
+ + startEditRule(rule)}> + Edit + + duplicateRule(rule.id)}> + Duplicate + + + {rule.status === 'inactive' && ( + { + setRuleStatus(rule.id, 'connecting'); + setTimeout(() => setRuleStatus(rule.id, 'active'), 1000); + }}> + Start + + )} + {(rule.status === 'active' || rule.status === 'connecting') && ( + setRuleStatus(rule.id, 'inactive')}> + Stop + + )} + + deleteRule(rule.id)}> + Delete + + +
+ ); + }; + + // Render wizard panel content + const renderWizardContent = () => { + const selectedHost = hosts.find(h => h.id === draftRule.hostId); + + switch (wizardStep) { + case 'type': + return ( + <> +
Select the port forwarding type:
+
+ {(['local', 'remote', 'dynamic'] as PortForwardingType[]).map((type) => ( + + ))} +
+ +
+ +
+ +

+ {TYPE_DESCRIPTIONS[wizardType]} +

+ + {/* Host Selection Button */} + {wizardType !== 'dynamic' && ( +
+
+ {wizardType === 'local' ? 'Select the SSH tunnel host:' : 'Select the remote host:'} +
+ +
+ )} + + ); + + case 'local-config': + return ( + <> +
Set the local port and binding address:
+ + + +

+ This port will be open on the local (current) device, and it will receive the traffic. +

+ +
+
+ + setDraftRule(prev => ({ ...prev, localPort: parseInt(e.target.value) || undefined }))} + /> +
+
+ + setDraftRule(prev => ({ ...prev, bindAddress: e.target.value }))} + /> +
+
+ + ); + + case 'remote-config': + return ( + <> +
Set the remote port to open:
+ + + +

+ This port will be opened on the remote host and will forward traffic to the destination. +

+ +
+
+ + setDraftRule(prev => ({ ...prev, localPort: parseInt(e.target.value) || undefined }))} + /> +
+
+ + setDraftRule(prev => ({ ...prev, bindAddress: e.target.value }))} + /> +
+
+ + ); + + case 'destination': + return ( + <> +
Set the destination:
+ + + +

+ {wizardType === 'local' + ? 'Enter the remote destination that you want to access through the tunnel.' + : 'Enter the local destination where traffic will be forwarded.' + } +

+ +
+
+ + setDraftRule(prev => ({ ...prev, remoteHost: e.target.value }))} + /> +
+
+ + setDraftRule(prev => ({ ...prev, remotePort: parseInt(e.target.value) || undefined }))} + /> +
+
+ + setDraftRule(prev => ({ ...prev, label: e.target.value }))} + /> +
+
+ + ); + + default: + return null; + } + }; + + const hasRules = filteredRules.length > 0; + return ( - - - + {/* Main Content */} +
+ {/* Toolbar */} +
+ + + + + + + + + + + +
+
+ + setSearch(e.target.value)} + /> +
+ + {/* View mode toggle */} + + + + + + + + + + + {/* Sort mode toggle */} + + + + + + {(Object.keys(SORT_LABELS) as SortMode[]).map(mode => ( + + ))} + + +
+
+ + {/* Rules List */} +
+ {!hasRules ? ( +
+
+ +
+

Set up port forwarding

+

+ Save port forwarding to access databases, web apps, and other services. +

+
+ ) : ( +
+
+

Port Forwarding

+ {filteredRules.length} rules +
+ +
+ {filteredRules.map(rule => renderRuleCard(rule))} +
+
+ )} +
+
+ + {/* Wizard Panel */} + {showWizard && ( +
+ {/* Header */} +
+
+

+ {isEditing ? 'Edit Port Forwarding' : 'New Port Forwarding'} +

+

Personal vault

+
+ +
+ + {/* Content */} +
+ {/* Back button */} + {getPrevStep() && ( + + )} + + {renderWizardContent()} +
+ + {/* Footer */} +
+ + +
+
)} - onClick={() => { - setSelectedRuleId(rule.id); - startEditRule(rule); - }} - > - -
- {rule.type[0].toUpperCase()} -
-
-
{rule.label}
-
- - {rule.type === 'dynamic' - ? `SOCKS on ${rule.bindAddress}:${rule.localPort}` - : `${rule.bindAddress}:${rule.localPort} → ${rule.remoteHost}:${rule.remotePort}` - } - + + {/* Host Selector Overlay - Same width as wizard panel */} + {showHostSelector && ( +
+ {/* Header */} +
+ +
+

Select Host

+

{hostSelectorPath || 'Personal vault'}

+
+
+ + {/* Toolbar */} +
+ +
+ + setHostSearchQuery(e.target.value)} + /> +
+
+ + +
+
+ + {/* Content */} + +
+ {/* Groups Section */} + {groupsWithCounts.length > 0 && ( +
+

Groups

+
+ {groupsWithCounts.map(group => ( +
setHostSelectorPath(group.path)} + > +
+ +
+
+
{group.name}
+
{group.count} Host{group.count !== 1 ? 's' : ''}
+
+
+ ))} +
+
+ )} + + {/* Hosts Section */} +
+

Hosts

+
+ {filteredHosts.map(host => ( +
{ + setDraftRule(prev => ({ ...prev, hostId: host.id })); + setShowHostSelector(false); + setHostSearchQuery(''); + setHostSelectorPath(null); + }} + > + +
+
{host.label}
+
+ {host.protocol || 'ssh'}, {host.username} +
+
+ {draftRule.hostId === host.id && ( + + )} +
+ ))} +
+
+
+
+ + {/* Footer */} +
+ +
-
-
- - {rule.status} - -
- {rule.status === 'inactive' ? ( - - ) : rule.status === 'active' || rule.status === 'connecting' ? ( - - ) : null} -
-
- - - - - startEditRule(rule)}> - Edit - - duplicateRule(rule.id)}> - Duplicate - - - {rule.status === 'inactive' && ( - { - setRuleStatus(rule.id, 'connecting'); - setTimeout(() => setRuleStatus(rule.id, 'active'), 1000); - }}> - Start - - )} - {(rule.status === 'active' || rule.status === 'connecting') && ( - setRuleStatus(rule.id, 'inactive')}> - Stop - - )} - - deleteRule(rule.id)}> - Delete - - - + )} +
); - }; - - // Render wizard panel content - const renderWizardContent = () => { - const selectedHost = hosts.find(h => h.id === draftRule.hostId); - - switch (wizardStep) { - case 'type': - return ( - <> -
Select the port forwarding type:
-
- {(['local', 'remote', 'dynamic'] as PortForwardingType[]).map((type) => ( - - ))} -
- -
- -
- -

- {TYPE_DESCRIPTIONS[wizardType]} -

- - {/* Host Selection Button */} - {wizardType !== 'dynamic' && ( -
-
- {wizardType === 'local' ? 'Select the SSH tunnel host:' : 'Select the remote host:'} -
- -
- )} - - ); - - case 'local-config': - return ( - <> -
Set the local port and binding address:
- - - -

- This port will be open on the local (current) device, and it will receive the traffic. -

- -
-
- - setDraftRule(prev => ({ ...prev, localPort: parseInt(e.target.value) || undefined }))} - /> -
-
- - setDraftRule(prev => ({ ...prev, bindAddress: e.target.value }))} - /> -
-
- - ); - - case 'remote-config': - return ( - <> -
Set the remote port to open:
- - - -

- This port will be opened on the remote host and will forward traffic to the destination. -

- -
-
- - setDraftRule(prev => ({ ...prev, localPort: parseInt(e.target.value) || undefined }))} - /> -
-
- - setDraftRule(prev => ({ ...prev, bindAddress: e.target.value }))} - /> -
-
- - ); - - case 'destination': - return ( - <> -
Set the destination:
- - - -

- {wizardType === 'local' - ? 'Enter the remote destination that you want to access through the tunnel.' - : 'Enter the local destination where traffic will be forwarded.' - } -

- -
-
- - setDraftRule(prev => ({ ...prev, remoteHost: e.target.value }))} - /> -
-
- - setDraftRule(prev => ({ ...prev, remotePort: parseInt(e.target.value) || undefined }))} - /> -
-
- - setDraftRule(prev => ({ ...prev, label: e.target.value }))} - /> -
-
- - ); - - default: - return null; - } - }; - - const hasRules = filteredRules.length > 0; - - return ( -
- {/* Main Content */} -
- {/* Toolbar */} -
- - - - - - - - - - - -
-
- - setSearch(e.target.value)} - /> -
- - {/* View mode toggle */} - - - - - - - - - - - {/* Sort mode toggle */} - - - - - - {(Object.keys(SORT_LABELS) as SortMode[]).map(mode => ( - - ))} - - -
-
- - {/* Rules List */} -
- {!hasRules ? ( -
-
- -
-

Set up port forwarding

-

- Save port forwarding to access databases, web apps, and other services. -

-
- ) : ( -
-
-

Port Forwarding

- {filteredRules.length} rules -
- -
- {filteredRules.map(rule => renderRuleCard(rule))} -
-
- )} -
-
- - {/* Wizard Panel */} - {showWizard && ( -
- {/* Header */} -
-
-

- {isEditing ? 'Edit Port Forwarding' : 'New Port Forwarding'} -

-

Personal vault

-
- -
- - {/* Content */} -
- {/* Back button */} - {getPrevStep() && ( - - )} - - {renderWizardContent()} -
- - {/* Footer */} -
- - -
-
- )} - - {/* Host Selector Overlay - Same width as wizard panel */} - {showHostSelector && ( -
- {/* Header */} -
- -
-

Select Host

-

{hostSelectorPath || 'Personal vault'}

-
-
- - {/* Toolbar */} -
- -
- - setHostSearchQuery(e.target.value)} - /> -
-
- - -
-
- - {/* Content */} - -
- {/* Groups Section */} - {groupsWithCounts.length > 0 && ( -
-

Groups

-
- {groupsWithCounts.map(group => ( -
setHostSelectorPath(group.path)} - > -
- -
-
-
{group.name}
-
{group.count} Host{group.count !== 1 ? 's' : ''}
-
-
- ))} -
-
- )} - - {/* Hosts Section */} -
-

Hosts

-
- {filteredHosts.map(host => ( -
{ - setDraftRule(prev => ({ ...prev, hostId: host.id })); - setShowHostSelector(false); - setHostSearchQuery(''); - setHostSelectorPath(null); - }} - > - -
-
{host.label}
-
- {host.protocol || 'ssh'}, {host.username} -
-
- {draftRule.hostId === host.id && ( - - )} -
- ))} -
-
-
-
- - {/* Footer */} -
- -
-
- )} -
- ); }; export default PortForwarding; diff --git a/components/VaultView.tsx b/components/VaultView.tsx index c8e21b3d5..bacb582cf 100644 --- a/components/VaultView.tsx +++ b/components/VaultView.tsx @@ -291,164 +291,164 @@ const VaultViewInner: React.FC = ({ )} {currentSection !== 'port' && ( -
- {currentSection === 'hosts' && ( - <> -
-
- - {selectedGroupPath && selectedGroupPath.split('/').filter(Boolean).map((part, idx, arr) => { - const crumbPath = arr.slice(0, idx + 1).join('/'); - const isLast = idx === arr.length - 1; - return ( - - › - - - ); - })} -
- {displayedGroups.length > 0 && ( - <> -
-

Groups

-
{displayedGroups.length} total
-
- - )} -
{ e.preventDefault(); }} - onDrop={(e) => { - e.preventDefault(); - e.stopPropagation(); - const hostId = e.dataTransfer.getData('host-id'); - const groupPath = e.dataTransfer.getData('group-path'); - if (hostId) moveHostToGroup(hostId, selectedGroupPath); - if (groupPath && selectedGroupPath !== null) moveGroup(groupPath, selectedGroupPath); - }}> - {displayedGroups.map(node => ( - - -
e.dataTransfer.setData('group-path', node.path)} - onDoubleClick={() => setSelectedGroupPath(node.path)} - onClick={() => setSelectedGroupPath(node.path)} - onDragOver={(e) => { e.preventDefault(); e.stopPropagation(); }} - onDrop={(e) => { - e.preventDefault(); - e.stopPropagation(); - const hostId = e.dataTransfer.getData('host-id'); - const groupPath = e.dataTransfer.getData('group-path'); - if (hostId) moveHostToGroup(hostId, node.path); - if (groupPath) moveGroup(groupPath, node.path); - }} - > -
-
- -
-
-
{node.name}
-
{node.hosts.length} Hosts
-
-
-
-
- - { setTargetParentPath(node.path); setIsNewFolderOpen(true); }}> - New Subgroup - - deleteGroupPath(node.path)}> - Delete Group - - -
- ))} -
-
- -
-
-

Hosts

-
- {displayedHosts.length} entries -
{sessions.length} live
+
+ {currentSection === 'hosts' && ( + <> +
+
+ + {selectedGroupPath && selectedGroupPath.split('/').filter(Boolean).map((part, idx, arr) => { + const crumbPath = arr.slice(0, idx + 1).join('/'); + const isLast = idx === arr.length - 1; + return ( + + › + + + ); + })}
-
-
- {displayedHosts.map((host) => { - const safeHost = sanitizeHost(host); - const distroBadge = { text: (safeHost.os || 'L')[0].toUpperCase(), label: safeHost.distro || safeHost.os || 'Linux' }; - return ( - - + {displayedGroups.length > 0 && ( + <> +
+

Groups

+
{displayedGroups.length} total
+
+ + )} +
{ e.preventDefault(); }} + onDrop={(e) => { + e.preventDefault(); + e.stopPropagation(); + const hostId = e.dataTransfer.getData('host-id'); + const groupPath = e.dataTransfer.getData('group-path'); + if (hostId) moveHostToGroup(hostId, selectedGroupPath); + if (groupPath && selectedGroupPath !== null) moveGroup(groupPath, selectedGroupPath); + }}> + {displayedGroups.map(node => ( + +
{ - e.dataTransfer.effectAllowed = 'move'; - e.dataTransfer.setData('host-id', host.id); + onDragStart={(e) => e.dataTransfer.setData('group-path', node.path)} + onDoubleClick={() => setSelectedGroupPath(node.path)} + onClick={() => setSelectedGroupPath(node.path)} + onDragOver={(e) => { e.preventDefault(); e.stopPropagation(); }} + onDrop={(e) => { + e.preventDefault(); + e.stopPropagation(); + const hostId = e.dataTransfer.getData('host-id'); + const groupPath = e.dataTransfer.getData('group-path'); + if (hostId) moveHostToGroup(hostId, node.path); + if (groupPath) moveGroup(groupPath, node.path); }} - onClick={() => onConnect(safeHost)} > -
- -
-
{safeHost.label}
-
{safeHost.username}@{safeHost.hostname}
- {safeHost.distro &&
{distroBadge.label}
} +
+
+ +
+
+
{node.name}
+
{node.hosts.length} Hosts
- onConnect(host)}> - Connect + { setTargetParentPath(node.path); setIsNewFolderOpen(true); }}> + New Subgroup - onEditHost(host)}> - Edit - - onDeleteHost(host.id)}> - Delete + deleteGroupPath(node.path)}> + Delete Group - ); - })} - {displayedHosts.length === 0 && ( -
-
- -
-

Set up your hosts

-

- Save hosts to quickly connect to your servers, VMs, and containers. -

-
- )} -
-
- - )} + ))} +
+ - {currentSection === 'keys' && ( - onUpdateKeys([...keys, k])} onDelete={id => onUpdateKeys(keys.filter(k => k.id !== id))} /> - )} - {currentSection === 'snippets' && ( - onUpdateSnippets(snippets.find(ex => ex.id === s.id) ? snippets.map(ex => ex.id === s.id ? s : ex) : [...snippets, s])} - onDelete={id => onUpdateSnippets(snippets.filter(s => s.id !== id))} - /> - )} -
+
+
+

Hosts

+
+ {displayedHosts.length} entries +
{sessions.length} live
+
+
+
+ {displayedHosts.map((host) => { + const safeHost = sanitizeHost(host); + const distroBadge = { text: (safeHost.os || 'L')[0].toUpperCase(), label: safeHost.distro || safeHost.os || 'Linux' }; + return ( + + +
{ + e.dataTransfer.effectAllowed = 'move'; + e.dataTransfer.setData('host-id', host.id); + }} + onClick={() => onConnect(safeHost)} + > +
+ +
+
{safeHost.label}
+
{safeHost.username}@{safeHost.hostname}
+ {safeHost.distro &&
{distroBadge.label}
} +
+
+
+
+ + onConnect(host)}> + Connect + + onEditHost(host)}> + Edit + + onDeleteHost(host.id)}> + Delete + + +
+ ); + })} + {displayedHosts.length === 0 && ( +
+
+ +
+

Set up your hosts

+

+ Save hosts to quickly connect to your servers, VMs, and containers. +

+
+ )} +
+
+ + )} + + {currentSection === 'keys' && ( + onUpdateKeys([...keys, k])} onDelete={id => onUpdateKeys(keys.filter(k => k.id !== id))} /> + )} + {currentSection === 'snippets' && ( + onUpdateSnippets(snippets.find(ex => ex.id === s.id) ? snippets.map(ex => ex.id === s.id ? s : ex) : [...snippets, s])} + onDelete={id => onUpdateSnippets(snippets.filter(s => s.id !== id))} + /> + )} +
)} {currentSection === 'port' && }