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