-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checkbox actions on selected nodes (#833)
* Toggle visibility for all selected nodes * Remove no longer needed refs * Cleanup
- Loading branch information
Showing
2 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...ges/itwin/tree-widget/src/components/trees/experimental/common/UseMultiCheckboxHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { PresentationHierarchyNode, PresentationTreeNode, isPresentationHierarchyNode } from "@itwin/presentation-hierarchies-react"; | ||
|
||
interface UseMultiCheckboxHandlerProps { | ||
rootNodes: PresentationTreeNode[] | undefined; | ||
isNodeSelected: (nodeId: string) => boolean; | ||
onClick: (node: PresentationHierarchyNode, checked: boolean) => void; | ||
} | ||
|
||
interface UseMultiCheckboxHandlerResult { | ||
onCheckboxClicked: (node: PresentationHierarchyNode, checked: boolean) => void; | ||
} | ||
|
||
/** @internal */ | ||
export function useMultiCheckboxHandler({ rootNodes, isNodeSelected, onClick }: UseMultiCheckboxHandlerProps): UseMultiCheckboxHandlerResult { | ||
const clickSelectedNodes = (nodes: Array<PresentationTreeNode>, checked: boolean) => { | ||
nodes.forEach((node) => { | ||
if (!isPresentationHierarchyNode(node)) { | ||
return; | ||
} | ||
if (isNodeSelected(node.id)) { | ||
onClick(node, checked); | ||
} | ||
if (node.isExpanded && typeof node.children !== "boolean") { | ||
clickSelectedNodes(node.children, checked); | ||
} | ||
}); | ||
}; | ||
|
||
const onCheckboxClicked = (node: PresentationHierarchyNode, checked: boolean) => { | ||
if (!isNodeSelected(node.id)) { | ||
onClick(node, checked); | ||
return; | ||
} | ||
rootNodes && clickSelectedNodes(rootNodes, checked); | ||
}; | ||
|
||
return { onCheckboxClicked }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters