-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add button to delete checkpoints only #10802
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
Draft
roomote
wants to merge
1
commit into
main
Choose a base branch
from
feature/delete-checkpoints-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions
39
webview-ui/src/components/history/DeleteCheckpointsButton.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,39 @@ | ||
| import { useCallback } from "react" | ||
|
|
||
| import { Button, StandardTooltip } from "@/components/ui" | ||
| import { useAppTranslation } from "@/i18n/TranslationContext" | ||
| import { vscode } from "@/utils/vscode" | ||
|
|
||
| type DeleteCheckpointsButtonProps = { | ||
| itemId: string | ||
| onDeleteCheckpoints?: (taskId: string) => void | ||
| } | ||
|
|
||
| export const DeleteCheckpointsButton = ({ itemId, onDeleteCheckpoints }: DeleteCheckpointsButtonProps) => { | ||
| const { t } = useAppTranslation() | ||
|
|
||
| const handleDeleteCheckpointsClick = useCallback( | ||
| (e: React.MouseEvent) => { | ||
| e.stopPropagation() | ||
| if (e.shiftKey) { | ||
| vscode.postMessage({ type: "deleteTaskCheckpointsWithId", text: itemId }) | ||
| } else if (onDeleteCheckpoints) { | ||
| onDeleteCheckpoints(itemId) | ||
| } | ||
| }, | ||
| [itemId, onDeleteCheckpoints], | ||
| ) | ||
|
|
||
| return ( | ||
| <StandardTooltip content={t("history:deleteCheckpointsTitle")}> | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| data-testid="delete-checkpoints-button" | ||
| onClick={handleDeleteCheckpointsClick} | ||
| className="opacity-70"> | ||
| <span className="codicon codicon-history size-4 align-middle text-vscode-descriptionForeground" /> | ||
| </Button> | ||
| </StandardTooltip> | ||
| ) | ||
| } |
63 changes: 63 additions & 0 deletions
63
webview-ui/src/components/history/DeleteCheckpointsDialog.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,63 @@ | ||
| import { useCallback, useEffect } from "react" | ||
| import { useKeyPress } from "react-use" | ||
| import { AlertDialogProps } from "@radix-ui/react-alert-dialog" | ||
|
|
||
| import { | ||
| AlertDialog, | ||
| AlertDialogAction, | ||
| AlertDialogCancel, | ||
| AlertDialogContent, | ||
| AlertDialogDescription, | ||
| AlertDialogFooter, | ||
| AlertDialogHeader, | ||
| AlertDialogTitle, | ||
| Button, | ||
| } from "@/components/ui" | ||
| import { useAppTranslation } from "@/i18n/TranslationContext" | ||
|
|
||
| import { vscode } from "@/utils/vscode" | ||
|
|
||
| interface DeleteCheckpointsDialogProps extends AlertDialogProps { | ||
| taskId: string | ||
| } | ||
|
|
||
| export const DeleteCheckpointsDialog = ({ taskId, ...props }: DeleteCheckpointsDialogProps) => { | ||
| const { t } = useAppTranslation() | ||
| const [isEnterPressed] = useKeyPress("Enter") | ||
|
|
||
| const { onOpenChange } = props | ||
|
|
||
| const onDeleteCheckpoints = useCallback(() => { | ||
| if (taskId) { | ||
| vscode.postMessage({ type: "deleteTaskCheckpointsWithId", text: taskId }) | ||
| onOpenChange?.(false) | ||
| } | ||
| }, [taskId, onOpenChange]) | ||
|
|
||
| useEffect(() => { | ||
| if (taskId && isEnterPressed) { | ||
| onDeleteCheckpoints() | ||
| } | ||
| }, [taskId, isEnterPressed, onDeleteCheckpoints]) | ||
|
|
||
| return ( | ||
| <AlertDialog {...props}> | ||
| <AlertDialogContent onEscapeKeyDown={() => onOpenChange?.(false)}> | ||
| <AlertDialogHeader> | ||
| <AlertDialogTitle>{t("history:deleteCheckpoints")}</AlertDialogTitle> | ||
| <AlertDialogDescription>{t("history:deleteCheckpointsMessage")}</AlertDialogDescription> | ||
| </AlertDialogHeader> | ||
| <AlertDialogFooter> | ||
| <AlertDialogCancel asChild> | ||
| <Button variant="secondary">{t("history:cancel")}</Button> | ||
| </AlertDialogCancel> | ||
| <AlertDialogAction asChild> | ||
| <Button variant="destructive" onClick={onDeleteCheckpoints}> | ||
| {t("history:delete")} | ||
| </Button> | ||
| </AlertDialogAction> | ||
| </AlertDialogFooter> | ||
| </AlertDialogContent> | ||
| </AlertDialog> | ||
| ) | ||
| } |
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
21 changes: 21 additions & 0 deletions
21
webview-ui/src/components/history/__tests__/DeleteCheckpointsButton.spec.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,21 @@ | ||
| import { render, screen, fireEvent } from "@/utils/test-utils" | ||
|
|
||
| import { DeleteCheckpointsButton } from "../DeleteCheckpointsButton" | ||
|
|
||
| vi.mock("@src/i18n/TranslationContext", () => ({ | ||
| useAppTranslation: () => ({ | ||
| t: (key: string) => key, | ||
| }), | ||
| })) | ||
|
|
||
| describe("DeleteCheckpointsButton", () => { | ||
| it("calls onDeleteCheckpoints when clicked", () => { | ||
| const onDeleteCheckpoints = vi.fn() | ||
| render(<DeleteCheckpointsButton itemId="test-id" onDeleteCheckpoints={onDeleteCheckpoints} />) | ||
|
|
||
| const deleteCheckpointsButton = screen.getByRole("button") | ||
| fireEvent.click(deleteCheckpointsButton) | ||
|
|
||
| expect(onDeleteCheckpoints).toHaveBeenCalledWith("test-id") | ||
| }) | ||
| }) |
74 changes: 74 additions & 0 deletions
74
webview-ui/src/components/history/__tests__/DeleteCheckpointsDialog.spec.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,74 @@ | ||
| import { render, screen, fireEvent, act } from "@/utils/test-utils" | ||
|
|
||
| import { DeleteCheckpointsDialog } from "../DeleteCheckpointsDialog" | ||
| import { vscode } from "@/utils/vscode" | ||
|
|
||
| vi.mock("@src/i18n/TranslationContext", () => ({ | ||
| useAppTranslation: () => ({ | ||
| t: (key: string) => key, | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock("@/utils/vscode", () => ({ | ||
| vscode: { | ||
| postMessage: vi.fn(), | ||
| }, | ||
| })) | ||
|
|
||
| describe("DeleteCheckpointsDialog", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it("renders dialog with correct content", async () => { | ||
| await act(async () => { | ||
| render(<DeleteCheckpointsDialog taskId="test-id" open={true} onOpenChange={() => {}} />) | ||
| }) | ||
|
|
||
| expect(screen.getByText("history:deleteCheckpoints")).toBeInTheDocument() | ||
| expect(screen.getByText("history:deleteCheckpointsMessage")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("calls vscode.postMessage when delete is confirmed", async () => { | ||
| const onOpenChange = vi.fn() | ||
| await act(async () => { | ||
| render(<DeleteCheckpointsDialog taskId="test-id" open={true} onOpenChange={onOpenChange} />) | ||
| }) | ||
|
|
||
| await act(async () => { | ||
| fireEvent.click(screen.getByText("history:delete")) | ||
| }) | ||
|
|
||
| expect(vscode.postMessage).toHaveBeenCalledWith({ | ||
| type: "deleteTaskCheckpointsWithId", | ||
| text: "test-id", | ||
| }) | ||
| expect(onOpenChange).toHaveBeenCalledWith(false) | ||
| }) | ||
|
|
||
| it("calls onOpenChange when cancel is clicked", async () => { | ||
| const onOpenChange = vi.fn() | ||
| await act(async () => { | ||
| render(<DeleteCheckpointsDialog taskId="test-id" open={true} onOpenChange={onOpenChange} />) | ||
| }) | ||
|
|
||
| await act(async () => { | ||
| fireEvent.click(screen.getByText("history:cancel")) | ||
| }) | ||
|
|
||
| expect(vscode.postMessage).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not call vscode.postMessage when taskId is empty", async () => { | ||
| const onOpenChange = vi.fn() | ||
| await act(async () => { | ||
| render(<DeleteCheckpointsDialog taskId="" open={true} onOpenChange={onOpenChange} />) | ||
| }) | ||
|
|
||
| await act(async () => { | ||
| fireEvent.click(screen.getByText("history:delete")) | ||
| }) | ||
|
|
||
| expect(vscode.postMessage).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
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.
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.
This test is named "calls onOpenChange when cancel is clicked" but it doesn't actually assert that
onOpenChangeis called. Compare with the existingDeleteTaskDialog.spec.tsxwhich properly includesexpect(mockOnOpenChange).toHaveBeenCalledWith(false). The missing assertion should be added to verify the behavior claimed by the test name.Fix it with Roo Code or mention @roomote and request a fix.