diff --git a/src/App.tsx b/src/App.tsx index b19869bc..326d0cc9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -475,7 +475,9 @@ function AppContent() { }, []); const handleConnectionSelect = (connection: ConnectionNode) => { - setSelectedConnection(connection); + if (connection.type === 'connection') { + setSelectedConnection(connection); + } }; const handleConnectionConnect = async (connection: ConnectionNode) => { @@ -677,7 +679,7 @@ function AppContent() { }, [state.groups, dispatch]); const handleNewTab = useCallback((folderPath?: string) => { - setConnectionInitialFolder(folderPath); + setConnectionInitialFolder(typeof folderPath === 'string' ? folderPath : undefined); setConnectionDialogOpen(true); setEditingConnection(null); }, []); diff --git a/src/__tests__/connection-dialog-folder.test.tsx b/src/__tests__/connection-dialog-folder.test.tsx index 928742b6..e4bd3f71 100644 --- a/src/__tests__/connection-dialog-folder.test.tsx +++ b/src/__tests__/connection-dialog-folder.test.tsx @@ -6,6 +6,7 @@ */ import { beforeEach, describe, expect, it, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; +import { type ComponentProps } from 'react'; import { ConnectionDialog } from '../components/connection-dialog'; vi.mock('@tauri-apps/api/core', () => ({ @@ -62,7 +63,7 @@ function getFolderSelect() { } describe('ConnectionDialog folder pre-selection', () => { - function renderDialog(props: Partial> = {}) { + function renderDialog(props: Partial> = {}) { return render( f.path).sort(); setAvailableFolders(folderPaths); - // Pre-select folder when initialFolder is provided (new connection from folder context menu) - if (initialFolder && !editingConnection) { - setConnectionFolder(initialFolder); - } - // Load editing connection data into config when dialog opens if (editingConnection) { setConfig({ @@ -185,6 +180,13 @@ export function ConnectionDialog({ // Reset connection state when dialog closes resetConnectionState(); } + }, [open, editingConnection]); + + // Dedicated effect: pre-select folder when initialFolder is provided (new connection from folder context menu) + useEffect(() => { + if (open && !editingConnection && initialFolder) { + setConnectionFolder(initialFolder); + } }, [open, editingConnection, initialFolder]); const _handleSaveProfile = () => { diff --git a/src/components/connection-manager.tsx b/src/components/connection-manager.tsx index 0be4ce19..8f9feaae 100644 --- a/src/components/connection-manager.tsx +++ b/src/components/connection-manager.tsx @@ -672,6 +672,8 @@ export function ConnectionManager({ variant="ghost" size="sm" className="p-0 h-4 w-4" + aria-label={node.isExpanded ? t('connectionManager.collapseFolder') : t('connectionManager.expandFolder')} + aria-expanded={node.isExpanded} onClick={(e) => { e.stopPropagation(); toggleExpanded(node.id); @@ -754,13 +756,17 @@ export function ConnectionManager({ {nodeContent} - onNewConnection?.(node.path)} - > - - {t('connectionManager.newConnection')} - - + {onNewConnection && ( + <> + onNewConnection(node.path)} + > + + {t('connectionManager.newConnection')} + + + + )} openNewFolderDialog(node.path)} > diff --git a/src/locales/en.json b/src/locales/en.json index 658901ca..b021ba60 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -767,7 +767,9 @@ "connectionDetails": "Connection Details", "noConnectionSelected": "No connection selected", "movedToRoot": "Moved \"{{name}}\" to All Connections", - "failedToReorder": "Failed to reorder items" + "failedToReorder": "Failed to reorder items", + "expandFolder": "Expand folder", + "collapseFolder": "Collapse folder" }, "filePanel": { "selectDirectory": "Select a directory to view its contents", diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index 40d4c218..711765ae 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -767,7 +767,9 @@ "connectionDetails": "连接详情", "noConnectionSelected": "未选择连接", "movedToRoot": "已将\"{{name}}\"移动到所有连接", - "failedToReorder": "重新排序失败" + "failedToReorder": "重新排序失败", + "expandFolder": "展开文件夹", + "collapseFolder": "折叠文件夹" }, "filePanel": { "selectDirectory": "选择目录以查看其内容",