-
Notifications
You must be signed in to change notification settings - Fork 524
fix: add project path validation across all project switching methods #341
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4abf4bb
fix: add project path validation across all project switching methods
illia1f d58f756
refactor: implement project path validation logic and hooks
illia1f bbe533d
refactor: streamline project cycling logic and remove Inconsistent in…
illia1f 21e6daa
test: enhance profiles CRUD tests with temporary directory setup
illia1f f21bc42
Merge branch 'main' into fix/project-path-validation
illia1f 58903a8
fix: format project path validation files with prettier
illia1f 61eb3a0
Merge branch 'main' into fix/project-path-validation
illia1f 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
129 changes: 129 additions & 0 deletions
129
apps/ui/src/components/dialogs/project-path-validation-dialog.tsx
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,129 @@ | ||
| import { FolderX, RefreshCw, Trash2, AlertTriangle } from 'lucide-react'; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from '@/components/ui/dialog'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { HotkeyButton } from '@/components/ui/hotkey-button'; | ||
| import type { Project } from '@/lib/electron'; | ||
| import { useFileBrowser } from '@/contexts/file-browser-context'; | ||
|
|
||
| interface ProjectPathValidationDialogProps { | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| project: Project | null; | ||
| onRefreshPath: (project: Project, newPath: string) => Promise<void>; | ||
| onRemoveProject: (project: Project) => void; | ||
| onDismiss?: () => void; | ||
| } | ||
|
|
||
| export function ProjectPathValidationDialog({ | ||
| open, | ||
| onOpenChange, | ||
| project, | ||
| onRefreshPath, | ||
| onRemoveProject, | ||
| onDismiss, | ||
| }: ProjectPathValidationDialogProps) { | ||
| const { openFileBrowser } = useFileBrowser(); | ||
|
|
||
| const handleRefreshPath = async () => { | ||
| if (!project) return; | ||
|
|
||
| const newPath = await openFileBrowser({ | ||
| title: 'Select New Project Location', | ||
| description: 'Choose the new directory for this project', | ||
| initialPath: project.path, | ||
| }); | ||
|
|
||
| if (!newPath) { | ||
| // User cancelled - stay on dialog | ||
| return; | ||
| } | ||
|
|
||
| await onRefreshPath(project, newPath); | ||
| }; | ||
|
|
||
| const handleRemoveProject = () => { | ||
| if (!project) return; | ||
| onRemoveProject(project); | ||
| onOpenChange(false); | ||
| }; | ||
|
|
||
| const handleDismiss = () => { | ||
| onDismiss?.(); | ||
| onOpenChange(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog open={open} onOpenChange={onOpenChange}> | ||
| <DialogContent | ||
| className="max-w-md gap-4 shadow-xl border-destructive/20 p-5" | ||
| onInteractOutside={(e) => e.preventDefault()} | ||
| showCloseButton={false} | ||
| > | ||
| <DialogHeader className="space-y-1"> | ||
| <div className="flex items-center gap-2 mb-1"> | ||
| <div className="w-8 h-8 rounded-full bg-destructive/10 flex items-center justify-center shrink-0"> | ||
| <FolderX className="w-4 h-4 text-destructive" /> | ||
| </div> | ||
| <DialogTitle className="text-lg">Project Path Not Found</DialogTitle> | ||
| </div> | ||
| <DialogDescription> | ||
| The project directory cannot be found at its saved location. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| {project && ( | ||
| <div className="space-y-3"> | ||
| <div className="bg-muted/30 border rounded-lg p-3 space-y-2"> | ||
| <div className="flex items-start gap-2.5"> | ||
| <AlertTriangle className="w-4 h-4 text-warning shrink-0 mt-0.5" /> | ||
| <div className="space-y-0.5 min-w-0 flex-1"> | ||
| <p className="font-medium text-sm leading-none truncate">{project.name}</p> | ||
| <p className="text-xs font-mono text-muted-foreground break-all opacity-80"> | ||
| {project.path} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <p className="text-xs text-muted-foreground"> | ||
| Select the new location if it was moved, or remove it from your list. | ||
| </p> | ||
| </div> | ||
| )} | ||
|
|
||
| <DialogFooter className="gap-2 sm:gap-2 mt-2"> | ||
| <Button variant="ghost" onClick={handleDismiss} size="sm" className="h-9 px-3"> | ||
| Dismiss | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={handleRemoveProject} | ||
| size="sm" | ||
| className="h-9 px-3 text-destructive hover:text-destructive hover:bg-destructive/10 border-destructive/20 hover:border-destructive/30" | ||
| > | ||
| <Trash2 className="w-4 h-4 mr-2" /> | ||
| Remove | ||
| </Button> | ||
| <HotkeyButton | ||
| variant="default" | ||
| onClick={handleRefreshPath} | ||
| hotkey={{ key: 'Enter', cmdCtrl: true }} | ||
| hotkeyActive={open} | ||
| size="sm" | ||
| className="h-9 px-3" | ||
| > | ||
| <RefreshCw className="w-4 h-4 mr-2" /> | ||
| Locate Project | ||
| </HotkeyButton> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } |
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
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,94 @@ | ||
| import { useState, useCallback } from 'react'; | ||
| import { useNavigate } from '@tanstack/react-router'; | ||
| import { toast } from 'sonner'; | ||
| import type { Project } from '@/lib/electron'; | ||
| import { useAppStore } from '@/store/app-store'; | ||
| import { validateProjectPath } from '@/lib/validate-project-path'; | ||
|
|
||
| interface UseProjectPathValidationOptions { | ||
| /** | ||
| * Whether to navigate to /board after successful path refresh. | ||
| * Defaults to true. | ||
| */ | ||
| navigateOnRefresh?: boolean; | ||
| } | ||
|
|
||
| export function useProjectPathValidation(options: UseProjectPathValidationOptions = {}) { | ||
| const { navigateOnRefresh = true } = options; | ||
| const navigate = useNavigate(); | ||
| const { projects, setProjects, setCurrentProject, removeProject } = useAppStore(); | ||
|
|
||
| const [validationDialogOpen, setValidationDialogOpen] = useState(false); | ||
| const [invalidProject, setInvalidProject] = useState<Project | null>(null); | ||
|
|
||
| const showValidationDialog = useCallback((project: Project) => { | ||
| setInvalidProject(project); | ||
| setValidationDialogOpen(true); | ||
| }, []); | ||
|
|
||
| const handleRefreshPath = useCallback( | ||
| async (project: Project, newPath: string) => { | ||
| try { | ||
| // Validate new path | ||
| const isValid = await validateProjectPath({ ...project, path: newPath }); | ||
|
|
||
| if (!isValid) { | ||
| toast.error('Invalid path', { | ||
| description: 'Selected path does not exist or is not accessible', | ||
| }); | ||
| return; // Stay on dialog | ||
| } | ||
|
|
||
| // Update project in store | ||
| const updatedProject = { ...project, path: newPath, lastOpened: new Date().toISOString() }; | ||
| const updatedProjects = projects.map((p) => (p.id === project.id ? updatedProject : p)); | ||
| setProjects(updatedProjects); | ||
|
|
||
| // Update current project reference | ||
| setCurrentProject(updatedProject); | ||
|
|
||
| // Close dialog | ||
| setValidationDialogOpen(false); | ||
|
|
||
| // Navigate to board if requested | ||
| if (navigateOnRefresh) { | ||
| navigate({ to: '/board' }); | ||
| } | ||
|
|
||
| toast.success('Project path updated'); | ||
| } catch (error) { | ||
| console.error('Failed to update project path:', error); | ||
| toast.error('Failed to update path', { | ||
| description: 'An unexpected error occurred. Please try again.', | ||
| }); | ||
| } | ||
| }, | ||
| [projects, setProjects, setCurrentProject, navigate, navigateOnRefresh] | ||
| ); | ||
|
|
||
| const handleRemoveProject = useCallback( | ||
| (project: Project) => { | ||
| removeProject(project.id); | ||
| setCurrentProject(null); | ||
| setValidationDialogOpen(false); | ||
| navigate({ to: '/' }); | ||
| toast.info('Project removed', { description: project.name }); | ||
| }, | ||
| [removeProject, setCurrentProject, navigate] | ||
| ); | ||
|
|
||
| const handleDismiss = useCallback(() => { | ||
| setCurrentProject(null); | ||
| setValidationDialogOpen(false); | ||
| }, [setCurrentProject]); | ||
|
|
||
| return { | ||
| validationDialogOpen, | ||
| setValidationDialogOpen, | ||
| invalidProject, | ||
| showValidationDialog, | ||
| handleRefreshPath, | ||
| handleRemoveProject, | ||
| handleDismiss, | ||
| }; | ||
| } |
Oops, something went wrong.
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.