@itwin/tree-widget-react 0.6.1 → 0.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/lib/cjs/TreeWidget.js +1 -1
- package/lib/cjs/TreeWidget.js.map +1 -1
- package/lib/cjs/components/IconButton.js +3 -3
- package/lib/cjs/components/IconButton.js.map +1 -1
- package/lib/cjs/components/TreeFilteringState.js +4 -4
- package/lib/cjs/components/TreeFilteringState.js.map +1 -1
- package/lib/cjs/components/TreeWidgetComponent.d.ts +1 -1
- package/lib/cjs/components/TreeWidgetComponent.js +5 -5
- package/lib/cjs/components/TreeWidgetComponent.js.map +1 -1
- package/lib/cjs/components/TreeWidgetComponent.scss +1 -1
- package/lib/cjs/components/TreeWidgetUiItemsProvider.d.ts +4 -5
- package/lib/cjs/components/TreeWidgetUiItemsProvider.js +19 -14
- package/lib/cjs/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/cjs/components/search-bar/SearchBar.d.ts +0 -3
- package/lib/cjs/components/search-bar/SearchBar.js +17 -28
- package/lib/cjs/components/search-bar/SearchBar.js.map +1 -1
- package/lib/cjs/components/search-bar/SearchBar.scss +18 -34
- package/lib/cjs/components/search-bar/SearchBox.js +1 -1
- package/lib/cjs/components/search-bar/SearchBox.js.map +1 -1
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.d.ts +19 -0
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js +118 -0
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js.map +1 -0
- package/lib/cjs/components/trees/IModelContentTree.js +4 -4
- package/lib/cjs/components/trees/IModelContentTree.js.map +1 -1
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.d.ts +4 -5
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.js +17 -9
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.js.map +1 -1
- package/lib/cjs/components/trees/VisibilityTreeRenderer.d.ts +4 -4
- package/lib/cjs/components/trees/VisibilityTreeRenderer.js +2 -2
- package/lib/cjs/components/trees/VisibilityTreeRenderer.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoriesTree.d.ts +9 -15
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js +8 -36
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.d.ts +7 -2
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js +65 -27
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.d.ts +11 -15
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js +15 -92
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/Hierarchy.GroupedByClass.json +1 -2
- package/lib/cjs/components/trees/models-tree/Hierarchy.json +1 -2
- package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +5 -13
- package/lib/cjs/components/trees/models-tree/ModelsTree.js +11 -29
- package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.d.ts +19 -2
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +112 -64
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.d.ts +6 -8
- package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
- package/lib/cjs/components/trees/spatial-tree/SpatialTreeComponent.js +9 -7
- package/lib/cjs/components/trees/spatial-tree/SpatialTreeComponent.js.map +1 -1
- package/lib/cjs/components/utils/AutoSizer.js +4 -4
- package/lib/cjs/components/utils/AutoSizer.js.map +1 -1
- package/lib/cjs/tree-widget-react.d.ts +0 -1
- package/lib/cjs/tree-widget-react.js +0 -1
- package/lib/cjs/tree-widget-react.js.map +1 -1
- package/lib/cjs/types.d.ts +19 -5
- package/lib/cjs/types.js +4 -0
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/components/TreeWidgetComponent.d.ts +1 -1
- package/lib/esm/components/TreeWidgetComponent.js +1 -1
- package/lib/esm/components/TreeWidgetComponent.js.map +1 -1
- package/lib/esm/components/TreeWidgetComponent.scss +1 -1
- package/lib/esm/components/TreeWidgetUiItemsProvider.d.ts +4 -5
- package/lib/esm/components/TreeWidgetUiItemsProvider.js +13 -8
- package/lib/esm/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/esm/components/search-bar/SearchBar.d.ts +0 -3
- package/lib/esm/components/search-bar/SearchBar.js +14 -25
- package/lib/esm/components/search-bar/SearchBar.js.map +1 -1
- package/lib/esm/components/search-bar/SearchBar.scss +18 -34
- package/lib/esm/components/trees/CategoriesVisibilityUtils.d.ts +19 -0
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js +110 -0
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js.map +1 -0
- package/lib/esm/components/trees/VisibilityTreeEventHandler.d.ts +4 -5
- package/lib/esm/components/trees/VisibilityTreeEventHandler.js +13 -5
- package/lib/esm/components/trees/VisibilityTreeEventHandler.js.map +1 -1
- package/lib/esm/components/trees/VisibilityTreeRenderer.d.ts +4 -4
- package/lib/esm/components/trees/VisibilityTreeRenderer.js +1 -1
- package/lib/esm/components/trees/VisibilityTreeRenderer.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoriesTree.d.ts +9 -15
- package/lib/esm/components/trees/category-tree/CategoriesTree.js +2 -28
- package/lib/esm/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.d.ts +7 -2
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js +64 -26
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.d.ts +11 -15
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js +12 -88
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/esm/components/trees/models-tree/Hierarchy.GroupedByClass.json +1 -2
- package/lib/esm/components/trees/models-tree/Hierarchy.json +1 -2
- package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +5 -13
- package/lib/esm/components/trees/models-tree/ModelsTree.js +4 -22
- package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.d.ts +19 -2
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +107 -59
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.d.ts +6 -8
- package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
- package/lib/esm/components/trees/spatial-tree/SpatialTreeComponent.js +4 -2
- package/lib/esm/components/trees/spatial-tree/SpatialTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react.d.ts +0 -1
- package/lib/esm/tree-widget-react.js +0 -1
- package/lib/esm/tree-widget-react.js.map +1 -1
- package/lib/esm/types.d.ts +19 -5
- package/lib/esm/types.js +4 -0
- package/lib/esm/types.js.map +1 -1
- package/package.json +32 -40
- package/lib/cjs/components/header/TreeHeader.d.ts +0 -15
- package/lib/cjs/components/header/TreeHeader.js +0 -43
- package/lib/cjs/components/header/TreeHeader.js.map +0 -1
- package/lib/cjs/components/header/TreeHeader.scss +0 -20
- package/lib/cjs/components/search-bar/Popup.d.ts +0 -50
- package/lib/cjs/components/search-bar/Popup.js +0 -246
- package/lib/cjs/components/search-bar/Popup.js.map +0 -1
- package/lib/cjs/components/search-bar/Popup.scss +0 -316
- package/lib/esm/components/header/TreeHeader.d.ts +0 -15
- package/lib/esm/components/header/TreeHeader.js +0 -20
- package/lib/esm/components/header/TreeHeader.js.map +0 -1
- package/lib/esm/components/header/TreeHeader.scss +0 -20
- package/lib/esm/components/search-bar/Popup.d.ts +0 -50
- package/lib/esm/components/search-bar/Popup.js +0 -220
- package/lib/esm/components/search-bar/Popup.js.map +0 -1
- package/lib/esm/components/search-bar/Popup.scss +0 -316
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.CategoryTree = exports.RULESET_CATEGORIES = void 0;
|
|
27
27
|
require("./CategoriesTree.scss");
|
|
28
28
|
const React = __importStar(require("react"));
|
|
29
29
|
const components_react_1 = require("@itwin/components-react");
|
|
@@ -47,28 +47,27 @@ exports.RULESET_CATEGORIES = require("./Categories.json"); // eslint-disable-lin
|
|
|
47
47
|
*/
|
|
48
48
|
function CategoryTree(props) {
|
|
49
49
|
var _a;
|
|
50
|
-
const { nodeLoader } = presentation_components_1.usePresentationTreeNodeLoader({
|
|
50
|
+
const { nodeLoader } = (0, presentation_components_1.usePresentationTreeNodeLoader)({
|
|
51
51
|
imodel: props.iModel,
|
|
52
52
|
ruleset: exports.RULESET_CATEGORIES,
|
|
53
53
|
pagingSize: PAGING_SIZE,
|
|
54
54
|
});
|
|
55
|
-
const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = VisibilityTreeRenderer_1.useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);
|
|
55
|
+
const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = (0, VisibilityTreeRenderer_1.useVisibilityTreeFiltering)(nodeLoader, props.filterInfo, props.onFilterApplied);
|
|
56
56
|
// istanbul ignore next
|
|
57
57
|
const viewManager = (_a = props.viewManager) !== null && _a !== void 0 ? _a : core_frontend_1.IModelApp.viewManager;
|
|
58
58
|
const { activeView, allViewports, categoryVisibilityHandler } = props;
|
|
59
59
|
const currentActiveView = activeView !== null && activeView !== void 0 ? activeView : viewManager.getFirstOpenView();
|
|
60
|
-
const
|
|
61
|
-
const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, categories, currentActiveView, allViewports, categoryVisibilityHandler);
|
|
60
|
+
const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, currentActiveView, allViewports, categoryVisibilityHandler);
|
|
62
61
|
React.useEffect(() => {
|
|
63
62
|
setViewType(currentActiveView); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
64
63
|
}, [currentActiveView]);
|
|
65
|
-
const eventHandler = core_react_1.useDisposable(React.useCallback(() => new VisibilityTreeEventHandler_1.VisibilityTreeEventHandler({
|
|
64
|
+
const eventHandler = (0, core_react_1.useDisposable)(React.useCallback(() => new VisibilityTreeEventHandler_1.VisibilityTreeEventHandler({
|
|
66
65
|
nodeLoader: filteredNodeLoader,
|
|
67
66
|
visibilityHandler,
|
|
68
67
|
collapsedChildrenDisposalEnabled: true,
|
|
69
68
|
}), [filteredNodeLoader, visibilityHandler]));
|
|
70
|
-
const treeModel = components_react_1.useTreeModel(filteredNodeLoader.modelSource);
|
|
71
|
-
const treeRenderer = VisibilityTreeRenderer_1.useVisibilityTreeRenderer(false, true);
|
|
69
|
+
const treeModel = (0, components_react_1.useTreeModel)(filteredNodeLoader.modelSource);
|
|
70
|
+
const treeRenderer = (0, VisibilityTreeRenderer_1.useVisibilityTreeRenderer)(false, true);
|
|
72
71
|
const overlay = isFiltering ? React.createElement("div", { className: "filteredTreeOverlay" }) : undefined;
|
|
73
72
|
const filterApplied = filteredNodeLoader !== nodeLoader;
|
|
74
73
|
const noFilteredDataRenderer = React.useCallback(() => {
|
|
@@ -80,7 +79,7 @@ function CategoryTree(props) {
|
|
|
80
79
|
}
|
|
81
80
|
exports.CategoryTree = CategoryTree;
|
|
82
81
|
function useCategoryVisibilityHandler(viewManager, imodel, categories, activeView, allViewports, visibilityHandler) {
|
|
83
|
-
return core_react_1.useDisposable(React.useCallback(() =>
|
|
82
|
+
return (0, core_react_1.useDisposable)(React.useCallback(() =>
|
|
84
83
|
// istanbul ignore next
|
|
85
84
|
visibilityHandler !== null && visibilityHandler !== void 0 ? visibilityHandler : new CategoryVisibilityHandler_1.CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }), [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]));
|
|
86
85
|
}
|
|
@@ -91,31 +90,4 @@ async function setViewType(activeView) {
|
|
|
91
90
|
const viewType = view.is3d() ? "3d" : "2d";
|
|
92
91
|
await presentation_frontend_1.Presentation.presentation.vars(exports.RULESET_CATEGORIES.id).setString("ViewType", viewType);
|
|
93
92
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Toggles visibility of categories to show or hide.
|
|
96
|
-
* @alpha
|
|
97
|
-
*/
|
|
98
|
-
async function toggleAllCategories(viewManager, imodel, display, viewport, forAllViewports, filteredProvider) {
|
|
99
|
-
// istanbul ignore next
|
|
100
|
-
const activeView = viewport !== null && viewport !== void 0 ? viewport : viewManager.getFirstOpenView();
|
|
101
|
-
const ids = await getCategories(imodel, activeView, filteredProvider);
|
|
102
|
-
// istanbul ignore else
|
|
103
|
-
if (ids.length > 0) {
|
|
104
|
-
CategoryVisibilityHandler_1.CategoryVisibilityHandler.enableCategory(viewManager, imodel, ids, display, forAllViewports !== null && forAllViewports !== void 0 ? forAllViewports : false);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.toggleAllCategories = toggleAllCategories;
|
|
108
|
-
/**
|
|
109
|
-
* Gets ids of all categories or categories from filtered data provider.
|
|
110
|
-
* @alpha
|
|
111
|
-
*/
|
|
112
|
-
async function getCategories(imodel, viewport, filteredProvider) {
|
|
113
|
-
if (filteredProvider) {
|
|
114
|
-
const nodes = await filteredProvider.getNodes();
|
|
115
|
-
return nodes.map((node) => CategoryVisibilityHandler_1.CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));
|
|
116
|
-
}
|
|
117
|
-
const categories = await CategoryVisibilityHandler_1.loadCategoriesFromViewport(imodel, viewport);
|
|
118
|
-
return categories.map((category) => category.key);
|
|
119
|
-
}
|
|
120
|
-
exports.getCategories = getCategories;
|
|
121
93
|
//# sourceMappingURL=CategoriesTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTree.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,iCAA+B;AAC/B,6CAA+B;AAC/B,8DAAsF;AACtF,wDAAiD;AACjD,kDAAkD;AAClD,4EAA+E;AAC/E,wEAA4D;AAC5D,oDAAiD;AACjD,8EAA2E;AAC3E,sEAAgI;AAChI,2EAAmH;AAOnH,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;GAGG;AACU,QAAA,kBAAkB,GAAY,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,yDAAyD;AAwClI;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAwB;;IACnD,MAAM,EAAE,UAAU,EAAE,GAAG,uDAA6B,CAAC;QACnD,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO,EAAE,0BAAkB;QAC3B,UAAU,EAAE,WAAW;KACxB,CAAC,CAAC;IAEH,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,GAAG,mDAA0B,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IACnJ,uBAAuB;IACvB,MAAM,WAAW,GAAG,MAAA,KAAK,CAAC,WAAW,mCAAI,yBAAS,CAAC,WAAW,CAAC;IAC/D,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,yBAAyB,EAAE,GAAG,KAAK,CAAC;IACtE,MAAM,iBAAiB,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IACvE,MAAM,UAAU,GAAG,yCAAa,CAAC,WAAW,EAAE,KAAK,C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B,EAAE,QAAmB,EAAE,eAAyB,EAAE,gBAAgD;IAC9M,uBAAuB;IACvB,MAAM,UAAU,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC9D,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAEtE,uBAAuB;IACvB,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;QAClB,qDAAyB,CAAC,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,KAAK,CAAC,CAAC;KACvG;AACH,CAAC;AATD,kDASC;AAED;;;GAGG;AACI,KAAK,UAAU,aAAa,CAAC,MAAwB,EAAE,QAAmB,EAAE,gBAAgD;IACjI,IAAI,gBAAgB,EAAE;QACpB,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qDAAyB,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACvH;IAED,MAAM,UAAU,GAAG,MAAM,sDAA0B,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACtE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpD,CAAC;AARD,sCAQC","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 \"./CategoriesTree.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { useDisposable } from \"@itwin/core-react\";\nimport { usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { CategoryVisibilityHandler, loadCategoriesFromViewport, useCategories } from \"./CategoryVisibilityHandler\";\nimport type { IModelConnection, SpatialViewState, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { Ruleset } from \"@itwin/presentation-common\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { VisibilityTreeFilterInfo } from \"../Common\";\nimport type { Category } from \"./CategoryVisibilityHandler\";\n\nconst PAGING_SIZE = 20;\n\n/**\n * Presentation rules used by ControlledCategoriesTree\n * @internal\n */\nexport const RULESET_CATEGORIES: Ruleset = require(\"./Categories.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/**\n * Properties for the [[CategoryTree]] component\n * @public\n */\nexport interface CategoryTreeProps {\n /** Flag for accommodating all viewports */\n allViewports?: boolean;\n /** Active viewport */\n activeView?: Viewport;\n /**\n * An IModel to pull data from\n */\n iModel: IModelConnection;\n /** Width of the component */\n width: number;\n /** Height of the component */\n height: number;\n /**\n * Information for tree filtering.\n * @alpha\n */\n filterInfo?: VisibilityTreeFilterInfo;\n /**\n * Callback invoked when tree is filtered.\n */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n /**\n * Custom category visibility handler to use for testing\n * @internal\n */\n categoryVisibilityHandler?: CategoryVisibilityHandler;\n /**\n * Custom view manager to use for testing\n * @internal\n */\n viewManager?: ViewManager;\n}\n\n/**\n * Tree which displays and manages categories contained in an iModel.\n * @public\n */\nexport function CategoryTree(props: CategoryTreeProps) {\n const { nodeLoader } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: RULESET_CATEGORIES,\n pagingSize: PAGING_SIZE,\n });\n\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n // istanbul ignore next\n const viewManager = props.viewManager ?? IModelApp.viewManager;\n const { activeView, allViewports, categoryVisibilityHandler } = props;\n const currentActiveView = activeView ?? viewManager.getFirstOpenView();\n const categories = useCategories(viewManager, props.iModel, currentActiveView);\n const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, categories, currentActiveView, allViewports, categoryVisibilityHandler);\n\n React.useEffect(() => {\n setViewType(currentActiveView); // eslint-disable-line @typescript-eslint/no-floating-promises\n }, [currentActiveView]);\n\n const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n collapsedChildrenDisposalEnabled: true,\n }), [filteredNodeLoader, visibilityHandler]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = useVisibilityTreeRenderer(false, true);\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const noFilteredDataRenderer = React.useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"categoriesTree.noCategoryFound\")}\n message={TreeWidget.translate(\"categoriesTree.noMatchingCategoryNames\")}\n />;\n }, []);\n\n return (\n <div className=\"tree-widget-categories-tree\">\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n descriptionsEnabled={true}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useCategoryVisibilityHandler(viewManager: ViewManager, imodel: IModelConnection, categories: Category[], activeView?: Viewport, allViewports?: boolean, visibilityHandler?: CategoryVisibilityHandler) {\n return useDisposable(React.useCallback(\n () =>\n // istanbul ignore next\n visibilityHandler ?? new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }),\n [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]),\n );\n}\n\nasync function setViewType(activeView?: Viewport) {\n if (!activeView)\n return;\n\n const view = activeView.view as SpatialViewState;\n const viewType = view.is3d() ? \"3d\" : \"2d\";\n await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString(\"ViewType\", viewType);\n}\n\n/**\n * Toggles visibility of categories to show or hide.\n * @alpha\n */\nexport async function toggleAllCategories(viewManager: ViewManager, imodel: IModelConnection, display: boolean, viewport?: Viewport, forAllViewports?: boolean, filteredProvider?: IPresentationTreeDataProvider) {\n // istanbul ignore next\n const activeView = viewport ?? viewManager.getFirstOpenView();\n const ids = await getCategories(imodel, activeView, filteredProvider);\n\n // istanbul ignore else\n if (ids.length > 0) {\n CategoryVisibilityHandler.enableCategory(viewManager, imodel, ids, display, forAllViewports ?? false);\n }\n}\n\n/**\n * Gets ids of all categories or categories from filtered data provider.\n * @alpha\n */\nexport async function getCategories(imodel: IModelConnection, viewport?: Viewport, filteredProvider?: IPresentationTreeDataProvider) {\n if (filteredProvider) {\n const nodes = await filteredProvider.getNodes();\n return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));\n }\n\n const categories = await loadCategoriesFromViewport(imodel, viewport);\n return categories.map((category) => category.key);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CategoriesTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTree.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,iCAA+B;AAC/B,6CAA+B;AAC/B,8DAAsF;AACtF,wDAA4G;AAC5G,kDAAkD;AAElD,4EAA8G;AAC9G,wEAA4D;AAC5D,oDAA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AsB,EAAE,iBAA6C;IAChN,OAAO,IAAA,0BAAa,EAAC,KAAK,CAAC,WAAW,CACpC,GAAG,EAAE;IACH,uBAAuB;IACvB,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,IAAI,qDAAyB,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,EACnH,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAChF,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,UAAqB;IAC9C,IAAI,CAAC,UAAU;QACb,OAAO;IAET,MAAM,IAAI,GAAG,UAAU,CAAC,IAAwB,CAAC;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3C,MAAM,oCAAY,CAAC,YAAY,CAAC,IAAI,CAAC,0BAAkB,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC9F,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 \"./CategoriesTree.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { IModelApp, IModelConnection, SpatialViewState, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport { useDisposable } from \"@itwin/core-react\";\nimport { Ruleset } from \"@itwin/presentation-common\";\nimport { IPresentationTreeDataProvider, usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { VisibilityTreeFilterInfo } from \"../Common\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { CategoryInfo, CategoryVisibilityHandler } from \"./CategoryVisibilityHandler\";\n\nconst PAGING_SIZE = 20;\n\n/**\n * Presentation rules used by ControlledCategoriesTree\n * @internal\n */\nexport const RULESET_CATEGORIES: Ruleset = require(\"./Categories.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/**\n * Properties for the [[CategoryTree]] component\n * @public\n */\nexport interface CategoryTreeProps {\n /** Flag for accommodating all viewports */\n allViewports?: boolean;\n /** Active viewport */\n activeView?: Viewport;\n /**\n * An IModel to pull data from\n */\n iModel: IModelConnection;\n /** Width of the component */\n width: number;\n /** Height of the component */\n height: number;\n /**\n * Information for tree filtering.\n * @alpha\n */\n filterInfo?: VisibilityTreeFilterInfo;\n /**\n * Callback invoked when tree is filtered.\n */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n /**\n * Custom category visibility handler to use for testing\n * @internal\n */\n categoryVisibilityHandler?: CategoryVisibilityHandler;\n /**\n * Custom view manager to use for testing\n * @internal\n */\n viewManager?: ViewManager;\n\n /**\n * Available iModel categories\n */\n categories: CategoryInfo[];\n}\n\n/**\n * Tree which displays and manages categories contained in an iModel.\n * @public\n */\nexport function CategoryTree(props: CategoryTreeProps) {\n const { nodeLoader } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: RULESET_CATEGORIES,\n pagingSize: PAGING_SIZE,\n });\n\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n // istanbul ignore next\n const viewManager = props.viewManager ?? IModelApp.viewManager;\n const { activeView, allViewports, categoryVisibilityHandler } = props;\n const currentActiveView = activeView ?? viewManager.getFirstOpenView();\n const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, currentActiveView, allViewports, categoryVisibilityHandler);\n\n React.useEffect(() => {\n setViewType(currentActiveView); // eslint-disable-line @typescript-eslint/no-floating-promises\n }, [currentActiveView]);\n\n const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n collapsedChildrenDisposalEnabled: true,\n }), [filteredNodeLoader, visibilityHandler]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = useVisibilityTreeRenderer(false, true);\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const noFilteredDataRenderer = React.useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"categoriesTree.noCategoryFound\")}\n message={TreeWidget.translate(\"categoriesTree.noMatchingCategoryNames\")}\n />;\n }, []);\n\n return (\n <div className=\"tree-widget-categories-tree\">\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n descriptionsEnabled={true}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useCategoryVisibilityHandler(viewManager: ViewManager, imodel: IModelConnection, categories: CategoryInfo[], activeView?: Viewport, allViewports?: boolean, visibilityHandler?: CategoryVisibilityHandler) {\n return useDisposable(React.useCallback(\n () =>\n // istanbul ignore next\n visibilityHandler ?? new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }),\n [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]),\n );\n}\n\nasync function setViewType(activeView?: Viewport) {\n if (!activeView)\n return;\n\n const view = activeView.view as SpatialViewState;\n const viewType = view.is3d() ? \"3d\" : \"2d\";\n await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString(\"ViewType\", viewType);\n}\n"]}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import "./CategoriesTree.scss";
|
|
3
|
-
import type { CategoriesTreeProps } from "../../../types";
|
|
4
|
-
export declare function CategoriesTreeComponent(props: CategoriesTreeProps): JSX.Element;
|
|
3
|
+
import type { CategoriesTreeHeaderButtonProps, CategoriesTreeProps } from "../../../types";
|
|
4
|
+
export declare function CategoriesTreeComponent(props: CategoriesTreeProps): JSX.Element | null;
|
|
5
|
+
export declare namespace CategoriesTreeComponent {
|
|
6
|
+
var ShowAllButton: (props: CategoriesTreeHeaderButtonProps) => JSX.Element;
|
|
7
|
+
var HideAllButton: (props: CategoriesTreeHeaderButtonProps) => JSX.Element;
|
|
8
|
+
var InvertButton: (props: CategoriesTreeHeaderButtonProps) => JSX.Element;
|
|
9
|
+
}
|
|
5
10
|
//# sourceMappingURL=CategoriesTreeComponent.d.ts.map
|
|
@@ -30,31 +30,73 @@ const appui_react_1 = require("@itwin/appui-react");
|
|
|
30
30
|
const core_frontend_1 = require("@itwin/core-frontend");
|
|
31
31
|
const CategoriesTree_1 = require("./CategoriesTree");
|
|
32
32
|
const CategoryVisibilityHandler_1 = require("./CategoryVisibilityHandler");
|
|
33
|
-
const
|
|
33
|
+
const CategoriesVisibilityUtils_1 = require("../CategoriesVisibilityUtils");
|
|
34
34
|
const TreeFilteringState_1 = require("../../TreeFilteringState");
|
|
35
35
|
const AutoSizer_1 = require("../../utils/AutoSizer");
|
|
36
|
+
const IconButton_1 = require("../../IconButton");
|
|
37
|
+
const TreeWidget_1 = require("../../../TreeWidget");
|
|
38
|
+
const SearchBar_1 = require("../../search-bar/SearchBar");
|
|
36
39
|
function CategoriesTreeComponent(props) {
|
|
37
|
-
const iModel = appui_react_1.useActiveIModelConnection();
|
|
38
|
-
const viewport = appui_react_1.useActiveViewport();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const iModel = (0, appui_react_1.useActiveIModelConnection)();
|
|
41
|
+
const viewport = (0, appui_react_1.useActiveViewport)();
|
|
42
|
+
if (!iModel || !viewport) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return (react_1.default.createElement(CategoriesTreeComponentImpl, { ...props, iModel: iModel, viewport: viewport }));
|
|
46
|
+
}
|
|
47
|
+
exports.CategoriesTreeComponent = CategoriesTreeComponent;
|
|
48
|
+
CategoriesTreeComponent.ShowAllButton = ShowAllButton;
|
|
49
|
+
CategoriesTreeComponent.HideAllButton = HideAllButton;
|
|
50
|
+
CategoriesTreeComponent.InvertButton = InvertButton;
|
|
51
|
+
function CategoriesTreeComponentImpl(props) {
|
|
52
|
+
var _a;
|
|
53
|
+
const categories = (0, CategoryVisibilityHandler_1.useCategories)(core_frontend_1.IModelApp.viewManager, props.iModel, props.viewport);
|
|
54
|
+
const [filteredCategories, setFilteredCategories] = (0, react_1.useState)();
|
|
55
|
+
const { searchOptions, filterString, activeMatchIndex, onFilterApplied, filteredProvider, } = (0, TreeFilteringState_1.useTreeFilteringState)();
|
|
56
|
+
(0, react_1.useEffect)(() => {
|
|
57
|
+
(async () => {
|
|
58
|
+
if (filteredProvider)
|
|
59
|
+
setFilteredCategories((await getFilteredCategories(filteredProvider)).map((category) => ({ categoryId: category })));
|
|
60
|
+
else
|
|
61
|
+
setFilteredCategories(undefined);
|
|
62
|
+
})();
|
|
63
|
+
}, [filteredProvider]);
|
|
64
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
65
|
+
react_1.default.createElement(SearchBar_1.SearchBar, { value: "", valueChangedDelay: 500, placeholder: TreeWidget_1.TreeWidget.translate("search"), title: TreeWidget_1.TreeWidget.translate("searchForSomething"), filteringInProgress: searchOptions.isFiltering, onFilterCancel: searchOptions.onFilterCancel, onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount: (_a = searchOptions.matchedResultCount) !== null && _a !== void 0 ? _a : 0 }, props.headerButtons
|
|
66
|
+
? props.headerButtons.map((btn, index) => react_1.default.createElement(react_1.default.Fragment, { key: index }, btn({ viewport: props.viewport, categories, filteredCategories })))
|
|
67
|
+
: [
|
|
68
|
+
react_1.default.createElement(ShowAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, key: "show-all-btn" }),
|
|
69
|
+
react_1.default.createElement(HideAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, key: "hide-all-btn" }),
|
|
70
|
+
react_1.default.createElement(InvertButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, key: "invert-all-btn" }),
|
|
71
|
+
]),
|
|
72
|
+
react_1.default.createElement(AutoSizer_1.AutoSizer, null, ({ width, height }) => (react_1.default.createElement(CategoriesTree_1.CategoryTree, { ...props, categories: categories, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex }, onFilterApplied: onFilterApplied })))));
|
|
73
|
+
}
|
|
74
|
+
async function getFilteredCategories(filteredProvider) {
|
|
75
|
+
const nodes = await filteredProvider.getNodes();
|
|
76
|
+
return nodes.map((node) => CategoryVisibilityHandler_1.CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));
|
|
77
|
+
}
|
|
78
|
+
function ShowAllButton(props) {
|
|
79
|
+
const showAll = () => {
|
|
80
|
+
var _a;
|
|
81
|
+
(0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId), true, true);
|
|
82
|
+
};
|
|
83
|
+
return (react_1.default.createElement(IconButton_1.IconButton, { className: "tree-widget-header-tree-toolbar-icon", icon: "icon-visibility", title: TreeWidget_1.TreeWidget.translate("showAll"), onClick: showAll }));
|
|
84
|
+
}
|
|
85
|
+
function HideAllButton(props) {
|
|
86
|
+
const hideAll = () => {
|
|
87
|
+
var _a;
|
|
88
|
+
(0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId), false, true);
|
|
89
|
+
};
|
|
90
|
+
return (react_1.default.createElement(IconButton_1.IconButton, { className: "tree-widget-header-tree-toolbar-icon", icon: "icon-visibility-hide-2", title: TreeWidget_1.TreeWidget.translate("hideAll"), onClick: hideAll }));
|
|
91
|
+
}
|
|
92
|
+
function InvertButton(props) {
|
|
93
|
+
const invert = () => {
|
|
94
|
+
var _a;
|
|
95
|
+
const ids = ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId);
|
|
54
96
|
const enabled = [];
|
|
55
97
|
const disabled = [];
|
|
56
98
|
for (const id of ids) {
|
|
57
|
-
if (viewport.view.viewsCategory(id)) {
|
|
99
|
+
if (props.viewport.view.viewsCategory(id)) {
|
|
58
100
|
enabled.push(id);
|
|
59
101
|
}
|
|
60
102
|
else {
|
|
@@ -62,14 +104,10 @@ function CategoriesTreeComponent(props) {
|
|
|
62
104
|
}
|
|
63
105
|
}
|
|
64
106
|
// Disable enabled
|
|
65
|
-
|
|
107
|
+
(0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, enabled, false, true);
|
|
66
108
|
// Enable disabled
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return (react_1.default.createElement(
|
|
70
|
-
react_1.default.createElement(react_1.default.Fragment, null,
|
|
71
|
-
react_1.default.createElement(TreeHeader_1.TreeHeaderComponent, { searchOptions: searchOptions, showAll: showAll, hideAll: hideAll, invert: invert }),
|
|
72
|
-
react_1.default.createElement(AutoSizer_1.AutoSizer, null, ({ width, height }) => (react_1.default.createElement(CategoriesTree_1.CategoryTree, { ...props, iModel: iModel, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex }, onFilterApplied: onFilterApplied }))))));
|
|
109
|
+
(0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, disabled, true, true);
|
|
110
|
+
};
|
|
111
|
+
return (react_1.default.createElement(IconButton_1.IconButton, { className: "tree-widget-header-tree-toolbar-icon", title: TreeWidget_1.TreeWidget.translate("invert"), icon: "icon-visibility-invert", onClick: invert }));
|
|
73
112
|
}
|
|
74
|
-
exports.CategoriesTreeComponent = CategoriesTreeComponent;
|
|
75
113
|
//# sourceMappingURL=CategoriesTreeComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,iCAA+B;AAC/B,+CAA2C;AAC3C,oDAAkF;AAClF,wDAAiD;AACjD,qDAAoF;AACpF,2EAAwE;AACxE,wDAA8D;AAC9D,iEAAiE;AACjE,qDAAkD;AAGlD,SAAgB,uBAAuB,CAAC,KAA0B;IAChE,MAAM,MAAM,GAAG,uCAAyB,EAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,+BAAiB,EAAE,CAAC;IAErC,MAAM,EACJ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,GAAG,0CAAqB,EAAE,CAAC;IAE5B,MAAM,OAAO,GAAG,mBAAW,CAAC,KAAK,IAAI,EAAE;QACrC,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,OAAO,oCAAmB,CACxB,yBAAS,CAAC,WAAW,EACrB,MAAM,EACN,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,gBAAgB,CACjB,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,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OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GACd;YACF,8BAAC,qBAAS,QACP,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CACtB,8BAAC,6BAAY,OACP,KAAK,EACT,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,EACtD,eAAe,EAAE,eAAe,GAChC,CACH,CACS,CACX,CAEJ,CACJ,CAAC;AACJ,CAAC;AA9FD,0DA8FC","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*--------------------------------------------------------------------------------------------*/\nimport \"./CategoriesTree.scss\";\nimport React, { useCallback } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { CategoryTree, getCategories, toggleAllCategories } from \"./CategoriesTree\";\nimport { CategoryVisibilityHandler } from \"./CategoryVisibilityHandler\";\nimport { TreeHeaderComponent } from \"../../header/TreeHeader\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport type { CategoriesTreeProps } from \"../../../types\";\n\nexport function CategoriesTreeComponent(props: CategoriesTreeProps) {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n const {\n searchOptions,\n filterString,\n activeMatchIndex,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n const showAll = useCallback(async () => {\n if (!iModel) return;\n\n return toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n true,\n undefined,\n true,\n filteredProvider\n );\n }, [iModel, filteredProvider]);\n\n const hideAll = useCallback(async () => {\n if (!iModel) return;\n return toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n false,\n undefined,\n true,\n filteredProvider\n );\n }, [iModel, filteredProvider]);\n\n const invert = useCallback(async () => {\n if (!iModel || !viewport) return;\n\n const ids = await getCategories(iModel, viewport, filteredProvider);\n const enabled: string[] = [];\n const disabled: string[] = [];\n for (const id of ids) {\n if (viewport.view.viewsCategory(id)) {\n enabled.push(id);\n } else {\n disabled.push(id);\n }\n }\n // Disable enabled\n CategoryVisibilityHandler.enableCategory(\n IModelApp.viewManager,\n iModel,\n enabled,\n false,\n true\n );\n // Enable disabled\n CategoryVisibilityHandler.enableCategory(\n IModelApp.viewManager,\n iModel,\n disabled,\n true,\n true\n );\n }, [iModel, viewport, filteredProvider]);\n\n return (\n <>\n {iModel && viewport &&\n <>\n <TreeHeaderComponent\n searchOptions={searchOptions}\n showAll={showAll}\n hideAll={hideAll}\n invert={invert}\n />\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n iModel={iModel}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n }\n </>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,iCAA+B;AAC/B,+CAAmD;AACnD,oDAAkF;AAClF,wDAAmF;AACnF,qDAAgD;AAChD,2EAAqG;AACrG,4EAA8D;AAC9D,iEAAiE;AACjE,qDAAkD;AAGlD,iDAA8C;AAC9C,oDAAiD;AACjD,0DAAuD;AAEvD,SAAgB,uBAAuB,CAAC,KAA0B;IAChE,MAAM,MAAM,GAAG,IAAA,uCAAyB,GAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAA,+BAAiB,GAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;I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------------------------------------------------------\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*--------------------------------------------------------------------------------------------*/\nimport \"./CategoriesTree.scss\";\nimport React, { useEffect, useState } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp, IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryInfo, CategoryVisibilityHandler, useCategories } from \"./CategoryVisibilityHandler\";\nimport { enableCategory } from \"../CategoriesVisibilityUtils\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport type { CategoriesTreeHeaderButtonProps, CategoriesTreeProps } from \"../../../types\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport { IconButton } from \"../../IconButton\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { SearchBar } from \"../../search-bar/SearchBar\";\n\nexport function CategoriesTreeComponent(props: CategoriesTreeProps) {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return (\n <CategoriesTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />\n );\n}\n\nCategoriesTreeComponent.ShowAllButton = ShowAllButton;\nCategoriesTreeComponent.HideAllButton = HideAllButton;\nCategoriesTreeComponent.InvertButton = InvertButton;\n\nfunction CategoriesTreeComponentImpl(props: CategoriesTreeProps & { iModel: IModelConnection, viewport: ScreenViewport }) {\n const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);\n const [filteredCategories, setFilteredCategories] = useState<CategoryInfo[]>();\n const {\n searchOptions,\n filterString,\n activeMatchIndex,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n useEffect(() => {\n (async () => {\n if (filteredProvider)\n setFilteredCategories((await getFilteredCategories(filteredProvider)).map((category) => ({ categoryId: category })));\n else\n setFilteredCategories(undefined);\n })();\n }, [filteredProvider]);\n\n return (\n <>\n <SearchBar\n value=\"\"\n valueChangedDelay={500}\n placeholder={TreeWidget.translate(\"search\")}\n title={TreeWidget.translate(\"searchForSomething\")}\n filteringInProgress={searchOptions.isFiltering}\n onFilterCancel={searchOptions.onFilterCancel}\n onFilterClear={searchOptions.onFilterCancel}\n onFilterStart={searchOptions.onFilterStart}\n onSelectedChanged={searchOptions.onResultSelectedChanged}\n resultCount={searchOptions.matchedResultCount ?? 0}\n >\n {props.headerButtons\n ? props.headerButtons.map((btn, index) =>\n <React.Fragment key={index}>\n {btn({ viewport: props.viewport, categories, filteredCategories })}\n </React.Fragment>)\n : [\n <ShowAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"show-all-btn\" />,\n <HideAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"hide-all-btn\" />,\n <InvertButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"invert-all-btn\" />,\n ]\n }\n </SearchBar>\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n categories={categories}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n );\n}\n\nasync function getFilteredCategories(filteredProvider: IPresentationTreeDataProvider) {\n const nodes = await filteredProvider.getNodes();\n return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));\n}\n\nfunction ShowAllButton(props: CategoriesTreeHeaderButtonProps) {\n const showAll = () => {\n enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n true,\n true,\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n icon=\"icon-visibility\"\n title={TreeWidget.translate(\"showAll\")}\n onClick={showAll}\n />\n );\n}\n\nfunction HideAllButton(props: CategoriesTreeHeaderButtonProps) {\n const hideAll = () => {\n enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n false,\n true,\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n icon=\"icon-visibility-hide-2\"\n title={TreeWidget.translate(\"hideAll\")}\n onClick={hideAll}\n />\n );\n}\n\nfunction InvertButton(props: CategoriesTreeHeaderButtonProps) {\n const invert = () => {\n const ids = (props.filteredCategories ?? props.categories).map((category) => category.categoryId);\n\n const enabled: string[] = [];\n const disabled: string[] = [];\n for (const id of ids) {\n if (props.viewport.view.viewsCategory(id)) {\n enabled.push(id);\n } else {\n disabled.push(id);\n }\n }\n // Disable enabled\n enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n enabled,\n false,\n true\n );\n\n // Enable disabled\n enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n disabled,\n true,\n true\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n title={TreeWidget.translate(\"invert\")}\n icon=\"icon-visibility-invert\"\n onClick={invert}\n />\n );\n}\n"]}
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
+
import { TreeNodeItem } from "@itwin/components-react";
|
|
1
2
|
import { BeEvent } from "@itwin/core-bentley";
|
|
3
|
+
import { IModelConnection, ViewManager, Viewport } from "@itwin/core-frontend";
|
|
2
4
|
import { NodeKey } from "@itwin/presentation-common";
|
|
3
|
-
import
|
|
4
|
-
import type { TreeNodeItem } from "@itwin/components-react";
|
|
5
|
-
import type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from "../VisibilityTreeEventHandler";
|
|
5
|
+
import { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from "../VisibilityTreeEventHandler";
|
|
6
6
|
/**
|
|
7
7
|
* Loads categories from viewport or uses provided list of categories.
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
export declare function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport):
|
|
11
|
-
/** @internal */
|
|
12
|
-
export declare function loadCategoriesFromViewport(iModel?: IModelConnection, vp?: Viewport): Promise<Category[]>;
|
|
10
|
+
export declare function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport): CategoryInfo[];
|
|
13
11
|
/**
|
|
14
12
|
* Data structure that describes category.
|
|
15
13
|
* @alpha
|
|
16
14
|
*/
|
|
17
|
-
export interface
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
export interface CategoryInfo {
|
|
16
|
+
categoryId: string;
|
|
17
|
+
subCategoryIds?: string[];
|
|
20
18
|
}
|
|
21
19
|
/** @alpha */
|
|
22
20
|
export interface CategoryVisibilityHandlerParams {
|
|
23
21
|
viewManager: ViewManager;
|
|
24
22
|
imodel: IModelConnection;
|
|
25
|
-
categories:
|
|
23
|
+
categories: CategoryInfo[];
|
|
26
24
|
activeView?: Viewport;
|
|
27
25
|
allViewports?: boolean;
|
|
28
26
|
}
|
|
@@ -41,14 +39,12 @@ export declare class CategoryVisibilityHandler implements IVisibilityHandler {
|
|
|
41
39
|
changeVisibility(node: TreeNodeItem, nodeKey: NodeKey, shouldDisplay: boolean): Promise<void>;
|
|
42
40
|
getSubCategoryVisibility(id: string): "visible" | "hidden";
|
|
43
41
|
getCategoryVisibility(id: string): "visible" | "hidden";
|
|
44
|
-
getParent(key: string):
|
|
42
|
+
getParent(key: string): CategoryInfo | undefined;
|
|
45
43
|
private onDisplayStyleChanged;
|
|
46
44
|
private onViewedCategoriesChanged;
|
|
47
45
|
private onVisibilityChangeInternal;
|
|
48
46
|
static getInstanceIdFromTreeNodeKey(nodeKey: NodeKey): string;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
/** Changes subcategory display in the viewport */
|
|
52
|
-
static enableSubCategory(viewManager: ViewManager, key: string, enabled: boolean, forAllViewports?: boolean): void;
|
|
47
|
+
enableCategory(ids: string[], enabled: boolean, enableAllSubCategories?: boolean): void;
|
|
48
|
+
enableSubCategory(key: string, enabled: boolean): void;
|
|
53
49
|
}
|
|
54
50
|
//# sourceMappingURL=CategoryVisibilityHandler.d.ts.map
|
|
@@ -23,13 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.CategoryVisibilityHandler = exports.
|
|
26
|
+
exports.CategoryVisibilityHandler = exports.useCategories = void 0;
|
|
27
27
|
const React = __importStar(require("react"));
|
|
28
28
|
const components_react_1 = require("@itwin/components-react");
|
|
29
29
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
30
|
-
const core_common_1 = require("@itwin/core-common");
|
|
31
|
-
const core_frontend_1 = require("@itwin/core-frontend");
|
|
32
30
|
const presentation_common_1 = require("@itwin/presentation-common");
|
|
31
|
+
const CategoriesVisibilityUtils_1 = require("../CategoriesVisibilityUtils");
|
|
33
32
|
const EMPTY_CATEGORIES_ARRAY = [];
|
|
34
33
|
/**
|
|
35
34
|
* Loads categories from viewport or uses provided list of categories.
|
|
@@ -38,32 +37,10 @@ const EMPTY_CATEGORIES_ARRAY = [];
|
|
|
38
37
|
function useCategories(viewManager, imodel, view) {
|
|
39
38
|
var _a;
|
|
40
39
|
const currentView = view || viewManager.getFirstOpenView();
|
|
41
|
-
const categoriesPromise = React.useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);
|
|
42
|
-
return (_a = components_react_1.useAsyncValue(categoriesPromise)) !== null && _a !== void 0 ? _a : EMPTY_CATEGORIES_ARRAY;
|
|
40
|
+
const categoriesPromise = React.useMemo(async () => (0, CategoriesVisibilityUtils_1.loadCategoriesFromViewport)(imodel, currentView), [imodel, currentView]);
|
|
41
|
+
return (_a = (0, components_react_1.useAsyncValue)(categoriesPromise)) !== null && _a !== void 0 ? _a : EMPTY_CATEGORIES_ARRAY;
|
|
43
42
|
}
|
|
44
43
|
exports.useCategories = useCategories;
|
|
45
|
-
/** @internal */
|
|
46
|
-
async function loadCategoriesFromViewport(iModel, vp) {
|
|
47
|
-
if (!vp)
|
|
48
|
-
return EMPTY_CATEGORIES_ARRAY;
|
|
49
|
-
// Query categories and add them to state
|
|
50
|
-
const selectUsedSpatialCategoryIds = "SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)";
|
|
51
|
-
const selectUsedDrawingCategoryIds = "SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)";
|
|
52
|
-
const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;
|
|
53
|
-
const ecsql2 = `SELECT ECInstanceId as id, UserLabel as label, CodeValue as code FROM ${vp.view.is3d() ? "BisCore.SpatialCategory" : "BisCore.DrawingCategory"} WHERE ECInstanceId IN (${ecsql})`;
|
|
54
|
-
const categories = [];
|
|
55
|
-
// istanbul ignore else
|
|
56
|
-
if (iModel) {
|
|
57
|
-
const rowIterator = iModel.query(ecsql2, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames });
|
|
58
|
-
// istanbul ignore next
|
|
59
|
-
for await (const row of rowIterator) {
|
|
60
|
-
const subCategoryIds = iModel.subcategories.getSubCategories(row.id);
|
|
61
|
-
categories.push({ key: row.id, children: (subCategoryIds) ? [...subCategoryIds] : undefined });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return categories;
|
|
65
|
-
}
|
|
66
|
-
exports.loadCategoriesFromViewport = loadCategoriesFromViewport;
|
|
67
44
|
/** @alpha */
|
|
68
45
|
class CategoryVisibilityHandler {
|
|
69
46
|
constructor(params) {
|
|
@@ -105,21 +82,21 @@ class CategoryVisibilityHandler {
|
|
|
105
82
|
if (node.parentId) {
|
|
106
83
|
const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
|
|
107
84
|
// istanbul ignore next
|
|
108
|
-
const parentId = (_a = this.getParent(childId)) === null || _a === void 0 ? void 0 : _a.
|
|
85
|
+
const parentId = (_a = this.getParent(childId)) === null || _a === void 0 ? void 0 : _a.categoryId;
|
|
109
86
|
// make sure parent category is enabled
|
|
110
87
|
if (shouldDisplay && parentId)
|
|
111
|
-
|
|
112
|
-
|
|
88
|
+
this.enableCategory([parentId], true, false);
|
|
89
|
+
this.enableSubCategory(childId, shouldDisplay);
|
|
113
90
|
return;
|
|
114
91
|
}
|
|
115
92
|
const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
|
|
116
|
-
|
|
93
|
+
this.enableCategory([instanceId], shouldDisplay, true);
|
|
117
94
|
}
|
|
118
95
|
getSubCategoryVisibility(id) {
|
|
119
96
|
const parentItem = this.getParent(id);
|
|
120
97
|
if (!parentItem || !this._activeView)
|
|
121
98
|
return "hidden";
|
|
122
|
-
const isVisible = this._activeView.view.viewsCategory(parentItem.
|
|
99
|
+
const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);
|
|
123
100
|
return isVisible ? "visible" : "hidden";
|
|
124
101
|
}
|
|
125
102
|
getCategoryVisibility(id) {
|
|
@@ -130,8 +107,8 @@ class CategoryVisibilityHandler {
|
|
|
130
107
|
getParent(key) {
|
|
131
108
|
for (const category of this._categories) {
|
|
132
109
|
// istanbul ignore else
|
|
133
|
-
if (category.
|
|
134
|
-
if (category.
|
|
110
|
+
if (category.subCategoryIds) {
|
|
111
|
+
if (category.subCategoryIds.indexOf(key) !== -1)
|
|
135
112
|
return category;
|
|
136
113
|
}
|
|
137
114
|
}
|
|
@@ -148,65 +125,11 @@ class CategoryVisibilityHandler {
|
|
|
148
125
|
static getInstanceIdFromTreeNodeKey(nodeKey) {
|
|
149
126
|
return (presentation_common_1.NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0) ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ "";
|
|
150
127
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (!viewManager.selectedView)
|
|
154
|
-
return;
|
|
155
|
-
const updateViewport = (vp) => {
|
|
156
|
-
// Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we
|
|
157
|
-
// are using 'allViewports' property
|
|
158
|
-
if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {
|
|
159
|
-
vp.changeCategoryDisplay(ids, enabled, enableAllSubCategories);
|
|
160
|
-
// remove category overrides per model
|
|
161
|
-
const modelsContainingOverrides = [];
|
|
162
|
-
for (const ovr of vp.perModelCategoryVisibility) {
|
|
163
|
-
// istanbul ignore else
|
|
164
|
-
if (ids.findIndex((id) => id === ovr.categoryId) !== -1)
|
|
165
|
-
modelsContainingOverrides.push(ovr.modelId);
|
|
166
|
-
}
|
|
167
|
-
vp.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, core_frontend_1.PerModelCategoryVisibility.Override.None);
|
|
168
|
-
// changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.
|
|
169
|
-
if (false === enabled) {
|
|
170
|
-
ids.forEach((id) => {
|
|
171
|
-
const subCategoryIds = imodel.subcategories.getSubCategories(id);
|
|
172
|
-
// istanbul ignore else
|
|
173
|
-
if (subCategoryIds) {
|
|
174
|
-
subCategoryIds.forEach((subCategoryId) => CategoryVisibilityHandler.enableSubCategory(viewManager, subCategoryId, false, forAllViewports));
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
// This property let us act on all viewports or just on the selected one, configurable by the app
|
|
181
|
-
if (forAllViewports) {
|
|
182
|
-
for (const viewport of viewManager) {
|
|
183
|
-
updateViewport(viewport);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
updateViewport(viewManager.selectedView);
|
|
188
|
-
}
|
|
128
|
+
enableCategory(ids, enabled, enableAllSubCategories = true) {
|
|
129
|
+
(0, CategoriesVisibilityUtils_1.enableCategory)(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);
|
|
189
130
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (!viewManager.selectedView)
|
|
193
|
-
return;
|
|
194
|
-
const updateViewport = (vp) => {
|
|
195
|
-
// Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we
|
|
196
|
-
// are using 'allViewports' property
|
|
197
|
-
if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {
|
|
198
|
-
vp.changeSubCategoryDisplay(key, enabled);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
// This property let us act on all viewports or just on the selected one, configurable by the app
|
|
202
|
-
if (forAllViewports) {
|
|
203
|
-
for (const viewport of viewManager) {
|
|
204
|
-
updateViewport(viewport);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
updateViewport(viewManager.selectedView);
|
|
209
|
-
}
|
|
131
|
+
enableSubCategory(key, enabled) {
|
|
132
|
+
(0, CategoriesVisibilityUtils_1.enableSubCategory)(this._viewManager, key, enabled, this._useAllViewports);
|
|
210
133
|
}
|
|
211
134
|
}
|
|
212
135
|
exports.CategoryVisibilityHandler = CategoryVisibilityHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoryVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoryVisibilityHandler.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,6CAA+B;AAC/B,8DAAwD;AACxD,sDAA8C;AAC9C,oDAAoD;AACpD,wDAAkE;AAClE,oEAAqD;AAKrD,MAAM,sBAAsB,GAAe,EAAE,CAAC;AAE9C;;;GAGG;AACH,SAAgB,aAAa,CAAC,WAAwB,EAAE,MAAwB,EAAE,IAAe;;IAC/F,MAAM,WAAW,GAAG,IAAI,IAA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------------------------------------------------------------------------------\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 * as React from \"react\";\nimport { useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { QueryRowFormat } from \"@itwin/core-common\";\nimport { PerModelCategoryVisibility } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport type { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from \"../VisibilityTreeEventHandler\";\n\nconst EMPTY_CATEGORIES_ARRAY: Category[] = [];\n\n/**\n * Loads categories from viewport or uses provided list of categories.\n * @internal\n */\nexport function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport) {\n const currentView = view || viewManager.getFirstOpenView();\n const categoriesPromise = React.useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/** @internal */\nexport async function loadCategoriesFromViewport(iModel?: IModelConnection, vp?: Viewport) {\n if (!vp)\n return EMPTY_CATEGORIES_ARRAY;\n\n // Query categories and add them to state\n const selectUsedSpatialCategoryIds = \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)\";\n const selectUsedDrawingCategoryIds = \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)\";\n const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;\n const ecsql2 = `SELECT ECInstanceId as id, UserLabel as label, CodeValue as code FROM ${vp.view.is3d() ? \"BisCore.SpatialCategory\" : \"BisCore.DrawingCategory\"} WHERE ECInstanceId IN (${ecsql})`;\n\n const categories: Category[] = [];\n\n // istanbul ignore else\n if (iModel) {\n const rowIterator = iModel.query(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames });\n // istanbul ignore next\n for await (const row of rowIterator) {\n const subCategoryIds = iModel.subcategories.getSubCategories(row.id);\n categories.push({ key: row.id, children: (subCategoryIds) ? [...subCategoryIds] : undefined });\n }\n }\n\n return categories;\n}\n\n/**\n * Data structure that describes category.\n * @alpha\n */\nexport interface Category {\n key: string;\n children?: string[];\n}\n\n/** @alpha */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: Category[];\n activeView?: Viewport;\n allViewports?: boolean;\n}\n\n/** @alpha */\nexport class CategoryVisibilityHandler implements IVisibilityHandler {\n private _viewManager: ViewManager;\n private _imodel: IModelConnection;\n private _pendingVisibilityChange: any | undefined;\n private _activeView?: Viewport;\n private _useAllViewports: boolean;\n private _categories: Category[];\n\n constructor(params: CategoryVisibilityHandlerParams) {\n this._viewManager = params.viewManager;\n this._imodel = params.imodel;\n this._activeView = params.activeView;\n // istanbul ignore next\n this._useAllViewports = params.allViewports ?? false;\n this._categories = params.categories;\n if (this._activeView) {\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n }\n\n public dispose() {\n if (this._activeView) {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n }\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent<VisibilityChangeListener>();\n\n public getVisibilityStatus(node: TreeNodeItem, nodeKey: NodeKey): VisibilityStatus {\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };\n }\n\n public async changeVisibility(node: TreeNodeItem, nodeKey: NodeKey, shouldDisplay: boolean): Promise<void> {\n // handle subcategory visibility change\n if (node.parentId) {\n const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n // istanbul ignore next\n const parentId = this.getParent(childId)?.key;\n\n // make sure parent category is enabled\n if (shouldDisplay && parentId)\n CategoryVisibilityHandler.enableCategory(this._viewManager, this._imodel, [parentId], true, this._useAllViewports, false);\n\n CategoryVisibilityHandler.enableSubCategory(this._viewManager, childId, shouldDisplay, this._useAllViewports);\n return;\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n CategoryVisibilityHandler.enableCategory(this._viewManager, this._imodel, [instanceId], shouldDisplay, true);\n }\n\n public getSubCategoryVisibility(id: string) {\n const parentItem = this.getParent(id);\n if (!parentItem || !this._activeView)\n return \"hidden\";\n\n const isVisible = this._activeView.view.viewsCategory(parentItem.key) && this._activeView.isSubCategoryVisible(id);\n return isVisible ? \"visible\" : \"hidden\";\n }\n\n public getCategoryVisibility(id: string) {\n if (!this._activeView)\n return \"hidden\";\n return this._activeView.view.viewsCategory(id) ? \"visible\" : \"hidden\";\n }\n\n public getParent(key: string): Category | undefined {\n for (const category of this._categories) {\n // istanbul ignore else\n if (category.children) {\n if (category.children.indexOf(key) !== -1)\n return category;\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onDisplayStyleChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onViewedCategoriesChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n private onVisibilityChangeInternal() {\n if (this._pendingVisibilityChange)\n return;\n\n this._pendingVisibilityChange = setTimeout(() => {\n this.onVisibilityChange.raiseEvent();\n this._pendingVisibilityChange = undefined;\n }, 0);\n }\n\n public static getInstanceIdFromTreeNodeKey(nodeKey: NodeKey) {\n return (NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0) ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ \"\";\n }\n\n /** Changes category display in the viewport */\n public static enableCategory(viewManager: ViewManager, imodel: IModelConnection, ids: string[], enabled: boolean, forAllViewports: boolean, enableAllSubCategories = true) {\n if (!viewManager.selectedView)\n return;\n\n const updateViewport = (vp: Viewport) => {\n // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we\n // are using 'allViewports' property\n if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {\n vp.changeCategoryDisplay(ids, enabled, enableAllSubCategories);\n\n // remove category overrides per model\n const modelsContainingOverrides: string[] = [];\n for (const ovr of vp.perModelCategoryVisibility) {\n // istanbul ignore else\n if (ids.findIndex((id) => id === ovr.categoryId) !== -1)\n modelsContainingOverrides.push(ovr.modelId);\n }\n vp.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, PerModelCategoryVisibility.Override.None);\n\n // changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.\n if (false === enabled) {\n ids.forEach((id) => {\n const subCategoryIds = imodel.subcategories.getSubCategories(id);\n // istanbul ignore else\n if (subCategoryIds) {\n subCategoryIds.forEach((subCategoryId) => CategoryVisibilityHandler.enableSubCategory(viewManager, subCategoryId, false, forAllViewports));\n }\n });\n }\n }\n };\n\n // This property let us act on all viewports or just on the selected one, configurable by the app\n if (forAllViewports) {\n for (const viewport of viewManager) {\n updateViewport(viewport);\n }\n } else {\n updateViewport(viewManager.selectedView);\n }\n }\n\n /** Changes subcategory display in the viewport */\n public static enableSubCategory(viewManager: ViewManager, key: string, enabled: boolean, forAllViewports?: boolean) {\n if (!viewManager.selectedView)\n return;\n\n const updateViewport = (vp: Viewport) => {\n // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we\n // are using 'allViewports' property\n if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {\n vp.changeSubCategoryDisplay(key, enabled);\n }\n };\n\n // This property let us act on all viewports or just on the selected one, configurable by the app\n if (forAllViewports) {\n for (const viewport of viewManager) {\n updateViewport(viewport);\n }\n } else {\n updateViewport(viewManager.selectedView);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CategoryVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoryVisibilityHandler.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,6CAA+B;AAC/B,8DAAsE;AACtE,sDAA8C;AAE9C,oEAAqD;AACrD,4EAA6G;AAG7G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACH,SAAgB,aAAa,CAAC,WAAwB,EAAE,MAAwB,EAAE,IAAe;;IAC/F,MAAM,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC3D,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,IAAA,sDAA0B,EAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC5H,OAAO,MAAA,IAAA,gCAAa,EAAC,iBAAiB,CAAC,mCAAI,sBAAsB,CAAC;AACpE,CAAC;AAJD,sCAIC;AAoBD,aAAa;AACb,MAAa,yBAAyB;IAQpC,YAAY,MAAuC;;QAqB5C,uBAAkB,GAAG,IAAI,sBAAO,EAA4B,CAAC;QAqDpE,gEAAgE;QACxD,0BAAqB,GAAG,GAAG,EAAE;YACnC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QAEF,gEAAgE;QACxD,8BAAyB,GAAG,GAAG,EAAE;YACvC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QAjFA,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,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,CAAC,cAAc,EAAE;gBAC3B,IAAI,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBAC7C,OAAO,QAAQ,CAAC;aACnB;SACF;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAYO,0BAA0B;QAChC,IAAI,IAAI,CAAC,wBAAwB;YAC/B,OAAO;QAET,IAAI,CAAC,wBAAwB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9C,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,CAAC;YACrC,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;QAC5C,CAAC,EAAE,CAAC,CAAC,CAAC;IACR,CAAC;IAEM,MAAM,CAAC,4BAA4B,CAAC,OAAgB;QACzD,OAAO,CAAC,6BAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,0BAA0B,CAAC,EAAE,CAAC;IAC/I,CAAC;IAEM,cAAc,CAAC,GAAa,EAAE,OAAgB,EAAE,sBAAsB,GAAG,IAAI;QAClF,IAAA,0CAAc,EAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAAC;IAC/G,CAAC;IAEM,iBAAiB,CAAC,GAAW,EAAE,OAAgB;QACpD,IAAA,6CAAiB,EAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC5E,CAAC;CACF;AAjHD,8DAiHC","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 * as React from \"react\";\nimport { TreeNodeItem, useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport { enableCategory, enableSubCategory, loadCategoriesFromViewport } from \"../CategoriesVisibilityUtils\";\nimport { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from \"../VisibilityTreeEventHandler\";\n\nconst EMPTY_CATEGORIES_ARRAY: CategoryInfo[] = [];\n\n/**\n * Loads categories from viewport or uses provided list of categories.\n * @internal\n */\nexport function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport) {\n const currentView = view || viewManager.getFirstOpenView();\n const categoriesPromise = React.useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/**\n * Data structure that describes category.\n * @alpha\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/** @alpha */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: CategoryInfo[];\n activeView?: Viewport;\n allViewports?: boolean;\n}\n\n/** @alpha */\nexport class CategoryVisibilityHandler implements IVisibilityHandler {\n private _viewManager: ViewManager;\n private _imodel: IModelConnection;\n private _pendingVisibilityChange: any | undefined;\n private _activeView?: Viewport;\n private _useAllViewports: boolean;\n private _categories: CategoryInfo[];\n\n constructor(params: CategoryVisibilityHandlerParams) {\n this._viewManager = params.viewManager;\n this._imodel = params.imodel;\n this._activeView = params.activeView;\n // istanbul ignore next\n this._useAllViewports = params.allViewports ?? false;\n this._categories = params.categories;\n if (this._activeView) {\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n }\n\n public dispose() {\n if (this._activeView) {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n }\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent<VisibilityChangeListener>();\n\n public getVisibilityStatus(node: TreeNodeItem, nodeKey: NodeKey): VisibilityStatus {\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };\n }\n\n public async changeVisibility(node: TreeNodeItem, nodeKey: NodeKey, shouldDisplay: boolean): Promise<void> {\n // handle subcategory visibility change\n if (node.parentId) {\n const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n // istanbul ignore next\n const parentId = this.getParent(childId)?.categoryId;\n\n // make sure parent category is enabled\n if (shouldDisplay && parentId)\n this.enableCategory([parentId], true, false);\n\n this.enableSubCategory(childId, shouldDisplay);\n return;\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n this.enableCategory([instanceId], shouldDisplay, true);\n }\n\n public getSubCategoryVisibility(id: string) {\n const parentItem = this.getParent(id);\n if (!parentItem || !this._activeView)\n return \"hidden\";\n\n const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);\n return isVisible ? \"visible\" : \"hidden\";\n }\n\n public getCategoryVisibility(id: string) {\n if (!this._activeView)\n return \"hidden\";\n return this._activeView.view.viewsCategory(id) ? \"visible\" : \"hidden\";\n }\n\n public getParent(key: string): CategoryInfo | undefined {\n for (const category of this._categories) {\n // istanbul ignore else\n if (category.subCategoryIds) {\n if (category.subCategoryIds.indexOf(key) !== -1)\n return category;\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onDisplayStyleChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onViewedCategoriesChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n private onVisibilityChangeInternal() {\n if (this._pendingVisibilityChange)\n return;\n\n this._pendingVisibilityChange = setTimeout(() => {\n this.onVisibilityChange.raiseEvent();\n this._pendingVisibilityChange = undefined;\n }, 0);\n }\n\n public static getInstanceIdFromTreeNodeKey(nodeKey: NodeKey) {\n return (NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0) ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ \"\";\n }\n\n public enableCategory(ids: string[], enabled: boolean, enableAllSubCategories = true) {\n enableCategory(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);\n }\n\n public enableSubCategory(key: string, enabled: boolean) {\n enableSubCategory(this._viewManager, key, enabled, this._useAllViewports);\n }\n}\n"]}
|
|
@@ -266,7 +266,7 @@
|
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
],
|
|
269
|
-
"instanceFilter": "this.Model.Id = parent.parent.ECInstanceId ANDALSO this.Parent = NULL
|
|
269
|
+
"instanceFilter": "this.Model.Id = parent.parent.ECInstanceId ANDALSO this.Parent = NULL",
|
|
270
270
|
"groupByClass": true,
|
|
271
271
|
"groupByLabel": false
|
|
272
272
|
}
|
|
@@ -300,7 +300,6 @@
|
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
],
|
|
303
|
-
"instanceFilter": "NOT HasVariable(\"filtered-element-ids\") OR GetVariableIntValues(\"filtered-element-ids\").AnyMatch(id => id = this.ECInstanceId)",
|
|
304
303
|
"groupByClass": true,
|
|
305
304
|
"groupByLabel": false
|
|
306
305
|
}
|