1- import { useCallback } from "react"
1+ import { useCallback , useMemo } from "react"
22import { useAppTranslation } from "@/i18n/TranslationContext"
33import {
44 AlertDialog ,
@@ -13,6 +13,7 @@ import {
1313} from "@/components/ui"
1414import { vscode } from "@/utils/vscode"
1515import { AlertDialogProps } from "@radix-ui/react-alert-dialog"
16+ import { useExtensionState } from "@/context/ExtensionStateContext"
1617
1718interface BatchDeleteTaskDialogProps extends AlertDialogProps {
1819 taskIds : string [ ]
@@ -21,36 +22,73 @@ interface BatchDeleteTaskDialogProps extends AlertDialogProps {
2122export const BatchDeleteTaskDialog = ( { taskIds, ...props } : BatchDeleteTaskDialogProps ) => {
2223 const { t } = useAppTranslation ( )
2324 const { onOpenChange } = props
25+ const { taskHistory } = useExtensionState ( )
26+
27+ // Filter out starred tasks
28+ const { deletableTaskIds, starredCount } = useMemo ( ( ) => {
29+ const deletable : string [ ] = [ ]
30+ let starred = 0
31+
32+ taskIds . forEach ( ( id ) => {
33+ const task = taskHistory . find ( ( item ) => item . id === id )
34+ if ( task ?. starred ) {
35+ starred ++
36+ } else {
37+ deletable . push ( id )
38+ }
39+ } )
40+
41+ return { deletableTaskIds : deletable , starredCount : starred }
42+ } , [ taskIds , taskHistory ] )
2443
2544 const onDelete = useCallback ( ( ) => {
26- if ( taskIds . length > 0 ) {
27- vscode . postMessage ( { type : "deleteMultipleTasksWithIds" , ids : taskIds } )
45+ if ( deletableTaskIds . length > 0 ) {
46+ vscode . postMessage ( { type : "deleteMultipleTasksWithIds" , ids : deletableTaskIds } )
2847 onOpenChange ?.( false )
2948 }
30- } , [ taskIds , onOpenChange ] )
49+ } , [ deletableTaskIds , onOpenChange ] )
3150
3251 return (
3352 < AlertDialog { ...props } >
3453 < AlertDialogContent className = "max-w-md" >
3554 < AlertDialogHeader >
3655 < AlertDialogTitle > { t ( "history:deleteTasks" ) } </ AlertDialogTitle >
3756 < AlertDialogDescription className = "text-vscode-foreground" >
38- < div className = "mb-2" > { t ( "history:confirmDeleteTasks" , { count : taskIds . length } ) } </ div >
39- < div className = "text-vscode-editor-foreground bg-vscode-editor-background p-2 rounded text-sm" >
40- { t ( "history:deleteTasksWarning" ) }
41- </ div >
57+ { starredCount > 0 ? (
58+ < >
59+ < div className = "mb-2 text-vscode-notificationsWarningIcon-foreground" >
60+ { t ( "history:starredTasksExcluded" , { count : starredCount } ) }
61+ </ div >
62+ { deletableTaskIds . length > 0 && (
63+ < div className = "mb-2" >
64+ { t ( "history:confirmDeleteTasks" , { count : deletableTaskIds . length } ) }
65+ </ div >
66+ ) }
67+ </ >
68+ ) : (
69+ < div className = "mb-2" >
70+ { t ( "history:confirmDeleteTasks" , { count : deletableTaskIds . length } ) }
71+ </ div >
72+ ) }
73+ { deletableTaskIds . length > 0 && (
74+ < div className = "text-vscode-editor-foreground bg-vscode-editor-background p-2 rounded text-sm" >
75+ { t ( "history:deleteTasksWarning" ) }
76+ </ div >
77+ ) }
4278 </ AlertDialogDescription >
4379 </ AlertDialogHeader >
4480 < AlertDialogFooter >
4581 < AlertDialogCancel asChild >
4682 < Button variant = "secondary" > { t ( "history:cancel" ) } </ Button >
4783 </ AlertDialogCancel >
48- < AlertDialogAction asChild >
49- < Button variant = "destructive" onClick = { onDelete } >
50- < span className = "codicon codicon-trash mr-1" > </ span >
51- { t ( "history:deleteItems" , { count : taskIds . length } ) }
52- </ Button >
53- </ AlertDialogAction >
84+ { deletableTaskIds . length > 0 && (
85+ < AlertDialogAction asChild >
86+ < Button variant = "destructive" onClick = { onDelete } >
87+ < span className = "codicon codicon-trash mr-1" > </ span >
88+ { t ( "history:deleteItems" , { count : deletableTaskIds . length } ) }
89+ </ Button >
90+ </ AlertDialogAction >
91+ ) }
5492 </ AlertDialogFooter >
5593 </ AlertDialogContent >
5694 </ AlertDialog >
0 commit comments