Skip to content

Commit 656ab2f

Browse files
authored
Merge pull request #1100 from mosleyit/improvement/task_delete_confirmation_854
Improvement/task delete confirmation 854
2 parents 91ca35d + 1922b8a commit 656ab2f

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from "react"
2+
import {
3+
AlertDialog,
4+
AlertDialogAction,
5+
AlertDialogCancel,
6+
AlertDialogContent,
7+
AlertDialogDescription,
8+
AlertDialogFooter,
9+
AlertDialogHeader,
10+
AlertDialogTitle,
11+
} from "@/components/ui/alert-dialog"
12+
import { Button } from "@/components/ui"
13+
import { vscode } from "@/utils/vscode"
14+
15+
interface DeleteTaskDialogProps {
16+
taskId: string
17+
open: boolean
18+
onOpenChange: (open: boolean) => void
19+
}
20+
21+
export const DeleteTaskDialog = ({ taskId, open, onOpenChange }: DeleteTaskDialogProps) => {
22+
const handleDelete = () => {
23+
vscode.postMessage({ type: "deleteTaskWithId", text: taskId })
24+
onOpenChange(false)
25+
}
26+
27+
return (
28+
<AlertDialog open={open} onOpenChange={onOpenChange}>
29+
<AlertDialogContent>
30+
<AlertDialogHeader>
31+
<AlertDialogTitle>Delete Task</AlertDialogTitle>
32+
<AlertDialogDescription>
33+
Are you sure you want to delete this task? This action cannot be undone.
34+
</AlertDialogDescription>
35+
</AlertDialogHeader>
36+
<AlertDialogFooter>
37+
<AlertDialogCancel asChild>
38+
<Button variant="secondary">Cancel</Button>
39+
</AlertDialogCancel>
40+
<AlertDialogAction asChild>
41+
<Button variant="destructive" onClick={handleDelete}>
42+
Delete
43+
</Button>
44+
</AlertDialogAction>
45+
</AlertDialogFooter>
46+
</AlertDialogContent>
47+
</AlertDialog>
48+
)
49+
}

webview-ui/src/components/history/HistoryView.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { memo, useMemo, useState, useEffect } from "react"
2+
import { DeleteTaskDialog } from "./DeleteTaskDialog"
23
import { Fzf } from "fzf"
34
import prettyBytes from "pretty-bytes"
45
import { Virtuoso } from "react-virtuoso"
@@ -37,8 +38,12 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
3738
vscode.postMessage({ type: "showTaskWithId", text: id })
3839
}
3940

41+
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false)
42+
const [taskToDelete, setTaskToDelete] = useState<string | null>(null)
43+
4044
const handleDeleteHistoryItem = (id: string) => {
41-
vscode.postMessage({ type: "deleteTaskWithId", text: id })
45+
setTaskToDelete(id)
46+
setDeleteDialogOpen(true)
4247
}
4348

4449
const formatDate = (timestamp: number) => {
@@ -398,6 +403,18 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
398403
)}
399404
/>
400405
</div>
406+
{taskToDelete && (
407+
<DeleteTaskDialog
408+
taskId={taskToDelete}
409+
open={deleteDialogOpen}
410+
onOpenChange={(open) => {
411+
setDeleteDialogOpen(open)
412+
if (!open) {
413+
setTaskToDelete(null)
414+
}
415+
}}
416+
/>
417+
)}
401418
</div>
402419
)
403420
}

webview-ui/src/components/history/__tests__/HistoryView.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,22 @@ describe("HistoryView", () => {
135135
})
136136
})
137137

138-
it("handles task deletion", () => {
138+
it("handles task deletion", async () => {
139139
const onDone = jest.fn()
140140
render(<HistoryView onDone={onDone} />)
141141

142142
// Find and hover over first task
143143
const taskContainer = screen.getByTestId("virtuoso-item-1")
144144
fireEvent.mouseEnter(taskContainer)
145145

146+
// Click delete button to open confirmation dialog
146147
const deleteButton = within(taskContainer).getByTitle("Delete Task")
147148
fireEvent.click(deleteButton)
148149

150+
// Find and click the confirm delete button in the dialog
151+
const confirmDeleteButton = screen.getByRole("button", { name: /delete/i })
152+
fireEvent.click(confirmDeleteButton)
153+
149154
// Verify vscode message was sent
150155
expect(vscode.postMessage).toHaveBeenCalledWith({
151156
type: "deleteTaskWithId",

0 commit comments

Comments
 (0)