mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-01 02:01:27 +00:00
- SE-1: deny-by-default guard for unavailable custom mode config - SE-2: groupOptionsCache mode-scoped keys to prevent cross-mode contamination - SE-3: recordToolUsage moved after MCP filter check - Loading spinner for MCP servers/tools list while data loads
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { useRef, useEffect, useCallback } from "react"
|
|
|
|
import type { GroupEntry, ToolGroup } from "@roo-code/types"
|
|
|
|
import { syncCacheFromGroups, removeGroupWithCache, addGroupWithCache } from "./groupOptionsCache"
|
|
|
|
/**
|
|
* Custom hook that caches group options (tuple second element) when
|
|
* groups are removed, and restores them when groups are re-added.
|
|
*
|
|
* This prevents data loss when toggling a group like "mcp" off and
|
|
* back on — without the cache, the MCP filter config (mcpServers,
|
|
* mcpDefaultPolicy) would be discarded on uncheck.
|
|
*/
|
|
export function useGroupOptionsCache(groups: GroupEntry[], modeSlug: string) {
|
|
const groupOptionsCache = useRef<Map<string, object>>(new Map())
|
|
|
|
// Sync cache with external state: if external state has tuple
|
|
// entries, update the cache so that toggles preserve them.
|
|
useEffect(() => {
|
|
syncCacheFromGroups(groupOptionsCache.current, groups, modeSlug)
|
|
}, [groups, modeSlug])
|
|
|
|
const removeGroup = useCallback(
|
|
(currentGroups: GroupEntry[], groupName: string): GroupEntry[] => {
|
|
return removeGroupWithCache(groupOptionsCache.current, currentGroups, groupName, modeSlug)
|
|
},
|
|
[modeSlug],
|
|
)
|
|
|
|
const addGroup = useCallback(
|
|
(currentGroups: GroupEntry[], groupName: ToolGroup): GroupEntry[] => {
|
|
return addGroupWithCache(groupOptionsCache.current, currentGroups, groupName, modeSlug)
|
|
},
|
|
[modeSlug],
|
|
)
|
|
|
|
return { removeGroup, addGroup, cache: groupOptionsCache }
|
|
}
|