feat(customHomePage/hierarchy): add possibility to automatically expand a single root node (#14429)

This commit is contained in:
v-tarasevich-blitz-brain 2025-08-21 00:51:32 +03:00 committed by GitHub
parent 22683e66ed
commit b5dad155f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 0 deletions

View File

@ -70,6 +70,7 @@ export default function DomainsTreeView({ assetUrns, shouldShowRelatedEntities,
nodes={tree.nodes}
loadChildren={startLoadingOfChildren}
onExpand={onExpand}
shouldExpandSingleRootNode
renderNodeLabel={(nodeProps) => (
<EntityItem
entity={nodeProps.node.entity}

View File

@ -71,6 +71,7 @@ export default function GlossaryTreeView({ assetUrns, shouldShowRelatedEntities,
nodes={tree.nodes}
loadChildren={startLoadingOfChildren}
onExpand={onExpand}
shouldExpandSingleRootNode
renderNodeLabel={(nodeProps) => (
<EntityItem
entity={nodeProps.node.entity}

View File

@ -18,6 +18,7 @@ export default function TreeViewContextProvider({
expandedValues,
updateExpandedValues,
onExpand,
shouldExpandSingleRootNode,
selectable,
updateSelectedValues,
expandParentNodesOfInitialSelectedValues,
@ -148,6 +149,18 @@ export default function TreeViewContextProvider({
[getAllSiblings, getIsExpandable],
);
const [isInitialAutoExpandingDone, setIsInitialAutoExpandingDone] = useState<boolean>(false);
useEffect(() => {
if (!isInitialAutoExpandingDone && preprocessedNodes.length > 0) {
if (shouldExpandSingleRootNode && preprocessedNodes.length === 1) {
expand(preprocessedNodes[0]);
}
setIsInitialAutoExpandingDone(true);
}
}, [shouldExpandSingleRootNode, isInitialAutoExpandingDone, preprocessedNodes, expand]);
// Sync internal expanded values
useEffect(() => {
if (expandedValues !== undefined) setInternalExpandedValues(expandedValues);

View File

@ -77,6 +77,8 @@ export interface TreeViewContextProviderProps {
updateExpandedValues?: (values: string[]) => void;
// Called when node was expanded
onExpand?: (node: TreeNode) => void;
// If enabled, automatically expand a single root node
shouldExpandSingleRootNode?: boolean;
// SELECTION
// If enabled it shows checkboxes next to nodes and enables selecting