From 2ef4e56bcadfc05b4a337d3eec80f7580df943d8 Mon Sep 17 00:00:00 2001 From: Ara Date: Thu, 10 Apr 2025 02:23:10 +0530 Subject: [PATCH] ENG-377 Changing Checkpoint UI to take less real space on the chat interface (#2752) * Enhance chat component interactivity by adding row index and hover state management. Updated BrowserSessionRow, ChatRow, and CheckmarkControl to support row-specific hover effects and state tracking, improving user experience during interactions. * Adding hovered row index * Adding hovered row index * Adding hovered row index --- .../src/components/chat/BrowserSessionRow.tsx | 18 +++++- webview-ui/src/components/chat/ChatRow.tsx | 58 +++++++++++-------- webview-ui/src/components/chat/ChatView.tsx | 14 ++++- .../components/common/CheckmarkControl.tsx | 11 +++- webview-ui/src/hooks/useChatRowStyles.ts | 40 +++++++++++++ 5 files changed, 113 insertions(+), 28 deletions(-) create mode 100644 webview-ui/src/hooks/useChatRowStyles.ts diff --git a/webview-ui/src/components/chat/BrowserSessionRow.tsx b/webview-ui/src/components/chat/BrowserSessionRow.tsx index a375d158..16718b15 100644 --- a/webview-ui/src/components/chat/BrowserSessionRow.tsx +++ b/webview-ui/src/components/chat/BrowserSessionRow.tsx @@ -275,11 +275,19 @@ const BrowserSessionRow = memo((props: BrowserSessionRowProps) => { consoleLogs: currentPage?.currentState.consoleLogs, screenshot: currentPage?.currentState.screenshot, } - + const [rowIndex, setRowIndex] = useState(0) + const [hoveredRowIndex, setHoveredRowIndex] = useState(null) const [actionContent, { height: actionHeight }] = useSize(
{currentPage?.nextAction?.messages.map((message) => ( - + ))} {!isBrowsing && messages.some((m) => m.say === "browser_action_result") && currentPageIndex === 0 && ( @@ -473,6 +481,8 @@ const BrowserSessionRow = memo((props: BrowserSessionRowProps) => { interface BrowserSessionRowContentProps extends Omit { message: ClineMessage setMaxActionHeight: (height: number) => void + rowIndex: number + hoveredRowIndex: number | null } const BrowserSessionRowContent = ({ @@ -482,6 +492,8 @@ const BrowserSessionRowContent = ({ lastModifiedMessage, isLast, setMaxActionHeight, + rowIndex, + hoveredRowIndex, }: BrowserSessionRowContentProps) => { if (message.ask === "browser_action_launch" || message.say === "browser_action_launch") { return ( @@ -504,6 +516,8 @@ const BrowserSessionRowContent = ({ return (
{ diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index 01c3892f..809152d3 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -17,6 +17,7 @@ import { COMMAND_OUTPUT_STRING, COMMAND_REQ_APP_STRING } from "@shared/combineCo import { useExtensionState } from "@/context/ExtensionStateContext" import { findMatchingResourceOrTemplate, getMcpServerDisplayName } from "@/utils/mcp" import { vscode } from "@/utils/vscode" +import { useChatRowStyles } from "@/hooks/useChatRowStyles" import { CheckmarkControl } from "@/components/common/CheckmarkControl" import { CheckpointControls, CheckpointOverlay } from "../common/CheckpointControls" import CodeAccordian, { cleanPathPrefix } from "../common/CodeAccordian" @@ -49,9 +50,16 @@ interface ChatRowProps { lastModifiedMessage?: ClineMessage isLast: boolean onHeightChange: (isTaller: boolean) => void + rowIndex: number + hoveredRowIndex: number | null + setHoveredRowIndex: React.Dispatch> } -interface ChatRowContentProps extends Omit {} +interface ChatRowContentProps + extends Omit { + rowIndex: number + hoveredRowIndex: number | null +} export const ProgressIndicator = () => (
{ const ChatRow = memo( (props: ChatRowProps) => { - const { isLast, onHeightChange, message, lastModifiedMessage } = props + const { isLast, onHeightChange, message, lastModifiedMessage, rowIndex, hoveredRowIndex, setHoveredRowIndex } = props // Store the previous height to compare with the current height // This allows us to detect changes without causing re-renders const prevHeightRef = useRef(0) - - // NOTE: for tools that are interrupted and not responded to (approved or rejected) there won't be a checkpoint hash - let shouldShowCheckpoints = - message.lastCheckpointHash != null && - (message.say === "tool" || - message.ask === "tool" || - message.say === "command" || - message.ask === "command" || - // message.say === "completion_result" || - // message.ask === "completion_result" || - message.say === "use_mcp_server" || - message.ask === "use_mcp_server") - - if (shouldShowCheckpoints && isLast) { - shouldShowCheckpoints = - lastModifiedMessage?.ask === "resume_completed_task" || lastModifiedMessage?.ask === "resume_task" - } + // Calculate dynamic styles using the custom hook + const { padding, minHeight } = useChatRowStyles(message, hoveredRowIndex, rowIndex) const [chatrow, { height }] = useSize( - - - {shouldShowCheckpoints && } + setHoveredRowIndex(rowIndex)} + onMouseLeave={() => setHoveredRowIndex(null)}> + , ) @@ -135,7 +130,15 @@ const ChatRow = memo( export default ChatRow -export const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifiedMessage, isLast }: ChatRowContentProps) => { +export const ChatRowContent = ({ + message, + isExpanded, + onToggleExpand, + lastModifiedMessage, + isLast, + rowIndex, + hoveredRowIndex, +}: ChatRowContentProps) => { const { mcpServers, mcpMarketplaceCatalog } = useExtensionState() const [seeNewChangesDisabled, setSeeNewChangesDisabled] = useState(false) @@ -985,9 +988,16 @@ export const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifi ) case "checkpoint_created": + // Determine if the hover is near the checkpoint marker's visual position (either on the preceding row or the checkpoint row itself) + const isHoveredNearCheckpoint = hoveredRowIndex === rowIndex - 1 || hoveredRowIndex === rowIndex + return ( <> - + ) case "completion_result": diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 5594ef84..e77e8e71 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -77,6 +77,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie const disableAutoScrollRef = useRef(false) const [showScrollToBottom, setShowScrollToBottom] = useState(false) const [isAtBottom, setIsAtBottom] = useState(false) + const [hoveredRowIndex, setHoveredRowIndex] = useState(null) // UI layout depends on the last 2 messages // (since it relies on the content of these messages, we are deep comparing. i.e. the button state after hitting button sets enableButtons to false, and this effect otherwise would have to true again even if messages didn't change @@ -780,10 +781,21 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie lastModifiedMessage={modifiedMessages.at(-1)} isLast={index === groupedMessages.length - 1} onHeightChange={handleRowHeightChange} + rowIndex={index} + hoveredRowIndex={hoveredRowIndex} + setHoveredRowIndex={setHoveredRowIndex} /> ) }, - [expandedRows, modifiedMessages, groupedMessages.length, toggleRowExpansion, handleRowHeightChange], + [ + expandedRows, + modifiedMessages, + groupedMessages.length, + toggleRowExpansion, + handleRowHeightChange, + hoveredRowIndex, + setHoveredRowIndex, + ], ) return ( diff --git a/webview-ui/src/components/common/CheckmarkControl.tsx b/webview-ui/src/components/common/CheckmarkControl.tsx index d4e61568..ad1d8ebe 100644 --- a/webview-ui/src/components/common/CheckmarkControl.tsx +++ b/webview-ui/src/components/common/CheckmarkControl.tsx @@ -11,9 +11,11 @@ import { useFloating, offset, flip, shift } from "@floating-ui/react" interface CheckmarkControlProps { messageTs?: number isCheckpointCheckedOut?: boolean + /** Determines if the hover is near the checkpoint marker's visual position (either on the preceding row or the checkpoint row itself) */ + isHoveredNearCheckpoint: boolean } -export const CheckmarkControl = ({ messageTs, isCheckpointCheckedOut }: CheckmarkControlProps) => { +export const CheckmarkControl = ({ messageTs, isCheckpointCheckedOut, isHoveredNearCheckpoint }: CheckmarkControlProps) => { const [compareDisabled, setCompareDisabled] = useState(false) const [restoreTaskDisabled, setRestoreTaskDisabled] = useState(false) const [restoreWorkspaceDisabled, setRestoreWorkspaceDisabled] = useState(false) @@ -119,6 +121,13 @@ export const CheckmarkControl = ({ messageTs, isCheckpointCheckedOut }: Checkmar useEvent("message", handleMessage) + // Hide checkpoint if it is not the currently restored one AND the user is not hovering near it. + // This keeps the UI clean but ensures the checkpoint appear on hover for interaction. + const shouldHideCheckpoint = !isCheckpointCheckedOut && !isHoveredNearCheckpoint + if (shouldHideCheckpoint) { + return null + } + return ( { + return useMemo(() => { + // Check if the current message is a checkpoint creation message. + const isCheckpointMessage = message.say === "checkpoint_created" + + // Determine if the hover state is relevant to this row or the one immediately preceding it. + // This is because the checkpoint marker is visually associated with the row *before* the checkpoint message, + // but its visibility is controlled by the hover state of *both* the preceding row and the checkpoint message row itself. + const isHoverRelevant = hoveredRowIndex === rowIndex - 1 || hoveredRowIndex === rowIndex + + // Calculate styles based on checkpoint status and hover relevance. + // If it's a checkpoint message, not currently checked out, and not relevantly hovered, + // reset padding to 0 and set minHeight to 1px to visually collapse it. + // Otherwise, use default styles (undefined, letting CSS handle it). + const padding = isCheckpointMessage && !message.isCheckpointCheckedOut && !isHoverRelevant ? 0 : undefined + const minHeight = isCheckpointMessage && !message.isCheckpointCheckedOut && !isHoverRelevant ? 1 : undefined + + return { padding, minHeight } + }, [message.say, message.isCheckpointCheckedOut, hoveredRowIndex, rowIndex]) +}