@itwin/grouping-mapping-widget 0.32.0 → 0.34.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 (63) hide show
  1. package/lib/cjs/WidgetShell/GroupingMapping.d.ts +1 -0
  2. package/lib/cjs/WidgetShell/GroupingMapping.js +1 -1
  3. package/lib/cjs/WidgetShell/GroupingMapping.js.map +1 -1
  4. package/lib/cjs/WidgetShell/GroupingMappingContent.d.ts +2 -1
  5. package/lib/cjs/WidgetShell/GroupingMappingContent.js +2 -2
  6. package/lib/cjs/WidgetShell/GroupingMappingContent.js.map +1 -1
  7. package/lib/cjs/WidgetShell/Router/GroupingMappingRouter.d.ts +2 -1
  8. package/lib/cjs/WidgetShell/Router/GroupingMappingRouter.js +2 -2
  9. package/lib/cjs/WidgetShell/Router/GroupingMappingRouter.js.map +1 -1
  10. package/lib/cjs/components/Groups/Groups.d.ts +2 -1
  11. package/lib/cjs/components/Groups/Groups.js +2 -2
  12. package/lib/cjs/components/Groups/Groups.js.map +1 -1
  13. package/lib/cjs/components/Groups/GroupsView.d.ts +2 -1
  14. package/lib/cjs/components/Groups/GroupsView.js +4 -3
  15. package/lib/cjs/components/Groups/GroupsView.js.map +1 -1
  16. package/lib/cjs/components/Groups/GroupsVisualization.d.ts +1 -2
  17. package/lib/cjs/components/Groups/GroupsVisualization.js +2 -2
  18. package/lib/cjs/components/Groups/GroupsVisualization.js.map +1 -1
  19. package/lib/cjs/components/Groups/QueryBuilder/QueryBuilder.d.ts +7 -3
  20. package/lib/cjs/components/Groups/QueryBuilder/QueryBuilder.js +41 -12
  21. package/lib/cjs/components/Groups/QueryBuilder/QueryBuilder.js.map +1 -1
  22. package/lib/cjs/components/Properties/PropertyAction.js +7 -2
  23. package/lib/cjs/components/Properties/PropertyAction.js.map +1 -1
  24. package/lib/cjs/components/customUI/GroupQueryBuilderCustomUI.js +1 -1
  25. package/lib/cjs/components/customUI/GroupQueryBuilderCustomUI.js.map +1 -1
  26. package/lib/cjs/test/QueryBuilder.test.js +17 -6
  27. package/lib/cjs/test/QueryBuilder.test.js.map +1 -1
  28. package/lib/cjs/test/QueryBuilder.testdata.js +46 -0
  29. package/lib/cjs/test/QueryBuilder.testdata.js.map +1 -1
  30. package/lib/cjs/test/QueryBuilderTestData.d.ts +2 -2
  31. package/lib/cjs/test/QueryBuilderTestData.js.map +1 -1
  32. package/lib/esm/WidgetShell/GroupingMapping.d.ts +1 -0
  33. package/lib/esm/WidgetShell/GroupingMapping.js +1 -1
  34. package/lib/esm/WidgetShell/GroupingMapping.js.map +1 -1
  35. package/lib/esm/WidgetShell/GroupingMappingContent.d.ts +2 -1
  36. package/lib/esm/WidgetShell/GroupingMappingContent.js +2 -2
  37. package/lib/esm/WidgetShell/GroupingMappingContent.js.map +1 -1
  38. package/lib/esm/WidgetShell/Router/GroupingMappingRouter.d.ts +2 -1
  39. package/lib/esm/WidgetShell/Router/GroupingMappingRouter.js +2 -2
  40. package/lib/esm/WidgetShell/Router/GroupingMappingRouter.js.map +1 -1
  41. package/lib/esm/components/Groups/Groups.d.ts +2 -1
  42. package/lib/esm/components/Groups/Groups.js +2 -2
  43. package/lib/esm/components/Groups/Groups.js.map +1 -1
  44. package/lib/esm/components/Groups/GroupsView.d.ts +2 -1
  45. package/lib/esm/components/Groups/GroupsView.js +4 -3
  46. package/lib/esm/components/Groups/GroupsView.js.map +1 -1
  47. package/lib/esm/components/Groups/GroupsVisualization.d.ts +1 -2
  48. package/lib/esm/components/Groups/GroupsVisualization.js +2 -2
  49. package/lib/esm/components/Groups/GroupsVisualization.js.map +1 -1
  50. package/lib/esm/components/Groups/QueryBuilder/QueryBuilder.d.ts +7 -3
  51. package/lib/esm/components/Groups/QueryBuilder/QueryBuilder.js +41 -12
  52. package/lib/esm/components/Groups/QueryBuilder/QueryBuilder.js.map +1 -1
  53. package/lib/esm/components/Properties/PropertyAction.js +7 -2
  54. package/lib/esm/components/Properties/PropertyAction.js.map +1 -1
  55. package/lib/esm/components/customUI/GroupQueryBuilderCustomUI.js +1 -1
  56. package/lib/esm/components/customUI/GroupQueryBuilderCustomUI.js.map +1 -1
  57. package/lib/esm/test/QueryBuilder.test.js +17 -6
  58. package/lib/esm/test/QueryBuilder.test.js.map +1 -1
  59. package/lib/esm/test/QueryBuilder.testdata.js +46 -0
  60. package/lib/esm/test/QueryBuilder.testdata.js.map +1 -1
  61. package/lib/esm/test/QueryBuilderTestData.d.ts +2 -2
  62. package/lib/esm/test/QueryBuilderTestData.js.map +1 -1
  63. package/package.json +1 -1
@@ -3,17 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QueryBuilder = void 0;
4
4
  const appui_abstract_1 = require("@itwin/appui-abstract");
5
5
  const itwinui_react_1 = require("@itwin/itwinui-react");
6
+ const core_common_1 = require("@itwin/core-common");
6
7
  /* This class is to build adaptive and dynamic query for find similar property selections */
7
8
  class QueryBuilder {
8
- constructor(provider) {
9
+ constructor(dataProvider, iModelConnection) {
10
+ this.dataProvider = dataProvider;
11
+ this.iModelConnection = iModelConnection;
9
12
  this._propertyMap = new Map();
10
13
  this.resetQueryBuilder = () => {
11
14
  this._propertyMap = new Map();
12
15
  };
13
- this.regenerateQuery = () => {
16
+ this.regenerateQuery = async () => {
14
17
  this.query = undefined;
15
18
  for (const property of this._propertyMap.values()) {
16
- this.buildProperty(property.propertyRecord, property.propertiesField);
19
+ await this.buildProperty(property.propertyRecord, property.propertiesField);
17
20
  }
18
21
  };
19
22
  this.relationalJoinSegments = (classes, querySegments) => {
@@ -36,12 +39,27 @@ class QueryBuilder {
36
39
  const propertyValue = needsQuote ? `'${property.value}'` : property.value;
37
40
  return `${className}.${property.name} = ${propertyValue}`;
38
41
  };
39
- this.dataProvider = provider;
40
42
  }
41
43
  isCategory(propertyField) {
42
44
  const classInfo = propertyField.properties[0].property.navigationPropertyInfo?.classInfo;
43
45
  return classInfo?.name === "BisCore:GeometricElement3dIsInCategory";
44
46
  }
47
+ async getPotentialModeledElement(propertyField, propertyRecord) {
48
+ const classInfo = propertyField.properties[0].property.navigationPropertyInfo?.classInfo;
49
+ if (propertyRecord.value?.valueFormat !== appui_abstract_1.PropertyValueFormat.Primitive)
50
+ return;
51
+ const navigationPropertyValue = propertyRecord.value.value;
52
+ if (classInfo?.name === "BisCore:ModelContainsElements") {
53
+ // https://www.itwinjs.org/bis/guide/fundamentals/model-fundamentals/#model-identity
54
+ // Lookup the modeled element as they share the same ECInstanceId
55
+ const modeledElementQuery = `SELECT ec_classname(ecclassid) FROM biscore.element WHERE ecinstanceid = ? LIMIT 1`;
56
+ const queryBinder = new core_common_1.QueryBinder();
57
+ queryBinder.bindString(1, navigationPropertyValue.id);
58
+ const modeledElement = (await this.iModelConnection.createQueryReader(modeledElementQuery, queryBinder).next()).value[0];
59
+ return modeledElement.replace(":", ".");
60
+ }
61
+ return;
62
+ }
45
63
  async addProperty(prop) {
46
64
  // TODO: only handle primitive properties now
47
65
  if (prop.value?.valueFormat !== appui_abstract_1.PropertyValueFormat.Primitive) {
@@ -63,7 +81,7 @@ class QueryBuilder {
63
81
  const propertyField = (await this.dataProvider.getFieldByPropertyRecord(prop));
64
82
  this._propertyMap.delete(JSON.stringify(propertyField.getFieldDescriptor()));
65
83
  }
66
- buildProperty(prop, propertiesField) {
84
+ async buildProperty(prop, propertiesField) {
67
85
  if (prop.value?.valueFormat !== appui_abstract_1.PropertyValueFormat.Primitive || prop.value.value === undefined) {
68
86
  itwinui_react_1.toaster.negative("Error. An unexpected error has occured while building a query.");
69
87
  return;
@@ -79,17 +97,22 @@ class QueryBuilder {
79
97
  // get the special cases
80
98
  const isNavigation = prop.property.typename.toLowerCase() === "navigation";
81
99
  const isCategory = isNavigation && this.isCategory(propertiesField);
100
+ const modeledElement = await this.getPotentialModeledElement(propertiesField, prop);
82
101
  const isAspect = pathToPrimaryClass?.find((a) => a.relationshipInfo?.name === QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS || a.relationshipInfo?.name === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS) !== undefined;
83
102
  for (let i = 0; i < propertiesField.properties.length; i++) {
84
103
  const property = propertiesField.properties[i].property;
85
104
  const className = property.classInfo.name.replace(":", ".");
86
- const propertyName = isNavigation ? (isCategory ? `${property.name}.CodeValue` : `${property.name}.id`) : property.name;
87
- const propertyValue = isNavigation ? (isCategory ? prop.value.displayValue ?? "" : prop.value.value.id) : prop.value.value;
105
+ const propertyName = isNavigation ? (isCategory || modeledElement ? `${property.name}.CodeValue` : `${property.name}.id`) : property.name;
106
+ const propertyValue = isNavigation
107
+ ? isCategory || modeledElement
108
+ ? prop.value.displayValue ?? ""
109
+ : prop.value.value.id
110
+ : prop.value.value;
88
111
  if (!isAspect && pathToPrimaryClass && pathToPrimaryClass.length > 0) {
89
112
  this.addRelatedToQuery(i, propertiesField, propertyName, propertyValue);
90
113
  }
91
114
  else {
92
- this.addPropertyToQuery(i, className, propertyName, propertyValue, this.needsQuote(propertiesField), isCategory, isAspect);
115
+ this.addPropertyToQuery(i, className, propertyName, propertyValue, this.needsQuote(propertiesField), isCategory, modeledElement, isAspect);
93
116
  }
94
117
  }
95
118
  return true;
@@ -110,7 +133,7 @@ class QueryBuilder {
110
133
  this.addClassToQuery(unionIndex, targetClassName, `ECInstanceId`, relClassName, relPropertyValue);
111
134
  this.addClassToQuery(unionIndex, relClassName, relClassProperty, sourceClassName, `ECInstanceId`);
112
135
  if (path.sourceClassInfo?.name === propertyField.parent?.contentClassInfo.name) {
113
- this.addPropertyToQuery(unionIndex, sourceClassName, propertyName, propertyValue, this.needsQuote(propertyField), false, false);
136
+ this.addPropertyToQuery(unionIndex, sourceClassName, propertyName, propertyValue, this.needsQuote(propertyField), false, "", false);
114
137
  }
115
138
  });
116
139
  }
@@ -143,7 +166,7 @@ class QueryBuilder {
143
166
  }
144
167
  this.query.unions[unionIndex].classes.push(queryClass);
145
168
  }
146
- addPropertyToQuery(unionIndex, className, propertyName, propertyValue, needsQuote, isCategory, isAspect) {
169
+ addPropertyToQuery(unionIndex, className, propertyName, propertyValue, needsQuote, isCategory, modeledElementClass, isAspect) {
147
170
  if (this.query === undefined) {
148
171
  this.query = { unions: [] };
149
172
  }
@@ -155,6 +178,7 @@ class QueryBuilder {
155
178
  const queryProperty = {
156
179
  className,
157
180
  isCategory,
181
+ modeledElementClass,
158
182
  isAspect,
159
183
  classProperties: [queryJoin],
160
184
  };
@@ -177,8 +201,8 @@ class QueryBuilder {
177
201
  }
178
202
  this.query.unions[unionIndex].properties.push(queryProperty);
179
203
  }
180
- buildQueryString() {
181
- this.regenerateQuery();
204
+ async buildQueryString() {
205
+ await this.regenerateQuery();
182
206
  if (this.query === undefined || this.query.unions.find((u) => u.classes.length === 0 && u.properties.length === 0)) {
183
207
  return "";
184
208
  }
@@ -200,6 +224,11 @@ class QueryBuilder {
200
224
  whereSegments.push(this.categoryWhereQuery(property.classProperties[0].value.toString()));
201
225
  continue;
202
226
  }
227
+ else if (property.modeledElementClass) {
228
+ querySegments.set(property.modeledElementClass, [`${property.modeledElementClass}.ECInstanceId = BisCore.Element.Model.id`]);
229
+ whereSegments.push(`${property.modeledElementClass}.UserLabel = '${property.classProperties[0].value.toString()}' OR ${property.modeledElementClass}.CodeValue = '${property.classProperties[0].value.toString()}'`);
230
+ continue;
231
+ }
203
232
  const joinIdName = property.isAspect ? `${property.className}.Element.id` : `${property.className}.ECInstanceId`;
204
233
  if (!querySegments.has(property.className) && property.className !== baseClassName)
205
234
  querySegments.set(property.className, [`${joinIdName} = ${baseIdName}`]);
@@ -1 +1 @@
1
- {"version":3,"file":"QueryBuilder.js","sourceRoot":"","sources":["../../../../../src/components/Groups/QueryBuilder/QueryBuilder.ts"],"names":[],"mappings":";;;AAOA,0DAA4D;AAC5D,wDAA+C;AAyC/C,4FAA4F;AAC5F,MAAa,YAAY;IAQvB,YAAY,QAA0C;QAS9C,iBAAY,GAA+B,IAAI,GAAG,EAAE,CAAC;QAEtD,sBAAiB,GAAG,GAAG,EAAE;YAC9B,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------------\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 { InstanceKey, PropertiesField } 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 = \"BisCore:ElementOwnsMultiAspects\";\n private static readonly UNIQUE_ASPECT_PRIMARY_CLASS = \"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 private isCategory(propertyField: PropertiesField): boolean {\n const classInfo = propertyField.properties[0].property.navigationPropertyInfo?.classInfo;\n return classInfo?.name === \"BisCore:GeometricElement3dIsInCategory\";\n }\n\n private _propertyMap: Map<string, AddedProperty> = new Map();\n\n public resetQueryBuilder = () => {\n this._propertyMap = new Map();\n };\n\n private regenerateQuery = () => {\n this.query = undefined;\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(prop)) as PropertiesField;\n\n if (!propertyField) {\n toaster.negative(\"Error. Failed to fetch field for this property record.\");\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(prop)) 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(\"Error. An unexpected error has occured while building a query.\");\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 ((typeof prop.value.value === \"string\" || prop.value.value instanceof String) && String(prop.value.value).indexOf(\"'\") >= 0) {\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 = prop.property.typename.toLowerCase() === \"navigation\";\n const isCategory: boolean = isNavigation && this.isCategory(propertiesField);\n\n const isAspect: boolean =\n pathToPrimaryClass?.find(\n (a) => a.relationshipInfo?.name === QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS || 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 ? (isCategory ? `${property.name}.CodeValue` : `${property.name}.id`) : property.name;\n const propertyValue = isNavigation ? (isCategory ? prop.value.displayValue ?? \"\" : (prop.value.value as InstanceKey).id) : prop.value.value;\n\n if (!isAspect && pathToPrimaryClass && pathToPrimaryClass.length > 0) {\n this.addRelatedToQuery(i, propertiesField, propertyName, propertyValue);\n } else {\n this.addPropertyToQuery(i, className, propertyName, propertyValue, this.needsQuote(propertiesField), isCategory, isAspect);\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 const typeName = propertyField.type.typeName.toLowerCase();\n return \"string\" === typeName || \"uri\" === typeName;\n }\n\n private addRelatedToQuery(unionIndex: number, propertyField: PropertiesField, propertyName: string, propertyValue: Primitives.Value) {\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 ? `SourceECInstanceId` : `TargetECInstanceId`;\n\n const relPropertyValue = path.isForwardRelationship ? `TargetECInstanceId` : `SourceECInstanceId`;\n\n this.addClassToQuery(unionIndex, targetClassName, `ECInstanceId`, relClassName, relPropertyValue);\n\n this.addClassToQuery(unionIndex, relClassName, relClassProperty, sourceClassName, `ECInstanceId`);\n\n if (path.sourceClassInfo?.name === propertyField.parent?.contentClassInfo.name) {\n this.addPropertyToQuery(unionIndex, sourceClassName, propertyName, propertyValue, this.needsQuote(propertyField), false, false);\n }\n });\n }\n\n private addClassToQuery(unionIndex: number, className: string, classProperty: string, joinClassName: string, joinClassProperty: string) {\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) => c.className === className);\n\n if (foundClass) {\n const foundJoin = foundClass.classJoins.find(\n (join) => join.classProperty === classProperty && join.joinClassName === joinClassName && join.joinClassProperty === joinClassProperty,\n );\n\n if (!foundJoin) 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) => p.className === className);\n\n if (foundPropertyClass) {\n const foundJoin = foundPropertyClass?.classProperties.find((join) => join.name === propertyName);\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 (this.query === undefined || this.query.unions.find((u) => u.classes.length === 0 && u.properties.length === 0)) {\n return \"\";\n }\n\n const unionSegments: string[] = [];\n for (const union of this.query.unions) {\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 ? `${property.className}.Element.id` : `${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 (\n `ROUND(${className}.${property.name}, ` +\n `${QueryBuilder.DEFAULT_DOUBLE_PRECISION}) = ` +\n `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`\n );\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"]}
1
+ {"version":3,"file":"QueryBuilder.js","sourceRoot":"","sources":["../../../../../src/components/Groups/QueryBuilder/QueryBuilder.ts"],"names":[],"mappings":";;;AAOA,0DAA4D;AAC5D,wDAA+C;AAE/C,oDAAiD;AA0CjD,4FAA4F;AAC5F,MAAa,YAAY;IAMvB,YACmB,YAA8C,EAC9C,gBAAkC;QADlC,iBAAY,GAAZ,YAAY,CAAkC;QAC9C,qBAAgB,GAAhB,gBAAgB,CAAkB;QAwB7C,iBAAY,GAA+B,IAAI,GAAG,EAAE,CAAC;QAEtD,sBAAiB,GAAG,GAAG,EAAE;YAC9B,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,CAAC,CAAC;QAEM,oBAAe,GAAG,KAAK,IAAI,EAAE;YACnC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YAEvB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE;gBACjD,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;aAC7E;QACH,CAAC,CAAC;QA2QM,2B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AC,EAAE,CAAC;YAE3D,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,GAAG,WAAW,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;SAC3E;QAED,OAAO,aAAa,CAAC,IAAI,CAAC,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;IA4BO,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;;AAvVH,oCAwVC;AAvVyB,uCAA0B,GAAG,iCAAiC,CAAC;AAC/D,wCAA2B,GAAG,iCAAiC,CAAC;AAChE,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 { InstanceKey, NavigationPropertyValue, PropertiesField } from \"@itwin/presentation-common\";\nimport type { Primitives, PropertyRecord } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport { toaster } from \"@itwin/itwinui-react\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport { QueryBinder } from \"@itwin/core-common\";\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 modeledElementClass?: string;\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 = \"BisCore:ElementOwnsMultiAspects\";\n private static readonly UNIQUE_ASPECT_PRIMARY_CLASS = \"BisCore:ElementOwnsUniqueAspect\";\n private static readonly DEFAULT_DOUBLE_PRECISION = 4;\n private query: Query | undefined;\n\n constructor(\n private readonly dataProvider: PresentationPropertyDataProvider,\n private readonly iModelConnection: IModelConnection,\n ) {}\n\n private isCategory(propertyField: PropertiesField): boolean {\n const classInfo = propertyField.properties[0].property.navigationPropertyInfo?.classInfo;\n return classInfo?.name === \"BisCore:GeometricElement3dIsInCategory\";\n }\n\n private async getPotentialModeledElement(propertyField: PropertiesField, propertyRecord: PropertyRecord): Promise<string | undefined> {\n const classInfo = propertyField.properties[0].property.navigationPropertyInfo?.classInfo;\n if (propertyRecord.value?.valueFormat !== PropertyValueFormat.Primitive) return;\n const navigationPropertyValue = propertyRecord.value.value as NavigationPropertyValue;\n if (classInfo?.name === \"BisCore:ModelContainsElements\") {\n // https://www.itwinjs.org/bis/guide/fundamentals/model-fundamentals/#model-identity\n // Lookup the modeled element as they share the same ECInstanceId\n const modeledElementQuery = `SELECT ec_classname(ecclassid) FROM biscore.element WHERE ecinstanceid = ? LIMIT 1`;\n const queryBinder = new QueryBinder();\n queryBinder.bindString(1, navigationPropertyValue.id);\n const modeledElement = (await this.iModelConnection.createQueryReader(modeledElementQuery, queryBinder).next()).value[0];\n return modeledElement.replace(\":\", \".\");\n }\n return;\n }\n\n private _propertyMap: Map<string, AddedProperty> = new Map();\n\n public resetQueryBuilder = () => {\n this._propertyMap = new Map();\n };\n\n private regenerateQuery = async () => {\n this.query = undefined;\n\n for (const property of this._propertyMap.values()) {\n await 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(prop)) as PropertiesField;\n\n if (!propertyField) {\n toaster.negative(\"Error. Failed to fetch field for this property record.\");\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(prop)) as PropertiesField;\n\n this._propertyMap.delete(JSON.stringify(propertyField.getFieldDescriptor()));\n }\n\n private async buildProperty(prop: PropertyRecord, propertiesField: PropertiesField) {\n if (prop.value?.valueFormat !== PropertyValueFormat.Primitive || prop.value.value === undefined) {\n toaster.negative(\"Error. An unexpected error has occured while building a query.\");\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 ((typeof prop.value.value === \"string\" || prop.value.value instanceof String) && String(prop.value.value).indexOf(\"'\") >= 0) {\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 = prop.property.typename.toLowerCase() === \"navigation\";\n const isCategory: boolean = isNavigation && this.isCategory(propertiesField);\n const modeledElement = await this.getPotentialModeledElement(propertiesField, prop);\n\n const isAspect: boolean =\n pathToPrimaryClass?.find(\n (a) => a.relationshipInfo?.name === QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS || 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 ? (isCategory || modeledElement ? `${property.name}.CodeValue` : `${property.name}.id`) : property.name;\n const propertyValue = isNavigation\n ? isCategory || modeledElement\n ? prop.value.displayValue ?? \"\"\n : (prop.value.value as InstanceKey).id\n : prop.value.value;\n\n if (!isAspect && pathToPrimaryClass && pathToPrimaryClass.length > 0) {\n this.addRelatedToQuery(i, propertiesField, propertyName, propertyValue);\n } else {\n this.addPropertyToQuery(i, className, propertyName, propertyValue, this.needsQuote(propertiesField), isCategory, modeledElement, isAspect);\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 const typeName = propertyField.type.typeName.toLowerCase();\n return \"string\" === typeName || \"uri\" === typeName;\n }\n\n private addRelatedToQuery(unionIndex: number, propertyField: PropertiesField, propertyName: string, propertyValue: Primitives.Value) {\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 ? `SourceECInstanceId` : `TargetECInstanceId`;\n\n const relPropertyValue = path.isForwardRelationship ? `TargetECInstanceId` : `SourceECInstanceId`;\n\n this.addClassToQuery(unionIndex, targetClassName, `ECInstanceId`, relClassName, relPropertyValue);\n\n this.addClassToQuery(unionIndex, relClassName, relClassProperty, sourceClassName, `ECInstanceId`);\n\n if (path.sourceClassInfo?.name === propertyField.parent?.contentClassInfo.name) {\n this.addPropertyToQuery(unionIndex, sourceClassName, propertyName, propertyValue, this.needsQuote(propertyField), false, \"\", false);\n }\n });\n }\n\n private addClassToQuery(unionIndex: number, className: string, classProperty: string, joinClassName: string, joinClassProperty: string) {\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) => c.className === className);\n\n if (foundClass) {\n const foundJoin = foundClass.classJoins.find(\n (join) => join.classProperty === classProperty && join.joinClassName === joinClassName && join.joinClassProperty === joinClassProperty,\n );\n\n if (!foundJoin) 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 modeledElementClass: string | undefined,\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 modeledElementClass,\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) => p.className === className);\n\n if (foundPropertyClass) {\n const foundJoin = foundPropertyClass?.classProperties.find((join) => join.name === propertyName);\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 async buildQueryString() {\n await this.regenerateQuery();\n if (this.query === undefined || this.query.unions.find((u) => u.classes.length === 0 && u.properties.length === 0)) {\n return \"\";\n }\n\n const unionSegments: string[] = [];\n for (const union of this.query.unions) {\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 } else if (property.modeledElementClass) {\n querySegments.set(property.modeledElementClass, [`${property.modeledElementClass}.ECInstanceId = BisCore.Element.Model.id`]);\n whereSegments.push(\n `${property.modeledElementClass}.UserLabel = '${property.classProperties[0].value.toString()}' OR ${property.modeledElementClass}.CodeValue = '${property.classProperties[0].value.toString()}'`,\n );\n continue;\n }\n\n const joinIdName = property.isAspect ? `${property.className}.Element.id` : `${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 (\n `ROUND(${className}.${property.name}, ` +\n `${QueryBuilder.DEFAULT_DOUBLE_PRECISION}) = ` +\n `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`\n );\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"]}
@@ -33,8 +33,13 @@ const appui_abstract_1 = require("@itwin/appui-abstract");
33
33
  const PropertyGridWrapperContext_1 = require("../context/PropertyGridWrapperContext");
34
34
  const itwinui_react_1 = require("@itwin/itwinui-react");
35
35
  require("./PropertyAction.scss");
36
+ const GroupingApiConfigContext_1 = require("../context/GroupingApiConfigContext");
36
37
  const usePropertySelection = (property, currentPropertyList, queryBuilder) => {
37
38
  const [isCheckboxLoading, setIsCheckboxLoading] = (0, react_1.useState)(false);
39
+ const { iModelConnection } = (0, GroupingApiConfigContext_1.useGroupingMappingApiConfig)();
40
+ if (!iModelConnection) {
41
+ throw new Error("This hook requires an active iModelConnection.");
42
+ }
38
43
  const checkIfPropertyIsSelected = (0, react_1.useCallback)((property) => {
39
44
  if (property.value.valueFormat === appui_abstract_1.PropertyValueFormat.Primitive) {
40
45
  return currentPropertyList.includes(property);
@@ -76,12 +81,12 @@ const PropertyAction = ({ property }) => {
76
81
  if (isPropertySelected) {
77
82
  await removeProperty(property);
78
83
  setCurrentPropertyList((prevList) => prevList.filter((x) => x !== property));
79
- setQuery(queryBuilder?.buildQueryString() ?? "");
84
+ setQuery(await queryBuilder?.buildQueryString() ?? "");
80
85
  }
81
86
  else {
82
87
  if (await addProperty(property)) {
83
88
  setCurrentPropertyList((prevList) => prevList.concat(property));
84
- setQuery(queryBuilder?.buildQueryString() ?? "");
89
+ setQuery(await queryBuilder?.buildQueryString() ?? "");
85
90
  }
86
91
  }
87
92
  }, [addProperty, isPropertySelected, property, removeProperty, queryBuilder, setCurrentPropertyList, setQuery]);
@@ -1 +1 @@
1
- {"version":3,"file":"PropertyAction.js","sourceRoot":"","sources":["../../../../src/components/Properties/PropertyAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,+CAAgE;AAEhE,0DAA4D;AAC5D,sFAA+E;AAC/E,wDAAgD;AAChD,iCAA+B;AAO/B,MAAM,oBAAoB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AAgB,EAAE,IAAI,EAAE,CAAC,CAAC;SAClD;aAAM;YACL,IAAI,MAAM,WAAW,CAAC,QAAQ,CAAC,EAAE;gBAC/B,sBAAsB,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAChE,QAAQ,CAAC,YAAY,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;aAClD;SACF;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,sBAAsB,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEhH,OAAO,CACL,uCAAK,SAAS,EAAC,iCAAiC,IAC7C,QAAQ,CAAC,KAAK,CAAC,WAAW,KAAK,oCAAmB,CAAC,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,CACrG,8BAAC,wBAAQ,IAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,0BAA0B,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,GAAI,CACpI,CACG,CACP,CAAC;AACJ,CAAC,CAAC;AAjCW,QAAA,cAAc,kBAiCzB","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 React, { useCallback, useEffect, useState } from \"react\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport { usePropertyGridWrapper } from \"../context/PropertyGridWrapperContext\";\nimport { Checkbox } from \"@itwin/itwinui-react\";\nimport \"./PropertyAction.scss\";\nimport type { QueryBuilder } from \"../Groups/QueryBuilder/QueryBuilder\";\n\nexport interface PropertyActionProps {\n property: PropertyRecord;\n}\n\nconst usePropertySelection = (property: PropertyRecord, currentPropertyList: PropertyRecord[], queryBuilder: QueryBuilder | undefined) => {\n const [isCheckboxLoading, setIsCheckboxLoading] = useState(false);\n\n const checkIfPropertyIsSelected = useCallback(\n (property: PropertyRecord): boolean => {\n if (property.value.valueFormat === PropertyValueFormat.Primitive) {\n return currentPropertyList.includes(property);\n }\n\n if (property.value.valueFormat === PropertyValueFormat.Array) {\n return property.value.items.length === 0 && currentPropertyList.includes(property);\n }\n return Object.values(property.value.members).every((subProp: PropertyRecord) => checkIfPropertyIsSelected(subProp));\n },\n [currentPropertyList],\n );\n\n const isPropertySelected = checkIfPropertyIsSelected(property);\n\n const addProperty = useCallback(\n async (prop: PropertyRecord) => {\n if (prop.value.valueFormat === PropertyValueFormat.Primitive && !currentPropertyList.includes(prop) && (await queryBuilder?.addProperty(prop))) {\n setIsCheckboxLoading(false);\n return true;\n }\n return false;\n },\n [currentPropertyList, queryBuilder],\n );\n\n const removeProperty = useCallback(\n async (prop: PropertyRecord) => {\n if (currentPropertyList.includes(prop)) {\n await queryBuilder?.removeProperty(prop);\n setIsCheckboxLoading(false);\n }\n },\n [currentPropertyList, queryBuilder],\n );\n\n return {\n isPropertySelected,\n addProperty,\n removeProperty,\n isCheckboxLoading,\n setIsCheckboxLoading,\n };\n};\n\nexport const PropertyAction = ({ property }: PropertyActionProps) => {\n const { currentPropertyList, queryBuilder, setCurrentPropertyList, setQuery, isUpdating } = usePropertyGridWrapper();\n\n const { isPropertySelected, addProperty, removeProperty, isCheckboxLoading, setIsCheckboxLoading } = usePropertySelection(\n property,\n currentPropertyList,\n queryBuilder,\n );\n\n useEffect(() => {\n setIsCheckboxLoading(isPropertySelected && isUpdating);\n }, [isPropertySelected, isUpdating, setIsCheckboxLoading]);\n\n const onPropertySelectionChanged = useCallback(async () => {\n if (isPropertySelected) {\n await removeProperty(property);\n setCurrentPropertyList((prevList) => prevList.filter((x) => x !== property));\n setQuery(queryBuilder?.buildQueryString() ?? \"\");\n } else {\n if (await addProperty(property)) {\n setCurrentPropertyList((prevList) => prevList.concat(property));\n setQuery(queryBuilder?.buildQueryString() ?? \"\");\n }\n }\n }, [addProperty, isPropertySelected, property, removeProperty, queryBuilder, setCurrentPropertyList, setQuery]);\n\n return (\n <div className=\"gmw-property-selection-checkbox\">\n {property.value.valueFormat === PropertyValueFormat.Primitive && property.value.value !== undefined && (\n <Checkbox checked={isPropertySelected} onChange={onPropertySelectionChanged} disabled={isUpdating} isLoading={isCheckboxLoading} />\n )}\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"PropertyAction.js","sourceRoot":"","sources":["../../../../src/components/Properties/PropertyAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,+CAAgE;AAEhE,0DAA4D;AAC5D,sFAA+E;AAC/E,wDAAgD;AAChD,iCAA+B;AAE/B,kFAAkF;AAMlF,MAAM,oBAAoB,GAAG,CAAC,QAAwB,EAAE,mBAAqC,EAAE,YAAsC,EAAE,EAAE;IACvI,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAClE,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAA,sDAA2B,GAAE,CAAC;IAC3D,IAAI,CAAC,gBAAgB,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;KACnE;IAED,MAAM,yBAAyB,GAAG,IAAA,mBAAW,EAC3C,CAAC,QAAwB,EAAW,EAAE;QACpC,IAAI,QAAQ,CAAC,KAAK,CAAC,WAAW,KAAK,oCAAmB,CAAC,SAAS,EAAE;YAChE,OAAO,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SAC/C;QAED,IAAI,QAAQ,CAAC,KAAK,CAAC,WAAW,KAAK,oCAAmB,CAAC,KAAK,EAAE;YAC5D,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,mBAAmB,CAAC,QAAQ,C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QAAQ,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,CACrG,8BAAC,wBAAQ,IAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,0BAA0B,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,GAAI,CACpI,CACG,CACP,CAAC;AACJ,CAAC,CAAC;AAjCW,QAAA,cAAc,kBAiCzB","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 React, { useCallback, useEffect, useState } from \"react\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport { usePropertyGridWrapper } from \"../context/PropertyGridWrapperContext\";\nimport { Checkbox } from \"@itwin/itwinui-react\";\nimport \"./PropertyAction.scss\";\nimport type { QueryBuilder } from \"../Groups/QueryBuilder/QueryBuilder\";\nimport { useGroupingMappingApiConfig } from \"../context/GroupingApiConfigContext\";\n\nexport interface PropertyActionProps {\n property: PropertyRecord;\n}\n\nconst usePropertySelection = (property: PropertyRecord, currentPropertyList: PropertyRecord[], queryBuilder: QueryBuilder | undefined) => {\n const [isCheckboxLoading, setIsCheckboxLoading] = useState(false);\n const { iModelConnection } = useGroupingMappingApiConfig();\n if (!iModelConnection) {\n throw new Error(\"This hook requires an active iModelConnection.\");\n }\n\n const checkIfPropertyIsSelected = useCallback(\n (property: PropertyRecord): boolean => {\n if (property.value.valueFormat === PropertyValueFormat.Primitive) {\n return currentPropertyList.includes(property);\n }\n\n if (property.value.valueFormat === PropertyValueFormat.Array) {\n return property.value.items.length === 0 && currentPropertyList.includes(property);\n }\n return Object.values(property.value.members).every((subProp: PropertyRecord) => checkIfPropertyIsSelected(subProp));\n },\n [currentPropertyList],\n );\n\n const isPropertySelected = checkIfPropertyIsSelected(property);\n\n const addProperty = useCallback(\n async (prop: PropertyRecord) => {\n if (prop.value.valueFormat === PropertyValueFormat.Primitive && !currentPropertyList.includes(prop) && (await queryBuilder?.addProperty(prop))) {\n setIsCheckboxLoading(false);\n return true;\n }\n return false;\n },\n [currentPropertyList, queryBuilder],\n );\n\n const removeProperty = useCallback(\n async (prop: PropertyRecord) => {\n if (currentPropertyList.includes(prop)) {\n await queryBuilder?.removeProperty(prop);\n setIsCheckboxLoading(false);\n }\n },\n [currentPropertyList, queryBuilder],\n );\n\n return {\n isPropertySelected,\n addProperty,\n removeProperty,\n isCheckboxLoading,\n setIsCheckboxLoading,\n };\n};\n\nexport const PropertyAction = ({ property }: PropertyActionProps) => {\n const { currentPropertyList, queryBuilder, setCurrentPropertyList, setQuery, isUpdating } = usePropertyGridWrapper();\n\n const { isPropertySelected, addProperty, removeProperty, isCheckboxLoading, setIsCheckboxLoading } = usePropertySelection(\n property,\n currentPropertyList,\n queryBuilder,\n );\n\n useEffect(() => {\n setIsCheckboxLoading(isPropertySelected && isUpdating);\n }, [isPropertySelected, isUpdating, setIsCheckboxLoading]);\n\n const onPropertySelectionChanged = useCallback(async () => {\n if (isPropertySelected) {\n await removeProperty(property);\n setCurrentPropertyList((prevList) => prevList.filter((x) => x !== property));\n setQuery(await queryBuilder?.buildQueryString() ?? \"\");\n } else {\n if (await addProperty(property)) {\n setCurrentPropertyList((prevList) => prevList.concat(property));\n setQuery(await queryBuilder?.buildQueryString() ?? \"\");\n }\n }\n }, [addProperty, isPropertySelected, property, removeProperty, queryBuilder, setCurrentPropertyList, setQuery]);\n\n return (\n <div className=\"gmw-property-selection-checkbox\">\n {property.value.valueFormat === PropertyValueFormat.Primitive && property.value.value !== undefined && (\n <Checkbox checked={isPropertySelected} onChange={onPropertySelectionChanged} disabled={isUpdating} isLoading={isCheckboxLoading} />\n )}\n </div>\n );\n};\n"]}
@@ -76,7 +76,7 @@ const GroupQueryBuilderCustomUI = ({ updateQuery, isUpdating, resetView }) => {
76
76
  setSelectionKeyset(keys);
77
77
  const dataProvider = await createPropertyDataProvider(keys, iModelConnection);
78
78
  setDataProvider(dataProvider);
79
- setQueryBuilder(new QueryBuilder_1.QueryBuilder(dataProvider));
79
+ setQueryBuilder(new QueryBuilder_1.QueryBuilder(dataProvider, iModelConnection));
80
80
  };
81
81
  return iModelConnection ? presentation_frontend_1.Presentation.selection.selectionChange.addListener(onSelectionChanged) : () => { };
82
82
  }, [iModelConnection]);
@@ -1 +1 @@
1
- {"version":3,"file":"GroupQueryBuilderCustomUI.js","sourceRoot":"","sources":["../../../../src/components/customUI/GroupQueryBuilderCustomUI.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,+CAAyE;AACzE,wEAA4D;AAE5D,oEAAoD;AACpD,4CAA0C;AAC1C,sEAAmE;AAEnE,4EAAiH;AAGjH,8DAAkF;AAClF,kDAA+D;AAE/D,sFAAmF;AACnF,iEAA8D;AAC9D,wDAAqD;AACrD,kFAAkF;AAClF,wDAAiD;AAEjD,MAAM,0BAA0B,GAAG,KAAK,EAAE,IAAY,EAAE,gBAAkC,EAA6C,EAAE;IACvI,MAAM,YAAY,GAAG,IAAI,0DAAgC,CAAC;QACxD,MAAM,EAAE,gBAAgB;QACxB,OAAO,EAAE,uDAA6B;KACvC,CAAC,CAAC;IACH,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC;IACzB,YAAY,CAAC,uCAAuC,GAAG,IAAI,CAAC;IAC5D,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,CAAC;IAC1C,MAAM,gBAAgB,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAC3C,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,KAAK,yBAAS,CAAC,YAAY,CAAC,kBAAkB,CAAC,0CAA0C,CAAC,CACvH,CAAC;IACF,IAAI,gBAAgB,EAAE;QACpB,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC;KAChC;IACD,OAAO,YAAY,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AAsC,IAClD,CAAC,YAAY,IAAI,eAAe,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAC7C,8BAAC,qBAAK,IAAC,IAAI,EAAC,eAAe,6GAA+G,CAC3I,CAAC,CAAC,CAAC,CACF;QACE,uCAAK,SAAS,EAAC,oCAAoC;YACjD,8BAAC,uCAA0B,IAAC,QAAQ,EAAE,MAAM,GAAI;YAChD,8BAAC,uDAA0B,CAAC,QAAQ,IAAC,KAAK,EAAE,qBAAqB;gBAC/D,8BAAC,0DAAuC,IACtC,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,MAAM,EAAE,IAAI,CAAC,MAAM,EACnB,qBAAqB,EAAE,qBAAqB,GAC5C,CACkC,CAClC;QACN,uCAAK,SAAS,EAAC,yBAAyB;YACtC,8BAAC,sBAAM,IAAC,SAAS,EAAC,SAAS,EAAC,IAAI,EAAC,OAAO,EAAC,OAAO,EAAE,kBAAkB,YAE3D,CACL,CACL,CACJ,CACG,CACP,CAAC;AACJ,CAAC,CAAC;AA5EW,QAAA,yBAAyB,6BA4EpC","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 React, { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport type { ISelectionProvider, SelectionChangeEventArgs } from \"@itwin/presentation-frontend\";\nimport { KeySet } from \"@itwin/presentation-common\";\nimport \"./GroupQueryBuilderCustomUI.scss\";\nimport { QueryBuilder } from \"../Groups/QueryBuilder/QueryBuilder\";\nimport type { GroupingCustomUIProps } from \"./GroupingMappingCustomUI\";\nimport { DEFAULT_PROPERTY_GRID_RULESET, PresentationPropertyDataProvider } from \"@itwin/presentation-components\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { ActionButtonRendererProps } from \"@itwin/components-react\";\nimport { VirtualizedPropertyGridWithDataProvider } from \"@itwin/components-react\";\nimport { ResizableContainerObserver } from \"@itwin/core-react\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { PropertyGridWrapperContext } from \"../context/PropertyGridWrapperContext\";\nimport { PropertyAction } from \"../Properties/PropertyAction\";\nimport { Alert, Button } from \"@itwin/itwinui-react\";\nimport { useGroupingMappingApiConfig } from \"../context/GroupingApiConfigContext\";\nimport { IModelApp } from \"@itwin/core-frontend\";\n\nconst createPropertyDataProvider = async (keys: KeySet, iModelConnection: IModelConnection): Promise<PresentationPropertyDataProvider> => {\n const dataProvider = new PresentationPropertyDataProvider({\n imodel: iModelConnection,\n ruleset: DEFAULT_PROPERTY_GRID_RULESET,\n });\n dataProvider.keys = keys;\n dataProvider.isNestedPropertyCategoryGroupingEnabled = true;\n const data = await dataProvider.getData();\n const selectedCategory = data.categories.find(\n (category) => category.label === IModelApp.localization.getLocalizedString(\"Presentation:selectedItems.categoryLabel\"),\n );\n if (selectedCategory) {\n selectedCategory.expand = true;\n }\n return dataProvider;\n};\n\ninterface ContainerDimensions {\n width: number;\n height: number;\n}\n\n/**\n * A default group query builder for the Grouping Mapping Widget that uses the property grid to generate queries.\n * @public\n */\nexport const GroupQueryBuilderCustomUI = ({ updateQuery, isUpdating, resetView }: GroupingCustomUIProps) => {\n const { iModelConnection } = useGroupingMappingApiConfig();\n if (!iModelConnection) {\n throw new Error(\"This component requires an active iModelConnection.\");\n }\n const [size, setSize] = useState<ContainerDimensions>({ width: 0, height: 0 });\n const [dataProvider, setDataProvider] = useState<PresentationPropertyDataProvider | undefined>(undefined);\n const [currentPropertyList, setCurrentPropertyList] = useState<PropertyRecord[]>([]);\n const [selectionKeySet, setSelectionKeyset] = useState<KeySet>(new KeySet());\n const [queryBuilder, setQueryBuilder] = useState<QueryBuilder | undefined>();\n\n useEffect(() => {\n const onSelectionChanged = async (evt: SelectionChangeEventArgs, selectionProvider: ISelectionProvider) => {\n const selection = selectionProvider.getSelection(evt.imodel, evt.level);\n const keys = new KeySet(selection);\n setSelectionKeyset(keys);\n const dataProvider = await createPropertyDataProvider(keys, iModelConnection);\n setDataProvider(dataProvider);\n setQueryBuilder(new QueryBuilder(dataProvider));\n };\n\n return iModelConnection ? Presentation.selection.selectionChange.addListener(onSelectionChanged) : () => {};\n }, [iModelConnection]);\n\n const onClickResetButton = async () => {\n queryBuilder?.resetQueryBuilder();\n updateQuery(\"\");\n setCurrentPropertyList([]);\n if (resetView)\n await resetView().catch((e) =>\n /* eslint-disable no-console */\n console.error(e),\n );\n };\n\n const resize = useCallback((width, height) => setSize({ width, height }), []);\n\n const propertyContextValues = useMemo(\n () => ({\n currentPropertyList,\n setCurrentPropertyList,\n queryBuilder,\n setQuery: updateQuery,\n isUpdating: isUpdating ?? false,\n }),\n [currentPropertyList, isUpdating, queryBuilder, updateQuery],\n );\n\n const actionButtonRenderers = useMemo(() => [({ property }: ActionButtonRendererProps) => <PropertyAction property={property} />], []);\n\n return (\n <div className=\"gmw-select-query-generator-container\">\n {!dataProvider || selectionKeySet.size === 0 ? (\n <Alert type=\"informational\">Please select on an element within the viewer first, then select properties to generate a group query.</Alert>\n ) : (\n <>\n <div className=\"gmw-select-property-grid-container\">\n <ResizableContainerObserver onResize={resize} />\n <PropertyGridWrapperContext.Provider value={propertyContextValues}>\n <VirtualizedPropertyGridWithDataProvider\n dataProvider={dataProvider}\n width={size.width}\n height={size.height}\n actionButtonRenderers={actionButtonRenderers}\n />\n </PropertyGridWrapperContext.Provider>\n </div>\n <div className=\"gmw-select-reset-button\">\n <Button styleType=\"default\" size=\"small\" onClick={onClickResetButton}>\n Reset\n </Button>\n </div>\n </>\n )}\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"GroupQueryBuilderCustomUI.js","sourceRoot":"","sources":["../../../../src/components/customUI/GroupQueryBuilderCustomUI.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,+CAAy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CAAC,MAAM,EACnB,qBAAqB,EAAE,qBAAqB,GAC5C,CACkC,CAClC;QACN,uCAAK,SAAS,EAAC,yBAAyB;YACtC,8BAAC,sBAAM,IAAC,SAAS,EAAC,SAAS,EAAC,IAAI,EAAC,OAAO,EAAC,OAAO,EAAE,kBAAkB,YAE3D,CACL,CACL,CACJ,CACG,CACP,CAAC;AACJ,CAAC,CAAC;AA5EW,QAAA,yBAAyB,6BA4EpC","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 React, { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport type { ISelectionProvider, SelectionChangeEventArgs } from \"@itwin/presentation-frontend\";\nimport { KeySet } from \"@itwin/presentation-common\";\nimport \"./GroupQueryBuilderCustomUI.scss\";\nimport { QueryBuilder } from \"../Groups/QueryBuilder/QueryBuilder\";\nimport type { GroupingCustomUIProps } from \"./GroupingMappingCustomUI\";\nimport { DEFAULT_PROPERTY_GRID_RULESET, PresentationPropertyDataProvider } from \"@itwin/presentation-components\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { ActionButtonRendererProps } from \"@itwin/components-react\";\nimport { VirtualizedPropertyGridWithDataProvider } from \"@itwin/components-react\";\nimport { ResizableContainerObserver } from \"@itwin/core-react\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { PropertyGridWrapperContext } from \"../context/PropertyGridWrapperContext\";\nimport { PropertyAction } from \"../Properties/PropertyAction\";\nimport { Alert, Button } from \"@itwin/itwinui-react\";\nimport { useGroupingMappingApiConfig } from \"../context/GroupingApiConfigContext\";\nimport { IModelApp } from \"@itwin/core-frontend\";\n\nconst createPropertyDataProvider = async (keys: KeySet, iModelConnection: IModelConnection): Promise<PresentationPropertyDataProvider> => {\n const dataProvider = new PresentationPropertyDataProvider({\n imodel: iModelConnection,\n ruleset: DEFAULT_PROPERTY_GRID_RULESET,\n });\n dataProvider.keys = keys;\n dataProvider.isNestedPropertyCategoryGroupingEnabled = true;\n const data = await dataProvider.getData();\n const selectedCategory = data.categories.find(\n (category) => category.label === IModelApp.localization.getLocalizedString(\"Presentation:selectedItems.categoryLabel\"),\n );\n if (selectedCategory) {\n selectedCategory.expand = true;\n }\n return dataProvider;\n};\n\ninterface ContainerDimensions {\n width: number;\n height: number;\n}\n\n/**\n * A default group query builder for the Grouping Mapping Widget that uses the property grid to generate queries.\n * @public\n */\nexport const GroupQueryBuilderCustomUI = ({ updateQuery, isUpdating, resetView }: GroupingCustomUIProps) => {\n const { iModelConnection } = useGroupingMappingApiConfig();\n if (!iModelConnection) {\n throw new Error(\"This component requires an active iModelConnection.\");\n }\n const [size, setSize] = useState<ContainerDimensions>({ width: 0, height: 0 });\n const [dataProvider, setDataProvider] = useState<PresentationPropertyDataProvider | undefined>(undefined);\n const [currentPropertyList, setCurrentPropertyList] = useState<PropertyRecord[]>([]);\n const [selectionKeySet, setSelectionKeyset] = useState<KeySet>(new KeySet());\n const [queryBuilder, setQueryBuilder] = useState<QueryBuilder | undefined>();\n\n useEffect(() => {\n const onSelectionChanged = async (evt: SelectionChangeEventArgs, selectionProvider: ISelectionProvider) => {\n const selection = selectionProvider.getSelection(evt.imodel, evt.level);\n const keys = new KeySet(selection);\n setSelectionKeyset(keys);\n const dataProvider = await createPropertyDataProvider(keys, iModelConnection);\n setDataProvider(dataProvider);\n setQueryBuilder(new QueryBuilder(dataProvider, iModelConnection));\n };\n\n return iModelConnection ? Presentation.selection.selectionChange.addListener(onSelectionChanged) : () => {};\n }, [iModelConnection]);\n\n const onClickResetButton = async () => {\n queryBuilder?.resetQueryBuilder();\n updateQuery(\"\");\n setCurrentPropertyList([]);\n if (resetView)\n await resetView().catch((e) =>\n /* eslint-disable no-console */\n console.error(e),\n );\n };\n\n const resize = useCallback((width, height) => setSize({ width, height }), []);\n\n const propertyContextValues = useMemo(\n () => ({\n currentPropertyList,\n setCurrentPropertyList,\n queryBuilder,\n setQuery: updateQuery,\n isUpdating: isUpdating ?? false,\n }),\n [currentPropertyList, isUpdating, queryBuilder, updateQuery],\n );\n\n const actionButtonRenderers = useMemo(() => [({ property }: ActionButtonRendererProps) => <PropertyAction property={property} />], []);\n\n return (\n <div className=\"gmw-select-query-generator-container\">\n {!dataProvider || selectionKeySet.size === 0 ? (\n <Alert type=\"informational\">Please select on an element within the viewer first, then select properties to generate a group query.</Alert>\n ) : (\n <>\n <div className=\"gmw-select-property-grid-container\">\n <ResizableContainerObserver onResize={resize} />\n <PropertyGridWrapperContext.Provider value={propertyContextValues}>\n <VirtualizedPropertyGridWithDataProvider\n dataProvider={dataProvider}\n width={size.width}\n height={size.height}\n actionButtonRenderers={actionButtonRenderers}\n />\n </PropertyGridWrapperContext.Provider>\n </div>\n <div className=\"gmw-select-reset-button\">\n <Button styleType=\"default\" size=\"small\" onClick={onClickResetButton}>\n Reset\n </Button>\n </div>\n </>\n )}\n </div>\n );\n};\n"]}
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- /*---------------------------------------------------------------------------------------------
4
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
5
- * See LICENSE.md in the project root for license terms and full copyright notice.
6
- *--------------------------------------------------------------------------------------------*/
7
3
  const appui_abstract_1 = require("@itwin/appui-abstract");
8
4
  const presentation_common_1 = require("@itwin/presentation-common");
9
5
  const presentation_components_1 = require("@itwin/presentation-components");
@@ -17,7 +13,22 @@ describe("QueryBuilder", () => {
17
13
  beforeEach(() => {
18
14
  dataProvider = MockFactory_1.MockFactory.create(presentation_components_1.PresentationPropertyDataProvider);
19
15
  MockFactory_1.MockFactory.stubProperty(dataProvider, "getContentDescriptor", () => () => true);
20
- sut = new QueryBuilder_1.QueryBuilder(dataProvider);
16
+ const imodel = {
17
+ createQueryReader: (query) => {
18
+ if (query.includes("SELECT ec_classname(ecclassid) FROM biscore.element WHERE ecinstanceid = ?")) {
19
+ return {
20
+ next: async () => {
21
+ return {
22
+ value: ["mockModeledElement"],
23
+ done: true,
24
+ };
25
+ },
26
+ };
27
+ }
28
+ return '';
29
+ }
30
+ };
31
+ sut = new QueryBuilder_1.QueryBuilder(dataProvider, imodel);
21
32
  });
22
33
  afterEach(() => {
23
34
  dataProvider.getFieldByPropertyRecord.restore();
@@ -73,7 +84,7 @@ describe("QueryBuilder", () => {
73
84
  await queryBuilder.removeProperty(prop);
74
85
  }
75
86
  }
76
- const result = queryBuilder.buildQueryString();
87
+ const result = await queryBuilder.buildQueryString();
77
88
  chai_1.assert.strictEqual(result, expectedResult);
78
89
  };
79
90
  });
@@ -1 +1 @@
1
- {"version":3,"file":"QueryBuilder.test.js","sourceRoot":"","sources":["../../../src/test/QueryBuilder.test.ts"],"names":[],"mappings":";;AAAA;;;gGAGgG;AAChG,0DAAuD;AACvD,oEAAkF;AAElF,4EAAkF;AAClF,+BAA8B;AAC9B,iFAA8E;AAC9E,+CAA4C;AAG5C,mEAAoD;AAEpD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,GAAiB,CAAC;IACtB,IAAI,YAA2D,CAAC;IAEhE,UAAU,CAAC,GAAG,EAAE;QACd,YAAY,GAAG,yBAAW,CAAC,MAAM,CAAC,0DAAgC,CAAC,CAAC;QACpE,yBAAW,CAAC,YAAY,CAAC,YAAY,EAAE,sBAAsB,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QAEjF,GAAG,GAAG,IAAI,2BAAY,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,YAAY,CAAC,wBAAwB,CAAC,OAAO,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAyB,iCAAS,CAAC;IACjD,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,C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IAAI,CAAC,CAAC;gBACpD,aAAM,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC;aAC/C;YACD,IAAI,EAAE,CAAC,aAAa,KAAK,gBAAgB,EAAE;gBACzC,MAAM,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;aACzC;SACF;QAED,MAAM,MAAM,GAAG,YAAY,CAAC,gBAAgB,EAAE,CAAC;QAC/C,aAAM,CAAC,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC,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 { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { FieldDescriptorType, PropertiesField } from \"@itwin/presentation-common\";\nimport type { FieldDescriptor, RelationshipPath, StrippedRelatedClassInfo } from \"@itwin/presentation-common\";\nimport { PresentationPropertyDataProvider } from \"@itwin/presentation-components\";\nimport { assert } from \"chai\";\nimport { QueryBuilder } from \"../components/Groups/QueryBuilder/QueryBuilder\";\nimport { MockFactory } from \"./MockFactory\";\nimport type { StubbedType } from \"./MockFactory\";\nimport type { OperationTestData, PropertiesTestData, PropertyRecordTestData, QueryBuilderTestData } from \"./QueryBuilderTestData\";\nimport { testCases } from \"./QueryBuilder.testdata\";\n\ndescribe(\"QueryBuilder\", () => {\n let sut: QueryBuilder;\n let dataProvider: StubbedType<PresentationPropertyDataProvider>;\n\n beforeEach(() => {\n dataProvider = MockFactory.create(PresentationPropertyDataProvider);\n MockFactory.stubProperty(dataProvider, \"getContentDescriptor\", () => () => true);\n\n sut = new QueryBuilder(dataProvider);\n });\n\n afterEach(() => {\n dataProvider.getFieldByPropertyRecord.restore();\n });\n\n const testData: QueryBuilderTestData = testCases;\n testData.testCases.forEach((testCase) => {\n it(testCase.name, async () => executeTest(sut, testCase.expectedResult, testCase.operations));\n });\n\n const createFieldDescriptor = (\n pathToClass: RelationshipPath | undefined,\n fieldProperties: PropertiesTestData[],\n type: FieldDescriptorType,\n fieldName: string | undefined,\n ): FieldDescriptor => {\n switch (type) {\n case FieldDescriptorType.Properties:\n const pathFromSelectToPropertyClass: StrippedRelatedClassInfo[] = (pathToClass ?? []).map((x) => ({\n sourceClassName: x.sourceClassInfo.name,\n targetClassName: x.targetClassInfo.name,\n relationshipName: x.relationshipInfo.name,\n isForwardRelationship: x.isForwardRelationship,\n }));\n\n const properties = fieldProperties.map((x) => ({\n class: x.property.classInfo.name,\n name: x.property.name,\n }));\n\n return {\n pathFromSelectToPropertyClass,\n properties,\n type,\n };\n case FieldDescriptorType.Name:\n return {\n type,\n fieldName: fieldName ?? \"\",\n };\n }\n };\n\n const createPropertyRecord = (propertyRecord: PropertyRecordTestData, propertiesField: PropertiesField, fieldDescriptor: FieldDescriptor) => {\n const propertiesFieldMock: StubbedType<PropertiesField> = MockFactory.create(PropertiesField);\n\n MockFactory.stubProperty(propertiesFieldMock, \"parent\", () => propertiesField.parent);\n MockFactory.stubProperty(propertiesFieldMock, \"properties\", () => propertiesField.properties);\n MockFactory.stubProperty(propertiesFieldMock, \"type\", () => propertiesField.type);\n MockFactory.stubProperty(propertiesFieldMock, \"getFieldDescriptor\", () => () => fieldDescriptor);\n\n const prop: PropertyRecord = new PropertyRecord(propertyRecord.value, propertyRecord.property);\n dataProvider.getFieldByPropertyRecord.withArgs(prop).resolves(propertiesFieldMock);\n return prop;\n };\n\n const executeTest = async (queryBuilder: QueryBuilder, expectedResult: string, operations: OperationTestData[]) => {\n for (const op of operations) {\n const fieldDescriptor = createFieldDescriptor(\n op.propertiesField.parent?.pathToPrimaryClass,\n op.propertiesField.properties,\n op.fieldDescriptorType,\n op.fieldDescriptorName,\n );\n\n const prop = createPropertyRecord(op.propertyRecord, op.propertiesField as PropertiesField, fieldDescriptor);\n\n if (op.operationType === \"addProperty\") {\n const result = await queryBuilder.addProperty(prop);\n assert.strictEqual(result, op.expectedResult);\n }\n if (op.operationType === \"removeProperty\") {\n await queryBuilder.removeProperty(prop);\n }\n }\n\n const result = queryBuilder.buildQueryString();\n assert.strictEqual(result, expectedResult);\n };\n});\n"]}
1
+ {"version":3,"file":"QueryBuilder.test.js","sourceRoot":"","sources":["../../../src/test/QueryBuilder.test.ts"],"names":[],"mappings":";;AAKA,0DAAuD;AACvD,oEAAkF;AAElF,4EAAkF;AAClF,+BAA8B;AAC9B,iFAA8E;AAC9E,+CAA4C;AAG5C,mEAAoD;AAIpD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,GAAiB,CAAC;IACtB,IAAI,YAA2D,CAAC;IAEhE,UAAU,CAAC,GAAG,EAAE;QACd,YAAY,GAAG,yBAAW,CAAC,MAAM,CAAC,0DAAgC,CAAC,CAAC;QACpE,yBAAW,CAAC,YAAY,CAAC,YAAY,EAAE,sBAAsB,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACjF,MAAM,MAAM,GAAG;YACb,iBAAiB,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC3B,IAAI,KAAK,CAAC,QAAQ,CAAC,4EAA4E,CAAC,EAAE;oBAChG,OAAO;wBACL,IAAI,EAAE,KAAK,IAAI,EAAE;4BACf,OAAO;gCACL,KAAK,EAAE,CAAC,oBAAoB,CAAC;gCAC7B,IAAI,EAAE,IAAI;6BACX,CAAC;wBACJ,CAAC;qBACa,CAAC;iBAClB;gBACD,OAAO,EAAE,CAAC;YACZ,CAAC;SACkB,CAAC;QAEtB,GAAG,GAAG,IAAI,2BAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,YAAY,CAAC,wBAAwB,CAAC,OAAO,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAyB,i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;gBACtC,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBACpD,aAAM,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC;aAC/C;YACD,IAAI,EAAE,CAAC,aAAa,KAAK,gBAAgB,EAAE;gBACzC,MAAM,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;aACzC;SACF;QAED,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,gBAAgB,EAAE,CAAC;QACrD,aAAM,CAAC,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC,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 { PropertyValue } from \"@itwin/appui-abstract\";\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { FieldDescriptorType, PropertiesField } from \"@itwin/presentation-common\";\nimport type { FieldDescriptor, RelationshipPath, StrippedRelatedClassInfo } from \"@itwin/presentation-common\";\nimport { PresentationPropertyDataProvider } from \"@itwin/presentation-components\";\nimport { assert } from \"chai\";\nimport { QueryBuilder } from \"../components/Groups/QueryBuilder/QueryBuilder\";\nimport { MockFactory } from \"./MockFactory\";\nimport type { StubbedType } from \"./MockFactory\";\nimport type { OperationTestData, PropertiesTestData, PropertyRecordTestData, QueryBuilderTestData } from \"./QueryBuilderTestData\";\nimport { testCases } from \"./QueryBuilder.testdata\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { ECSqlReader } from \"@itwin/core-common\";\n\ndescribe(\"QueryBuilder\", () => {\n let sut: QueryBuilder;\n let dataProvider: StubbedType<PresentationPropertyDataProvider>;\n\n beforeEach(() => {\n dataProvider = MockFactory.create(PresentationPropertyDataProvider);\n MockFactory.stubProperty(dataProvider, \"getContentDescriptor\", () => () => true);\n const imodel = {\n createQueryReader: (query) => {\n if (query.includes(\"SELECT ec_classname(ecclassid) FROM biscore.element WHERE ecinstanceid = ?\")) {\n return {\n next: async () => {\n return {\n value: [\"mockModeledElement\"],\n done: true,\n };\n },\n } as ECSqlReader;\n }\n return '';\n }\n } as IModelConnection;\n\n sut = new QueryBuilder(dataProvider, imodel);\n });\n\n afterEach(() => {\n dataProvider.getFieldByPropertyRecord.restore();\n });\n\n const testData: QueryBuilderTestData = testCases;\n testData.testCases.forEach((testCase) => {\n it(testCase.name, async () => executeTest(sut, testCase.expectedResult, testCase.operations));\n });\n\n const createFieldDescriptor = (\n pathToClass: RelationshipPath | undefined,\n fieldProperties: PropertiesTestData[],\n type: FieldDescriptorType,\n fieldName: string | undefined,\n ): FieldDescriptor => {\n switch (type) {\n case FieldDescriptorType.Properties:\n const pathFromSelectToPropertyClass: StrippedRelatedClassInfo[] = (pathToClass ?? []).map((x) => ({\n sourceClassName: x.sourceClassInfo.name,\n targetClassName: x.targetClassInfo.name,\n relationshipName: x.relationshipInfo.name,\n isForwardRelationship: x.isForwardRelationship,\n }));\n\n const properties = fieldProperties.map((x) => ({\n class: x.property.classInfo.name,\n name: x.property.name,\n }));\n\n return {\n pathFromSelectToPropertyClass,\n properties,\n type,\n };\n case FieldDescriptorType.Name:\n return {\n type,\n fieldName: fieldName ?? \"\",\n };\n }\n };\n\n const createPropertyRecord = (propertyRecord: PropertyRecordTestData, propertiesField: PropertiesField, fieldDescriptor: FieldDescriptor) => {\n const propertiesFieldMock: StubbedType<PropertiesField> = MockFactory.create(PropertiesField);\n\n MockFactory.stubProperty(propertiesFieldMock, \"parent\", () => propertiesField.parent);\n MockFactory.stubProperty(propertiesFieldMock, \"properties\", () => propertiesField.properties);\n MockFactory.stubProperty(propertiesFieldMock, \"type\", () => propertiesField.type);\n MockFactory.stubProperty(propertiesFieldMock, \"getFieldDescriptor\", () => () => fieldDescriptor);\n\n const prop: PropertyRecord = new PropertyRecord(propertyRecord.value as PropertyValue, propertyRecord.property);\n dataProvider.getFieldByPropertyRecord.withArgs(prop).resolves(propertiesFieldMock);\n return prop;\n };\n\n const executeTest = async (queryBuilder: QueryBuilder, expectedResult: string, operations: OperationTestData[]) => {\n for (const op of operations) {\n const fieldDescriptor = createFieldDescriptor(\n op.propertiesField.parent?.pathToPrimaryClass,\n op.propertiesField.properties,\n op.fieldDescriptorType,\n op.fieldDescriptorName,\n );\n\n const prop = createPropertyRecord(op.propertyRecord, op.propertiesField as PropertiesField, fieldDescriptor);\n\n if (op.operationType === \"addProperty\") {\n const result = await queryBuilder.addProperty(prop);\n assert.strictEqual(result, op.expectedResult);\n }\n if (op.operationType === \"removeProperty\") {\n await queryBuilder.removeProperty(prop);\n }\n }\n\n const result = await queryBuilder.buildQueryString();\n assert.strictEqual(result, expectedResult);\n };\n});\n"]}
@@ -1256,6 +1256,52 @@ exports.testCases = {
1256
1256
  },
1257
1257
  ],
1258
1258
  },
1259
+ {
1260
+ name: "when property is a model, return a model query string",
1261
+ expectedResult: "SELECT BisCore.B.ECInstanceId, BisCore.B.ECClassId FROM BisCore.B JOIN mockModeledElement ON mockModeledElement.ECInstanceId = BisCore.Element.Model.id WHERE mockModeledElement.UserLabel = 'displayValueString' OR mockModeledElement.CodeValue = 'displayValueString'",
1262
+ operations: [
1263
+ {
1264
+ expectedResult: true,
1265
+ operationType: "addProperty",
1266
+ fieldDescriptorType: presentation_common_1.FieldDescriptorType.Properties,
1267
+ propertyRecord: {
1268
+ value: {
1269
+ valueFormat: 0,
1270
+ value: { id: "fakeId" },
1271
+ displayValue: "displayValueString",
1272
+ },
1273
+ property: {
1274
+ typename: "navigation",
1275
+ name: "propertyName",
1276
+ displayLabel: "propertyDisplayLabel",
1277
+ },
1278
+ },
1279
+ propertiesField: {
1280
+ properties: [
1281
+ {
1282
+ property: {
1283
+ name: "somePropName",
1284
+ classInfo: {
1285
+ name: "BisCore:B",
1286
+ },
1287
+ navigationPropertyInfo: {
1288
+ classInfo: {
1289
+ name: "BisCore:ModelContainsElements",
1290
+ },
1291
+ },
1292
+ },
1293
+ },
1294
+ ],
1295
+ type: {
1296
+ typeName: "long",
1297
+ },
1298
+ parent: {
1299
+ pathToPrimaryClass: [],
1300
+ },
1301
+ },
1302
+ },
1303
+ ],
1304
+ },
1259
1305
  {
1260
1306
  name: "when category property and relational property added, return query string with property value, relational chain and with category joined",
1261
1307
  expectedResult: "SELECT BisCore.B.ECInstanceId, BisCore.B.ECClassId FROM BisCore.B JOIN BisCore.Category ON BisCore.Category.ECInstanceId = BisCore.GeometricElement3d.category.id WHERE ((BisCore.Category.CodeValue = 'displayValueString') OR (BisCore.Category.UserLabel = 'displayValueString'))",