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