Skip to content

Commit 70e753e

Browse files
authored
[Condense] Move condense button out of expanded task menu (#4093)
* [Condense] Move condense button out of expanded task menu * tests * fix test * fix test again * tailwind css
1 parent 3ee7786 commit 70e753e

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

webview-ui/src/components/chat/TaskActions.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ import { IconButton } from "./IconButton"
1212
interface TaskActionsProps {
1313
item?: HistoryItem
1414
buttonsDisabled: boolean
15-
handleCondenseContext: (taskId: string) => void
1615
}
1716

18-
export const TaskActions = ({ item, buttonsDisabled, handleCondenseContext }: TaskActionsProps) => {
17+
export const TaskActions = ({ item, buttonsDisabled }: TaskActionsProps) => {
1918
const [deleteTaskId, setDeleteTaskId] = useState<string | null>(null)
2019
const { t } = useTranslation()
2120

@@ -29,12 +28,6 @@ export const TaskActions = ({ item, buttonsDisabled, handleCondenseContext }: Ta
2928
/>
3029
{!!item?.size && item.size > 0 && (
3130
<>
32-
<IconButton
33-
iconClass="codicon-fold"
34-
title={t("chat:task.condenseContext")}
35-
disabled={buttonsDisabled}
36-
onClick={() => handleCondenseContext(item.id)}
37-
/>
3831
<div className="flex items-center">
3932
<IconButton
4033
iconClass="codicon-trash"

webview-ui/src/components/chat/TaskHeader.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Thumbnails from "../common/Thumbnails"
1919
import { TaskActions } from "./TaskActions"
2020
import { ContextWindowProgress } from "./ContextWindowProgress"
2121
import { Mention } from "./Mention"
22+
import { IconButton } from "./IconButton"
2223

2324
export interface TaskHeaderProps {
2425
task: ClineMessage
@@ -97,7 +98,7 @@ const TaskHeader = ({
9798
</div>
9899
{/* Collapsed state: Track context and cost if we have any */}
99100
{!isTaskExpanded && contextWindow > 0 && (
100-
<div className={`w-full flex flex-row gap-1 h-auto`}>
101+
<div className={`w-full flex flex-row items-center gap-1 h-auto`}>
101102
<ContextWindowProgress
102103
contextWindow={contextWindow}
103104
contextTokens={contextTokens || 0}
@@ -107,6 +108,13 @@ const TaskHeader = ({
107108
: undefined
108109
}
109110
/>
111+
<IconButton
112+
iconClass="codicon-fold"
113+
title={t("chat:task.condenseContext")}
114+
disabled={buttonsDisabled}
115+
onClick={() => currentTaskItem && handleCondenseContext(currentTaskItem.id)}
116+
className="shrink-0 min-h-[20px] min-w-[20px] p-[2px]"
117+
/>
110118
{!!totalCost && <VSCodeBadge>${totalCost.toFixed(2)}</VSCodeBadge>}
111119
</div>
112120
)}
@@ -169,13 +177,7 @@ const TaskHeader = ({
169177
</span>
170178
)}
171179
</div>
172-
{!totalCost && (
173-
<TaskActions
174-
item={currentTaskItem}
175-
buttonsDisabled={buttonsDisabled}
176-
handleCondenseContext={handleCondenseContext}
177-
/>
178-
)}
180+
{!totalCost && <TaskActions item={currentTaskItem} buttonsDisabled={buttonsDisabled} />}
179181
</div>
180182

181183
{doesModelSupportPromptCache &&
@@ -204,11 +206,7 @@ const TaskHeader = ({
204206
<span className="font-bold">{t("chat:task.apiCost")}</span>
205207
<span>${totalCost?.toFixed(2)}</span>
206208
</div>
207-
<TaskActions
208-
item={currentTaskItem}
209-
buttonsDisabled={buttonsDisabled}
210-
handleCondenseContext={handleCondenseContext}
211-
/>
209+
<TaskActions item={currentTaskItem} buttonsDisabled={buttonsDisabled} />
212210
</div>
213211
)}
214212
</div>

webview-ui/src/components/chat/__tests__/TaskHeader.test.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
// npx jest src/components/chat/__tests__/TaskHeader.test.tsx
22

33
import React from "react"
4-
import { render, screen } from "@testing-library/react"
4+
import { render, screen, fireEvent } from "@testing-library/react"
55
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
66

77
import type { ProviderSettings } from "@roo-code/types"
88

99
import TaskHeader, { TaskHeaderProps } from "../TaskHeader"
1010

11+
// Mock i18n
12+
jest.mock("react-i18next", () => ({
13+
useTranslation: () => ({
14+
t: (key: string) => key, // Simple mock that returns the key
15+
}),
16+
// Mock initReactI18next to prevent initialization errors in tests
17+
initReactI18next: {
18+
type: "3rdParty",
19+
init: jest.fn(),
20+
},
21+
}))
22+
1123
// Mock the vscode API
1224
jest.mock("@/utils/vscode", () => ({
1325
vscode: {
@@ -28,7 +40,7 @@ jest.mock("@src/context/ExtensionStateContext", () => ({
2840
apiKey: "test-api-key", // Add relevant fields
2941
apiModelId: "claude-3-opus-20240229", // Add relevant fields
3042
} as ProviderSettings, // Optional: Add type assertion if ProviderSettings is imported
31-
currentTaskItem: null,
43+
currentTaskItem: { id: "test-task-id" },
3244
}),
3345
}))
3446

@@ -79,4 +91,25 @@ describe("TaskHeader", () => {
7991
renderTaskHeader({ totalCost: NaN })
8092
expect(screen.queryByText(/\$/)).not.toBeInTheDocument()
8193
})
94+
95+
it("should render the condense context button", () => {
96+
renderTaskHeader()
97+
expect(screen.getByTitle("chat:task.condenseContext")).toBeInTheDocument()
98+
})
99+
100+
it("should call handleCondenseContext when condense context button is clicked", () => {
101+
const handleCondenseContext = jest.fn()
102+
renderTaskHeader({ handleCondenseContext })
103+
const condenseButton = screen.getByTitle("chat:task.condenseContext")
104+
fireEvent.click(condenseButton)
105+
expect(handleCondenseContext).toHaveBeenCalledWith("test-task-id")
106+
})
107+
108+
it("should disable the condense context button when buttonsDisabled is true", () => {
109+
const handleCondenseContext = jest.fn()
110+
renderTaskHeader({ buttonsDisabled: true, handleCondenseContext })
111+
const condenseButton = screen.getByTitle("chat:task.condenseContext")
112+
fireEvent.click(condenseButton)
113+
expect(handleCondenseContext).not.toHaveBeenCalled()
114+
})
82115
})

0 commit comments

Comments
 (0)