(props: {
tools: readonly ToolSummary[];
selectedToolId: string | null;
onSelect: (toolId: string) => void;
onSetPolicy?: (pattern: string, action: ToolPolicyAction) => void;
onClearPolicy?: (pattern: string) => void;
patternForDisplay: (displayPattern: string) => string;
exactPatterns: ReadonlyMap<string, ToolPolicyAction>;
search: string;
terms: readonly string[];
selectedRowRef: React.Ref<HTMLButtonElement>;
})
| 495 | // --------------------------------------------------------------------------- |
| 496 | |
| 497 | function ToolTreeBody(props: { |
| 498 | tools: readonly ToolSummary[]; |
| 499 | selectedToolId: string | null; |
| 500 | onSelect: (toolId: string) => void; |
| 501 | onSetPolicy?: (pattern: string, action: ToolPolicyAction) => void; |
| 502 | onClearPolicy?: (pattern: string) => void; |
| 503 | patternForDisplay: (displayPattern: string) => string; |
| 504 | exactPatterns: ReadonlyMap<string, ToolPolicyAction>; |
| 505 | search: string; |
| 506 | terms: readonly string[]; |
| 507 | selectedRowRef: React.Ref<HTMLButtonElement>; |
| 508 | }) { |
| 509 | const { |
| 510 | tools, |
| 511 | selectedToolId, |
| 512 | onSelect, |
| 513 | onSetPolicy, |
| 514 | onClearPolicy, |
| 515 | patternForDisplay, |
| 516 | exactPatterns, |
| 517 | search, |
| 518 | terms, |
| 519 | selectedRowRef, |
| 520 | } = props; |
| 521 | const [manualOpen, setManualOpen] = useState<Set<string>>(() => new Set()); |
| 522 | |
| 523 | const tree = useMemo(() => buildTree(tools), [tools]); |
| 524 | |
| 525 | // When searching, expand everything so matches are visible. |
| 526 | // Also auto-expand groups that contain the selected tool. |
| 527 | const openSet = useMemo(() => { |
| 528 | if (terms.length > 0) { |
| 529 | const all = new Set<string>(); |
| 530 | collectGroupPaths(tree, all); |
| 531 | return all; |
| 532 | } |
| 533 | const set = new Set(manualOpen); |
| 534 | if (selectedToolId) { |
| 535 | const parts = selectedToolId.split("."); |
| 536 | // Progressively add ancestor paths (best-effort, based on dotted name). |
| 537 | let acc = ""; |
| 538 | for (let i = 0; i < parts.length - 1; i++) { |
| 539 | acc = acc ? `${acc}.${parts[i]}` : parts[i]!; |
| 540 | set.add(acc); |
| 541 | } |
| 542 | } |
| 543 | return set; |
| 544 | }, [tree, manualOpen, selectedToolId, terms.length]); |
| 545 | |
| 546 | const rows = useMemo(() => { |
| 547 | const acc: Row[] = []; |
| 548 | flattenTree(tree, 0, openSet, acc); |
| 549 | return acc; |
| 550 | }, [tree, openSet]); |
| 551 | |
| 552 | const toggleGroup = (path: string) => { |
| 553 | setManualOpen((prev) => { |
| 554 | const next = new Set(prev); |
nothing calls this directly
no test coverage detected