diff --git a/.gitignore b/.gitignore index 0c032bbf76..e45916d7e7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ node_modules coverage/ mock/ +# Webview UI specific ignores +webview-ui/node_modules +webview-ui/dist + .DS_Store # IDEs diff --git a/webview-ui/src/components/chat/AutoApproveMenu.tsx b/webview-ui/src/components/chat/AutoApproveMenu.tsx index ac02d6b8c4..e7f59f606c 100644 --- a/webview-ui/src/components/chat/AutoApproveMenu.tsx +++ b/webview-ui/src/components/chat/AutoApproveMenu.tsx @@ -43,6 +43,7 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => { (key: AutoApproveSetting, value: boolean) => { vscode.postMessage({ type: key, bool: value }) + // Update the specific setting switch (key) { case "alwaysAllowReadOnly": setAlwaysAllowReadOnly(value) @@ -69,6 +70,29 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => { setAlwaysApproveResubmit(value) break } + + // After updating the specific setting, check if any action is now enabled. + // If so, ensure autoApprovalEnabled is true. + // This needs to be done after the state updates, so we'll use a temporary check + // or re-evaluate the `toggles` object. + // For simplicity, we'll assume the `toggles` state will reflect the change + // in the next render cycle, and we can force autoApprovalEnabled to true + // if any action is being enabled. + if (value === true) { + setAutoApprovalEnabled(true) + vscode.postMessage({ type: "autoApprovalEnabled", bool: true }) + } else { + // If an action is being disabled, check if all are now disabled. + // If so, set autoApprovalEnabled to false. + // This requires re-evaluating the state of all toggles *after* the current one is set. + // A more robust solution would involve passing the updated `toggles` object + // or re-calculating `hasAnyAutoApprovedAction` here. + // For now, let's rely on the `hasAnyAutoApprovedAction` memoized value + // which will update on the next render. + // If the user unchecks the last enabled option, autoApprovalEnabled should become false. + // This logic is already handled by the main checkbox's disabled state in the collapsed view. + // So, we only need to ensure it turns ON when an individual is turned ON. + } }, [ setAlwaysAllowReadOnly, @@ -79,6 +103,7 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => { setAlwaysAllowModeSwitch, setAlwaysAllowSubtasks, setAlwaysApproveResubmit, + setAutoApprovalEnabled, // Added setAutoApprovalEnabled to dependencies ], ) @@ -107,10 +132,17 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => { ], ) - const enabledActionsList = Object.entries(toggles) - .filter(([_key, value]) => !!value) - .map(([key]) => t(autoApproveSettingsConfig[key as AutoApproveSetting].labelKey)) - .join(", ") + const hasAnyAutoApprovedAction = useMemo(() => Object.values(toggles).some((value) => !!value), [toggles]) + + const displayedAutoApproveText = useMemo(() => { + if (autoApprovalEnabled && hasAnyAutoApprovedAction) { + return Object.entries(toggles) + .filter(([_key, value]) => !!value) + .map(([key]) => t(autoApproveSettingsConfig[key as AutoApproveSetting].labelKey)) + .join(", ") + } + return t("chat:autoApprove.none") + }, [autoApprovalEnabled, hasAnyAutoApprovedAction, toggles, t]) const handleOpenSettings = useCallback( () => @@ -140,9 +172,10 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => { onClick={toggleExpanded}>