(node, isChecked)
| 83 | // Handle checkbox toggle and collect all checked nodes |
| 84 | // to pass complete selection state to the backup dialog |
| 85 | const toggleCheck = (node, isChecked) => { |
| 86 | const newState = { ...checkedState }; |
| 87 | |
| 88 | // Update the clicked node and all its descendants with the new checked value |
| 89 | const updateDescendants = (n, val) => { |
| 90 | newState[n.id] = val; |
| 91 | n.children?.forEach(child => { updateDescendants(child, val); }); |
| 92 | }; |
| 93 | updateDescendants(node, isChecked); |
| 94 | |
| 95 | // Update ancestor nodes to reflect the correct state (checked/unchecked/indeterminate) |
| 96 | // This ensures parent nodes show proper visual feedback based on children's state |
| 97 | let parent = node.parent; |
| 98 | while (parent && parent.id !== '__root__') { |
| 99 | // Check if ALL children are fully checked (state must be exactly true, |
| 100 | // not 'indeterminate') to mark parent as fully checked |
| 101 | const allChecked = parent.children.every(c => newState[c.id] === true); |
| 102 | // Check if ALL children are unchecked (falsy value: false, undefined, or null) |
| 103 | const noneChecked = parent.children.every(c => !newState[c.id]); |
| 104 | |
| 105 | if (allChecked) { |
| 106 | // All children checked -> parent is fully checked |
| 107 | newState[parent.id] = true; |
| 108 | } else if (noneChecked) { |
| 109 | // No children checked -> parent is unchecked |
| 110 | newState[parent.id] = false; |
| 111 | } else { |
| 112 | // Some children checked, some not -> parent shows indeterminate state |
| 113 | newState[parent.id] = 'indeterminate'; |
| 114 | } |
| 115 | parent = parent.parent; |
| 116 | } |
| 117 | |
| 118 | setCheckedState(newState); |
| 119 | |
| 120 | // Collect all checked/indeterminate nodes from the entire tree |
| 121 | // to provide complete selection state to selectionChange callback. |
| 122 | // We use wrapper objects to avoid mutating the original node data. |
| 123 | const allCheckedNodes = []; |
| 124 | const collectAllCheckedNodes = (n) => { |
| 125 | if (!n) return; |
| 126 | const state = newState[n.id]; |
| 127 | if (state === true || state === 'indeterminate') { |
| 128 | // Pass wrapper object with isIndeterminate flag to differentiate |
| 129 | // full schema selection from partial selection in backup dialog |
| 130 | allCheckedNodes.push({ |
| 131 | node: n, |
| 132 | isIndeterminate: state === 'indeterminate' |
| 133 | }); |
| 134 | } |
| 135 | // Recursively check all children |
| 136 | n.children?.forEach(child => { collectAllCheckedNodes(child); }); |
| 137 | }; |
| 138 | |
| 139 | // Navigate up to find the root level of the tree (parent of root nodes is '__root__') |
| 140 | let rootNode = node; |
| 141 | while (rootNode.parent && rootNode.parent.id !== '__root__') { |
| 142 | rootNode = rootNode.parent; |
nothing calls this directly
no test coverage detected