-
Notifications
You must be signed in to change notification settings - Fork 962
feat (desktop): allow deleting on workspaces page #713
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
26 changes: 26 additions & 0 deletions
26
apps/desktop/src/renderer/react-query/workspaces/useDeleteWorktree.ts
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,26 @@ | ||
| import { trpc } from "renderer/lib/trpc"; | ||
|
|
||
| /** | ||
| * Mutation hook for deleting a closed worktree (one without an active workspace). | ||
| * Handles cache invalidation for worktree-related queries. | ||
| */ | ||
| export function useDeleteWorktree( | ||
| options?: Parameters<typeof trpc.workspaces.deleteWorktree.useMutation>[0], | ||
| ) { | ||
| const utils = trpc.useUtils(); | ||
|
|
||
| return trpc.workspaces.deleteWorktree.useMutation({ | ||
| ...options, | ||
| onSettled: async (...args) => { | ||
| // Invalidate worktree queries to refresh the list | ||
| await utils.workspaces.getWorktreesByProject.invalidate(); | ||
| await options?.onSettled?.(...args); | ||
| }, | ||
| onSuccess: async (...args) => { | ||
| await options?.onSuccess?.(...args); | ||
| }, | ||
| onError: async (...args) => { | ||
| await options?.onError?.(...args); | ||
| }, | ||
| }); | ||
| } |
120 changes: 120 additions & 0 deletions
120
...renderer/screens/main/components/WorkspacesListView/WorkspaceRow/DeleteWorktreeDialog.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,120 @@ | ||
| import { | ||
| AlertDialog, | ||
| AlertDialogContent, | ||
| AlertDialogDescription, | ||
| AlertDialogFooter, | ||
| AlertDialogHeader, | ||
| AlertDialogTitle, | ||
| } from "@superset/ui/alert-dialog"; | ||
| import { Button } from "@superset/ui/button"; | ||
| import { toast } from "@superset/ui/sonner"; | ||
| import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; | ||
| import { trpc } from "renderer/lib/trpc"; | ||
| import { useDeleteWorktree } from "renderer/react-query/workspaces/useDeleteWorktree"; | ||
|
|
||
| interface DeleteWorktreeDialogProps { | ||
| worktreeId: string; | ||
| worktreeName: string; | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| } | ||
|
|
||
| export function DeleteWorktreeDialog({ | ||
| worktreeId, | ||
| worktreeName, | ||
| open, | ||
| onOpenChange, | ||
| }: DeleteWorktreeDialogProps) { | ||
| const deleteWorktree = useDeleteWorktree(); | ||
|
|
||
| const { data: canDeleteData, isLoading } = | ||
| trpc.workspaces.canDeleteWorktree.useQuery( | ||
| { worktreeId }, | ||
| { | ||
| enabled: open, | ||
| staleTime: Number.POSITIVE_INFINITY, | ||
| }, | ||
| ); | ||
|
|
||
| const handleDelete = () => { | ||
| onOpenChange(false); | ||
|
|
||
| toast.promise(deleteWorktree.mutateAsync({ worktreeId }), { | ||
| loading: `Deleting "${worktreeName}"...`, | ||
| success: `Deleted "${worktreeName}"`, | ||
| error: (error) => | ||
| error instanceof Error ? error.message : "Failed to delete", | ||
| }); | ||
| }; | ||
|
|
||
| const canDelete = canDeleteData?.canDelete ?? true; | ||
| const reason = canDeleteData?.reason; | ||
| const hasChanges = canDeleteData?.hasChanges ?? false; | ||
| const hasUnpushedCommits = canDeleteData?.hasUnpushedCommits ?? false; | ||
| const hasWarnings = hasChanges || hasUnpushedCommits; | ||
|
|
||
| return ( | ||
| <AlertDialog open={open} onOpenChange={onOpenChange}> | ||
| <AlertDialogContent className="max-w-[340px] gap-0 p-0"> | ||
| <AlertDialogHeader className="px-4 pt-4 pb-2"> | ||
| <AlertDialogTitle className="font-medium"> | ||
| Delete worktree "{worktreeName}"? | ||
| </AlertDialogTitle> | ||
| <AlertDialogDescription asChild> | ||
| <div className="text-muted-foreground space-y-1.5"> | ||
| {isLoading ? ( | ||
| "Checking status..." | ||
| ) : !canDelete ? ( | ||
| <span className="text-destructive">{reason}</span> | ||
| ) : ( | ||
| <span className="block"> | ||
| This will permanently delete the worktree and its files from | ||
| disk. | ||
| </span> | ||
| )} | ||
| </div> | ||
| </AlertDialogDescription> | ||
| </AlertDialogHeader> | ||
|
|
||
| {!isLoading && canDelete && hasWarnings && ( | ||
| <div className="px-4 pb-2"> | ||
| <div className="text-sm text-amber-700 dark:text-amber-300 bg-amber-100 dark:bg-amber-950/50 border border-amber-200 dark:border-amber-800 rounded px-2 py-1.5"> | ||
| {hasChanges && hasUnpushedCommits | ||
| ? "Has uncommitted changes and unpushed commits" | ||
| : hasChanges | ||
| ? "Has uncommitted changes" | ||
| : "Has unpushed commits"} | ||
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
| <AlertDialogFooter className="px-4 pb-4 pt-2 flex-row justify-end gap-2"> | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| className="h-7 px-3 text-xs" | ||
| onClick={() => onOpenChange(false)} | ||
| > | ||
| Cancel | ||
| </Button> | ||
| <Tooltip delayDuration={400}> | ||
| <TooltipTrigger asChild> | ||
| <Button | ||
| variant="destructive" | ||
| size="sm" | ||
| className="h-7 px-3 text-xs" | ||
| onClick={handleDelete} | ||
| disabled={!canDelete || isLoading} | ||
| > | ||
| Delete | ||
| </Button> | ||
|
Comment on lines
+102
to
+110
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add The delete button should also be disabled while the mutation is in progress to prevent multiple deletion attempts if the user clicks rapidly before the dialog closes. 🐛 Proposed fix <Button
variant="destructive"
size="sm"
className="h-7 px-3 text-xs"
onClick={handleDelete}
- disabled={!canDelete || isLoading}
+ disabled={!canDelete || isLoading || deleteWorktree.isPending}
>
Delete
</Button>🤖 Prompt for AI Agents |
||
| </TooltipTrigger> | ||
| <TooltipContent side="top" className="text-xs max-w-[200px]"> | ||
| Permanently delete worktree from disk. | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| </AlertDialogFooter> | ||
| </AlertDialogContent> | ||
| </AlertDialog> | ||
| ); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default
canDeletetofalseto prevent premature deletion.Defaulting
canDeletetotruebefore the query completes could allow the user to click "Delete" during the brief window before the query returns. Since the button is also disabled whenisLoading, this is mitigated, but the default should still befalsefor defense-in-depth.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents