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