@itwin/presentation-hierarchies 1.2.0 → 1.3.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +4 -3
  3. package/lib/cjs/hierarchies/HierarchyFiltering.d.ts +48 -3
  4. package/lib/cjs/hierarchies/HierarchyFiltering.d.ts.map +1 -1
  5. package/lib/cjs/hierarchies/HierarchyFiltering.js +137 -2
  6. package/lib/cjs/hierarchies/HierarchyFiltering.js.map +1 -1
  7. package/lib/cjs/hierarchies/HierarchyNode.d.ts +1 -0
  8. package/lib/cjs/hierarchies/HierarchyNode.d.ts.map +1 -1
  9. package/lib/cjs/hierarchies/HierarchyNode.js +3 -0
  10. package/lib/cjs/hierarchies/HierarchyNode.js.map +1 -1
  11. package/lib/cjs/hierarchies/HierarchyProvider.d.ts +43 -8
  12. package/lib/cjs/hierarchies/HierarchyProvider.d.ts.map +1 -1
  13. package/lib/cjs/hierarchies/HierarchyProvider.js.map +1 -1
  14. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.d.ts +3 -6
  15. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.d.ts.map +1 -1
  16. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.js +134 -181
  17. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.js.map +1 -1
  18. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.d.ts.map +1 -1
  19. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.js +11 -7
  20. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.js.map +1 -1
  21. package/lib/cjs/hierarchies/imodel/NodeSelectQueryFactory.d.ts.map +1 -1
  22. package/lib/cjs/hierarchies/imodel/NodeSelectQueryFactory.js.map +1 -1
  23. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts +1 -1
  24. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts.map +1 -1
  25. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.js +12 -0
  26. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.js.map +1 -1
  27. package/lib/cjs/package.json +1 -0
  28. package/lib/cjs/presentation-hierarchies.d.ts +1 -1
  29. package/lib/cjs/presentation-hierarchies.d.ts.map +1 -1
  30. package/lib/cjs/presentation-hierarchies.js +3 -2
  31. package/lib/cjs/presentation-hierarchies.js.map +1 -1
  32. package/lib/esm/hierarchies/HierarchyFiltering.d.ts +48 -3
  33. package/lib/esm/hierarchies/HierarchyFiltering.d.ts.map +1 -1
  34. package/lib/esm/hierarchies/HierarchyFiltering.js +136 -2
  35. package/lib/esm/hierarchies/HierarchyFiltering.js.map +1 -1
  36. package/lib/esm/hierarchies/HierarchyNode.d.ts +1 -0
  37. package/lib/esm/hierarchies/HierarchyNode.d.ts.map +1 -1
  38. package/lib/esm/hierarchies/HierarchyNode.js +3 -0
  39. package/lib/esm/hierarchies/HierarchyNode.js.map +1 -1
  40. package/lib/esm/hierarchies/HierarchyProvider.d.ts +43 -8
  41. package/lib/esm/hierarchies/HierarchyProvider.d.ts.map +1 -1
  42. package/lib/esm/hierarchies/HierarchyProvider.js.map +1 -1
  43. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.d.ts +3 -6
  44. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.d.ts.map +1 -1
  45. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.js +132 -180
  46. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.js.map +1 -1
  47. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.d.ts.map +1 -1
  48. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.js +11 -7
  49. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.js.map +1 -1
  50. package/lib/esm/hierarchies/imodel/NodeSelectQueryFactory.d.ts.map +1 -1
  51. package/lib/esm/hierarchies/imodel/NodeSelectQueryFactory.js.map +1 -1
  52. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts +1 -1
  53. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts.map +1 -1
  54. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.js +12 -0
  55. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.js.map +1 -1
  56. package/lib/esm/presentation-hierarchies.d.ts +1 -1
  57. package/lib/esm/presentation-hierarchies.d.ts.map +1 -1
  58. package/lib/esm/presentation-hierarchies.js +1 -1
  59. package/lib/esm/presentation-hierarchies.js.map +1 -1
  60. package/package.json +6 -6
@@ -18,18 +18,15 @@ export declare class FilteringHierarchyDefinition implements HierarchyDefinition
18
18
  private shouldExpandGroupingNode;
19
19
  get postProcessNode(): NodePostProcessor;
20
20
  get parseNode(): NodeParser;
21
- private getChildrenIdentifierPaths;
22
21
  defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition>;
23
22
  }
24
23
  /** @internal */
25
- export declare const ECSQL_COLUMN_NAME_HasFilterTargetAncestor = "HasFilterTargetAncestor";
26
- /** @internal */
27
24
  export declare const ECSQL_COLUMN_NAME_FilterECInstanceId = "FilterECInstanceId";
28
25
  /** @internal */
29
26
  export declare const ECSQL_COLUMN_NAME_FilterClassName = "FilterClassName";
30
27
  /** @internal */
31
- export declare function applyECInstanceIdsFilter(def: InstanceNodesQueryDefinition, matchingFilters: Array<{
32
- id: InstanceKey;
33
- }>, hasFilterTargetAncestor: boolean): InstanceNodesQueryDefinition;
28
+ export declare function applyECInstanceIdsFilter(def: InstanceNodesQueryDefinition, filteredInstanceKeys: InstanceKey[]): InstanceNodesQueryDefinition;
29
+ /** @internal */
30
+ export declare function applyECInstanceIdsSelector(def: InstanceNodesQueryDefinition): InstanceNodesQueryDefinition;
34
31
  export {};
35
32
  //# sourceMappingURL=FilteringHierarchyDefinition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FilteringHierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/FilteringHierarchyDefinition.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAyB,sBAAsB,EAAiC,MAAM,0BAA0B,CAAC;AAIxH,OAAO,EACL,yBAAyB,EAEzB,mBAAmB,EAEnB,wBAAwB,EAExB,4BAA4B,EAC5B,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAIxC,UAAU,iCAAiC;IACzC,YAAY,EAAE,yBAAyB,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,MAAM,EAAE,mBAAmB,CAAC;IAC5B,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;CAC/C;AAED,gBAAgB;AAChB,qBAAa,4BAA6B,YAAW,mBAAmB;IACtE,OAAO,CAAC,aAAa,CAAoD;IACzE,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,oBAAoB,CAA2B;gBAEpC,KAAK,EAAE,iCAAiC;IAM3D,IAAW,cAAc,IAAI,gBAAgB,CAS5C;IAED,OAAO,CAAC,wBAAwB;IA2ChC,IAAW,eAAe,IAAI,iBAAiB,CAS9C;IAED,IAAW,SAAS,IAAI,UAAU,CAqBjC;YAEa,0BAA0B;IA8C3B,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CA+DvG;AA4GD,gBAAgB;AAEhB,eAAO,MAAM,yCAAyC,4BAA4B,CAAC;AAEnF,gBAAgB;AAEhB,eAAO,MAAM,oCAAoC,uBAAuB,CAAC;AAEzE,gBAAgB;AAEhB,eAAO,MAAM,iCAAiC,oBAAoB,CAAC;AAenE,gBAAgB;AAChB,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,4BAA4B,EACjC,eAAe,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,WAAW,CAAA;CAAE,CAAC,EAC3C,uBAAuB,EAAE,OAAO,GAC/B,4BAA4B,CAoC9B"}
1
+ {"version":3,"file":"FilteringHierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/FilteringHierarchyDefinition.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAkC,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAIlG,OAAO,EACL,yBAAyB,EAEzB,mBAAmB,EAEnB,wBAAwB,EAExB,4BAA4B,EAC5B,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAKxC,UAAU,iCAAiC;IACzC,YAAY,EAAE,yBAAyB,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,MAAM,EAAE,mBAAmB,CAAC;IAC5B,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;CAC/C;AAED,gBAAgB;AAChB,qBAAa,4BAA6B,YAAW,mBAAmB;IACtE,OAAO,CAAC,aAAa,CAAoD;IACzE,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,oBAAoB,CAA2B;gBAEpC,KAAK,EAAE,iCAAiC;IAM3D,IAAW,cAAc,IAAI,gBAAgB,CAS5C;IAED,OAAO,CAAC,wBAAwB;IA2ChC,IAAW,eAAe,IAAI,iBAAiB,CAS9C;IAED,IAAW,SAAS,IAAI,UAAU,CAwCjC;IAEY,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAsGvG;AAED,gBAAgB;AAEhB,eAAO,MAAM,oCAAoC,uBAAuB,CAAC;AAEzE,gBAAgB;AAEhB,eAAO,MAAM,iCAAiC,oBAAoB,CAAC;AAenE,gBAAgB;AAChB,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,WAAW,EAAE,GAAG,4BAA4B,CAgC7I;AAED,gBAAgB;AAChB,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,4BAA4B,GAAG,4BAA4B,CAc1G"}
@@ -4,13 +4,16 @@
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ECSQL_COLUMN_NAME_FilterClassName = exports.ECSQL_COLUMN_NAME_FilterECInstanceId = exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor = exports.FilteringHierarchyDefinition = void 0;
7
+ exports.ECSQL_COLUMN_NAME_FilterClassName = exports.ECSQL_COLUMN_NAME_FilterECInstanceId = exports.FilteringHierarchyDefinition = void 0;
8
8
  exports.applyECInstanceIdsFilter = applyECInstanceIdsFilter;
9
+ exports.applyECInstanceIdsSelector = applyECInstanceIdsSelector;
10
+ const rxjs_1 = require("rxjs");
9
11
  const HierarchyFiltering_js_1 = require("../HierarchyFiltering.js");
10
- const HierarchyNode_js_1 = require("../HierarchyNode.js");
11
12
  const HierarchyNodeIdentifier_js_1 = require("../HierarchyNodeIdentifier.js");
13
+ const Partition_js_1 = require("../internal/operators/Partition.js");
12
14
  const IModelHierarchyDefinition_js_1 = require("./IModelHierarchyDefinition.js");
13
15
  const IModelHierarchyNode_js_1 = require("./IModelHierarchyNode.js");
16
+ const NodeSelectQueryFactory_js_1 = require("./NodeSelectQueryFactory.js");
14
17
  const TreeNodesReader_js_1 = require("./TreeNodesReader.js");
15
18
  /** @internal */
16
19
  class FilteringHierarchyDefinition {
@@ -80,208 +83,143 @@ class FilteringHierarchyDefinition {
80
83
  }
81
84
  get parseNode() {
82
85
  return async (row, parentNode) => {
83
- const hasFilterTargetAncestor = !!row[exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor];
84
- const { filteredChildrenIdentifierPaths, filterTargetOptions, isFilterTarget } = row[exports.ECSQL_COLUMN_NAME_FilterECInstanceId] && row[exports.ECSQL_COLUMN_NAME_FilterClassName]
85
- ? await this.getChildrenIdentifierPaths(parentNode?.filtering?.filteredChildrenIdentifierPaths ?? this._nodeIdentifierPaths, {
86
- className: row[exports.ECSQL_COLUMN_NAME_FilterClassName],
87
- id: row[exports.ECSQL_COLUMN_NAME_FilterECInstanceId],
88
- })
89
- : { filteredChildrenIdentifierPaths: [], filterTargetOptions: undefined, isFilterTarget: false };
90
- const defaultNode = await (this._source.parseNode ?? TreeNodesReader_js_1.defaultNodesParser)(row);
91
- return applyFilterAttributes({
92
- node: defaultNode,
93
- filteredChildrenIdentifierPaths,
94
- isFilterTarget,
95
- filterTargetOptions,
96
- hasFilterTargetAncestor,
97
- });
98
- };
99
- }
100
- async getChildrenIdentifierPaths(filteredChildrenNodeIdentifierPaths, providedIdentifier) {
101
- const { id, className } = providedIdentifier;
102
- let filteredChildrenIdentifierPaths;
103
- let isFilterTarget = false;
104
- let filterTargetOptions;
105
- for (const filteredChildrenNodeIdentifierPath of filteredChildrenNodeIdentifierPaths) {
106
- const { path, options } = HierarchyFiltering_js_1.HierarchyFilteringPath.normalize(filteredChildrenNodeIdentifierPath);
107
- /* c8 ignore next 3 */
108
- if (path.length === 0) {
109
- continue;
110
- }
111
- // We need to check if identifiers have the same id and imodelKey and are
112
- // of the same class / derived class / is derived from class
113
- const identifier = path[0];
114
- if (identifier.id !== id) {
115
- continue;
116
- }
117
- if (HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {
118
- if (identifier.imodelKey && identifier.imodelKey !== this._imodelAccess.imodelKey) {
119
- continue;
120
- }
121
- if (identifier.className !== className &&
122
- !(await this._imodelAccess.classDerivesFrom(identifier.className, className)) &&
123
- !(await this._imodelAccess.classDerivesFrom(className, identifier.className))) {
124
- continue;
125
- }
126
- }
127
- if (!filteredChildrenIdentifierPaths) {
128
- filteredChildrenIdentifierPaths = [];
129
- }
130
- if (path.length > 1) {
131
- filteredChildrenIdentifierPaths.push(options ? { path: path.slice(1), options } : path.slice(1));
132
- }
133
- else if (isFilterTarget) {
134
- filterTargetOptions = HierarchyFiltering_js_1.HierarchyFilteringPath.mergeOptions(filterTargetOptions, options);
86
+ const parsedNode = await (this._source.parseNode ?? TreeNodesReader_js_1.defaultNodesParser)(row);
87
+ const filteringHelper = (0, HierarchyFiltering_js_1.createHierarchyFilteringHelper)(this._nodeIdentifierPaths, parentNode);
88
+ const nodeExtraProps = row[exports.ECSQL_COLUMN_NAME_FilterECInstanceId] && row[exports.ECSQL_COLUMN_NAME_FilterClassName]
89
+ ? await (async () => {
90
+ const rowInstanceKey = { className: row[exports.ECSQL_COLUMN_NAME_FilterClassName], id: row[exports.ECSQL_COLUMN_NAME_FilterECInstanceId] };
91
+ return filteringHelper.createChildNodePropsAsync({
92
+ pathMatcher: (identifier) => {
93
+ if (identifier.id !== rowInstanceKey.id) {
94
+ return false;
95
+ }
96
+ if (!HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {
97
+ return false;
98
+ }
99
+ if (identifier.imodelKey && identifier.imodelKey !== this._imodelAccess.imodelKey) {
100
+ return false;
101
+ }
102
+ if (identifier.className === rowInstanceKey.className) {
103
+ return true;
104
+ }
105
+ return Promise.all([
106
+ this._imodelAccess.classDerivesFrom(identifier.className, rowInstanceKey.className),
107
+ this._imodelAccess.classDerivesFrom(rowInstanceKey.className, identifier.className),
108
+ ]).then(([isDerivedFrom, isDerivedTo]) => isDerivedFrom || isDerivedTo);
109
+ },
110
+ });
111
+ })()
112
+ : undefined;
113
+ if (nodeExtraProps?.autoExpand) {
114
+ parsedNode.autoExpand = true;
135
115
  }
136
- else {
137
- isFilterTarget = true;
138
- filterTargetOptions = options;
116
+ if (nodeExtraProps?.filtering) {
117
+ parsedNode.filtering = nodeExtraProps.filtering;
139
118
  }
140
- }
141
- return { filteredChildrenIdentifierPaths, filterTargetOptions, isFilterTarget };
119
+ return parsedNode;
120
+ };
142
121
  }
143
122
  async defineHierarchyLevel(props) {
144
123
  const sourceDefinitions = await this._source.defineHierarchyLevel(props);
145
- const filteringProps = (0, HierarchyFiltering_js_1.extractFilteringProps)(this._nodeIdentifierPaths, props.parentNode);
146
- if (!filteringProps) {
124
+ const filteringHelper = (0, HierarchyFiltering_js_1.createHierarchyFilteringHelper)(this._nodeIdentifierPaths, props.parentNode);
125
+ const childNodeFilteringIdentifiers = filteringHelper.getChildNodeFilteringIdentifiers();
126
+ if (!childNodeFilteringIdentifiers) {
147
127
  return sourceDefinitions;
148
128
  }
149
- const filteredDefinitions = [];
150
- await Promise.all(sourceDefinitions.map(async (definition) => {
151
- let matchedDefinition;
152
- if (IModelHierarchyDefinition_js_1.HierarchyNodesDefinition.isGenericNode(definition)) {
153
- matchedDefinition = await matchFilters(definition, filteringProps, async (id) => {
154
- return (HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isGenericNodeIdentifier(id) &&
155
- (!id.source || id.source === this._imodelAccess.imodelKey) &&
156
- id.id === definition.node.key);
157
- }, this._imodelAccess, (def, matchingFilters) => {
158
- const filteredChildrenIdentifierPaths = matchingFilters.reduce((r, c) => [...r, ...c.childrenIdentifierPaths], new Array());
159
- return {
160
- ...def,
161
- node: applyFilterAttributes({
162
- node: def.node,
163
- filteredChildrenIdentifierPaths,
164
- isFilterTarget: matchingFilters.some((mc) => mc.isFilterTarget),
165
- filterTargetOptions: matchingFilters.find((mc) => mc.isFilterTarget)?.filterTargetOptions,
166
- hasFilterTargetAncestor: filteringProps.hasFilterTargetAncestor,
167
- }),
168
- };
169
- });
170
- }
171
- else {
172
- matchedDefinition = await matchFilters(definition, filteringProps, async (id) => {
173
- return (HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(id) &&
174
- (!id.imodelKey || id.imodelKey === this._imodelAccess.imodelKey) &&
175
- (await this._imodelAccess.classDerivesFrom(id.className, definition.fullClassName)));
176
- }, this._imodelAccess, (def, matchingFilters) => applyECInstanceIdsFilter(def, matchingFilters, !!filteringProps.hasFilterTargetAncestor), false);
177
- }
178
- if (matchedDefinition) {
179
- filteredDefinitions.push(matchedDefinition);
180
- }
181
- }));
182
- return filteredDefinitions;
183
- }
184
- }
185
- exports.FilteringHierarchyDefinition = FilteringHierarchyDefinition;
186
- async function matchFilters(definition, filteringProps, predicate, classHierarchy, matchedDefinitionProcessor, extractPathsAndOptions = true) {
187
- const { filteredNodePaths, hasFilterTargetAncestor } = filteringProps;
188
- const matchingFilters = [];
189
- for (const filteredNodePath of filteredNodePaths) {
190
- const { path, options } = HierarchyFiltering_js_1.HierarchyFilteringPath.normalize(filteredNodePath);
191
- if (path.length === 0) {
192
- continue;
193
- }
194
- const nodeId = path[0];
195
- if (await predicate(nodeId)) {
196
- let entry = await findMatchingFilterEntry(matchingFilters, nodeId, classHierarchy);
197
- if (!entry) {
198
- entry = {
199
- // ideally, `predicate` would act as a type guard to guarantee that `id` is `TIdentifier`, but at the moment
200
- // async type guards aren't supported
201
- id: nodeId,
202
- childrenIdentifierPaths: [],
203
- isFilterTarget: false,
129
+ const [genericNodeDefinitions, instanceNodeDefinitions] = (0, Partition_js_1.partition)(sourceDefinitions, IModelHierarchyDefinition_js_1.HierarchyNodesDefinition.isGenericNode);
130
+ return (0, rxjs_1.firstValueFrom)((0, rxjs_1.merge)(genericNodeDefinitions.pipe((0, rxjs_1.map)((definition) => {
131
+ if (filteringHelper.hasFilterTargetAncestor ||
132
+ childNodeFilteringIdentifiers.some((identifier) => HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isGenericNodeIdentifier(identifier) &&
133
+ (!identifier.source || identifier.source === this._imodelAccess.imodelKey) &&
134
+ identifier.id === definition.node.key)) {
135
+ return {
136
+ ...definition,
137
+ node: {
138
+ ...definition.node,
139
+ ...filteringHelper.createChildNodeProps({ pathMatcher: ({ id }) => id === definition.node.key }),
140
+ },
204
141
  };
205
- matchingFilters.push(entry);
206
- }
207
- if (!extractPathsAndOptions) {
208
- continue;
209
- }
210
- if (path.length > 1) {
211
- entry.childrenIdentifierPaths.push(options ? { path: path.slice(1), options } : path.slice(1));
212
- }
213
- else if (entry.isFilterTarget) {
214
- entry.filterTargetOptions = HierarchyFiltering_js_1.HierarchyFilteringPath.mergeOptions(entry.filterTargetOptions, options);
215
142
  }
216
- else {
217
- Object.assign(entry, { isFilterTarget: true, filterTargetOptions: options });
143
+ return undefined;
144
+ }), (0, rxjs_1.filter)((def) => !!def)), instanceNodeDefinitions.pipe((0, rxjs_1.mergeMap)((definition) => {
145
+ if (filteringHelper.hasFilterTargetAncestor) {
146
+ // if we have a filter target ancestor, we don't need to filter the definitions - we use all of them
147
+ return (0, rxjs_1.of)(applyECInstanceIdsSelector(definition));
218
148
  }
219
- }
220
- }
221
- if (hasFilterTargetAncestor || matchingFilters.length > 0) {
222
- return matchedDefinitionProcessor(definition, matchingFilters);
223
- }
224
- return undefined;
225
- }
226
- async function findMatchingFilterEntry(filters, nodeId, classHierarchy) {
227
- for (const filter of filters) {
228
- if (await identifiersEqual(filter.id, nodeId, classHierarchy)) {
229
- return filter;
230
- }
231
- }
232
- return undefined;
233
- }
234
- async function identifiersEqual(lhs, rhs, classHierarchy) {
235
- if (HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(lhs) && HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(rhs)) {
236
- return (lhs.id === rhs.id &&
237
- (lhs.className === rhs.className ||
238
- (await classHierarchy.classDerivesFrom(lhs.className, rhs.className)) ||
239
- (await classHierarchy.classDerivesFrom(rhs.className, lhs.className))));
240
- }
241
- return HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.equal(lhs, rhs);
242
- }
243
- function applyFilterAttributes(props) {
244
- const { node, filteredChildrenIdentifierPaths } = props;
245
- const result = { ...node };
246
- const shouldAutoExpand = !!filteredChildrenIdentifierPaths?.some((childPath) => {
247
- return !!HierarchyFiltering_js_1.HierarchyFilteringPath.normalize(childPath).options?.autoExpand;
248
- });
249
- if (shouldAutoExpand) {
250
- result.autoExpand = true;
251
- }
252
- const filteringProps = HierarchyNode_js_1.HierarchyNodeFilteringProps.create(props);
253
- if (filteringProps) {
254
- result.filtering = filteringProps;
149
+ return (0, rxjs_1.defer)(async () => {
150
+ const imodelAccess = this._imodelAccess;
151
+ const matches = new Map();
152
+ async function getEntries(x) {
153
+ let entries = matches.get(x.id);
154
+ if (!entries) {
155
+ entries = [];
156
+ matches.set(x.id, entries);
157
+ }
158
+ // make sure that we don't have path identifiers that only differ by class name, where
159
+ // class names are in the same class hierarchy, e.g.:
160
+ // [{ className: "bis.Element", id: "0x1" }, { className: "bis.Subject", id: "0x1" }]
161
+ // are actually the same instance, so we only need to keep one of them, or otherwise the query will
162
+ // duplicate it
163
+ for (const entry of entries) {
164
+ if (entry.className === x.className ||
165
+ (await imodelAccess.classDerivesFrom(entry.className, x.className)) ||
166
+ (await imodelAccess.classDerivesFrom(x.className, entry.className))) {
167
+ return undefined;
168
+ }
169
+ }
170
+ return entries;
171
+ }
172
+ for (const id of childNodeFilteringIdentifiers) {
173
+ // take only identifiers that match the definition by type, source and class
174
+ if (!HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(id)) {
175
+ continue;
176
+ }
177
+ if (id.imodelKey && id.imodelKey !== imodelAccess.imodelKey) {
178
+ continue;
179
+ }
180
+ if (id.className !== definition.fullClassName &&
181
+ !(await Promise.all([
182
+ imodelAccess.classDerivesFrom(id.className, definition.fullClassName),
183
+ imodelAccess.classDerivesFrom(definition.fullClassName, id.className),
184
+ ]).then(([isDerivedFrom, isDerivedTo]) => isDerivedFrom || isDerivedTo))) {
185
+ continue;
186
+ }
187
+ const entriesTargetForPathIdentifier = await getEntries(id);
188
+ if (entriesTargetForPathIdentifier) {
189
+ entriesTargetForPathIdentifier.push(id);
190
+ }
191
+ }
192
+ return Array.from(matches.values()).flat();
193
+ }).pipe(
194
+ // only take definitions that have matching path identifiers
195
+ (0, rxjs_1.filter)((pathIdentifiers) => pathIdentifiers.length > 0),
196
+ // for each definition that we're going to use, apply query-level filter
197
+ (0, rxjs_1.map)((pathIdentifiers) => applyECInstanceIdsFilter(definition, pathIdentifiers)));
198
+ }))).pipe((0, rxjs_1.toArray)()));
255
199
  }
256
- return result;
257
200
  }
258
- /** @internal */
259
- // eslint-disable-next-line @typescript-eslint/naming-convention
260
- exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor = "HasFilterTargetAncestor";
201
+ exports.FilteringHierarchyDefinition = FilteringHierarchyDefinition;
261
202
  /** @internal */
262
203
  // eslint-disable-next-line @typescript-eslint/naming-convention
263
204
  exports.ECSQL_COLUMN_NAME_FilterECInstanceId = "FilterECInstanceId";
264
205
  /** @internal */
265
206
  // eslint-disable-next-line @typescript-eslint/naming-convention
266
207
  exports.ECSQL_COLUMN_NAME_FilterClassName = "FilterClassName";
267
- function getClassECInstanceIds(matchingFilters) {
208
+ function getClassECInstanceIds(filteredInstanceKeys) {
268
209
  const classNameECInstanceIds = new Map();
269
- for (const matchingFilter of matchingFilters) {
270
- const entry = classNameECInstanceIds.get(matchingFilter.id.className);
210
+ for (const key of filteredInstanceKeys) {
211
+ const entry = classNameECInstanceIds.get(key.className);
271
212
  if (entry === undefined) {
272
- classNameECInstanceIds.set(matchingFilter.id.className, [matchingFilter.id.id]);
213
+ classNameECInstanceIds.set(key.className, [key.id]);
273
214
  continue;
274
215
  }
275
- entry.push(matchingFilter.id.id);
216
+ entry.push(key.id);
276
217
  }
277
218
  return classNameECInstanceIds;
278
219
  }
279
220
  /** @internal */
280
- function applyECInstanceIdsFilter(def, matchingFilters, hasFilterTargetAncestor) {
281
- if (matchingFilters.length === 0) {
282
- return def;
283
- }
284
- const matchingFiltersToUse = getClassECInstanceIds(matchingFilters);
221
+ function applyECInstanceIdsFilter(def, filteredInstanceKeys) {
222
+ const instanceIdsByClass = getClassECInstanceIds(filteredInstanceKeys);
285
223
  return {
286
224
  ...def,
287
225
  query: {
@@ -289,7 +227,7 @@ function applyECInstanceIdsFilter(def, matchingFilters, hasFilterTargetAncestor)
289
227
  ctes: [
290
228
  ...(def.query.ctes ?? []),
291
229
  `FilteringInfo(ECInstanceId, FilterClassName) AS (
292
- ${Array.from(matchingFiltersToUse)
230
+ ${Array.from(instanceIdsByClass)
293
231
  .map(([className, ecInstanceIds]) => `
294
232
  SELECT ECInstanceId, '${className}' AS FilterClassName
295
233
  FROM ${className}
@@ -301,13 +239,28 @@ function applyECInstanceIdsFilter(def, matchingFilters, hasFilterTargetAncestor)
301
239
  ecsql: `
302
240
  SELECT
303
241
  [q].*,
304
- ${hasFilterTargetAncestor ? "1" : "0"} AS [${exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor}],
305
242
  IdToHex([f].[ECInstanceId]) AS [${exports.ECSQL_COLUMN_NAME_FilterECInstanceId}],
306
243
  [f].[FilterClassName] AS [${exports.ECSQL_COLUMN_NAME_FilterClassName}]
307
244
  FROM (
308
245
  ${def.query.ecsql}
309
246
  ) [q]
310
- ${hasFilterTargetAncestor ? "LEFT " : ""} JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]
247
+ JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]
248
+ `,
249
+ },
250
+ };
251
+ }
252
+ /** @internal */
253
+ function applyECInstanceIdsSelector(def) {
254
+ return {
255
+ ...def,
256
+ query: {
257
+ ...def.query,
258
+ ecsql: `
259
+ SELECT
260
+ [q].*,
261
+ IdToHex([q].[ECInstanceId]) AS [${exports.ECSQL_COLUMN_NAME_FilterECInstanceId}],
262
+ [q].[${NodeSelectQueryFactory_js_1.NodeSelectClauseColumnNames.FullClassName}] AS [${exports.ECSQL_COLUMN_NAME_FilterClassName}]
263
+ FROM (${def.query.ecsql}) [q]
311
264
  `,
312
265
  },
313
266
  };
@@ -1 +1 @@
1
- {"version":3,"file":"FilteringHierarchyDefinition.js","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/Filtering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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 { Id64String } from \"@itwin/core-bentley\";\nimport { ECClassHierarchyInspector, InstanceKey } from \"@itwin/presentation-shared\";\nimport { extractFilteringProps, HierarchyFilteringPath, HierarchyFilteringPathOptions } from \"../HierarchyFiltering.js\";\nimport { HierarchyNodeFilteringProps } from \"../HierarchyNode.js\";\nimport { HierarchyNodeIdentifier } from \"../HierarchyNodeIdentifier.js\";\nimport { GenericNodeKey } from \"../HierarchyNodeKey.js\";\nimport {\n DefineHierarchyLevelProps,\n GenericHierarchyNodeDefinition,\n HierarchyDefinition,\n HierarchyDefinitionParentNode,\n HierarchyLevelDefinition,\n HierarchyNodesDefinition,\n InstanceNodesQueryDefinition,\n NodeParser,\n NodePostProcessor,\n NodePreProcessor,\n} from \"./IModelHierarchyDefinition.js\";\nimport { ProcessedGroupingHierarchyNode, ProcessedHierarchyNode, SourceHierarchyNode, SourceInstanceHierarchyNode } from \"./IModelHierarchyNode.js\";\nimport { defaultNodesParser } from \"./TreeNodesReader.js\";\n\ninterface FilteringHierarchyDefinitionProps {\n imodelAccess: ECClassHierarchyInspector & { imodelKey: string };\n source: HierarchyDefinition;\n nodeIdentifierPaths: HierarchyFilteringPath[];\n}\n\n/** @internal */\nexport class FilteringHierarchyDefinition implements HierarchyDefinition {\n private _imodelAccess: ECClassHierarchyInspector & { imodelKey: string };\n private _source: HierarchyDefinition;\n private _nodeIdentifierPaths: HierarchyFilteringPath[];\n\n public constructor(props: FilteringHierarchyDefinitionProps) {\n this._imodelAccess = props.imodelAccess;\n this._source = props.source;\n this._nodeIdentifierPaths = props.nodeIdentifierPaths;\n }\n\n public get preProcessNode(): NodePreProcessor {\n return async (node) => {\n const processedNode = this._source.preProcessNode ? await this._source.preProcessNode(node) : node;\n if (processedNode?.processingParams?.hideInHierarchy && processedNode.filtering?.isFilterTarget && !processedNode.filtering.hasFilterTargetAncestor) {\n // we want to hide target nodes if they have `hideInHierarchy` param, but only if they're not under another filter target\n return undefined;\n }\n return processedNode;\n };\n }\n\n private shouldExpandGroupingNode(node: ProcessedGroupingHierarchyNode) {\n for (const child of node.children) {\n /* c8 ignore next 3 */\n if (!child.filtering) {\n continue;\n }\n\n if (child.filtering.isFilterTarget) {\n const childAutoExpand = child.filtering.filterTargetOptions?.autoExpand;\n\n // If child is a filter target and is has no `autoExpand` flag, then it's always to be expanded.\n if (childAutoExpand === true) {\n return true;\n }\n\n // If it's not an object and not `true`, then it's falsy - continue looking\n if (typeof childAutoExpand !== \"object\") {\n continue;\n }\n\n // If grouping node's child has `autoExpandUntil` flag,\n // auto-expand the grouping node only if it's depth is lower than that of the grouping node in associated with the target.\n const nodeDepth = node.parentKeys.length;\n const filterTargetDepth = childAutoExpand.depth;\n if (nodeDepth < filterTargetDepth) {\n return true;\n }\n }\n\n if (!child.filtering.filteredChildrenIdentifierPaths) {\n /* c8 ignore next */\n continue;\n }\n\n for (const path of child.filtering.filteredChildrenIdentifierPaths) {\n if (\"path\" in path && path.options?.autoExpand) {\n return true;\n }\n }\n }\n return false;\n }\n\n public get postProcessNode(): NodePostProcessor {\n return async (node: ProcessedHierarchyNode) => {\n const processedNode = this._source.postProcessNode ? await this._source.postProcessNode(node) : node;\n // instance nodes get the auto-expand flag in `parseNode`, but grouping ones need to be handled during post-processing\n if (ProcessedHierarchyNode.isGroupingNode(node) && this.shouldExpandGroupingNode(node)) {\n Object.assign(processedNode, { autoExpand: true });\n }\n return processedNode;\n };\n }\n\n public get parseNode(): NodeParser {\n return async (row: { [columnName: string]: any }, parentNode?: HierarchyDefinitionParentNode): Promise<SourceInstanceHierarchyNode> => {\n const hasFilterTargetAncestor: boolean = !!row[ECSQL_COLUMN_NAME_HasFilterTargetAncestor];\n\n const { filteredChildrenIdentifierPaths, filterTargetOptions, isFilterTarget } =\n row[ECSQL_COLUMN_NAME_FilterECInstanceId] && row[ECSQL_COLUMN_NAME_FilterClassName]\n ? await this.getChildrenIdentifierPaths(parentNode?.filtering?.filteredChildrenIdentifierPaths ?? this._nodeIdentifierPaths, {\n className: row[ECSQL_COLUMN_NAME_FilterClassName],\n id: row[ECSQL_COLUMN_NAME_FilterECInstanceId],\n })\n : { filteredChildrenIdentifierPaths: [], filterTargetOptions: undefined, isFilterTarget: false };\n\n const defaultNode = await (this._source.parseNode ?? defaultNodesParser)(row);\n return applyFilterAttributes({\n node: defaultNode,\n filteredChildrenIdentifierPaths,\n isFilterTarget,\n filterTargetOptions,\n hasFilterTargetAncestor,\n });\n };\n }\n\n private async getChildrenIdentifierPaths(filteredChildrenNodeIdentifierPaths: HierarchyFilteringPath[], providedIdentifier: InstanceKey) {\n const { id, className } = providedIdentifier;\n\n let filteredChildrenIdentifierPaths: HierarchyFilteringPath[] | undefined;\n let isFilterTarget = false;\n let filterTargetOptions: HierarchyFilteringPathOptions | undefined;\n for (const filteredChildrenNodeIdentifierPath of filteredChildrenNodeIdentifierPaths) {\n const { path, options } = HierarchyFilteringPath.normalize(filteredChildrenNodeIdentifierPath);\n /* c8 ignore next 3 */\n if (path.length === 0) {\n continue;\n }\n\n // We need to check if identifiers have the same id and imodelKey and are\n // of the same class / derived class / is derived from class\n const identifier = path[0];\n if (identifier.id !== id) {\n continue;\n }\n if (HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {\n if (identifier.imodelKey && identifier.imodelKey !== this._imodelAccess.imodelKey) {\n continue;\n }\n if (\n identifier.className !== className &&\n !(await this._imodelAccess.classDerivesFrom(identifier.className, className)) &&\n !(await this._imodelAccess.classDerivesFrom(className, identifier.className))\n ) {\n continue;\n }\n }\n if (!filteredChildrenIdentifierPaths) {\n filteredChildrenIdentifierPaths = [];\n }\n if (path.length > 1) {\n filteredChildrenIdentifierPaths.push(options ? { path: path.slice(1), options } : path.slice(1));\n } else if (isFilterTarget) {\n filterTargetOptions = HierarchyFilteringPath.mergeOptions(filterTargetOptions, options);\n } else {\n isFilterTarget = true;\n filterTargetOptions = options;\n }\n }\n return { filteredChildrenIdentifierPaths, filterTargetOptions, isFilterTarget };\n }\n\n public async defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition> {\n const sourceDefinitions = await this._source.defineHierarchyLevel(props);\n const filteringProps = extractFilteringProps(this._nodeIdentifierPaths, props.parentNode);\n if (!filteringProps) {\n return sourceDefinitions;\n }\n\n const filteredDefinitions: HierarchyLevelDefinition = [];\n await Promise.all(\n sourceDefinitions.map(async (definition) => {\n let matchedDefinition: HierarchyNodesDefinition | undefined;\n if (HierarchyNodesDefinition.isGenericNode(definition)) {\n matchedDefinition = await matchFilters<GenericNodeKey>(\n definition,\n filteringProps,\n async (id) => {\n return (\n HierarchyNodeIdentifier.isGenericNodeIdentifier(id) &&\n (!id.source || id.source === this._imodelAccess.imodelKey) &&\n id.id === definition.node.key\n );\n },\n this._imodelAccess,\n (def, matchingFilters) => {\n const filteredChildrenIdentifierPaths = matchingFilters.reduce(\n (r, c) => [...r, ...c.childrenIdentifierPaths],\n new Array<HierarchyFilteringPath>(),\n );\n return {\n ...def,\n node: applyFilterAttributes({\n node: def.node,\n filteredChildrenIdentifierPaths,\n isFilterTarget: matchingFilters.some((mc) => mc.isFilterTarget),\n filterTargetOptions: matchingFilters.find((mc) => mc.isFilterTarget)?.filterTargetOptions,\n hasFilterTargetAncestor: filteringProps.hasFilterTargetAncestor,\n }),\n };\n },\n );\n } else {\n matchedDefinition = await matchFilters<InstanceKey>(\n definition,\n filteringProps,\n async (id) => {\n return (\n HierarchyNodeIdentifier.isInstanceNodeIdentifier(id) &&\n (!id.imodelKey || id.imodelKey === this._imodelAccess.imodelKey) &&\n (await this._imodelAccess.classDerivesFrom(id.className, definition.fullClassName))\n );\n },\n this._imodelAccess,\n (def, matchingFilters) => applyECInstanceIdsFilter(def, matchingFilters, !!filteringProps.hasFilterTargetAncestor),\n false,\n );\n }\n if (matchedDefinition) {\n filteredDefinitions.push(matchedDefinition);\n }\n }),\n );\n return filteredDefinitions;\n }\n}\n\ntype MatchedFilter<TIdentifier extends HierarchyNodeIdentifier> = {\n id: TIdentifier;\n childrenIdentifierPaths: HierarchyFilteringPath[];\n} & ({ isFilterTarget: false } | { isFilterTarget: true; filterTargetOptions?: HierarchyFilteringPathOptions });\n\nasync function matchFilters<\n TIdentifier extends HierarchyNodeIdentifier,\n TDefinition = TIdentifier extends InstanceKey ? InstanceNodesQueryDefinition : GenericHierarchyNodeDefinition,\n>(\n definition: TDefinition,\n filteringProps: { filteredNodePaths: HierarchyFilteringPath[]; hasFilterTargetAncestor?: boolean },\n predicate: (id: HierarchyNodeIdentifier) => Promise<boolean>,\n classHierarchy: ECClassHierarchyInspector,\n matchedDefinitionProcessor: (def: TDefinition, matchingFilters: Array<MatchedFilter<TIdentifier>>) => TDefinition,\n extractPathsAndOptions: boolean = true,\n): Promise<TDefinition | undefined> {\n const { filteredNodePaths, hasFilterTargetAncestor } = filteringProps;\n const matchingFilters: Array<MatchedFilter<TIdentifier>> = [];\n for (const filteredNodePath of filteredNodePaths) {\n const { path, options } = HierarchyFilteringPath.normalize(filteredNodePath);\n if (path.length === 0) {\n continue;\n }\n const nodeId = path[0];\n if (await predicate(nodeId)) {\n let entry = await findMatchingFilterEntry(matchingFilters, nodeId, classHierarchy);\n if (!entry) {\n entry = {\n // ideally, `predicate` would act as a type guard to guarantee that `id` is `TIdentifier`, but at the moment\n // async type guards aren't supported\n id: nodeId as TIdentifier,\n childrenIdentifierPaths: [],\n isFilterTarget: false,\n };\n matchingFilters.push(entry);\n }\n\n if (!extractPathsAndOptions) {\n continue;\n }\n\n if (path.length > 1) {\n entry.childrenIdentifierPaths.push(options ? { path: path.slice(1), options } : path.slice(1));\n } else if (entry.isFilterTarget) {\n entry.filterTargetOptions = HierarchyFilteringPath.mergeOptions(entry.filterTargetOptions, options);\n } else {\n Object.assign(entry, { isFilterTarget: true, filterTargetOptions: options });\n }\n }\n }\n if (hasFilterTargetAncestor || matchingFilters.length > 0) {\n return matchedDefinitionProcessor(definition, matchingFilters);\n }\n return undefined;\n}\n\nasync function findMatchingFilterEntry<TEntry extends { id: TIdentifier }, TIdentifier extends HierarchyNodeIdentifier>(\n filters: TEntry[],\n nodeId: TIdentifier,\n classHierarchy: ECClassHierarchyInspector,\n): Promise<TEntry | undefined> {\n for (const filter of filters) {\n if (await identifiersEqual(filter.id, nodeId, classHierarchy)) {\n return filter;\n }\n }\n return undefined;\n}\n\nasync function identifiersEqual<TIdentifier extends HierarchyNodeIdentifier>(lhs: TIdentifier, rhs: TIdentifier, classHierarchy: ECClassHierarchyInspector) {\n if (HierarchyNodeIdentifier.isInstanceNodeIdentifier(lhs) && HierarchyNodeIdentifier.isInstanceNodeIdentifier(rhs)) {\n return (\n lhs.id === rhs.id &&\n (lhs.className === rhs.className ||\n (await classHierarchy.classDerivesFrom(lhs.className, rhs.className)) ||\n (await classHierarchy.classDerivesFrom(rhs.className, lhs.className)))\n );\n }\n return HierarchyNodeIdentifier.equal(lhs, rhs);\n}\n\nfunction applyFilterAttributes<TNode extends SourceHierarchyNode>(props: {\n node: TNode;\n filteredChildrenIdentifierPaths: HierarchyFilteringPath[] | undefined;\n isFilterTarget?: boolean;\n filterTargetOptions?: HierarchyFilteringPathOptions;\n hasFilterTargetAncestor: boolean;\n}): TNode {\n const { node, filteredChildrenIdentifierPaths } = props;\n const result = { ...node };\n\n const shouldAutoExpand = !!filteredChildrenIdentifierPaths?.some((childPath) => {\n return !!HierarchyFilteringPath.normalize(childPath).options?.autoExpand;\n });\n if (shouldAutoExpand) {\n result.autoExpand = true;\n }\n\n const filteringProps = HierarchyNodeFilteringProps.create(props);\n if (filteringProps) {\n result.filtering = filteringProps;\n }\n\n return result;\n}\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_HasFilterTargetAncestor = \"HasFilterTargetAncestor\";\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_FilterECInstanceId = \"FilterECInstanceId\";\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_FilterClassName = \"FilterClassName\";\n\nfunction getClassECInstanceIds(matchingFilters: Array<{ id: InstanceKey }>) {\n const classNameECInstanceIds = new Map<string, Id64String[]>();\n for (const matchingFilter of matchingFilters) {\n const entry = classNameECInstanceIds.get(matchingFilter.id.className);\n if (entry === undefined) {\n classNameECInstanceIds.set(matchingFilter.id.className, [matchingFilter.id.id]);\n continue;\n }\n entry.push(matchingFilter.id.id);\n }\n return classNameECInstanceIds;\n}\n\n/** @internal */\nexport function applyECInstanceIdsFilter(\n def: InstanceNodesQueryDefinition,\n matchingFilters: Array<{ id: InstanceKey }>,\n hasFilterTargetAncestor: boolean,\n): InstanceNodesQueryDefinition {\n if (matchingFilters.length === 0) {\n return def;\n }\n const matchingFiltersToUse = getClassECInstanceIds(matchingFilters);\n return {\n ...def,\n query: {\n ...def.query,\n ctes: [\n ...(def.query.ctes ?? []),\n `FilteringInfo(ECInstanceId, FilterClassName) AS (\n ${Array.from(matchingFiltersToUse)\n .map(\n ([className, ecInstanceIds]) => `\n SELECT ECInstanceId, '${className}' AS FilterClassName\n FROM ${className}\n WHERE ECInstanceId IN (${ecInstanceIds.join(\", \")})\n `,\n )\n .join(\" UNION ALL \")}\n )`,\n ],\n ecsql: `\n SELECT\n [q].*,\n ${hasFilterTargetAncestor ? \"1\" : \"0\"} AS [${ECSQL_COLUMN_NAME_HasFilterTargetAncestor}],\n IdToHex([f].[ECInstanceId]) AS [${ECSQL_COLUMN_NAME_FilterECInstanceId}],\n [f].[FilterClassName] AS [${ECSQL_COLUMN_NAME_FilterClassName}]\n FROM (\n ${def.query.ecsql}\n ) [q]\n ${hasFilterTargetAncestor ? \"LEFT \" : \"\"} JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]\n `,\n },\n };\n}\n"]}
1
+ {"version":3,"file":"FilteringHierarchyDefinition.js","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/FilteringHierarchyDefinition.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAoRhG,4DAgCC;AAGD,gEAcC;AAnUD,+BAAwF;AAGxF,oEAAkG;AAClG,8EAAwE;AAExE,qEAA+D;AAC/D,iFAWwC;AACxC,qEAA+H;AAC/H,2EAA0E;AAC1E,6DAA0D;AAQ1D,gBAAgB;AAChB,MAAa,4BAA4B;IAC/B,aAAa,CAAoD;IACjE,OAAO,CAAsB;IAC7B,oBAAoB,CAA2B;IAEvD,YAAmB,KAAwC;QACzD,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC,mBAAmB,CAAC;IACxD,CAAC;IAED,IAAW,cAAc;QACvB,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE;YACpB,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACnG,IAAI,aAAa,EAAE,gBAAgB,EAAE,eAAe,IAAI,aAAa,CAAC,SAAS,EAAE,cAAc,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,uBAAuB,EAAE,CAAC;gBACpJ,yHAAyH;gBACzH,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC;IACJ,CAAC;IAEO,wBAAwB,CAAC,IAAoC;QACnE,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,sBAAsB;YACtB,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;gBACrB,SAAS;YACX,CAAC;YAED,IAAI,KAAK,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C,EAAE,CAAC,CAAC,CAAC;YACpD,SAAS;QACX,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED,gBAAgB;AAChB,SAAgB,wBAAwB,CAAC,GAAiC,EAAE,oBAAmC;IAC7G,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,oBAAoB,CAAC,CAAC;IACvE,OAAO;QACL,GAAG,GAAG;QACN,KAAK,EAAE;YACL,GAAG,GAAG,CAAC,KAAK;YACZ,IAAI,EAAE;gBACJ,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;gBACzB;YACI,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC;qBAC7B,GAAG,CACF,CAAC,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,EAAE,CAAC;wCACN,SAAS;uBAC1B,SAAS;yCACS,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;eAClD,CACF;qBACA,IAAI,CAAC,aAAa,CAAC;UACtB;aACH;YACD,KAAK,EAAE;;;4CAG+B,4CAAoC;sCAC1C,yCAAiC;;YAE3D,GAAG,CAAC,KAAK,CAAC,KAAK;;;OAGpB;SACF;KACF,CAAC;AACJ,CAAC;AAED,gBAAgB;AAChB,SAAgB,0BAA0B,CAAC,GAAiC;IAC1E,OAAO;QACL,GAAG,GAAG;QACN,KAAK,EAAE;YACL,GAAG,GAAG,CAAC,KAAK;YACZ,KAAK,EAAE;;;4CAG+B,4CAAoC;iBAC/D,uDAA2B,CAAC,aAAa,SAAS,yCAAiC;gBACpF,GAAG,CAAC,KAAK,CAAC,KAAK;OACxB;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { defer, filter, firstValueFrom, map, merge, mergeMap, of, toArray } from \"rxjs\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { ECClassHierarchyInspector, InstanceKey } from \"@itwin/presentation-shared\";\nimport { createHierarchyFilteringHelper, HierarchyFilteringPath } from \"../HierarchyFiltering.js\";\nimport { HierarchyNodeIdentifier } from \"../HierarchyNodeIdentifier.js\";\nimport { IModelInstanceKey } from \"../HierarchyNodeKey.js\";\nimport { partition } from \"../internal/operators/Partition.js\";\nimport {\n DefineHierarchyLevelProps,\n GenericHierarchyNodeDefinition,\n HierarchyDefinition,\n HierarchyDefinitionParentNode,\n HierarchyLevelDefinition,\n HierarchyNodesDefinition,\n InstanceNodesQueryDefinition,\n NodeParser,\n NodePostProcessor,\n NodePreProcessor,\n} from \"./IModelHierarchyDefinition.js\";\nimport { ProcessedGroupingHierarchyNode, ProcessedHierarchyNode, SourceInstanceHierarchyNode } from \"./IModelHierarchyNode.js\";\nimport { NodeSelectClauseColumnNames } from \"./NodeSelectQueryFactory.js\";\nimport { defaultNodesParser } from \"./TreeNodesReader.js\";\n\ninterface FilteringHierarchyDefinitionProps {\n imodelAccess: ECClassHierarchyInspector & { imodelKey: string };\n source: HierarchyDefinition;\n nodeIdentifierPaths: HierarchyFilteringPath[];\n}\n\n/** @internal */\nexport class FilteringHierarchyDefinition implements HierarchyDefinition {\n private _imodelAccess: ECClassHierarchyInspector & { imodelKey: string };\n private _source: HierarchyDefinition;\n private _nodeIdentifierPaths: HierarchyFilteringPath[];\n\n public constructor(props: FilteringHierarchyDefinitionProps) {\n this._imodelAccess = props.imodelAccess;\n this._source = props.source;\n this._nodeIdentifierPaths = props.nodeIdentifierPaths;\n }\n\n public get preProcessNode(): NodePreProcessor {\n return async (node) => {\n const processedNode = this._source.preProcessNode ? await this._source.preProcessNode(node) : node;\n if (processedNode?.processingParams?.hideInHierarchy && processedNode.filtering?.isFilterTarget && !processedNode.filtering.hasFilterTargetAncestor) {\n // we want to hide target nodes if they have `hideInHierarchy` param, but only if they're not under another filter target\n return undefined;\n }\n return processedNode;\n };\n }\n\n private shouldExpandGroupingNode(node: ProcessedGroupingHierarchyNode) {\n for (const child of node.children) {\n /* c8 ignore next 3 */\n if (!child.filtering) {\n continue;\n }\n\n if (child.filtering.isFilterTarget) {\n const childAutoExpand = child.filtering.filterTargetOptions?.autoExpand;\n\n // If child is a filter target and is has no `autoExpand` flag, then it's always to be expanded.\n if (childAutoExpand === true) {\n return true;\n }\n\n // If it's not an object and not `true`, then it's falsy - continue looking\n if (typeof childAutoExpand !== \"object\") {\n continue;\n }\n\n // If grouping node's child has `autoExpandUntil` flag,\n // auto-expand the grouping node only if it's depth is lower than that of the grouping node in associated with the target.\n const nodeDepth = node.parentKeys.length;\n const filterTargetDepth = childAutoExpand.depth;\n if (nodeDepth < filterTargetDepth) {\n return true;\n }\n }\n\n if (!child.filtering.filteredChildrenIdentifierPaths) {\n /* c8 ignore next */\n continue;\n }\n\n for (const path of child.filtering.filteredChildrenIdentifierPaths) {\n if (\"path\" in path && path.options?.autoExpand) {\n return true;\n }\n }\n }\n return false;\n }\n\n public get postProcessNode(): NodePostProcessor {\n return async (node: ProcessedHierarchyNode) => {\n const processedNode = this._source.postProcessNode ? await this._source.postProcessNode(node) : node;\n // instance nodes get the auto-expand flag in `parseNode`, but grouping ones need to be handled during post-processing\n if (ProcessedHierarchyNode.isGroupingNode(node) && this.shouldExpandGroupingNode(node)) {\n Object.assign(processedNode, { autoExpand: true });\n }\n return processedNode;\n };\n }\n\n public get parseNode(): NodeParser {\n return async (row: { [columnName: string]: any }, parentNode?: HierarchyDefinitionParentNode): Promise<SourceInstanceHierarchyNode> => {\n const parsedNode = await (this._source.parseNode ?? defaultNodesParser)(row);\n\n const filteringHelper = createHierarchyFilteringHelper(this._nodeIdentifierPaths, parentNode);\n const nodeExtraProps =\n row[ECSQL_COLUMN_NAME_FilterECInstanceId] && row[ECSQL_COLUMN_NAME_FilterClassName]\n ? await (async () => {\n const rowInstanceKey = { className: row[ECSQL_COLUMN_NAME_FilterClassName], id: row[ECSQL_COLUMN_NAME_FilterECInstanceId] };\n return filteringHelper.createChildNodePropsAsync({\n pathMatcher: (identifier): boolean | Promise<boolean> => {\n if (identifier.id !== rowInstanceKey.id) {\n return false;\n }\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {\n return false;\n }\n if (identifier.imodelKey && identifier.imodelKey !== this._imodelAccess.imodelKey) {\n return false;\n }\n if (identifier.className === rowInstanceKey.className) {\n return true;\n }\n return Promise.all([\n this._imodelAccess.classDerivesFrom(identifier.className, rowInstanceKey.className),\n this._imodelAccess.classDerivesFrom(rowInstanceKey.className, identifier.className),\n ]).then(([isDerivedFrom, isDerivedTo]) => isDerivedFrom || isDerivedTo);\n },\n });\n })()\n : undefined;\n if (nodeExtraProps?.autoExpand) {\n parsedNode.autoExpand = true;\n }\n if (nodeExtraProps?.filtering) {\n parsedNode.filtering = nodeExtraProps.filtering;\n }\n\n return parsedNode;\n };\n }\n\n public async defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition> {\n const sourceDefinitions = await this._source.defineHierarchyLevel(props);\n\n const filteringHelper = createHierarchyFilteringHelper(this._nodeIdentifierPaths, props.parentNode);\n const childNodeFilteringIdentifiers = filteringHelper.getChildNodeFilteringIdentifiers();\n if (!childNodeFilteringIdentifiers) {\n return sourceDefinitions;\n }\n\n const [genericNodeDefinitions, instanceNodeDefinitions] = partition(sourceDefinitions, HierarchyNodesDefinition.isGenericNode);\n return firstValueFrom(\n merge(\n genericNodeDefinitions.pipe(\n map((definition) => {\n if (\n filteringHelper.hasFilterTargetAncestor ||\n childNodeFilteringIdentifiers.some(\n (identifier) =>\n HierarchyNodeIdentifier.isGenericNodeIdentifier(identifier) &&\n (!identifier.source || identifier.source === this._imodelAccess.imodelKey) &&\n identifier.id === definition.node.key,\n )\n ) {\n return {\n ...definition,\n node: {\n ...definition.node,\n ...filteringHelper.createChildNodeProps({ pathMatcher: ({ id }) => id === definition.node.key }),\n },\n };\n }\n return undefined;\n }),\n filter((def): def is GenericHierarchyNodeDefinition => !!def),\n ),\n\n instanceNodeDefinitions.pipe(\n mergeMap((definition) => {\n if (filteringHelper.hasFilterTargetAncestor) {\n // if we have a filter target ancestor, we don't need to filter the definitions - we use all of them\n return of(applyECInstanceIdsSelector(definition));\n }\n return defer(async () => {\n const imodelAccess = this._imodelAccess;\n const matches = new Map<Id64String, IModelInstanceKey[]>();\n async function getEntries(x: IModelInstanceKey) {\n let entries = matches.get(x.id);\n if (!entries) {\n entries = [];\n matches.set(x.id, entries);\n }\n // make sure that we don't have path identifiers that only differ by class name, where\n // class names are in the same class hierarchy, e.g.:\n // [{ className: \"bis.Element\", id: \"0x1\" }, { className: \"bis.Subject\", id: \"0x1\" }]\n // are actually the same instance, so we only need to keep one of them, or otherwise the query will\n // duplicate it\n for (const entry of entries) {\n if (\n entry.className === x.className ||\n (await imodelAccess.classDerivesFrom(entry.className, x.className)) ||\n (await imodelAccess.classDerivesFrom(x.className, entry.className))\n ) {\n return undefined;\n }\n }\n return entries;\n }\n for (const id of childNodeFilteringIdentifiers) {\n // take only identifiers that match the definition by type, source and class\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(id)) {\n continue;\n }\n if (id.imodelKey && id.imodelKey !== imodelAccess.imodelKey) {\n continue;\n }\n if (\n id.className !== definition.fullClassName &&\n !(await Promise.all([\n imodelAccess.classDerivesFrom(id.className, definition.fullClassName),\n imodelAccess.classDerivesFrom(definition.fullClassName, id.className),\n ]).then(([isDerivedFrom, isDerivedTo]) => isDerivedFrom || isDerivedTo))\n ) {\n continue;\n }\n const entriesTargetForPathIdentifier = await getEntries(id);\n if (entriesTargetForPathIdentifier) {\n entriesTargetForPathIdentifier.push(id);\n }\n }\n return Array.from(matches.values()).flat();\n }).pipe(\n // only take definitions that have matching path identifiers\n filter((pathIdentifiers) => pathIdentifiers.length > 0),\n\n // for each definition that we're going to use, apply query-level filter\n map((pathIdentifiers) => applyECInstanceIdsFilter(definition, pathIdentifiers)),\n );\n }),\n ),\n ).pipe(toArray()),\n );\n }\n}\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_FilterECInstanceId = \"FilterECInstanceId\";\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_FilterClassName = \"FilterClassName\";\n\nfunction getClassECInstanceIds(filteredInstanceKeys: InstanceKey[]) {\n const classNameECInstanceIds = new Map<string, Id64String[]>();\n for (const key of filteredInstanceKeys) {\n const entry = classNameECInstanceIds.get(key.className);\n if (entry === undefined) {\n classNameECInstanceIds.set(key.className, [key.id]);\n continue;\n }\n entry.push(key.id);\n }\n return classNameECInstanceIds;\n}\n\n/** @internal */\nexport function applyECInstanceIdsFilter(def: InstanceNodesQueryDefinition, filteredInstanceKeys: InstanceKey[]): InstanceNodesQueryDefinition {\n const instanceIdsByClass = getClassECInstanceIds(filteredInstanceKeys);\n return {\n ...def,\n query: {\n ...def.query,\n ctes: [\n ...(def.query.ctes ?? []),\n `FilteringInfo(ECInstanceId, FilterClassName) AS (\n ${Array.from(instanceIdsByClass)\n .map(\n ([className, ecInstanceIds]) => `\n SELECT ECInstanceId, '${className}' AS FilterClassName\n FROM ${className}\n WHERE ECInstanceId IN (${ecInstanceIds.join(\", \")})\n `,\n )\n .join(\" UNION ALL \")}\n )`,\n ],\n ecsql: `\n SELECT\n [q].*,\n IdToHex([f].[ECInstanceId]) AS [${ECSQL_COLUMN_NAME_FilterECInstanceId}],\n [f].[FilterClassName] AS [${ECSQL_COLUMN_NAME_FilterClassName}]\n FROM (\n ${def.query.ecsql}\n ) [q]\n JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]\n `,\n },\n };\n}\n\n/** @internal */\nexport function applyECInstanceIdsSelector(def: InstanceNodesQueryDefinition): InstanceNodesQueryDefinition {\n return {\n ...def,\n query: {\n ...def.query,\n ecsql: `\n SELECT\n [q].*,\n IdToHex([q].[ECInstanceId]) AS [${ECSQL_COLUMN_NAME_FilterECInstanceId}],\n [q].[${NodeSelectClauseColumnNames.FullClassName}] AS [${ECSQL_COLUMN_NAME_FilterClassName}]\n FROM (${def.query.ecsql}) [q]\n `,\n },\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IModelHierarchyProvider.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/IModelHierarchyProvider.ts"],"names":[],"mappings":"AA2BA,OAAO,EAGL,yBAAyB,EACzB,gBAAgB,EAGhB,KAAK,EAGL,wBAAwB,EAEzB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAA0B,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAiBpF,OAAO,EAA6B,mBAAmB,EAA4B,MAAM,gCAAgC,CAAC;AAS1H,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAe7E;;;GAGG;AACH,UAAU,uCAAuC;IAC/C;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,cAAc;AACd,KAAK,YAAY,GAAG,gBAAgB,GAAG,0BAA0B,GAAG,yBAAyB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtH;;;GAGG;AACH,UAAU,4BAA4B;IACpC;;;;;;OAMG;IACH,YAAY,EAAE,YAAY,CAAC;IAE3B,wFAAwF;IACxF,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAElC;;;OAGG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;IAEzC,qGAAqG;IACrG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,OAAO,CAAC,uCAAuC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,SAAS,CAAC,EAAE,wBAAwB,CAAC;IACrC,yCAAyC;IACzC,SAAS,CAAC,EAAE;QACV,2DAA2D;QAC3D,KAAK,EAAE,sBAAsB,EAAE,CAAC;KACjC,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,4BAA4B,GAAG,iBAAiB,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAE9H"}
1
+ {"version":3,"file":"IModelHierarchyProvider.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/IModelHierarchyProvider.ts"],"names":[],"mappings":"AA2BA,OAAO,EAGL,yBAAyB,EACzB,gBAAgB,EAGhB,KAAK,EAIL,wBAAwB,EAEzB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAA0B,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAiBpF,OAAO,EAA6B,mBAAmB,EAA4B,MAAM,gCAAgC,CAAC;AAS1H,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAe7E;;;GAGG;AACH,UAAU,uCAAuC;IAC/C;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,cAAc;AACd,KAAK,YAAY,GAAG,gBAAgB,GAAG,0BAA0B,GAAG,yBAAyB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtH;;;GAGG;AACH,UAAU,4BAA4B;IACpC;;;;;;OAMG;IACH,YAAY,EAAE,YAAY,CAAC;IAE3B,wFAAwF;IACxF,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAElC;;;OAGG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;IAEzC,qGAAqG;IACrG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,OAAO,CAAC,uCAAuC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,SAAS,CAAC,EAAE,wBAAwB,CAAC;IACrC,yCAAyC;IACzC,SAAS,CAAC,EAAE;QACV,2DAA2D;QAC3D,KAAK,EAAE,sBAAsB,EAAE,CAAC;KACjC,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,4BAA4B,GAAG,iBAAiB,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAE9H"}
@@ -44,7 +44,7 @@ function createIModelHierarchyProvider(props) {
44
44
  }
45
45
  class IModelHierarchyProviderImpl {
46
46
  _imodelAccess;
47
- _imodelChanged;
47
+ _hierarchyChanged;
48
48
  _valuesFormatter;
49
49
  _sourceHierarchyDefinition;
50
50
  _activeHierarchyDefinition;
@@ -55,7 +55,7 @@ class IModelHierarchyProviderImpl {
55
55
  _dispose = new rxjs_1.Subject();
56
56
  constructor(props) {
57
57
  this._imodelAccess = props.imodelAccess;
58
- this._imodelChanged = props.imodelChanged ?? new core_bentley_1.BeEvent();
58
+ this._hierarchyChanged = new core_bentley_1.BeEvent();
59
59
  this._activeHierarchyDefinition = this._sourceHierarchyDefinition = props.hierarchyDefinition;
60
60
  this._valuesFormatter = props?.formatter ?? (0, presentation_shared_1.createDefaultValueFormatter)();
61
61
  this._localizedStrings = { other: "Other", unspecified: "Not specified", ...props?.localizedStrings };
@@ -68,18 +68,19 @@ class IModelHierarchyProviderImpl {
68
68
  size: Math.ceil(queryCacheSize / 2),
69
69
  variationsCount: 1,
70
70
  });
71
- this._unsubscribe = props.imodelChanged?.addListener(() => {
72
- this.invalidateHierarchyCache("Data source changed");
73
- this._dispose.next();
74
- });
75
71
  }
72
+ this._unsubscribe = props.imodelChanged?.addListener(() => {
73
+ this.invalidateHierarchyCache("Data source changed");
74
+ this._dispose.next();
75
+ this._hierarchyChanged.raiseEvent();
76
+ });
76
77
  }
77
78
  dispose() {
78
79
  this._dispose.next();
79
80
  this._unsubscribe?.();
80
81
  }
81
82
  get hierarchyChanged() {
82
- return this._imodelChanged;
83
+ return this._hierarchyChanged;
83
84
  }
84
85
  invalidateHierarchyCache(reason) {
85
86
  (0, LoggingUtils_js_1.doLog)({
@@ -94,6 +95,7 @@ class IModelHierarchyProviderImpl {
94
95
  */
95
96
  setFormatter(formatter) {
96
97
  this._valuesFormatter = formatter ?? (0, presentation_shared_1.createDefaultValueFormatter)();
98
+ this._hierarchyChanged.raiseEvent({ formatterChange: { newFormatter: this._valuesFormatter } });
97
99
  }
98
100
  setHierarchyFilter(props) {
99
101
  if (!props) {
@@ -101,6 +103,7 @@ class IModelHierarchyProviderImpl {
101
103
  this._activeHierarchyDefinition = this._sourceHierarchyDefinition;
102
104
  this.invalidateHierarchyCache("Hierarchy filter reset");
103
105
  }
106
+ this._hierarchyChanged.raiseEvent({ filterChange: { newFilter: undefined } });
104
107
  return;
105
108
  }
106
109
  this._activeHierarchyDefinition = new FilteringHierarchyDefinition_js_1.FilteringHierarchyDefinition({
@@ -110,6 +113,7 @@ class IModelHierarchyProviderImpl {
110
113
  });
111
114
  this.invalidateHierarchyCache("Hierarchy filter set");
112
115
  this._dispose.next();
116
+ this._hierarchyChanged.raiseEvent({ filterChange: { newFilter: props } });
113
117
  }
114
118
  onGroupingNodeCreated(groupingNode, props) {
115
119
  this._nodesCache?.set({ ...props, parentNode: groupingNode }, { observable: (0, rxjs_1.from)(groupingNode.children), processingStatus: "pre-processed" });