This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathCheckpointMenu.tsx
More file actions
214 lines (200 loc) · 6.67 KB
/
Copy pathCheckpointMenu.tsx
File metadata and controls
214 lines (200 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import { useState, useCallback } from "react"
import { CheckIcon, Cross2Icon } from "@radix-ui/react-icons"
import { useTranslation } from "react-i18next"
import { Button, Popover, PopoverContent, PopoverTrigger, StandardTooltip } from "@/components/ui"
import { useRooPortal } from "@/components/ui/hooks"
import { vscode } from "@src/utils/vscode"
import { Checkpoint } from "./schema"
type CheckpointMenuBaseProps = {
ts: number
commitHash: string
checkpoint: Checkpoint
isInitial?: boolean
}
type CheckpointMenuControlledProps = {
onOpenChange: (open: boolean) => void
}
type CheckpointMenuUncontrolledProps = {
onOpenChange?: undefined
}
type CheckpointMenuProps = CheckpointMenuBaseProps & (CheckpointMenuControlledProps | CheckpointMenuUncontrolledProps)
export const CheckpointMenu = ({ ts, commitHash, checkpoint, isInitial, onOpenChange }: CheckpointMenuProps) => {
const { t } = useTranslation()
const [internalRestoreOpen, setInternalRestoreOpen] = useState(false)
const [restoreConfirming, setRestoreConfirming] = useState(false)
const [internalMoreOpen, setInternalMoreOpen] = useState(false)
const portalContainer = useRooPortal("roo-portal")
const previousCommitHash = checkpoint?.from
const restoreOpen = internalRestoreOpen
const moreOpen = internalMoreOpen
const setRestoreOpen = useCallback(
(open: boolean) => {
setInternalRestoreOpen(open)
if (onOpenChange) {
onOpenChange(open)
}
},
[onOpenChange],
)
const setMoreOpen = useCallback(
(open: boolean) => {
setInternalMoreOpen(open)
if (onOpenChange) {
onOpenChange(open)
}
},
[onOpenChange],
)
const onCheckpointDiff = useCallback(() => {
vscode.postMessage({
type: "checkpointDiff",
payload: { ts, previousCommitHash, commitHash, mode: "checkpoint" },
})
}, [ts, previousCommitHash, commitHash])
const onDiffFromInit = useCallback(() => {
vscode.postMessage({
type: "checkpointDiff",
payload: { ts, commitHash, mode: "from-init" },
})
}, [ts, commitHash])
const onDiffWithCurrent = useCallback(() => {
vscode.postMessage({
type: "checkpointDiff",
payload: { ts, commitHash, mode: "to-current" },
})
}, [ts, commitHash])
const onPreview = useCallback(() => {
vscode.postMessage({
type: "checkpointRestore",
payload: { ts, commitHash, mode: "preview", ...(isInitial && { isInitial: true }) },
})
setRestoreOpen(false)
}, [ts, commitHash, isInitial, setRestoreOpen])
const onRestore = useCallback(() => {
vscode.postMessage({
type: "checkpointRestore",
payload: { ts, commitHash, mode: "restore", ...(isInitial && { isInitial: true }) },
})
setRestoreOpen(false)
}, [ts, commitHash, isInitial, setRestoreOpen])
const handleOpenChange = useCallback(
(open: boolean) => {
setRestoreOpen(open)
if (!open) {
setRestoreConfirming(false)
}
},
[setRestoreOpen],
)
return (
<div className="flex flex-row gap-1">
{/* Hide "View Diff" for initial checkpoint - no previous checkpoint to diff against */}
{!isInitial && (
<StandardTooltip content={t("chat:checkpoint.menu.viewDiff")}>
<Button variant="ghost" size="icon" onClick={onCheckpointDiff}>
<span className="codicon codicon-diff-single" />
</Button>
</StandardTooltip>
)}
<Popover
open={restoreOpen}
onOpenChange={(open) => {
handleOpenChange(open)
setRestoreConfirming(false)
}}
data-testid="restore-popover">
<StandardTooltip content={t("chat:checkpoint.menu.restore")}>
<PopoverTrigger asChild>
<Button variant="ghost" size="icon" aria-label={t("chat:checkpoint.menu.restore")}>
<span className="codicon codicon-history" />
</Button>
</PopoverTrigger>
</StandardTooltip>
<PopoverContent align="end" container={portalContainer}>
<div className="flex flex-col gap-2">
<div className="flex flex-col gap-1 group hover:text-foreground">
<Button variant="secondary" onClick={onPreview} data-testid="restore-files-btn">
{t("chat:checkpoint.menu.restoreFiles")}
</Button>
<div className="text-muted transition-colors group-hover:text-foreground">
{t("chat:checkpoint.menu.restoreFilesDescription")}
</div>
</div>
<div className="flex flex-col gap-1 group hover:text-foreground">
{!restoreConfirming ? (
<Button
variant="secondary"
onClick={() => setRestoreConfirming(true)}
data-testid="restore-files-and-task-btn">
{t("chat:checkpoint.menu.restoreFilesAndTask")}
</Button>
) : (
<>
<Button
variant="primary"
onClick={onRestore}
className="grow"
data-testid="confirm-restore-btn">
<div className="flex flex-row gap-1">
<CheckIcon />
<div>{t("chat:checkpoint.menu.confirm")}</div>
</div>
</Button>
<Button variant="secondary" onClick={() => setRestoreConfirming(false)}>
<div className="flex flex-row gap-1">
<Cross2Icon />
<div>{t("chat:checkpoint.menu.cancel")}</div>
</div>
</Button>
</>
)}
{restoreConfirming ? (
<div data-testid="checkpoint-confirm-warning" className="text-destructive font-bold">
{t("chat:checkpoint.menu.cannotUndo")}
</div>
) : (
<div className="text-muted transition-colors group-hover:text-foreground">
{t("chat:checkpoint.menu.restoreFilesAndTaskDescription")}
</div>
)}
</div>
</div>
</PopoverContent>
</Popover>
<Popover open={moreOpen} onOpenChange={(open) => setMoreOpen(open)} data-testid="more-popover">
<StandardTooltip content={t("chat:task.seeMore")}>
<PopoverTrigger asChild>
<Button variant="ghost" size="icon" aria-label={t("chat:checkpoint.menu.more")}>
<span className="codicon codicon-kebab-vertical" />
</Button>
</PopoverTrigger>
</StandardTooltip>
<PopoverContent align="end" container={portalContainer} className="w-auto min-w-max">
<div className="flex flex-col gap-2">
{/* Hide "View All Changes" for initial checkpoint - already at init */}
{!isInitial && (
<Button
variant="secondary"
onClick={() => {
onDiffFromInit()
setMoreOpen(false)
}}>
<span className="codicon codicon-versions mr-2" />
{t("chat:checkpoint.menu.viewDiffFromInit")}
</Button>
)}
<Button
variant="secondary"
onClick={() => {
onDiffWithCurrent()
setMoreOpen(false)
}}>
<span className="codicon codicon-diff mr-2" />
{t("chat:checkpoint.menu.viewDiffWithCurrent")}
</Button>
</div>
</PopoverContent>
</Popover>
</div>
)
}