Skip to content

Commit fd4c064

Browse files
author
Eric Wheeler
committed
fix: allow auto-approve checkbox to be toggled at any time
During model responses, users need the ability to disable auto-approval for safety when they realize the model is about to perform unintended actions. The checkbox was previously disabled when no options were selected or when the menu was open, preventing users from turning off auto-approval when needed most. - Remove disabled state from main auto-approve checkbox - Simplify toggle logic to always allow state changes - Add memoization to reduce unnecessary re-renders that cause flickering - Update tests to reflect new always-enabled behavior This ensures users can always disable auto-approval for safety, especially during time-critical situations when the model is actively responding. Fixes: #6060 Signed-off-by: Eric Wheeler <[email protected]>
1 parent 2f4d833 commit fd4c064

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useMemo, useState } from "react"
1+
import { memo, useCallback, useMemo, useState } from "react"
22
import { Trans } from "react-i18next"
33
import { VSCodeCheckbox, VSCodeLink, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
44

@@ -129,11 +129,6 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
129129
setIsExpanded((prev) => !prev)
130130
}, [])
131131

132-
// Disable main checkbox while menu is open or no options selected
133-
const isCheckboxDisabled = useMemo(() => {
134-
return !hasEnabledOptions || isExpanded
135-
}, [hasEnabledOptions, isExpanded])
136-
137132
const enabledActionsList = Object.entries(toggles)
138133
.filter(([_key, value]) => !!value)
139134
.map(([key]) => t(autoApproveSettingsConfig[key as AutoApproveSetting].labelKey))
@@ -178,19 +173,15 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
178173
content={!hasEnabledOptions ? t("chat:autoApprove.selectOptionsFirst") : undefined}>
179174
<VSCodeCheckbox
180175
checked={effectiveAutoApprovalEnabled}
181-
disabled={isCheckboxDisabled}
182176
aria-label={
183177
hasEnabledOptions
184178
? t("chat:autoApprove.toggleAriaLabel")
185179
: t("chat:autoApprove.disabledAriaLabel")
186180
}
187181
onChange={() => {
188-
if (hasEnabledOptions) {
189-
const newValue = !(autoApprovalEnabled ?? false)
190-
setAutoApprovalEnabled(newValue)
191-
vscode.postMessage({ type: "autoApprovalEnabled", bool: newValue })
192-
}
193-
// If no options enabled, do nothing
182+
const newValue = !(autoApprovalEnabled ?? false)
183+
setAutoApprovalEnabled(newValue)
184+
vscode.postMessage({ type: "autoApprovalEnabled", bool: newValue })
194185
}}
195186
/>
196187
</StandardTooltip>
@@ -290,4 +281,4 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
290281
)
291282
}
292283

293-
export default AutoApproveMenu
284+
export default memo(AutoApproveMenu)

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe("AutoApproveMenu", () => {
115115
expect(screen.getByText("Read-only operations")).toBeInTheDocument()
116116
})
117117

118-
it("should not allow toggling master checkbox when no options are selected", () => {
118+
it("should allow toggling master checkbox even when no options are selected", () => {
119119
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
120120
...defaultExtensionState,
121121
autoApprovalEnabled: false,
@@ -128,8 +128,11 @@ describe("AutoApproveMenu", () => {
128128
const masterCheckbox = screen.getByRole("checkbox")
129129
fireEvent.click(masterCheckbox)
130130

131-
// Should not send any message since no options are selected
132-
expect(mockPostMessage).not.toHaveBeenCalled()
131+
// Should send message to toggle auto-approval even when no options are selected
132+
expect(mockPostMessage).toHaveBeenCalledWith({
133+
type: "autoApprovalEnabled",
134+
bool: true,
135+
})
133136
})
134137

135138
it("should toggle master checkbox when options are selected", () => {

0 commit comments

Comments
 (0)