@itwin/grouping-mapping-widget 0.8.1 → 0.8.3
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/README.md +1 -1
- package/lib/cjs/formula/InfixToPostfixConverter.js +1 -1
- package/lib/cjs/formula/InfixToPostfixConverter.js.map +1 -1
- package/lib/cjs/test/GroupingMappingCustomUI.test.js +144 -0
- package/lib/cjs/test/GroupingMappingCustomUI.test.js.map +1 -1
- package/lib/cjs/test/QueryBuilder.test.d.ts +2 -0
- package/lib/cjs/test/QueryBuilder.test.js +158 -0
- package/lib/cjs/test/QueryBuilder.test.js.map +1 -0
- package/lib/cjs/widget/components/GroupPropertyUtils.js +2 -2
- package/lib/cjs/widget/components/GroupPropertyUtils.js.map +1 -1
- package/lib/cjs/widget/components/QueryBuilder.d.ts +3 -1
- package/lib/cjs/widget/components/QueryBuilder.js +49 -115
- package/lib/cjs/widget/components/QueryBuilder.js.map +1 -1
- package/lib/esm/formula/InfixToPostfixConverter.js +1 -1
- package/lib/esm/formula/InfixToPostfixConverter.js.map +1 -1
- package/lib/esm/test/GroupingMappingCustomUI.test.js +144 -0
- package/lib/esm/test/GroupingMappingCustomUI.test.js.map +1 -1
- package/lib/esm/test/QueryBuilder.test.d.ts +2 -0
- package/lib/esm/test/QueryBuilder.test.js +156 -0
- package/lib/esm/test/QueryBuilder.test.js.map +1 -0
- package/lib/esm/widget/components/GroupPropertyUtils.js +2 -2
- package/lib/esm/widget/components/GroupPropertyUtils.js.map +1 -1
- package/lib/esm/widget/components/QueryBuilder.d.ts +3 -1
- package/lib/esm/widget/components/QueryBuilder.js +49 -115
- package/lib/esm/widget/components/QueryBuilder.js.map +1 -1
- package/package.json +6 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupPropertyUtils.js","sourceRoot":"","sources":["../../../../src/widget/components/GroupPropertyUtils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,w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,EAAE,CAAC,CAAC,CAAC,wBAAwB,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAAE,gBAAkC,EAAE,MAAc,EAAE,EAAE;IACtG,MAAM,OAAO,GAAY;QACvB,EAAE,EAAE,wBAAwB;QAC5B,KAAK,EAAE;YACL;gBACE,QAAQ,EAAE,SAAS,CAAC,OAAO;gBAC3B,cAAc,EAAE;oBACd;wBACE,QAAQ,EAAE,yBAAyB,CAAC,qBAAqB;qBAC1D;iBACF;aACF;SAAC;KACL,CAAC;IACF,MAAM,cAAc,GAA+E;QACjG,MAAM,EAAE,gBAAgB;QACxB,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,OAAO;QACpB,WAAW,EAAE,0BAA0B,CAAC,YAAY;KACrD,CAAC;IACF,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,oBAAoB,CACrE,cAAc,CACf,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,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 { IModelConnection } from \"@itwin/core-frontend\";\nimport type { ECProperty } from \"@itwin/insights-client\";\nimport { DataType } from \"@itwin/insights-client\";\nimport type {\n ContentDescriptorRequestOptions,\n Field,\n KeySet,\n NestedContentField,\n PropertiesField,\n Ruleset,\n RulesetVariable,\n StructFieldMemberDescription,\n} from \"@itwin/presentation-common\";\nimport {\n ContentSpecificationTypes,\n DefaultContentDisplayTypes,\n PropertyValueFormat,\n RelationshipMeaning,\n RuleTypes,\n} from \"@itwin/presentation-common\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { deepEqual } from \"fast-equals\";\n\nexport interface PropertyMetaData {\n displayLabel: string;\n sourceSchema: string;\n sourceClassName: string;\n categoryLabel: string;\n propertyType: DataType;\n actualECClassName: string;\n parentPropertyClassName: string | undefined;\n ecPropertyTraversal: string[];\n primitiveNavigationClass: string;\n key: string;\n}\n\nconst convertType = (type: string): DataType => {\n switch (type) {\n case \"int\":\n case \"enum\":\n case \"long\":\n return DataType.Integer;\n case \"boolean\":\n return DataType.Boolean;\n case \"double\":\n return DataType.Double;\n case \"number\":\n return DataType.Number;\n default:\n return DataType.String;\n }\n};\n\nconst extractPrimitives = (\n propertyTraversal: string[],\n propertyField: PropertiesField\n): PropertyMetaData[] => propertyField.properties.map((property) => {\n const propertyName = property.property.name;\n const displayLabel = propertyField.label;\n // It belongs to this parent class\n const parentPropertyClassName = propertyField.parent?.contentClassInfo.name;\n const primitiveNavigationClass = property.property.navigationPropertyInfo?.classInfo.name ?? \"\";\n /* Presentation assigns primitive navigations properties as a long type due to how it stores the\n ECInstanceId of the class in the meta.ECClassDef table on the C++ layer.\n We are handling this special case.\n */\n const propertyType = primitiveNavigationClass ? DataType.String : convertType(property.property.type);\n const actualECClassName = property.property.classInfo.name;\n const newPropertyTraversal = [...propertyTraversal, propertyName];\n\n return (\n {\n displayLabel,\n sourceSchema: \"*\",\n sourceClassName: \"*\",\n ecPropertyTraversal: newPropertyTraversal,\n propertyType,\n primitiveNavigationClass,\n actualECClassName,\n parentPropertyClassName,\n key: `${actualECClassName}__${newPropertyTraversal.join(\"_\")}`,\n categoryLabel: propertyField.category.label,\n }\n );\n});\n\nconst extractPrimitiveStructProperties = (\n propertyTraversal: string[],\n members: StructFieldMemberDescription[],\n categoryLabel: string,\n actualECClassName: string,\n parentPropertyClassName?: string,\n): PropertyMetaData[] => members.flatMap((member) => {\n if (member.type.valueFormat === PropertyValueFormat.Primitive) {\n const propertyName = member.name;\n const displayLabel = member.label;\n const propertyType = convertType(member.type.typeName);\n const newPropertyTraversal = [...propertyTraversal, propertyName];\n\n return ({\n displayLabel,\n sourceSchema: \"*\",\n sourceClassName: \"*\",\n ecPropertyTraversal: newPropertyTraversal,\n propertyType,\n primitiveNavigationClass: \"\",\n actualECClassName,\n parentPropertyClassName,\n key: `${actualECClassName}__${newPropertyTraversal.join(\"_\")}`,\n categoryLabel,\n });\n\n } else if (member.type.valueFormat === PropertyValueFormat.Struct) {\n return extractPrimitiveStructProperties(\n propertyTraversal,\n member.type.members,\n categoryLabel,\n actualECClassName,\n parentPropertyClassName\n );\n }\n\n return [];\n});\n\nconst extractStruct = (property: Field) => {\n if (property.type.valueFormat !== PropertyValueFormat.Struct) {\n return [];\n }\n\n const columnName = (property as PropertiesField).properties[0]\n .property.name;\n const actualECClassName = (property as PropertiesField).properties[0].property.classInfo.name;\n return extractPrimitiveStructProperties(\n [columnName],\n property.type.members,\n property.category.label,\n actualECClassName\n );\n};\n\nconst extractNested = (propertyTraversal: string[], propertyFields: Field[]): PropertyMetaData[] =>\n propertyFields.flatMap((property) => {\n // Generate base ECProperty\n switch (property.type.valueFormat) {\n case PropertyValueFormat.Primitive: {\n return extractPrimitives([...propertyTraversal], property as PropertiesField);\n }\n // Get structs\n case PropertyValueFormat.Struct: {\n const nestedContentField = property as NestedContentField;\n // Only handling single path and not handling nested content fields within navigations\n if (\n nestedContentField.pathToPrimaryClass &&\n nestedContentField.pathToPrimaryClass.length > 1\n ) {\n break;\n }\n\n switch (nestedContentField.relationshipMeaning) {\n // Aspects are not looked at again. Extraction does not support aspects within navigations.\n // Navigation properties\n case RelationshipMeaning.RelatedInstance: {\n if (\n // Deal with a TypeDefinition\n nestedContentField.pathToPrimaryClass[0].relationshipInfo.name ===\n \"BisCore:GeometricElement3dHasTypeDefinition\"\n ) {\n return extractNested([...propertyTraversal, \"TypeDefinition\"], nestedContentField.nestedFields);\n }\n break;\n }\n default: {\n // Some elements don't have a path to primary class or relationship meaning..\n // Most likely a simple struct property\n if (!nestedContentField.pathToPrimaryClass) {\n return extractStruct(property);\n }\n }\n }\n }\n }\n return [];\n });\n\nexport const convertPresentationFields = (propertyFields: Field[]): PropertyMetaData[] =>\n propertyFields.flatMap((property) => {\n // Generate base ECProperty\n switch (property.type.valueFormat) {\n case PropertyValueFormat.Primitive: {\n const extractedPrimitives = extractPrimitives([], property as PropertiesField);\n for (const extractedPrimitive of extractedPrimitives) {\n extractedPrimitive.sourceSchema = \"*\";\n extractedPrimitive.sourceClassName = \"*\";\n return extractedPrimitive;\n }\n break;\n }\n // Get structs\n case PropertyValueFormat.Struct: {\n const nestedContentField = property as NestedContentField;\n // Only handling single path and not handling nested content fields within navigations\n if (\n nestedContentField.pathToPrimaryClass &&\n nestedContentField.pathToPrimaryClass.length > 1\n ) {\n break;\n }\n switch (nestedContentField.relationshipMeaning) {\n case RelationshipMeaning.SameInstance: {\n // Check for aspects.\n if (\n (nestedContentField.pathToPrimaryClass[0].relationshipInfo\n .name === \"BisCore:ElementOwnsUniqueAspect\" ||\n nestedContentField.pathToPrimaryClass[0].relationshipInfo\n .name === \"BisCore:ElementOwnsMultiAspects\")\n ) {\n const fullClassName = nestedContentField.contentClassInfo.name;\n const schema = fullClassName.split(\":\")[0];\n const className = fullClassName.split(\":\")[1];\n const extractedNested = extractNested([], nestedContentField.nestedFields);\n const aspectExtractedNested = extractedNested.map((ecProperty) => ({ ...ecProperty, schema, className }));\n return aspectExtractedNested;\n }\n break;\n }\n // Navigation properties\n case RelationshipMeaning.RelatedInstance: {\n if (\n // Deal with a TypeDefinition\n nestedContentField.pathToPrimaryClass[0].relationshipInfo.name ===\n \"BisCore:GeometricElement3dHasTypeDefinition\"\n ) {\n return extractNested([\"TypeDefinition\"], nestedContentField.nestedFields);\n }\n break;\n }\n default: {\n // Some elements don't have a path to primary class or relationship meaning..\n // Most likely a simple struct property\n if (!nestedContentField.pathToPrimaryClass) {\n return extractStruct(property);\n }\n }\n }\n }\n }\n return [];\n });\n\nexport const convertToECProperties = (property: PropertyMetaData): ECProperty[] => {\n const ecProperty: ECProperty = {\n ecSchemaName: property.sourceSchema,\n ecClassName: property.sourceClassName,\n ecPropertyType: property.propertyType,\n ecPropertyName: \"\",\n };\n switch (property.primitiveNavigationClass) {\n // Hardcode Models navigation path and label behavior\n case \"BisCore:ModelContainsElements\": {\n return [\n {\n ...ecProperty,\n ecPropertyName: [\n ...property.ecPropertyTraversal,\n \"ModeledElement\",\n \"UserLabel\",\n ].join(\".\"),\n },\n {\n ...ecProperty,\n ecPropertyName: [\n ...property.ecPropertyTraversal,\n \"ModeledElement\",\n \"CodeValue\",\n ].join(\".\"),\n },\n ];\n }\n // Hardcode Category and Physical Material navigation path and label behavior\n case \"BisCore:GeometricElement3dIsInCategory\":\n case \"BisCore:PhysicalElementIsOfPhysicalMaterial\":\n return [\n {\n ...ecProperty,\n ecPropertyName: [\n ...property.ecPropertyTraversal,\n \"UserLabel\",\n ].join(\".\"),\n },\n {\n ...ecProperty,\n ecPropertyName: [\n ...property.ecPropertyTraversal,\n \"CodeValue\",\n ].join(\".\"),\n },\n ];\n default: {\n return [\n {\n ...ecProperty,\n ecPropertyName: property.ecPropertyTraversal.join(\".\"),\n },\n ];\n }\n }\n};\n\nexport const findProperties = (ecProperties: ECProperty[], propertiesMetaData: PropertyMetaData[]) => {\n let ecPropertiesCopy = [...ecProperties];\n const propertiesMetaDataResult: PropertyMetaData[] = new Array<PropertyMetaData>();\n let notFound = false;\n while (ecPropertiesCopy.length !== 0) {\n for (let i = 0; i < propertiesMetaData.length; i++) {\n const generatedProperty = convertToECProperties(propertiesMetaData[i]);\n const slicedEcProperties = ecPropertiesCopy.slice(0, generatedProperty.length);\n if (deepEqual(generatedProperty, slicedEcProperties)) {\n propertiesMetaDataResult.push(propertiesMetaData[i]);\n ecPropertiesCopy = ecPropertiesCopy.slice(generatedProperty.length);\n break;\n }\n if (i === propertiesMetaData.length - 1) {\n notFound = true;\n }\n }\n if (notFound)\n break;\n }\n return notFound ? [] : propertiesMetaDataResult;\n};\n\nexport const fetchPresentationDescriptor = async (iModelConnection: IModelConnection, keySet: KeySet) => {\n const ruleSet: Ruleset = {\n id: \"gmw-element-properties\",\n rules: [\n {\n ruleType: RuleTypes.Content,\n specifications: [\n {\n specType: ContentSpecificationTypes.SelectedNodeInstances,\n },\n ],\n }],\n };\n const requestOptions: ContentDescriptorRequestOptions<IModelConnection, KeySet, RulesetVariable> = {\n imodel: iModelConnection,\n keys: keySet,\n rulesetOrId: ruleSet,\n displayType: DefaultContentDisplayTypes.PropertyPane,\n };\n const descriptor = await Presentation.presentation.getContentDescriptor(\n requestOptions\n );\n return descriptor;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"GroupPropertyUtils.js","sourceRoot":"","sources":["../../../../src/widget/components/GroupPropertyUtils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAWlD,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,GACV,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAexC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAY,EAAE;IAC7C,QAAQ,IAAI,EAAE;QACZ,KAAK,KAAK,CAAC;QACX,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,MAAM,CAAC;QACzB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,MAAM,CAAC;QACzB;YACE,OAAO,QAAQ,CAAC,MAAM,CAAC;KAC1B;AACH,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CACxB,iBAA2B,EAC3B,aAA8B,EACV,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;;IACjE,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5C,MAAM,YAAY,GA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AC;YAC/E,IAAI,SAAS,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,EAAE;gBACpD,wBAAwB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;gBACrD,gBAAgB,GAAG,gBAAgB,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;gBACpE,MAAM;aACP;YACD,IAAI,CAAC,KAAK,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;gBACvC,QAAQ,GAAG,IAAI,CAAC;aACjB;SACF;QACD,IAAI,QAAQ;YACV,MAAM;KACT;IACD,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,wBAAwB,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAAE,gBAAkC,EAAE,MAAc,EAAE,EAAE;IACtG,MAAM,OAAO,GAAY;QACvB,EAAE,EAAE,wBAAwB;QAC5B,KAAK,EAAE;YACL;gBACE,QAAQ,EAAE,SAAS,CAAC,OAAO;gBAC3B,cAAc,EAAE;oBACd;wBACE,QAAQ,EAAE,yBAAyB,CAAC,qBAAqB;qBAC1D;iBACF;aACF;SAAC;KACL,CAAC;IACF,MAAM,cAAc,GAA+E;QACjG,MAAM,EAAE,gBAAgB;QACxB,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,OAAO;QACpB,WAAW,EAAE,0BAA0B,CAAC,YAAY;KACrD,CAAC;IACF,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,oBAAoB,CACrE,cAAc,CACf,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,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 { IModelConnection } from \"@itwin/core-frontend\";\nimport type { ECProperty } from \"@itwin/insights-client\";\nimport { DataType } from \"@itwin/insights-client\";\nimport type {\n ContentDescriptorRequestOptions,\n Field,\n KeySet,\n NestedContentField,\n PropertiesField,\n Ruleset,\n RulesetVariable,\n StructFieldMemberDescription,\n} from \"@itwin/presentation-common\";\nimport {\n ContentSpecificationTypes,\n DefaultContentDisplayTypes,\n PropertyValueFormat,\n RelationshipMeaning,\n RuleTypes,\n} from \"@itwin/presentation-common\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { deepEqual } from \"fast-equals\";\n\nexport interface PropertyMetaData {\n displayLabel: string;\n sourceSchema: string;\n sourceClassName: string;\n categoryLabel: string;\n propertyType: DataType;\n actualECClassName: string;\n parentPropertyClassName: string | undefined;\n ecPropertyTraversal: string[];\n primitiveNavigationClass: string;\n key: string;\n}\n\nconst convertType = (type: string): DataType => {\n switch (type) {\n case \"int\":\n case \"enum\":\n case \"long\":\n return DataType.Integer;\n case \"boolean\":\n return DataType.Boolean;\n case \"double\":\n return DataType.Double;\n case \"number\":\n return DataType.Number;\n default:\n return DataType.String;\n }\n};\n\nconst extractPrimitives = (\n propertyTraversal: string[],\n propertyField: PropertiesField\n): PropertyMetaData[] => propertyField.properties.map((property) => {\n const propertyName = property.property.name;\n const displayLabel = propertyField.label;\n // It belongs to this parent class\n const parentPropertyClassName = propertyField.parent?.contentClassInfo.name;\n const primitiveNavigationClass = property.property.navigationPropertyInfo?.classInfo.name ?? \"\";\n /* Presentation assigns primitive navigations properties as a long type due to how it stores the\n ECInstanceId of the class in the meta.ECClassDef table on the C++ layer.\n We are handling this special case.\n */\n const propertyType = primitiveNavigationClass ? DataType.String : convertType(property.property.type);\n const actualECClassName = property.property.classInfo.name;\n const newPropertyTraversal = [...propertyTraversal, propertyName];\n\n return (\n {\n displayLabel,\n sourceSchema: \"*\",\n sourceClassName: \"*\",\n ecPropertyTraversal: newPropertyTraversal,\n propertyType,\n primitiveNavigationClass,\n actualECClassName,\n parentPropertyClassName,\n key: `${parentPropertyClassName}|${actualECClassName}|${newPropertyTraversal.join(\"|\")}`,\n categoryLabel: propertyField.category.label,\n }\n );\n});\n\nconst extractPrimitiveStructProperties = (\n propertyTraversal: string[],\n members: StructFieldMemberDescription[],\n categoryLabel: string,\n actualECClassName: string,\n parentPropertyClassName?: string,\n): PropertyMetaData[] => members.flatMap((member) => {\n if (member.type.valueFormat === PropertyValueFormat.Primitive) {\n const propertyName = member.name;\n const displayLabel = member.label;\n const propertyType = convertType(member.type.typeName);\n const newPropertyTraversal = [...propertyTraversal, propertyName];\n\n return ({\n displayLabel,\n sourceSchema: \"*\",\n sourceClassName: \"*\",\n ecPropertyTraversal: newPropertyTraversal,\n propertyType,\n primitiveNavigationClass: \"\",\n actualECClassName,\n parentPropertyClassName,\n key: `${parentPropertyClassName}|${actualECClassName}|${newPropertyTraversal.join(\"|\")}`,\n categoryLabel,\n });\n\n } else if (member.type.valueFormat === PropertyValueFormat.Struct) {\n return extractPrimitiveStructProperties(\n propertyTraversal,\n member.type.members,\n categoryLabel,\n actualECClassName,\n parentPropertyClassName\n );\n }\n\n return [];\n});\n\nconst extractStruct = (property: Field) => {\n if (property.type.valueFormat !== PropertyValueFormat.Struct) {\n return [];\n }\n\n const columnName = (property as PropertiesField).properties[0]\n .property.name;\n const actualECClassName = (property as PropertiesField).properties[0].property.classInfo.name;\n return extractPrimitiveStructProperties(\n [columnName],\n property.type.members,\n property.category.label,\n actualECClassName\n );\n};\n\nconst extractNested = (propertyTraversal: string[], propertyFields: Field[]): PropertyMetaData[] =>\n propertyFields.flatMap((property) => {\n // Generate base ECProperty\n switch (property.type.valueFormat) {\n case PropertyValueFormat.Primitive: {\n return extractPrimitives([...propertyTraversal], property as PropertiesField);\n }\n // Get structs\n case PropertyValueFormat.Struct: {\n const nestedContentField = property as NestedContentField;\n // Only handling single path and not handling nested content fields within navigations\n if (\n nestedContentField.pathToPrimaryClass &&\n nestedContentField.pathToPrimaryClass.length > 1\n ) {\n break;\n }\n\n switch (nestedContentField.relationshipMeaning) {\n // Aspects are not looked at again. Extraction does not support aspects within navigations.\n // Navigation properties\n case RelationshipMeaning.RelatedInstance: {\n if (\n // Deal with a TypeDefinition\n nestedContentField.pathToPrimaryClass[0].relationshipInfo.name ===\n \"BisCore:GeometricElement3dHasTypeDefinition\"\n ) {\n return extractNested([...propertyTraversal, \"TypeDefinition\"], nestedContentField.nestedFields);\n }\n break;\n }\n default: {\n // Some elements don't have a path to primary class or relationship meaning..\n // Most likely a simple struct property\n if (!nestedContentField.pathToPrimaryClass) {\n return extractStruct(property);\n }\n }\n }\n }\n }\n return [];\n });\n\nexport const convertPresentationFields = (propertyFields: Field[]): PropertyMetaData[] =>\n propertyFields.flatMap((property) => {\n // Generate base ECProperty\n switch (property.type.valueFormat) {\n case PropertyValueFormat.Primitive: {\n const extractedPrimitives = extractPrimitives([], property as PropertiesField);\n for (const extractedPrimitive of extractedPrimitives) {\n extractedPrimitive.sourceSchema = \"*\";\n extractedPrimitive.sourceClassName = \"*\";\n return extractedPrimitive;\n }\n break;\n }\n // Get structs\n case PropertyValueFormat.Struct: {\n const nestedContentField = property as NestedContentField;\n // Only handling single path and not handling nested content fields within navigations\n if (\n nestedContentField.pathToPrimaryClass &&\n nestedContentField.pathToPrimaryClass.length > 1\n ) {\n break;\n }\n switch (nestedContentField.relationshipMeaning) {\n case RelationshipMeaning.SameInstance: {\n // Check for aspects.\n if (\n (nestedContentField.pathToPrimaryClass[0].relationshipInfo\n .name === \"BisCore:ElementOwnsUniqueAspect\" ||\n nestedContentField.pathToPrimaryClass[0].relationshipInfo\n .name === \"BisCore:ElementOwnsMultiAspects\")\n ) {\n const fullClassName = nestedContentField.contentClassInfo.name;\n const schema = fullClassName.split(\":\")[0];\n const className = fullClassName.split(\":\")[1];\n const extractedNested = extractNested([], nestedContentField.nestedFields);\n const aspectExtractedNested = extractedNested.map((ecProperty) => ({ ...ecProperty, schema, className }));\n return aspectExtractedNested;\n }\n break;\n }\n // Navigation properties\n case RelationshipMeaning.RelatedInstance: {\n if (\n // Deal with a TypeDefinition\n nestedContentField.pathToPrimaryClass[0].relationshipInfo.name ===\n \"BisCore:GeometricElement3dHasTypeDefinition\"\n ) {\n return extractNested([\"TypeDefinition\"], nestedContentField.nestedFields);\n }\n break;\n }\n default: {\n // Some elements don't have a path to primary class or relationship meaning..\n // Most likely a simple struct property\n if (!nestedContentField.pathToPrimaryClass) {\n return extractStruct(property);\n }\n }\n }\n }\n }\n return [];\n });\n\nexport const convertToECProperties = (property: PropertyMetaData): ECProperty[] => {\n const ecProperty: ECProperty = {\n ecSchemaName: property.sourceSchema,\n ecClassName: property.sourceClassName,\n ecPropertyType: property.propertyType,\n ecPropertyName: \"\",\n };\n switch (property.primitiveNavigationClass) {\n // Hardcode Models navigation path and label behavior\n case \"BisCore:ModelContainsElements\": {\n return [\n {\n ...ecProperty,\n ecPropertyName: [\n ...property.ecPropertyTraversal,\n \"ModeledElement\",\n \"UserLabel\",\n ].join(\".\"),\n },\n {\n ...ecProperty,\n ecPropertyName: [\n ...property.ecPropertyTraversal,\n \"ModeledElement\",\n \"CodeValue\",\n ].join(\".\"),\n },\n ];\n }\n // Hardcode Category and Physical Material navigation path and label behavior\n case \"BisCore:GeometricElement3dIsInCategory\":\n case \"BisCore:PhysicalElementIsOfPhysicalMaterial\":\n return [\n {\n ...ecProperty,\n ecPropertyName: [\n ...property.ecPropertyTraversal,\n \"UserLabel\",\n ].join(\".\"),\n },\n {\n ...ecProperty,\n ecPropertyName: [\n ...property.ecPropertyTraversal,\n \"CodeValue\",\n ].join(\".\"),\n },\n ];\n default: {\n return [\n {\n ...ecProperty,\n ecPropertyName: property.ecPropertyTraversal.join(\".\"),\n },\n ];\n }\n }\n};\n\nexport const findProperties = (ecProperties: ECProperty[], propertiesMetaData: PropertyMetaData[]) => {\n let ecPropertiesCopy = [...ecProperties];\n const propertiesMetaDataResult: PropertyMetaData[] = new Array<PropertyMetaData>();\n let notFound = false;\n while (ecPropertiesCopy.length !== 0) {\n for (let i = 0; i < propertiesMetaData.length; i++) {\n const generatedProperty = convertToECProperties(propertiesMetaData[i]);\n const slicedEcProperties = ecPropertiesCopy.slice(0, generatedProperty.length);\n if (deepEqual(generatedProperty, slicedEcProperties)) {\n propertiesMetaDataResult.push(propertiesMetaData[i]);\n ecPropertiesCopy = ecPropertiesCopy.slice(generatedProperty.length);\n break;\n }\n if (i === propertiesMetaData.length - 1) {\n notFound = true;\n }\n }\n if (notFound)\n break;\n }\n return notFound ? [] : propertiesMetaDataResult;\n};\n\nexport const fetchPresentationDescriptor = async (iModelConnection: IModelConnection, keySet: KeySet) => {\n const ruleSet: Ruleset = {\n id: \"gmw-element-properties\",\n rules: [\n {\n ruleType: RuleTypes.Content,\n specifications: [\n {\n specType: ContentSpecificationTypes.SelectedNodeInstances,\n },\n ],\n }],\n };\n const requestOptions: ContentDescriptorRequestOptions<IModelConnection, KeySet, RulesetVariable> = {\n imodel: iModelConnection,\n keys: keySet,\n rulesetOrId: ruleSet,\n displayType: DefaultContentDisplayTypes.PropertyPane,\n };\n const descriptor = await Presentation.presentation.getContentDescriptor(\n requestOptions\n );\n return descriptor;\n};\n"]}
|
|
@@ -37,8 +37,10 @@ export declare class QueryBuilder {
|
|
|
37
37
|
removeProperty(prop: PropertyRecord): Promise<void>;
|
|
38
38
|
removeRelatedProperty(unionIndex: number, propertyField: PropertiesField, propertyName: string): void;
|
|
39
39
|
removePropertyFromQuery(unionIndex: number, className: string, propertyName: string): void;
|
|
40
|
-
categoryQuery(codeValue: string): string;
|
|
41
40
|
buildQueryString(): string;
|
|
41
|
+
private _whereSegment;
|
|
42
|
+
private _propertySegment;
|
|
43
|
+
private _categoryQuery;
|
|
42
44
|
private _isFloat;
|
|
43
45
|
}
|
|
44
46
|
//# sourceMappingURL=QueryBuilder.d.ts.map
|
|
@@ -6,6 +6,15 @@ export class QueryBuilder {
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
constructor(provider) {
|
|
9
|
+
this._whereSegment = (baseClass, baseClassName) => {
|
|
10
|
+
const segments = [];
|
|
11
|
+
const properties = baseClass.properties;
|
|
12
|
+
for (let i = 0; i < properties.length; i++) {
|
|
13
|
+
const prefix = i === 0 ? "WHERE" : "AND";
|
|
14
|
+
segments.push(this._propertySegment(baseClassName, properties[i], prefix));
|
|
15
|
+
}
|
|
16
|
+
return segments.join("");
|
|
17
|
+
};
|
|
9
18
|
this.dataProvider = provider;
|
|
10
19
|
}
|
|
11
20
|
isCategory(propertyField) {
|
|
@@ -274,23 +283,22 @@ export class QueryBuilder {
|
|
|
274
283
|
}
|
|
275
284
|
}
|
|
276
285
|
}
|
|
277
|
-
categoryQuery(codeValue) {
|
|
278
|
-
return ` JOIN bis.Category ON bis.Category.ECInstanceId = bis.GeometricElement3d.category.id AND ((bis.Category.CodeValue='${codeValue}') OR (bis.Category.UserLabel='${codeValue}'))`;
|
|
279
|
-
}
|
|
280
286
|
buildQueryString() {
|
|
281
287
|
if (this.query === undefined ||
|
|
282
288
|
this.query.unions.length === 0 ||
|
|
283
289
|
this.query.unions[0].classes.length === 0) {
|
|
284
290
|
return "";
|
|
285
291
|
}
|
|
286
|
-
|
|
292
|
+
const unionSegments = [];
|
|
287
293
|
for (const union of this.query.unions) {
|
|
294
|
+
const querySegments = [];
|
|
288
295
|
const baseClass = union.classes[0];
|
|
289
296
|
const baseClassName = baseClass.className;
|
|
290
297
|
const baseIdName = baseClass.isAspect
|
|
291
298
|
? `${baseClassName}.Element.id`
|
|
292
299
|
: `${baseClassName}.ECInstanceId`;
|
|
293
|
-
|
|
300
|
+
const selectSegment = `SELECT ${baseIdName}${baseClass.isAspect ? " ECInstanceId" : ""} FROM ${baseClassName}`;
|
|
301
|
+
querySegments.push(selectSegment);
|
|
294
302
|
if (union.classes.length > 1) {
|
|
295
303
|
for (let i = 1; i < union.classes.length; i++) {
|
|
296
304
|
const joinClass = union.classes[i];
|
|
@@ -298,125 +306,51 @@ export class QueryBuilder {
|
|
|
298
306
|
const joinIdName = joinClass.isAspect
|
|
299
307
|
? `${joinClassName}.Element.id`
|
|
300
308
|
: `${joinClassName}.ECInstanceId`;
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}='${joinClass.properties[0].value}'`;
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
if (this._isFloat(joinClass.properties[0].value)) {
|
|
313
|
-
queryString += ` ON ROUND(${joinClassName}.${joinClass.properties[0].name}, `;
|
|
314
|
-
queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
|
|
315
|
-
queryString += `${Number(joinClass.properties[0].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}=${joinClass.properties[0].value}`;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
// when base is regular property, link base to first joined relational property
|
|
324
|
-
if (!baseClass.isRelational && i === 1) {
|
|
325
|
-
queryString += ` AND ${joinIdName} = ${baseIdName}`;
|
|
326
|
-
}
|
|
327
|
-
for (const property of joinClass.properties) {
|
|
328
|
-
if (property.isCategory) {
|
|
329
|
-
queryString += this.categoryQuery(property.value.toString());
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
if (property.needsQuote) {
|
|
333
|
-
queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
if (this._isFloat(property.value)) {
|
|
337
|
-
queryString += ` AND ROUND(${joinClassName}.${property.name}, `;
|
|
338
|
-
queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
|
|
339
|
-
queryString += `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
309
|
+
const joinSegment = joinClass.isRelational
|
|
310
|
+
? ` JOIN ${joinClassName}`
|
|
311
|
+
: ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;
|
|
312
|
+
querySegments.push(joinSegment);
|
|
313
|
+
for (let j = 0; j < joinClass.properties.length; j++) {
|
|
314
|
+
const prefix = j === 0 && joinClass.isRelational ? "ON" : "AND";
|
|
315
|
+
const propertySegment = this._propertySegment(joinClassName, joinClass.properties[j], prefix);
|
|
316
|
+
querySegments.push(propertySegment);
|
|
347
317
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (property.isCategory) {
|
|
352
|
-
queryString += this.categoryQuery(property.value.toString());
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
if (property.needsQuote) {
|
|
356
|
-
queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
if (this._isFloat(property.value)) {
|
|
360
|
-
queryString += ` AND ROUND(${joinClassName}.${property.name}, `;
|
|
361
|
-
queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
|
|
362
|
-
queryString += `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
318
|
+
// when base is regular property, link base to first joined relational property
|
|
319
|
+
if (joinClass.isRelational && !baseClass.isRelational && i === 1) {
|
|
320
|
+
querySegments.push(` AND ${joinIdName} = ${baseIdName}`);
|
|
370
321
|
}
|
|
371
322
|
}
|
|
372
323
|
}
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
324
|
+
const whereSegment = this._whereSegment(baseClass, baseClassName);
|
|
325
|
+
querySegments.push(whereSegment);
|
|
326
|
+
unionSegments.push(querySegments.join(""));
|
|
327
|
+
}
|
|
328
|
+
return unionSegments.join(" UNION ");
|
|
329
|
+
}
|
|
330
|
+
_propertySegment(className, property, prefix) {
|
|
331
|
+
const segments = [];
|
|
332
|
+
if (property.isCategory) {
|
|
333
|
+
segments.push(this._categoryQuery(property.value.toString()));
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
if (property.needsQuote) {
|
|
337
|
+
segments.push(` ${prefix} ${className}.${property.name}='${property.value}'`);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
if (this._isFloat(property.value)) {
|
|
341
|
+
segments.push(` ${prefix} ROUND(${className}.${property.name}, `);
|
|
342
|
+
segments.push(`${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`);
|
|
343
|
+
segments.push(`${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`);
|
|
377
344
|
}
|
|
378
345
|
else {
|
|
379
|
-
|
|
380
|
-
queryString += ` WHERE ${baseClassName}.${properties[0].name}='${properties[0].value}'`;
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
if (this._isFloat(properties[0].value)) {
|
|
384
|
-
queryString += ` WHERE ROUND(${baseClassName}.${properties[0].name}, `;
|
|
385
|
-
queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
|
|
386
|
-
queryString += `${Number(properties[0].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
queryString += ` WHERE ${baseClassName}.${properties[0].name}=${properties[0].value}`;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
if (properties.length > 1) {
|
|
394
|
-
for (let i = 1; i < properties.length; i++) {
|
|
395
|
-
if (properties[i].isCategory) {
|
|
396
|
-
queryString += this.categoryQuery(properties[i].value.toString());
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
if (properties[i].needsQuote) {
|
|
400
|
-
queryString += ` AND ${baseClassName}.${properties[i].name}='${properties[i].value}'`;
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
if (this._isFloat(properties[i].value)) {
|
|
404
|
-
queryString += ` AND ROUND(${baseClassName}.${properties[i].name}, `;
|
|
405
|
-
queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
|
|
406
|
-
queryString += `${Number(properties[i].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
queryString += ` AND ${baseClassName}.${properties[i].name}=${properties[i].value}`;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
346
|
+
segments.push(` ${prefix} ${className}.${property.name}=${property.value}`);
|
|
414
347
|
}
|
|
415
348
|
}
|
|
416
|
-
unionQuery += `${queryString} UNION `;
|
|
417
349
|
}
|
|
418
|
-
|
|
419
|
-
|
|
350
|
+
return segments.join("");
|
|
351
|
+
}
|
|
352
|
+
_categoryQuery(codeValue) {
|
|
353
|
+
return ` JOIN bis.Category ON bis.Category.ECInstanceId = bis.GeometricElement3d.category.id AND ((bis.Category.CodeValue='${codeValue}') OR (bis.Category.UserLabel='${codeValue}'))`;
|
|
420
354
|
}
|
|
421
355
|
_isFloat(n) {
|
|
422
356
|
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,MAAM,OAAO,YAAY;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,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,QAAQ,CAAC,CAAU;QACzB,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;;AA5mBsB,uCAA0B,GAC/C,iCAAiC,CAAC;AACb,wCAA2B,GAChD,iCAAiC,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 public 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[\n i\n ].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 public addRelatedProperty(\n unionIndex: number,\n propertyField: PropertiesField,\n propertyName: string,\n propertyValue: Primitives.Value,\n isAspect: boolean,\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 if (!path.isForwardRelationship) {\n this.addPropertyToQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n `${relClassName}.SourceECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n this.addPropertyToQuery(\n unionIndex,\n relClassName,\n `TargetECInstanceId`,\n `${sourceClassName}.ECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n propertyValue,\n isAspect,\n this._needsQuote(propertyField),\n false,\n true,\n );\n } else {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n `${relClassName}.TargetECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n }\n } else {\n this.addPropertyToQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n `${relClassName}.TargetECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n this.addPropertyToQuery(\n unionIndex,\n relClassName,\n `SourceECInstanceId`,\n `${sourceClassName}.ECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n propertyValue,\n isAspect,\n this._needsQuote(propertyField),\n false,\n true,\n );\n } else {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n `${relClassName}.SourceECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n }\n }\n });\n }\n\n public 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 = {\n unions: [\n {\n classes: [\n {\n className,\n isAspect,\n isRelational,\n properties: [\n {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n },\n ],\n },\n ],\n },\n ],\n };\n return;\n }\n\n if (this.query.unions.length <= unionIndex) {\n this.query.unions.push({\n classes: [\n {\n className,\n isAspect,\n isRelational,\n properties: [\n {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n },\n ],\n },\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({\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n });\n }\n } else {\n this.query.unions[unionIndex].classes.push({\n className,\n isRelational,\n properties: [\n {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n },\n ],\n isAspect,\n });\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[\n i\n ].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 public 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 if (!path.isForwardRelationship) {\n this.removePropertyFromQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n );\n this.removePropertyFromQuery(\n unionIndex,\n relClassName,\n `TargetECInstanceId`,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n );\n } else {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n );\n }\n } else {\n this.removePropertyFromQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n );\n this.removePropertyFromQuery(\n unionIndex,\n relClassName,\n `SourceECInstanceId`,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n );\n } else {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n );\n }\n }\n });\n }\n\n public 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 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 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 let unionQuery = \"\";\n for (const union of this.query.unions) {\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 let queryString = `SELECT ${baseIdName}${\n baseClass.isAspect ? \" ECInstanceId\" : \"\"\n } FROM ${baseClassName}`;\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 if (joinClass.isRelational) {\n queryString += ` JOIN ${joinClassName}`;\n if (joinClass.properties.length > 0) {\n if (joinClass.properties[0].isCategory) {\n queryString += this.categoryQuery(\n joinClass.properties[0].value.toString(),\n );\n } else {\n if (joinClass.properties[0].needsQuote) {\n queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}='${joinClass.properties[0].value}'`;\n } else {\n if (this._isFloat(joinClass.properties[0].value)) {\n queryString += ` ON ROUND(${joinClassName}.${joinClass.properties[0].name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(\n joinClass.properties[0].value,\n ).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;\n } else {\n queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}=${joinClass.properties[0].value}`;\n }\n }\n }\n }\n // when base is regular property, link base to first joined relational property\n if (!baseClass.isRelational && i === 1) {\n queryString += ` AND ${joinIdName} = ${baseIdName}`;\n }\n for (const property of joinClass.properties) {\n if (property.isCategory) {\n queryString += this.categoryQuery(property.value.toString());\n } else {\n if (property.needsQuote) {\n queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;\n } else {\n if (this._isFloat(property.value)) {\n queryString += ` AND ROUND(${joinClassName}.${property.name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(property.value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION,\n )}`;\n } else {\n queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;\n }\n }\n }\n }\n } else {\n queryString += ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;\n for (const property of joinClass.properties) {\n if (property.isCategory) {\n queryString += this.categoryQuery(property.value.toString());\n } else {\n if (property.needsQuote) {\n queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;\n } else {\n if (this._isFloat(property.value)) {\n queryString += ` AND ROUND(${joinClassName}.${property.name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(property.value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION,\n )}`;\n } else {\n queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;\n }\n }\n }\n }\n }\n }\n }\n\n const properties = baseClass.properties;\n if (properties.length > 0) {\n if (properties[0].isCategory) {\n queryString += this.categoryQuery(properties[0].value.toString());\n } else {\n if (properties[0].needsQuote) {\n queryString += ` WHERE ${baseClassName}.${properties[0].name}='${properties[0].value}'`;\n } else {\n if (this._isFloat(properties[0].value)) {\n queryString += ` WHERE ROUND(${baseClassName}.${properties[0].name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(properties[0].value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION,\n )}`;\n } else {\n queryString += ` WHERE ${baseClassName}.${properties[0].name}=${properties[0].value}`;\n }\n }\n }\n if (properties.length > 1) {\n for (let i = 1; i < properties.length; i++) {\n if (properties[i].isCategory) {\n queryString += this.categoryQuery(properties[i].value.toString());\n } else {\n if (properties[i].needsQuote) {\n queryString += ` AND ${baseClassName}.${properties[i].name}='${properties[i].value}'`;\n } else {\n if (this._isFloat(properties[i].value)) {\n queryString += ` AND ROUND(${baseClassName}.${properties[i].name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(properties[i].value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION,\n )}`;\n } else {\n queryString += ` AND ${baseClassName}.${properties[i].name}=${properties[i].value}`;\n }\n }\n }\n }\n }\n }\n unionQuery += `${queryString} UNION `;\n }\n unionQuery = unionQuery.slice(0, unionQuery.length - 7);\n return unionQuery;\n }\n\n private _isFloat(n: unknown): boolean {\n return Number(n) === n && n % 1 !== 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,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;iBAC7E;aACF;SACF;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAEO,cAAc,CAAC,SAAiB;QACtC,OAAO,sHAAsH,SAAS,kCAAkC,SAAS,KAAK,CAAC;IACzL,CAAC;IAEO,QAAQ,CAAC,CAAU;QACzB,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;;AA5jBsB,uCAA0B,GAC/C,iCAAiC,CAAC;AACb,wCAA2B,GAChD,iCAAiC,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 public 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[\n i\n ].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 public addRelatedProperty(\n unionIndex: number,\n propertyField: PropertiesField,\n propertyName: string,\n propertyValue: Primitives.Value,\n isAspect: boolean,\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 if (!path.isForwardRelationship) {\n this.addPropertyToQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n `${relClassName}.SourceECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n this.addPropertyToQuery(\n unionIndex,\n relClassName,\n `TargetECInstanceId`,\n `${sourceClassName}.ECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n propertyValue,\n isAspect,\n this._needsQuote(propertyField),\n false,\n true,\n );\n } else {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n `${relClassName}.TargetECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n }\n } else {\n this.addPropertyToQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n `${relClassName}.TargetECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n this.addPropertyToQuery(\n unionIndex,\n relClassName,\n `SourceECInstanceId`,\n `${sourceClassName}.ECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n propertyValue,\n isAspect,\n this._needsQuote(propertyField),\n false,\n true,\n );\n } else {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n `${relClassName}.SourceECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n }\n }\n });\n }\n\n public 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 = {\n unions: [\n {\n classes: [\n {\n className,\n isAspect,\n isRelational,\n properties: [\n {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n },\n ],\n },\n ],\n },\n ],\n };\n return;\n }\n\n if (this.query.unions.length <= unionIndex) {\n this.query.unions.push({\n classes: [\n {\n className,\n isAspect,\n isRelational,\n properties: [\n {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n },\n ],\n },\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({\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n });\n }\n } else {\n this.query.unions[unionIndex].classes.push({\n className,\n isRelational,\n properties: [\n {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n },\n ],\n isAspect,\n });\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[\n i\n ].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 public 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 if (!path.isForwardRelationship) {\n this.removePropertyFromQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n );\n this.removePropertyFromQuery(\n unionIndex,\n relClassName,\n `TargetECInstanceId`,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n );\n } else {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n );\n }\n } else {\n this.removePropertyFromQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n );\n this.removePropertyFromQuery(\n unionIndex,\n relClassName,\n `SourceECInstanceId`,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n );\n } else {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n );\n }\n }\n });\n }\n\n public 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/grouping-mapping-widget",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "An iTwin.js 3D Viewer Widget that interfaces with the iTwin Reporting Platform.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Bentley",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
],
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/iTwin/viewer-components-react.git",
|
|
14
|
+
"directory": "packages/itwin/grouping-mapping-widget"
|
|
14
15
|
},
|
|
15
16
|
"license": "MIT",
|
|
16
17
|
"author": {
|
|
@@ -76,6 +77,7 @@
|
|
|
76
77
|
"@testing-library/jest-dom": "^5.16.3",
|
|
77
78
|
"@testing-library/react": "^12.1.4",
|
|
78
79
|
"@testing-library/user-event": "^14.1.1",
|
|
80
|
+
"@types/chai": "4.2.11",
|
|
79
81
|
"@types/i18next": "^8.4.2",
|
|
80
82
|
"@types/jest": "^27.4.1",
|
|
81
83
|
"@types/node": "^14.14.20",
|
|
@@ -86,6 +88,7 @@
|
|
|
86
88
|
"@types/testing-library__jest-dom": "^5.14.3",
|
|
87
89
|
"@typescript-eslint/eslint-plugin": "^5.3.1",
|
|
88
90
|
"@typescript-eslint/parser": "^5.10.1",
|
|
91
|
+
"chai": "^4.2.0",
|
|
89
92
|
"cpx2": "^3.0.0",
|
|
90
93
|
"eslint": "^7.32.0",
|
|
91
94
|
"eslint-plugin-node": "^11.1.0",
|
|
@@ -135,5 +138,5 @@
|
|
|
135
138
|
"test": "jest",
|
|
136
139
|
"test:watch": "jest --watch "
|
|
137
140
|
},
|
|
138
|
-
"readme": "# @itwin/grouping-mapping-widget\r\n\r\nCopyright © Bentley Systems, Incorporated. All rights reserved.\r\nThe Grouping Mapping widget is a UI component for iTwin Viewer applications that simplifies how users (and developers) interface with the [Reporting Platform APIs](https://developer.bentley.com/apis/insights/overview/).\r\nThe grouping-mapping-widget package provides a UiProvider class - `GroupingMappingProvider` - which can be passed into the `uiProviders` prop of the iTwin Viewer's `<Viewer />` component.\r\n\r\n## Getting Started\r\n\r\nThis is not a standalone UI and requires a parent iTwin Viewer application to work as intended.\r\nA guide on how to create a basic iTwin Viewer application can be found here: <https://www.itwinjs.org/learning/tutorials/develop-web-viewer/>.\r\nThis package provides a viewer 'widget'. Documentation on how to add a widget to your application can be found here: <https://developer.bentley.com/tutorials/itwin-viewer-hello-world/#2-your-first-ui-widget>.\r\n\r\n## Permissions and Scopes\r\n\r\nThe SPA client used by your iTwin viewer must have these additional scopes:\r\n\r\n- `insights:read`\r\n- `insights:modify`\r\n- `projects:read`\r\n\r\nIn addition, users must have the `imodels_read` and `imodels_write` [permissions](https://developer.bentley.com/apis/insights/operations/create-mapping/#authorization) assigned at either the Project or iModel level. Further instruction on how to create roles and assign permissions can be found in the [iTwin Platform Projects API documentation](https://developer.bentley.com/apis/projects/tutorials/).\r\n\r\n## Sample usage\r\n\r\n```tsx\r\nimport { GroupingMappingProvider } from \"@itwin/grouping-mapping-widget\";\r\n<Viewer\r\n ...\r\n uiProviders={[new GroupingMappingProvider()]}\r\n/>\r\n```\r\n\r\n## Custom UI\r\n\r\nThis package provides an interface to define your own custom UI or callback functions in grouping mapping widget. There are different types of custom UIs provided.\r\n\r\n### Grouping Custom UI\r\n\r\nYou can use your own UI component to define group creation method.\r\n\r\nAn example of grouping custom UI, [ManualGroupingCustomUI](
|
|
141
|
+
"readme": "# @itwin/grouping-mapping-widget\r\n\r\nCopyright © Bentley Systems, Incorporated. All rights reserved.\r\nThe Grouping Mapping widget is a UI component for iTwin Viewer applications that simplifies how users (and developers) interface with the [Reporting Platform APIs](https://developer.bentley.com/apis/insights/overview/).\r\nThe grouping-mapping-widget package provides a UiProvider class - `GroupingMappingProvider` - which can be passed into the `uiProviders` prop of the iTwin Viewer's `<Viewer />` component.\r\n\r\n## Getting Started\r\n\r\nThis is not a standalone UI and requires a parent iTwin Viewer application to work as intended.\r\nA guide on how to create a basic iTwin Viewer application can be found here: <https://www.itwinjs.org/learning/tutorials/develop-web-viewer/>.\r\nThis package provides a viewer 'widget'. Documentation on how to add a widget to your application can be found here: <https://developer.bentley.com/tutorials/itwin-viewer-hello-world/#2-your-first-ui-widget>.\r\n\r\n## Permissions and Scopes\r\n\r\nThe SPA client used by your iTwin viewer must have these additional scopes:\r\n\r\n- `insights:read`\r\n- `insights:modify`\r\n- `projects:read`\r\n\r\nIn addition, users must have the `imodels_read` and `imodels_write` [permissions](https://developer.bentley.com/apis/insights/operations/create-mapping/#authorization) assigned at either the Project or iModel level. Further instruction on how to create roles and assign permissions can be found in the [iTwin Platform Projects API documentation](https://developer.bentley.com/apis/projects/tutorials/).\r\n\r\n## Sample usage\r\n\r\n```tsx\r\nimport { GroupingMappingProvider } from \"@itwin/grouping-mapping-widget\";\r\n<Viewer\r\n ...\r\n uiProviders={[new GroupingMappingProvider()]}\r\n/>\r\n```\r\n\r\n## Custom UI\r\n\r\nThis package provides an interface to define your own custom UI or callback functions in grouping mapping widget. There are different types of custom UIs provided.\r\n\r\n### Grouping Custom UI\r\n\r\nYou can use your own UI component to define group creation method.\r\n\r\nAn example of grouping custom UI, [ManualGroupingCustomUI](./src/widget/components/customUI/ManualGroupingCustomUI.tsx) helps user to manually define ECSQL query for groups.\r\n\r\nIn `GroupingCustomUIProps`:\r\n\r\n- `updateQuery` is used to run the query and visualize results in the viewer.\r\n- `isUpdating` keeps track of the status of query execution.\r\n- `resetView` enables you to reset the viewer state.\r\n\r\nTo configure your own grouping custom UI, you need to give it:\r\n\r\n- a `type` as `GroupingMappingCustomUIType.Grouping`\r\n- a `name` as identifier\r\n- a `displayLabel` which will be shown in the 'Add Group' dropdown list\r\n- a `uiComponent` like above\r\n- an optional `icon`\r\n\r\nYou can define your UI provider as follows in the GroupingMappingProvider:\r\n\r\n```tsx\r\nnew GroupingMappingProvider({\r\n customUIs: [\r\n {\r\n type: GroupingMappingCustomUIType.Grouping,\r\n name: \"Manual\",\r\n displayLabel: \"Manual Query\",\r\n uiComponent: ManualGroupingCustomUI,\r\n icon: <SvgDraw />,\r\n },\r\n ],\r\n});\r\n```\r\n\r\nAfter adding the grouping custom UI, it will be presented in the 'Add Group' drop down list.\r\n\r\n\r\n\r\n### Context Custom UI\r\n\r\nYou can also add custom UI in context menu for each group. This could be UI driven interaction or simply a callback function to execute your own code.\r\n\r\nYou can use the `iModelId`, `mappingId` and `groupId` in `ContextCustomUIProps` provided by Grouping Mapping Widget in your UI component or callback.\r\n\r\nTo configure your own context custom UI, you need to give it:\r\n\r\n- a `type` as `GroupingMappingCustomUIType.Context`\r\n- a `name` as identifier\r\n- a `displayLabel` which will be shown in the context dropdown list in each group tile\r\n- an optional `uiComponent` which will be presented in the widget as a UI component\r\n- an optional `onClick` callback function where you could make your own API calls\r\n- an optional `icon`\r\n\r\nYou can define your context custom UI as following example in the GroupingMappingProvider with an example is to use [clash detection](https://www.itwinjs.org/sandboxes/iTwinPlatform/Clash%20Review) in the widget:\r\n\r\n```tsx\r\nconst customCB = (groupId: string, mappingId: string, iModelId: string) => {\r\n toaster.informational(`Called callback for group ${groupId}`)\r\n}\r\n\r\nnew GroupingMappingProvider({\r\n customUIs: [\r\n {\r\n type: GroupingMappingCustomUIType.Context,\r\n name: \"ClashDetection\",\r\n displayLabel: \"Clash Detection\",\r\n uiComponent: ClashDetectionCustomUI,\r\n onClick: customCB,\r\n icon: <SvgClash />,\r\n },\r\n ],\r\n});\r\n```\r\n\r\nAfter adding the context custom UI, the context menu item will look like this with additional `Clash Detection` menu item.\r\n\r\n\r\n"
|
|
139
142
|
}
|