Skip to content

Commit 782174e

Browse files
author
Merge Resolver
committed
feat(webview-ui): show all auto-approve icons in collapsed view and highlight active ones; update tests
1 parent cfa2081 commit 782174e

File tree

2 files changed

+51
-40
lines changed

2 files changed

+51
-40
lines changed

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

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,8 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
129129
setIsExpanded((prev) => !prev)
130130
}, [])
131131

132-
// Get enabled icons for display
133-
const enabledIcons = useMemo(() => {
134-
return Object.entries(toggles)
135-
.filter(([_key, value]) => !!value)
136-
.map(([key]) => autoApproveSettingsConfig[key as AutoApproveSetting].icon)
137-
}, [toggles])
132+
// Get all icons for display and highlight based on toggle state
133+
const allConfigs = useMemo(() => Object.values(autoApproveSettingsConfig), [])
138134

139135
const handleOpenSettings = useCallback(
140136
() =>
@@ -211,27 +207,25 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
211207
alignItems: "center",
212208
gap: "6px",
213209
}}>
214-
{!effectiveAutoApprovalEnabled || !hasEnabledOptions
215-
? t("chat:autoApprove.none")
216-
: enabledIcons.map((icon, index) => {
217-
// Find the config for this icon to get the label
218-
const config = Object.values(autoApproveSettingsConfig).find(
219-
(cfg) => cfg.icon === icon,
220-
)
221-
const tooltipContent = config ? t(config.labelKey) : ""
222-
223-
return (
224-
<StandardTooltip key={index} content={tooltipContent}>
225-
<span
226-
className={`codicon codicon-${icon}`}
227-
style={{
228-
fontSize: "14px",
229-
flexShrink: 0,
230-
}}
231-
/>
232-
</StandardTooltip>
233-
)
234-
})}
210+
{allConfigs.map(({ key, icon, labelKey }) => {
211+
const isEnabled = !!toggles[key]
212+
return (
213+
<StandardTooltip key={key} content={t(labelKey)}>
214+
<span
215+
className={`codicon codicon-${icon}`}
216+
data-active={isEnabled ? "true" : "false"}
217+
style={{
218+
fontSize: "14px",
219+
flexShrink: 0,
220+
opacity: isEnabled ? 1 : 0.5,
221+
color: isEnabled
222+
? "var(--vscode-foreground)"
223+
: "var(--vscode-descriptionForeground)",
224+
}}
225+
/>
226+
</StandardTooltip>
227+
)
228+
})}
235229
</span>
236230
<span
237231
className={`codicon codicon-chevron-${isExpanded ? "down" : "right"}`}

webview-ui/src/components/chat/__tests__/AutoApproveMenu.spec.tsx

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe("AutoApproveMenu", () => {
8585
})
8686

8787
describe("Master checkbox behavior", () => {
88-
it("should show 'None selected' when no sub-options are selected", () => {
88+
it("should show all icons with none highlighted when no sub-options are selected", () => {
8989
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
9090
...defaultExtensionState,
9191
autoApprovalEnabled: false,
@@ -98,11 +98,23 @@ describe("AutoApproveMenu", () => {
9898

9999
render(<AutoApproveMenu />)
100100

101-
// Check that the text shows "None selected"
102-
expect(screen.getByText("None selected")).toBeInTheDocument()
101+
const container = screen.getByText("Auto-approve").parentElement?.parentElement
102+
103+
// All primary icons are rendered
104+
expect(container?.querySelector(".codicon-eye")).toBeInTheDocument()
105+
expect(container?.querySelector(".codicon-edit")).toBeInTheDocument()
106+
expect(container?.querySelector(".codicon-terminal")).toBeInTheDocument()
107+
108+
// None are active
109+
expect(container?.querySelector(".codicon-eye")?.getAttribute("data-active")).toBe("false")
110+
expect(container?.querySelector(".codicon-edit")?.getAttribute("data-active")).toBe("false")
111+
expect(container?.querySelector(".codicon-terminal")?.getAttribute("data-active")).toBe("false")
112+
113+
// "None selected" helper text is not shown anymore
114+
expect(screen.queryByText("None selected")).not.toBeInTheDocument()
103115
})
104116

105-
it("should show enabled options when sub-options are selected", () => {
117+
it("should highlight the enabled icons when sub-options are selected", () => {
106118
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
107119
...defaultExtensionState,
108120
autoApprovalEnabled: true,
@@ -112,9 +124,15 @@ describe("AutoApproveMenu", () => {
112124

113125
render(<AutoApproveMenu />)
114126

115-
// Check that the icon for read-only operations is shown
116-
const container = screen.getByText("Auto-approve").parentElement?.parentElement
117-
expect(container?.querySelector(".codicon-eye")).toBeInTheDocument()
127+
const container = screen.getByText("Auto-approve").parentElement?.parentElement as HTMLElement
128+
const eyeIcon = container.querySelector(".codicon-eye") as HTMLElement
129+
const editIcon = container.querySelector(".codicon-edit") as HTMLElement
130+
131+
expect(eyeIcon).toBeInTheDocument()
132+
expect(editIcon).toBeInTheDocument()
133+
134+
expect(eyeIcon.getAttribute("data-active")).toBe("true")
135+
expect(editIcon.getAttribute("data-active")).toBe("false")
118136
})
119137

120138
it("should not allow toggling master checkbox when no options are selected", () => {
@@ -213,7 +231,7 @@ describe("AutoApproveMenu", () => {
213231
})
214232

215233
describe("Complex scenarios", () => {
216-
it("should display multiple enabled options in summary text", () => {
234+
it("should highlight multiple enabled icons in collapsed view", () => {
217235
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
218236
...defaultExtensionState,
219237
autoApprovalEnabled: true,
@@ -224,11 +242,10 @@ describe("AutoApproveMenu", () => {
224242

225243
render(<AutoApproveMenu />)
226244

227-
// Should show icons for all enabled options
228-
const container = screen.getByText("Auto-approve").parentElement?.parentElement
229-
expect(container?.querySelector(".codicon-eye")).toBeInTheDocument() // Read
230-
expect(container?.querySelector(".codicon-edit")).toBeInTheDocument() // Write
231-
expect(container?.querySelector(".codicon-terminal")).toBeInTheDocument() // Execute
245+
const container = screen.getByText("Auto-approve").parentElement?.parentElement as HTMLElement
246+
expect(container.querySelector(".codicon-eye")?.getAttribute("data-active")).toBe("true") // Read
247+
expect(container.querySelector(".codicon-edit")?.getAttribute("data-active")).toBe("true") // Write
248+
expect(container.querySelector(".codicon-terminal")?.getAttribute("data-active")).toBe("true") // Execute
232249
})
233250

234251
it("should display tooltips on icons in collapsed view", async () => {

0 commit comments

Comments
 (0)