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,72 @@ interface BatchDeleteTaskDialogProps extends AlertDialogProps {
2122export const BatchDeleteTaskDialog = ( { taskIds, ...props } : BatchDeleteTaskDialogProps ) => {
2223 const { t } = useAppTranslation ( )
2324 const { onOpenChange } = props
25+ const { taskHistory } = useExtensionState ( )
26+
27+ // Check if any of the selected tasks are starred
28+ const starredTaskIds = useMemo ( ( ) => {
29+ return taskIds . filter ( ( id ) => {
30+ const task = taskHistory . find ( ( t ) => t . id === id )
31+ return task ?. isStarred || false
32+ } )
33+ } , [ taskIds , taskHistory ] )
34+
35+ const hasStarredTasks = starredTaskIds . length > 0
36+ const unstarredTaskIds = taskIds . filter ( ( id ) => ! starredTaskIds . includes ( id ) )
2437
2538 const onDelete = useCallback ( ( ) => {
26- if ( taskIds . length > 0 ) {
27- vscode . postMessage ( { type : "deleteMultipleTasksWithIds" , ids : taskIds } )
39+ if ( unstarredTaskIds . length > 0 ) {
40+ vscode . postMessage ( { type : "deleteMultipleTasksWithIds" , ids : unstarredTaskIds } )
2841 onOpenChange ?.( false )
2942 }
30- } , [ taskIds , onOpenChange ] )
43+ } , [ unstarredTaskIds , onOpenChange ] )
3144
3245 return (
3346 < AlertDialog { ...props } >
3447 < AlertDialogContent className = "max-w-md" >
3548 < AlertDialogHeader >
3649 < AlertDialogTitle > { t ( "history:deleteTasks" ) } </ AlertDialogTitle >
3750 < 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 >
51+ { hasStarredTasks ? (
52+ < >
53+ < div className = "mb-2 text-vscode-errorForeground" >
54+ { starredTaskIds . length === taskIds . length
55+ ? "All selected tasks are starred. Please unstar them before deleting."
56+ : `${ starredTaskIds . length } of ${ taskIds . length } selected tasks are starred and will not be deleted.` }
57+ </ div >
58+ { unstarredTaskIds . length > 0 && (
59+ < >
60+ < div className = "mb-2" >
61+ { t ( "history:confirmDeleteTasks" , { count : unstarredTaskIds . length } ) }
62+ </ div >
63+ < div className = "text-vscode-editor-foreground bg-vscode-editor-background p-2 rounded text-sm" >
64+ { t ( "history:deleteTasksWarning" ) }
65+ </ div >
66+ </ >
67+ ) }
68+ </ >
69+ ) : (
70+ < >
71+ < div className = "mb-2" > { t ( "history:confirmDeleteTasks" , { count : taskIds . length } ) } </ div >
72+ < div className = "text-vscode-editor-foreground bg-vscode-editor-background p-2 rounded text-sm" >
73+ { t ( "history:deleteTasksWarning" ) }
74+ </ div >
75+ </ >
76+ ) }
4277 </ AlertDialogDescription >
4378 </ AlertDialogHeader >
4479 < AlertDialogFooter >
4580 < AlertDialogCancel asChild >
4681 < Button variant = "secondary" > { t ( "history:cancel" ) } </ Button >
4782 </ 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 >
83+ { unstarredTaskIds . length > 0 && (
84+ < AlertDialogAction asChild >
85+ < Button variant = "destructive" onClick = { onDelete } >
86+ < span className = "codicon codicon-trash mr-1" > </ span >
87+ { t ( "history:deleteItems" , { count : unstarredTaskIds . length } ) }
88+ </ Button >
89+ </ AlertDialogAction >
90+ ) }
5491 </ AlertDialogFooter >
5592 </ AlertDialogContent >
5693 </ AlertDialog >
0 commit comments