-
Notifications
You must be signed in to change notification settings - Fork 14
🤖 feat: add web directory picker for server projects #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+357
−31
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fdd1ba1
🤖 feat: add project directory picker
ibetitsmike c423339
feat: add web directory picker for server projects
ibetitsmike 1a3348a
chore: format directory picker changes
ibetitsmike 47c77b3
refactor: inject project directory picker for desktop only
ibetitsmike cb59ac3
refactor: format ipcMain project directory picker
ibetitsmike 0f1ada1
🤖 fix: handle directory picker errors in server mode
ibetitsmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import React, { useCallback, useEffect, useState } from "react"; | ||
| import { Modal, ModalActions, CancelButton, PrimaryButton } from "./Modal"; | ||
| import type { FileTreeNode } from "@/common/utils/git/numstatParser"; | ||
| import { DirectoryTree } from "./DirectoryTree"; | ||
| import type { IPCApi } from "@/common/types/ipc"; | ||
|
|
||
| interface DirectoryPickerModalProps { | ||
| isOpen: boolean; | ||
| initialPath: string; | ||
| onClose: () => void; | ||
| onSelectPath: (path: string) => void; | ||
| } | ||
|
|
||
| export const DirectoryPickerModal: React.FC<DirectoryPickerModalProps> = ({ | ||
| isOpen, | ||
| initialPath, | ||
| onClose, | ||
| onSelectPath, | ||
| }) => { | ||
| type FsListDirectoryResponse = FileTreeNode & { success?: boolean; error?: unknown }; | ||
| const [root, setRoot] = useState<FileTreeNode | null>(null); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| const loadDirectory = useCallback(async (path: string) => { | ||
| const api = window.api as unknown as IPCApi; | ||
| if (!api.fs?.listDirectory) { | ||
| setError("Directory picker is not available in this environment."); | ||
| return; | ||
| } | ||
|
|
||
| setIsLoading(true); | ||
| setError(null); | ||
|
|
||
| try { | ||
| const tree = (await api.fs.listDirectory(path)) as FsListDirectoryResponse; | ||
|
|
||
| // In browser/server mode, HttpIpcMainAdapter wraps handler errors as | ||
| // { success: false, error }, and invokeIPC returns that object instead | ||
| // of throwing. Detect that shape and surface a friendly error instead | ||
| // of crashing when accessing tree.children. | ||
| if (tree.success === false) { | ||
| const errorMessage = typeof tree.error === "string" ? tree.error : "Unknown error"; | ||
| setError(`Failed to load directory: ${errorMessage}`); | ||
| setRoot(null); | ||
| return; | ||
| } | ||
|
|
||
| setRoot(tree); | ||
| } catch (err) { | ||
| const message = err instanceof Error ? err.message : String(err); | ||
| setError(`Failed to load directory: ${message}`); | ||
| setRoot(null); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| if (!isOpen) return; | ||
| void loadDirectory(initialPath || "."); | ||
| }, [isOpen, initialPath, loadDirectory]); | ||
|
|
||
| const handleNavigateTo = useCallback( | ||
| (path: string) => { | ||
| void loadDirectory(path); | ||
| }, | ||
| [loadDirectory] | ||
| ); | ||
|
|
||
| const handleNavigateParent = useCallback(() => { | ||
| if (!root) return; | ||
| void loadDirectory(`${root.path}/..`); | ||
| }, [loadDirectory, root]); | ||
|
|
||
| const handleConfirm = useCallback(() => { | ||
| if (!root) { | ||
| return; | ||
| } | ||
|
|
||
| onSelectPath(root.path); | ||
| onClose(); | ||
| }, [onClose, onSelectPath, root]); | ||
|
|
||
| if (!isOpen) return null; | ||
| const entries = | ||
| root?.children | ||
| .filter((child) => child.isDirectory) | ||
| .map((child) => ({ name: child.name, path: child.path })) ?? []; | ||
|
|
||
| return ( | ||
| <Modal | ||
| isOpen={isOpen} | ||
| title="Select Project Directory" | ||
| subtitle={root ? root.path : "Select a directory to use as your project root"} | ||
| onClose={onClose} | ||
| isLoading={isLoading} | ||
| > | ||
| {error && <div className="text-error mb-3 text-xs">{error}</div>} | ||
| <div className="bg-modal-bg border-border-medium mb-4 h-64 overflow-hidden rounded border"> | ||
| <DirectoryTree | ||
| currentPath={root ? root.path : null} | ||
| entries={entries} | ||
| isLoading={isLoading} | ||
| onNavigateTo={handleNavigateTo} | ||
| onNavigateParent={handleNavigateParent} | ||
| /> | ||
| </div> | ||
| <ModalActions> | ||
| <CancelButton onClick={onClose} disabled={isLoading}> | ||
| Cancel | ||
| </CancelButton> | ||
| <PrimaryButton onClick={() => void handleConfirm()} disabled={isLoading || !root}> | ||
| Select | ||
| </PrimaryButton> | ||
| </ModalActions> | ||
| </Modal> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import React from "react"; | ||
|
|
||
| interface DirectoryTreeEntry { | ||
| name: string; | ||
| path: string; | ||
| } | ||
|
|
||
| interface DirectoryTreeProps { | ||
| currentPath: string | null; | ||
| entries: DirectoryTreeEntry[]; | ||
| isLoading?: boolean; | ||
| onNavigateTo: (path: string) => void; | ||
| onNavigateParent: () => void; | ||
| } | ||
|
|
||
| export const DirectoryTree: React.FC<DirectoryTreeProps> = (props) => { | ||
| const { currentPath, entries, isLoading = false, onNavigateTo, onNavigateParent } = props; | ||
|
|
||
| const hasEntries = entries.length > 0; | ||
| const containerRef = React.useRef<HTMLDivElement | null>(null); | ||
|
|
||
| React.useEffect(() => { | ||
| if (containerRef.current) { | ||
| containerRef.current.scrollTop = 0; | ||
| } | ||
| }, [currentPath]); | ||
|
|
||
| return ( | ||
| <div ref={containerRef} className="h-full overflow-y-auto p-2 font-mono text-xs"> | ||
| {isLoading && !currentPath ? ( | ||
| <div className="text-muted py-4 text-center">Loading directories...</div> | ||
| ) : ( | ||
| <ul className="m-0 list-none p-0"> | ||
| {currentPath && ( | ||
| <li | ||
| className="text-muted cursor-pointer rounded px-2 py-1 text-xs hover:bg-white/5" | ||
| onClick={onNavigateParent} | ||
| > | ||
| ... | ||
| </li> | ||
| )} | ||
|
|
||
| {!isLoading && !hasEntries ? ( | ||
| <li className="text-muted px-2 py-1 text-xs">No subdirectories found</li> | ||
| ) : null} | ||
|
|
||
| {entries.map((entry) => ( | ||
| <li | ||
| key={entry.path} | ||
| className="text-muted cursor-pointer rounded px-2 py-1 text-xs hover:bg-white/5" | ||
| onClick={() => onNavigateTo(entry.path)} | ||
| > | ||
| {entry.name} | ||
| </li> | ||
| ))} | ||
|
|
||
| {isLoading && currentPath && !hasEntries ? ( | ||
| <li className="text-muted px-2 py-1 text-xs">Loading directories...</li> | ||
| ) : null} | ||
| </ul> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.