Skip to content

Commit ff34264

Browse files
committed
Add clear‑all‑checkpoints command with UI button, handle temporary checkpoint removal, display a 'Nothing to delete' info message, and extend messages and dictionary accordingly
1 parent cf15c5a commit ff34264

8 files changed

Lines changed: 113 additions & 18 deletions

File tree

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const dictionary = {
8181
NO_TEXT_SELECTED_FOR_SELECTION_PLACEHOLDER:
8282
'No text selected for #Selection placeholder.',
8383
PLEASE_CONFIRM: 'Please confirm',
84+
NOTHING_TO_DELETE: 'Nothing to delete.',
8485
RESTORED_CONTEXT: (context_name: string) =>
8586
`Restored context "${context_name}".`,
8687
NO_GIT_REPOSITORY_FOUND_IN_WORKSPACE:

‎packages/vscode/src/commands/checkpoints-command/actions/clear-all-checkpoints.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import * as vscode from 'vscode'
2-
import { CHECKPOINTS_STATE_KEY } from '../../../constants/state-keys'
2+
import {
3+
CHECKPOINTS_STATE_KEY,
4+
TEMPORARY_CHECKPOINT_STATE_KEY
5+
} from '../../../constants/state-keys'
36
import { get_checkpoint_path } from '../utils'
47
import { get_checkpoints } from './get-checkpoints'
58
import { Logger } from '@shared/utils/logger'
69
import { PanelProvider } from '@/views/panel/backend/panel-provider'
10+
import type { Checkpoint } from '../types'
711

812
export const clear_all_checkpoints = async (
913
context: vscode.ExtensionContext,
@@ -25,6 +29,27 @@ export const clear_all_checkpoints = async (
2529
})
2630
}
2731
}
32+
const temp_checkpoint = context.workspaceState.get<Checkpoint>(
33+
TEMPORARY_CHECKPOINT_STATE_KEY
34+
)
35+
if (temp_checkpoint) {
36+
try {
37+
const checkpoint_path = get_checkpoint_path(temp_checkpoint.timestamp)
38+
await vscode.workspace.fs.delete(vscode.Uri.file(checkpoint_path), {
39+
recursive: true
40+
})
41+
} catch (error) {
42+
Logger.warn({
43+
function_name: 'clear_all_checkpoints',
44+
message: 'Could not delete temporary checkpoint file',
45+
data: error
46+
})
47+
}
48+
}
49+
await context.workspaceState.update(
50+
TEMPORARY_CHECKPOINT_STATE_KEY,
51+
undefined
52+
)
2853
await context.workspaceState.update(CHECKPOINTS_STATE_KEY, [])
2954
await panel_provider.send_checkpoints()
3055
}

‎packages/vscode/src/commands/checkpoints-command/checkpoints-command.ts‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ export const checkpoints_command = (params: {
106106

107107
const visible_checkpoints = checkpoints.filter((c) => !c.is_temporary)
108108

109-
if (visible_checkpoints.length > 0) {
110-
quick_pick.buttons = [clear_all_button]
111-
} else {
112-
quick_pick.buttons = []
113-
}
109+
quick_pick.buttons = [clear_all_button]
114110

115111
visible_checkpoints.sort((a, b) => {
116112
return b.timestamp - a.timestamp
@@ -280,6 +276,19 @@ export const checkpoints_command = (params: {
280276
quick_pick.onDidTriggerButton(async (button) => {
281277
if (button === clear_all_button) {
282278
quick_pick.hide()
279+
280+
const temp_checkpoint =
281+
params.context.workspaceState.get<Checkpoint>(
282+
TEMPORARY_CHECKPOINT_STATE_KEY
283+
)
284+
if (checkpoints.length === 0 && !temp_checkpoint) {
285+
vscode.window.showInformationMessage(
286+
dictionary.information_message.NOTHING_TO_DELETE
287+
)
288+
quick_pick.show()
289+
return
290+
}
291+
283292
const confirmation = await vscode.window.showWarningMessage(
284293
dictionary.warning_message.CONFIRM_CLEAR_ALL_CHECKPOINTS,
285294
{ modal: true },
@@ -293,10 +302,6 @@ export const checkpoints_command = (params: {
293302
dictionary.information_message.ALL_CHECKPOINTS_CLEARED
294303
)
295304
}
296-
await params.context.workspaceState.update(
297-
TEMPORARY_CHECKPOINT_STATE_KEY,
298-
undefined
299-
)
300305
await refresh_and_update_view()
301306
}
302307
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as vscode from 'vscode'
2+
import { PanelProvider } from '../panel-provider'
3+
import {
4+
clear_all_checkpoints,
5+
get_checkpoints
6+
} from '@/commands/checkpoints-command/actions'
7+
import { dictionary } from '@shared/constants/dictionary'
8+
import { TEMPORARY_CHECKPOINT_STATE_KEY } from '@/constants/state-keys'
9+
import type { Checkpoint } from '@/commands/checkpoints-command/types'
10+
11+
export const handle_clear_all_checkpoints = async (
12+
panel_provider: PanelProvider
13+
) => {
14+
const checkpoints = await get_checkpoints(panel_provider.context)
15+
const temp_checkpoint = panel_provider.context.workspaceState.get<Checkpoint>(
16+
TEMPORARY_CHECKPOINT_STATE_KEY
17+
)
18+
19+
if (checkpoints.length === 0 && !temp_checkpoint) {
20+
vscode.window.showInformationMessage(
21+
dictionary.information_message.NOTHING_TO_DELETE
22+
)
23+
return
24+
}
25+
26+
const confirmation = await vscode.window.showWarningMessage(
27+
dictionary.warning_message.CONFIRM_CLEAR_ALL_CHECKPOINTS,
28+
{ modal: true },
29+
'Clear All'
30+
)
31+
32+
if (confirmation == 'Clear All') {
33+
panel_provider.active_checkpoint_delete_operation = null
34+
await clear_all_checkpoints(panel_provider.context, panel_provider)
35+
vscode.window.showInformationMessage(
36+
dictionary.information_message.ALL_CHECKPOINTS_CLEARED
37+
)
38+
}
39+
}

‎packages/vscode/src/views/panel/backend/message-handlers/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ export * from './handle-save-component-collapsed-state'
5353
export * from './handle-undo'
5454
export * from './handle-show-diff'
5555
export * from './handle-delete-checkpoint'
56+
export * from './handle-clear-all-checkpoints'

‎packages/vscode/src/views/panel/backend/panel-provider.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
handle_update_preset,
2121
handle_delete_preset,
2222
handle_create_checkpoint,
23+
handle_clear_all_checkpoints,
2324
handle_delete_group,
2425
handle_delete_separator,
2526
handle_duplicate_preset,
@@ -464,6 +465,8 @@ export class PanelProvider implements vscode.WebviewViewProvider {
464465
})
465466
} else if (message.command == 'DELETE_CHECKPOINT') {
466467
await handle_delete_checkpoint(this, message)
468+
} else if (message.command == 'CLEAR_ALL_CHECKPOINTS') {
469+
await handle_clear_all_checkpoints(this)
467470
} else if (message.command == 'GET_HISTORY') {
468471
handle_get_history(this)
469472
} else if (message.command == 'GET_RESPONSE_HISTORY') {

‎packages/vscode/src/views/panel/frontend/Home/Home.tsx‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export const Home: React.FC<Props> = (props) => {
4848
} as FrontendMessage)
4949
}
5050

51+
const handle_delete_all_checkpoints_click = () => {
52+
post_message(props.vscode, {
53+
command: 'CLEAR_ALL_CHECKPOINTS'
54+
} as FrontendMessage)
55+
}
56+
5157
return (
5258
<>
5359
<div className={styles.header}>
@@ -112,14 +118,24 @@ export const Home: React.FC<Props> = (props) => {
112118
set_is_timeline_collapsed(!is_timeline_collapsed)
113119
}
114120
actions={
115-
<IconButton
116-
codicon_icon="add"
117-
title="New Checkpoint"
118-
on_click={(e) => {
119-
e.stopPropagation()
120-
handle_create_checkpoint_click()
121-
}}
122-
/>
121+
<>
122+
<IconButton
123+
codicon_icon="add"
124+
title="New Checkpoint"
125+
on_click={(e) => {
126+
e.stopPropagation()
127+
handle_create_checkpoint_click()
128+
}}
129+
/>
130+
<IconButton
131+
codicon_icon="trash"
132+
title="Delete all checkpoints"
133+
on_click={(e) => {
134+
e.stopPropagation()
135+
handle_delete_all_checkpoints_click()
136+
}}
137+
/>
138+
</>
123139
}
124140
/>
125141
{!is_timeline_collapsed && (

‎packages/vscode/src/views/panel/types/messages.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ export interface DeleteCheckpointMessage extends BaseMessage {
395395
timestamp: number
396396
}
397397

398+
export interface ClearAllCheckpointsMessage extends BaseMessage {
399+
command: 'CLEAR_ALL_CHECKPOINTS'
400+
}
401+
398402
export type FrontendMessage =
399403
| GetInstructionsMessage
400404
| SaveInstructionsMessage
@@ -467,6 +471,7 @@ export type FrontendMessage =
467471
| RemoveResponseHistoryItemMessage
468472
| UpdateCheckpointDescriptionMessage
469473
| DeleteCheckpointMessage
474+
| ClearAllCheckpointsMessage
470475

471476
// === FROM BACKEND TO FRONTEND ===
472477
export interface InstructionsMessage extends BaseMessage {

0 commit comments

Comments
 (0)