1- import React , { memo , useState , useMemo } from "react"
2- import { ArrowLeft , Settings } from "lucide-react"
1+ import React , { memo , useState , useMemo , useCallback , useEffect } from "react"
2+ import { ArrowLeft , Settings , FolderOpen , RefreshCw , Loader2 } from "lucide-react"
33import { DeleteTaskDialog } from "./DeleteTaskDialog"
44import { BatchDeleteTaskDialog } from "./BatchDeleteTaskDialog"
55import { Virtuoso } from "react-virtuoso"
@@ -11,6 +11,14 @@ import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
1111import { vscode } from "@/utils/vscode"
1212import { useExtensionState } from "@/context/ExtensionStateContext"
1313import {
14+ AlertDialog ,
15+ AlertDialogAction ,
16+ AlertDialogCancel ,
17+ AlertDialogContent ,
18+ AlertDialogDescription ,
19+ AlertDialogFooter ,
20+ AlertDialogHeader ,
21+ AlertDialogTitle ,
1422 Button ,
1523 Checkbox ,
1624 Popover ,
@@ -48,7 +56,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
4856 showAllWorkspaces,
4957 setShowAllWorkspaces,
5058 } = useTaskSearch ( )
51- const { taskHistoryRetention } = useExtensionState ( )
59+ const { taskHistoryRetention, taskHistorySize } = useExtensionState ( )
5260 const { t } = useAppTranslation ( )
5361
5462 // Use grouped tasks hook
@@ -60,6 +68,39 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
6068 const [ selectedTaskIds , setSelectedTaskIds ] = useState < string [ ] > ( [ ] )
6169 const [ showBatchDeleteDialog , setShowBatchDeleteDialog ] = useState < boolean > ( false )
6270 const [ isRetentionPopoverOpen , setIsRetentionPopoverOpen ] = useState ( false )
71+ const [ pendingRetention , setPendingRetention ] = useState < TaskHistoryRetentionSetting | null > ( null )
72+ const [ showRetentionConfirmDialog , setShowRetentionConfirmDialog ] = useState ( false )
73+ const [ isRefreshingTaskCount , setIsRefreshingTaskCount ] = useState ( false )
74+ const [ cachedTaskCount , setCachedTaskCount ] = useState < number | undefined > ( taskHistorySize ?. taskCount )
75+
76+ // Update cached task count when taskHistorySize changes
77+ useEffect ( ( ) => {
78+ if ( taskHistorySize ) {
79+ setCachedTaskCount ( taskHistorySize . taskCount )
80+ setIsRefreshingTaskCount ( false )
81+ }
82+ } , [ taskHistorySize ] )
83+
84+ // Handle refresh task count
85+ const handleRefreshTaskCount = useCallback ( ( ) => {
86+ setIsRefreshingTaskCount ( true )
87+ vscode . postMessage ( { type : "refreshTaskHistorySize" } )
88+ } , [ ] )
89+
90+ // Get task count display text
91+ const getTaskCountDisplayText = ( ) : string => {
92+ const count = taskHistorySize ?. taskCount ?? cachedTaskCount
93+ if ( count === undefined ) {
94+ return t ( "settings:taskHistoryStorage.clickToCount" )
95+ }
96+ if ( count === 0 ) {
97+ return t ( "settings:taskHistoryStorage.empty" )
98+ }
99+ if ( count === 1 ) {
100+ return t ( "settings:taskHistoryStorage.countSingular" )
101+ }
102+ return t ( "settings:taskHistoryStorage.count" , { count } )
103+ }
63104
64105 // Normalize retention setting to ensure it's valid
65106 const normalizedRetention : TaskHistoryRetentionSetting = TASK_HISTORY_RETENTION_OPTIONS . includes (
@@ -68,9 +109,31 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
68109 ? ( taskHistoryRetention as TaskHistoryRetentionSetting )
69110 : "never"
70111
71- // Handle retention setting change
112+ // Handle retention setting change - show confirmation dialog first
72113 const handleRetentionChange = ( value : TaskHistoryRetentionSetting ) => {
73- vscode . postMessage ( { type : "updateSettings" , updatedSettings : { taskHistoryRetention : value } } )
114+ // If selecting the same value, do nothing
115+ if ( value === normalizedRetention ) {
116+ return
117+ }
118+ // Show confirmation dialog for any change
119+ setPendingRetention ( value )
120+ setShowRetentionConfirmDialog ( true )
121+ }
122+
123+ // Confirm retention change
124+ const confirmRetentionChange = ( ) => {
125+ if ( pendingRetention !== null ) {
126+ vscode . postMessage ( { type : "updateSettings" , updatedSettings : { taskHistoryRetention : pendingRetention } } )
127+ }
128+ setShowRetentionConfirmDialog ( false )
129+ setPendingRetention ( null )
130+ setIsRetentionPopoverOpen ( false )
131+ }
132+
133+ // Cancel retention change
134+ const cancelRetentionChange = ( ) => {
135+ setShowRetentionConfirmDialog ( false )
136+ setPendingRetention ( null )
74137 }
75138
76139 // Get subtask count for a task
@@ -148,7 +211,28 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
148211 </ StandardTooltip >
149212 < PopoverContent className = "w-72" align = "end" >
150213 < div className = "space-y-3" >
151- < h4 className = "font-medium text-sm" > { t ( "settings:aboutRetention.label" ) } </ h4 >
214+ { /* Task count display */ }
215+ < div className = "flex items-center gap-2" >
216+ < FolderOpen className = "size-4 text-vscode-descriptionForeground shrink-0" />
217+ < span className = "text-sm" > { getTaskCountDisplayText ( ) } </ span >
218+ < Button
219+ variant = "ghost"
220+ size = "sm"
221+ onClick = { handleRefreshTaskCount }
222+ disabled = { isRefreshingTaskCount }
223+ className = "h-6 w-6 p-0 ml-auto"
224+ title = { t ( "settings:taskHistoryStorage.refresh" ) } >
225+ { isRefreshingTaskCount ? (
226+ < Loader2 className = "size-3.5 animate-spin" />
227+ ) : (
228+ < RefreshCw className = "size-3.5" />
229+ ) }
230+ </ Button >
231+ </ div >
232+
233+ < div className = "border-t border-vscode-settings-headerBorder pt-3" >
234+ < h4 className = "font-medium text-sm" > { t ( "settings:aboutRetention.label" ) } </ h4 >
235+ </ div >
152236 < Select
153237 value = { normalizedRetention }
154238 onValueChange = { ( value : TaskHistoryRetentionSetting ) => {
@@ -175,9 +259,8 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
175259 </ SelectContent >
176260 </ Select >
177261 < p className = "text-vscode-descriptionForeground text-xs" >
178- { t ( "settings:aboutRetention.description " ) }
262+ { t ( "settings:aboutRetention.warning " ) }
179263 </ p >
180- < p className = "text-red-500 text-xs" > { t ( "settings:aboutRetention.warning" ) } </ p >
181264 </ div >
182265 </ PopoverContent >
183266 </ Popover >
@@ -421,6 +504,32 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
421504 } }
422505 />
423506 ) }
507+
508+ { /* Retention change confirmation dialog */ }
509+ < AlertDialog open = { showRetentionConfirmDialog } onOpenChange = { setShowRetentionConfirmDialog } >
510+ < AlertDialogContent >
511+ < AlertDialogHeader >
512+ < AlertDialogTitle > { t ( "settings:aboutRetention.confirmDialog.title" ) } </ AlertDialogTitle >
513+ < AlertDialogDescription >
514+ { pendingRetention === "never"
515+ ? t ( "settings:aboutRetention.confirmDialog.descriptionNever" )
516+ : t ( "settings:aboutRetention.confirmDialog.description" , {
517+ period : pendingRetention ,
518+ } ) }
519+ </ AlertDialogDescription >
520+ </ AlertDialogHeader >
521+ < AlertDialogFooter >
522+ < AlertDialogCancel onClick = { cancelRetentionChange } >
523+ { t ( "settings:aboutRetention.confirmDialog.cancel" ) }
524+ </ AlertDialogCancel >
525+ < AlertDialogAction onClick = { confirmRetentionChange } >
526+ { pendingRetention === "never"
527+ ? t ( "settings:aboutRetention.confirmDialog.confirmNever" )
528+ : t ( "settings:aboutRetention.confirmDialog.confirm" ) }
529+ </ AlertDialogAction >
530+ </ AlertDialogFooter >
531+ </ AlertDialogContent >
532+ </ AlertDialog >
424533 </ Tab >
425534 )
426535}
0 commit comments