@itwin/presentation-hierarchies-react 1.6.8 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/lib/cjs/presentation-hierarchies-react/UseIModelTree.d.ts +2 -0
- package/lib/cjs/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/cjs/presentation-hierarchies-react/UseIModelTree.js +1 -1
- package/lib/cjs/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/cjs/presentation-hierarchies-react/UseTree.d.ts +3 -1
- package/lib/cjs/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/cjs/presentation-hierarchies-react/UseTree.js +3 -1
- package/lib/cjs/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/cjs/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/cjs/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +36 -23
- package/lib/cjs/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts +2 -0
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +3 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +3 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +37 -24
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @itwin/presentation-hierarchies-react
|
|
2
2
|
|
|
3
|
+
## 1.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 64e80beaeb87e5797d8238c14fa9cd8dbfcee7c3: Added `abortSignal` to `getFilteredPaths` callback used by `UseTree` hook. This allows to cancel ongoing requests when component is unmounted or new request is started.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies:
|
|
12
|
+
- @itwin/presentation-hierarchies@1.6.0
|
|
13
|
+
|
|
14
|
+
## 1.6.9
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#1000](https://github.com/iTwin/presentation/pull/1000): Made sure `Apply filter` button becomes focused after hierarchy level filter is applied.
|
|
19
|
+
|
|
3
20
|
## 1.6.8
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -19,6 +19,8 @@ type UseIModelTreeProps = Omit<UseTreeProps, "getHierarchyProvider" | "getFilter
|
|
|
19
19
|
getFilteredPaths?: (props: {
|
|
20
20
|
/** Object that provides access to the iModel schema and can run queries against the iModel. */
|
|
21
21
|
imodelAccess: IModelAccess;
|
|
22
|
+
/** Signal indicating that that the request was canceled */
|
|
23
|
+
abortSignal: AbortSignal;
|
|
22
24
|
}) => Promise<HierarchyFilteringPath[] | undefined>;
|
|
23
25
|
};
|
|
24
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC7H,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CA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AAG,cAAc,GAAG,eAAe,CAAC,GAAG;IAC1F,sDAAsD;IACtD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,YAAY,EAAE,YAAY,CAAA;KAAE,KAAK,mBAAmB,CAAC;IAEvF,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE;QACzB,+FAA+F;QAC/F,YAAY,EAAE,YAAY,CAAC;QAC3B,2DAA2D;QAC3D,WAAW,EAAE,WAAW,CAAC;KAC1B,KAAK,OAAO,CAAC,sBAAsB,EAAE,GAAG,SAAS,CAAC,CAAC;CACrD,CAAC;AAEJ;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAMtE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,kBAAkB,GAAG,4BAA4B,GAAG,aAAa,CAMrH"}
|
|
@@ -60,7 +60,7 @@ function useIModelTreeProps(props) {
|
|
|
60
60
|
hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),
|
|
61
61
|
localizedStrings,
|
|
62
62
|
}), [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings]),
|
|
63
|
-
getFilteredPaths: (0, react_1.useCallback)(async () => getFilteredPaths?.({ imodelAccess }), [imodelAccess, getFilteredPaths]),
|
|
63
|
+
getFilteredPaths: (0, react_1.useCallback)(async ({ abortSignal }) => getFilteredPaths?.({ imodelAccess, abortSignal }), [imodelAccess, getFilteredPaths]),
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
//# sourceMappingURL=UseIModelTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;
|
|
1
|
+
{"version":3,"file":"UseIModelTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModel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gBAAgB,CAAC,CACxE;QACD,gBAAgB,EAAE,IAAA,mBAAW,EAC3B,KAAK,EAAE,EAAE,WAAW,EAAgC,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,EAC1G,CAAC,YAAY,EAAE,gBAAgB,CAAC,CACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { createIModelHierarchyProvider, HierarchyDefinition, HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\nimport { Props } from \"@itwin/presentation-shared\";\nimport { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { useTree, UseTreeProps, UseTreeResult, useUnifiedSelectionTree } from \"./UseTree.js\";\n\n/** @public */\ntype IModelHierarchyProviderProps = Props<typeof createIModelHierarchyProvider>;\n\n/** @public */\ntype IModelAccess = IModelHierarchyProviderProps[\"imodelAccess\"];\n\n/**\n * Props for `useIModelTree` and `useIModelUnifiedSelectionTree` hooks.\n * @public\n */\ntype UseIModelTreeProps = Omit<UseTreeProps, \"getHierarchyProvider\" | \"getFilteredPaths\"> &\n Pick<IModelHierarchyProviderProps, \"localizedStrings\" | \"imodelAccess\" | \"imodelChanged\"> & {\n /** Provides the hierarchy definition for the tree. */\n getHierarchyDefinition: (props: { imodelAccess: IModelAccess }) => HierarchyDefinition;\n\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: (props: {\n /** Object that provides access to the iModel schema and can run queries against the iModel. */\n imodelAccess: IModelAccess;\n /** Signal indicating that that the request was canceled */\n abortSignal: AbortSignal;\n }) => Promise<HierarchyFilteringPath[] | undefined>;\n };\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @public\n */\nexport function useIModelTree(props: UseIModelTreeProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),\n });\n}\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data and that is integrated with unified selection through the given selection\n * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useIModelTree`\n * @see `useUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useIModelUnifiedSelectionTree(props: UseIModelTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"localizedStrings\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getFilteredPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings } = props;\n return {\n getHierarchyProvider: useCallback(\n () =>\n createIModelHierarchyProvider({\n imodelAccess,\n imodelChanged,\n hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),\n localizedStrings,\n }),\n [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings],\n ),\n getFilteredPaths: useCallback(\n async ({ abortSignal }: { abortSignal: AbortSignal }) => getFilteredPaths?.({ imodelAccess, abortSignal }),\n [imodelAccess, getFilteredPaths],\n ),\n };\n}\n"]}
|
|
@@ -58,7 +58,9 @@ export interface UseTreeProps {
|
|
|
58
58
|
/** Provides the hierarchy provider for the tree. */
|
|
59
59
|
getHierarchyProvider: () => HierarchyProvider;
|
|
60
60
|
/** Provides paths to filtered nodes. */
|
|
61
|
-
getFilteredPaths?: (
|
|
61
|
+
getFilteredPaths?: ({ abortSignal }: {
|
|
62
|
+
abortSignal: AbortSignal;
|
|
63
|
+
}) => Promise<HierarchyFilteringPath[] | undefined>;
|
|
62
64
|
/**
|
|
63
65
|
* Callback that is called just after a certain action is finished.
|
|
64
66
|
* Can be used for performance tracking.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAClI,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAGnF,OAAO,EAA2B,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAE1G,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,8FAA8F;IAC9F,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,8DAA8D;IAC9D,uBAAuB,EAAE,CAAC,KAAK,CAAC,EAAE;QAChC,cAAc,CAAC,EAAE,qBAAqB,CAAC;QACvC,uBAAuB,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;KAChD,KAAK,qBAAqB,CAA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EAAE,CAAC,SAAS,EAAE,wBAAwB,GAAG,SAAS,KAAK,IAAI,CAAC;CACzE"}
|
|
@@ -85,6 +85,7 @@ function useTreeInternal({ getHierarchyProvider, getFilteredPaths, onPerformance
|
|
|
85
85
|
const [isFiltering, setIsFiltering] = (0, react_1.useState)(false);
|
|
86
86
|
(0, react_1.useEffect)(() => {
|
|
87
87
|
let disposed = false;
|
|
88
|
+
const controller = new AbortController();
|
|
88
89
|
void (async () => {
|
|
89
90
|
if (!hierarchyProvider) {
|
|
90
91
|
return;
|
|
@@ -99,7 +100,7 @@ function useTreeInternal({ getHierarchyProvider, getFilteredPaths, onPerformance
|
|
|
99
100
|
setIsFiltering(true);
|
|
100
101
|
let paths;
|
|
101
102
|
try {
|
|
102
|
-
paths = await getFilteredPaths();
|
|
103
|
+
paths = await getFilteredPaths({ abortSignal: controller.signal });
|
|
103
104
|
}
|
|
104
105
|
catch {
|
|
105
106
|
}
|
|
@@ -111,6 +112,7 @@ function useTreeInternal({ getHierarchyProvider, getFilteredPaths, onPerformance
|
|
|
111
112
|
}
|
|
112
113
|
})();
|
|
113
114
|
return () => {
|
|
115
|
+
controller.abort();
|
|
114
116
|
disposed = true;
|
|
115
117
|
};
|
|
116
118
|
}, [hierarchyProvider, getFilteredPaths, actions]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAiDhG,0BAGC;AAiBD,0DAMC;AAzED,iCAAiE;AACjE,8EAAkI;AAElI,8DAAwD;AACxD,0DAA6J;AAC7J,8EAA0G;AAC1G,kDAAkD;AA6BlD;;;;;;;;;;;GAWG;AACH,SAAgB,OAAO,CAAC,KAAmB;IACzC,MAAM,EAAE,gBAAgB,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAChE,OAAO,IAAI,CAAC;AACd,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K,CAAC,CAAC,CAAC;IAEZ,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { GenericInstanceFilter, HierarchyFilteringPath, HierarchyNode, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey, IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { isTreeModelHierarchyNode, isTreeModelInfoNode, TreeModel, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection, UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { PresentationHierarchyNode, PresentationTreeNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\n\n/**\n * A data structure that contains information about a single hierarchy level.\n * @public\n */\nexport interface HierarchyLevelDetails {\n /** The parent node whose hierarchy level's information is contained in this data structure */\n hierarchyNode: HierarchyNode | undefined;\n\n /** A function to get instance keys of the hierarchy level. */\n getInstanceKeysIterator: (props?: {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n }) => AsyncIterableIterator<InstanceKey>;\n\n /** Get the limit of how many nodes can be loaded in this hierarchy level. */\n sizeLimit?: number | \"unbounded\";\n /** Set the limit of how many nodes can be loaded in this hierarchy level. */\n setSizeLimit: (value: undefined | number | \"unbounded\") => void;\n\n /** Get the active instance filter applied to this hierarchy level. */\n instanceFilter?: GenericInstanceFilter;\n /** Set the instance filter to apply to this hierarchy level */\n setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;\n}\n\n/**\n * A React hook that creates state for a tree component.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({ sourceName, selectionStorage, ...props }: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n return {\n ...rest,\n ...useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode }),\n };\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: () => Promise<HierarchyFilteringPath[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n}\n\n/**\n * Options for doing either full or a sub tree reload.\n * @public\n */\ninterface ReloadTreeOptions {\n /** Specifies parent node under which sub tree should be reloaded. */\n parentNodeId: string | undefined;\n\n /**\n * Specifies how current tree state should be handled:\n * - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).\n * - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.\n * - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.\n *\n * Defaults to `\"keep\"`.\n */\n state?: \"keep\" | \"discard\" | \"reset\";\n}\n\n/** @public */\nexport interface UseTreeResult {\n /**\n * Array containing root tree nodes. It is `undefined` on initial render until any nodes are loaded.\n */\n rootNodes: PresentationTreeNode[] | undefined;\n /**\n * Specifies whether tree is loading or not. It is set to `true` when initial tree load is in progress\n * or tree is reloading.\n */\n isLoading: boolean;\n /**\n * A function that should be called to reload the tree.\n */\n reloadTree: (options?: ReloadTreeOptions) => void;\n /**\n * A function that should be called to either expand or collapse the given node.\n */\n expandNode: (nodeId: string, isExpanded: boolean) => void;\n /**\n * A function that should be called to select nodes in the tree.\n * @param nodeIds Ids of the nodes that are selected.\n * @param changeType Type of change that occurred for the selection.\n */\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n /** Determines whether a given node is selected. */\n isNodeSelected: (nodeId: string) => boolean;\n /** Get a tree node by id */\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n /** Returns hierarchy level details for a given node ID. */\n getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;\n /** Sets a formatter for the primitive values that are displayed in the hierarchy. */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n}\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<PresentationTreeNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getFilteredPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes = model.parentChildMap.get(undefined) !== undefined ? generateTreeStructure(undefined, model) : undefined;\n setState({\n model,\n rootNodes,\n });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs?.filterChange?.newFilter !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isFiltering, setIsFiltering] = useState(false);\n useEffect(() => {\n let disposed = false;\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getFilteredPaths) {\n hierarchyProvider.setHierarchyFilter(undefined);\n // reload tree in case hierarchy provider does not use hierarchy filter to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsFiltering(false);\n return;\n }\n\n setIsFiltering(true);\n let paths: HierarchyFilteringPath[] | undefined;\n try {\n paths = await getFilteredPaths();\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchyFilter(paths ? { paths } : undefined);\n setIsFiltering(false);\n }\n }\n })();\n return () => {\n disposed = true;\n };\n }, [hierarchyProvider, getFilteredPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): PresentationHierarchyNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return undefined;\n }\n return createPresentationHierarchyNode(node, state.model);\n },\n [actions, state.model],\n );\n\n const expandNode = useCallback<UseTreeResult[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<UseTreeResult[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<UseTreeResult[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<UseTreeResult[\"isNodeSelected\"]>((nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId), [state]);\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n /* c8 ignore next 3 */\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<UseTreeResult[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node || isTreeModelInfoNode(node)) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n return {\n rootNodes: state.rootNodes,\n isLoading: !!state.model.rootNode.isLoading || isFiltering,\n expandNode,\n reloadTree,\n selectNodes,\n isNodeSelected,\n getTreeModelNode,\n getNode,\n getHierarchyLevelDetails,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(parentNodeId: string | undefined, model: TreeModel): Array<PresentationTreeNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelNode => !!node)\n .map<PresentationTreeNode>((node) => {\n if (isTreeModelHierarchyNode(node)) {\n return createPresentationHierarchyNode(node, model);\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n resultSetSizeLimit: node.resultSetSizeLimit,\n };\n }\n\n if (node.type === \"NoFilterMatches\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n };\n }\n\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n message: node.message,\n };\n });\n}\n\nfunction createPresentationHierarchyNode(modelNode: TreeModelHierarchyNode, model: TreeModel): PresentationHierarchyNode {\n let children: Array<PresentationTreeNode> | undefined;\n return {\n ...toPresentationHierarchyNodeBase(modelNode),\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n\nfunction toPresentationHierarchyNodeBase(node: TreeModelHierarchyNode): Omit<PresentationHierarchyNode, \"children\"> {\n return {\n id: node.id,\n label: node.label,\n nodeData: node.nodeData,\n isLoading: !!node.isLoading,\n isExpanded: !!node.isExpanded,\n isFilterable: !HierarchyNode.isGroupingNode(node.nodeData) && !!node.nodeData.supportsFiltering && node.children,\n isFiltered: !!node.instanceFilter,\n extendedData: node.nodeData.extendedData,\n };\n}\n\nfunction useLatest<T>(value: T) {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAiDhG,0BAGC;AAiBD,0DAMC;AAzED,iCAAiE;AACjE,8EAAkI;AAElI,8DAAwD;AACxD,0DAA6J;AAC7J,8EAA0G;AAC1G,kDAAkD;AA6BlD;;;;;;;;;;;GAWG;AACH,SAAgB,OAAO,CAAC,KAAmB;IACzC,MAAM,EAAE,gBAAgB,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAChE,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,uBAAuB,CAAC,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,KAAK,EAA+C;IAC7H,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAC7D,OAAO;QACL,GAAG,IAAI;QACP,GAAG,IAAA,gDAAuB,EAAC,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;KAC/E,CAAC;AACJ,CAAC;AA8ED,SAAS,eAAe,CAAC,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,GACP;IAGb,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAY;QAC5C,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,cAAc,EAAE,IAAI,GAAG,EAAE,EA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;QACvE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,+BAA+B,CAAC,IAA4B;IACnE,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS;QAC3B,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU;QAC7B,YAAY,EAAE,CAAC,wCAAa,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,iBAAiB,IAAI,IAAI,CAAC,QAAQ;QAChH,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc;QACjC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY;KACzC,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAI,KAAQ;IAC5B,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,KAAK,CAAC,CAAC;IAC1B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { GenericInstanceFilter, HierarchyFilteringPath, HierarchyNode, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey, IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { isTreeModelHierarchyNode, isTreeModelInfoNode, TreeModel, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection, UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { PresentationHierarchyNode, PresentationTreeNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\n\n/**\n * A data structure that contains information about a single hierarchy level.\n * @public\n */\nexport interface HierarchyLevelDetails {\n /** The parent node whose hierarchy level's information is contained in this data structure */\n hierarchyNode: HierarchyNode | undefined;\n\n /** A function to get instance keys of the hierarchy level. */\n getInstanceKeysIterator: (props?: {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n }) => AsyncIterableIterator<InstanceKey>;\n\n /** Get the limit of how many nodes can be loaded in this hierarchy level. */\n sizeLimit?: number | \"unbounded\";\n /** Set the limit of how many nodes can be loaded in this hierarchy level. */\n setSizeLimit: (value: undefined | number | \"unbounded\") => void;\n\n /** Get the active instance filter applied to this hierarchy level. */\n instanceFilter?: GenericInstanceFilter;\n /** Set the instance filter to apply to this hierarchy level */\n setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;\n}\n\n/**\n * A React hook that creates state for a tree component.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({ sourceName, selectionStorage, ...props }: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n return {\n ...rest,\n ...useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode }),\n };\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: ({ abortSignal }: { abortSignal: AbortSignal }) => Promise<HierarchyFilteringPath[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n}\n\n/**\n * Options for doing either full or a sub tree reload.\n * @public\n */\ninterface ReloadTreeOptions {\n /** Specifies parent node under which sub tree should be reloaded. */\n parentNodeId: string | undefined;\n\n /**\n * Specifies how current tree state should be handled:\n * - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).\n * - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.\n * - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.\n *\n * Defaults to `\"keep\"`.\n */\n state?: \"keep\" | \"discard\" | \"reset\";\n}\n\n/** @public */\nexport interface UseTreeResult {\n /**\n * Array containing root tree nodes. It is `undefined` on initial render until any nodes are loaded.\n */\n rootNodes: PresentationTreeNode[] | undefined;\n /**\n * Specifies whether tree is loading or not. It is set to `true` when initial tree load is in progress\n * or tree is reloading.\n */\n isLoading: boolean;\n /**\n * A function that should be called to reload the tree.\n */\n reloadTree: (options?: ReloadTreeOptions) => void;\n /**\n * A function that should be called to either expand or collapse the given node.\n */\n expandNode: (nodeId: string, isExpanded: boolean) => void;\n /**\n * A function that should be called to select nodes in the tree.\n * @param nodeIds Ids of the nodes that are selected.\n * @param changeType Type of change that occurred for the selection.\n */\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n /** Determines whether a given node is selected. */\n isNodeSelected: (nodeId: string) => boolean;\n /** Get a tree node by id */\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n /** Returns hierarchy level details for a given node ID. */\n getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;\n /** Sets a formatter for the primitive values that are displayed in the hierarchy. */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n}\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<PresentationTreeNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getFilteredPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes = model.parentChildMap.get(undefined) !== undefined ? generateTreeStructure(undefined, model) : undefined;\n setState({\n model,\n rootNodes,\n });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs?.filterChange?.newFilter !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isFiltering, setIsFiltering] = useState(false);\n useEffect(() => {\n let disposed = false;\n const controller = new AbortController();\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getFilteredPaths) {\n hierarchyProvider.setHierarchyFilter(undefined);\n // reload tree in case hierarchy provider does not use hierarchy filter to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsFiltering(false);\n return;\n }\n\n setIsFiltering(true);\n let paths: HierarchyFilteringPath[] | undefined;\n try {\n paths = await getFilteredPaths({ abortSignal: controller.signal });\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchyFilter(paths ? { paths } : undefined);\n setIsFiltering(false);\n }\n }\n })();\n return () => {\n controller.abort();\n disposed = true;\n };\n }, [hierarchyProvider, getFilteredPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): PresentationHierarchyNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return undefined;\n }\n return createPresentationHierarchyNode(node, state.model);\n },\n [actions, state.model],\n );\n\n const expandNode = useCallback<UseTreeResult[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<UseTreeResult[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<UseTreeResult[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<UseTreeResult[\"isNodeSelected\"]>((nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId), [state]);\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n /* c8 ignore next 3 */\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<UseTreeResult[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node || isTreeModelInfoNode(node)) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n return {\n rootNodes: state.rootNodes,\n isLoading: !!state.model.rootNode.isLoading || isFiltering,\n expandNode,\n reloadTree,\n selectNodes,\n isNodeSelected,\n getTreeModelNode,\n getNode,\n getHierarchyLevelDetails,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(parentNodeId: string | undefined, model: TreeModel): Array<PresentationTreeNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelNode => !!node)\n .map<PresentationTreeNode>((node) => {\n if (isTreeModelHierarchyNode(node)) {\n return createPresentationHierarchyNode(node, model);\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n resultSetSizeLimit: node.resultSetSizeLimit,\n };\n }\n\n if (node.type === \"NoFilterMatches\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n };\n }\n\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n message: node.message,\n };\n });\n}\n\nfunction createPresentationHierarchyNode(modelNode: TreeModelHierarchyNode, model: TreeModel): PresentationHierarchyNode {\n let children: Array<PresentationTreeNode> | undefined;\n return {\n ...toPresentationHierarchyNodeBase(modelNode),\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n\nfunction toPresentationHierarchyNodeBase(node: TreeModelHierarchyNode): Omit<PresentationHierarchyNode, \"children\"> {\n return {\n id: node.id,\n label: node.label,\n nodeData: node.nodeData,\n isLoading: !!node.isLoading,\n isExpanded: !!node.isExpanded,\n isFilterable: !HierarchyNode.isGroupingNode(node.nodeData) && !!node.nodeData.supportsFiltering && node.children,\n isFiltered: !!node.instanceFilter,\n extendedData: node.nodeData.extendedData,\n };\n}\n\nfunction useLatest<T>(value: T) {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EAAE,wBAAw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EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACxH,iGAAiG;IACjG,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACrF,6CAA6C;IAC7C,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,gFAAgF;IAChF,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAC3B;;;;;;;;OAQG;IACH,uBAAuB,CAAC,EAAE,eAAe,GAAG,MAAM,CAAC;CACpD;AAED,cAAc;AACd,KAAK,qBAAqB,GAAG,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,GAC5D,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,0BAA0B,CAAC,CAAC,GACxD,IAAI,CAAC,aAAa,EAAE,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,MAAM,CAAC,GACnE,wBAAwB,CAAC;AAE3B;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,yBAAyB,CAAC,qBAAqB,GAAG,aAAa,CAAC,cAAc,CAAC,CA+FnH,CAAC"}
|
|
@@ -27,48 +27,61 @@ const LocalizationContext_js_1 = require("./LocalizationContext.js");
|
|
|
27
27
|
*/
|
|
28
28
|
exports.TreeNodeRenderer = (0, react_1.forwardRef)(({ node, expandNode, getIcon, getLabel, getSublabel, onFilterClick, onNodeClick, onNodeKeyDown, isSelected, isDisabled, actionButtonsClassName, getHierarchyLevelDetails, reloadTree, size, filterButtonsVisibility, ...treeNodeProps }, forwardedRef) => {
|
|
29
29
|
const { localizedStrings } = (0, LocalizationContext_js_1.useLocalizationContext)();
|
|
30
|
-
const applyFilterButtonRef = (0, react_1.useRef)(null);
|
|
31
|
-
const nodeRef = (0, react_1.useRef)(null);
|
|
32
|
-
const ref = useMergedRefs(forwardedRef, nodeRef);
|
|
33
30
|
if ("type" in node && node.type === "ChildrenPlaceholder") {
|
|
34
|
-
return (0, jsx_runtime_1.jsx)(PlaceholderNode, { ...treeNodeProps, ref:
|
|
31
|
+
return (0, jsx_runtime_1.jsx)(PlaceholderNode, { ...treeNodeProps, ref: forwardedRef, size: size });
|
|
35
32
|
}
|
|
36
33
|
if ((0, TreeNode_js_1.isPresentationHierarchyNode)(node)) {
|
|
37
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
38
|
-
// Ignore if it is called on the element inside, e.g. checkbox or expander
|
|
39
|
-
if (!isDisabled && event.target === nodeRef.current) {
|
|
40
|
-
onNodeKeyDown?.(node, !isSelected, event);
|
|
41
|
-
}
|
|
42
|
-
}, onExpanded: (_, isExpanded) => {
|
|
43
|
-
expandNode(node.id, isExpanded);
|
|
44
|
-
}, icon: getIcon ? getIcon(node) : undefined, label: getLabel ? getLabel(node) : node.label, sublabel: getSublabel ? getSublabel(node) : undefined, children: (0, jsx_runtime_1.jsxs)(itwinui_react_1.ButtonGroup, { className: (0, classnames_1.default)("action-buttons", actionButtonsClassName), children: [getHierarchyLevelDetails && node.isFiltered ? ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { className: "filtering-action-button", styleType: "borderless", size: "small", label: localizedStrings.clearHierarchyLevelFilter, onClick: (e) => {
|
|
45
|
-
e.stopPropagation();
|
|
46
|
-
getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);
|
|
47
|
-
applyFilterButtonRef.current?.focus();
|
|
48
|
-
}, children: (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgRemove, {}) })) : null, onFilterClick && node.isFilterable && (filterButtonsVisibility !== "hide" || node.isFiltered) ? ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { ref: applyFilterButtonRef, className: "filtering-action-button", styleType: "borderless", size: "small", label: localizedStrings.filterHierarchyLevel, onClick: (e) => {
|
|
49
|
-
e.stopPropagation();
|
|
50
|
-
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
51
|
-
hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);
|
|
52
|
-
}, children: node.isFiltered ? (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgFilter, {}) : (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgFilterHollow, {}) })) : null] }) }));
|
|
34
|
+
return ((0, jsx_runtime_1.jsx)(HierarchyNodeRenderer, { ...treeNodeProps, ref: forwardedRef, node: node, expandNode: expandNode, getIcon: getIcon, getLabel: getLabel, getSublabel: getSublabel, onFilterClick: onFilterClick, onNodeClick: onNodeClick, onNodeKeyDown: onNodeKeyDown, isSelected: isSelected, isDisabled: isDisabled, actionButtonsClassName: actionButtonsClassName, getHierarchyLevelDetails: getHierarchyLevelDetails, filterButtonsVisibility: filterButtonsVisibility }));
|
|
53
35
|
}
|
|
54
36
|
if (node.type === "ResultSetTooLarge") {
|
|
55
37
|
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);
|
|
56
38
|
const isFilterable = hierarchyLevelDetails?.hierarchyNode &&
|
|
57
39
|
!presentation_hierarchies_1.HierarchyNode.isGroupingNode(hierarchyLevelDetails.hierarchyNode) &&
|
|
58
40
|
hierarchyLevelDetails.hierarchyNode.supportsFiltering;
|
|
59
|
-
return ((0, jsx_runtime_1.jsx)(ResultSetTooLargeNode, { ...treeNodeProps, ref:
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(ResultSetTooLargeNode, { ...treeNodeProps, ref: forwardedRef, limit: node.resultSetSizeLimit, onOverrideLimit: hierarchyLevelDetails ? (limit) => hierarchyLevelDetails.setSizeLimit(limit) : undefined, onFilterClick: onFilterClick && hierarchyLevelDetails && isFilterable
|
|
60
42
|
? () => {
|
|
61
43
|
onFilterClick(hierarchyLevelDetails);
|
|
62
44
|
}
|
|
63
45
|
: undefined }));
|
|
64
46
|
}
|
|
65
47
|
if (node.type === "NoFilterMatches") {
|
|
66
|
-
return (0, jsx_runtime_1.jsx)(itwinui_react_1.TreeNode, { ...treeNodeProps, ref:
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(itwinui_react_1.TreeNode, { ...treeNodeProps, ref: forwardedRef, label: localizedStrings.noFilteredChildren, isDisabled: true, onExpanded: /* c8 ignore next */ () => { } }));
|
|
67
49
|
}
|
|
68
50
|
const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: "reset" }) : undefined;
|
|
69
|
-
return ((0, jsx_runtime_1.jsx)(itwinui_react_1.TreeNode, { ...treeNodeProps, ref:
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)(itwinui_react_1.TreeNode, { ...treeNodeProps, ref: forwardedRef, label: (0, jsx_runtime_1.jsx)(ErrorNodeLabel, { message: node.message, onRetry: onRetry }), isDisabled: true, onExpanded: /* c8 ignore next */ () => { } }));
|
|
70
52
|
});
|
|
71
53
|
exports.TreeNodeRenderer.displayName = "TreeNodeRenderer";
|
|
54
|
+
const HierarchyNodeRenderer = (0, react_1.forwardRef)(({ node, expandNode, getIcon, getLabel, getSublabel, onFilterClick, onNodeClick, onNodeKeyDown, isSelected, isDisabled, actionButtonsClassName, getHierarchyLevelDetails, filterButtonsVisibility, ...treeNodeProps }, forwardedRef) => {
|
|
55
|
+
const { localizedStrings } = (0, LocalizationContext_js_1.useLocalizationContext)();
|
|
56
|
+
const applyFilterButtonRef = (0, react_1.useRef)(null);
|
|
57
|
+
const nodeRef = (0, react_1.useRef)(null);
|
|
58
|
+
const ref = useMergedRefs(forwardedRef, nodeRef);
|
|
59
|
+
const prevIsFiltered = (0, react_1.useRef)(node.isFiltered);
|
|
60
|
+
(0, react_1.useEffect)(() => {
|
|
61
|
+
// If the node is filtered, focus the apply filter button
|
|
62
|
+
if (node.isFiltered && !prevIsFiltered.current) {
|
|
63
|
+
applyFilterButtonRef.current?.focus();
|
|
64
|
+
}
|
|
65
|
+
prevIsFiltered.current = node.isFiltered;
|
|
66
|
+
}, [node.isFiltered]);
|
|
67
|
+
return ((0, jsx_runtime_1.jsx)(itwinui_react_1.TreeNode, { ...treeNodeProps, ref: ref, isSelected: isSelected, isDisabled: isDisabled, className: (0, classnames_1.default)(treeNodeProps.className, "stateless-tree-node", { filtered: node.isFiltered }), onClick: (event) => !isDisabled && onNodeClick?.(node, !isSelected, event), onKeyDown: (event) => {
|
|
68
|
+
// Ignore if it is called on the element inside, e.g. checkbox or expander
|
|
69
|
+
if (!isDisabled && event.target === nodeRef.current) {
|
|
70
|
+
onNodeKeyDown?.(node, !isSelected, event);
|
|
71
|
+
}
|
|
72
|
+
}, onExpanded: (_, isExpanded) => {
|
|
73
|
+
expandNode(node.id, isExpanded);
|
|
74
|
+
}, icon: getIcon ? getIcon(node) : undefined, label: getLabel ? getLabel(node) : node.label, sublabel: getSublabel ? getSublabel(node) : undefined, children: (0, jsx_runtime_1.jsxs)(itwinui_react_1.ButtonGroup, { className: (0, classnames_1.default)("action-buttons", actionButtonsClassName), children: [getHierarchyLevelDetails && node.isFiltered ? ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { className: "filtering-action-button", styleType: "borderless", size: "small", label: localizedStrings.clearHierarchyLevelFilter, onClick: (e) => {
|
|
75
|
+
e.stopPropagation();
|
|
76
|
+
getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);
|
|
77
|
+
applyFilterButtonRef.current?.focus();
|
|
78
|
+
}, children: (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgRemove, {}) })) : null, onFilterClick && node.isFilterable && (filterButtonsVisibility !== "hide" || node.isFiltered) ? ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { ref: applyFilterButtonRef, className: "filtering-action-button", styleType: "borderless", size: "small", label: localizedStrings.filterHierarchyLevel, onClick: (e) => {
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
81
|
+
hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);
|
|
82
|
+
}, children: node.isFiltered ? (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgFilter, {}) : (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgFilterHollow, {}) })) : null] }) }));
|
|
83
|
+
});
|
|
84
|
+
HierarchyNodeRenderer.displayName = "HierarchyNodeRenderer";
|
|
72
85
|
const PlaceholderNode = (0, react_1.forwardRef)(({ size, ...props }, forwardedRef) => {
|
|
73
86
|
const { localizedStrings } = (0, LocalizationContext_js_1.useLocalizationContext)();
|
|
74
87
|
return ((0, jsx_runtime_1.jsx)(itwinui_react_1.TreeNode, { ...props, ref: forwardedRef, label: localizedStrings.loading, icon: (0, jsx_runtime_1.jsx)(itwinui_react_1.ProgressRadial, { size: "x-small", indeterminate: true, title: localizedStrings.loading, className: (0, classnames_1.default)(props.className, { "stateless-tree-node-small-spinner": size === "small" }) }), onExpanded: /* c8 ignore next */ () => { } }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";;;;;;;AAAA;;;gGAGgG;AAEhG,kCAAgC;AAChC,4DAA4B;AAC5B,iCAAiJ;AACjJ,oEAAmF;AACnF,wDAA6G;AAC7G,8EAAgE;AAChE,mDAA0D;AAC1D,gDAAwF;AAExF,qEAAkE;AA8ClE;;;;;;GAMG;AACU,QAAA,gBAAgB,GAA2F,IAAA,kBAAU,EAChI,CACE,EACE,IAAI,EACJ,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa,EACb,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,IAAI,EACJ,uBAAuB,EACvB,GAAG,aAAa,EACjB,EACD,YAAY,EACZ,EAAE;IACF,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAA,+CAAsB,GAAE,CAA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CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,uDAAuD;IAC1D,CAAC,GAAG,IAAI,CAAC,CACV,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./TreeNodeRenderer.css\";\nimport cx from \"classnames\";\nimport { ComponentPropsWithoutRef, forwardRef, LegacyRef, MutableRefObject, ReactElement, Ref, RefAttributes, useCallback, useRef } from \"react\";\nimport { SvgFilter, SvgFilterHollow, SvgRemove } from \"@itwin/itwinui-icons-react\";\nimport { Anchor, ButtonGroup, Flex, IconButton, ProgressRadial, Text, TreeNode } from \"@itwin/itwinui-react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, UseTreeResult } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { RenderedTreeNode } from \"./TreeRenderer.js\";\n\n/** @public */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof TreeNode>;\n\n/** @public */\ninterface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: RenderedTreeNode;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /** Returns an icon for a given node. */\n getIcon?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** CSS class name for the action buttons. */\n actionButtonsClassName?: string;\n /** Tree node size. Should match the size passed to `TreeRenderer` component. */\n size?: \"default\" | \"small\";\n /**\n * Configures filter buttons visibility.\n *\n * Options:\n * - `show-on-hover` - show filter buttons when hovering over node, or the node is in focus.\n * - `hide` - hide filter buttons, but will show them if the filter is applied.\n *\n * Default value: `show-on-hover`\n */\n filterButtonsVisibility?: \"show-on-hover\" | \"hide\";\n}\n\n/** @public */\ntype TreeNodeRendererProps = Pick<UseTreeResult, \"expandNode\"> &\n Partial<Pick<UseTreeResult, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"label\" | \"onExpanded\" | \"onSelected\" | \"icon\"> &\n TreeNodeRendererOwnProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: React.ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLDivElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isSelected,\n isDisabled,\n actionButtonsClassName,\n getHierarchyLevelDetails,\n reloadTree,\n size,\n filterButtonsVisibility,\n ...treeNodeProps\n },\n forwardedRef,\n ) => {\n const { localizedStrings } = useLocalizationContext();\n const applyFilterButtonRef = useRef<HTMLButtonElement>(null);\n const nodeRef = useRef<HTMLDivElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n if (\"type\" in node && node.type === \"ChildrenPlaceholder\") {\n return <PlaceholderNode {...treeNodeProps} ref={ref} size={size} />;\n }\n\n if (isPresentationHierarchyNode(node)) {\n return (\n <TreeNode\n {...treeNodeProps}\n ref={ref}\n isSelected={isSelected}\n isDisabled={isDisabled}\n className={cx(treeNodeProps.className, \"stateless-tree-node\", { filtered: node.isFiltered })}\n onClick={(event) => !isDisabled && onNodeClick?.(node, !isSelected, event)}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!isDisabled && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !isSelected, event);\n }\n }}\n onExpanded={(_, isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n icon={getIcon ? getIcon(node) : undefined}\n label={getLabel ? getLabel(node) : node.label}\n sublabel={getSublabel ? getSublabel(node) : undefined}\n >\n <ButtonGroup className={cx(\"action-buttons\", actionButtonsClassName)}>\n {getHierarchyLevelDetails && node.isFiltered ? (\n <IconButton\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n label={localizedStrings.clearHierarchyLevelFilter}\n onClick={(e) => {\n e.stopPropagation();\n getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);\n applyFilterButtonRef.current?.focus();\n }}\n >\n <SvgRemove />\n </IconButton>\n ) : null}\n {onFilterClick && node.isFilterable && (filterButtonsVisibility !== \"hide\" || node.isFiltered) ? (\n <IconButton\n ref={applyFilterButtonRef}\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n label={localizedStrings.filterHierarchyLevel}\n onClick={(e) => {\n e.stopPropagation();\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }}\n >\n {node.isFiltered ? <SvgFilter /> : <SvgFilterHollow />}\n </IconButton>\n ) : null}\n </ButtonGroup>\n </TreeNode>\n );\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n const isFilterable =\n hierarchyLevelDetails?.hierarchyNode &&\n !HierarchyNode.isGroupingNode(hierarchyLevelDetails.hierarchyNode) &&\n hierarchyLevelDetails.hierarchyNode.supportsFiltering;\n return (\n <ResultSetTooLargeNode\n {...treeNodeProps}\n ref={ref}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={hierarchyLevelDetails ? (limit) => hierarchyLevelDetails.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick && hierarchyLevelDetails && isFilterable\n ? () => {\n onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return <TreeNode {...treeNodeProps} ref={ref} label={localizedStrings.noFilteredChildren} isDisabled={true} onExpanded={/* c8 ignore next */ () => {}} />;\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return (\n <TreeNode\n {...treeNodeProps}\n ref={ref}\n label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />}\n isDisabled={true}\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<\n HTMLDivElement,\n Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & {\n size?: \"default\" | \"small\";\n }\n>(({ size, ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return (\n <TreeNode\n {...props}\n ref={forwardedRef}\n label={localizedStrings.loading}\n icon={\n <ProgressRadial\n size=\"x-small\"\n indeterminate\n title={localizedStrings.loading}\n className={cx(props.className, { \"stateless-tree-node-small-spinner\": size === \"small\" })}\n />\n }\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nconst ResultSetTooLargeNode = forwardRef<HTMLDivElement, Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps>(\n ({ onFilterClick, onOverrideLimit, limit, ...props }, forwardedRef) => {\n return (\n <TreeNode\n {...props}\n ref={forwardedRef}\n className=\"stateless-tree-node\"\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n onExpanded={/* c8 ignore next */ () => {}}\n isDisabled={true}\n />\n );\n },\n);\nResultSetTooLargeNode.displayName = \"ResultSetTooLargeNode\";\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Flex flexDirection=\"row\" gap=\"xs\" title={message} alignItems=\"start\">\n <Text>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </Flex>\n );\n}\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <Flex flexDirection=\"column\" gap=\"3xs\" title={title} alignItems=\"start\">\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </Flex>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {messageWithLimit}\n </Text>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <div>\n {textBefore ? (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {textBefore}\n </Text>\n ) : null}\n <Anchor\n style={{ whiteSpace: \"normal\" }}\n underline\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {textAfter}\n </Text>\n ) : null}\n </div>\n ),\n };\n}\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";;;;;;;AAAA;;;gGAGgG;AAEhG,kCAAgC;AAChC,4DAA4B;AAC5B,iCAA4J;AAC5J,oEAAmF;AACnF,wDAA6G;AAC7G,8EAAgE;AAChE,mDAA0D;AAC1D,gDAAwF;AAExF,qEAAkE;AA8ClE;;;;;;GAMG;AACU,QAAA,gBAAgB,GAA2F,IAAA,kBAAU,EAChI,CACE,EACE,IAAI,EACJ,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa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AU,EAAE,CAAC;gBAC9B,GAAG,CAAC,QAAQ,CAAC,CAAC;YAChB,CAAC;iBAAM,IAAI,GAAG,EAAE,CAAC;gBACd,GAAkC,CAAC,OAAO,GAAG,QAAQ,CAAC;YACzD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,uDAAuD;IAC1D,CAAC,GAAG,IAAI,CAAC,CACV,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./TreeNodeRenderer.css\";\nimport cx from \"classnames\";\nimport { ComponentPropsWithoutRef, forwardRef, LegacyRef, MutableRefObject, ReactElement, Ref, RefAttributes, useCallback, useEffect, useRef } from \"react\";\nimport { SvgFilter, SvgFilterHollow, SvgRemove } from \"@itwin/itwinui-icons-react\";\nimport { Anchor, ButtonGroup, Flex, IconButton, ProgressRadial, Text, TreeNode } from \"@itwin/itwinui-react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, UseTreeResult } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { RenderedTreeNode } from \"./TreeRenderer.js\";\n\n/** @public */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof TreeNode>;\n\n/** @public */\ninterface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: RenderedTreeNode;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /** Returns an icon for a given node. */\n getIcon?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** CSS class name for the action buttons. */\n actionButtonsClassName?: string;\n /** Tree node size. Should match the size passed to `TreeRenderer` component. */\n size?: \"default\" | \"small\";\n /**\n * Configures filter buttons visibility.\n *\n * Options:\n * - `show-on-hover` - show filter buttons when hovering over node, or the node is in focus.\n * - `hide` - hide filter buttons, but will show them if the filter is applied.\n *\n * Default value: `show-on-hover`\n */\n filterButtonsVisibility?: \"show-on-hover\" | \"hide\";\n}\n\n/** @public */\ntype TreeNodeRendererProps = Pick<UseTreeResult, \"expandNode\"> &\n Partial<Pick<UseTreeResult, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"label\" | \"onExpanded\" | \"onSelected\" | \"icon\"> &\n TreeNodeRendererOwnProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: React.ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLDivElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isSelected,\n isDisabled,\n actionButtonsClassName,\n getHierarchyLevelDetails,\n reloadTree,\n size,\n filterButtonsVisibility,\n ...treeNodeProps\n },\n forwardedRef,\n ) => {\n const { localizedStrings } = useLocalizationContext();\n if (\"type\" in node && node.type === \"ChildrenPlaceholder\") {\n return <PlaceholderNode {...treeNodeProps} ref={forwardedRef} size={size} />;\n }\n\n if (isPresentationHierarchyNode(node)) {\n return (\n <HierarchyNodeRenderer\n {...treeNodeProps}\n ref={forwardedRef}\n node={node}\n expandNode={expandNode}\n getIcon={getIcon}\n getLabel={getLabel}\n getSublabel={getSublabel}\n onFilterClick={onFilterClick}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n isSelected={isSelected}\n isDisabled={isDisabled}\n actionButtonsClassName={actionButtonsClassName}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n filterButtonsVisibility={filterButtonsVisibility}\n />\n );\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n const isFilterable =\n hierarchyLevelDetails?.hierarchyNode &&\n !HierarchyNode.isGroupingNode(hierarchyLevelDetails.hierarchyNode) &&\n hierarchyLevelDetails.hierarchyNode.supportsFiltering;\n return (\n <ResultSetTooLargeNode\n {...treeNodeProps}\n ref={forwardedRef}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={hierarchyLevelDetails ? (limit) => hierarchyLevelDetails.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick && hierarchyLevelDetails && isFilterable\n ? () => {\n onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return (\n <TreeNode\n {...treeNodeProps}\n ref={forwardedRef}\n label={localizedStrings.noFilteredChildren}\n isDisabled={true}\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return (\n <TreeNode\n {...treeNodeProps}\n ref={forwardedRef}\n label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />}\n isDisabled={true}\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst HierarchyNodeRenderer = forwardRef<HTMLDivElement, Omit<TreeNodeRendererProps, \"node\" | \"reloadTree\" | \"size\"> & { node: PresentationHierarchyNode }>(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isSelected,\n isDisabled,\n actionButtonsClassName,\n getHierarchyLevelDetails,\n filterButtonsVisibility,\n ...treeNodeProps\n },\n forwardedRef,\n ) => {\n const { localizedStrings } = useLocalizationContext();\n const applyFilterButtonRef = useRef<HTMLButtonElement>(null);\n const nodeRef = useRef<HTMLDivElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n\n const prevIsFiltered = useRef(node.isFiltered);\n useEffect(() => {\n // If the node is filtered, focus the apply filter button\n if (node.isFiltered && !prevIsFiltered.current) {\n applyFilterButtonRef.current?.focus();\n }\n prevIsFiltered.current = node.isFiltered;\n }, [node.isFiltered]);\n\n return (\n <TreeNode\n {...treeNodeProps}\n ref={ref}\n isSelected={isSelected}\n isDisabled={isDisabled}\n className={cx(treeNodeProps.className, \"stateless-tree-node\", { filtered: node.isFiltered })}\n onClick={(event) => !isDisabled && onNodeClick?.(node, !isSelected, event)}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!isDisabled && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !isSelected, event);\n }\n }}\n onExpanded={(_, isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n icon={getIcon ? getIcon(node) : undefined}\n label={getLabel ? getLabel(node) : node.label}\n sublabel={getSublabel ? getSublabel(node) : undefined}\n >\n <ButtonGroup className={cx(\"action-buttons\", actionButtonsClassName)}>\n {getHierarchyLevelDetails && node.isFiltered ? (\n <IconButton\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n label={localizedStrings.clearHierarchyLevelFilter}\n onClick={(e) => {\n e.stopPropagation();\n getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);\n applyFilterButtonRef.current?.focus();\n }}\n >\n <SvgRemove />\n </IconButton>\n ) : null}\n {onFilterClick && node.isFilterable && (filterButtonsVisibility !== \"hide\" || node.isFiltered) ? (\n <IconButton\n ref={applyFilterButtonRef}\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n label={localizedStrings.filterHierarchyLevel}\n onClick={(e) => {\n e.stopPropagation();\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }}\n >\n {node.isFiltered ? <SvgFilter /> : <SvgFilterHollow />}\n </IconButton>\n ) : null}\n </ButtonGroup>\n </TreeNode>\n );\n },\n);\nHierarchyNodeRenderer.displayName = \"HierarchyNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<\n HTMLDivElement,\n Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & {\n size?: \"default\" | \"small\";\n }\n>(({ size, ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return (\n <TreeNode\n {...props}\n ref={forwardedRef}\n label={localizedStrings.loading}\n icon={\n <ProgressRadial\n size=\"x-small\"\n indeterminate\n title={localizedStrings.loading}\n className={cx(props.className, { \"stateless-tree-node-small-spinner\": size === \"small\" })}\n />\n }\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nconst ResultSetTooLargeNode = forwardRef<HTMLDivElement, Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps>(\n ({ onFilterClick, onOverrideLimit, limit, ...props }, forwardedRef) => {\n return (\n <TreeNode\n {...props}\n ref={forwardedRef}\n className=\"stateless-tree-node\"\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n onExpanded={/* c8 ignore next */ () => {}}\n isDisabled={true}\n />\n );\n },\n);\nResultSetTooLargeNode.displayName = \"ResultSetTooLargeNode\";\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Flex flexDirection=\"row\" gap=\"xs\" title={message} alignItems=\"start\">\n <Text>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </Flex>\n );\n}\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <Flex flexDirection=\"column\" gap=\"3xs\" title={title} alignItems=\"start\">\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </Flex>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {messageWithLimit}\n </Text>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <div>\n {textBefore ? (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {textBefore}\n </Text>\n ) : null}\n <Anchor\n style={{ whiteSpace: \"normal\" }}\n underline\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {textAfter}\n </Text>\n ) : null}\n </div>\n ),\n };\n}\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
|
|
@@ -19,6 +19,8 @@ type UseIModelTreeProps = Omit<UseTreeProps, "getHierarchyProvider" | "getFilter
|
|
|
19
19
|
getFilteredPaths?: (props: {
|
|
20
20
|
/** Object that provides access to the iModel schema and can run queries against the iModel. */
|
|
21
21
|
imodelAccess: IModelAccess;
|
|
22
|
+
/** Signal indicating that that the request was canceled */
|
|
23
|
+
abortSignal: AbortSignal;
|
|
22
24
|
}) => Promise<HierarchyFilteringPath[] | undefined>;
|
|
23
25
|
};
|
|
24
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC7H,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,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,GAAG,cAAc,GAAG,eAAe,CAAC,GAAG;IAC1F,sDAAsD;IACtD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,YAAY,EAAE,YAAY,CAAA;KAAE,KAAK,mBAAmB,CAAC;IAEvF,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE;QACzB,+FAA+F;QAC/F,YAAY,EAAE,YAAY,CAAC;QAC3B,2DAA2D;QAC3D,WAAW,EAAE,WAAW,CAAC;KAC1B,KAAK,OAAO,CAAC,sBAAsB,EAAE,GAAG,SAAS,CAAC,CAAC;CACrD,CAAC;AAEJ;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAMtE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,kBAAkB,GAAG,4BAA4B,GAAG,aAAa,CAMrH"}
|
|
@@ -56,7 +56,7 @@ function useIModelTreeProps(props) {
|
|
|
56
56
|
hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),
|
|
57
57
|
localizedStrings,
|
|
58
58
|
}), [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings]),
|
|
59
|
-
getFilteredPaths: useCallback(async () => getFilteredPaths?.({ imodelAccess }), [imodelAccess, getFilteredPaths]),
|
|
59
|
+
getFilteredPaths: useCallback(async ({ abortSignal }) => getFilteredPaths?.({ imodelAccess, abortSignal }), [imodelAccess, getFilteredPaths]),
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
//# sourceMappingURL=UseIModelTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAA+C,MAAM,iCAAiC,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;QACL,oBAAoB,EAAE,WAAW,CAC/B,GAAG,EAAE,CACH,6BAA6B,CAAC;YAC5B,YAAY;YACZ,aAAa;YACb,mBAAmB,EAAE,sBAAsB,CAAC,EAAE,YAAY,EAAE,CAAC;YAC7D,gBAAgB;SACjB,CAAC,EACJ,CAAC,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,CAAC,CACxE;QACD,gBAAgB,EAAE,WAAW,CAC3B,KAAK,EAAE,EAAE,WAAW,EAAgC,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,EAC1G,CAAC,YAAY,EAAE,gBAAgB,CAAC,CACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { createIModelHierarchyProvider, HierarchyDefinition, HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\nimport { Props } from \"@itwin/presentation-shared\";\nimport { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { useTree, UseTreeProps, UseTreeResult, useUnifiedSelectionTree } from \"./UseTree.js\";\n\n/** @public */\ntype IModelHierarchyProviderProps = Props<typeof createIModelHierarchyProvider>;\n\n/** @public */\ntype IModelAccess = IModelHierarchyProviderProps[\"imodelAccess\"];\n\n/**\n * Props for `useIModelTree` and `useIModelUnifiedSelectionTree` hooks.\n * @public\n */\ntype UseIModelTreeProps = Omit<UseTreeProps, \"getHierarchyProvider\" | \"getFilteredPaths\"> &\n Pick<IModelHierarchyProviderProps, \"localizedStrings\" | \"imodelAccess\" | \"imodelChanged\"> & {\n /** Provides the hierarchy definition for the tree. */\n getHierarchyDefinition: (props: { imodelAccess: IModelAccess }) => HierarchyDefinition;\n\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: (props: {\n /** Object that provides access to the iModel schema and can run queries against the iModel. */\n imodelAccess: IModelAccess;\n /** Signal indicating that that the request was canceled */\n abortSignal: AbortSignal;\n }) => Promise<HierarchyFilteringPath[] | undefined>;\n };\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @public\n */\nexport function useIModelTree(props: UseIModelTreeProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),\n });\n}\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data and that is integrated with unified selection through the given selection\n * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useIModelTree`\n * @see `useUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useIModelUnifiedSelectionTree(props: UseIModelTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"localizedStrings\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getFilteredPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings } = props;\n return {\n getHierarchyProvider: useCallback(\n () =>\n createIModelHierarchyProvider({\n imodelAccess,\n imodelChanged,\n hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),\n localizedStrings,\n }),\n [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings],\n ),\n getFilteredPaths: useCallback(\n async ({ abortSignal }: { abortSignal: AbortSignal }) => getFilteredPaths?.({ imodelAccess, abortSignal }),\n [imodelAccess, getFilteredPaths],\n ),\n };\n}\n"]}
|
|
@@ -58,7 +58,9 @@ export interface UseTreeProps {
|
|
|
58
58
|
/** Provides the hierarchy provider for the tree. */
|
|
59
59
|
getHierarchyProvider: () => HierarchyProvider;
|
|
60
60
|
/** Provides paths to filtered nodes. */
|
|
61
|
-
getFilteredPaths?: (
|
|
61
|
+
getFilteredPaths?: ({ abortSignal }: {
|
|
62
|
+
abortSignal: AbortSignal;
|
|
63
|
+
}) => Promise<HierarchyFilteringPath[] | undefined>;
|
|
62
64
|
/**
|
|
63
65
|
* Callback that is called just after a certain action is finished.
|
|
64
66
|
* Can be used for performance tracking.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAClI,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAGnF,OAAO,EAA2B,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAE1G,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,8FAA8F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C,4BAA4B;IAC5B,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,yBAAyB,GAAG,SAAS,CAAC;IACnE,2DAA2D;IAC3D,wBAAwB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,qBAAqB,GAAG,SAAS,CAAC;IAC5F,qFAAqF;IACrF,YAAY,EAAE,CAAC,SAAS,EAAE,wBAAwB,GAAG,SAAS,KAAK,IAAI,CAAC;CACzE"}
|
|
@@ -81,6 +81,7 @@ function useTreeInternal({ getHierarchyProvider, getFilteredPaths, onPerformance
|
|
|
81
81
|
const [isFiltering, setIsFiltering] = useState(false);
|
|
82
82
|
useEffect(() => {
|
|
83
83
|
let disposed = false;
|
|
84
|
+
const controller = new AbortController();
|
|
84
85
|
void (async () => {
|
|
85
86
|
if (!hierarchyProvider) {
|
|
86
87
|
return;
|
|
@@ -95,7 +96,7 @@ function useTreeInternal({ getHierarchyProvider, getFilteredPaths, onPerformance
|
|
|
95
96
|
setIsFiltering(true);
|
|
96
97
|
let paths;
|
|
97
98
|
try {
|
|
98
|
-
paths = await getFilteredPaths();
|
|
99
|
+
paths = await getFilteredPaths({ abortSignal: controller.signal });
|
|
99
100
|
}
|
|
100
101
|
catch {
|
|
101
102
|
}
|
|
@@ -107,6 +108,7 @@ function useTreeInternal({ getHierarchyProvider, getFilteredPaths, onPerformance
|
|
|
107
108
|
}
|
|
108
109
|
})();
|
|
109
110
|
return () => {
|
|
111
|
+
controller.abort();
|
|
110
112
|
disposed = true;
|
|
111
113
|
};
|
|
112
114
|
}, [hierarchyProvider, getFilteredPaths, actions]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAiD,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Q;QAChH,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc;QACjC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY;KACzC,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAI,KAAQ;IAC5B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { GenericInstanceFilter, HierarchyFilteringPath, HierarchyNode, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey, IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { isTreeModelHierarchyNode, isTreeModelInfoNode, TreeModel, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection, UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { PresentationHierarchyNode, PresentationTreeNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\n\n/**\n * A data structure that contains information about a single hierarchy level.\n * @public\n */\nexport interface HierarchyLevelDetails {\n /** The parent node whose hierarchy level's information is contained in this data structure */\n hierarchyNode: HierarchyNode | undefined;\n\n /** A function to get instance keys of the hierarchy level. */\n getInstanceKeysIterator: (props?: {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n }) => AsyncIterableIterator<InstanceKey>;\n\n /** Get the limit of how many nodes can be loaded in this hierarchy level. */\n sizeLimit?: number | \"unbounded\";\n /** Set the limit of how many nodes can be loaded in this hierarchy level. */\n setSizeLimit: (value: undefined | number | \"unbounded\") => void;\n\n /** Get the active instance filter applied to this hierarchy level. */\n instanceFilter?: GenericInstanceFilter;\n /** Set the instance filter to apply to this hierarchy level */\n setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;\n}\n\n/**\n * A React hook that creates state for a tree component.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({ sourceName, selectionStorage, ...props }: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n return {\n ...rest,\n ...useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode }),\n };\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: () => Promise<HierarchyFilteringPath[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n}\n\n/**\n * Options for doing either full or a sub tree reload.\n * @public\n */\ninterface ReloadTreeOptions {\n /** Specifies parent node under which sub tree should be reloaded. */\n parentNodeId: string | undefined;\n\n /**\n * Specifies how current tree state should be handled:\n * - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).\n * - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.\n * - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.\n *\n * Defaults to `\"keep\"`.\n */\n state?: \"keep\" | \"discard\" | \"reset\";\n}\n\n/** @public */\nexport interface UseTreeResult {\n /**\n * Array containing root tree nodes. It is `undefined` on initial render until any nodes are loaded.\n */\n rootNodes: PresentationTreeNode[] | undefined;\n /**\n * Specifies whether tree is loading or not. It is set to `true` when initial tree load is in progress\n * or tree is reloading.\n */\n isLoading: boolean;\n /**\n * A function that should be called to reload the tree.\n */\n reloadTree: (options?: ReloadTreeOptions) => void;\n /**\n * A function that should be called to either expand or collapse the given node.\n */\n expandNode: (nodeId: string, isExpanded: boolean) => void;\n /**\n * A function that should be called to select nodes in the tree.\n * @param nodeIds Ids of the nodes that are selected.\n * @param changeType Type of change that occurred for the selection.\n */\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n /** Determines whether a given node is selected. */\n isNodeSelected: (nodeId: string) => boolean;\n /** Get a tree node by id */\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n /** Returns hierarchy level details for a given node ID. */\n getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;\n /** Sets a formatter for the primitive values that are displayed in the hierarchy. */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n}\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<PresentationTreeNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getFilteredPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes = model.parentChildMap.get(undefined) !== undefined ? generateTreeStructure(undefined, model) : undefined;\n setState({\n model,\n rootNodes,\n });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs?.filterChange?.newFilter !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isFiltering, setIsFiltering] = useState(false);\n useEffect(() => {\n let disposed = false;\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getFilteredPaths) {\n hierarchyProvider.setHierarchyFilter(undefined);\n // reload tree in case hierarchy provider does not use hierarchy filter to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsFiltering(false);\n return;\n }\n\n setIsFiltering(true);\n let paths: HierarchyFilteringPath[] | undefined;\n try {\n paths = await getFilteredPaths();\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchyFilter(paths ? { paths } : undefined);\n setIsFiltering(false);\n }\n }\n })();\n return () => {\n disposed = true;\n };\n }, [hierarchyProvider, getFilteredPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): PresentationHierarchyNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return undefined;\n }\n return createPresentationHierarchyNode(node, state.model);\n },\n [actions, state.model],\n );\n\n const expandNode = useCallback<UseTreeResult[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<UseTreeResult[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<UseTreeResult[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<UseTreeResult[\"isNodeSelected\"]>((nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId), [state]);\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n /* c8 ignore next 3 */\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<UseTreeResult[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node || isTreeModelInfoNode(node)) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n return {\n rootNodes: state.rootNodes,\n isLoading: !!state.model.rootNode.isLoading || isFiltering,\n expandNode,\n reloadTree,\n selectNodes,\n isNodeSelected,\n getTreeModelNode,\n getNode,\n getHierarchyLevelDetails,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(parentNodeId: string | undefined, model: TreeModel): Array<PresentationTreeNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelNode => !!node)\n .map<PresentationTreeNode>((node) => {\n if (isTreeModelHierarchyNode(node)) {\n return createPresentationHierarchyNode(node, model);\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n resultSetSizeLimit: node.resultSetSizeLimit,\n };\n }\n\n if (node.type === \"NoFilterMatches\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n };\n }\n\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n message: node.message,\n };\n });\n}\n\nfunction createPresentationHierarchyNode(modelNode: TreeModelHierarchyNode, model: TreeModel): PresentationHierarchyNode {\n let children: Array<PresentationTreeNode> | undefined;\n return {\n ...toPresentationHierarchyNodeBase(modelNode),\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n\nfunction toPresentationHierarchyNodeBase(node: TreeModelHierarchyNode): Omit<PresentationHierarchyNode, \"children\"> {\n return {\n id: node.id,\n label: node.label,\n nodeData: node.nodeData,\n isLoading: !!node.isLoading,\n isExpanded: !!node.isExpanded,\n isFilterable: !HierarchyNode.isGroupingNode(node.nodeData) && !!node.nodeData.supportsFiltering && node.children,\n isFiltered: !!node.instanceFilter,\n extendedData: node.nodeData.extendedData,\n };\n}\n\nfunction useLatest<T>(value: T) {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAiD,aAAa,EAAqB,MAAM,iCAAiC,CAAC;AAElI,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,SAAS,EAA4D,MAAM,yBAAyB,CAAC;AAC7J,OAAO,EAAE,uBAAuB,EAAgC,MAAM,mCAAmC,CAAC;AAC1G,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AA6BlD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CAAC,KAAmB;IACzC,MAAM,EAAE,gBAAgB,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAChE,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;GAcG;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AAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { GenericInstanceFilter, HierarchyFilteringPath, HierarchyNode, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey, IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { isTreeModelHierarchyNode, isTreeModelInfoNode, TreeModel, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection, UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { PresentationHierarchyNode, PresentationTreeNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\n\n/**\n * A data structure that contains information about a single hierarchy level.\n * @public\n */\nexport interface HierarchyLevelDetails {\n /** The parent node whose hierarchy level's information is contained in this data structure */\n hierarchyNode: HierarchyNode | undefined;\n\n /** A function to get instance keys of the hierarchy level. */\n getInstanceKeysIterator: (props?: {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n }) => AsyncIterableIterator<InstanceKey>;\n\n /** Get the limit of how many nodes can be loaded in this hierarchy level. */\n sizeLimit?: number | \"unbounded\";\n /** Set the limit of how many nodes can be loaded in this hierarchy level. */\n setSizeLimit: (value: undefined | number | \"unbounded\") => void;\n\n /** Get the active instance filter applied to this hierarchy level. */\n instanceFilter?: GenericInstanceFilter;\n /** Set the instance filter to apply to this hierarchy level */\n setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;\n}\n\n/**\n * A React hook that creates state for a tree component.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({ sourceName, selectionStorage, ...props }: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n return {\n ...rest,\n ...useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode }),\n };\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: ({ abortSignal }: { abortSignal: AbortSignal }) => Promise<HierarchyFilteringPath[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n}\n\n/**\n * Options for doing either full or a sub tree reload.\n * @public\n */\ninterface ReloadTreeOptions {\n /** Specifies parent node under which sub tree should be reloaded. */\n parentNodeId: string | undefined;\n\n /**\n * Specifies how current tree state should be handled:\n * - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).\n * - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.\n * - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.\n *\n * Defaults to `\"keep\"`.\n */\n state?: \"keep\" | \"discard\" | \"reset\";\n}\n\n/** @public */\nexport interface UseTreeResult {\n /**\n * Array containing root tree nodes. It is `undefined` on initial render until any nodes are loaded.\n */\n rootNodes: PresentationTreeNode[] | undefined;\n /**\n * Specifies whether tree is loading or not. It is set to `true` when initial tree load is in progress\n * or tree is reloading.\n */\n isLoading: boolean;\n /**\n * A function that should be called to reload the tree.\n */\n reloadTree: (options?: ReloadTreeOptions) => void;\n /**\n * A function that should be called to either expand or collapse the given node.\n */\n expandNode: (nodeId: string, isExpanded: boolean) => void;\n /**\n * A function that should be called to select nodes in the tree.\n * @param nodeIds Ids of the nodes that are selected.\n * @param changeType Type of change that occurred for the selection.\n */\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n /** Determines whether a given node is selected. */\n isNodeSelected: (nodeId: string) => boolean;\n /** Get a tree node by id */\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n /** Returns hierarchy level details for a given node ID. */\n getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;\n /** Sets a formatter for the primitive values that are displayed in the hierarchy. */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n}\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<PresentationTreeNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getFilteredPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes = model.parentChildMap.get(undefined) !== undefined ? generateTreeStructure(undefined, model) : undefined;\n setState({\n model,\n rootNodes,\n });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs?.filterChange?.newFilter !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isFiltering, setIsFiltering] = useState(false);\n useEffect(() => {\n let disposed = false;\n const controller = new AbortController();\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getFilteredPaths) {\n hierarchyProvider.setHierarchyFilter(undefined);\n // reload tree in case hierarchy provider does not use hierarchy filter to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsFiltering(false);\n return;\n }\n\n setIsFiltering(true);\n let paths: HierarchyFilteringPath[] | undefined;\n try {\n paths = await getFilteredPaths({ abortSignal: controller.signal });\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchyFilter(paths ? { paths } : undefined);\n setIsFiltering(false);\n }\n }\n })();\n return () => {\n controller.abort();\n disposed = true;\n };\n }, [hierarchyProvider, getFilteredPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): PresentationHierarchyNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return undefined;\n }\n return createPresentationHierarchyNode(node, state.model);\n },\n [actions, state.model],\n );\n\n const expandNode = useCallback<UseTreeResult[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<UseTreeResult[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<UseTreeResult[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<UseTreeResult[\"isNodeSelected\"]>((nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId), [state]);\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n /* c8 ignore next 3 */\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<UseTreeResult[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node || isTreeModelInfoNode(node)) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n return {\n rootNodes: state.rootNodes,\n isLoading: !!state.model.rootNode.isLoading || isFiltering,\n expandNode,\n reloadTree,\n selectNodes,\n isNodeSelected,\n getTreeModelNode,\n getNode,\n getHierarchyLevelDetails,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(parentNodeId: string | undefined, model: TreeModel): Array<PresentationTreeNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelNode => !!node)\n .map<PresentationTreeNode>((node) => {\n if (isTreeModelHierarchyNode(node)) {\n return createPresentationHierarchyNode(node, model);\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n resultSetSizeLimit: node.resultSetSizeLimit,\n };\n }\n\n if (node.type === \"NoFilterMatches\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n };\n }\n\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n message: node.message,\n };\n });\n}\n\nfunction createPresentationHierarchyNode(modelNode: TreeModelHierarchyNode, model: TreeModel): PresentationHierarchyNode {\n let children: Array<PresentationTreeNode> | undefined;\n return {\n ...toPresentationHierarchyNodeBase(modelNode),\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n\nfunction toPresentationHierarchyNodeBase(node: TreeModelHierarchyNode): Omit<PresentationHierarchyNode, \"children\"> {\n return {\n id: node.id,\n label: node.label,\n nodeData: node.nodeData,\n isLoading: !!node.isLoading,\n isExpanded: !!node.isExpanded,\n isFilterable: !HierarchyNode.isGroupingNode(node.nodeData) && !!node.nodeData.supportsFiltering && node.children,\n isFiltered: !!node.instanceFilter,\n extendedData: node.nodeData.extendedData,\n };\n}\n\nfunction useLatest<T>(value: T) {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EAAE,wBAAwB,EAA2C,YAAY,EAAO,aAAa,
|
|
1
|
+
{"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EAAE,wBAAwB,EAA2C,YAAY,EAAO,aAAa,EAAkC,MAAM,OAAO,CAAC;AAE5J,OAAO,EAA+D,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAG7G,OAAO,EAA+B,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,cAAc;AACd,KAAK,aAAa,GAAG,wBAAwB,CAAC,OAAO,QAAQ,CAAC,CAAC;AAE/D,cAAc;AACd,UAAU,wBAAwB;IAChC,6BAA6B;IAC7B,IAAI,EAAE,gBAAgB,CAAC;IACvB,yEAAyE;IACzE,aAAa,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACvE,wCAAwC;IACxC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,yBAAyB,KAAK,YAAY,GAAG,SAAS,CAA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FnH,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
import "./TreeNodeRenderer.css";
|
|
7
7
|
import cx from "classnames";
|
|
8
|
-
import { forwardRef, useCallback, useRef } from "react";
|
|
8
|
+
import { forwardRef, useCallback, useEffect, useRef } from "react";
|
|
9
9
|
import { SvgFilter, SvgFilterHollow, SvgRemove } from "@itwin/itwinui-icons-react";
|
|
10
10
|
import { Anchor, ButtonGroup, Flex, IconButton, ProgressRadial, Text, TreeNode } from "@itwin/itwinui-react";
|
|
11
11
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
@@ -21,48 +21,61 @@ import { useLocalizationContext } from "./LocalizationContext.js";
|
|
|
21
21
|
*/
|
|
22
22
|
export const TreeNodeRenderer = forwardRef(({ node, expandNode, getIcon, getLabel, getSublabel, onFilterClick, onNodeClick, onNodeKeyDown, isSelected, isDisabled, actionButtonsClassName, getHierarchyLevelDetails, reloadTree, size, filterButtonsVisibility, ...treeNodeProps }, forwardedRef) => {
|
|
23
23
|
const { localizedStrings } = useLocalizationContext();
|
|
24
|
-
const applyFilterButtonRef = useRef(null);
|
|
25
|
-
const nodeRef = useRef(null);
|
|
26
|
-
const ref = useMergedRefs(forwardedRef, nodeRef);
|
|
27
24
|
if ("type" in node && node.type === "ChildrenPlaceholder") {
|
|
28
|
-
return _jsx(PlaceholderNode, { ...treeNodeProps, ref:
|
|
25
|
+
return _jsx(PlaceholderNode, { ...treeNodeProps, ref: forwardedRef, size: size });
|
|
29
26
|
}
|
|
30
27
|
if (isPresentationHierarchyNode(node)) {
|
|
31
|
-
return (_jsx(
|
|
32
|
-
// Ignore if it is called on the element inside, e.g. checkbox or expander
|
|
33
|
-
if (!isDisabled && event.target === nodeRef.current) {
|
|
34
|
-
onNodeKeyDown?.(node, !isSelected, event);
|
|
35
|
-
}
|
|
36
|
-
}, onExpanded: (_, isExpanded) => {
|
|
37
|
-
expandNode(node.id, isExpanded);
|
|
38
|
-
}, icon: getIcon ? getIcon(node) : undefined, label: getLabel ? getLabel(node) : node.label, sublabel: getSublabel ? getSublabel(node) : undefined, children: _jsxs(ButtonGroup, { className: cx("action-buttons", actionButtonsClassName), children: [getHierarchyLevelDetails && node.isFiltered ? (_jsx(IconButton, { className: "filtering-action-button", styleType: "borderless", size: "small", label: localizedStrings.clearHierarchyLevelFilter, onClick: (e) => {
|
|
39
|
-
e.stopPropagation();
|
|
40
|
-
getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);
|
|
41
|
-
applyFilterButtonRef.current?.focus();
|
|
42
|
-
}, children: _jsx(SvgRemove, {}) })) : null, onFilterClick && node.isFilterable && (filterButtonsVisibility !== "hide" || node.isFiltered) ? (_jsx(IconButton, { ref: applyFilterButtonRef, className: "filtering-action-button", styleType: "borderless", size: "small", label: localizedStrings.filterHierarchyLevel, onClick: (e) => {
|
|
43
|
-
e.stopPropagation();
|
|
44
|
-
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
45
|
-
hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);
|
|
46
|
-
}, children: node.isFiltered ? _jsx(SvgFilter, {}) : _jsx(SvgFilterHollow, {}) })) : null] }) }));
|
|
28
|
+
return (_jsx(HierarchyNodeRenderer, { ...treeNodeProps, ref: forwardedRef, node: node, expandNode: expandNode, getIcon: getIcon, getLabel: getLabel, getSublabel: getSublabel, onFilterClick: onFilterClick, onNodeClick: onNodeClick, onNodeKeyDown: onNodeKeyDown, isSelected: isSelected, isDisabled: isDisabled, actionButtonsClassName: actionButtonsClassName, getHierarchyLevelDetails: getHierarchyLevelDetails, filterButtonsVisibility: filterButtonsVisibility }));
|
|
47
29
|
}
|
|
48
30
|
if (node.type === "ResultSetTooLarge") {
|
|
49
31
|
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);
|
|
50
32
|
const isFilterable = hierarchyLevelDetails?.hierarchyNode &&
|
|
51
33
|
!HierarchyNode.isGroupingNode(hierarchyLevelDetails.hierarchyNode) &&
|
|
52
34
|
hierarchyLevelDetails.hierarchyNode.supportsFiltering;
|
|
53
|
-
return (_jsx(ResultSetTooLargeNode, { ...treeNodeProps, ref:
|
|
35
|
+
return (_jsx(ResultSetTooLargeNode, { ...treeNodeProps, ref: forwardedRef, limit: node.resultSetSizeLimit, onOverrideLimit: hierarchyLevelDetails ? (limit) => hierarchyLevelDetails.setSizeLimit(limit) : undefined, onFilterClick: onFilterClick && hierarchyLevelDetails && isFilterable
|
|
54
36
|
? () => {
|
|
55
37
|
onFilterClick(hierarchyLevelDetails);
|
|
56
38
|
}
|
|
57
39
|
: undefined }));
|
|
58
40
|
}
|
|
59
41
|
if (node.type === "NoFilterMatches") {
|
|
60
|
-
return _jsx(TreeNode, { ...treeNodeProps, ref:
|
|
42
|
+
return (_jsx(TreeNode, { ...treeNodeProps, ref: forwardedRef, label: localizedStrings.noFilteredChildren, isDisabled: true, onExpanded: /* c8 ignore next */ () => { } }));
|
|
61
43
|
}
|
|
62
44
|
const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: "reset" }) : undefined;
|
|
63
|
-
return (_jsx(TreeNode, { ...treeNodeProps, ref:
|
|
45
|
+
return (_jsx(TreeNode, { ...treeNodeProps, ref: forwardedRef, label: _jsx(ErrorNodeLabel, { message: node.message, onRetry: onRetry }), isDisabled: true, onExpanded: /* c8 ignore next */ () => { } }));
|
|
64
46
|
});
|
|
65
47
|
TreeNodeRenderer.displayName = "TreeNodeRenderer";
|
|
48
|
+
const HierarchyNodeRenderer = forwardRef(({ node, expandNode, getIcon, getLabel, getSublabel, onFilterClick, onNodeClick, onNodeKeyDown, isSelected, isDisabled, actionButtonsClassName, getHierarchyLevelDetails, filterButtonsVisibility, ...treeNodeProps }, forwardedRef) => {
|
|
49
|
+
const { localizedStrings } = useLocalizationContext();
|
|
50
|
+
const applyFilterButtonRef = useRef(null);
|
|
51
|
+
const nodeRef = useRef(null);
|
|
52
|
+
const ref = useMergedRefs(forwardedRef, nodeRef);
|
|
53
|
+
const prevIsFiltered = useRef(node.isFiltered);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
// If the node is filtered, focus the apply filter button
|
|
56
|
+
if (node.isFiltered && !prevIsFiltered.current) {
|
|
57
|
+
applyFilterButtonRef.current?.focus();
|
|
58
|
+
}
|
|
59
|
+
prevIsFiltered.current = node.isFiltered;
|
|
60
|
+
}, [node.isFiltered]);
|
|
61
|
+
return (_jsx(TreeNode, { ...treeNodeProps, ref: ref, isSelected: isSelected, isDisabled: isDisabled, className: cx(treeNodeProps.className, "stateless-tree-node", { filtered: node.isFiltered }), onClick: (event) => !isDisabled && onNodeClick?.(node, !isSelected, event), onKeyDown: (event) => {
|
|
62
|
+
// Ignore if it is called on the element inside, e.g. checkbox or expander
|
|
63
|
+
if (!isDisabled && event.target === nodeRef.current) {
|
|
64
|
+
onNodeKeyDown?.(node, !isSelected, event);
|
|
65
|
+
}
|
|
66
|
+
}, onExpanded: (_, isExpanded) => {
|
|
67
|
+
expandNode(node.id, isExpanded);
|
|
68
|
+
}, icon: getIcon ? getIcon(node) : undefined, label: getLabel ? getLabel(node) : node.label, sublabel: getSublabel ? getSublabel(node) : undefined, children: _jsxs(ButtonGroup, { className: cx("action-buttons", actionButtonsClassName), children: [getHierarchyLevelDetails && node.isFiltered ? (_jsx(IconButton, { className: "filtering-action-button", styleType: "borderless", size: "small", label: localizedStrings.clearHierarchyLevelFilter, onClick: (e) => {
|
|
69
|
+
e.stopPropagation();
|
|
70
|
+
getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);
|
|
71
|
+
applyFilterButtonRef.current?.focus();
|
|
72
|
+
}, children: _jsx(SvgRemove, {}) })) : null, onFilterClick && node.isFilterable && (filterButtonsVisibility !== "hide" || node.isFiltered) ? (_jsx(IconButton, { ref: applyFilterButtonRef, className: "filtering-action-button", styleType: "borderless", size: "small", label: localizedStrings.filterHierarchyLevel, onClick: (e) => {
|
|
73
|
+
e.stopPropagation();
|
|
74
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
75
|
+
hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);
|
|
76
|
+
}, children: node.isFiltered ? _jsx(SvgFilter, {}) : _jsx(SvgFilterHollow, {}) })) : null] }) }));
|
|
77
|
+
});
|
|
78
|
+
HierarchyNodeRenderer.displayName = "HierarchyNodeRenderer";
|
|
66
79
|
const PlaceholderNode = forwardRef(({ size, ...props }, forwardedRef) => {
|
|
67
80
|
const { localizedStrings } = useLocalizationContext();
|
|
68
81
|
return (_jsx(TreeNode, { ...props, ref: forwardedRef, label: localizedStrings.loading, icon: _jsx(ProgressRadial, { size: "x-small", indeterminate: true, title: localizedStrings.loading, className: cx(props.className, { "stateless-tree-node-small-spinner": size === "small" }) }), onExpanded: /* c8 ignore next */ () => { } }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAA4B,UAAU,EAAiE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjJ,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAA6B,MAAM,gBAAgB,CAAC;AAExF,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CAChB,CAAC,QAAkB,EAAE,EAAE;QACrB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;gBAC9B,GAAG,CAAC,QAAQ,CAAC,CAAC;YAChB,CAAC;iBAAM,IAAI,GAAG,EAAE,CAAC;gBACd,GAAkC,CAAC,OAAO,GAAG,QAAQ,CAAC;YACzD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,uDAAuD;IAC1D,CAAC,GAAG,IAAI,CAAC,CACV,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./TreeNodeRenderer.css\";\nimport cx from \"classnames\";\nimport { ComponentPropsWithoutRef, forwardRef, LegacyRef, MutableRefObject, ReactElement, Ref, RefAttributes, useCallback, useRef } from \"react\";\nimport { SvgFilter, SvgFilterHollow, SvgRemove } from \"@itwin/itwinui-icons-react\";\nimport { Anchor, ButtonGroup, Flex, IconButton, ProgressRadial, Text, TreeNode } from \"@itwin/itwinui-react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, UseTreeResult } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { RenderedTreeNode } from \"./TreeRenderer.js\";\n\n/** @public */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof TreeNode>;\n\n/** @public */\ninterface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: RenderedTreeNode;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /** Returns an icon for a given node. */\n getIcon?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** CSS class name for the action buttons. */\n actionButtonsClassName?: string;\n /** Tree node size. Should match the size passed to `TreeRenderer` component. */\n size?: \"default\" | \"small\";\n /**\n * Configures filter buttons visibility.\n *\n * Options:\n * - `show-on-hover` - show filter buttons when hovering over node, or the node is in focus.\n * - `hide` - hide filter buttons, but will show them if the filter is applied.\n *\n * Default value: `show-on-hover`\n */\n filterButtonsVisibility?: \"show-on-hover\" | \"hide\";\n}\n\n/** @public */\ntype TreeNodeRendererProps = Pick<UseTreeResult, \"expandNode\"> &\n Partial<Pick<UseTreeResult, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"label\" | \"onExpanded\" | \"onSelected\" | \"icon\"> &\n TreeNodeRendererOwnProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: React.ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLDivElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isSelected,\n isDisabled,\n actionButtonsClassName,\n getHierarchyLevelDetails,\n reloadTree,\n size,\n filterButtonsVisibility,\n ...treeNodeProps\n },\n forwardedRef,\n ) => {\n const { localizedStrings } = useLocalizationContext();\n const applyFilterButtonRef = useRef<HTMLButtonElement>(null);\n const nodeRef = useRef<HTMLDivElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n if (\"type\" in node && node.type === \"ChildrenPlaceholder\") {\n return <PlaceholderNode {...treeNodeProps} ref={ref} size={size} />;\n }\n\n if (isPresentationHierarchyNode(node)) {\n return (\n <TreeNode\n {...treeNodeProps}\n ref={ref}\n isSelected={isSelected}\n isDisabled={isDisabled}\n className={cx(treeNodeProps.className, \"stateless-tree-node\", { filtered: node.isFiltered })}\n onClick={(event) => !isDisabled && onNodeClick?.(node, !isSelected, event)}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!isDisabled && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !isSelected, event);\n }\n }}\n onExpanded={(_, isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n icon={getIcon ? getIcon(node) : undefined}\n label={getLabel ? getLabel(node) : node.label}\n sublabel={getSublabel ? getSublabel(node) : undefined}\n >\n <ButtonGroup className={cx(\"action-buttons\", actionButtonsClassName)}>\n {getHierarchyLevelDetails && node.isFiltered ? (\n <IconButton\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n label={localizedStrings.clearHierarchyLevelFilter}\n onClick={(e) => {\n e.stopPropagation();\n getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);\n applyFilterButtonRef.current?.focus();\n }}\n >\n <SvgRemove />\n </IconButton>\n ) : null}\n {onFilterClick && node.isFilterable && (filterButtonsVisibility !== \"hide\" || node.isFiltered) ? (\n <IconButton\n ref={applyFilterButtonRef}\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n label={localizedStrings.filterHierarchyLevel}\n onClick={(e) => {\n e.stopPropagation();\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }}\n >\n {node.isFiltered ? <SvgFilter /> : <SvgFilterHollow />}\n </IconButton>\n ) : null}\n </ButtonGroup>\n </TreeNode>\n );\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n const isFilterable =\n hierarchyLevelDetails?.hierarchyNode &&\n !HierarchyNode.isGroupingNode(hierarchyLevelDetails.hierarchyNode) &&\n hierarchyLevelDetails.hierarchyNode.supportsFiltering;\n return (\n <ResultSetTooLargeNode\n {...treeNodeProps}\n ref={ref}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={hierarchyLevelDetails ? (limit) => hierarchyLevelDetails.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick && hierarchyLevelDetails && isFilterable\n ? () => {\n onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return <TreeNode {...treeNodeProps} ref={ref} label={localizedStrings.noFilteredChildren} isDisabled={true} onExpanded={/* c8 ignore next */ () => {}} />;\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return (\n <TreeNode\n {...treeNodeProps}\n ref={ref}\n label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />}\n isDisabled={true}\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<\n HTMLDivElement,\n Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & {\n size?: \"default\" | \"small\";\n }\n>(({ size, ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return (\n <TreeNode\n {...props}\n ref={forwardedRef}\n label={localizedStrings.loading}\n icon={\n <ProgressRadial\n size=\"x-small\"\n indeterminate\n title={localizedStrings.loading}\n className={cx(props.className, { \"stateless-tree-node-small-spinner\": size === \"small\" })}\n />\n }\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nconst ResultSetTooLargeNode = forwardRef<HTMLDivElement, Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps>(\n ({ onFilterClick, onOverrideLimit, limit, ...props }, forwardedRef) => {\n return (\n <TreeNode\n {...props}\n ref={forwardedRef}\n className=\"stateless-tree-node\"\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n onExpanded={/* c8 ignore next */ () => {}}\n isDisabled={true}\n />\n );\n },\n);\nResultSetTooLargeNode.displayName = \"ResultSetTooLargeNode\";\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Flex flexDirection=\"row\" gap=\"xs\" title={message} alignItems=\"start\">\n <Text>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </Flex>\n );\n}\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <Flex flexDirection=\"column\" gap=\"3xs\" title={title} alignItems=\"start\">\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </Flex>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {messageWithLimit}\n </Text>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <div>\n {textBefore ? (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {textBefore}\n </Text>\n ) : null}\n <Anchor\n style={{ whiteSpace: \"normal\" }}\n underline\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {textAfter}\n </Text>\n ) : null}\n </div>\n ),\n };\n}\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAChC,O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AE,EAC/B,SAAS,QACT,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;wBACb,CAAC,CAAC,eAAe,EAAE,CAAC;wBACpB,OAAO,EAAE,EAAE,CAAC;oBACd,CAAC,YAEA,SAAS,GACH,EACR,SAAS,CAAC,CAAC,CAAC,CACX,KAAC,IAAI,IAAC,EAAE,EAAC,MAAM,EAAC,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,YAC5C,SAAS,GACL,CACR,CAAC,CAAC,CAAC,IAAI,IACJ,CACP;KACF,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAI,GAAG,IAA6D;IACxF,OAAO,WAAW,CAChB,CAAC,QAAkB,EAAE,EAAE;QACrB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;gBAC9B,GAAG,CAAC,QAAQ,CAAC,CAAC;YAChB,CAAC;iBAAM,IAAI,GAAG,EAAE,CAAC;gBACd,GAAkC,CAAC,OAAO,GAAG,QAAQ,CAAC;YACzD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,uDAAuD;IAC1D,CAAC,GAAG,IAAI,CAAC,CACV,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./TreeNodeRenderer.css\";\nimport cx from \"classnames\";\nimport { ComponentPropsWithoutRef, forwardRef, LegacyRef, MutableRefObject, ReactElement, Ref, RefAttributes, useCallback, useEffect, useRef } from \"react\";\nimport { SvgFilter, SvgFilterHollow, SvgRemove } from \"@itwin/itwinui-icons-react\";\nimport { Anchor, ButtonGroup, Flex, IconButton, ProgressRadial, Text, TreeNode } from \"@itwin/itwinui-react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, UseTreeResult } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { RenderedTreeNode } from \"./TreeRenderer.js\";\n\n/** @public */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof TreeNode>;\n\n/** @public */\ninterface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: RenderedTreeNode;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /** Returns an icon for a given node. */\n getIcon?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** CSS class name for the action buttons. */\n actionButtonsClassName?: string;\n /** Tree node size. Should match the size passed to `TreeRenderer` component. */\n size?: \"default\" | \"small\";\n /**\n * Configures filter buttons visibility.\n *\n * Options:\n * - `show-on-hover` - show filter buttons when hovering over node, or the node is in focus.\n * - `hide` - hide filter buttons, but will show them if the filter is applied.\n *\n * Default value: `show-on-hover`\n */\n filterButtonsVisibility?: \"show-on-hover\" | \"hide\";\n}\n\n/** @public */\ntype TreeNodeRendererProps = Pick<UseTreeResult, \"expandNode\"> &\n Partial<Pick<UseTreeResult, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"label\" | \"onExpanded\" | \"onSelected\" | \"icon\"> &\n TreeNodeRendererOwnProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: React.ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLDivElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isSelected,\n isDisabled,\n actionButtonsClassName,\n getHierarchyLevelDetails,\n reloadTree,\n size,\n filterButtonsVisibility,\n ...treeNodeProps\n },\n forwardedRef,\n ) => {\n const { localizedStrings } = useLocalizationContext();\n if (\"type\" in node && node.type === \"ChildrenPlaceholder\") {\n return <PlaceholderNode {...treeNodeProps} ref={forwardedRef} size={size} />;\n }\n\n if (isPresentationHierarchyNode(node)) {\n return (\n <HierarchyNodeRenderer\n {...treeNodeProps}\n ref={forwardedRef}\n node={node}\n expandNode={expandNode}\n getIcon={getIcon}\n getLabel={getLabel}\n getSublabel={getSublabel}\n onFilterClick={onFilterClick}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n isSelected={isSelected}\n isDisabled={isDisabled}\n actionButtonsClassName={actionButtonsClassName}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n filterButtonsVisibility={filterButtonsVisibility}\n />\n );\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n const isFilterable =\n hierarchyLevelDetails?.hierarchyNode &&\n !HierarchyNode.isGroupingNode(hierarchyLevelDetails.hierarchyNode) &&\n hierarchyLevelDetails.hierarchyNode.supportsFiltering;\n return (\n <ResultSetTooLargeNode\n {...treeNodeProps}\n ref={forwardedRef}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={hierarchyLevelDetails ? (limit) => hierarchyLevelDetails.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick && hierarchyLevelDetails && isFilterable\n ? () => {\n onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return (\n <TreeNode\n {...treeNodeProps}\n ref={forwardedRef}\n label={localizedStrings.noFilteredChildren}\n isDisabled={true}\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return (\n <TreeNode\n {...treeNodeProps}\n ref={forwardedRef}\n label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />}\n isDisabled={true}\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst HierarchyNodeRenderer = forwardRef<HTMLDivElement, Omit<TreeNodeRendererProps, \"node\" | \"reloadTree\" | \"size\"> & { node: PresentationHierarchyNode }>(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isSelected,\n isDisabled,\n actionButtonsClassName,\n getHierarchyLevelDetails,\n filterButtonsVisibility,\n ...treeNodeProps\n },\n forwardedRef,\n ) => {\n const { localizedStrings } = useLocalizationContext();\n const applyFilterButtonRef = useRef<HTMLButtonElement>(null);\n const nodeRef = useRef<HTMLDivElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n\n const prevIsFiltered = useRef(node.isFiltered);\n useEffect(() => {\n // If the node is filtered, focus the apply filter button\n if (node.isFiltered && !prevIsFiltered.current) {\n applyFilterButtonRef.current?.focus();\n }\n prevIsFiltered.current = node.isFiltered;\n }, [node.isFiltered]);\n\n return (\n <TreeNode\n {...treeNodeProps}\n ref={ref}\n isSelected={isSelected}\n isDisabled={isDisabled}\n className={cx(treeNodeProps.className, \"stateless-tree-node\", { filtered: node.isFiltered })}\n onClick={(event) => !isDisabled && onNodeClick?.(node, !isSelected, event)}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!isDisabled && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !isSelected, event);\n }\n }}\n onExpanded={(_, isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n icon={getIcon ? getIcon(node) : undefined}\n label={getLabel ? getLabel(node) : node.label}\n sublabel={getSublabel ? getSublabel(node) : undefined}\n >\n <ButtonGroup className={cx(\"action-buttons\", actionButtonsClassName)}>\n {getHierarchyLevelDetails && node.isFiltered ? (\n <IconButton\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n label={localizedStrings.clearHierarchyLevelFilter}\n onClick={(e) => {\n e.stopPropagation();\n getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);\n applyFilterButtonRef.current?.focus();\n }}\n >\n <SvgRemove />\n </IconButton>\n ) : null}\n {onFilterClick && node.isFilterable && (filterButtonsVisibility !== \"hide\" || node.isFiltered) ? (\n <IconButton\n ref={applyFilterButtonRef}\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n label={localizedStrings.filterHierarchyLevel}\n onClick={(e) => {\n e.stopPropagation();\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }}\n >\n {node.isFiltered ? <SvgFilter /> : <SvgFilterHollow />}\n </IconButton>\n ) : null}\n </ButtonGroup>\n </TreeNode>\n );\n },\n);\nHierarchyNodeRenderer.displayName = \"HierarchyNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<\n HTMLDivElement,\n Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & {\n size?: \"default\" | \"small\";\n }\n>(({ size, ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return (\n <TreeNode\n {...props}\n ref={forwardedRef}\n label={localizedStrings.loading}\n icon={\n <ProgressRadial\n size=\"x-small\"\n indeterminate\n title={localizedStrings.loading}\n className={cx(props.className, { \"stateless-tree-node-small-spinner\": size === \"small\" })}\n />\n }\n onExpanded={/* c8 ignore next */ () => {}}\n />\n );\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nconst ResultSetTooLargeNode = forwardRef<HTMLDivElement, Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps>(\n ({ onFilterClick, onOverrideLimit, limit, ...props }, forwardedRef) => {\n return (\n <TreeNode\n {...props}\n ref={forwardedRef}\n className=\"stateless-tree-node\"\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n onExpanded={/* c8 ignore next */ () => {}}\n isDisabled={true}\n />\n );\n },\n);\nResultSetTooLargeNode.displayName = \"ResultSetTooLargeNode\";\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Flex flexDirection=\"row\" gap=\"xs\" title={message} alignItems=\"start\">\n <Text>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </Flex>\n );\n}\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <Flex flexDirection=\"column\" gap=\"3xs\" title={title} alignItems=\"start\">\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </Flex>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {messageWithLimit}\n </Text>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <div>\n {textBefore ? (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {textBefore}\n </Text>\n ) : null}\n <Anchor\n style={{ whiteSpace: \"normal\" }}\n underline\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? (\n <Text as=\"span\" style={{ whiteSpace: \"normal\" }}>\n {textAfter}\n </Text>\n ) : null}\n </div>\n ),\n };\n}\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/presentation-hierarchies-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "React components based on `@itwin/presentation-hierarchies`",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"immer": "^10.1.1",
|
|
47
47
|
"react-error-boundary": "^4.0.13",
|
|
48
48
|
"rxjs": "^7.8.1",
|
|
49
|
-
"@itwin/presentation-hierarchies": "^1.
|
|
49
|
+
"@itwin/presentation-hierarchies": "^1.6.0",
|
|
50
50
|
"@itwin/presentation-shared": "^1.2.2",
|
|
51
51
|
"@itwin/unified-selection": "^1.4.2"
|
|
52
52
|
},
|