@itwin/grouping-mapping-widget 0.3.5 → 0.5.1

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