Skip to content

Commit a3f1c05

Browse files
Address CodeRabbit review: immutable selection state and lint-compliant forEach callbacks.
1 parent 0717703 commit a3f1c05

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

web/pgadmin/static/js/PgTreeView/index.jsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default function PgTreeView({ data = [], hasCheckbox = false,
8888
// Update the clicked node and all its descendants with the new checked value
8989
const updateDescendants = (n, val) => {
9090
newState[n.id] = val;
91-
n.children?.forEach(child => updateDescendants(child, val));
91+
n.children?.forEach(child => { updateDescendants(child, val); });
9292
};
9393
updateDescendants(node, isChecked);
9494

@@ -118,19 +118,22 @@ export default function PgTreeView({ data = [], hasCheckbox = false,
118118
setCheckedState(newState);
119119

120120
// Collect all checked/indeterminate nodes from the entire tree
121-
// to provide complete selection state to selectionChange callback.
121+
// to provide complete selection state to selectionChange callback.
122+
// We use wrapper objects to avoid mutating the original node data.
122123
const allCheckedNodes = [];
123124
const collectAllCheckedNodes = (n) => {
124125
if (!n) return;
125126
const state = newState[n.id];
126127
if (state === true || state === 'indeterminate') {
127-
// Set isIndeterminate flag to differentiate full schema selection
128-
// from partial selection (only specific tables) in backup dialog
129-
n.data.isIndeterminate = (state === 'indeterminate');
130-
allCheckedNodes.push(n);
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+
});
131134
}
132135
// Recursively check all children
133-
n.children?.forEach(child => collectAllCheckedNodes(child));
136+
n.children?.forEach(child => { collectAllCheckedNodes(child); });
134137
};
135138

136139
// Navigate up to find the root level of the tree (parent of root nodes is '__root__')
@@ -143,7 +146,7 @@ export default function PgTreeView({ data = [], hasCheckbox = false,
143146
const rootParent = rootNode.parent;
144147
if (rootParent && rootParent.children) {
145148
// Iterate through all sibling root nodes to collect all checked nodes
146-
rootParent.children.forEach(root => collectAllCheckedNodes(root));
149+
rootParent.children.forEach(root => { collectAllCheckedNodes(root); });
147150
} else {
148151
// Fallback: if we can't find siblings, just traverse from the found root
149152
collectAllCheckedNodes(rootNode);

web/pgadmin/tools/backup/static/js/backup.ui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,8 @@ export default class BackupSchema extends BaseUISchema {
758758
'foreign table': [],
759759
'materialized view': [],
760760
};
761-
state?.objects?.forEach((node)=> {
762-
if(node.data.is_schema && !node.data?.isIndeterminate) {
761+
state?.objects?.forEach(({ node, isIndeterminate })=> {
762+
if(node.data.is_schema && !isIndeterminate) {
763763
selectedNodeCollection['schema'].push(node.data.name);
764764
} else if(['table', 'view', 'materialized view', 'foreign table', 'sequence'].includes(node.data.type) &&
765765
!node.data.is_collection && !selectedNodeCollection['schema'].includes(node.data.schema)) {

0 commit comments

Comments
 (0)