From 16767a2a778b57a17320a4984cb7dd280890d406 Mon Sep 17 00:00:00 2001 From: Chris Scott Date: Thu, 27 Nov 2025 08:28:17 -0500 Subject: [PATCH] Add dynamic path display to file browser with truncation support --- backend/src/services/files.ts | 2 + .../components/file-browser/FileBrowser.tsx | 4 +- .../file-browser/FileBrowserSheet.tsx | 42 ++++++++++++++----- .../components/file-browser/FilePreview.tsx | 12 +++--- .../file-browser/MobileFilePreviewModal.tsx | 11 ----- frontend/src/components/ui/path-display.tsx | 32 ++++++++++++++ frontend/src/types/files.ts | 1 + 7 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 frontend/src/components/ui/path-display.tsx diff --git a/backend/src/services/files.ts b/backend/src/services/files.ts index 62801e0a..83f3281e 100644 --- a/backend/src/services/files.ts +++ b/backend/src/services/files.ts @@ -24,6 +24,7 @@ interface FileInfo { content?: string children?: FileInfo[] lastModified: Date + workspaceRoot?: string } interface FileUploadResult { @@ -96,6 +97,7 @@ export async function getFile(userPath: string): Promise { return a.name.localeCompare(b.name) }), lastModified: stats.lastModified, + workspaceRoot: SHARED_WORKSPACE_BASE, } } else { // It's a file - get content diff --git a/frontend/src/components/file-browser/FileBrowser.tsx b/frontend/src/components/file-browser/FileBrowser.tsx index 550cf71a..f25aa26f 100644 --- a/frontend/src/components/file-browser/FileBrowser.tsx +++ b/frontend/src/components/file-browser/FileBrowser.tsx @@ -20,9 +20,10 @@ interface FileBrowserProps { onFileSelect?: (file: FileInfo) => void embedded?: boolean initialSelectedFile?: string + onDirectoryLoad?: (info: { workspaceRoot?: string; currentPath: string }) => void } -export function FileBrowser({ basePath = '', onFileSelect, embedded = false, initialSelectedFile }: FileBrowserProps) { +export function FileBrowser({ basePath = '', onFileSelect, embedded = false, initialSelectedFile, onDirectoryLoad }: FileBrowserProps) { const [currentPath, setCurrentPath] = useState(basePath) const [files, setFiles] = useState(null) const [selectedFile, setSelectedFile] = useState(null) @@ -65,6 +66,7 @@ useEffect(() => { const data = await response.json() setFiles(data) setCurrentPath(path) + onDirectoryLoad?.({ workspaceRoot: data.workspaceRoot, currentPath: path }) } catch (err) { setError(err instanceof Error ? err.message : 'Failed to load files') } finally { diff --git a/frontend/src/components/file-browser/FileBrowserSheet.tsx b/frontend/src/components/file-browser/FileBrowserSheet.tsx index ee10a90e..afcdc4d1 100644 --- a/frontend/src/components/file-browser/FileBrowserSheet.tsx +++ b/frontend/src/components/file-browser/FileBrowserSheet.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react' import { FileBrowser } from './FileBrowser' import { Button } from '@/components/ui/button' +import { PathDisplay } from '@/components/ui/path-display' import { X } from 'lucide-react' interface FileBrowserSheetProps { @@ -12,7 +13,29 @@ interface FileBrowserSheetProps { } export function FileBrowserSheet({ isOpen, onClose, basePath = '', repoName, initialSelectedFile }: FileBrowserSheetProps) { + const normalizedBasePath = basePath || '.' const [isEditing, setIsEditing] = useState(false) + const [displayPath, setDisplayPath] = useState('/') + const handleDirectoryLoad = (info: { workspaceRoot?: string; currentPath: string }) => { + if (!info.currentPath || info.currentPath === '.' || info.currentPath === '') { + setDisplayPath('/') + return + } + + const pathParts = info.currentPath.split('/').filter(Boolean) + + if (repoName) { + const repoIndex = pathParts.findIndex(p => p === repoName || p.startsWith(repoName + '-')) + if (repoIndex >= 0) { + const subPath = pathParts.slice(repoIndex + 1) + setDisplayPath(subPath.length > 0 ? '/' + subPath.join('/') : '/') + } else { + setDisplayPath('/' + pathParts.join('/')) + } + } else { + setDisplayPath('/' + pathParts.join('/')) + } + } useEffect(() => { const handleEscape = (e: KeyboardEvent) => { @@ -44,17 +67,15 @@ export function FileBrowserSheet({ isOpen, onClose, basePath = '', repoName, ini
{/* Header */} -
+
-

- {repoName ? `${repoName} - Files` : 'Workspace Files'} -

- {basePath && ( - - {basePath} - + {(displayPath === '/' || !repoName) && ( +

+ {repoName || 'Workspace Files'} +

)} +
{!isEditing && (
) -} \ No newline at end of file +} diff --git a/frontend/src/components/file-browser/FilePreview.tsx b/frontend/src/components/file-browser/FilePreview.tsx index 969e2284..fa5d5606 100644 --- a/frontend/src/components/file-browser/FilePreview.tsx +++ b/frontend/src/components/file-browser/FilePreview.tsx @@ -182,12 +182,6 @@ export function FilePreview({ file, hideHeader = false, isMobileModal = false, o
- {isMobileModal && onCloseModal && ( - - )} - {isTextFile && viewMode !== 'edit' && ( )} + + {viewMode !== 'edit' && isMobileModal && onCloseModal && ( + + )}
diff --git a/frontend/src/components/file-browser/MobileFilePreviewModal.tsx b/frontend/src/components/file-browser/MobileFilePreviewModal.tsx index b42efda8..f13cdac3 100644 --- a/frontend/src/components/file-browser/MobileFilePreviewModal.tsx +++ b/frontend/src/components/file-browser/MobileFilePreviewModal.tsx @@ -15,14 +15,6 @@ export function MobileFilePreviewModal({ file, showFilePreviewHeader = false, }: MobileFilePreviewModalProps) { - const handleTouchStart = (e: React.TouchEvent) => { - e.preventDefault(); - }; - - const handleTouchEnd = (e: React.TouchEvent) => { - e.preventDefault(); - }; - if (!file || file.isDirectory) { return null; } @@ -31,8 +23,6 @@ export function MobileFilePreviewModal({ !open && onClose()}>
); } - diff --git a/frontend/src/components/ui/path-display.tsx b/frontend/src/components/ui/path-display.tsx new file mode 100644 index 00000000..d242b34c --- /dev/null +++ b/frontend/src/components/ui/path-display.tsx @@ -0,0 +1,32 @@ +import { useMemo } from 'react' + +interface PathDisplayProps { + path: string + maxSegments?: number + className?: string +} + +export function PathDisplay({ path, maxSegments = 3, className = '' }: PathDisplayProps) { + const displayPath = useMemo(() => { + if (!path || path === '/') return '/' + + const normalizedPath = path.startsWith('/') ? path : '/' + path + const segments = normalizedPath.split('/').filter(Boolean) + + if (segments.length <= maxSegments) { + return '/' + segments.join('/') + } + + const visibleSegments = segments.slice(-maxSegments) + return '/.../' + visibleSegments.join('/') + }, [path, maxSegments]) + + return ( + + {displayPath} + + ) +} diff --git a/frontend/src/types/files.ts b/frontend/src/types/files.ts index e334346d..81b4dd35 100644 --- a/frontend/src/types/files.ts +++ b/frontend/src/types/files.ts @@ -7,4 +7,5 @@ export interface FileInfo { content?: string children?: FileInfo[] lastModified: Date + workspaceRoot?: string }