@itwin/grouping-mapping-widget 0.9.0 → 0.9.2
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.
- package/lib/cjs/test/GroupPropertyUtils.test.js +61 -1
- package/lib/cjs/test/GroupPropertyUtils.test.js.map +1 -1
- package/lib/cjs/test/GroupingMappingCustomUI.test.js +44 -53
- package/lib/cjs/test/GroupingMappingCustomUI.test.js.map +1 -1
- package/lib/cjs/test/QueryBuilder.test.js +30 -2
- package/lib/cjs/test/QueryBuilder.test.js.map +1 -1
- package/lib/cjs/test/QueryBuilder.testdata.js +471 -7
- package/lib/cjs/test/QueryBuilder.testdata.js.map +1 -1
- package/lib/cjs/test/QueryBuilderTestData.d.ts +3 -1
- package/lib/cjs/test/QueryBuilderTestData.js.map +1 -1
- package/lib/cjs/widget/components/GroupAction.js +2 -21
- package/lib/cjs/widget/components/GroupAction.js.map +1 -1
- package/lib/cjs/widget/components/GroupPropertyUtils.js +2 -1
- package/lib/cjs/widget/components/GroupPropertyUtils.js.map +1 -1
- package/lib/cjs/widget/components/GroupQueryBuilderContainer.d.ts +3 -2
- package/lib/cjs/widget/components/GroupQueryBuilderContainer.js +38 -45
- package/lib/cjs/widget/components/GroupQueryBuilderContainer.js.map +1 -1
- package/lib/cjs/widget/components/Grouping.js +1 -1
- package/lib/cjs/widget/components/Grouping.js.map +1 -1
- package/lib/cjs/widget/components/Grouping.scss +1 -1
- package/lib/cjs/widget/components/QueryBuilder.d.ts +35 -21
- package/lib/cjs/widget/components/QueryBuilder.js +153 -181
- package/lib/cjs/widget/components/QueryBuilder.js.map +1 -1
- package/lib/cjs/widget/components/context/PropertyGridWrapperContext.d.ts +15 -0
- package/lib/cjs/widget/components/context/{GroupQueryBuilderContext.js → PropertyGridWrapperContext.js} +13 -9
- package/lib/cjs/widget/components/context/PropertyGridWrapperContext.js.map +1 -0
- package/lib/cjs/widget/components/property-grid/PropertyGrid.d.ts +1 -1
- package/lib/cjs/widget/components/property-grid/PropertyGrid.js +2 -2
- package/lib/cjs/widget/components/property-grid/PropertyGrid.js.map +1 -1
- package/lib/cjs/widget/components/property-grid/PropertyGridWrapper.d.ts +10 -4
- package/lib/cjs/widget/components/property-grid/PropertyGridWrapper.js +18 -8
- package/lib/cjs/widget/components/property-grid/PropertyGridWrapper.js.map +1 -1
- package/lib/cjs/widget/components/property-grid/PropertyView.d.ts +1 -1
- package/lib/cjs/widget/components/property-grid/PropertyView.js +46 -60
- package/lib/cjs/widget/components/property-grid/PropertyView.js.map +1 -1
- package/lib/cjs/widget/components/viewerUtils.js +1 -3
- package/lib/cjs/widget/components/viewerUtils.js.map +1 -1
- package/lib/esm/test/GroupPropertyUtils.test.js +61 -1
- package/lib/esm/test/GroupPropertyUtils.test.js.map +1 -1
- package/lib/esm/test/GroupingMappingCustomUI.test.js +45 -54
- package/lib/esm/test/GroupingMappingCustomUI.test.js.map +1 -1
- package/lib/esm/test/QueryBuilder.test.js +31 -3
- package/lib/esm/test/QueryBuilder.test.js.map +1 -1
- package/lib/esm/test/QueryBuilder.testdata.js +471 -7
- package/lib/esm/test/QueryBuilder.testdata.js.map +1 -1
- package/lib/esm/test/QueryBuilderTestData.d.ts +3 -1
- package/lib/esm/test/QueryBuilderTestData.js.map +1 -1
- package/lib/esm/widget/components/GroupAction.js +2 -21
- package/lib/esm/widget/components/GroupAction.js.map +1 -1
- package/lib/esm/widget/components/GroupPropertyUtils.js +2 -1
- package/lib/esm/widget/components/GroupPropertyUtils.js.map +1 -1
- package/lib/esm/widget/components/GroupQueryBuilderContainer.d.ts +3 -2
- package/lib/esm/widget/components/GroupQueryBuilderContainer.js +34 -25
- package/lib/esm/widget/components/GroupQueryBuilderContainer.js.map +1 -1
- package/lib/esm/widget/components/Grouping.js +1 -1
- package/lib/esm/widget/components/Grouping.js.map +1 -1
- package/lib/esm/widget/components/Grouping.scss +1 -1
- package/lib/esm/widget/components/QueryBuilder.d.ts +35 -21
- package/lib/esm/widget/components/QueryBuilder.js +153 -181
- package/lib/esm/widget/components/QueryBuilder.js.map +1 -1
- package/lib/esm/widget/components/context/PropertyGridWrapperContext.d.ts +15 -0
- package/lib/esm/widget/components/context/{GroupQueryBuilderContext.js → PropertyGridWrapperContext.js} +11 -8
- package/lib/esm/widget/components/context/PropertyGridWrapperContext.js.map +1 -0
- package/lib/esm/widget/components/property-grid/PropertyGrid.d.ts +1 -1
- package/lib/esm/widget/components/property-grid/PropertyGrid.js +2 -2
- package/lib/esm/widget/components/property-grid/PropertyGrid.js.map +1 -1
- package/lib/esm/widget/components/property-grid/PropertyGridWrapper.d.ts +10 -4
- package/lib/esm/widget/components/property-grid/PropertyGridWrapper.js +16 -6
- package/lib/esm/widget/components/property-grid/PropertyGridWrapper.js.map +1 -1
- package/lib/esm/widget/components/property-grid/PropertyView.d.ts +1 -1
- package/lib/esm/widget/components/property-grid/PropertyView.js +32 -30
- package/lib/esm/widget/components/property-grid/PropertyView.js.map +1 -1
- package/lib/esm/widget/components/viewerUtils.js +1 -3
- package/lib/esm/widget/components/viewerUtils.js.map +1 -1
- package/package.json +2 -2
- package/lib/cjs/api/GroupQueryBuilderApi.d.ts +0 -15
- package/lib/cjs/api/GroupQueryBuilderApi.js +0 -27
- package/lib/cjs/api/GroupQueryBuilderApi.js.map +0 -1
- package/lib/cjs/widget/components/context/GroupQueryBuilderContext.d.ts +0 -16
- package/lib/cjs/widget/components/context/GroupQueryBuilderContext.js.map +0 -1
- package/lib/esm/api/GroupQueryBuilderApi.d.ts +0 -15
- package/lib/esm/api/GroupQueryBuilderApi.js +0 -23
- package/lib/esm/api/GroupQueryBuilderApi.js.map +0 -1
- package/lib/esm/widget/components/context/GroupQueryBuilderContext.d.ts +0 -16
- package/lib/esm/widget/components/context/GroupQueryBuilderContext.js.map +0 -1
|
@@ -2,19 +2,37 @@ import { PropertyValueFormat } from "@itwin/appui-abstract";
|
|
|
2
2
|
import { toaster } from "@itwin/itwinui-react";
|
|
3
3
|
/* This class is to build adaptive and dynamic query for find similar property selections */
|
|
4
4
|
export class QueryBuilder {
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
5
|
constructor(provider) {
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
this.resetQuery = () => {
|
|
7
|
+
this.query = undefined;
|
|
8
|
+
};
|
|
9
|
+
this._propertyMap = new Map();
|
|
10
|
+
this.regenerateQuery = () => {
|
|
11
|
+
this.resetQuery();
|
|
12
|
+
for (const property of this._propertyMap.values()) {
|
|
13
|
+
this.buildProperty(property.propertyRecord, property.propertiesField);
|
|
16
14
|
}
|
|
17
|
-
|
|
15
|
+
};
|
|
16
|
+
this.relationalJoinSegments = (classes, querySegments) => {
|
|
17
|
+
var _a;
|
|
18
|
+
for (const queryClass of classes) {
|
|
19
|
+
for (const classJoin of queryClass.classJoins) {
|
|
20
|
+
const querySegment = [
|
|
21
|
+
...(_a = querySegments.get(classJoin.joinClassName)) !== null && _a !== void 0 ? _a : [],
|
|
22
|
+
`${queryClass.className}.${classJoin.classProperty} = ${classJoin.joinClassName}.${classJoin.joinClassProperty}`,
|
|
23
|
+
];
|
|
24
|
+
querySegments.set(classJoin.joinClassName, querySegment);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return querySegments;
|
|
28
|
+
};
|
|
29
|
+
this.propertyQuerySegment = (className, property, needsQuote) => {
|
|
30
|
+
if (this.isFloat(property.value))
|
|
31
|
+
return `ROUND(${className}.${property.name}, ` +
|
|
32
|
+
`${QueryBuilder.DEFAULT_DOUBLE_PRECISION}) = ` +
|
|
33
|
+
`${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
|
|
34
|
+
const propertyValue = needsQuote ? `'${property.value}'` : property.value;
|
|
35
|
+
return `${className}.${property.name} = ${propertyValue}`;
|
|
18
36
|
};
|
|
19
37
|
this.dataProvider = provider;
|
|
20
38
|
}
|
|
@@ -24,7 +42,7 @@ export class QueryBuilder {
|
|
|
24
42
|
return (classInfo === null || classInfo === void 0 ? void 0 : classInfo.name) === "BisCore:GeometricElement3dIsInCategory";
|
|
25
43
|
}
|
|
26
44
|
async addProperty(prop) {
|
|
27
|
-
var _a
|
|
45
|
+
var _a;
|
|
28
46
|
// TODO: only handle primitive properties now
|
|
29
47
|
if (((_a = prop.value) === null || _a === void 0 ? void 0 : _a.valueFormat) !== PropertyValueFormat.Primitive) {
|
|
30
48
|
toaster.warning("Only primitive types are supported for now.");
|
|
@@ -33,6 +51,24 @@ export class QueryBuilder {
|
|
|
33
51
|
if (prop.value.value === undefined) {
|
|
34
52
|
return false;
|
|
35
53
|
}
|
|
54
|
+
const propertyField = (await this.dataProvider.getFieldByPropertyRecord(prop));
|
|
55
|
+
if (!propertyField) {
|
|
56
|
+
toaster.negative("Error. Failed to fetch field for this property record.");
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
this._propertyMap.set(JSON.stringify(propertyField.getFieldDescriptor()), { propertyRecord: prop, propertiesField: propertyField });
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
async removeProperty(prop) {
|
|
63
|
+
const propertyField = (await this.dataProvider.getFieldByPropertyRecord(prop));
|
|
64
|
+
this._propertyMap.delete(JSON.stringify(propertyField.getFieldDescriptor()));
|
|
65
|
+
}
|
|
66
|
+
buildProperty(prop, propertiesField) {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
if (((_a = prop.value) === null || _a === void 0 ? void 0 : _a.valueFormat) !== PropertyValueFormat.Primitive || prop.value.value === undefined) {
|
|
69
|
+
toaster.negative("Error. An unexpected error has occured while building a query.");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
36
72
|
function replaceAll(str, match, replacement) {
|
|
37
73
|
return str.split(match).join(replacement);
|
|
38
74
|
}
|
|
@@ -42,41 +78,36 @@ export class QueryBuilder {
|
|
|
42
78
|
String(prop.value.value).indexOf("'") >= 0) {
|
|
43
79
|
prop.value.value = replaceAll(prop.value.value.toString(), "'", "''");
|
|
44
80
|
}
|
|
45
|
-
|
|
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) {
|
|
49
|
-
toaster.negative("Error. Failed to fetch field for this property record.");
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
81
|
+
const pathToPrimaryClass = (_b = propertiesField.parent) === null || _b === void 0 ? void 0 : _b.pathToPrimaryClass;
|
|
52
82
|
// get the special cases
|
|
53
83
|
const isNavigation = prop.property.typename.toLowerCase() === "navigation";
|
|
54
|
-
const isCategory = isNavigation && this.isCategory(
|
|
55
|
-
const isAspect = (
|
|
84
|
+
const isCategory = isNavigation && this.isCategory(propertiesField);
|
|
85
|
+
const isAspect = (pathToPrimaryClass === null || pathToPrimaryClass === void 0 ? void 0 : pathToPrimaryClass.find((a) => {
|
|
56
86
|
var _a, _b;
|
|
57
87
|
return ((_a = a.relationshipInfo) === null || _a === void 0 ? void 0 : _a.name) ===
|
|
58
88
|
QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||
|
|
59
89
|
((_b = a.relationshipInfo) === null || _b === void 0 ? void 0 : _b.name) === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS;
|
|
60
90
|
})) !== undefined;
|
|
61
|
-
for (let i = 0; i <
|
|
62
|
-
const
|
|
91
|
+
for (let i = 0; i < propertiesField.properties.length; i++) {
|
|
92
|
+
const property = propertiesField.properties[i].property;
|
|
93
|
+
const className = property.classInfo.name.replace(":", ".");
|
|
63
94
|
const propertyName = isNavigation
|
|
64
95
|
? isCategory
|
|
65
|
-
? `${
|
|
66
|
-
: `${
|
|
67
|
-
:
|
|
96
|
+
? `${property.name}.CodeValue`
|
|
97
|
+
: `${property.name}.id`
|
|
98
|
+
: property.name;
|
|
68
99
|
const propertyValue = isNavigation
|
|
69
100
|
? isCategory
|
|
70
|
-
? (
|
|
101
|
+
? (_c = prop.value.displayValue) !== null && _c !== void 0 ? _c : ""
|
|
71
102
|
: prop.value.value.id
|
|
72
103
|
: prop.value.value;
|
|
73
104
|
if (!isAspect &&
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.
|
|
105
|
+
pathToPrimaryClass &&
|
|
106
|
+
pathToPrimaryClass.length > 0) {
|
|
107
|
+
this.addRelatedToQuery(i, propertiesField, propertyName, propertyValue);
|
|
77
108
|
}
|
|
78
109
|
else {
|
|
79
|
-
this.addPropertyToQuery(i, className, propertyName, propertyValue,
|
|
110
|
+
this.addPropertyToQuery(i, className, propertyName, propertyValue, this.needsQuote(propertiesField), isCategory, isAspect);
|
|
80
111
|
}
|
|
81
112
|
}
|
|
82
113
|
return true;
|
|
@@ -91,207 +122,148 @@ export class QueryBuilder {
|
|
|
91
122
|
}
|
|
92
123
|
return false;
|
|
93
124
|
}
|
|
94
|
-
|
|
125
|
+
addRelatedToQuery(unionIndex, propertyField, propertyName, propertyValue) {
|
|
95
126
|
var _a, _b;
|
|
96
|
-
const addProperty = this.addRelatedPropertyToQuery(unionIndex, isAspect);
|
|
97
127
|
const paths = [...((_b = (_a = propertyField.parent) === null || _a === void 0 ? void 0 : _a.pathToPrimaryClass) !== null && _b !== void 0 ? _b : [])];
|
|
98
128
|
paths.reverse().forEach((path) => {
|
|
99
129
|
var _a, _b, _c, _d, _e;
|
|
100
130
|
const sourceClassName = (_a = path.sourceClassInfo) === null || _a === void 0 ? void 0 : _a.name.replace(":", ".");
|
|
101
131
|
const targetClassName = (_b = path.targetClassInfo) === null || _b === void 0 ? void 0 : _b.name.replace(":", ".");
|
|
102
132
|
const relClassName = (_c = path.relationshipInfo) === null || _c === void 0 ? void 0 : _c.name.replace(":", ".");
|
|
103
|
-
const
|
|
133
|
+
const relClassProperty = path.isForwardRelationship
|
|
104
134
|
? `SourceECInstanceId`
|
|
105
135
|
: `TargetECInstanceId`;
|
|
106
136
|
const relPropertyValue = path.isForwardRelationship
|
|
107
|
-
?
|
|
108
|
-
:
|
|
109
|
-
|
|
110
|
-
|
|
137
|
+
? `TargetECInstanceId`
|
|
138
|
+
: `SourceECInstanceId`;
|
|
139
|
+
this.addClassToQuery(unionIndex, targetClassName, `ECInstanceId`, relClassName, relPropertyValue);
|
|
140
|
+
this.addClassToQuery(unionIndex, relClassName, relClassProperty, sourceClassName, `ECInstanceId`);
|
|
111
141
|
if (((_d = path.sourceClassInfo) === null || _d === void 0 ? void 0 : _d.name)
|
|
112
142
|
=== ((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.contentClassInfo.name)) {
|
|
113
|
-
|
|
143
|
+
this.addPropertyToQuery(unionIndex, sourceClassName, propertyName, propertyValue, this.needsQuote(propertyField), false, false);
|
|
114
144
|
}
|
|
115
145
|
});
|
|
116
146
|
}
|
|
117
|
-
|
|
118
|
-
if (this.query === undefined
|
|
147
|
+
addClassToQuery(unionIndex, className, classProperty, joinClassName, joinClassProperty) {
|
|
148
|
+
if (this.query === undefined) {
|
|
119
149
|
this.query = { unions: [] };
|
|
120
150
|
}
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
isCategory,
|
|
151
|
+
const classJoin = {
|
|
152
|
+
classProperty,
|
|
153
|
+
joinClassName,
|
|
154
|
+
joinClassProperty,
|
|
126
155
|
};
|
|
127
156
|
const queryClass = {
|
|
128
157
|
className,
|
|
129
|
-
|
|
130
|
-
isRelational,
|
|
131
|
-
properties: [
|
|
132
|
-
queryProperty,
|
|
133
|
-
],
|
|
158
|
+
classJoins: [classJoin],
|
|
134
159
|
};
|
|
135
160
|
if (this.query.unions.length <= unionIndex) {
|
|
136
161
|
this.query.unions.push({
|
|
137
|
-
classes: [
|
|
138
|
-
|
|
139
|
-
],
|
|
162
|
+
classes: [queryClass],
|
|
163
|
+
properties: [],
|
|
140
164
|
});
|
|
141
165
|
return;
|
|
142
166
|
}
|
|
143
167
|
const foundClass = this.query.unions[unionIndex].classes.find((c) => c.className === className);
|
|
144
168
|
if (foundClass) {
|
|
145
|
-
foundClass.
|
|
146
|
-
if (!
|
|
147
|
-
foundClass.
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
this.query.unions[unionIndex].classes.push(queryClass);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
async removeProperty(prop) {
|
|
155
|
-
var _a, _b, _c, _d, _e;
|
|
156
|
-
if (this.query === undefined || this.query.unions.length === 0) {
|
|
169
|
+
const foundJoin = foundClass.classJoins.find((join) => join.classProperty === classProperty && join.joinClassName === joinClassName && join.joinClassProperty === joinClassProperty);
|
|
170
|
+
if (!foundJoin)
|
|
171
|
+
foundClass.classJoins.push(classJoin);
|
|
157
172
|
return;
|
|
158
173
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
174
|
+
this.query.unions[unionIndex].classes.push(queryClass);
|
|
175
|
+
}
|
|
176
|
+
addPropertyToQuery(unionIndex, className, propertyName, propertyValue, needsQuote, isCategory, isAspect) {
|
|
177
|
+
if (this.query === undefined) {
|
|
178
|
+
this.query = { unions: [] };
|
|
162
179
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
180
|
+
const queryJoin = {
|
|
181
|
+
name: propertyName,
|
|
182
|
+
value: propertyValue,
|
|
183
|
+
needsQuote,
|
|
184
|
+
};
|
|
185
|
+
const queryProperty = {
|
|
186
|
+
className,
|
|
187
|
+
isCategory,
|
|
188
|
+
isAspect,
|
|
189
|
+
classProperties: [queryJoin],
|
|
190
|
+
};
|
|
191
|
+
if (this.query.unions.length <= unionIndex) {
|
|
192
|
+
this.query.unions.push({
|
|
193
|
+
classes: [],
|
|
194
|
+
properties: [queryProperty],
|
|
195
|
+
});
|
|
166
196
|
return;
|
|
167
197
|
}
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const isNavigation = prop.property.typename.toLowerCase() === "navigation";
|
|
175
|
-
const isCategory = isNavigation && this.isCategory(propertyField);
|
|
176
|
-
for (let i = 0; i < propertyField.properties.length; i++) {
|
|
177
|
-
const propertyName = isNavigation
|
|
178
|
-
? isCategory
|
|
179
|
-
? `${propertyField.properties[i].property.name}.CodeValue`
|
|
180
|
-
: `${propertyField.properties[i].property.name}.id`
|
|
181
|
-
: propertyField.properties[i].property.name;
|
|
182
|
-
const className = propertyField.properties[i].property.classInfo.name.replace(":", ".");
|
|
183
|
-
if (!isAspect &&
|
|
184
|
-
((_d = propertyField.parent) === null || _d === void 0 ? void 0 : _d.pathToPrimaryClass) &&
|
|
185
|
-
((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.pathToPrimaryClass.length) > 0) {
|
|
186
|
-
this.removeRelatedProperty(i, propertyField, propertyName);
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
this.removePropertyFromQuery(i, className, propertyName);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
removeRelatedProperty(unionIndex, propertyField, propertyName) {
|
|
194
|
-
var _a, _b;
|
|
195
|
-
const paths = [...((_b = (_a = propertyField.parent) === null || _a === void 0 ? void 0 : _a.pathToPrimaryClass) !== null && _b !== void 0 ? _b : [])];
|
|
196
|
-
paths.reverse().forEach((path) => {
|
|
197
|
-
var _a, _b, _c, _d, _e;
|
|
198
|
-
const sourceClassName = (_a = path.sourceClassInfo) === null || _a === void 0 ? void 0 : _a.name.replace(":", ".");
|
|
199
|
-
const targetClassName = (_b = path.targetClassInfo) === null || _b === void 0 ? void 0 : _b.name.replace(":", ".");
|
|
200
|
-
const relClassName = (_c = path.relationshipInfo) === null || _c === void 0 ? void 0 : _c.name.replace(":", ".");
|
|
201
|
-
this.removePropertyFromQuery(unionIndex, targetClassName, `ECInstanceId`);
|
|
202
|
-
const relPropertyName = path.isForwardRelationship ? `SourceECInstanceId` : `TargetECInstanceId`;
|
|
203
|
-
this.removePropertyFromQuery(unionIndex, relClassName, relPropertyName);
|
|
204
|
-
if (((_d = path.sourceClassInfo) === null || _d === void 0 ? void 0 : _d.name) ===
|
|
205
|
-
((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.contentClassInfo.name)) {
|
|
206
|
-
this.removePropertyFromQuery(unionIndex, sourceClassName, propertyName);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
removePropertyFromQuery(unionIndex, className, propertyName) {
|
|
211
|
-
var _a, _b, _c, _d;
|
|
212
|
-
const foundClass = (_a = this.query) === null || _a === void 0 ? void 0 : _a.unions[unionIndex].classes.find((c) => c.className === className);
|
|
213
|
-
if (foundClass) {
|
|
214
|
-
const foundPropertyIndex = foundClass.properties.findIndex((p) => p.name === propertyName);
|
|
215
|
-
if (foundPropertyIndex > -1) {
|
|
216
|
-
foundClass.properties.splice(foundPropertyIndex, 1);
|
|
217
|
-
}
|
|
218
|
-
if (foundClass.properties.length === 0) {
|
|
219
|
-
// remove the entire class if all properties are removed
|
|
220
|
-
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;
|
|
221
|
-
if (foundClassIndex > -1) {
|
|
222
|
-
(_d = this.query) === null || _d === void 0 ? void 0 : _d.unions[unionIndex].classes.splice(foundClassIndex, 1);
|
|
223
|
-
}
|
|
198
|
+
const foundPropertyClass = this.query.unions[unionIndex].properties.find((p) => p.className === className);
|
|
199
|
+
if (foundPropertyClass) {
|
|
200
|
+
const foundJoin = foundPropertyClass === null || foundPropertyClass === void 0 ? void 0 : foundPropertyClass.classProperties.find((join) => join.name === propertyName);
|
|
201
|
+
if (foundJoin) {
|
|
202
|
+
foundJoin.value = propertyValue;
|
|
203
|
+
return;
|
|
224
204
|
}
|
|
205
|
+
foundPropertyClass.classProperties.push(queryJoin);
|
|
206
|
+
return;
|
|
225
207
|
}
|
|
208
|
+
this.query.unions[unionIndex].properties.push(queryProperty);
|
|
226
209
|
}
|
|
227
210
|
buildQueryString() {
|
|
211
|
+
var _a;
|
|
212
|
+
this.regenerateQuery();
|
|
228
213
|
if (this.query === undefined ||
|
|
229
|
-
this.query.unions.length === 0
|
|
230
|
-
this.query.unions[0].classes.length === 0) {
|
|
214
|
+
(this.query.unions.find((u) => u.classes.length === 0 && u.properties.length === 0))) {
|
|
231
215
|
return "";
|
|
232
216
|
}
|
|
233
217
|
const unionSegments = [];
|
|
234
218
|
for (const union of this.query.unions) {
|
|
235
|
-
const querySegments = [];
|
|
236
219
|
const baseClass = union.classes[0];
|
|
237
|
-
const
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
querySegments.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
? ` JOIN ${joinClassName}`
|
|
252
|
-
: ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;
|
|
253
|
-
querySegments.push(joinSegment);
|
|
254
|
-
for (let j = 0; j < joinClass.properties.length; j++) {
|
|
255
|
-
const prefix = j === 0 && joinClass.isRelational ? "ON" : "AND";
|
|
256
|
-
const propertySegment = this.propertySegment(joinClassName, joinClass.properties[j], prefix);
|
|
257
|
-
querySegments.push(propertySegment);
|
|
258
|
-
}
|
|
259
|
-
// when base is regular property, link base to first joined relational property
|
|
260
|
-
if (joinClass.isRelational && !baseClass.isRelational && i === 1) {
|
|
261
|
-
querySegments.push(` AND ${joinIdName} = ${baseIdName}`);
|
|
262
|
-
}
|
|
220
|
+
const baseProperty = union.properties[0];
|
|
221
|
+
const baseClassName = baseClass ? baseClass.className : baseProperty === null || baseProperty === void 0 ? void 0 : baseProperty.className;
|
|
222
|
+
const baseIdName = `${baseClassName}.ECInstanceId`;
|
|
223
|
+
const selectClause = this.selectClause(baseProperty, baseClass);
|
|
224
|
+
let querySegments = new Map();
|
|
225
|
+
querySegments = this.relationalJoinSegments(union.classes, querySegments);
|
|
226
|
+
const whereSegments = [];
|
|
227
|
+
for (const property of union.properties) {
|
|
228
|
+
if (property.isCategory) {
|
|
229
|
+
if (property.className !== baseClassName)
|
|
230
|
+
querySegments.set("BisCore.GeometricElement3d", [`BisCore.GeometricElement3d.ECInstanceId = ${baseIdName}`]);
|
|
231
|
+
querySegments.set("BisCore.Category", [`BisCore.Category.ECInstanceId = BisCore.GeometricElement3d.category.id`]);
|
|
232
|
+
whereSegments.push(this.categoryWhereQuery(property.classProperties[0].value.toString()));
|
|
233
|
+
continue;
|
|
263
234
|
}
|
|
235
|
+
const joinIdName = property.isAspect
|
|
236
|
+
? `${property.className}.Element.id`
|
|
237
|
+
: `${property.className}.ECInstanceId`;
|
|
238
|
+
if (!querySegments.has(property.className) && property.className !== baseClassName)
|
|
239
|
+
querySegments.set(property.className, [`${joinIdName} = ${baseIdName}`]);
|
|
240
|
+
for (const prop of property.classProperties) {
|
|
241
|
+
whereSegments.push(this.propertyQuerySegment(property.className, prop, prop.needsQuote));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const joinClauses = [];
|
|
245
|
+
for (const key of querySegments.keys()) {
|
|
246
|
+
joinClauses.push(`JOIN ${key} ON ${(_a = querySegments.get(key)) === null || _a === void 0 ? void 0 : _a.join(" AND ")}`);
|
|
264
247
|
}
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
unionSegments.push(querySegments.join(""));
|
|
248
|
+
const whereClause = `WHERE ${whereSegments.join(" AND ")}`;
|
|
249
|
+
unionSegments.push([selectClause, ...joinClauses, whereClause].join(" "));
|
|
268
250
|
}
|
|
269
251
|
return unionSegments.join(" UNION ");
|
|
270
252
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
segments.push(this.categoryQuery(property.value.toString()));
|
|
253
|
+
selectClause(baseProperty, baseClass) {
|
|
254
|
+
if (baseClass) {
|
|
255
|
+
return `SELECT ${baseClass.className}.ECInstanceId, ${baseClass.className}.ECClassId FROM ${baseClass.className}`;
|
|
275
256
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (this.isFloat(property.value)) {
|
|
282
|
-
segments.push(` ${prefix} ROUND(${className}.${property.name}, `);
|
|
283
|
-
segments.push(`${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`);
|
|
284
|
-
segments.push(`${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`);
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
segments.push(` ${prefix} ${className}.${property.name}=${property.value}`);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
257
|
+
if (baseProperty) {
|
|
258
|
+
const baseIdName = baseProperty.isAspect
|
|
259
|
+
? `${baseProperty.className}.Element.id ECInstanceId`
|
|
260
|
+
: `${baseProperty.className}.ECInstanceId, ${baseProperty.className}.ECClassId`;
|
|
261
|
+
return `SELECT ${baseIdName} FROM ${baseProperty.className}`;
|
|
290
262
|
}
|
|
291
|
-
return
|
|
263
|
+
return "";
|
|
292
264
|
}
|
|
293
|
-
|
|
294
|
-
return `
|
|
265
|
+
categoryWhereQuery(codeValue) {
|
|
266
|
+
return `((BisCore.Category.CodeValue = '${codeValue}') OR (BisCore.Category.UserLabel = '${codeValue}'))`;
|
|
295
267
|
}
|
|
296
268
|
isFloat(n) {
|
|
297
269
|
return Number(n) === n && n % 1 !== 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.js","sourceRoot":"","sources":["../../../../src/widget/components/QueryBuilder.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAyB/C,4FAA4F;AAC5F,MA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iC,CAAC;AACb,qCAAwB,GAAG,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { PresentationPropertyDataProvider } from \"@itwin/presentation-components\";\nimport type {\n InstanceKey,\n PropertiesField,\n} from \"@itwin/presentation-common\";\nimport type { Primitives, PropertyRecord } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport { toaster } from \"@itwin/itwinui-react\";\n\nexport interface Query {\n unions: QueryUnion[];\n}\n\nexport interface QueryUnion {\n classes: QueryClass[];\n}\n\nexport interface QueryClass {\n // schemaName.className\n className: string;\n properties: QueryProperty[];\n isAspect: boolean;\n isRelational?: boolean;\n}\n\nexport interface QueryProperty {\n name: string;\n value: Primitives.Value;\n needsQuote: boolean;\n isCategory: boolean;\n}\n\n/* This class is to build adaptive and dynamic query for find similar property selections */\nexport class QueryBuilder {\n public static readonly MULTI_ASPECT_PRIMARY_CLASS =\n \"BisCore:ElementOwnsMultiAspects\";\n public static readonly UNIQUE_ASPECT_PRIMARY_CLASS =\n \"BisCore:ElementOwnsUniqueAspect\";\n public static readonly DEFAULT_DOUBLE_PRECISION = 4;\n\n public dataProvider: PresentationPropertyDataProvider | undefined;\n public query: Query | undefined;\n\n /**\n *\n */\n constructor(provider: PresentationPropertyDataProvider | undefined) {\n this.dataProvider = provider;\n }\n\n private isCategory(propertyField: PropertiesField): boolean {\n const classInfo =\n propertyField.properties[0].property.navigationPropertyInfo?.classInfo;\n return classInfo?.name === \"BisCore:GeometricElement3dIsInCategory\";\n }\n\n public async addProperty(prop: PropertyRecord): Promise<boolean> {\n // TODO: only handle primitive properties now\n if (prop.value?.valueFormat !== PropertyValueFormat.Primitive) {\n toaster.warning(\"Only primitive types are supported for now.\");\n return false;\n }\n if (prop.value.value === undefined) {\n return false;\n }\n\n function replaceAll(str: string, match: string, replacement: string) {\n return str.split(match).join(replacement);\n }\n // if property value has single quote, escape\n if (\n (typeof prop.value.value === \"string\" ||\n prop.value.value instanceof String) &&\n String(prop.value.value).indexOf(\"'\") >= 0\n ) {\n prop.value.value = replaceAll(prop.value.value.toString(), \"'\", \"''\");\n }\n\n // get descriptor\n const descriptor = await this.dataProvider?.getContentDescriptor();\n const propertyField = (await this.dataProvider?.getFieldByPropertyRecord(\n prop,\n )) as PropertiesField;\n\n if (!descriptor || !propertyField) {\n toaster.negative(\n \"Error. Failed to fetch field for this property record.\",\n );\n return false;\n }\n\n // get the special cases\n const isNavigation: boolean =\n prop.property.typename.toLowerCase() === \"navigation\";\n const isCategory: boolean = isNavigation && this.isCategory(propertyField);\n const isAspect: boolean =\n propertyField.parent?.pathToPrimaryClass.find(\n (a) =>\n a.relationshipInfo?.name ===\n QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||\n a.relationshipInfo?.name === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS,\n ) !== undefined;\n\n for (let i = 0; i < propertyField.properties.length; i++) {\n const className = propertyField.properties[i].property.classInfo.name.replace(\":\", \".\");\n const propertyName = isNavigation\n ? isCategory\n ? `${propertyField.properties[i].property.name}.CodeValue`\n : `${propertyField.properties[i].property.name}.id`\n : propertyField.properties[i].property.name;\n const propertyValue = isNavigation\n ? isCategory\n ? prop.value.displayValue ?? \"\"\n : (prop.value.value as InstanceKey).id\n : prop.value.value;\n\n if (\n !isAspect &&\n propertyField.parent?.pathToPrimaryClass &&\n propertyField.parent?.pathToPrimaryClass.length > 0\n ) {\n this.addRelatedProperty(\n i,\n propertyField,\n propertyName,\n propertyValue,\n isAspect,\n );\n } else {\n this.addPropertyToQuery(\n i,\n className,\n propertyName,\n propertyValue,\n isAspect,\n this.needsQuote(propertyField),\n isCategory,\n false,\n );\n }\n }\n return true;\n }\n\n private needsQuote(propertyField: PropertiesField): boolean {\n // list of property types that need quote around property value\n if (propertyField.type.typeName.toLowerCase() === \"string\") {\n return true;\n }\n if (propertyField.type.typeName.toLowerCase() === \"uri\") {\n return true;\n }\n return false;\n }\n\n private addRelatedProperty(\n unionIndex: number,\n propertyField: PropertiesField,\n propertyName: string,\n propertyValue: Primitives.Value,\n isAspect: boolean,\n ) {\n const addProperty = this.addRelatedPropertyToQuery(unionIndex, isAspect);\n\n const paths = [...(propertyField.parent?.pathToPrimaryClass ?? [])];\n paths.reverse().forEach((path) => {\n const sourceClassName = path.sourceClassInfo?.name.replace(\":\", \".\");\n const targetClassName = path.targetClassInfo?.name.replace(\":\", \".\");\n const relClassName = path.relationshipInfo?.name.replace(\":\", \".\");\n\n const relPropertyName = path.isForwardRelationship\n ? `SourceECInstanceId`\n : `TargetECInstanceId`;\n\n const relPropertyValue = path.isForwardRelationship\n ? `${relClassName}.TargetECInstanceId`\n : `${relClassName}.SourceECInstanceId`;\n\n addProperty(\n targetClassName,\n `ECInstanceId`,\n relPropertyValue,\n false\n );\n\n addProperty(\n relClassName,\n relPropertyName,\n `${sourceClassName}.ECInstanceId`,\n false\n );\n\n if (path.sourceClassInfo?.name\n === propertyField.parent?.contentClassInfo.name) {\n addProperty(\n sourceClassName,\n propertyName,\n propertyValue,\n this.needsQuote(propertyField)\n );\n }\n });\n }\n\n private addRelatedPropertyToQuery = (\n unionIndex: number,\n isAspect: boolean,\n ) => (\n className: string,\n propertyName: string,\n propertyValue: Primitives.Value,\n needsQuote: boolean,\n ) => this.addPropertyToQuery(unionIndex, className, propertyName, propertyValue, isAspect, needsQuote, false, true);\n\n private addPropertyToQuery(\n unionIndex: number,\n className: string,\n propertyName: string,\n propertyValue: Primitives.Value,\n isAspect: boolean,\n needsQuote: boolean,\n isCategory: boolean,\n isRelational?: boolean,\n ) {\n if (this.query === undefined || this.query.unions.length === 0) {\n this.query = { unions: [] };\n }\n\n const queryProperty: QueryProperty = {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n };\n\n const queryClass: QueryClass = {\n className,\n isAspect,\n isRelational,\n properties: [\n queryProperty,\n ],\n };\n\n if (this.query.unions.length <= unionIndex) {\n this.query.unions.push({\n classes: [\n queryClass,\n ],\n });\n return;\n }\n\n const foundClass = this.query.unions[unionIndex].classes.find(\n (c) => c.className === className,\n );\n if (foundClass) {\n foundClass.isRelational = isRelational;\n if (!foundClass.properties.find((x) => x.name === propertyName)) {\n foundClass.properties.push(queryProperty);\n }\n } else {\n this.query.unions[unionIndex].classes.push(queryClass);\n }\n }\n\n public async removeProperty(prop: PropertyRecord) {\n if (this.query === undefined || this.query.unions.length === 0) {\n return;\n }\n if (\n this.query.unions.length === 1 &&\n this.query.unions[0].classes.length === 0\n ) {\n return;\n }\n\n const descriptor = await this.dataProvider?.getContentDescriptor();\n const propertyField = (await this.dataProvider?.getFieldByPropertyRecord(\n prop,\n )) as PropertiesField;\n if (!descriptor || !propertyField) {\n return;\n }\n\n const isAspect: boolean =\n propertyField.parent?.pathToPrimaryClass.find(\n (a) =>\n a.relationshipInfo?.name ===\n QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||\n a.relationshipInfo?.name === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS,\n ) !== undefined;\n const isNavigation: boolean =\n prop.property.typename.toLowerCase() === \"navigation\";\n const isCategory: boolean = isNavigation && this.isCategory(propertyField);\n\n for (let i = 0; i < propertyField.properties.length; i++) {\n const propertyName = isNavigation\n ? isCategory\n ? `${propertyField.properties[i].property.name}.CodeValue`\n : `${propertyField.properties[i].property.name}.id`\n : propertyField.properties[i].property.name;\n const className = propertyField.properties[i].property.classInfo.name.replace(\":\", \".\");\n\n if (\n !isAspect &&\n propertyField.parent?.pathToPrimaryClass &&\n propertyField.parent?.pathToPrimaryClass.length > 0\n ) {\n this.removeRelatedProperty(i, propertyField, propertyName);\n } else {\n this.removePropertyFromQuery(i, className, propertyName);\n }\n }\n }\n\n private removeRelatedProperty(\n unionIndex: number,\n propertyField: PropertiesField,\n propertyName: string,\n ) {\n const paths = [...(propertyField.parent?.pathToPrimaryClass ?? [])];\n paths.reverse().forEach((path) => {\n const sourceClassName = path.sourceClassInfo?.name.replace(\":\", \".\");\n const targetClassName = path.targetClassInfo?.name.replace(\":\", \".\");\n const relClassName = path.relationshipInfo?.name.replace(\":\", \".\");\n\n this.removePropertyFromQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n );\n\n const relPropertyName = path.isForwardRelationship ? `SourceECInstanceId` : `TargetECInstanceId`;\n this.removePropertyFromQuery(\n unionIndex,\n relClassName,\n relPropertyName,\n );\n\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n );\n }\n });\n }\n\n private removePropertyFromQuery(\n unionIndex: number,\n className: string,\n propertyName: string,\n ) {\n const foundClass = this.query?.unions[unionIndex].classes.find(\n (c) => c.className === className,\n );\n if (foundClass) {\n const foundPropertyIndex = foundClass.properties.findIndex(\n (p) => p.name === propertyName,\n );\n if (foundPropertyIndex > -1) {\n foundClass.properties.splice(foundPropertyIndex, 1);\n }\n if (foundClass.properties.length === 0) {\n // remove the entire class if all properties are removed\n const foundClassIndex =\n this.query?.unions[unionIndex].classes.findIndex(\n (c) => c.className === className,\n ) ?? -1;\n if (foundClassIndex > -1) {\n this.query?.unions[unionIndex].classes.splice(foundClassIndex, 1);\n }\n }\n }\n }\n\n public buildQueryString() {\n if (\n this.query === undefined ||\n this.query.unions.length === 0 ||\n this.query.unions[0].classes.length === 0\n ) {\n return \"\";\n }\n\n const unionSegments: string[] = [];\n for (const union of this.query.unions) {\n const querySegments: string[] = [];\n\n const baseClass = union.classes[0];\n const baseClassName = baseClass.className;\n const baseIdName = baseClass.isAspect\n ? `${baseClassName}.Element.id`\n : `${baseClassName}.ECInstanceId`;\n\n const selectSegment = `SELECT ${baseIdName}${baseClass.isAspect ? \" ECInstanceId\" : \"\"} FROM ${baseClassName}`;\n querySegments.push(selectSegment);\n\n if (union.classes.length > 1) {\n for (let i = 1; i < union.classes.length; i++) {\n const joinClass = union.classes[i];\n const joinClassName = joinClass.className;\n const joinIdName = joinClass.isAspect\n ? `${joinClassName}.Element.id`\n : `${joinClassName}.ECInstanceId`;\n\n const joinSegment = joinClass.isRelational\n ? ` JOIN ${joinClassName}`\n : ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;\n querySegments.push(joinSegment);\n\n for (let j = 0; j < joinClass.properties.length; j++) {\n const prefix = j === 0 && joinClass.isRelational ? \"ON\" : \"AND\";\n const propertySegment = this.propertySegment(joinClassName, joinClass.properties[j], prefix);\n querySegments.push(propertySegment);\n }\n // when base is regular property, link base to first joined relational property\n if (joinClass.isRelational && !baseClass.isRelational && i === 1) {\n querySegments.push(` AND ${joinIdName} = ${baseIdName}`);\n }\n }\n }\n\n const whereSegment = this.whereSegment(baseClass, baseClassName);\n querySegments.push(whereSegment);\n\n unionSegments.push(querySegments.join(\"\"));\n }\n\n return unionSegments.join(\" UNION \");\n }\n\n private whereSegment = (\n baseClass: QueryClass,\n baseClassName: string\n ): string => {\n const segments: string[] = [];\n\n const properties = baseClass.properties;\n for (let i = 0; i < properties.length; i++) {\n const prefix = i === 0 ? \"WHERE\" : \"AND\";\n segments.push(this.propertySegment(baseClassName, properties[i], prefix));\n }\n\n return segments.join(\"\");\n }\n\n private propertySegment(\n className: string,\n property: QueryProperty,\n prefix: string\n ): string {\n const segments: string[] = [];\n\n if (property.isCategory) {\n segments.push(this.categoryQuery(property.value.toString()));\n } else {\n if (property.needsQuote) {\n segments.push(` ${prefix} ${className}.${property.name}='${property.value}'`);\n } else {\n if (this.isFloat(property.value)) {\n segments.push(` ${prefix} ROUND(${className}.${property.name}, `);\n segments.push(`${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`);\n segments.push(`${Number(property.value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION\n )}`);\n } else {\n segments.push(` ${prefix} ${className}.${property.name}=${property.value}`);\n }\n }\n }\n\n return segments.join(\"\");\n }\n\n private categoryQuery(codeValue: string): string {\n return ` JOIN bis.Category ON bis.Category.ECInstanceId = bis.GeometricElement3d.category.id AND ((bis.Category.CodeValue='${codeValue}') OR (bis.Category.UserLabel='${codeValue}'))`;\n }\n\n private isFloat(n: unknown): boolean {\n return Number(n) === n && n % 1 !== 0;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"QueryBuilder.js","sourceRoot":"","sources":["../../../../src/widget/components/QueryBuilder.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAyC/C,4FAA4F;AAC5F,MAAM,OAAO,YAAY;IAUvB,YAAY,QAA0C;QAI/C,eAAU,GAAG,GAAG,EAAE;YACvB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACzB,CAAC,CAAA;QAQO,iBAAY,GAA+B,IAAI,GAAG,EAAE,CAAC;QAErD,oBAAe,GAAG,GAAG,EAAE;YAC7B,IAAI,CAAC,UAAU,EAAE,CAAC;YAElB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE;gBACjD,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;aACvE;QACH,CAAC,CAAA;QA6VO,2BAAsB,GAAG,CAAC,OAAqB,EAAE,aAAoC,EAAyB,EAAE;;YACtH,KAAK,MAAM,UAAU,IAAI,OAAO,EAAE;gBAChC,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE;oBAC7C,MAAM,YAAY,GAAG;wBACnB,GAAG,MAAA,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,mCAAI,EAAE;wBACnD,GAAG,UAAU,CAAC,SAAS,IAAI,SAAS,CAAC,aAAa,MAAM,SAAS,CAAC,aAAa,IAAI,SAAS,CAAC,iBAAiB,EAAE;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,SAAS,CAAC,CAAC;IACvC,CAAC;IAEO,YAAY,CAAC,YAAuC,EAAE,SAAiC;QAC7F,IAAI,SAAS,EAAE;YACb,OAAO,UAAU,SAAS,CAAC,SAAS,kBAAkB,SAAS,CAAC,SAAS,mBAAmB,SAAS,CAAC,SAAS,EAAE,CAAC;SACnH;QAED,IAAI,YAAY,EAAE;YAChB,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ;gBACtC,CAAC,CAAC,GAAG,YAAY,CAAC,SAAS,0BAA0B;gBACrD,CAAC,CAAC,GAAG,YAAY,CAAC,SAAS,kBAAkB,YAAY,CAAC,SAAS,YAAY,CAAC;YAElF,OAAO,UAAU,UAAU,SAAS,YAAY,CAAC,SAAS,EAAE,CAAC;SAC9D;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IA0BO,kBAAkB,CAAC,SAAiB;QAC1C,OAAO,mCAAmC,SAAS,wCAAwC,SAAS,KAAK,CAAC;IAC5G,CAAC;IAEO,OAAO,CAAC,CAAU;QACxB,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;;AA1ZuB,uCAA0B,GAChD,iCAAiC,CAAC;AACZ,wCAA2B,GACjD,iCAAiC,CAAC;AACZ,qCAAwB,GAAG,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { PresentationPropertyDataProvider } from \"@itwin/presentation-components\";\nimport type {\n InstanceKey,\n PropertiesField,\n} from \"@itwin/presentation-common\";\nimport type { Primitives, PropertyRecord } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport { toaster } from \"@itwin/itwinui-react\";\n\nexport interface Query {\n unions: QueryUnion[];\n}\n\nexport interface QueryUnion {\n classes: QueryClass[];\n properties: QueryProperty[];\n}\n\nexport interface QueryClass {\n // schemaName.className\n className: string;\n classJoins: ClassJoin[];\n}\n\nexport interface ClassJoin {\n classProperty: string;\n joinClassName: string;\n joinClassProperty: string;\n}\n\nexport interface QueryProperty {\n className: string;\n classProperties: ClassProperty[];\n isCategory: boolean;\n isAspect: boolean;\n}\n\nexport interface ClassProperty {\n name: string;\n value: Primitives.Value;\n needsQuote: boolean;\n}\n\nexport interface AddedProperty {\n propertyRecord: PropertyRecord;\n propertiesField: PropertiesField;\n}\n\n/* This class is to build adaptive and dynamic query for find similar property selections */\nexport class QueryBuilder {\n private static readonly MULTI_ASPECT_PRIMARY_CLASS =\n \"BisCore:ElementOwnsMultiAspects\";\n private static readonly UNIQUE_ASPECT_PRIMARY_CLASS =\n \"BisCore:ElementOwnsUniqueAspect\";\n private static readonly DEFAULT_DOUBLE_PRECISION = 4;\n\n private dataProvider: PresentationPropertyDataProvider;\n private query: Query | undefined;\n\n constructor(provider: PresentationPropertyDataProvider) {\n this.dataProvider = provider;\n }\n\n public resetQuery = () => {\n this.query = undefined;\n }\n\n private isCategory(propertyField: PropertiesField): boolean {\n const classInfo =\n propertyField.properties[0].property.navigationPropertyInfo?.classInfo;\n return classInfo?.name === \"BisCore:GeometricElement3dIsInCategory\";\n }\n\n private _propertyMap: Map<string, AddedProperty> = new Map();\n\n private regenerateQuery = () => {\n this.resetQuery();\n\n for (const property of this._propertyMap.values()) {\n this.buildProperty(property.propertyRecord, property.propertiesField);\n }\n }\n\n public async addProperty(prop: PropertyRecord): Promise<boolean> {\n // TODO: only handle primitive properties now\n if (prop.value?.valueFormat !== PropertyValueFormat.Primitive) {\n toaster.warning(\"Only primitive types are supported for now.\");\n return false;\n }\n if (prop.value.value === undefined) {\n return false;\n }\n\n const propertyField = (await this.dataProvider.getFieldByPropertyRecord(\n prop,\n )) as PropertiesField;\n\n if (!propertyField) {\n toaster.negative(\n \"Error. Failed to fetch field for this property record.\",\n );\n return false;\n }\n\n this._propertyMap.set(JSON.stringify(propertyField.getFieldDescriptor()), { propertyRecord: prop, propertiesField: propertyField });\n return true;\n }\n\n public async removeProperty(prop: PropertyRecord) {\n const propertyField = (await this.dataProvider.getFieldByPropertyRecord(\n prop,\n )) as PropertiesField;\n\n this._propertyMap.delete(JSON.stringify(propertyField.getFieldDescriptor()));\n }\n\n private buildProperty(prop: PropertyRecord, propertiesField: PropertiesField) {\n if (prop.value?.valueFormat !== PropertyValueFormat.Primitive || prop.value.value === undefined) {\n toaster.negative(\n \"Error. An unexpected error has occured while building a query.\",\n );\n return;\n }\n\n function replaceAll(str: string, match: string, replacement: string) {\n return str.split(match).join(replacement);\n }\n // if property value has single quote, escape\n if (\n (typeof prop.value.value === \"string\" ||\n prop.value.value instanceof String) &&\n String(prop.value.value).indexOf(\"'\") >= 0\n ) {\n prop.value.value = replaceAll(prop.value.value.toString(), \"'\", \"''\");\n }\n\n const pathToPrimaryClass = propertiesField.parent?.pathToPrimaryClass;\n\n // get the special cases\n const isNavigation: boolean =\n prop.property.typename.toLowerCase() === \"navigation\";\n const isCategory: boolean = isNavigation && this.isCategory(propertiesField);\n\n const isAspect: boolean =\n pathToPrimaryClass?.find(\n (a) =>\n a.relationshipInfo?.name ===\n QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||\n a.relationshipInfo?.name === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS,\n ) !== undefined;\n\n for (let i = 0; i < propertiesField.properties.length; i++) {\n const property = propertiesField.properties[i].property;\n\n const className = property.classInfo.name.replace(\":\", \".\");\n const propertyName = isNavigation\n ? isCategory\n ? `${property.name}.CodeValue`\n : `${property.name}.id`\n : property.name;\n const propertyValue = isNavigation\n ? isCategory\n ? prop.value.displayValue ?? \"\"\n : (prop.value.value as InstanceKey).id\n : prop.value.value;\n\n if (\n !isAspect &&\n pathToPrimaryClass &&\n pathToPrimaryClass.length > 0\n ) {\n this.addRelatedToQuery(\n i,\n propertiesField,\n propertyName,\n propertyValue,\n );\n } else {\n this.addPropertyToQuery(\n i,\n className,\n propertyName,\n propertyValue,\n this.needsQuote(propertiesField),\n isCategory,\n isAspect,\n );\n }\n }\n return true;\n }\n\n private needsQuote(propertyField: PropertiesField): boolean {\n // list of property types that need quote around property value\n if (propertyField.type.typeName.toLowerCase() === \"string\") {\n return true;\n }\n if (propertyField.type.typeName.toLowerCase() === \"uri\") {\n return true;\n }\n return false;\n }\n\n private addRelatedToQuery(\n unionIndex: number,\n propertyField: PropertiesField,\n propertyName: string,\n propertyValue: Primitives.Value,\n ) {\n const paths = [...(propertyField.parent?.pathToPrimaryClass ?? [])];\n paths.reverse().forEach((path) => {\n const sourceClassName = path.sourceClassInfo?.name.replace(\":\", \".\");\n const targetClassName = path.targetClassInfo?.name.replace(\":\", \".\");\n const relClassName = path.relationshipInfo?.name.replace(\":\", \".\");\n\n const relClassProperty = path.isForwardRelationship\n ? `SourceECInstanceId`\n : `TargetECInstanceId`;\n\n const relPropertyValue = path.isForwardRelationship\n ? `TargetECInstanceId`\n : `SourceECInstanceId`;\n\n this.addClassToQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n relClassName,\n relPropertyValue\n );\n\n this.addClassToQuery(\n unionIndex,\n relClassName,\n relClassProperty,\n sourceClassName,\n `ECInstanceId`\n );\n\n if (path.sourceClassInfo?.name\n === propertyField.parent?.contentClassInfo.name) {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n propertyValue,\n this.needsQuote(propertyField),\n false,\n false,\n );\n }\n });\n }\n\n private addClassToQuery(\n unionIndex: number,\n className: string,\n classProperty: string,\n joinClassName: string,\n joinClassProperty: string,\n ) {\n if (this.query === undefined) {\n this.query = { unions: [] };\n }\n\n const classJoin: ClassJoin = {\n classProperty,\n joinClassName,\n joinClassProperty,\n };\n\n const queryClass: QueryClass = {\n className,\n classJoins: [classJoin],\n };\n\n if (this.query.unions.length <= unionIndex) {\n this.query.unions.push({\n classes: [queryClass],\n properties: [],\n });\n return;\n }\n\n const foundClass = this.query.unions[unionIndex].classes.find((c) =>\n c.className === className\n );\n\n if (foundClass) {\n const foundJoin = foundClass.classJoins.find((join) =>\n join.classProperty === classProperty && join.joinClassName === joinClassName && join.joinClassProperty === joinClassProperty\n );\n\n if (!foundJoin)\n foundClass.classJoins.push(classJoin);\n return;\n }\n\n this.query.unions[unionIndex].classes.push(queryClass);\n }\n\n private addPropertyToQuery(\n unionIndex: number,\n className: string,\n propertyName: string,\n propertyValue: Primitives.Value,\n needsQuote: boolean,\n isCategory: boolean,\n isAspect: boolean,\n ) {\n if (this.query === undefined) {\n this.query = { unions: [] };\n }\n\n const queryJoin: ClassProperty = {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n };\n\n const queryProperty: QueryProperty = {\n className,\n isCategory,\n isAspect,\n classProperties: [queryJoin],\n };\n\n if (this.query.unions.length <= unionIndex) {\n this.query.unions.push({\n classes: [],\n properties: [queryProperty],\n });\n return;\n }\n\n const foundPropertyClass = this.query.unions[unionIndex].properties.find((p) =>\n p.className === className\n );\n\n if (foundPropertyClass) {\n const foundJoin = foundPropertyClass?.classProperties.find((join) =>\n join.name === propertyName\n );\n\n if (foundJoin) {\n foundJoin.value = propertyValue;\n return;\n }\n\n foundPropertyClass.classProperties.push(queryJoin);\n return;\n }\n\n this.query.unions[unionIndex].properties.push(queryProperty);\n }\n\n public buildQueryString() {\n this.regenerateQuery();\n if (\n this.query === undefined ||\n (this.query.unions.find((u) => u.classes.length === 0 && u.properties.length === 0))\n ) {\n return \"\";\n }\n\n const unionSegments: string[] = [];\n for (const union of this.query.unions) {\n\n const baseClass = union.classes[0];\n const baseProperty = union.properties[0];\n const baseClassName = baseClass ? baseClass.className : baseProperty?.className;\n const baseIdName = `${baseClassName}.ECInstanceId`;\n\n const selectClause = this.selectClause(baseProperty, baseClass);\n\n let querySegments: Map<string, string[]> = new Map();\n querySegments = this.relationalJoinSegments(union.classes, querySegments);\n\n const whereSegments: string[] = [];\n for (const property of union.properties) {\n if (property.isCategory) {\n if (property.className !== baseClassName)\n querySegments.set(\"BisCore.GeometricElement3d\", [`BisCore.GeometricElement3d.ECInstanceId = ${baseIdName}`]);\n\n querySegments.set(\"BisCore.Category\", [`BisCore.Category.ECInstanceId = BisCore.GeometricElement3d.category.id`]);\n whereSegments.push(this.categoryWhereQuery(property.classProperties[0].value.toString()));\n continue;\n }\n\n const joinIdName = property.isAspect\n ? `${property.className}.Element.id`\n : `${property.className}.ECInstanceId`;\n\n if (!querySegments.has(property.className) && property.className !== baseClassName)\n querySegments.set(property.className, [`${joinIdName} = ${baseIdName}`]);\n\n for (const prop of property.classProperties) {\n whereSegments.push(this.propertyQuerySegment(property.className, prop, prop.needsQuote));\n }\n }\n\n const joinClauses: string[] = [];\n for (const key of querySegments.keys()) {\n joinClauses.push(`JOIN ${key} ON ${querySegments.get(key)?.join(\" AND \")}`);\n }\n\n const whereClause = `WHERE ${whereSegments.join(\" AND \")}`;\n\n unionSegments.push([selectClause, ...joinClauses, whereClause].join(\" \"));\n }\n\n return unionSegments.join(\" UNION \");\n }\n\n private selectClause(baseProperty: QueryProperty | undefined, baseClass: QueryClass | undefined) {\n if (baseClass) {\n return `SELECT ${baseClass.className}.ECInstanceId, ${baseClass.className}.ECClassId FROM ${baseClass.className}`;\n }\n\n if (baseProperty) {\n const baseIdName = baseProperty.isAspect\n ? `${baseProperty.className}.Element.id ECInstanceId`\n : `${baseProperty.className}.ECInstanceId, ${baseProperty.className}.ECClassId`;\n\n return `SELECT ${baseIdName} FROM ${baseProperty.className}`;\n }\n\n return \"\";\n }\n\n private relationalJoinSegments = (classes: QueryClass[], querySegments: Map<string, string[]>): Map<string, string[]> => {\n for (const queryClass of classes) {\n for (const classJoin of queryClass.classJoins) {\n const querySegment = [\n ...querySegments.get(classJoin.joinClassName) ?? [],\n `${queryClass.className}.${classJoin.classProperty} = ${classJoin.joinClassName}.${classJoin.joinClassProperty}`,\n ];\n querySegments.set(classJoin.joinClassName, querySegment);\n }\n }\n\n return querySegments;\n }\n\n private propertyQuerySegment = (className: string, property: ClassProperty, needsQuote: boolean): string => {\n if (this.isFloat(property.value))\n return `ROUND(${className}.${property.name}, ` +\n `${QueryBuilder.DEFAULT_DOUBLE_PRECISION}) = ` +\n `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;\n\n const propertyValue = needsQuote ? `'${property.value}'` : property.value;\n return `${className}.${property.name} = ${propertyValue}`;\n }\n\n private categoryWhereQuery(codeValue: string): string {\n return `((BisCore.Category.CodeValue = '${codeValue}') OR (BisCore.Category.UserLabel = '${codeValue}'))`;\n }\n\n private isFloat(n: unknown): boolean {\n return Number(n) === n && n % 1 !== 0;\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { PropertyRecord } from "@itwin/appui-abstract";
|
|
3
|
+
import type { QueryBuilder } from "../QueryBuilder";
|
|
4
|
+
export interface PropertySelection {
|
|
5
|
+
currentPropertyList: PropertyRecord[];
|
|
6
|
+
setCurrentPropertyList: (value: PropertyRecord[]) => void;
|
|
7
|
+
setQuery: (value: string) => void;
|
|
8
|
+
queryBuilder?: QueryBuilder;
|
|
9
|
+
setQueryBuilder: (value: QueryBuilder | undefined) => void;
|
|
10
|
+
isUpdating: boolean;
|
|
11
|
+
resetView: () => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare const PropertyGridWrapperContext: React.Context<PropertySelection>;
|
|
14
|
+
export declare const usePropertyGridWrapper: () => PropertySelection;
|
|
15
|
+
//# sourceMappingURL=PropertyGridWrapperContext.d.ts.map
|
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as React from "react";
|
|
6
|
-
|
|
7
|
-
export const GroupQueryBuilderContext = React.createContext({
|
|
6
|
+
export const PropertyGridWrapperContext = React.createContext({
|
|
8
7
|
currentPropertyList: [],
|
|
9
8
|
setCurrentPropertyList: () => [],
|
|
10
|
-
query: "",
|
|
11
9
|
setQuery: () => "",
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
isLoading: false,
|
|
15
|
-
isRendering: false,
|
|
10
|
+
setQueryBuilder: () => undefined,
|
|
11
|
+
isUpdating: false,
|
|
16
12
|
resetView: async () => { },
|
|
17
13
|
});
|
|
18
|
-
|
|
14
|
+
export const usePropertyGridWrapper = () => {
|
|
15
|
+
const context = React.useContext(PropertyGridWrapperContext);
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error("usePropertyGridWrapperContext should be used within a PropertyGridWrapperContext provider");
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=PropertyGridWrapperContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PropertyGridWrapperContext.js","sourceRoot":"","sources":["../../../../../src/widget/components/context/PropertyGridWrapperContext.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAc/B,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,CAAC,aAAa,CAAoB;IAC/E,mBAAmB,EAAE,EAAE;IACvB,sBAAsB,EAAE,GAAG,EAAE,CAAC,EAAE;IAChC,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE;IAClB,eAAe,EAAE,GAAG,EAAE,CAAC,SAAS;IAChC,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,KAAK,IAAI,EAAE,GAAG,CAAC;CAC3B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAsB,EAAE;IAC5D,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC;IAC7D,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport * as React from \"react\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport type { QueryBuilder } from \"../QueryBuilder\";\n\nexport interface PropertySelection {\n currentPropertyList: PropertyRecord[];\n setCurrentPropertyList: (value: PropertyRecord[]) => void;\n setQuery: (value: string) => void;\n queryBuilder?: QueryBuilder;\n setQueryBuilder: (value: QueryBuilder | undefined) => void;\n isUpdating: boolean;\n resetView: () => Promise<void>;\n}\n\nexport const PropertyGridWrapperContext = React.createContext<PropertySelection>({\n currentPropertyList: [],\n setCurrentPropertyList: () => [],\n setQuery: () => \"\",\n setQueryBuilder: () => undefined,\n isUpdating: false,\n resetView: async () => { },\n});\n\nexport const usePropertyGridWrapper = (): PropertySelection => {\n const context = React.useContext(PropertyGridWrapperContext);\n if (!context) {\n throw new Error(\n \"usePropertyGridWrapperContext should be used within a PropertyGridWrapperContext provider\"\n );\n }\n return context;\n};\n"]}
|