Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions webview-ui/src/components/chat/AutoApproveMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { memo, useCallback, useMemo, useState } from "react"
import { Trans } from "react-i18next"
import { VSCodeCheckbox, VSCodeLink, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
import { VSCodeCheckbox, VSCodeLink } from "@vscode/webview-ui-toolkit/react"

import { vscode } from "@src/utils/vscode"
import { useExtensionState } from "@src/context/ExtensionStateContext"
Expand All @@ -21,7 +21,6 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
autoApprovalEnabled,
setAutoApprovalEnabled,
alwaysApproveResubmit,
allowedMaxRequests,
setAlwaysAllowReadOnly,
setAlwaysAllowWrite,
setAlwaysAllowExecute,
Expand All @@ -32,7 +31,6 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
setAlwaysApproveResubmit,
setAlwaysAllowFollowupQuestions,
setAlwaysAllowUpdateTodoList,
setAllowedMaxRequests,
} = useExtensionState()

const { t } = useAppTranslation()
Expand Down Expand Up @@ -242,43 +240,6 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
</div>

<AutoApproveToggle {...toggles} onToggle={onAutoApproveToggle} />

{/* Auto-approve API request count limit input row inspired by Cline */}
<div
style={{
display: "flex",
alignItems: "center",
gap: "8px",
marginTop: "10px",
marginBottom: "8px",
color: "var(--vscode-descriptionForeground)",
}}>
<span style={{ flexShrink: 1, minWidth: 0 }}>
<Trans i18nKey="settings:autoApprove.apiRequestLimit.title" />:
</span>
<VSCodeTextField
placeholder={t("settings:autoApprove.apiRequestLimit.unlimited")}
value={(allowedMaxRequests ?? Infinity) === Infinity ? "" : allowedMaxRequests?.toString()}
onInput={(e) => {
const input = e.target as HTMLInputElement
// Remove any non-numeric characters
input.value = input.value.replace(/[^0-9]/g, "")
const value = parseInt(input.value)
const parsedValue = !isNaN(value) && value > 0 ? value : undefined
setAllowedMaxRequests(parsedValue)
vscode.postMessage({ type: "allowedMaxRequests", value: parsedValue })
}}
style={{ flex: 1 }}
/>
</div>
<div
style={{
color: "var(--vscode-descriptionForeground)",
fontSize: "12px",
marginBottom: "10px",
}}>
<Trans i18nKey="settings:autoApprove.apiRequestLimit.description" />
</div>
</div>
)}
</div>
Expand Down
32 changes: 31 additions & 1 deletion webview-ui/src/components/settings/AutoApproveSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { HTMLAttributes, useState } from "react"
import { X } from "lucide-react"
import { Trans } from "react-i18next"

import { useAppTranslation } from "@/i18n/TranslationContext"
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
import { VSCodeCheckbox, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
import { vscode } from "@/utils/vscode"
import { Button, Input, Slider, StandardTooltip } from "@/components/ui"

Expand Down Expand Up @@ -32,6 +33,7 @@ type AutoApproveSettingsProps = HTMLAttributes<HTMLDivElement> & {
followupAutoApproveTimeoutMs?: number
allowedCommands?: string[]
deniedCommands?: string[]
allowedMaxRequests?: number | null
setCachedStateField: SetCachedStateField<
| "alwaysAllowReadOnly"
| "alwaysAllowReadOnlyOutsideWorkspace"
Expand All @@ -50,6 +52,7 @@ type AutoApproveSettingsProps = HTMLAttributes<HTMLDivElement> & {
| "allowedCommands"
| "deniedCommands"
| "alwaysAllowUpdateTodoList"
| "allowedMaxRequests"
>
}

Expand All @@ -71,6 +74,7 @@ export const AutoApproveSettings = ({
alwaysAllowUpdateTodoList,
allowedCommands,
deniedCommands,
allowedMaxRequests,
setCachedStateField,
...props
}: AutoApproveSettingsProps) => {
Expand Down Expand Up @@ -374,6 +378,32 @@ export const AutoApproveSettings = ({
</div>
</div>
)}

{/* Max Requests Setting */}
<div className="flex flex-col gap-3 mt-6">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing visual grouping: Unlike other conditional settings sections (read-only, write, execute), this max requests setting doesn't have the visual grouping with left border that indicates it's part of the auto-approve feature set. This makes it appear disconnected from the other settings. Should this be grouped visually with the other auto-approve settings?

<div className="flex items-center gap-4 font-bold">
<span className="codicon codicon-number" />
<div>{t("settings:autoApprove.apiRequestLimit.title")}</div>
</div>
<div className="flex items-center gap-2">
<VSCodeTextField
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a data-testid attribute for testing consistency with other form elements in the component.

placeholder={t("settings:autoApprove.apiRequestLimit.unlimited")}
value={(allowedMaxRequests ?? Infinity) === Infinity ? "" : allowedMaxRequests?.toString()}
onInput={(e) => {
const input = e.target as HTMLInputElement
// Remove any non-numeric characters
input.value = input.value.replace(/[^0-9]/g, "")
const value = parseInt(input.value)
const parsedValue = !isNaN(value) && value > 0 ? value : undefined
setCachedStateField("allowedMaxRequests", parsedValue)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical: Missing immediate persistence behavior. The original implementation in AutoApproveMenu.tsx immediately persisted changes via vscode.postMessage. This new implementation only updates the cached state via setCachedStateField, which means the setting won't be saved until the user clicks the Save button. This creates inconsistent behavior compared to how this setting worked before. Should we maintain the immediate persistence behavior for consistency?

}}
style={{ flex: 1, maxWidth: "200px" }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent styling approach: This section mixes Tailwind classes with inline styles. For consistency with the rest of the component, consider using Tailwind classes throughout or following the existing pattern used by other settings sections.

/>
</div>
<div className="text-vscode-descriptionForeground text-sm">
<Trans i18nKey="settings:autoApprove.apiRequestLimit.description" />
</div>
</div>
</Section>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions webview-ui/src/components/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
followupAutoApproveTimeoutMs={followupAutoApproveTimeoutMs}
allowedCommands={allowedCommands}
deniedCommands={deniedCommands}
allowedMaxRequests={allowedMaxRequests}
setCachedStateField={setCachedStateField}
/>
)}
Expand Down