@itwin/tree-widget-react 4.0.0-alpha.7 → 4.0.0-alpha.9
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/lib/esm/tree-widget-react/TreeWidget.d.ts +6 -1
- package/lib/esm/tree-widget-react/TreeWidget.js +19 -2
- package/lib/esm/tree-widget-react/TreeWidget.js.map +1 -1
- package/lib/esm/tree-widget-react/components/TreeWidgetComponentImpl.d.ts +6 -0
- package/lib/esm/tree-widget-react/components/TreeWidgetComponentImpl.js +22 -23
- package/lib/esm/tree-widget-react/components/TreeWidgetComponentImpl.js.map +1 -1
- package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js +1 -1
- package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.d.ts +0 -1
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js +3 -4
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.css +1 -0
- package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.d.ts +12 -4
- package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.js +13 -9
- package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.d.ts +2 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js +2 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +3 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +36 -182
- package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +7 -11
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js +107 -191
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseFilteredPaths.d.ts +25 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseFilteredPaths.js +133 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseFilteredPaths.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.d.ts +8 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.js +48 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.d.ts +0 -2
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js +8 -4
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js +11 -10
- package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/Utils.d.ts +5 -0
- package/lib/esm/tree-widget-react/components/trees/common/Utils.js +5 -0
- package/lib/esm/tree-widget-react/components/trees/common/Utils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js +2 -2
- package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.d.ts +3 -3
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +11 -2
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.d.ts +6 -4
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js +20 -25
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js +10 -4
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js +6 -3
- package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js +12 -11
- package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.d.ts +3 -11
- package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.js +3 -15
- package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.d.ts +4 -23
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js +33 -57
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +2 -2
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +8 -8
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeComponent.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +2 -2
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +11 -11
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.js +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.d.ts +2 -2
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.js +2 -2
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +6 -6
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +36 -220
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +24 -87
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.d.ts +27 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.js +170 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.d.ts +8 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.js +47 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.js.map +1 -0
- package/lib/public/locales/en/TreeWidget.json +4 -95
- package/package.json +6 -6
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.css +0 -8
|
@@ -3,127 +3,40 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
import { useCallback, useEffect, useMemo,
|
|
6
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
7
|
+
import categorySvg from "@itwin/itwinui-icons/bis-category-3d.svg";
|
|
8
|
+
import classSvg from "@itwin/itwinui-icons/bis-class.svg";
|
|
9
|
+
import elementSvg from "@itwin/itwinui-icons/bis-element.svg";
|
|
10
|
+
import subjectSvg from "@itwin/itwinui-icons/bis-subject.svg";
|
|
11
|
+
import modelSvg from "@itwin/itwinui-icons/model-cube.svg";
|
|
7
12
|
import { Icon } from "@itwin/itwinui-react/bricks";
|
|
8
|
-
import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
|
|
9
|
-
import { HierarchyNodeIdentifier, HierarchyNodeKey } from "@itwin/presentation-hierarchies";
|
|
10
13
|
import { EmptyTreeContent, FilterUnknownError, NoFilterMatches, TooManyFilterMatches, TooManyInstancesFocused, UnknownInstanceFocusError, } from "../common/components/EmptyTree.js";
|
|
11
|
-
import { useFocusedInstancesContext } from "../common/FocusedInstancesContext.js";
|
|
12
|
-
import { GEOMETRIC_MODEL_3D_CLASS_NAME, SUBJECT_CLASS_NAME } from "../common/internal/ClassNameDefinitions.js";
|
|
13
|
-
import { useIModelChangeListener } from "../common/internal/UseIModelChangeListener.js";
|
|
14
|
-
import { FilterLimitExceededError } from "../common/TreeErrors.js";
|
|
15
|
-
import { useTelemetryContext } from "../common/UseTelemetryContext.js";
|
|
16
|
-
import { ModelsTreeIdsCache } from "./internal/ModelsTreeIdsCache.js";
|
|
17
14
|
import { ModelsTreeNode } from "./internal/ModelsTreeNode.js";
|
|
18
15
|
import { createModelsTreeVisibilityHandler } from "./internal/ModelsTreeVisibilityHandler.js";
|
|
16
|
+
import { useFilteredPaths } from "./internal/UseFilteredPaths.js";
|
|
17
|
+
import { useIdsCache } from "./internal/UseIdsCache.js";
|
|
19
18
|
import { defaultHierarchyConfiguration, ModelsTreeDefinition } from "./ModelsTreeDefinition.js";
|
|
20
19
|
/**
|
|
21
20
|
* Custom hook to create and manage state for the models tree.
|
|
22
21
|
* @beta
|
|
23
22
|
*/
|
|
24
23
|
export function useModelsTree({ activeView, filter, hierarchyConfig, visibilityHandlerOverrides, getFilteredPaths, onModelsFiltered, selectionPredicate: nodeTypeSelectionPredicate, emptyTreeContent, }) {
|
|
25
|
-
const [filteringError, setFilteringError] = useState(undefined);
|
|
26
24
|
const hierarchyConfiguration = useMemo(() => ({
|
|
27
25
|
...defaultHierarchyConfiguration,
|
|
28
26
|
...hierarchyConfig,
|
|
29
27
|
}),
|
|
30
28
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
29
|
Object.values(hierarchyConfig ?? {}));
|
|
32
|
-
const { onFeatureUsed } = useTelemetryContext();
|
|
33
30
|
const { getModelsTreeIdsCache, visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility(activeView, hierarchyConfiguration, visibilityHandlerOverrides);
|
|
34
|
-
const { loadFocusedItems } = useFocusedInstancesContext();
|
|
35
31
|
const getHierarchyDefinition = useCallback(({ imodelAccess }) => new ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }), [getModelsTreeIdsCache, hierarchyConfiguration]);
|
|
36
|
-
const getPaths =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
onFilteredPathsChanged(filteredPaths);
|
|
45
|
-
if (!onModelsFiltered) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const modelIds = await getModels(filteredPaths, getModelsTreeIdsCache(), classInspector);
|
|
49
|
-
onModelsFiltered(modelIds);
|
|
50
|
-
};
|
|
51
|
-
if (loadFocusedItems) {
|
|
52
|
-
return async ({ imodelAccess }) => {
|
|
53
|
-
try {
|
|
54
|
-
const focusedItems = await collectFocusedItems(loadFocusedItems);
|
|
55
|
-
const paths = await ModelsTreeDefinition.createInstanceKeyPaths({
|
|
56
|
-
imodelAccess,
|
|
57
|
-
idsCache: getModelsTreeIdsCache(),
|
|
58
|
-
targetItems: focusedItems,
|
|
59
|
-
hierarchyConfig: hierarchyConfiguration,
|
|
60
|
-
});
|
|
61
|
-
void handlePaths(paths, imodelAccess);
|
|
62
|
-
return paths.map((path) => ("path" in path ? path : { path, options: { autoExpand: true } }));
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
const newError = e instanceof FilterLimitExceededError ? "tooManyInstancesFocused" : "unknownInstanceFocusError";
|
|
66
|
-
if (newError !== "tooManyInstancesFocused") {
|
|
67
|
-
const feature = e instanceof Error && e.message.includes("query too long to execute or server is too busy") ? "error-timeout" : "error-unknown";
|
|
68
|
-
onFeatureUsed({ featureId: feature, reportInteraction: false });
|
|
69
|
-
}
|
|
70
|
-
setFilteringError(newError);
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
if (getFilteredPaths) {
|
|
76
|
-
return async ({ imodelAccess }) => {
|
|
77
|
-
try {
|
|
78
|
-
const paths = await getFilteredPaths({
|
|
79
|
-
createInstanceKeyPaths: async (props) => ModelsTreeDefinition.createInstanceKeyPaths({
|
|
80
|
-
...props,
|
|
81
|
-
imodelAccess,
|
|
82
|
-
idsCache: getModelsTreeIdsCache(),
|
|
83
|
-
hierarchyConfig: hierarchyConfiguration,
|
|
84
|
-
limit: "unbounded",
|
|
85
|
-
}),
|
|
86
|
-
});
|
|
87
|
-
void handlePaths(paths, imodelAccess);
|
|
88
|
-
return paths;
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
const newError = e instanceof FilterLimitExceededError ? "tooManyFilterMatches" : "unknownFilterError";
|
|
92
|
-
if (newError !== "tooManyFilterMatches") {
|
|
93
|
-
const feature = e instanceof Error && e.message.includes("query too long to execute or server is too busy") ? "error-timeout" : "error-unknown";
|
|
94
|
-
onFeatureUsed({ featureId: feature, reportInteraction: false });
|
|
95
|
-
}
|
|
96
|
-
setFilteringError(newError);
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
if (filter) {
|
|
102
|
-
return async ({ imodelAccess }) => {
|
|
103
|
-
onFeatureUsed({ featureId: "filtering", reportInteraction: true });
|
|
104
|
-
try {
|
|
105
|
-
const paths = await ModelsTreeDefinition.createInstanceKeyPaths({
|
|
106
|
-
imodelAccess,
|
|
107
|
-
label: filter,
|
|
108
|
-
idsCache: getModelsTreeIdsCache(),
|
|
109
|
-
hierarchyConfig: hierarchyConfiguration,
|
|
110
|
-
});
|
|
111
|
-
void handlePaths(paths, imodelAccess);
|
|
112
|
-
return paths.map((path) => ("path" in path ? path : { path, options: { autoExpand: true } }));
|
|
113
|
-
}
|
|
114
|
-
catch (e) {
|
|
115
|
-
const newError = e instanceof FilterLimitExceededError ? "tooManyFilterMatches" : "unknownFilterError";
|
|
116
|
-
if (newError !== "tooManyFilterMatches") {
|
|
117
|
-
const feature = e instanceof Error && e.message.includes("query too long to execute or server is too busy") ? "error-timeout" : "error-unknown";
|
|
118
|
-
onFeatureUsed({ featureId: feature, reportInteraction: false });
|
|
119
|
-
}
|
|
120
|
-
setFilteringError(newError);
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
return undefined;
|
|
126
|
-
}, [filter, loadFocusedItems, getModelsTreeIdsCache, onFeatureUsed, getFilteredPaths, hierarchyConfiguration, onModelsFiltered, onFilteredPathsChanged]);
|
|
32
|
+
const { getPaths, filteringError } = useFilteredPaths({
|
|
33
|
+
hierarchyConfiguration,
|
|
34
|
+
filter,
|
|
35
|
+
getFilteredPaths,
|
|
36
|
+
getModelsTreeIdsCache,
|
|
37
|
+
onFilteredPathsChanged,
|
|
38
|
+
onModelsFiltered,
|
|
39
|
+
});
|
|
127
40
|
const nodeSelectionPredicate = useCallback((node) => {
|
|
128
41
|
if (!nodeTypeSelectionPredicate) {
|
|
129
42
|
return true;
|
|
@@ -137,42 +50,31 @@ export function useModelsTree({ activeView, filter, hierarchyConfig, visibilityH
|
|
|
137
50
|
visibilityHandlerFactory,
|
|
138
51
|
getHierarchyDefinition,
|
|
139
52
|
getFilteredPaths: getPaths,
|
|
140
|
-
emptyTreeContent: getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent),
|
|
141
|
-
highlight: filter ? { text: filter } : undefined,
|
|
53
|
+
emptyTreeContent: useMemo(() => getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent), [filter, filteringError, emptyTreeContent]),
|
|
54
|
+
highlight: useMemo(() => (filter ? { text: filter } : undefined), [filter]),
|
|
142
55
|
selectionPredicate: nodeSelectionPredicate,
|
|
143
56
|
},
|
|
144
57
|
rendererProps: {
|
|
145
58
|
// onDoubleClick,
|
|
146
|
-
getDecorations: (node) => _jsx(ModelsTreeIcon, { node: node }),
|
|
59
|
+
getDecorations: useCallback((node) => _jsx(ModelsTreeIcon, { node: node }), []),
|
|
147
60
|
},
|
|
148
61
|
};
|
|
149
62
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
targetSubjectIds.add(currStep.id);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
// collect all the models from the filtered path
|
|
169
|
-
if (await classInspector.classDerivesFrom(currStep.className, GEOMETRIC_MODEL_3D_CLASS_NAME)) {
|
|
170
|
-
targetModelIds.add(currStep.id);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const matchingModels = await idsCache.getSubjectModelIds([...targetSubjectIds]);
|
|
175
|
-
return [...targetModelIds, ...matchingModels];
|
|
63
|
+
function createVisibilityHandlerFactory(activeView, idsCacheGetter, overrides, filteredPaths) {
|
|
64
|
+
return ({ imodelAccess }) => createModelsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides, filteredPaths });
|
|
65
|
+
}
|
|
66
|
+
function useCachedVisibility(activeView, hierarchyConfig, overrides) {
|
|
67
|
+
const { getCache: getModelsTreeIdsCache } = useIdsCache(activeView.iModel, hierarchyConfig);
|
|
68
|
+
const [filteredPaths, setFilteredPaths] = useState();
|
|
69
|
+
const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));
|
|
72
|
+
}, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]);
|
|
73
|
+
return {
|
|
74
|
+
getModelsTreeIdsCache,
|
|
75
|
+
visibilityHandlerFactory,
|
|
76
|
+
onFilteredPathsChanged: useCallback((paths) => setFilteredPaths(paths), []),
|
|
77
|
+
};
|
|
176
78
|
}
|
|
177
79
|
function getEmptyTreeContentComponent(filter, error, emptyTreeContent) {
|
|
178
80
|
if (isInstanceFocusError(error)) {
|
|
@@ -204,18 +106,13 @@ function InstanceFocusError({ error }) {
|
|
|
204
106
|
}
|
|
205
107
|
return _jsx(UnknownInstanceFocusError, { base: "modelsTree" });
|
|
206
108
|
}
|
|
207
|
-
const subjectSvg = new URL("@itwin/itwinui-icons/bis-subject.svg", import.meta.url).href;
|
|
208
|
-
const classSvg = new URL("@itwin/itwinui-icons/bis-class.svg", import.meta.url).href;
|
|
209
|
-
const modelSvg = new URL("@itwin/itwinui-icons/model-cube.svg", import.meta.url).href;
|
|
210
|
-
const categorySvg = new URL("@itwin/itwinui-icons/bis-category-3d.svg", import.meta.url).href;
|
|
211
|
-
const elementSvg = new URL("@itwin/itwinui-icons/bis-element.svg", import.meta.url).href;
|
|
212
109
|
/** @beta */
|
|
213
110
|
export function ModelsTreeIcon({ node }) {
|
|
214
|
-
if (node.extendedData?.imageId === undefined) {
|
|
111
|
+
if (node.nodeData.extendedData?.imageId === undefined) {
|
|
215
112
|
return undefined;
|
|
216
113
|
}
|
|
217
114
|
const getIcon = () => {
|
|
218
|
-
switch (node.extendedData.imageId) {
|
|
115
|
+
switch (node.nodeData.extendedData.imageId) {
|
|
219
116
|
case "icon-layers":
|
|
220
117
|
return categorySvg;
|
|
221
118
|
case "icon-item":
|
|
@@ -232,85 +129,4 @@ export function ModelsTreeIcon({ node }) {
|
|
|
232
129
|
};
|
|
233
130
|
return _jsx(Icon, { href: getIcon() });
|
|
234
131
|
}
|
|
235
|
-
function createVisibilityHandlerFactory(activeView, idsCacheGetter, overrides, filteredPaths) {
|
|
236
|
-
return ({ imodelAccess }) => createModelsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides, filteredPaths });
|
|
237
|
-
}
|
|
238
|
-
function useIdsCache(imodel, hierarchyConfig) {
|
|
239
|
-
const cacheRef = useRef(undefined);
|
|
240
|
-
const clearCacheRef = useRef(() => {
|
|
241
|
-
cacheRef.current?.[Symbol.dispose]?.();
|
|
242
|
-
cacheRef.current = undefined;
|
|
243
|
-
});
|
|
244
|
-
const createCacheGetterRef = useRef((currImodel, currHierarchyConfig) => {
|
|
245
|
-
return () => {
|
|
246
|
-
if (cacheRef.current === undefined) {
|
|
247
|
-
cacheRef.current = new ModelsTreeIdsCache(createECSqlQueryExecutor(currImodel), currHierarchyConfig);
|
|
248
|
-
}
|
|
249
|
-
return cacheRef.current;
|
|
250
|
-
};
|
|
251
|
-
});
|
|
252
|
-
const [getCache, setCacheGetter] = useState(() => createCacheGetterRef.current(imodel, hierarchyConfig));
|
|
253
|
-
useEffect(() => {
|
|
254
|
-
// clear cache in case it was created before `useEffect` was run first time
|
|
255
|
-
clearCacheRef.current();
|
|
256
|
-
// make sure all cache users rerender
|
|
257
|
-
setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));
|
|
258
|
-
return () => {
|
|
259
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
260
|
-
clearCacheRef.current();
|
|
261
|
-
};
|
|
262
|
-
}, [imodel, hierarchyConfig]);
|
|
263
|
-
useIModelChangeListener({
|
|
264
|
-
imodel,
|
|
265
|
-
action: useCallback(() => {
|
|
266
|
-
clearCacheRef.current();
|
|
267
|
-
// make sure all cache users rerender
|
|
268
|
-
setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));
|
|
269
|
-
}, [imodel, hierarchyConfig]),
|
|
270
|
-
});
|
|
271
|
-
return {
|
|
272
|
-
getCache,
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
function useCachedVisibility(activeView, hierarchyConfig, overrides) {
|
|
276
|
-
const { getCache: getModelsTreeIdsCache } = useIdsCache(activeView.iModel, hierarchyConfig);
|
|
277
|
-
const [filteredPaths, setFilteredPaths] = useState();
|
|
278
|
-
const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));
|
|
279
|
-
useEffect(() => {
|
|
280
|
-
setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));
|
|
281
|
-
}, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]);
|
|
282
|
-
return {
|
|
283
|
-
getModelsTreeIdsCache,
|
|
284
|
-
visibilityHandlerFactory,
|
|
285
|
-
onFilteredPathsChanged: useCallback((paths) => setFilteredPaths(paths), []),
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
async function collectFocusedItems(loadFocusedItems) {
|
|
289
|
-
const focusedItems = [];
|
|
290
|
-
const groupingNodeInfos = [];
|
|
291
|
-
for await (const key of loadFocusedItems()) {
|
|
292
|
-
if ("id" in key) {
|
|
293
|
-
focusedItems.push(key);
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
if (!HierarchyNodeKey.isClassGrouping(key.key)) {
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
const groupingNode = key;
|
|
300
|
-
if (!groupingNode.nonGroupingAncestor || !HierarchyNodeKey.isInstances(groupingNode.nonGroupingAncestor.key)) {
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
const parentKey = groupingNode.nonGroupingAncestor.key;
|
|
304
|
-
const type = groupingNode.nonGroupingAncestor.extendedData?.isCategory ? "category" : "element";
|
|
305
|
-
const modelIds = (groupingNode.nonGroupingAncestor.extendedData?.modelIds ?? []).flatMap((ids) => ids);
|
|
306
|
-
groupingNodeInfos.push({ groupingNode, parentType: type, parentKey, modelIds });
|
|
307
|
-
}
|
|
308
|
-
focusedItems.push(...groupingNodeInfos.map(({ parentKey, parentType, groupingNode, modelIds }) => ({
|
|
309
|
-
parent: parentType === "element"
|
|
310
|
-
? { type: "element", ids: parentKey.instanceKeys.map((key) => key.id) }
|
|
311
|
-
: { type: "category", ids: parentKey.instanceKeys.map((key) => key.id), modelIds },
|
|
312
|
-
groupingNode,
|
|
313
|
-
})));
|
|
314
|
-
return focusedItems;
|
|
315
|
-
}
|
|
316
132
|
//# sourceMappingURL=UseModelsTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseModelsTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/UseModelsTree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAC/G,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AACxF,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iCAAiC,EAAE,MAAM,2CAA2C,CAAC;AAC9F,OAAO,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AA0Ch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E,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;QAChG,MAAM,QAAQ,GAAG,CAAE,YAAY,CAAC,mBAAmB,CAAC,YAAY,EAAE,QAA2B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QAC3H,iBAAiB,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;KACjF;IACD,YAAY,CAAC,IAAI,CACf,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/E,MAAM,EACJ,UAAU,KAAK,SAAS;YACtB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAkB,EAAE,GAAG,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChF,CAAC,CAAC,EAAE,IAAI,EAAE,UAAmB,EAAE,GAAG,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE;QAC/F,YAAY;KACb,CAAC,CAAC,CACJ,CAAC;IACF,OAAO,YAAY,CAAC;AACtB,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, useMemo, useRef, useState } from \"react\";\nimport { Icon } from \"@itwin/itwinui-react/bricks\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { HierarchyNodeIdentifier, HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\nimport {\n EmptyTreeContent,\n FilterUnknownError,\n NoFilterMatches,\n TooManyFilterMatches,\n TooManyInstancesFocused,\n UnknownInstanceFocusError,\n} from \"../common/components/EmptyTree.js\";\nimport { useFocusedInstancesContext } from \"../common/FocusedInstancesContext.js\";\nimport { GEOMETRIC_MODEL_3D_CLASS_NAME, SUBJECT_CLASS_NAME } from \"../common/internal/ClassNameDefinitions.js\";\nimport { useIModelChangeListener } from \"../common/internal/UseIModelChangeListener.js\";\nimport { FilterLimitExceededError } from \"../common/TreeErrors.js\";\nimport { useTelemetryContext } from \"../common/UseTelemetryContext.js\";\nimport { ModelsTreeIdsCache } from \"./internal/ModelsTreeIdsCache.js\";\nimport { ModelsTreeNode } from \"./internal/ModelsTreeNode.js\";\nimport { createModelsTreeVisibilityHandler } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport { defaultHierarchyConfiguration, ModelsTreeDefinition } from \"./ModelsTreeDefinition.js\";\n\nimport type { ReactNode } from \"react\";\nimport type { GroupingHierarchyNode, HierarchyFilteringPath, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { ECClassHierarchyInspector, InstanceKey } from \"@itwin/presentation-shared\";\nimport type { IModelConnection, Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { ClassGroupingHierarchyNode, ElementsGroupInfo, ModelsTreeHierarchyConfiguration } from \"./ModelsTreeDefinition.js\";\nimport type { ModelsTreeVisibilityHandlerOverrides } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\n\ntype ModelsTreeFilteringError = \"tooManyFilterMatches\" | \"tooManyInstancesFocused\" | \"unknownFilterError\" | \"unknownInstanceFocusError\";\n\n/** @beta */\nexport interface UseModelsTreeProps {\n filter?: string;\n activeView: Viewport;\n hierarchyConfig?: Partial<ModelsTreeHierarchyConfiguration>;\n visibilityHandlerOverrides?: ModelsTreeVisibilityHandlerOverrides;\n getFilteredPaths?: (props: {\n createInstanceKeyPaths: (props: { targetItems: Array<InstanceKey | ElementsGroupInfo> } | { label: string }) => Promise<HierarchyFilteringPath[]>;\n }) => Promise<HierarchyFilteringPath[]>;\n onModelsFiltered?: (modelIds: Id64String[] | undefined) => void;\n /**\n * An optional predicate to allow or prohibit selection of a node.\n * When not supplied, all nodes are selectable.\n */\n selectionPredicate?: (props: { node: PresentationHierarchyNode; type: \"subject\" | \"model\" | \"category\" | \"element\" | \"elements-class-group\" }) => boolean;\n emptyTreeContent?: ReactNode;\n}\n\n/** @beta */\ninterface UseModelsTreeResult {\n modelsTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\" | \"selectionPredicate\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getDecorations\">>;\n}\n\n/**\n * Custom hook to create and manage state for the models tree.\n * @beta\n */\nexport function useModelsTree({\n activeView,\n filter,\n hierarchyConfig,\n visibilityHandlerOverrides,\n getFilteredPaths,\n onModelsFiltered,\n selectionPredicate: nodeTypeSelectionPredicate,\n emptyTreeContent,\n}: UseModelsTreeProps): UseModelsTreeResult {\n const [filteringError, setFilteringError] = useState<ModelsTreeFilteringError | undefined>(undefined);\n const hierarchyConfiguration = useMemo<ModelsTreeHierarchyConfiguration>(\n () => ({\n ...defaultHierarchyConfiguration,\n ...hierarchyConfig,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(hierarchyConfig ?? {}),\n );\n const { onFeatureUsed } = useTelemetryContext();\n\n const { getModelsTreeIdsCache, visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility(\n activeView,\n hierarchyConfiguration,\n visibilityHandlerOverrides,\n );\n const { loadFocusedItems } = useFocusedInstancesContext();\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n ({ imodelAccess }) => new ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }),\n [getModelsTreeIdsCache, hierarchyConfiguration],\n );\n\n const getPaths = useMemo<VisibilityTreeProps[\"getFilteredPaths\"] | undefined>(() => {\n setFilteringError(undefined);\n onModelsFiltered?.(undefined);\n\n // reset filtered paths if there is no filters applied. This allows to keep current filtered paths until new paths are loaded.\n if (!loadFocusedItems && !getFilteredPaths && !filter) {\n onFilteredPathsChanged(undefined);\n }\n\n const handlePaths = async (filteredPaths: HierarchyFilteringPath[], classInspector: ECClassHierarchyInspector) => {\n onFilteredPathsChanged(filteredPaths);\n if (!onModelsFiltered) {\n return;\n }\n\n const modelIds = await getModels(filteredPaths, getModelsTreeIdsCache(), classInspector);\n onModelsFiltered(modelIds);\n };\n\n if (loadFocusedItems) {\n return async ({ imodelAccess }) => {\n try {\n const focusedItems = await collectFocusedItems(loadFocusedItems);\n const paths = await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n idsCache: getModelsTreeIdsCache(),\n targetItems: focusedItems,\n hierarchyConfig: hierarchyConfiguration,\n });\n void handlePaths(paths, imodelAccess);\n return paths.map((path) => (\"path\" in path ? path : { path, options: { autoExpand: true } }));\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyInstancesFocused\" : \"unknownInstanceFocusError\";\n if (newError !== \"tooManyInstancesFocused\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }\n\n if (getFilteredPaths) {\n return async ({ imodelAccess }) => {\n try {\n const paths = await getFilteredPaths({\n createInstanceKeyPaths: async (props) =>\n ModelsTreeDefinition.createInstanceKeyPaths({\n ...props,\n imodelAccess,\n idsCache: getModelsTreeIdsCache(),\n hierarchyConfig: hierarchyConfiguration,\n limit: \"unbounded\",\n }),\n });\n void handlePaths(paths, imodelAccess);\n return paths;\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyFilterMatches\" : \"unknownFilterError\";\n if (newError !== \"tooManyFilterMatches\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }\n\n if (filter) {\n return async ({ imodelAccess }) => {\n onFeatureUsed({ featureId: \"filtering\", reportInteraction: true });\n try {\n const paths = await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n label: filter,\n idsCache: getModelsTreeIdsCache(),\n hierarchyConfig: hierarchyConfiguration,\n });\n void handlePaths(paths, imodelAccess);\n return paths.map((path) => (\"path\" in path ? path : { path, options: { autoExpand: true } }));\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyFilterMatches\" : \"unknownFilterError\";\n if (newError !== \"tooManyFilterMatches\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }\n return undefined;\n }, [filter, loadFocusedItems, getModelsTreeIdsCache, onFeatureUsed, getFilteredPaths, hierarchyConfiguration, onModelsFiltered, onFilteredPathsChanged]);\n\n const nodeSelectionPredicate = useCallback<NonNullable<VisibilityTreeProps[\"selectionPredicate\"]>>(\n (node) => {\n if (!nodeTypeSelectionPredicate) {\n return true;\n }\n return nodeTypeSelectionPredicate({ node, type: ModelsTreeNode.getType(node.nodeData) });\n },\n [nodeTypeSelectionPredicate],\n );\n\n // TODO: add double click logic\n return {\n modelsTreeProps: {\n treeName: \"models-tree-v2\",\n visibilityHandlerFactory,\n getHierarchyDefinition,\n getFilteredPaths: getPaths,\n emptyTreeContent: getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent),\n highlight: filter ? { text: filter } : undefined,\n selectionPredicate: nodeSelectionPredicate,\n },\n rendererProps: {\n // onDoubleClick,\n getDecorations: (node) => <ModelsTreeIcon node={node} />,\n },\n };\n}\n\nasync function getModels(paths: HierarchyFilteringPath[], idsCache: ModelsTreeIdsCache, classInspector: ECClassHierarchyInspector) {\n if (!paths) {\n return undefined;\n }\n\n const targetModelIds = new Set<Id64String>();\n const targetSubjectIds = new Set<Id64String>();\n for (const path of paths) {\n const currPath = Array.isArray(path) ? path : path.path;\n for (let i = 0; i < currPath.length; i++) {\n const currStep = currPath[i];\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(currStep)) {\n break;\n }\n\n // if paths end with subject need to get all models under that subject\n if (i === currPath.length - 1 && currStep.className === SUBJECT_CLASS_NAME) {\n targetSubjectIds.add(currStep.id);\n break;\n }\n\n // collect all the models from the filtered path\n if (await classInspector.classDerivesFrom(currStep.className, GEOMETRIC_MODEL_3D_CLASS_NAME)) {\n targetModelIds.add(currStep.id);\n }\n }\n }\n\n const matchingModels = await idsCache.getSubjectModelIds([...targetSubjectIds]);\n return [...targetModelIds, ...matchingModels];\n}\n\nfunction getEmptyTreeContentComponent(filter?: string, error?: ModelsTreeFilteringError, emptyTreeContent?: React.ReactNode) {\n if (isInstanceFocusError(error)) {\n return <InstanceFocusError error={error!} />;\n }\n if (isFilterError(error)) {\n if (error === \"tooManyFilterMatches\") {\n return <TooManyFilterMatches base={\"modelsTree\"} />;\n }\n return <FilterUnknownError base={\"modelsTree\"} />;\n }\n if (filter) {\n return <NoFilterMatches base={\"modelsTree\"} />;\n }\n if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={modelSvg} />;\n}\n\nfunction isFilterError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyFilterMatches\" || error === \"unknownFilterError\";\n}\n\nfunction isInstanceFocusError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyInstancesFocused\" || error === \"unknownInstanceFocusError\";\n}\n\nfunction InstanceFocusError({ error }: { error: ModelsTreeFilteringError }) {\n if (error === \"tooManyInstancesFocused\") {\n return <TooManyInstancesFocused base={\"modelsTree\"} />;\n }\n return <UnknownInstanceFocusError base={\"modelsTree\"} />;\n}\n\nconst subjectSvg = new URL(\"@itwin/itwinui-icons/bis-subject.svg\", import.meta.url).href;\nconst classSvg = new URL(\"@itwin/itwinui-icons/bis-class.svg\", import.meta.url).href;\nconst modelSvg = new URL(\"@itwin/itwinui-icons/model-cube.svg\", import.meta.url).href;\nconst categorySvg = new URL(\"@itwin/itwinui-icons/bis-category-3d.svg\", import.meta.url).href;\nconst elementSvg = new URL(\"@itwin/itwinui-icons/bis-element.svg\", import.meta.url).href;\n\n/** @beta */\nexport function ModelsTreeIcon({ node }: { node: PresentationHierarchyNode }) {\n if (node.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n const getIcon = () => {\n switch (node.extendedData!.imageId) {\n case \"icon-layers\":\n return categorySvg;\n case \"icon-item\":\n return elementSvg;\n case \"icon-ec-class\":\n return classSvg;\n case \"icon-folder\":\n return subjectSvg;\n case \"icon-model\":\n return modelSvg;\n default:\n return undefined;\n }\n };\n\n return <Icon href={getIcon()} />;\n}\n\nfunction createVisibilityHandlerFactory(\n activeView: Viewport,\n idsCacheGetter: () => ModelsTreeIdsCache,\n overrides?: ModelsTreeVisibilityHandlerOverrides,\n filteredPaths?: HierarchyFilteringPath[],\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n return ({ imodelAccess }) => createModelsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides, filteredPaths });\n}\n\nfunction useIdsCache(imodel: IModelConnection, hierarchyConfig: ModelsTreeHierarchyConfiguration) {\n const cacheRef = useRef<ModelsTreeIdsCache | undefined>(undefined);\n const clearCacheRef = useRef(() => {\n cacheRef.current?.[Symbol.dispose]?.();\n cacheRef.current = undefined;\n });\n const createCacheGetterRef = useRef((currImodel: IModelConnection, currHierarchyConfig: ModelsTreeHierarchyConfiguration) => {\n return () => {\n if (cacheRef.current === undefined) {\n cacheRef.current = new ModelsTreeIdsCache(createECSqlQueryExecutor(currImodel), currHierarchyConfig);\n }\n return cacheRef.current;\n };\n });\n const [getCache, setCacheGetter] = useState<() => ModelsTreeIdsCache>(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n\n useEffect(() => {\n // clear cache in case it was created before `useEffect` was run first time\n clearCacheRef.current();\n\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n clearCacheRef.current();\n };\n }, [imodel, hierarchyConfig]);\n\n useIModelChangeListener({\n imodel,\n action: useCallback(() => {\n clearCacheRef.current();\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n }, [imodel, hierarchyConfig]),\n });\n\n return {\n getCache,\n };\n}\n\nfunction useCachedVisibility(activeView: Viewport, hierarchyConfig: ModelsTreeHierarchyConfiguration, overrides?: ModelsTreeVisibilityHandlerOverrides) {\n const { getCache: getModelsTreeIdsCache } = useIdsCache(activeView.iModel, hierarchyConfig);\n const [filteredPaths, setFilteredPaths] = useState<HierarchyFilteringPath[]>();\n const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState<VisibilityTreeProps[\"visibilityHandlerFactory\"]>(() =>\n createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths),\n );\n\n useEffect(() => {\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));\n }, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]);\n\n return {\n getModelsTreeIdsCache,\n visibilityHandlerFactory,\n onFilteredPathsChanged: useCallback((paths: HierarchyFilteringPath[] | undefined) => setFilteredPaths(paths), []),\n };\n}\n\nasync function collectFocusedItems(loadFocusedItems: () => AsyncIterableIterator<InstanceKey | GroupingHierarchyNode>) {\n const focusedItems: Array<InstanceKey | ElementsGroupInfo> = [];\n const groupingNodeInfos: Array<{\n parentKey: InstancesNodeKey;\n parentType: \"element\" | \"category\";\n groupingNode: ClassGroupingHierarchyNode;\n modelIds: Id64Array;\n }> = [];\n for await (const key of loadFocusedItems()) {\n if (\"id\" in key) {\n focusedItems.push(key);\n continue;\n }\n\n if (!HierarchyNodeKey.isClassGrouping(key.key)) {\n continue;\n }\n\n const groupingNode = key as ClassGroupingHierarchyNode;\n if (!groupingNode.nonGroupingAncestor || !HierarchyNodeKey.isInstances(groupingNode.nonGroupingAncestor.key)) {\n continue;\n }\n\n const parentKey = groupingNode.nonGroupingAncestor.key;\n const type = groupingNode.nonGroupingAncestor.extendedData?.isCategory ? \"category\" : \"element\";\n const modelIds = ((groupingNode.nonGroupingAncestor.extendedData?.modelIds as Id64String[][]) ?? []).flatMap((ids) => ids);\n groupingNodeInfos.push({ groupingNode, parentType: type, parentKey, modelIds });\n }\n focusedItems.push(\n ...groupingNodeInfos.map(({ parentKey, parentType, groupingNode, modelIds }) => ({\n parent:\n parentType === \"element\"\n ? { type: \"element\" as const, ids: parentKey.instanceKeys.map((key) => key.id) }\n : { type: \"category\" as const, ids: parentKey.instanceKeys.map((key) => key.id), modelIds },\n groupingNode,\n })),\n );\n return focusedItems;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseModelsTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/UseModelsTree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,WAAW,MAAM,0CAA0C,CAAC;AACnE,OAAO,QAAQ,MAAM,oCAAoC,CAAC;AAC1D,OAAO,UAAU,MAAM,sCAAsC,CAAC;AAC9D,OAAO,UAAU,MAAM,sC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,UAAU,CAAC;YACpB,KAAK,YAAY;gBACf,OAAO,QAAQ,CAAC;YAClB;gBACE,OAAO,SAAS,CAAC;SACpB;IACH,CAAC,CAAC;IAEF,OAAO,KAAC,IAAI,IAAC,IAAI,EAAE,OAAO,EAAE,GAAI,CAAC;AACnC,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, useMemo, useState } from \"react\";\nimport categorySvg from \"@itwin/itwinui-icons/bis-category-3d.svg\";\nimport classSvg from \"@itwin/itwinui-icons/bis-class.svg\";\nimport elementSvg from \"@itwin/itwinui-icons/bis-element.svg\";\nimport subjectSvg from \"@itwin/itwinui-icons/bis-subject.svg\";\nimport modelSvg from \"@itwin/itwinui-icons/model-cube.svg\";\nimport { Icon } from \"@itwin/itwinui-react/bricks\";\nimport {\n EmptyTreeContent,\n FilterUnknownError,\n NoFilterMatches,\n TooManyFilterMatches,\n TooManyInstancesFocused,\n UnknownInstanceFocusError,\n} from \"../common/components/EmptyTree.js\";\nimport { ModelsTreeNode } from \"./internal/ModelsTreeNode.js\";\nimport { createModelsTreeVisibilityHandler } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport { useFilteredPaths } from \"./internal/UseFilteredPaths.js\";\nimport { useIdsCache } from \"./internal/UseIdsCache.js\";\nimport { defaultHierarchyConfiguration, ModelsTreeDefinition } from \"./ModelsTreeDefinition.js\";\n\nimport type { ModelsTreeIdsCache } from \"./internal/ModelsTreeIdsCache.js\";\nimport type { ReactNode } from \"react\";\nimport type { HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { ElementsGroupInfo, ModelsTreeHierarchyConfiguration } from \"./ModelsTreeDefinition.js\";\nimport type { ModelsTreeVisibilityHandlerOverrides } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\nimport type { ModelsTreeFilteringError } from \"./internal/UseFilteredPaths.js\";\n\n/** @beta */\nexport interface UseModelsTreeProps {\n filter?: string;\n activeView: Viewport;\n hierarchyConfig?: Partial<ModelsTreeHierarchyConfiguration>;\n visibilityHandlerOverrides?: ModelsTreeVisibilityHandlerOverrides;\n getFilteredPaths?: (props: {\n createInstanceKeyPaths: (props: { targetItems: Array<InstanceKey | ElementsGroupInfo> } | { label: string }) => Promise<HierarchyFilteringPath[]>;\n }) => Promise<HierarchyFilteringPath[]>;\n onModelsFiltered?: (modelIds: Id64String[] | undefined) => void;\n /**\n * An optional predicate to allow or prohibit selection of a node.\n * When not supplied, all nodes are selectable.\n */\n selectionPredicate?: (props: { node: PresentationHierarchyNode; type: \"subject\" | \"model\" | \"category\" | \"element\" | \"elements-class-group\" }) => boolean;\n emptyTreeContent?: ReactNode;\n}\n\n/** @beta */\ninterface UseModelsTreeResult {\n modelsTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\" | \"selectionPredicate\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getDecorations\">>;\n}\n\n/**\n * Custom hook to create and manage state for the models tree.\n * @beta\n */\nexport function useModelsTree({\n activeView,\n filter,\n hierarchyConfig,\n visibilityHandlerOverrides,\n getFilteredPaths,\n onModelsFiltered,\n selectionPredicate: nodeTypeSelectionPredicate,\n emptyTreeContent,\n}: UseModelsTreeProps): UseModelsTreeResult {\n const hierarchyConfiguration = useMemo<ModelsTreeHierarchyConfiguration>(\n () => ({\n ...defaultHierarchyConfiguration,\n ...hierarchyConfig,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(hierarchyConfig ?? {}),\n );\n\n const { getModelsTreeIdsCache, visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility(\n activeView,\n hierarchyConfiguration,\n visibilityHandlerOverrides,\n );\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n ({ imodelAccess }) => new ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }),\n [getModelsTreeIdsCache, hierarchyConfiguration],\n );\n\n const { getPaths, filteringError } = useFilteredPaths({\n hierarchyConfiguration,\n filter,\n getFilteredPaths,\n getModelsTreeIdsCache,\n onFilteredPathsChanged,\n onModelsFiltered,\n });\n\n const nodeSelectionPredicate = useCallback<NonNullable<VisibilityTreeProps[\"selectionPredicate\"]>>(\n (node) => {\n if (!nodeTypeSelectionPredicate) {\n return true;\n }\n return nodeTypeSelectionPredicate({ node, type: ModelsTreeNode.getType(node.nodeData) });\n },\n [nodeTypeSelectionPredicate],\n );\n\n // TODO: add double click logic\n return {\n modelsTreeProps: {\n treeName: \"models-tree-v2\",\n visibilityHandlerFactory,\n getHierarchyDefinition,\n getFilteredPaths: getPaths,\n emptyTreeContent: useMemo(() => getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent), [filter, filteringError, emptyTreeContent]),\n highlight: useMemo(() => (filter ? { text: filter } : undefined), [filter]),\n selectionPredicate: nodeSelectionPredicate,\n },\n rendererProps: {\n // onDoubleClick,\n getDecorations: useCallback((node) => <ModelsTreeIcon node={node} />, []),\n },\n };\n}\n\nfunction createVisibilityHandlerFactory(\n activeView: Viewport,\n idsCacheGetter: () => ModelsTreeIdsCache,\n overrides?: ModelsTreeVisibilityHandlerOverrides,\n filteredPaths?: HierarchyFilteringPath[],\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n return ({ imodelAccess }) => createModelsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides, filteredPaths });\n}\n\nfunction useCachedVisibility(activeView: Viewport, hierarchyConfig: ModelsTreeHierarchyConfiguration, overrides?: ModelsTreeVisibilityHandlerOverrides) {\n const { getCache: getModelsTreeIdsCache } = useIdsCache(activeView.iModel, hierarchyConfig);\n const [filteredPaths, setFilteredPaths] = useState<HierarchyFilteringPath[]>();\n const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState<VisibilityTreeProps[\"visibilityHandlerFactory\"]>(() =>\n createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths),\n );\n\n useEffect(() => {\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));\n }, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]);\n\n return {\n getModelsTreeIdsCache,\n visibilityHandlerFactory,\n onFilteredPathsChanged: useCallback((paths: HierarchyFilteringPath[] | undefined) => setFilteredPaths(paths), []),\n };\n}\n\nfunction getEmptyTreeContentComponent(filter?: string, error?: ModelsTreeFilteringError, emptyTreeContent?: React.ReactNode) {\n if (isInstanceFocusError(error)) {\n return <InstanceFocusError error={error} />;\n }\n if (isFilterError(error)) {\n if (error === \"tooManyFilterMatches\") {\n return <TooManyFilterMatches base={\"modelsTree\"} />;\n }\n return <FilterUnknownError base={\"modelsTree\"} />;\n }\n if (filter) {\n return <NoFilterMatches base={\"modelsTree\"} />;\n }\n if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={modelSvg} />;\n}\n\nfunction isFilterError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyFilterMatches\" || error === \"unknownFilterError\";\n}\n\nfunction isInstanceFocusError(error: ModelsTreeFilteringError | undefined): error is \"tooManyInstancesFocused\" | \"unknownInstanceFocusError\" {\n return error === \"tooManyInstancesFocused\" || error === \"unknownInstanceFocusError\";\n}\n\nfunction InstanceFocusError({ error }: { error: ModelsTreeFilteringError }) {\n if (error === \"tooManyInstancesFocused\") {\n return <TooManyInstancesFocused base={\"modelsTree\"} />;\n }\n return <UnknownInstanceFocusError base={\"modelsTree\"} />;\n}\n\n/** @beta */\nexport function ModelsTreeIcon({ node }: { node: PresentationHierarchyNode }) {\n if (node.nodeData.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n const getIcon = () => {\n switch (node.nodeData.extendedData!.imageId) {\n case \"icon-layers\":\n return categorySvg;\n case \"icon-item\":\n return elementSvg;\n case \"icon-ec-class\":\n return classSvg;\n case \"icon-folder\":\n return subjectSvg;\n case \"icon-model\":\n return modelSvg;\n default:\n return undefined;\n }\n };\n\n return <Icon href={getIcon()} />;\n}\n"]}
|