@itwin/grouping-mapping-widget 0.3.4 → 0.5.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 (197) hide show
  1. package/lib/cjs/formula/FormulaDataTypeResolver.d.ts +12 -0
  2. package/lib/cjs/formula/FormulaDataTypeResolver.js +50 -0
  3. package/lib/cjs/formula/FormulaDataTypeResolver.js.map +1 -0
  4. package/lib/cjs/formula/FormulaFunctionProvider.js +59 -59
  5. package/lib/cjs/formula/FormulaFunctionProvider.js.map +1 -1
  6. package/lib/cjs/formula/FormulaOperatorsProvider.js +7 -7
  7. package/lib/cjs/formula/FormulaOperatorsProvider.js.map +1 -1
  8. package/lib/cjs/formula/FormulaTokensDataTypeResolver.d.ts +6 -0
  9. package/lib/cjs/formula/{FormulaTokensValidator.js → FormulaTokensDataTypeResolver.js} +33 -31
  10. package/lib/cjs/formula/FormulaTokensDataTypeResolver.js.map +1 -0
  11. package/lib/cjs/formula/Types.d.ts +2 -2
  12. package/lib/cjs/formula/Types.js.map +1 -1
  13. package/lib/cjs/grouping-mapping-widget.d.ts +9 -0
  14. package/lib/cjs/grouping-mapping-widget.js +9 -1
  15. package/lib/cjs/grouping-mapping-widget.js.map +1 -1
  16. package/lib/cjs/widget/GroupingMappingWidget.d.ts +3 -4
  17. package/lib/cjs/widget/GroupingMappingWidget.js +3 -4
  18. package/lib/cjs/widget/GroupingMappingWidget.js.map +1 -1
  19. package/lib/cjs/widget/IMappingClient.d.ts +327 -0
  20. package/lib/cjs/widget/IMappingClient.js +7 -0
  21. package/lib/cjs/widget/IMappingClient.js.map +1 -0
  22. package/lib/cjs/widget/components/CalculatedPropertyAction.js +7 -6
  23. package/lib/cjs/widget/components/CalculatedPropertyAction.js.map +1 -1
  24. package/lib/cjs/widget/components/CalculatedPropertyTable.js +6 -5
  25. package/lib/cjs/widget/components/CalculatedPropertyTable.js.map +1 -1
  26. package/lib/cjs/widget/components/ConfirmMappingsImport.js +6 -5
  27. package/lib/cjs/widget/components/ConfirmMappingsImport.js.map +1 -1
  28. package/lib/cjs/widget/components/CustomCalculationAction.js +8 -7
  29. package/lib/cjs/widget/components/CustomCalculationAction.js.map +1 -1
  30. package/lib/cjs/widget/components/CustomCalculationTable.js +6 -5
  31. package/lib/cjs/widget/components/CustomCalculationTable.js.map +1 -1
  32. package/lib/cjs/widget/components/GroupAction.d.ts +2 -1
  33. package/lib/cjs/widget/components/GroupAction.js +21 -14
  34. package/lib/cjs/widget/components/GroupAction.js.map +1 -1
  35. package/lib/cjs/widget/components/GroupPropertyAction.js +19 -10
  36. package/lib/cjs/widget/components/GroupPropertyAction.js.map +1 -1
  37. package/lib/cjs/widget/components/GroupPropertyTable.js +6 -5
  38. package/lib/cjs/widget/components/GroupPropertyTable.js.map +1 -1
  39. package/lib/cjs/widget/components/GroupQueryBuilderContainer.js +8 -5
  40. package/lib/cjs/widget/components/GroupQueryBuilderContainer.js.map +1 -1
  41. package/lib/cjs/widget/components/GroupTile.d.ts +13 -0
  42. package/lib/cjs/widget/components/GroupTile.js +18 -0
  43. package/lib/cjs/widget/components/GroupTile.js.map +1 -0
  44. package/lib/cjs/widget/components/GroupTile.scss +32 -0
  45. package/lib/cjs/widget/components/Grouping.js +215 -166
  46. package/lib/cjs/widget/components/Grouping.js.map +1 -1
  47. package/lib/cjs/widget/components/Grouping.scss +39 -4
  48. package/lib/cjs/widget/components/GroupingMapping.d.ts +18 -11
  49. package/lib/cjs/widget/components/GroupingMapping.js +24 -15
  50. package/lib/cjs/widget/components/GroupingMapping.js.map +1 -1
  51. package/lib/cjs/widget/components/Mapping.js +20 -17
  52. package/lib/cjs/widget/components/Mapping.js.map +1 -1
  53. package/lib/cjs/widget/components/MappingAction.js +8 -7
  54. package/lib/cjs/widget/components/MappingAction.js.map +1 -1
  55. package/lib/cjs/widget/components/PropertyMenu.js +34 -26
  56. package/lib/cjs/widget/components/PropertyMenu.js.map +1 -1
  57. package/lib/cjs/widget/components/QueryBuilder.d.ts +10 -4
  58. package/lib/cjs/widget/components/QueryBuilder.js +223 -141
  59. package/lib/cjs/widget/components/QueryBuilder.js.map +1 -1
  60. package/lib/cjs/widget/components/SelectIModel.js +13 -4
  61. package/lib/cjs/widget/components/SelectIModel.js.map +1 -1
  62. package/lib/cjs/widget/components/SelectMappings.js +9 -8
  63. package/lib/cjs/widget/components/SelectMappings.js.map +1 -1
  64. package/lib/cjs/widget/components/SelectProject.js +13 -4
  65. package/lib/cjs/widget/components/SelectProject.js.map +1 -1
  66. package/lib/cjs/widget/components/{GroupQueryBuilderContext.d.ts → context/GroupQueryBuilderContext.d.ts} +2 -1
  67. package/lib/cjs/widget/components/{GroupQueryBuilderContext.js → context/GroupQueryBuilderContext.js} +2 -1
  68. package/lib/cjs/widget/components/context/GroupQueryBuilderContext.js.map +1 -0
  69. package/lib/cjs/widget/components/context/GroupingApiConfigContext.d.ts +11 -0
  70. package/lib/cjs/widget/components/context/GroupingApiConfigContext.js +37 -0
  71. package/lib/cjs/widget/components/context/GroupingApiConfigContext.js.map +1 -0
  72. package/lib/cjs/widget/components/context/MappingClientContext.d.ts +7 -0
  73. package/lib/cjs/widget/components/context/MappingClientContext.js +30 -0
  74. package/lib/cjs/widget/components/context/MappingClientContext.js.map +1 -0
  75. package/lib/cjs/widget/components/property-grid/PropertyGrid.d.ts +1 -1
  76. package/lib/cjs/widget/components/property-grid/PropertyGrid.js +5 -5
  77. package/lib/cjs/widget/components/property-grid/PropertyGrid.js.map +1 -1
  78. package/lib/cjs/widget/components/property-grid/PropertyGridWrapper.d.ts +1 -1
  79. package/lib/cjs/widget/components/property-grid/PropertyGridWrapper.js +2 -2
  80. package/lib/cjs/widget/components/property-grid/PropertyGridWrapper.js.map +1 -1
  81. package/lib/cjs/widget/components/property-grid/PropertyView.js +14 -6
  82. package/lib/cjs/widget/components/property-grid/PropertyView.js.map +1 -1
  83. package/lib/cjs/widget/components/utils.d.ts +6 -0
  84. package/lib/cjs/widget/components/utils.js +9 -1
  85. package/lib/cjs/widget/components/utils.js.map +1 -1
  86. package/lib/cjs/widget/components/utils.scss +12 -3
  87. package/lib/cjs/widget/components/viewerUtils.d.ts +19 -0
  88. package/lib/cjs/widget/components/viewerUtils.js +224 -3
  89. package/lib/cjs/widget/components/viewerUtils.js.map +1 -1
  90. package/lib/cjs/widget/hooks/useFormulaValidation.d.ts +1 -1
  91. package/lib/cjs/widget/hooks/useFormulaValidation.js +7 -6
  92. package/lib/cjs/widget/hooks/useFormulaValidation.js.map +1 -1
  93. package/lib/esm/formula/FormulaDataTypeResolver.d.ts +12 -0
  94. package/lib/esm/formula/FormulaDataTypeResolver.js +46 -0
  95. package/lib/esm/formula/FormulaDataTypeResolver.js.map +1 -0
  96. package/lib/esm/formula/FormulaFunctionProvider.js +59 -59
  97. package/lib/esm/formula/FormulaFunctionProvider.js.map +1 -1
  98. package/lib/esm/formula/FormulaOperatorsProvider.js +7 -7
  99. package/lib/esm/formula/FormulaOperatorsProvider.js.map +1 -1
  100. package/lib/esm/formula/FormulaTokensDataTypeResolver.d.ts +6 -0
  101. package/lib/esm/formula/{FormulaTokensValidator.js → FormulaTokensDataTypeResolver.js} +31 -29
  102. package/lib/esm/formula/FormulaTokensDataTypeResolver.js.map +1 -0
  103. package/lib/esm/formula/Types.d.ts +2 -2
  104. package/lib/esm/formula/Types.js.map +1 -1
  105. package/lib/esm/grouping-mapping-widget.d.ts +9 -0
  106. package/lib/esm/grouping-mapping-widget.js +6 -0
  107. package/lib/esm/grouping-mapping-widget.js.map +1 -1
  108. package/lib/esm/widget/GroupingMappingWidget.d.ts +3 -4
  109. package/lib/esm/widget/GroupingMappingWidget.js +3 -4
  110. package/lib/esm/widget/GroupingMappingWidget.js.map +1 -1
  111. package/lib/esm/widget/IMappingClient.d.ts +327 -0
  112. package/lib/esm/widget/IMappingClient.js +6 -0
  113. package/lib/esm/widget/IMappingClient.js.map +1 -0
  114. package/lib/esm/widget/components/CalculatedPropertyAction.js +8 -7
  115. package/lib/esm/widget/components/CalculatedPropertyAction.js.map +1 -1
  116. package/lib/esm/widget/components/CalculatedPropertyTable.js +7 -6
  117. package/lib/esm/widget/components/CalculatedPropertyTable.js.map +1 -1
  118. package/lib/esm/widget/components/ConfirmMappingsImport.js +7 -6
  119. package/lib/esm/widget/components/ConfirmMappingsImport.js.map +1 -1
  120. package/lib/esm/widget/components/CustomCalculationAction.js +9 -8
  121. package/lib/esm/widget/components/CustomCalculationAction.js.map +1 -1
  122. package/lib/esm/widget/components/CustomCalculationTable.js +7 -6
  123. package/lib/esm/widget/components/CustomCalculationTable.js.map +1 -1
  124. package/lib/esm/widget/components/GroupAction.d.ts +2 -1
  125. package/lib/esm/widget/components/GroupAction.js +23 -16
  126. package/lib/esm/widget/components/GroupAction.js.map +1 -1
  127. package/lib/esm/widget/components/GroupPropertyAction.js +20 -11
  128. package/lib/esm/widget/components/GroupPropertyAction.js.map +1 -1
  129. package/lib/esm/widget/components/GroupPropertyTable.js +7 -6
  130. package/lib/esm/widget/components/GroupPropertyTable.js.map +1 -1
  131. package/lib/esm/widget/components/GroupQueryBuilderContainer.js +8 -5
  132. package/lib/esm/widget/components/GroupQueryBuilderContainer.js.map +1 -1
  133. package/lib/esm/widget/components/GroupTile.d.ts +13 -0
  134. package/lib/esm/widget/components/GroupTile.js +11 -0
  135. package/lib/esm/widget/components/GroupTile.js.map +1 -0
  136. package/lib/esm/widget/components/GroupTile.scss +32 -0
  137. package/lib/esm/widget/components/Grouping.js +220 -171
  138. package/lib/esm/widget/components/Grouping.js.map +1 -1
  139. package/lib/esm/widget/components/Grouping.scss +39 -4
  140. package/lib/esm/widget/components/GroupingMapping.d.ts +18 -11
  141. package/lib/esm/widget/components/GroupingMapping.js +25 -15
  142. package/lib/esm/widget/components/GroupingMapping.js.map +1 -1
  143. package/lib/esm/widget/components/Mapping.js +21 -18
  144. package/lib/esm/widget/components/Mapping.js.map +1 -1
  145. package/lib/esm/widget/components/MappingAction.js +9 -8
  146. package/lib/esm/widget/components/MappingAction.js.map +1 -1
  147. package/lib/esm/widget/components/PropertyMenu.js +36 -28
  148. package/lib/esm/widget/components/PropertyMenu.js.map +1 -1
  149. package/lib/esm/widget/components/QueryBuilder.d.ts +10 -4
  150. package/lib/esm/widget/components/QueryBuilder.js +224 -142
  151. package/lib/esm/widget/components/QueryBuilder.js.map +1 -1
  152. package/lib/esm/widget/components/SelectIModel.js +14 -5
  153. package/lib/esm/widget/components/SelectIModel.js.map +1 -1
  154. package/lib/esm/widget/components/SelectMappings.js +10 -9
  155. package/lib/esm/widget/components/SelectMappings.js.map +1 -1
  156. package/lib/esm/widget/components/SelectProject.js +14 -5
  157. package/lib/esm/widget/components/SelectProject.js.map +1 -1
  158. package/lib/esm/widget/components/{GroupQueryBuilderContext.d.ts → context/GroupQueryBuilderContext.d.ts} +2 -1
  159. package/lib/esm/widget/components/{GroupQueryBuilderContext.js → context/GroupQueryBuilderContext.js} +2 -1
  160. package/lib/esm/widget/components/context/GroupQueryBuilderContext.js.map +1 -0
  161. package/lib/esm/widget/components/context/GroupingApiConfigContext.d.ts +11 -0
  162. package/lib/esm/widget/components/context/GroupingApiConfigContext.js +14 -0
  163. package/lib/esm/widget/components/context/GroupingApiConfigContext.js.map +1 -0
  164. package/lib/esm/widget/components/context/MappingClientContext.d.ts +7 -0
  165. package/lib/esm/widget/components/context/MappingClientContext.js +25 -0
  166. package/lib/esm/widget/components/context/MappingClientContext.js.map +1 -0
  167. package/lib/esm/widget/components/property-grid/PropertyGrid.d.ts +1 -1
  168. package/lib/esm/widget/components/property-grid/PropertyGrid.js +6 -6
  169. package/lib/esm/widget/components/property-grid/PropertyGrid.js.map +1 -1
  170. package/lib/esm/widget/components/property-grid/PropertyGridWrapper.d.ts +1 -1
  171. package/lib/esm/widget/components/property-grid/PropertyGridWrapper.js +2 -2
  172. package/lib/esm/widget/components/property-grid/PropertyGridWrapper.js.map +1 -1
  173. package/lib/esm/widget/components/property-grid/PropertyView.js +14 -6
  174. package/lib/esm/widget/components/property-grid/PropertyView.js.map +1 -1
  175. package/lib/esm/widget/components/utils.d.ts +6 -0
  176. package/lib/esm/widget/components/utils.js +6 -0
  177. package/lib/esm/widget/components/utils.js.map +1 -1
  178. package/lib/esm/widget/components/utils.scss +12 -3
  179. package/lib/esm/widget/components/viewerUtils.d.ts +19 -0
  180. package/lib/esm/widget/components/viewerUtils.js +207 -3
  181. package/lib/esm/widget/components/viewerUtils.js.map +1 -1
  182. package/lib/esm/widget/hooks/useFormulaValidation.d.ts +1 -1
  183. package/lib/esm/widget/hooks/useFormulaValidation.js +7 -6
  184. package/lib/esm/widget/hooks/useFormulaValidation.js.map +1 -1
  185. package/package.json +30 -30
  186. package/lib/cjs/formula/FormulaTokensValidator.d.ts +0 -5
  187. package/lib/cjs/formula/FormulaTokensValidator.js.map +0 -1
  188. package/lib/cjs/formula/FormulaValidator.d.ts +0 -3
  189. package/lib/cjs/formula/FormulaValidator.js +0 -35
  190. package/lib/cjs/formula/FormulaValidator.js.map +0 -1
  191. package/lib/cjs/widget/components/GroupQueryBuilderContext.js.map +0 -1
  192. package/lib/esm/formula/FormulaTokensValidator.d.ts +0 -5
  193. package/lib/esm/formula/FormulaTokensValidator.js.map +0 -1
  194. package/lib/esm/formula/FormulaValidator.d.ts +0 -3
  195. package/lib/esm/formula/FormulaValidator.js +0 -31
  196. package/lib/esm/formula/FormulaValidator.js.map +0 -1
  197. package/lib/esm/widget/components/GroupQueryBuilderContext.js.map +0 -1
@@ -12,8 +12,13 @@ class QueryBuilder {
12
12
  constructor(provider) {
13
13
  this.dataProvider = provider;
14
14
  }
15
+ isCategory(propertyField) {
16
+ var _a;
17
+ const classInfo = (_a = propertyField.properties[0].property.navigationPropertyInfo) === null || _a === void 0 ? void 0 : _a.classInfo;
18
+ return (classInfo === null || classInfo === void 0 ? void 0 : classInfo.name) === "BisCore:GeometricElement3dIsInCategory";
19
+ }
15
20
  async addProperty(prop) {
16
- var _a, _b, _c, _d, _e;
21
+ var _a, _b, _c, _d, _e, _f, _g;
17
22
  // TODO: only handle primitive properties now
18
23
  if (((_a = prop.value) === null || _a === void 0 ? void 0 : _a.valueFormat) !== appui_abstract_1.PropertyValueFormat.Primitive) {
19
24
  itwinui_react_1.toaster.warning("Only primitive types are supported for now.");
@@ -31,35 +36,42 @@ class QueryBuilder {
31
36
  String(prop.value.value).indexOf("'") >= 0) {
32
37
  prop.value.value = replaceAll(prop.value.value.toString(), "'", "''");
33
38
  }
34
- const propertyField = (await ((_b = this.dataProvider) === null || _b === void 0 ? void 0 : _b.getFieldByPropertyRecord(prop)));
35
- if (propertyField === undefined) {
39
+ // get descriptor
40
+ const descriptor = await ((_b = this.dataProvider) === null || _b === void 0 ? void 0 : _b.getContentDescriptor());
41
+ const propertyField = (await ((_c = this.dataProvider) === null || _c === void 0 ? void 0 : _c.getFieldByPropertyRecord(prop)));
42
+ if (!descriptor || !propertyField) {
36
43
  itwinui_react_1.toaster.negative("Error. Failed to fetch field for this property record.");
37
44
  return false;
38
45
  }
39
46
  // get the special cases
40
47
  const isNavigation = prop.property.typename.toLowerCase() === "navigation";
41
- const isAspect = ((_c = propertyField.parent) === null || _c === void 0 ? void 0 : _c.pathToPrimaryClass.find((a) => {
48
+ const isCategory = isNavigation && this.isCategory(propertyField);
49
+ const isAspect = ((_d = propertyField.parent) === null || _d === void 0 ? void 0 : _d.pathToPrimaryClass.find((a) => {
42
50
  var _a, _b;
43
51
  return ((_a = a.relationshipInfo) === null || _a === void 0 ? void 0 : _a.name) ===
44
52
  QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||
45
53
  ((_b = a.relationshipInfo) === null || _b === void 0 ? void 0 : _b.name) === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS;
46
54
  })) !== undefined;
47
- const className = propertyField.properties[0].property.classInfo.name.replace(":", ".");
48
- const propertyName = isNavigation
49
- ? `${propertyField.properties[0].property.name}.id`
50
- : propertyField.properties[0].property.name;
51
- const propertyValue = isNavigation
52
- ? prop.value.value.id
53
- : prop.value.value;
54
- // console.log(prop);
55
- // console.log(propertyField);
56
- if (!isAspect &&
57
- ((_d = propertyField.parent) === null || _d === void 0 ? void 0 : _d.pathToPrimaryClass) &&
58
- ((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.pathToPrimaryClass.length) > 0) {
59
- this.addRelatedProperty(propertyField, propertyName, propertyValue, isAspect);
60
- }
61
- else {
62
- this.addPropertyToQuery(className, propertyName, propertyValue, isAspect, this._needsQuote(propertyField), false);
55
+ for (let i = 0; i < propertyField.properties.length; i++) {
56
+ const className = propertyField.properties[i].property.classInfo.name.replace(":", ".");
57
+ const propertyName = isNavigation
58
+ ? isCategory
59
+ ? `${propertyField.properties[i].property.name}.CodeValue`
60
+ : `${propertyField.properties[i].property.name}.id`
61
+ : propertyField.properties[i].property.name;
62
+ const propertyValue = isNavigation
63
+ ? isCategory
64
+ ? (_e = prop.value.displayValue) !== null && _e !== void 0 ? _e : ""
65
+ : prop.value.value.id
66
+ : prop.value.value;
67
+ if (!isAspect &&
68
+ ((_f = propertyField.parent) === null || _f === void 0 ? void 0 : _f.pathToPrimaryClass) &&
69
+ ((_g = propertyField.parent) === null || _g === void 0 ? void 0 : _g.pathToPrimaryClass.length) > 0) {
70
+ this.addRelatedProperty(i, propertyField, propertyName, propertyValue, isAspect);
71
+ }
72
+ else {
73
+ this.addPropertyToQuery(i, className, propertyName, propertyValue, isAspect, this._needsQuote(propertyField), isCategory, false);
74
+ }
63
75
  }
64
76
  return true;
65
77
  }
@@ -73,7 +85,7 @@ class QueryBuilder {
73
85
  }
74
86
  return false;
75
87
  }
76
- addRelatedProperty(propertyField, propertyName, propertyValue, isAspect) {
88
+ addRelatedProperty(unionIndex, propertyField, propertyName, propertyValue, isAspect) {
77
89
  var _a, _b;
78
90
  const paths = [...((_b = (_a = propertyField.parent) === null || _a === void 0 ? void 0 : _a.pathToPrimaryClass) !== null && _b !== void 0 ? _b : [])];
79
91
  paths.reverse().forEach((path) => {
@@ -82,32 +94,56 @@ class QueryBuilder {
82
94
  const targetClassName = (_b = path.targetClassInfo) === null || _b === void 0 ? void 0 : _b.name.replace(":", ".");
83
95
  const relClassName = (_c = path.relationshipInfo) === null || _c === void 0 ? void 0 : _c.name.replace(":", ".");
84
96
  if (!path.isForwardRelationship) {
85
- this.addPropertyToQuery(targetClassName, `ECInstanceId`, `${relClassName}.SourceECInstanceId`, isAspect, false, true);
86
- this.addPropertyToQuery(relClassName, `TargetECInstanceId`, `${sourceClassName}.ECInstanceId`, isAspect, false, true);
97
+ this.addPropertyToQuery(unionIndex, targetClassName, `ECInstanceId`, `${relClassName}.SourceECInstanceId`, isAspect, false, false, true);
98
+ this.addPropertyToQuery(unionIndex, relClassName, `TargetECInstanceId`, `${sourceClassName}.ECInstanceId`, isAspect, false, false, true);
87
99
  if (((_d = path.sourceClassInfo) === null || _d === void 0 ? void 0 : _d.name) ===
88
100
  ((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.contentClassInfo.name)) {
89
- this.addPropertyToQuery(sourceClassName, propertyName, propertyValue, isAspect, this._needsQuote(propertyField), true);
101
+ this.addPropertyToQuery(unionIndex, sourceClassName, propertyName, propertyValue, isAspect, this._needsQuote(propertyField), false, true);
90
102
  }
91
103
  else {
92
- this.addPropertyToQuery(sourceClassName, `ECInstanceId`, `${relClassName}.TargetECInstanceId`, isAspect, false, true);
104
+ this.addPropertyToQuery(unionIndex, sourceClassName, `ECInstanceId`, `${relClassName}.TargetECInstanceId`, isAspect, false, false, true);
93
105
  }
94
106
  }
95
107
  else {
96
- this.addPropertyToQuery(targetClassName, `ECInstanceId`, `${relClassName}.TargetECInstanceId`, isAspect, false, true);
97
- this.addPropertyToQuery(relClassName, `SourceECInstanceId`, `${sourceClassName}.ECInstanceId`, isAspect, false, true);
108
+ this.addPropertyToQuery(unionIndex, targetClassName, `ECInstanceId`, `${relClassName}.TargetECInstanceId`, isAspect, false, false, true);
109
+ this.addPropertyToQuery(unionIndex, relClassName, `SourceECInstanceId`, `${sourceClassName}.ECInstanceId`, isAspect, false, false, true);
98
110
  if (((_f = path.sourceClassInfo) === null || _f === void 0 ? void 0 : _f.name) ===
99
111
  ((_g = propertyField.parent) === null || _g === void 0 ? void 0 : _g.contentClassInfo.name)) {
100
- this.addPropertyToQuery(sourceClassName, propertyName, propertyValue, isAspect, this._needsQuote(propertyField), true);
112
+ this.addPropertyToQuery(unionIndex, sourceClassName, propertyName, propertyValue, isAspect, this._needsQuote(propertyField), false, true);
101
113
  }
102
114
  else {
103
- this.addPropertyToQuery(sourceClassName, `ECInstanceId`, `${relClassName}.SourceECInstanceId`, isAspect, false, true);
115
+ this.addPropertyToQuery(unionIndex, sourceClassName, `ECInstanceId`, `${relClassName}.SourceECInstanceId`, isAspect, false, false, true);
104
116
  }
105
117
  }
106
118
  });
107
119
  }
108
- addPropertyToQuery(className, propertyName, propertyValue, isAspect, needsQuote, isRelational) {
109
- if (this.query === undefined || this.query.classes.length === 0) {
120
+ addPropertyToQuery(unionIndex, className, propertyName, propertyValue, isAspect, needsQuote, isCategory, isRelational) {
121
+ if (this.query === undefined || this.query.unions.length === 0) {
110
122
  this.query = {
123
+ unions: [
124
+ {
125
+ classes: [
126
+ {
127
+ className,
128
+ isAspect,
129
+ isRelational,
130
+ properties: [
131
+ {
132
+ name: propertyName,
133
+ value: propertyValue,
134
+ needsQuote,
135
+ isCategory,
136
+ },
137
+ ],
138
+ },
139
+ ],
140
+ },
141
+ ],
142
+ };
143
+ return;
144
+ }
145
+ if (this.query.unions.length <= unionIndex) {
146
+ this.query.unions.push({
111
147
  classes: [
112
148
  {
113
149
  className,
@@ -118,14 +154,15 @@ class QueryBuilder {
118
154
  name: propertyName,
119
155
  value: propertyValue,
120
156
  needsQuote,
157
+ isCategory,
121
158
  },
122
159
  ],
123
160
  },
124
161
  ],
125
- };
162
+ });
126
163
  return;
127
164
  }
128
- const foundClass = this.query.classes.find((c) => c.className === className);
165
+ const foundClass = this.query.unions[unionIndex].classes.find((c) => c.className === className);
129
166
  if (foundClass) {
130
167
  foundClass.isRelational = isRelational;
131
168
  if (!foundClass.properties.find((x) => x.name === propertyName)) {
@@ -133,11 +170,12 @@ class QueryBuilder {
133
170
  name: propertyName,
134
171
  value: propertyValue,
135
172
  needsQuote,
173
+ isCategory,
136
174
  });
137
175
  }
138
176
  }
139
177
  else {
140
- this.query.classes.push({
178
+ this.query.unions[unionIndex].classes.push({
141
179
  className,
142
180
  isRelational,
143
181
  properties: [
@@ -145,6 +183,7 @@ class QueryBuilder {
145
183
  name: propertyName,
146
184
  value: propertyValue,
147
185
  needsQuote,
186
+ isCategory,
148
187
  },
149
188
  ],
150
189
  isAspect,
@@ -152,35 +191,45 @@ class QueryBuilder {
152
191
  }
153
192
  }
154
193
  async removeProperty(prop) {
155
- var _a, _b, _c, _d;
156
- if (this.query === undefined || this.query.classes.length === 0) {
194
+ var _a, _b, _c, _d, _e;
195
+ if (this.query === undefined || this.query.unions.length === 0) {
196
+ return;
197
+ }
198
+ if (this.query.unions.length === 1 &&
199
+ this.query.unions[0].classes.length === 0) {
157
200
  return;
158
201
  }
159
- const propertyField = (await ((_a = this.dataProvider) === null || _a === void 0 ? void 0 : _a.getFieldByPropertyRecord(prop)));
160
- if (propertyField === undefined) {
202
+ const descriptor = await ((_a = this.dataProvider) === null || _a === void 0 ? void 0 : _a.getContentDescriptor());
203
+ const propertyField = (await ((_b = this.dataProvider) === null || _b === void 0 ? void 0 : _b.getFieldByPropertyRecord(prop)));
204
+ if (!descriptor || !propertyField) {
161
205
  return;
162
206
  }
163
- const isAspect = ((_b = propertyField.parent) === null || _b === void 0 ? void 0 : _b.pathToPrimaryClass.find((a) => {
207
+ const isAspect = ((_c = propertyField.parent) === null || _c === void 0 ? void 0 : _c.pathToPrimaryClass.find((a) => {
164
208
  var _a, _b;
165
209
  return ((_a = a.relationshipInfo) === null || _a === void 0 ? void 0 : _a.name) ===
166
210
  QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||
167
211
  ((_b = a.relationshipInfo) === null || _b === void 0 ? void 0 : _b.name) === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS;
168
212
  })) !== undefined;
169
213
  const isNavigation = prop.property.typename.toLowerCase() === "navigation";
170
- const propertyName = isNavigation
171
- ? `${propertyField.properties[0].property.name}.id`
172
- : propertyField.properties[0].property.name;
173
- const className = propertyField.properties[0].property.classInfo.name.replace(":", ".");
174
- if (!isAspect &&
175
- ((_c = propertyField.parent) === null || _c === void 0 ? void 0 : _c.pathToPrimaryClass) &&
176
- ((_d = propertyField.parent) === null || _d === void 0 ? void 0 : _d.pathToPrimaryClass.length) > 0) {
177
- this.removeRelatedProperty(propertyField, propertyName);
178
- }
179
- else {
180
- this.removePropertyFromQuery(className, propertyName);
214
+ const isCategory = isNavigation && this.isCategory(propertyField);
215
+ for (let i = 0; i < propertyField.properties.length; i++) {
216
+ const propertyName = isNavigation
217
+ ? isCategory
218
+ ? `${propertyField.properties[i].property.name}.CodeValue`
219
+ : `${propertyField.properties[i].property.name}.id`
220
+ : propertyField.properties[i].property.name;
221
+ const className = propertyField.properties[i].property.classInfo.name.replace(":", ".");
222
+ if (!isAspect &&
223
+ ((_d = propertyField.parent) === null || _d === void 0 ? void 0 : _d.pathToPrimaryClass) &&
224
+ ((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.pathToPrimaryClass.length) > 0) {
225
+ this.removeRelatedProperty(i, propertyField, propertyName);
226
+ }
227
+ else {
228
+ this.removePropertyFromQuery(i, className, propertyName);
229
+ }
181
230
  }
182
231
  }
183
- removeRelatedProperty(propertyField, propertyName) {
232
+ removeRelatedProperty(unionIndex, propertyField, propertyName) {
184
233
  var _a, _b;
185
234
  const paths = [...((_b = (_a = propertyField.parent) === null || _a === void 0 ? void 0 : _a.pathToPrimaryClass) !== null && _b !== void 0 ? _b : [])];
186
235
  paths.reverse().forEach((path) => {
@@ -189,32 +238,32 @@ class QueryBuilder {
189
238
  const targetClassName = (_b = path.targetClassInfo) === null || _b === void 0 ? void 0 : _b.name.replace(":", ".");
190
239
  const relClassName = (_c = path.relationshipInfo) === null || _c === void 0 ? void 0 : _c.name.replace(":", ".");
191
240
  if (!path.isForwardRelationship) {
192
- this.removePropertyFromQuery(targetClassName, `ECInstanceId`);
193
- this.removePropertyFromQuery(relClassName, `TargetECInstanceId`);
241
+ this.removePropertyFromQuery(unionIndex, targetClassName, `ECInstanceId`);
242
+ this.removePropertyFromQuery(unionIndex, relClassName, `TargetECInstanceId`);
194
243
  if (((_d = path.sourceClassInfo) === null || _d === void 0 ? void 0 : _d.name) ===
195
244
  ((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.contentClassInfo.name)) {
196
- this.removePropertyFromQuery(sourceClassName, propertyName);
245
+ this.removePropertyFromQuery(unionIndex, sourceClassName, propertyName);
197
246
  }
198
247
  else {
199
- this.removePropertyFromQuery(sourceClassName, `ECInstanceId`);
248
+ this.removePropertyFromQuery(unionIndex, sourceClassName, `ECInstanceId`);
200
249
  }
201
250
  }
202
251
  else {
203
- this.removePropertyFromQuery(targetClassName, `ECInstanceId`);
204
- this.removePropertyFromQuery(relClassName, `SourceECInstanceId`);
252
+ this.removePropertyFromQuery(unionIndex, targetClassName, `ECInstanceId`);
253
+ this.removePropertyFromQuery(unionIndex, relClassName, `SourceECInstanceId`);
205
254
  if (((_f = path.sourceClassInfo) === null || _f === void 0 ? void 0 : _f.name) ===
206
255
  ((_g = propertyField.parent) === null || _g === void 0 ? void 0 : _g.contentClassInfo.name)) {
207
- this.removePropertyFromQuery(sourceClassName, propertyName);
256
+ this.removePropertyFromQuery(unionIndex, sourceClassName, propertyName);
208
257
  }
209
258
  else {
210
- this.removePropertyFromQuery(sourceClassName, `ECInstanceId`);
259
+ this.removePropertyFromQuery(unionIndex, sourceClassName, `ECInstanceId`);
211
260
  }
212
261
  }
213
262
  });
214
263
  }
215
- removePropertyFromQuery(className, propertyName) {
264
+ removePropertyFromQuery(unionIndex, className, propertyName) {
216
265
  var _a, _b, _c, _d;
217
- const foundClass = (_a = this.query) === null || _a === void 0 ? void 0 : _a.classes.find((c) => c.className === className);
266
+ const foundClass = (_a = this.query) === null || _a === void 0 ? void 0 : _a.unions[unionIndex].classes.find((c) => c.className === className);
218
267
  if (foundClass) {
219
268
  const foundPropertyIndex = foundClass.properties.findIndex((p) => p.name === propertyName);
220
269
  if (foundPropertyIndex > -1) {
@@ -222,123 +271,156 @@ class QueryBuilder {
222
271
  }
223
272
  if (foundClass.properties.length === 0) {
224
273
  // remove the entire class if all properties are removed
225
- const foundClassIndex = (_c = (_b = this.query) === null || _b === void 0 ? void 0 : _b.classes.findIndex((c) => c.className === className)) !== null && _c !== void 0 ? _c : -1;
274
+ const foundClassIndex = (_c = (_b = this.query) === null || _b === void 0 ? void 0 : _b.unions[unionIndex].classes.findIndex((c) => c.className === className)) !== null && _c !== void 0 ? _c : -1;
226
275
  if (foundClassIndex > -1) {
227
- (_d = this.query) === null || _d === void 0 ? void 0 : _d.classes.splice(foundClassIndex, 1);
276
+ (_d = this.query) === null || _d === void 0 ? void 0 : _d.unions[unionIndex].classes.splice(foundClassIndex, 1);
228
277
  }
229
278
  }
230
279
  }
231
280
  }
281
+ categoryQuery(codeValue) {
282
+ return ` JOIN bis.Category ON bis.Category.ECInstanceId = bis.GeometricElement3d.category.id AND ((bis.Category.CodeValue='${codeValue}') OR (bis.Category.UserLabel='${codeValue}'))`;
283
+ }
232
284
  buildQueryString() {
233
- if (this.query === undefined || this.query.classes.length === 0) {
285
+ if (this.query === undefined ||
286
+ this.query.unions.length === 0 ||
287
+ this.query.unions[0].classes.length === 0) {
234
288
  return "";
235
289
  }
236
- const baseClass = this.query.classes[0];
237
- const baseClassName = baseClass.className;
238
- const baseIdName = baseClass.isAspect
239
- ? `${baseClassName}.Element.id`
240
- : `${baseClassName}.ECInstanceId`;
241
- let queryString = `SELECT ${baseIdName}${baseClass.isAspect ? " ECInstanceId" : ""} FROM ${baseClassName}`;
242
- if (this.query.classes.length > 1) {
243
- for (let i = 1; i < this.query.classes.length; i++) {
244
- const joinClass = this.query.classes[i];
245
- const joinClassName = joinClass.className;
246
- const joinIdName = joinClass.isAspect
247
- ? `${joinClassName}.Element.id`
248
- : `${joinClassName}.ECInstanceId`;
249
- if (joinClass.isRelational) {
250
- queryString += ` JOIN ${joinClassName}`;
251
- if (joinClass.properties.length > 0) {
252
- if (joinClass.properties[0].needsQuote) {
253
- queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}='${joinClass.properties[0].value}'`;
254
- }
255
- else {
256
- if (this._isFloat(joinClass.properties[0].value)) {
257
- queryString += ` ON ROUND(${joinClassName}.${joinClass.properties[0].name}, `;
258
- queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
259
- queryString += `${Number(joinClass.properties[0].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
290
+ let unionQuery = "";
291
+ for (const union of this.query.unions) {
292
+ const baseClass = union.classes[0];
293
+ const baseClassName = baseClass.className;
294
+ const baseIdName = baseClass.isAspect
295
+ ? `${baseClassName}.Element.id`
296
+ : `${baseClassName}.ECInstanceId`;
297
+ let queryString = `SELECT ${baseIdName}${baseClass.isAspect ? " ECInstanceId" : ""} FROM ${baseClassName}`;
298
+ if (union.classes.length > 1) {
299
+ for (let i = 1; i < union.classes.length; i++) {
300
+ const joinClass = union.classes[i];
301
+ const joinClassName = joinClass.className;
302
+ const joinIdName = joinClass.isAspect
303
+ ? `${joinClassName}.Element.id`
304
+ : `${joinClassName}.ECInstanceId`;
305
+ if (joinClass.isRelational) {
306
+ queryString += ` JOIN ${joinClassName}`;
307
+ if (joinClass.properties.length > 0) {
308
+ if (joinClass.properties[0].isCategory) {
309
+ queryString += this.categoryQuery(joinClass.properties[0].value.toString());
260
310
  }
261
311
  else {
262
- queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}=${joinClass.properties[0].value}`;
312
+ if (joinClass.properties[0].needsQuote) {
313
+ queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}='${joinClass.properties[0].value}'`;
314
+ }
315
+ else {
316
+ if (this._isFloat(joinClass.properties[0].value)) {
317
+ queryString += ` ON ROUND(${joinClassName}.${joinClass.properties[0].name}, `;
318
+ queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
319
+ queryString += `${Number(joinClass.properties[0].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
320
+ }
321
+ else {
322
+ queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}=${joinClass.properties[0].value}`;
323
+ }
324
+ }
263
325
  }
264
326
  }
265
- }
266
- // when base is regular property, link base to first joined relational property
267
- if (!baseClass.isRelational && i === 1) {
268
- queryString += ` AND ${joinIdName} = ${baseIdName}`;
269
- }
270
- for (const property of joinClass.properties) {
271
- if (property.needsQuote) {
272
- queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;
327
+ // when base is regular property, link base to first joined relational property
328
+ if (!baseClass.isRelational && i === 1) {
329
+ queryString += ` AND ${joinIdName} = ${baseIdName}`;
273
330
  }
274
- else {
275
- if (this._isFloat(property.value)) {
276
- queryString += ` AND ROUND(${joinClassName}.${property.name}, `;
277
- queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
278
- queryString += `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
331
+ for (const property of joinClass.properties) {
332
+ if (property.isCategory) {
333
+ queryString += this.categoryQuery(property.value.toString());
279
334
  }
280
335
  else {
281
- queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;
336
+ if (property.needsQuote) {
337
+ queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;
338
+ }
339
+ else {
340
+ if (this._isFloat(property.value)) {
341
+ queryString += ` AND ROUND(${joinClassName}.${property.name}, `;
342
+ queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
343
+ queryString += `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
344
+ }
345
+ else {
346
+ queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;
347
+ }
348
+ }
282
349
  }
283
350
  }
284
351
  }
285
- }
286
- else {
287
- queryString += ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;
288
- for (const property of joinClass.properties) {
289
- if (property.needsQuote) {
290
- queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;
291
- }
292
- else {
293
- if (this._isFloat(property.value)) {
294
- queryString += ` AND ROUND(${joinClassName}.${property.name}, `;
295
- queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
296
- queryString += `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
352
+ else {
353
+ queryString += ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;
354
+ for (const property of joinClass.properties) {
355
+ if (property.isCategory) {
356
+ queryString += this.categoryQuery(property.value.toString());
297
357
  }
298
358
  else {
299
- queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;
359
+ if (property.needsQuote) {
360
+ queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;
361
+ }
362
+ else {
363
+ if (this._isFloat(property.value)) {
364
+ queryString += ` AND ROUND(${joinClassName}.${property.name}, `;
365
+ queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
366
+ queryString += `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
367
+ }
368
+ else {
369
+ queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;
370
+ }
371
+ }
300
372
  }
301
373
  }
302
374
  }
303
375
  }
304
376
  }
305
- }
306
- const properties = baseClass.properties;
307
- if (properties.length > 0) {
308
- if (properties[0].needsQuote) {
309
- queryString += ` WHERE ${baseClassName}.${properties[0].name}='${properties[0].value}'`;
310
- }
311
- else {
312
- if (this._isFloat(properties[0].value)) {
313
- queryString += ` WHERE ROUND(${baseClassName}.${properties[0].name}, `;
314
- queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
315
- queryString += `${Number(properties[0].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
377
+ const properties = baseClass.properties;
378
+ if (properties.length > 0) {
379
+ if (properties[0].isCategory) {
380
+ queryString += this.categoryQuery(properties[0].value.toString());
316
381
  }
317
382
  else {
318
- queryString += ` WHERE ${baseClassName}.${properties[0].name}=${properties[0].value}`;
319
- }
320
- }
321
- if (properties.length > 1) {
322
- for (let i = 1; i < properties.length; i++) {
323
- if (properties[i].needsQuote) {
324
- queryString += ` AND ${baseClassName}.${properties[i].name}='${properties[i].value}'`;
383
+ if (properties[0].needsQuote) {
384
+ queryString += ` WHERE ${baseClassName}.${properties[0].name}='${properties[0].value}'`;
325
385
  }
326
386
  else {
327
- if (this._isFloat(properties[i].value)) {
328
- queryString += ` AND ROUND(${baseClassName}.${properties[i].name}, `;
387
+ if (this._isFloat(properties[0].value)) {
388
+ queryString += ` WHERE ROUND(${baseClassName}.${properties[0].name}, `;
329
389
  queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
330
- queryString += `${Number(properties[i].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
390
+ queryString += `${Number(properties[0].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
331
391
  }
332
392
  else {
333
- queryString += ` AND ${baseClassName}.${properties[i].name}=${properties[i].value}`;
393
+ queryString += ` WHERE ${baseClassName}.${properties[0].name}=${properties[0].value}`;
394
+ }
395
+ }
396
+ }
397
+ if (properties.length > 1) {
398
+ for (let i = 1; i < properties.length; i++) {
399
+ if (properties[i].isCategory) {
400
+ queryString += this.categoryQuery(properties[i].value.toString());
401
+ }
402
+ else {
403
+ if (properties[i].needsQuote) {
404
+ queryString += ` AND ${baseClassName}.${properties[i].name}='${properties[i].value}'`;
405
+ }
406
+ else {
407
+ if (this._isFloat(properties[i].value)) {
408
+ queryString += ` AND ROUND(${baseClassName}.${properties[i].name}, `;
409
+ queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
410
+ queryString += `${Number(properties[i].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
411
+ }
412
+ else {
413
+ queryString += ` AND ${baseClassName}.${properties[i].name}=${properties[i].value}`;
414
+ }
415
+ }
334
416
  }
335
417
  }
336
418
  }
337
419
  }
420
+ unionQuery += `${queryString} UNION `;
338
421
  }
339
- // console.log(queryString);
340
- // console.log(this.query);
341
- return queryString;
422
+ unionQuery = unionQuery.slice(0, unionQuery.length - 7);
423
+ return unionQuery;
342
424
  }
343
425
  _isFloat(n) {
344
426
  return Number(n) === n && n % 1 !== 0;