Skip to content

Commit f2d1364

Browse files
committed
fix: force expand all tree nodes on data updates
The tree component automatically collapses whenever the data updates. This happens because `defaultOpened` only works on the first load, and the library loses the expansion state when treeData receives new objects from useMemo. Added a useEffect that runs a recursive function to force open all nodes and their children every time treeData changes. This ensures the tree stays fully expanded even after data refreshes. Signed-off-by: Jasmina <jasmina.piric@secomind.com>
1 parent bbcd3d0 commit f2d1364

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

frontend/src/components/DeploymentDetails.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//
1717
// SPDX-License-Identifier: Apache-2.0
1818

19-
import { useCallback, useMemo, useState } from "react";
19+
import { useCallback, useEffect, useMemo, useState } from "react";
2020
import { Card, Col, Row } from "react-bootstrap";
2121
import Tree, { useTreeState } from "react-hyper-tree";
2222
import { FormattedMessage, useIntl } from "react-intl";
@@ -438,10 +438,26 @@ const ContainerDeploymentItem = ({
438438

439439
const { required, handlers } = useTreeState({
440440
data: treeData,
441-
defaultOpened: true,
442441
id: prefix,
443442
});
444443

444+
useEffect(() => {
445+
const openNodeAndChildren = (nodes: any[]) => {
446+
if (!nodes) return;
447+
448+
nodes.forEach((node) => {
449+
handlers.setOpen(node.id, true);
450+
if (node.children && node.children.length > 0) {
451+
openNodeAndChildren(node.children);
452+
}
453+
});
454+
};
455+
456+
if (treeData && treeData.length > 0) {
457+
openNodeAndChildren(treeData);
458+
}
459+
}, [treeData, handlers]);
460+
445461
return (
446462
<Tree
447463
{...required}

0 commit comments

Comments
 (0)