Skip to content

Commit 88171d6

Browse files
chore: update type definitions and dependencies for improved type safety
1 parent 7020d1d commit 88171d6

File tree

5 files changed

+176
-86
lines changed

5 files changed

+176
-86
lines changed

webview-ui/package-lock.json

Lines changed: 25 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@radix-ui/react-tooltip": "^1.1.8",
3333
"@tailwindcss/vite": "^4.0.0",
3434
"@tanstack/react-query": "^5.68.0",
35+
"@types/react-i18next": "^7.8.3",
3536
"@vscode/webview-ui-toolkit": "^1.4.0",
3637
"class-variance-authority": "^0.7.1",
3738
"clsx": "^2.1.1",
@@ -74,8 +75,8 @@
7475
"@testing-library/user-event": "^14.6.1",
7576
"@types/jest": "^27.5.2",
7677
"@types/node": "^18.0.0",
77-
"@types/react": "^18.3.18",
78-
"@types/react-dom": "^18.3.5",
78+
"@types/react": "^18.3.20",
79+
"@types/react-dom": "^18.3.6",
7980
"@types/shell-quote": "^1.7.5",
8081
"@types/testing-library__jest-dom": "^5.14.5",
8182
"@types/vscode-webview": "^1.57.5",

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

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { useCallback, useMemo, useState } from "react"
1+
/// <reference types="react" />
2+
import React, { useCallback, useMemo, useState, useEffect } from "react"
23
import { Trans } from "react-i18next"
34
import { VSCodeCheckbox, VSCodeLink } from "@vscode/webview-ui-toolkit/react"
45

@@ -11,7 +12,7 @@ interface AutoApproveMenuProps {
1112
style?: React.CSSProperties
1213
}
1314

14-
const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
15+
const AutoApproveMenu: React.FC<AutoApproveMenuProps> = ({ style = {} }: AutoApproveMenuProps) => {
1516
const [isExpanded, setIsExpanded] = useState(false)
1617

1718
const {
@@ -80,18 +81,18 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
8081
],
8182
)
8283

83-
const toggleExpanded = useCallback(() => setIsExpanded((prev) => !prev), [])
84+
const toggleExpanded = useCallback(() => setIsExpanded((prev: boolean) => !prev), [])
8485

8586
const toggles = useMemo(
8687
() => ({
87-
alwaysAllowReadOnly: alwaysAllowReadOnly,
88-
alwaysAllowWrite: alwaysAllowWrite,
89-
alwaysAllowExecute: alwaysAllowExecute,
90-
alwaysAllowBrowser: alwaysAllowBrowser,
91-
alwaysAllowMcp: alwaysAllowMcp,
92-
alwaysAllowModeSwitch: alwaysAllowModeSwitch,
93-
alwaysAllowSubtasks: alwaysAllowSubtasks,
94-
alwaysApproveResubmit: alwaysApproveResubmit,
88+
alwaysAllowReadOnly,
89+
alwaysAllowWrite,
90+
alwaysAllowExecute,
91+
alwaysAllowBrowser,
92+
alwaysAllowMcp,
93+
alwaysAllowModeSwitch,
94+
alwaysAllowSubtasks,
95+
alwaysApproveResubmit,
9596
}),
9697
[
9798
alwaysAllowReadOnly,
@@ -105,17 +106,29 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
105106
],
106107
)
107108

108-
const enabledActionsList = Object.entries(toggles)
109-
.filter(([_key, value]) => !!value)
110-
.map(([key]) => t(autoApproveSettingsConfig[key as AutoApproveSetting].labelKey))
111-
.join(", ")
109+
const enabledActions = Object.values(toggles).filter(Boolean)
110+
const hasEnabledActions = enabledActions.length > 0
111+
const enabledActionsList = hasEnabledActions
112+
? Object.entries(toggles)
113+
.filter(([_key, value]) => !!value)
114+
.map(([key]) => t(autoApproveSettingsConfig[key as AutoApproveSetting].labelKey))
115+
.join(", ")
116+
: t("chat:autoApprove.none")
112117

113118
const handleOpenSettings = useCallback(
114119
() =>
115120
window.postMessage({ type: "action", action: "settingsButtonClicked", values: { section: "autoApprove" } }),
116121
[],
117122
)
118123

124+
// Auto-uncheck if no actions are enabled
125+
useEffect(() => {
126+
if (autoApprovalEnabled && !hasEnabledActions) {
127+
setAutoApprovalEnabled(false)
128+
vscode.postMessage({ type: "autoApprovalEnabled", bool: false })
129+
}
130+
}, [autoApprovalEnabled, hasEnabledActions, setAutoApprovalEnabled])
131+
119132
return (
120133
<div
121134
style={{
@@ -136,14 +149,20 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
136149
cursor: "pointer",
137150
}}
138151
onClick={toggleExpanded}>
139-
<div onClick={(e) => e.stopPropagation()}>
152+
<div onClick={(e: React.MouseEvent) => e.stopPropagation()}>
140153
<VSCodeCheckbox
141154
checked={autoApprovalEnabled ?? false}
142155
onChange={() => {
143-
const newValue = !(autoApprovalEnabled ?? false)
144-
setAutoApprovalEnabled(newValue)
145-
vscode.postMessage({ type: "autoApprovalEnabled", bool: newValue })
156+
if (!isExpanded) {
157+
const newValue = !(autoApprovalEnabled ?? false)
158+
if (newValue && !hasEnabledActions) {
159+
return // Prevent checking if no actions enabled
160+
}
161+
setAutoApprovalEnabled(newValue)
162+
vscode.postMessage({ type: "autoApprovalEnabled", bool: newValue })
163+
}
146164
}}
165+
disabled={isExpanded || (!autoApprovalEnabled && !hasEnabledActions)}
147166
/>
148167
</div>
149168
<div
@@ -170,7 +189,7 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
170189
flex: 1,
171190
minWidth: 0,
172191
}}>
173-
{enabledActionsList || t("chat:autoApprove.none")}
192+
{enabledActionsList}
174193
</span>
175194
<span
176195
className={`codicon codicon-chevron-${isExpanded ? "down" : "right"}`}

0 commit comments

Comments
 (0)