Roo-Code/webview-ui/src/hooks/useAutoApprovalState.ts
Hannes Rudolph 6cf376f832
fix: Resolve confusing auto-approve checkbox states (#5602)
Co-authored-by: Daniel Riccio <ricciodaniel98@gmail.com>
2025-07-16 17:52:29 -04:00

29 lines
833 B
TypeScript

import { useMemo } from "react"
interface AutoApprovalToggles {
alwaysAllowReadOnly?: boolean
alwaysAllowWrite?: boolean
alwaysAllowExecute?: boolean
alwaysAllowBrowser?: boolean
alwaysAllowMcp?: boolean
alwaysAllowModeSwitch?: boolean
alwaysAllowSubtasks?: boolean
alwaysApproveResubmit?: boolean
alwaysAllowFollowupQuestions?: boolean
alwaysAllowUpdateTodoList?: boolean
}
export function useAutoApprovalState(toggles: AutoApprovalToggles, autoApprovalEnabled?: boolean) {
const hasEnabledOptions = useMemo(() => {
return Object.values(toggles).some((value) => !!value)
}, [toggles])
const effectiveAutoApprovalEnabled = useMemo(() => {
return hasEnabledOptions && (autoApprovalEnabled ?? false)
}, [hasEnabledOptions, autoApprovalEnabled])
return {
hasEnabledOptions,
effectiveAutoApprovalEnabled,
}
}