mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-25 00:48:45 +00:00
feat(customHomePage/hierarchy): add possibility to automatically expand a single root node (#14429)
This commit is contained in:
parent
22683e66ed
commit
b5dad155f7
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user