@itwin/tree-widget-react 3.5.1 → 3.6.1

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/README.md +2 -1
  3. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +6 -0
  4. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +49 -4
  5. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
  6. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.d.ts +4 -2
  7. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +91 -96
  8. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -1
  9. package/lib/cjs/tree-widget-react/components/trees/common/UseIModelAccess.d.ts +18 -0
  10. package/lib/cjs/tree-widget-react/components/trees/common/UseIModelAccess.js +34 -0
  11. package/lib/cjs/tree-widget-react/components/trees/common/UseIModelAccess.js.map +1 -0
  12. package/lib/cjs/tree-widget-react/components/trees/common/Utils.d.ts +0 -14
  13. package/lib/cjs/tree-widget-react/components/trees/common/Utils.js +1 -16
  14. package/lib/cjs/tree-widget-react/components/trees/common/Utils.js.map +1 -1
  15. package/lib/cjs/tree-widget-react/components/trees/common/components/Tree.d.ts +5 -0
  16. package/lib/cjs/tree-widget-react/components/trees/common/components/Tree.js +16 -9
  17. package/lib/cjs/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
  18. package/lib/cjs/tree-widget-react/components/trees/common/components/VisibilityTree.d.ts +2 -2
  19. package/lib/cjs/tree-widget-react/components/trees/common/components/VisibilityTree.js +8 -4
  20. package/lib/cjs/tree-widget-react/components/trees/common/components/VisibilityTree.js.map +1 -1
  21. package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +3 -1
  22. package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +12 -8
  23. package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  24. package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +1 -1
  25. package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  26. package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.d.ts +12 -1
  27. package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js +14 -44
  28. package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
  29. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +5 -3
  30. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +26 -60
  31. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
  32. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +22 -9
  33. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  34. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +6 -0
  35. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +49 -4
  36. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
  37. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.d.ts +4 -2
  38. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +92 -97
  39. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -1
  40. package/lib/esm/tree-widget-react/components/trees/common/UseIModelAccess.d.ts +18 -0
  41. package/lib/esm/tree-widget-react/components/trees/common/UseIModelAccess.js +30 -0
  42. package/lib/esm/tree-widget-react/components/trees/common/UseIModelAccess.js.map +1 -0
  43. package/lib/esm/tree-widget-react/components/trees/common/Utils.d.ts +0 -14
  44. package/lib/esm/tree-widget-react/components/trees/common/Utils.js +0 -14
  45. package/lib/esm/tree-widget-react/components/trees/common/Utils.js.map +1 -1
  46. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.d.ts +5 -0
  47. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +15 -9
  48. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
  49. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.d.ts +2 -2
  50. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.js +10 -6
  51. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.js.map +1 -1
  52. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +3 -1
  53. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +13 -9
  54. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  55. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +1 -1
  56. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  57. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.d.ts +12 -1
  58. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js +14 -44
  59. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
  60. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +5 -3
  61. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +27 -61
  62. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
  63. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +22 -9
  64. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  65. package/package.json +4 -5
package/CHANGELOG.md CHANGED
@@ -1,12 +1,34 @@
1
1
  # Change Log - @itwin/tree-widget-react
2
2
 
3
- This log was last generated on Thu, 06 Mar 2025 12:37:28 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 18 Apr 2025 17:06:09 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 3.6.1
8
+
9
+ Fri, 18 Apr 2025 17:06:09 GMT
10
+
11
+ ### Patches
12
+
13
+ - Fixed Categories tree not reacting to Category display changes from Models tree, when they're made on per-model category overrides. ([#1284](https://github.com/iTwin/viewer-components-react/pull/1284))
14
+ - Fixed `ModelsTree` and `CategoriesTree` not applying custom hierarchy level size limit. ([#1292](https://github.com/iTwin/viewer-components-react/pull/1292))
15
+
16
+ ## 3.6.0
17
+
18
+ Fri, 21 Mar 2025 11:37:20 GMT
19
+
20
+ ### Minor changes
21
+
22
+ - Add ability to remove root Subject node from Models and iModel content trees by setting `hideRootSubject: true` in the `hierarchyConfig` prop. ([#1251](https://github.com/iTwin/viewer-components-react/pull/1251))
23
+
24
+ ### Patches
25
+
26
+ - Fixed Models tree showing that modeled elements have children, when their sub model is private or when sub model does not have any elements. Now it shows that modeled element has children only when it's sub model has children and is not private. ([#1253](https://github.com/iTwin/viewer-components-react/pull/1253))
27
+ - Fixed Categories tree showing definition containers that contain categories without elements. Now it displays definition containers only when they have categories that contain elements. ([#1248](https://github.com/iTwin/viewer-components-react/pull/1248))
28
+
7
29
  ## 3.5.1
8
30
 
9
- Thu, 06 Mar 2025 12:37:28 GMT
31
+ Thu, 06 Mar 2025 12:37:44 GMT
10
32
 
11
33
  ### Patches
12
34
 
package/README.md CHANGED
@@ -180,7 +180,8 @@ function CustomModelsTreeRenderer(props: CustomModelsTreeRendererProps) {
180
180
  },
181
181
  [getLabel],
182
182
  );
183
- return <VisibilityTreeRenderer {...props} getLabel={getLabelCallback} getSublabel={getSublabel} />;
183
+ const getSublabelCallback = useCallback<Required<VisibilityTreeRendererProps>["getSublabel"]>((node) => <>Sublabel - {node.label}</>, []);
184
+ return <VisibilityTreeRenderer {...props} getLabel={getLabelCallback} getSublabel={getSublabelCallback} />;
184
185
  }
185
186
 
186
187
  interface CustomModelsTreeProps {
@@ -11,21 +11,26 @@ export declare class CategoriesTreeIdsCache {
11
11
  private _definitionContainersInfo;
12
12
  private _modelsCategoriesInfo;
13
13
  private _subCategoriesInfo;
14
+ private _elementModelsCategories;
14
15
  private _categoryClass;
15
16
  private _categoryElementClass;
17
+ private _categoryModelClass;
16
18
  private _isDefinitionContainerSupported;
17
19
  constructor(_queryExecutor: LimitingECSqlQueryExecutor, viewType: "3d" | "2d");
20
+ private queryElementModelCategories;
18
21
  private queryCategories;
19
22
  private queryIsDefinitionContainersSupported;
20
23
  private queryDefinitionContainers;
21
24
  private queryVisibleSubCategories;
22
25
  private getModelsCategoriesInfo;
26
+ private getElementModelsCategories;
23
27
  private getSubCategoriesInfo;
24
28
  private getDefinitionContainersInfo;
25
29
  getDirectChildDefinitionContainersAndCategories(parentDefinitionContainerIds: Id64Array): Promise<{
26
30
  categories: CategoryInfo[];
27
31
  definitionContainers: Id64Array;
28
32
  }>;
33
+ getCategoriesElementModels(categoryIds: Id64Array): Promise<Map<Id64String, Id64Array>>;
29
34
  getAllContainedCategories(definitionContainerIds: Id64Array): Promise<Id64Array>;
30
35
  getInstanceKeyPaths(props: {
31
36
  categoryId: Id64String;
@@ -49,6 +54,7 @@ export declare class CategoriesTreeIdsCache {
49
54
  export declare function getClassesByView(viewType: "2d" | "3d"): {
50
55
  categoryClass: string;
51
56
  categoryElementClass: string;
57
+ categoryModelClass: string;
52
58
  };
53
59
  export {};
54
60
  //# sourceMappingURL=CategoriesTreeIdsCache.d.ts.map
@@ -10,9 +10,22 @@ const ClassNameDefinitions_js_1 = require("./ClassNameDefinitions.js");
10
10
  class CategoriesTreeIdsCache {
11
11
  constructor(_queryExecutor, viewType) {
12
12
  this._queryExecutor = _queryExecutor;
13
- const { categoryClass, categoryElementClass } = getClassesByView(viewType);
13
+ const { categoryClass, categoryElementClass, categoryModelClass } = getClassesByView(viewType);
14
14
  this._categoryClass = categoryClass;
15
15
  this._categoryElementClass = categoryElementClass;
16
+ this._categoryModelClass = categoryModelClass;
17
+ }
18
+ async *queryElementModelCategories() {
19
+ const query = `
20
+ SELECT this.Model.Id modelId, this.Category.Id categoryId
21
+ FROM ${this._categoryModelClass} m
22
+ JOIN ${this._categoryElementClass} this ON m.ECInstanceId = this.Model.Id
23
+ WHERE m.IsPrivate = false
24
+ GROUP BY modelId, categoryId
25
+ `;
26
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: "tree-widget/categories-tree/element-models-and-categories-query" })) {
27
+ yield { modelId: row.modelId, categoryId: row.categoryId };
28
+ }
16
29
  }
17
30
  async *queryCategories() {
18
31
  const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();
@@ -73,7 +86,7 @@ class CategoriesTreeIdsCache {
73
86
  FROM
74
87
  ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} dc
75
88
  WHERE
76
- dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate)
89
+ dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = c.ECInstanceId))
77
90
  AND NOT dc.IsPrivate
78
91
 
79
92
  UNION ALL
@@ -126,6 +139,21 @@ class CategoriesTreeIdsCache {
126
139
  })();
127
140
  return this._modelsCategoriesInfo;
128
141
  }
142
+ async getElementModelsCategories() {
143
+ this._elementModelsCategories ??= (async () => {
144
+ const elementModelsCategories = new Map();
145
+ for await (const queriedCategory of this.queryElementModelCategories()) {
146
+ let modelEntry = elementModelsCategories.get(queriedCategory.modelId);
147
+ if (modelEntry === undefined) {
148
+ modelEntry = new Set();
149
+ elementModelsCategories.set(queriedCategory.modelId, modelEntry);
150
+ }
151
+ modelEntry.add(queriedCategory.categoryId);
152
+ }
153
+ return elementModelsCategories;
154
+ })();
155
+ return this._elementModelsCategories;
156
+ }
129
157
  async getSubCategoriesInfo() {
130
158
  this._subCategoriesInfo ??= (async () => {
131
159
  const allSubCategories = new Map();
@@ -186,6 +214,23 @@ class CategoriesTreeIdsCache {
186
214
  });
187
215
  return result;
188
216
  }
217
+ async getCategoriesElementModels(categoryIds) {
218
+ const elementModelsCategories = await this.getElementModelsCategories();
219
+ const result = new Map();
220
+ for (const categoryId of categoryIds) {
221
+ for (const [modelId, categories] of elementModelsCategories) {
222
+ if (categories.has(categoryId)) {
223
+ let categoryModels = result.get(categoryId);
224
+ if (!categoryModels) {
225
+ categoryModels = new Array();
226
+ result.set(categoryId, categoryModels);
227
+ }
228
+ categoryModels.push(modelId);
229
+ }
230
+ }
231
+ }
232
+ return result;
233
+ }
189
234
  async getAllContainedCategories(definitionContainerIds) {
190
235
  const result = new Array();
191
236
  const definitionContainersInfo = await this.getDefinitionContainersInfo();
@@ -278,8 +323,8 @@ exports.CategoriesTreeIdsCache = CategoriesTreeIdsCache;
278
323
  /** @internal */
279
324
  function getClassesByView(viewType) {
280
325
  return viewType === "2d"
281
- ? { categoryClass: "BisCore.DrawingCategory", categoryElementClass: "BisCore.GeometricElement2d" }
282
- : { categoryClass: "BisCore.SpatialCategory", categoryElementClass: "BisCore.GeometricElement3d" };
326
+ ? { categoryClass: "BisCore.DrawingCategory", categoryElementClass: "BisCore.GeometricElement2d", categoryModelClass: "BisCore.GeometricModel2d" }
327
+ : { categoryClass: "BisCore.SpatialCategory", categoryElementClass: "BisCore.GeometricElement3d", categoryModelClass: "BisCore.GeometricModel3d" };
283
328
  }
284
329
  exports.getClassesByView = getClassesByView;
285
330
  //# sourceMappingURL=CategoriesTreeIdsCache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CategoriesTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,uEAA2F;AA2B3F,gBAAgB;AAChB,MAAa,sBAAsB;IAQjC,YACU,cAA0C,EAClD,QAAqB;QADb,mBAAc,GAAd,cAAc,CAA4B;QAGlD,MAAM,EAAE,aAAa,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC3E,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,CAAC;IACpD,CAAC;IAEO,KAAK,CAAC,CAAC,eAAe;QAM5B,MAAM,8BAA8B,GAAG,MAAM,IAAI,CAAC,iCAAiC,EAAE,CAAC;QACtF,MAAM,eAAe,GAAG;;;;;UAMlB,8BAA8B;YAC5B,CAAC,CAAC;gEACkD,oDAA0B;;;cAG5E;YACF,CAAC,CAAC,OACN;;UAEE,IAAI,CAAC,cAAc;eACd,4CAAkB;;;;;oCAKG,IAAI,CAAC,qBAAqB;;KAEzD,CAAC;QACF,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE;YAClJ,MAAM,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,+BAA+B,EAAE,GAAG,CAAC,+BAA+B,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC;SAC9I;IACH,CAAC;IAEO,KAAK,C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,CAAC,CAAC;aAChE;SACF;QAED,KAAK,MAAM,CAAC,qBAAqB,EAAE,uBAAuB,CAAC,IAAI,wBAAwB,EAAE;YACvF,IAAI,CAAC,uBAAuB,CAAC,+BAA+B,EAAE;gBAC5D,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;aACzD;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,UAAsB;QAClD,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAG,IAAI,KAAK,EAAc,CAAC;QACvC,KAAK,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,IAAI,iBAAiB,EAAE;YAChE,IAAI,eAAe,CAAC,UAAU,KAAK,UAAU,EAAE;gBAC7C,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aAC5B;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,iCAAiC;QAC5C,IAAI,CAAC,+BAA+B,KAAK,IAAI,CAAC,oCAAoC,EAAE,CAAC;QACrF,OAAO,IAAI,CAAC,+BAA+B,CAAC;IAC9C,CAAC;CACF;AAlUD,wDAkUC;AAED,gBAAgB;AAChB,SAAgB,gBAAgB,CAAC,QAAqB;IACpD,OAAO,QAAQ,KAAK,IAAI;QACtB,CAAC,CAAC,EAAE,aAAa,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE;QAClG,CAAC,CAAC,EAAE,aAAa,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,CAAC;AACvG,CAAC;AAJD,4CAIC","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 { DEFINITION_CONTAINER_CLASS, SUB_CATEGORY_CLASS } from \"./ClassNameDefinitions.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\n\ninterface DefinitionContainerInfo {\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCategories: CategoryInfo[];\n childDefinitionContainers: Id64Array;\n}\n\ninterface CategoriesInfo {\n childCategories: CategoryInfo[];\n parentDefinitionContainerExists: boolean;\n}\n\ninterface CategoryInfo {\n id: Id64String;\n childCount: number;\n}\n\ninterface SubCategoryInfo {\n categoryId: Id64String;\n}\n\n/** @internal */\nexport class CategoriesTreeIdsCache {\n private _definitionContainersInfo: Promise<Map<Id64String, DefinitionContainerInfo>> | undefined;\n private _modelsCategoriesInfo: Promise<Map<Id64String, CategoriesInfo>> | undefined;\n private _subCategoriesInfo: Promise<Map<Id64String, SubCategoryInfo>> | undefined;\n private _categoryClass: string;\n private _categoryElementClass: string;\n private _isDefinitionContainerSupported: Promise<boolean> | undefined;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n viewType: \"3d\" | \"2d\",\n ) {\n const { categoryClass, categoryElementClass } = getClassesByView(viewType);\n this._categoryClass = categoryClass;\n this._categoryElementClass = categoryElementClass;\n }\n\n private async *queryCategories(): AsyncIterableIterator<{\n id: Id64String;\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCount: number;\n }> {\n const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();\n const categoriesQuery = `\n SELECT\n this.ECInstanceId id,\n COUNT(sc.ECInstanceId) childCount,\n this.Model.Id modelId,\n ${\n isDefinitionContainerSupported\n ? `\n IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${DEFINITION_CONTAINER_CLASS} dc),\n true,\n false\n )`\n : \"false\"\n } parentDefinitionContainerExists\n FROM\n ${this._categoryClass} this\n JOIN ${SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId\n JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id\n WHERE\n NOT this.IsPrivate\n AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))\n AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)\n GROUP BY this.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId, parentDefinitionContainerExists: row.parentDefinitionContainerExists, childCount: row.childCount };\n }\n }\n\n private async queryIsDefinitionContainersSupported(): Promise<boolean> {\n const query = `\n SELECT\n 1\n FROM\n ECDbMeta.ECSchemaDef s\n JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId\n WHERE\n s.Name = 'BisCore'\n AND c.Name = 'DefinitionContainer'\n `;\n\n for await (const _row of this._queryExecutor.createQueryReader({ ecsql: query })) {\n return true;\n }\n return false;\n }\n\n private async *queryDefinitionContainers(): AsyncIterableIterator<{ id: Id64String; modelId: Id64String }> {\n // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:\n // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}\n // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId\n // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId\n const DEFINITION_CONTAINERS_CTE = \"DefinitionContainers\";\n const ctes = [\n `\n ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId) AS (\n SELECT\n dc.ECInstanceId,\n dc.Model.Id\n FROM\n ${DEFINITION_CONTAINER_CLASS} dc\n WHERE\n dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate)\n AND NOT dc.IsPrivate\n\n UNION ALL\n\n SELECT\n pdc.ECInstanceId,\n pdc.Model.Id\n FROM\n ${DEFINITION_CONTAINERS_CTE} cdc\n JOIN ${DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId\n WHERE\n NOT pdc.IsPrivate\n )\n `,\n ];\n const definitionsQuery = `\n SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId };\n }\n }\n\n private async *queryVisibleSubCategories(categoriesInfo: Id64Array): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const definitionsQuery = `\n SELECT\n sc.ECInstanceId id,\n sc.Parent.Id categoryId\n FROM\n ${SUB_CATEGORY_CLASS} sc\n WHERE\n NOT sc.IsPrivate\n AND sc.Parent.Id IN (${categoriesInfo.join(\",\")})\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.categoryId };\n }\n }\n\n private async getModelsCategoriesInfo() {\n this._modelsCategoriesInfo ??= (async () => {\n const allModelsCategories = new Map<Id64String, CategoriesInfo>();\n for await (const queriedCategory of this.queryCategories()) {\n let modelCategories = allModelsCategories.get(queriedCategory.modelId);\n if (modelCategories === undefined) {\n modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };\n allModelsCategories.set(queriedCategory.modelId, modelCategories);\n }\n modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount });\n }\n return allModelsCategories;\n })();\n return this._modelsCategoriesInfo;\n }\n\n private async getSubCategoriesInfo() {\n this._subCategoriesInfo ??= (async () => {\n const allSubCategories = new Map<Id64String, SubCategoryInfo>();\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n const categoriesWithMoreThanOneSubCategory = new Array<Id64String>();\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n categoriesWithMoreThanOneSubCategory.push(\n ...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id),\n );\n }\n\n if (categoriesWithMoreThanOneSubCategory.length === 0) {\n return allSubCategories;\n }\n\n for await (const queriedSubCategory of this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory)) {\n allSubCategories.set(queriedSubCategory.id, { categoryId: queriedSubCategory.parentId });\n }\n return allSubCategories;\n })();\n return this._subCategoriesInfo;\n }\n\n private async getDefinitionContainersInfo() {\n this._definitionContainersInfo ??= (async () => {\n const definitionContainersInfo = new Map<Id64String, DefinitionContainerInfo>();\n const [isDefinitionContainerSupported, modelsCategoriesInfo] = await Promise.all([\n this.getIsDefinitionContainerSupported(),\n this.getModelsCategoriesInfo(),\n ]);\n if (!isDefinitionContainerSupported || modelsCategoriesInfo.size === 0) {\n return definitionContainersInfo;\n }\n\n for await (const queriedDefinitionContainer of this.queryDefinitionContainers()) {\n const modelCategoriesInfo = modelsCategoriesInfo.get(queriedDefinitionContainer.id);\n\n definitionContainersInfo.set(queriedDefinitionContainer.id, {\n childCategories: modelCategoriesInfo?.childCategories ?? [],\n modelId: queriedDefinitionContainer.modelId,\n childDefinitionContainers: [],\n parentDefinitionContainerExists: false,\n });\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);\n if (parentDefinitionContainer !== undefined) {\n parentDefinitionContainer.childDefinitionContainers.push(definitionContainerId);\n definitionContainerInfo.parentDefinitionContainerExists = true;\n }\n }\n\n return definitionContainersInfo;\n })();\n return this._definitionContainersInfo;\n }\n\n public async getDirectChildDefinitionContainersAndCategories(\n parentDefinitionContainerIds: Id64Array,\n ): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n\n parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {\n const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);\n if (parentDefinitionContainerInfo !== undefined) {\n result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainers);\n result.categories.push(...parentDefinitionContainerInfo.childCategories);\n }\n });\n return result;\n }\n\n public async getAllContainedCategories(definitionContainerIds: Id64Array): Promise<Id64Array> {\n const result = new Array<Id64String>();\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const indirectCategories = await Promise.all(\n definitionContainerIds.map(async (definitionContainerId) => {\n const definitionContainerInfo = definitionContainersInfo.get(definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n result.push(...definitionContainerInfo.childCategories.map((category) => category.id));\n return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainers);\n }),\n );\n for (const categories of indirectCategories) {\n result.push(...categories);\n }\n\n return result;\n }\n\n public async getInstanceKeyPaths(\n props: { categoryId: Id64String } | { definitionContainerId: Id64String } | { subCategoryId: Id64String },\n ): Promise<InstanceKey[]> {\n if (\"subCategoryId\" in props) {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const subCategoryInfo = subCategoriesInfo.get(props.subCategoryId);\n if (subCategoryInfo === undefined) {\n return [];\n }\n return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: SUB_CATEGORY_CLASS }];\n }\n\n if (\"categoryId\" in props) {\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {\n if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n return [{ id: props.categoryId, className: this._categoryClass }];\n }\n\n return [...(await this.getInstanceKeyPaths({ definitionContainerId: modelId })), { id: props.categoryId, className: this._categoryClass }];\n }\n }\n return [];\n }\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n return [{ id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS }];\n }\n\n return [\n ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),\n { id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS },\n ];\n }\n\n public async getAllDefinitionContainersAndCategories(): Promise<{ categories: Id64Array; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array<Id64String>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n result.categories.push(...modelCategoriesInfo.childCategories.map((childCategory) => childCategory.id));\n }\n\n return result;\n }\n\n public async getRootDefinitionContainersAndCategories(): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n result.categories.push(...modelCategoriesInfo.childCategories);\n }\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n result.definitionContainers.push(definitionContainerId);\n }\n }\n return result;\n }\n\n public async getSubCategories(categoryId: Id64String): Promise<Id64Array> {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const result = new Array<Id64String>();\n for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {\n if (subCategoryInfo.categoryId === categoryId) {\n result.push(subCategoryId);\n }\n }\n return result;\n }\n\n public async getIsDefinitionContainerSupported(): Promise<boolean> {\n this._isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported();\n return this._isDefinitionContainerSupported;\n }\n}\n\n/** @internal */\nexport function getClassesByView(viewType: \"2d\" | \"3d\") {\n return viewType === \"2d\"\n ? { categoryClass: \"BisCore.DrawingCategory\", categoryElementClass: \"BisCore.GeometricElement2d\" }\n : { categoryClass: \"BisCore.SpatialCategory\", categoryElementClass: \"BisCore.GeometricElement3d\" };\n}\n"]}
1
+ {"version":3,"file":"CategoriesTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,uEAA2F;AA2B3F,gBAAgB;AAChB,MAAa,sBAAsB;IAUjC,YACU,cAA0C,EAClD,QAAqB;QADb,mBAAc,GAAd,cAAc,CAA4B;QAGlD,MAAM,EAAE,aAAa,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC/F,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,CAAC;QAClD,IAAI,CAAC,mBAAmB,GAAG,kBAAkB,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,CAAC,2BAA2B;QAIxC,MAAM,KAAK,GAAG;;aAEL,IAAI,CAAC,mBAAmB;aACxB,IAAI,CAAC,qBAAqB;;;KAGlC,CAAC;QACF,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAC3D,EAAE,KAAK,EAAE,KAAK,EAAE,EAChB,EAAE,SAAS,EAAE,oBAAoB,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,iEAAiE,EAAE,CAC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C5D,MAAM,MAAM,GAAG,IAAI,KAAK,EAAc,CAAC;QACvC,KAAK,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,IAAI,iBAAiB,EAAE;YAChE,IAAI,eAAe,CAAC,UAAU,KAAK,UAAU,EAAE;gBAC7C,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aAC5B;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,iCAAiC;QAC5C,IAAI,CAAC,+BAA+B,KAAK,IAAI,CAAC,oCAAoC,EAAE,CAAC;QACrF,OAAO,IAAI,CAAC,+BAA+B,CAAC;IAC9C,CAAC;CACF;AA1XD,wDA0XC;AAED,gBAAgB;AAChB,SAAgB,gBAAgB,CAAC,QAAqB;IACpD,OAAO,QAAQ,KAAK,IAAI;QACtB,CAAC,CAAC,EAAE,aAAa,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,0BAA0B,EAAE;QAClJ,CAAC,CAAC,EAAE,aAAa,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,CAAC;AACvJ,CAAC;AAJD,4CAIC","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 { DEFINITION_CONTAINER_CLASS, SUB_CATEGORY_CLASS } from \"./ClassNameDefinitions.js\";\n\nimport type { Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\n\ninterface DefinitionContainerInfo {\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCategories: CategoryInfo[];\n childDefinitionContainers: Id64Array;\n}\n\ninterface CategoriesInfo {\n childCategories: CategoryInfo[];\n parentDefinitionContainerExists: boolean;\n}\n\ninterface CategoryInfo {\n id: Id64String;\n childCount: number;\n}\n\ninterface SubCategoryInfo {\n categoryId: Id64String;\n}\n\n/** @internal */\nexport class CategoriesTreeIdsCache {\n private _definitionContainersInfo: Promise<Map<Id64String, DefinitionContainerInfo>> | undefined;\n private _modelsCategoriesInfo: Promise<Map<Id64String, CategoriesInfo>> | undefined;\n private _subCategoriesInfo: Promise<Map<Id64String, SubCategoryInfo>> | undefined;\n private _elementModelsCategories: Promise<Map<Id64String, Id64Set>> | undefined;\n private _categoryClass: string;\n private _categoryElementClass: string;\n private _categoryModelClass: string;\n private _isDefinitionContainerSupported: Promise<boolean> | undefined;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n viewType: \"3d\" | \"2d\",\n ) {\n const { categoryClass, categoryElementClass, categoryModelClass } = getClassesByView(viewType);\n this._categoryClass = categoryClass;\n this._categoryElementClass = categoryElementClass;\n this._categoryModelClass = categoryModelClass;\n }\n\n private async *queryElementModelCategories(): AsyncIterableIterator<{\n modelId: Id64String;\n categoryId: Id64String;\n }> {\n const query = `\n SELECT this.Model.Id modelId, this.Category.Id categoryId\n FROM ${this._categoryModelClass} m\n JOIN ${this._categoryElementClass} this ON m.ECInstanceId = this.Model.Id\n WHERE m.IsPrivate = false\n GROUP BY modelId, categoryId\n `;\n for await (const row of this._queryExecutor.createQueryReader(\n { ecsql: query },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: \"tree-widget/categories-tree/element-models-and-categories-query\" },\n )) {\n yield { modelId: row.modelId, categoryId: row.categoryId };\n }\n }\n\n private async *queryCategories(): AsyncIterableIterator<{\n id: Id64String;\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCount: number;\n }> {\n const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();\n const categoriesQuery = `\n SELECT\n this.ECInstanceId id,\n COUNT(sc.ECInstanceId) childCount,\n this.Model.Id modelId,\n ${\n isDefinitionContainerSupported\n ? `\n IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${DEFINITION_CONTAINER_CLASS} dc),\n true,\n false\n )`\n : \"false\"\n } parentDefinitionContainerExists\n FROM\n ${this._categoryClass} this\n JOIN ${SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId\n JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id\n WHERE\n NOT this.IsPrivate\n AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))\n AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)\n GROUP BY this.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId, parentDefinitionContainerExists: row.parentDefinitionContainerExists, childCount: row.childCount };\n }\n }\n\n private async queryIsDefinitionContainersSupported(): Promise<boolean> {\n const query = `\n SELECT\n 1\n FROM\n ECDbMeta.ECSchemaDef s\n JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId\n WHERE\n s.Name = 'BisCore'\n AND c.Name = 'DefinitionContainer'\n `;\n\n for await (const _row of this._queryExecutor.createQueryReader({ ecsql: query })) {\n return true;\n }\n return false;\n }\n\n private async *queryDefinitionContainers(): AsyncIterableIterator<{ id: Id64String; modelId: Id64String }> {\n // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:\n // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}\n // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId\n // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId\n const DEFINITION_CONTAINERS_CTE = \"DefinitionContainers\";\n const ctes = [\n `\n ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId) AS (\n SELECT\n dc.ECInstanceId,\n dc.Model.Id\n FROM\n ${DEFINITION_CONTAINER_CLASS} dc\n WHERE\n dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = c.ECInstanceId))\n AND NOT dc.IsPrivate\n\n UNION ALL\n\n SELECT\n pdc.ECInstanceId,\n pdc.Model.Id\n FROM\n ${DEFINITION_CONTAINERS_CTE} cdc\n JOIN ${DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId\n WHERE\n NOT pdc.IsPrivate\n )\n `,\n ];\n const definitionsQuery = `\n SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId };\n }\n }\n\n private async *queryVisibleSubCategories(categoriesInfo: Id64Array): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const definitionsQuery = `\n SELECT\n sc.ECInstanceId id,\n sc.Parent.Id categoryId\n FROM\n ${SUB_CATEGORY_CLASS} sc\n WHERE\n NOT sc.IsPrivate\n AND sc.Parent.Id IN (${categoriesInfo.join(\",\")})\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.categoryId };\n }\n }\n\n private async getModelsCategoriesInfo() {\n this._modelsCategoriesInfo ??= (async () => {\n const allModelsCategories = new Map<Id64String, CategoriesInfo>();\n for await (const queriedCategory of this.queryCategories()) {\n let modelCategories = allModelsCategories.get(queriedCategory.modelId);\n if (modelCategories === undefined) {\n modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };\n allModelsCategories.set(queriedCategory.modelId, modelCategories);\n }\n modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount });\n }\n return allModelsCategories;\n })();\n return this._modelsCategoriesInfo;\n }\n\n private async getElementModelsCategories() {\n this._elementModelsCategories ??= (async () => {\n const elementModelsCategories = new Map<Id64String, Id64Set>();\n for await (const queriedCategory of this.queryElementModelCategories()) {\n let modelEntry = elementModelsCategories.get(queriedCategory.modelId);\n if (modelEntry === undefined) {\n modelEntry = new Set();\n elementModelsCategories.set(queriedCategory.modelId, modelEntry);\n }\n modelEntry.add(queriedCategory.categoryId);\n }\n return elementModelsCategories;\n })();\n return this._elementModelsCategories;\n }\n\n private async getSubCategoriesInfo() {\n this._subCategoriesInfo ??= (async () => {\n const allSubCategories = new Map<Id64String, SubCategoryInfo>();\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n const categoriesWithMoreThanOneSubCategory = new Array<Id64String>();\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n categoriesWithMoreThanOneSubCategory.push(\n ...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id),\n );\n }\n\n if (categoriesWithMoreThanOneSubCategory.length === 0) {\n return allSubCategories;\n }\n\n for await (const queriedSubCategory of this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory)) {\n allSubCategories.set(queriedSubCategory.id, { categoryId: queriedSubCategory.parentId });\n }\n return allSubCategories;\n })();\n return this._subCategoriesInfo;\n }\n\n private async getDefinitionContainersInfo() {\n this._definitionContainersInfo ??= (async () => {\n const definitionContainersInfo = new Map<Id64String, DefinitionContainerInfo>();\n const [isDefinitionContainerSupported, modelsCategoriesInfo] = await Promise.all([\n this.getIsDefinitionContainerSupported(),\n this.getModelsCategoriesInfo(),\n ]);\n if (!isDefinitionContainerSupported || modelsCategoriesInfo.size === 0) {\n return definitionContainersInfo;\n }\n\n for await (const queriedDefinitionContainer of this.queryDefinitionContainers()) {\n const modelCategoriesInfo = modelsCategoriesInfo.get(queriedDefinitionContainer.id);\n\n definitionContainersInfo.set(queriedDefinitionContainer.id, {\n childCategories: modelCategoriesInfo?.childCategories ?? [],\n modelId: queriedDefinitionContainer.modelId,\n childDefinitionContainers: [],\n parentDefinitionContainerExists: false,\n });\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);\n if (parentDefinitionContainer !== undefined) {\n parentDefinitionContainer.childDefinitionContainers.push(definitionContainerId);\n definitionContainerInfo.parentDefinitionContainerExists = true;\n }\n }\n\n return definitionContainersInfo;\n })();\n return this._definitionContainersInfo;\n }\n\n public async getDirectChildDefinitionContainersAndCategories(\n parentDefinitionContainerIds: Id64Array,\n ): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n\n parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {\n const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);\n if (parentDefinitionContainerInfo !== undefined) {\n result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainers);\n result.categories.push(...parentDefinitionContainerInfo.childCategories);\n }\n });\n return result;\n }\n\n public async getCategoriesElementModels(categoryIds: Id64Array): Promise<Map<Id64String, Id64Array>> {\n const elementModelsCategories = await this.getElementModelsCategories();\n const result = new Map<Id64String, Id64Array>();\n for (const categoryId of categoryIds) {\n for (const [modelId, categories] of elementModelsCategories) {\n if (categories.has(categoryId)) {\n let categoryModels = result.get(categoryId);\n if (!categoryModels) {\n categoryModels = new Array<Id64String>();\n result.set(categoryId, categoryModels);\n }\n categoryModels.push(modelId);\n }\n }\n }\n return result;\n }\n\n public async getAllContainedCategories(definitionContainerIds: Id64Array): Promise<Id64Array> {\n const result = new Array<Id64String>();\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const indirectCategories = await Promise.all(\n definitionContainerIds.map(async (definitionContainerId) => {\n const definitionContainerInfo = definitionContainersInfo.get(definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n result.push(...definitionContainerInfo.childCategories.map((category) => category.id));\n return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainers);\n }),\n );\n for (const categories of indirectCategories) {\n result.push(...categories);\n }\n\n return result;\n }\n\n public async getInstanceKeyPaths(\n props: { categoryId: Id64String } | { definitionContainerId: Id64String } | { subCategoryId: Id64String },\n ): Promise<InstanceKey[]> {\n if (\"subCategoryId\" in props) {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const subCategoryInfo = subCategoriesInfo.get(props.subCategoryId);\n if (subCategoryInfo === undefined) {\n return [];\n }\n return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: SUB_CATEGORY_CLASS }];\n }\n\n if (\"categoryId\" in props) {\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {\n if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n return [{ id: props.categoryId, className: this._categoryClass }];\n }\n\n return [...(await this.getInstanceKeyPaths({ definitionContainerId: modelId })), { id: props.categoryId, className: this._categoryClass }];\n }\n }\n return [];\n }\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n return [{ id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS }];\n }\n\n return [\n ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),\n { id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS },\n ];\n }\n\n public async getAllDefinitionContainersAndCategories(): Promise<{ categories: Id64Array; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array<Id64String>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n result.categories.push(...modelCategoriesInfo.childCategories.map((childCategory) => childCategory.id));\n }\n\n return result;\n }\n\n public async getRootDefinitionContainersAndCategories(): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n result.categories.push(...modelCategoriesInfo.childCategories);\n }\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n result.definitionContainers.push(definitionContainerId);\n }\n }\n return result;\n }\n\n public async getSubCategories(categoryId: Id64String): Promise<Id64Array> {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const result = new Array<Id64String>();\n for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {\n if (subCategoryInfo.categoryId === categoryId) {\n result.push(subCategoryId);\n }\n }\n return result;\n }\n\n public async getIsDefinitionContainerSupported(): Promise<boolean> {\n this._isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported();\n return this._isDefinitionContainerSupported;\n }\n}\n\n/** @internal */\nexport function getClassesByView(viewType: \"2d\" | \"3d\") {\n return viewType === \"2d\"\n ? { categoryClass: \"BisCore.DrawingCategory\", categoryElementClass: \"BisCore.GeometricElement2d\", categoryModelClass: \"BisCore.GeometricModel2d\" }\n : { categoryClass: \"BisCore.SpatialCategory\", categoryElementClass: \"BisCore.GeometricElement3d\", categoryModelClass: \"BisCore.GeometricModel3d\" };\n}\n"]}
@@ -20,15 +20,17 @@ export declare class CategoriesVisibilityHandler implements HierarchyVisibilityH
20
20
  /** Returns visibility status of the tree node. */
21
21
  getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus>;
22
22
  changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;
23
- private getSubCategoryVisibility;
23
+ private getSubCategoriesVisibility;
24
24
  private getDefinitionContainerVisibility;
25
25
  private getCategoriesVisibility;
26
- private getCategoryVisibilityFromOverrides;
26
+ private enableCategoriesElementModelsVisibility;
27
27
  private changeSubCategoryVisibility;
28
28
  private changeCategoryVisibility;
29
29
  private changeDefinitionContainerVisibility;
30
30
  private onDisplayStyleChanged;
31
31
  private onViewedCategoriesChanged;
32
+ private onViewedCategoriesPerModelChanged;
33
+ private onViewedModelsChanged;
32
34
  private onVisibilityChangeInternal;
33
35
  private static getInstanceIdsFromHierarchyNode;
34
36
  private changeCategoryState;
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.CategoriesVisibilityHandler = void 0;
8
8
  const core_bentley_1 = require("@itwin/core-bentley");
9
+ const core_frontend_1 = require("@itwin/core-frontend");
9
10
  const presentation_hierarchies_1 = require("@itwin/presentation-hierarchies");
10
11
  const CategoriesVisibilityUtils_js_1 = require("../../common/CategoriesVisibilityUtils.js");
11
12
  const Tooltip_js_1 = require("../../common/Tooltip.js");
@@ -14,18 +15,24 @@ const CategoriesTreeNode_js_1 = require("./CategoriesTreeNode.js");
14
15
  class CategoriesVisibilityHandler {
15
16
  constructor(props) {
16
17
  this.onVisibilityChange = new core_bentley_1.BeEvent();
17
- // eslint-disable-next-line @typescript-eslint/naming-convention
18
18
  this.onDisplayStyleChanged = () => {
19
19
  this.onVisibilityChangeInternal();
20
20
  };
21
- // eslint-disable-next-line @typescript-eslint/naming-convention
22
21
  this.onViewedCategoriesChanged = () => {
23
22
  this.onVisibilityChangeInternal();
24
23
  };
24
+ this.onViewedCategoriesPerModelChanged = () => {
25
+ this.onVisibilityChangeInternal();
26
+ };
27
+ this.onViewedModelsChanged = () => {
28
+ this.onVisibilityChangeInternal();
29
+ };
25
30
  this._idsCache = props.idsCache;
26
31
  this._viewport = props.viewport;
27
32
  this._viewport.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);
28
33
  this._viewport.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);
34
+ this._viewport.onViewedCategoriesPerModelChanged.addListener(this.onViewedCategoriesPerModelChanged);
35
+ this._viewport.onViewedModelsChanged.addListener(this.onViewedModelsChanged);
29
36
  }
30
37
  dispose() {
31
38
  this[Symbol.dispose]();
@@ -33,6 +40,8 @@ class CategoriesVisibilityHandler {
33
40
  [Symbol.dispose]() {
34
41
  this._viewport.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);
35
42
  this._viewport.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);
43
+ this._viewport.onViewedCategoriesPerModelChanged.removeListener(this.onViewedCategoriesPerModelChanged);
44
+ this._viewport.onViewedModelsChanged.removeListener(this.onViewedModelsChanged);
36
45
  clearTimeout(this._pendingVisibilityChange);
37
46
  }
38
47
  /** Returns visibility status of the tree node. */
@@ -41,7 +50,10 @@ class CategoriesVisibilityHandler {
41
50
  return { state: "hidden", isDisabled: true };
42
51
  }
43
52
  if (CategoriesTreeNode_js_1.CategoriesTreeNode.isSubCategoryNode(node)) {
44
- return (0, Tooltip_js_1.createVisibilityStatus)(this.getSubCategoryVisibility(node));
53
+ if (!node.extendedData?.categoryId) {
54
+ return { state: "hidden", isDisabled: true };
55
+ }
56
+ return (0, Tooltip_js_1.createVisibilityStatus)(await this.getSubCategoriesVisibility(CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node), node.extendedData.categoryId));
45
57
  }
46
58
  if (CategoriesTreeNode_js_1.CategoriesTreeNode.isCategoryNode(node)) {
47
59
  return (0, Tooltip_js_1.createVisibilityStatus)(await this.getCategoriesVisibility(CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node)));
@@ -56,7 +68,7 @@ class CategoriesVisibilityHandler {
56
68
  return;
57
69
  }
58
70
  if (CategoriesTreeNode_js_1.CategoriesTreeNode.isCategoryNode(node)) {
59
- return this.changeCategoryVisibility(node, on);
71
+ return this.changeCategoryVisibility(CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node), on);
60
72
  }
61
73
  if (CategoriesTreeNode_js_1.CategoriesTreeNode.isSubCategoryNode(node)) {
62
74
  return this.changeSubCategoryVisibility(node, on);
@@ -65,135 +77,118 @@ class CategoriesVisibilityHandler {
65
77
  return this.changeDefinitionContainerVisibility(node, on);
66
78
  }
67
79
  }
68
- getSubCategoryVisibility(node) {
69
- const parentCategoryId = node.extendedData?.categoryId;
70
- if (!parentCategoryId) {
71
- return "hidden";
80
+ async getSubCategoriesVisibility(subCategoryIds, parentCategoryId) {
81
+ let visibility = "unknown";
82
+ const categoryModels = [...(await this._idsCache.getCategoriesElementModels([parentCategoryId])).values()].flat();
83
+ let nonDefaultModelDisplayStatesCount = 0;
84
+ for (const modelId of categoryModels) {
85
+ if (!this._viewport.view.viewsModel(modelId)) {
86
+ if (visibility === "visible") {
87
+ return "partial";
88
+ }
89
+ visibility = "hidden";
90
+ ++nonDefaultModelDisplayStatesCount;
91
+ continue;
92
+ }
93
+ const override = this._viewport.perModelCategoryVisibility.getOverride(modelId, parentCategoryId);
94
+ if (override === core_frontend_1.PerModelCategoryVisibility.Override.Show) {
95
+ if (visibility === "hidden") {
96
+ return "partial";
97
+ }
98
+ visibility = "visible";
99
+ ++nonDefaultModelDisplayStatesCount;
100
+ continue;
101
+ }
102
+ if (override === core_frontend_1.PerModelCategoryVisibility.Override.Hide) {
103
+ if (visibility === "visible") {
104
+ return "partial";
105
+ }
106
+ visibility = "hidden";
107
+ ++nonDefaultModelDisplayStatesCount;
108
+ continue;
109
+ }
72
110
  }
73
- const categoryOverrideResult = this.getCategoryVisibilityFromOverrides(parentCategoryId);
74
- if (categoryOverrideResult === "hidden" || categoryOverrideResult === "visible") {
75
- return categoryOverrideResult;
111
+ if (categoryModels.length > 0 && nonDefaultModelDisplayStatesCount === categoryModels.length) {
112
+ (0, core_bentley_1.assert)(visibility === "visible" || visibility === "hidden");
113
+ return visibility;
76
114
  }
77
115
  if (!this._viewport.view.viewsCategory(parentCategoryId)) {
78
- return "hidden";
116
+ return visibility === "visible" ? "partial" : "hidden";
79
117
  }
80
- const subCategoryIds = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);
81
- let visibleCount = 0;
82
- let hiddenCount = 0;
83
- for (const subCategoryId of subCategoryIds) {
84
- const isVisible = this._viewport.isSubCategoryVisible(subCategoryId);
85
- if (isVisible) {
86
- ++visibleCount;
87
- }
88
- else {
89
- ++hiddenCount;
90
- }
91
- if (visibleCount > 0 && hiddenCount > 0) {
118
+ if (subCategoryIds.length === 0) {
119
+ if (visibility === "hidden") {
92
120
  return "partial";
93
121
  }
122
+ return "visible";
94
123
  }
95
- return visibleCount > 0 ? "visible" : "hidden";
96
- }
97
- async getDefinitionContainerVisibility(node) {
98
- const childrenResult = await this._idsCache.getAllContainedCategories(CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node));
99
- let hiddenCount = 0;
100
- let visibleCount = 0;
101
- for (const categoryId of childrenResult) {
102
- const categoryVisibility = await this.getCategoriesVisibility([categoryId]);
103
- if (categoryVisibility === "partial") {
124
+ for (const subCategoryId of subCategoryIds) {
125
+ const isSubCategoryVisible = this._viewport.isSubCategoryVisible(subCategoryId);
126
+ if (isSubCategoryVisible && visibility === "hidden") {
104
127
  return "partial";
105
128
  }
106
- if (categoryVisibility === "hidden") {
107
- ++hiddenCount;
108
- }
109
- else {
110
- ++visibleCount;
111
- }
112
- if (hiddenCount > 0 && visibleCount > 0) {
129
+ if (!isSubCategoryVisible && visibility === "visible") {
113
130
  return "partial";
114
131
  }
132
+ visibility = isSubCategoryVisible ? "visible" : "hidden";
115
133
  }
116
- return hiddenCount > 0 ? "hidden" : "visible";
134
+ (0, core_bentley_1.assert)(visibility === "visible" || visibility === "hidden");
135
+ return visibility;
136
+ }
137
+ async getDefinitionContainerVisibility(node) {
138
+ const categoryIds = await this._idsCache.getAllContainedCategories(CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node));
139
+ return this.getCategoriesVisibility(categoryIds);
117
140
  }
118
141
  async getCategoriesVisibility(categoryIds) {
119
- const overrideResult = this.getCategoryVisibilityFromOverrides(categoryIds);
120
- if (overrideResult !== "none") {
121
- return overrideResult;
122
- }
123
- let visibleCount = 0;
124
- let hiddenCount = 0;
125
- for (const categoryId of categoryIds) {
126
- const isVisible = this._viewport.view.viewsCategory(categoryId);
127
- if (isVisible) {
128
- ++visibleCount;
129
- }
130
- else {
131
- ++hiddenCount;
132
- }
133
- if (visibleCount > 0 && hiddenCount > 0) {
142
+ const subCategoriesVisibilities = await Promise.all(categoryIds.map(async (categoryId) => {
143
+ const subCategories = await this._idsCache.getSubCategories(categoryId);
144
+ return this.getSubCategoriesVisibility(subCategories, categoryId);
145
+ }));
146
+ let visibility = "unknown";
147
+ for (const subCategoriesVisibility of subCategoriesVisibilities) {
148
+ if (subCategoriesVisibility === "partial") {
134
149
  return "partial";
135
150
  }
136
- }
137
- if (hiddenCount > 0) {
138
- return "hidden";
139
- }
140
- const subCategories = (await Promise.all(categoryIds.map(async (id) => this._idsCache.getSubCategories(id)))).reduce((acc, val) => acc.concat(val), []);
141
- let visibleSubCategoryCount = 0;
142
- let hiddenSubCategoryCount = 0;
143
- for (const subCategory of subCategories) {
144
- const isVisible = this._viewport.isSubCategoryVisible(subCategory);
145
- if (isVisible) {
146
- ++visibleSubCategoryCount;
147
- }
148
- else {
149
- ++hiddenSubCategoryCount;
151
+ if (subCategoriesVisibility === "hidden" && visibility === "visible") {
152
+ return "partial";
150
153
  }
151
- if (hiddenSubCategoryCount > 0 && visibleSubCategoryCount > 0) {
154
+ if (subCategoriesVisibility === "visible" && visibility === "hidden") {
152
155
  return "partial";
153
156
  }
157
+ visibility = subCategoriesVisibility;
154
158
  }
155
- return hiddenSubCategoryCount > 0 ? "hidden" : "visible";
159
+ (0, core_bentley_1.assert)(visibility !== "unknown");
160
+ return visibility;
156
161
  }
157
- getCategoryVisibilityFromOverrides(categoryIds) {
158
- let showOverrides = 0;
159
- let hideOverrides = 0;
160
- for (const currentOverride of this._viewport.perModelCategoryVisibility) {
161
- if (categoryIds.includes(currentOverride.categoryId)) {
162
- if (currentOverride.visible) {
163
- ++showOverrides;
164
- }
165
- else {
166
- ++hideOverrides;
167
- }
168
- if (showOverrides > 0 && hideOverrides > 0) {
169
- return "partial";
170
- }
171
- }
162
+ async enableCategoriesElementModelsVisibility(categoryIds) {
163
+ const categoriesModelsMap = await this._idsCache.getCategoriesElementModels(categoryIds);
164
+ const modelIds = [...categoriesModelsMap.values()].flat();
165
+ const hiddenModels = modelIds.filter((modelId) => !this._viewport.view.viewsModel(modelId));
166
+ if (hiddenModels.length > 0) {
167
+ this._viewport.changeModelDisplay(hiddenModels, true);
172
168
  }
173
- if (showOverrides === 0 && hideOverrides === 0) {
174
- return "none";
175
- }
176
- return showOverrides > 0 ? "visible" : "hidden";
177
169
  }
178
170
  async changeSubCategoryVisibility(node, on) {
179
171
  const parentCategoryId = node.extendedData?.categoryId;
180
- // make sure parent category is enabled
172
+ // make sure parent category and models are enabled
181
173
  if (on && parentCategoryId) {
182
- await this.changeCategoryState([parentCategoryId], true, false);
174
+ await Promise.all([this.enableCategoriesElementModelsVisibility([parentCategoryId]), this.changeCategoryState([parentCategoryId], true, false)]);
183
175
  }
184
176
  const subCategoryIds = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);
185
177
  subCategoryIds.forEach((id) => {
186
178
  this.changeSubCategoryState(id, on);
187
179
  });
188
180
  }
189
- async changeCategoryVisibility(node, on) {
190
- const categoryIds = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);
181
+ async changeCategoryVisibility(categoryIds, on) {
182
+ // make sure models are enabled
183
+ if (on) {
184
+ await this.enableCategoriesElementModelsVisibility(categoryIds);
185
+ }
191
186
  return this.changeCategoryState(categoryIds, on, on);
192
187
  }
193
188
  async changeDefinitionContainerVisibility(node, on) {
194
189
  const definitionContainerId = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);
195
190
  const childCategories = await this._idsCache.getAllContainedCategories(definitionContainerId);
196
- return this.changeCategoryState(childCategories, on, on);
191
+ return this.changeCategoryVisibility(childCategories, on);
197
192
  }
198
193
  onVisibilityChangeInternal() {
199
194
  if (this._pendingVisibilityChange) {