Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 43 additions & 61 deletions webview-ui/src/components/chat/checkpoints/CheckpointMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Checkpoint } from "./schema"
type CheckpointMenuBaseProps = {
ts: number
commitHash: string
currentHash?: string
checkpoint: Checkpoint
}
type CheckpointMenuControlledProps = {
Expand All @@ -24,21 +23,12 @@ type CheckpointMenuUncontrolledProps = {
}
type CheckpointMenuProps = CheckpointMenuBaseProps & (CheckpointMenuControlledProps | CheckpointMenuUncontrolledProps)

export const CheckpointMenu = ({
ts,
commitHash,
currentHash,
checkpoint,
open,
onOpenChange,
}: CheckpointMenuProps) => {
export const CheckpointMenu = ({ ts, commitHash, checkpoint, open, onOpenChange }: CheckpointMenuProps) => {
const { t } = useTranslation()
const [internalOpen, setInternalOpen] = useState(false)
const [isConfirming, setIsConfirming] = useState(false)
const portalContainer = useRooPortal("roo-portal")

const isCurrent = currentHash === commitHash

const previousCommitHash = checkpoint?.from

const isOpen = open ?? internalOpen
Expand Down Expand Up @@ -88,60 +78,52 @@ export const CheckpointMenu = ({
</StandardTooltip>
<PopoverContent align="end" container={portalContainer}>
<div className="flex flex-col gap-2">
{!isCurrent && (
<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 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>
)}
{!isCurrent && (
<div className="flex flex-col gap-1 group hover:text-foreground">
<div className="flex flex-col gap-1 group hover:text-foreground">
{!isConfirming ? (
<Button
variant="secondary"
onClick={() => setIsConfirming(true)}
data-testid="restore-files-and-task-btn">
{t("chat:checkpoint.menu.restoreFilesAndTask")}
</Button>
) : (
<>
<Button
variant="default"
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={() => setIsConfirming(false)}>
<div className="flex flex-row gap-1">
<Cross2Icon />
<div>{t("chat:checkpoint.menu.cancel")}</div>
</div>
</Button>
</>
)}
{isConfirming ? (
<div
data-testid="checkpoint-confirm-warning"
className="text-destructive font-bold">
{t("chat:checkpoint.menu.cannotUndo")}
</div>
<div className="flex flex-col gap-1 group hover:text-foreground">
{!isConfirming ? (
<Button
variant="secondary"
onClick={() => setIsConfirming(true)}
data-testid="restore-files-and-task-btn">
{t("chat:checkpoint.menu.restoreFilesAndTask")}
</Button>
) : (
<>
<Button
variant="default"
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>
) : (
<div className="text-muted transition-colors group-hover:text-foreground">
{t("chat:checkpoint.menu.restoreFilesAndTaskDescription")}
</Button>
<Button variant="secondary" onClick={() => setIsConfirming(false)}>
<div className="flex flex-row gap-1">
<Cross2Icon />
<div>{t("chat:checkpoint.menu.cancel")}</div>
</div>
)}
</Button>
</>
)}
{isConfirming ? (
<div data-testid="checkpoint-confirm-warning" className="text-destructive font-bold">
{t("chat:checkpoint.menu.cannotUndo")}
</div>
</div>
)}
) : (
<div className="text-muted transition-colors group-hover:text-foreground">
{t("chat:checkpoint.menu.restoreFilesAndTaskDescription")}
</div>
)}
</div>
</div>
</PopoverContent>
</Popover>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type CheckpointSavedProps = {
checkpoint?: Record<string, unknown>
}

export const CheckpointSaved = ({ checkpoint, ...props }: CheckpointSavedProps) => {
export const CheckpointSaved = ({ checkpoint, currentHash, ...props }: CheckpointSavedProps) => {
const { t } = useTranslation()
const isCurrent = props.currentHash === props.commitHash
const isCurrent = currentHash === props.commitHash
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
const [isClosing, setIsClosing] = useState(false)
const closeTimer = useRef<number | null>(null)
Expand Down
Loading