Cui tree fix (#7680)

* [CUI] Fix for tree expansion

- Prevent infinite recursion
- Not sure how this has not happened before

* Code cleanup
This commit is contained in:
Oliver 2024-07-18 16:30:04 +10:00 committed by GitHub
parent 105dd7152e
commit cb2c2203f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -163,7 +163,13 @@ function generateTreeStructure(data, options) {
const nodes = {};
const roots = [];
for (let node of data) {
if (!data || !Array.isArray(data) || data.length == 0) {
return [];
}
for (let ii = 0; ii < data.length; ii++) {
let node = data[ii];
nodes[node.pk] = node;
node.selectable = false;
@ -173,12 +179,16 @@ function generateTreeStructure(data, options) {
};
if (options.processNode) {
data[data.indexOf(node)] = options.processNode(node);
node = options.processNode(node);
data[ii] = node;
}
}
for (let node of data) {
if (node.parent != null) {
for (let ii = 0; ii < data.length; ii++) {
let node = data[ii];
if (!!node.parent) {
if (nodes[node.parent].nodes) {
nodes[node.parent].nodes.push(node);
} else {
@ -186,9 +196,9 @@ function generateTreeStructure(data, options) {
}
if (node.state.expanded) {
while (node.parent != null) {
while (!!node.parent) {
nodes[node.parent].state.expanded = true;
data[data.indexOf(node)] = nodes[node.parent];
node = nodes[node.parent];
}
}