mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(ui): dock repo and session tools in a desktop side panel
Add a docked desktop tool panel with an icon rail, driven by the shared panel URL param, and keep the mobile dialogs and drawers. Extract dialog bodies into reusable content components, rename the walkthrough dialog to a sheet, and make walkthrough generation asynchronous with client polling.
This commit is contained in:
1 parent
bdbcc60716
commit
485ab940aa
49 files changed
+2631
-1753
No files matched your search
@@ -0,0 +1,126 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import '@testing-library/jest-dom'
|
||||
import { FileBrowser } from './FileBrowser'
|
||||
import type { FileInfo } from '@/types/files'
|
||||
import * as useMobile from '../../hooks/useMobile'
|
||||
|
||||
function createWrapper() {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
return ({ children }: { children: React.ReactNode }) => (
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
const fileInfo: FileInfo = {
|
||||
name: 'notes.txt',
|
||||
path: 'repo/notes.txt',
|
||||
isDirectory: false,
|
||||
size: 12,
|
||||
mimeType: 'text/plain',
|
||||
content: btoa('hello world'),
|
||||
lastModified: new Date('2026-01-01T00:00:00Z'),
|
||||
}
|
||||
|
||||
const directoryInfo: FileInfo = {
|
||||
name: 'repo',
|
||||
path: 'repo',
|
||||
isDirectory: true,
|
||||
size: 0,
|
||||
lastModified: new Date('2026-01-01T00:00:00Z'),
|
||||
children: [
|
||||
{
|
||||
name: 'notes.txt',
|
||||
path: 'repo/notes.txt',
|
||||
isDirectory: false,
|
||||
size: 12,
|
||||
mimeType: 'text/plain',
|
||||
lastModified: new Date('2026-01-01T00:00:00Z'),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
function jsonResponse(payload: unknown) {
|
||||
return new Response(JSON.stringify(payload), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
}
|
||||
|
||||
function stubFileFetch() {
|
||||
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
|
||||
const path = new URL(String(input), 'http://localhost').searchParams.get('path')
|
||||
if (path === 'repo/notes.txt') {
|
||||
return jsonResponse(fileInfo)
|
||||
}
|
||||
return jsonResponse(directoryInfo)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
return fetchMock
|
||||
}
|
||||
|
||||
describe('FileBrowser compact', () => {
|
||||
it('renders a single full-width column without the desktop preview pane', async () => {
|
||||
const mobileSpy = vi.spyOn(useMobile, 'useMobile').mockReturnValue(false)
|
||||
stubFileFetch()
|
||||
|
||||
try {
|
||||
render(<FileBrowser basePath="repo" embedded compact />, { wrapper: createWrapper() })
|
||||
|
||||
expect(await screen.findByText('notes.txt')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Select a file to preview')).not.toBeInTheDocument()
|
||||
|
||||
const column = screen.getByPlaceholderText('Search').closest('.border-r')
|
||||
expect(column).toHaveClass('w-full')
|
||||
expect(column).not.toHaveClass('w-[30%]')
|
||||
} finally {
|
||||
mobileSpy.mockRestore()
|
||||
vi.unstubAllGlobals()
|
||||
}
|
||||
})
|
||||
|
||||
it('shows the inline preview when a file is opened and returns to the list on close', async () => {
|
||||
const mobileSpy = vi.spyOn(useMobile, 'useMobile').mockReturnValue(false)
|
||||
stubFileFetch()
|
||||
|
||||
try {
|
||||
render(<FileBrowser basePath="repo" embedded compact />, { wrapper: createWrapper() })
|
||||
|
||||
fireEvent.click(await screen.findByText('notes.txt'))
|
||||
|
||||
await waitFor(() => expect(screen.queryByPlaceholderText('Search')).not.toBeInTheDocument())
|
||||
expect(screen.getByText('hello world')).toBeInTheDocument()
|
||||
expect(screen.getByTitle('Close preview')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByTitle('Close preview'))
|
||||
|
||||
await waitFor(() => expect(screen.getByPlaceholderText('Search')).toBeInTheDocument())
|
||||
expect(screen.queryByText('hello world')).not.toBeInTheDocument()
|
||||
} finally {
|
||||
mobileSpy.mockRestore()
|
||||
vi.unstubAllGlobals()
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps the split desktop layout when compact is not set', async () => {
|
||||
const mobileSpy = vi.spyOn(useMobile, 'useMobile').mockReturnValue(false)
|
||||
stubFileFetch()
|
||||
|
||||
try {
|
||||
render(<FileBrowser basePath="repo" embedded />, { wrapper: createWrapper() })
|
||||
|
||||
expect(await screen.findByText('notes.txt')).toBeInTheDocument()
|
||||
expect(screen.getByText('Select a file to preview')).toBeInTheDocument()
|
||||
} finally {
|
||||
mobileSpy.mockRestore()
|
||||
vi.unstubAllGlobals()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -27,6 +27,7 @@ interface FileBrowserProps {
|
||||
onDirectoryLoad?: (info: { workspaceRoot?: string; currentPath: string }) => void
|
||||
onPreviewStateChange?: (isOpen: boolean) => void
|
||||
allowNavigateAboveBase?: boolean
|
||||
compact?: boolean
|
||||
}
|
||||
|
||||
interface UploadItem {
|
||||
@@ -131,7 +132,7 @@ function getUploadItemsFromFileList(fileList: FileList): UploadItem[] {
|
||||
return items
|
||||
}
|
||||
|
||||
export const FileBrowser = forwardRef<FileBrowserHandle, FileBrowserProps>(function FileBrowser({ basePath = '', onFileSelect, embedded = false, initialSelectedFile, onDirectoryLoad, onPreviewStateChange, allowNavigateAboveBase = false }, ref) {
|
||||
export const FileBrowser = forwardRef<FileBrowserHandle, FileBrowserProps>(function FileBrowser({ basePath = '', onFileSelect, embedded = false, initialSelectedFile, onDirectoryLoad, onPreviewStateChange, allowNavigateAboveBase = false, compact = false }, ref) {
|
||||
const [currentPath, setCurrentPath] = useState(basePath)
|
||||
const [files, setFiles] = useState<FileInfo | null>(null)
|
||||
const [selectedFile, setSelectedFile] = useState<FileInfo | null>(null)
|
||||
@@ -146,6 +147,7 @@ export const FileBrowser = forwardRef<FileBrowserHandle, FileBrowserProps>(funct
|
||||
const uploadCancelledRef = useRef(false)
|
||||
const loadRequestRef = useRef(0)
|
||||
const isMobile = useMobile()
|
||||
const stacked = isMobile || compact
|
||||
|
||||
const { data: initialFileData, error: initialFileError } = useFile(initialSelectedFile)
|
||||
|
||||
@@ -257,7 +259,7 @@ useEffect(() => {
|
||||
onFileSelect?.(fullFileData)
|
||||
|
||||
// On mobile, open preview in modal
|
||||
if (isMobile) {
|
||||
if (stacked) {
|
||||
setIsPreviewModalOpen(true)
|
||||
onPreviewStateChange?.(true)
|
||||
}
|
||||
@@ -267,7 +269,7 @@ useEffect(() => {
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [onFileSelect, isMobile, onPreviewStateChange, loadFiles])
|
||||
}, [onFileSelect, stacked, onPreviewStateChange, loadFiles])
|
||||
|
||||
const handleFileSelect = useCallback(async (file: FileInfo) => {
|
||||
if (file.isDirectory) {
|
||||
@@ -465,10 +467,10 @@ useEffect(() => {
|
||||
}, [initialFileData, loadFiles])
|
||||
|
||||
useEffect(() => {
|
||||
if (!initialFileData || initialFileData.isDirectory || !isMobile) return
|
||||
if (!initialFileData || initialFileData.isDirectory || !stacked) return
|
||||
setIsPreviewModalOpen(true)
|
||||
onPreviewStateChange?.(true)
|
||||
}, [initialFileData, isMobile, onPreviewStateChange])
|
||||
}, [initialFileData, stacked, onPreviewStateChange])
|
||||
|
||||
useEffect(() => {
|
||||
const handleFileSaved = (event: CustomEvent<{ path: string; content?: string }>) => {
|
||||
@@ -600,7 +602,12 @@ useEffect(() => {
|
||||
|
||||
{/* Mobile: Full width file listing, Desktop: Split view */}
|
||||
<div className="flex-1 flex overflow-hidden min-h-0 h-full">
|
||||
<div className={`${isMobile ? 'w-full' : 'w-[30%]'} border-r border-border px-1 md:px-4 flex flex-col min-h-0 h-full`}>
|
||||
{compact && !isMobile && isPreviewModalOpen && selectedFile && !selectedFile.isDirectory ? (
|
||||
<div className="flex-1 min-h-0 overflow-hidden">
|
||||
<FilePreview key={selectedFile.path} file={selectedFile} isMobileModal onCloseModal={handleCloseModal} onOpenFile={openFilePath} />
|
||||
</div>
|
||||
) : (
|
||||
<div className={`${stacked ? 'w-full' : 'w-[30%]'} border-r border-border px-1 md:px-4 flex flex-col min-h-0 h-full`}>
|
||||
<div className="flex items-center gap-2 mb-4 mt-4 flex-shrink-0">
|
||||
<Input
|
||||
placeholder="Search"
|
||||
@@ -645,9 +652,10 @@ useEffect(() => {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Desktop only: Preview panel */}
|
||||
{!isMobile && (
|
||||
{!stacked && (
|
||||
<div className="flex-1 overflow-y-auto min-h-0 h-full">
|
||||
{selectedFile && !selectedFile.isDirectory ? (
|
||||
<FilePreview key={selectedFile.path} file={selectedFile} onOpenFile={openFilePath} />
|
||||
@@ -711,7 +719,7 @@ useEffect(() => {
|
||||
|
||||
<CardContent className="flex-1 flex overflow-hidden min-h-0">
|
||||
{/* Mobile: Full width file listing, Desktop: Split view */}
|
||||
<div className={`${isMobile ? 'w-full' : 'w-1/3'} border-r pr-4 flex flex-col min-h-0`}>
|
||||
<div className={`${stacked ? 'w-full' : 'w-1/3'} border-r pr-4 flex flex-col min-h-0`}>
|
||||
<div className="flex items-center gap-2 mb-4 flex-shrink-0">
|
||||
<Input
|
||||
placeholder="Search"
|
||||
@@ -749,7 +757,7 @@ useEffect(() => {
|
||||
</div>
|
||||
|
||||
{/* Desktop only: Preview panel */}
|
||||
{!isMobile && (
|
||||
{!stacked && (
|
||||
<div className="flex-1 overflow-y-auto min-h-0 ">
|
||||
{selectedFile && !selectedFile.isDirectory ? (
|
||||
<FilePreview key={selectedFile.path} file={selectedFile} onOpenFile={openFilePath} />
|
||||
|
||||
Reference in new issue
Block a user