@itwin/grouping-mapping-widget 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/cjs/test/GroupPropertyUtils.test.js +61 -1
  2. package/lib/cjs/test/GroupPropertyUtils.test.js.map +1 -1
  3. package/lib/cjs/test/GroupingMappingCustomUI.test.js +44 -53
  4. package/lib/cjs/test/GroupingMappingCustomUI.test.js.map +1 -1
  5. package/lib/cjs/test/QueryBuilder.test.js +30 -2
  6. package/lib/cjs/test/QueryBuilder.test.js.map +1 -1
  7. package/lib/cjs/test/QueryBuilder.testdata.js +471 -7
  8. package/lib/cjs/test/QueryBuilder.testdata.js.map +1 -1
  9. package/lib/cjs/test/QueryBuilderTestData.d.ts +3 -1
  10. package/lib/cjs/test/QueryBuilderTestData.js.map +1 -1
  11. package/lib/cjs/widget/components/GroupAction.js +2 -21
  12. package/lib/cjs/widget/components/GroupAction.js.map +1 -1
  13. package/lib/cjs/widget/components/GroupPropertyUtils.js +2 -1
  14. package/lib/cjs/widget/components/GroupPropertyUtils.js.map +1 -1
  15. package/lib/cjs/widget/components/GroupQueryBuilderContainer.d.ts +3 -2
  16. package/lib/cjs/widget/components/GroupQueryBuilderContainer.js +38 -45
  17. package/lib/cjs/widget/components/GroupQueryBuilderContainer.js.map +1 -1
  18. package/lib/cjs/widget/components/Grouping.js +1 -1
  19. package/lib/cjs/widget/components/Grouping.js.map +1 -1
  20. package/lib/cjs/widget/components/Grouping.scss +1 -1
  21. package/lib/cjs/widget/components/QueryBuilder.d.ts +35 -21
  22. package/lib/cjs/widget/components/QueryBuilder.js +153 -181
  23. package/lib/cjs/widget/components/QueryBuilder.js.map +1 -1
  24. package/lib/cjs/widget/components/context/PropertyGridWrapperContext.d.ts +15 -0
  25. package/lib/cjs/widget/components/context/{GroupQueryBuilderContext.js → PropertyGridWrapperContext.js} +13 -9
  26. package/lib/cjs/widget/components/context/PropertyGridWrapperContext.js.map +1 -0
  27. package/lib/cjs/widget/components/property-grid/PropertyGrid.d.ts +1 -1
  28. package/lib/cjs/widget/components/property-grid/PropertyGrid.js +2 -2
  29. package/lib/cjs/widget/components/property-grid/PropertyGrid.js.map +1 -1
  30. package/lib/cjs/widget/components/property-grid/PropertyGridWrapper.d.ts +10 -4
  31. package/lib/cjs/widget/components/property-grid/PropertyGridWrapper.js +18 -8
  32. package/lib/cjs/widget/components/property-grid/PropertyGridWrapper.js.map +1 -1
  33. package/lib/cjs/widget/components/property-grid/PropertyView.d.ts +1 -1
  34. package/lib/cjs/widget/components/property-grid/PropertyView.js +46 -60
  35. package/lib/cjs/widget/components/property-grid/PropertyView.js.map +1 -1
  36. package/lib/cjs/widget/components/viewerUtils.js +1 -3
  37. package/lib/cjs/widget/components/viewerUtils.js.map +1 -1
  38. package/lib/esm/test/GroupPropertyUtils.test.js +61 -1
  39. package/lib/esm/test/GroupPropertyUtils.test.js.map +1 -1
  40. package/lib/esm/test/GroupingMappingCustomUI.test.js +45 -54
  41. package/lib/esm/test/GroupingMappingCustomUI.test.js.map +1 -1
  42. package/lib/esm/test/QueryBuilder.test.js +31 -3
  43. package/lib/esm/test/QueryBuilder.test.js.map +1 -1
  44. package/lib/esm/test/QueryBuilder.testdata.js +471 -7
  45. package/lib/esm/test/QueryBuilder.testdata.js.map +1 -1
  46. package/lib/esm/test/QueryBuilderTestData.d.ts +3 -1
  47. package/lib/esm/test/QueryBuilderTestData.js.map +1 -1
  48. package/lib/esm/widget/components/GroupAction.js +2 -21
  49. package/lib/esm/widget/components/GroupAction.js.map +1 -1
  50. package/lib/esm/widget/components/GroupPropertyUtils.js +2 -1
  51. package/lib/esm/widget/components/GroupPropertyUtils.js.map +1 -1
  52. package/lib/esm/widget/components/GroupQueryBuilderContainer.d.ts +3 -2
  53. package/lib/esm/widget/components/GroupQueryBuilderContainer.js +34 -25
  54. package/lib/esm/widget/components/GroupQueryBuilderContainer.js.map +1 -1
  55. package/lib/esm/widget/components/Grouping.js +1 -1
  56. package/lib/esm/widget/components/Grouping.js.map +1 -1
  57. package/lib/esm/widget/components/Grouping.scss +1 -1
  58. package/lib/esm/widget/components/QueryBuilder.d.ts +35 -21
  59. package/lib/esm/widget/components/QueryBuilder.js +153 -181
  60. package/lib/esm/widget/components/QueryBuilder.js.map +1 -1
  61. package/lib/esm/widget/components/context/PropertyGridWrapperContext.d.ts +15 -0
  62. package/lib/esm/widget/components/context/{GroupQueryBuilderContext.js → PropertyGridWrapperContext.js} +11 -8
  63. package/lib/esm/widget/components/context/PropertyGridWrapperContext.js.map +1 -0
  64. package/lib/esm/widget/components/property-grid/PropertyGrid.d.ts +1 -1
  65. package/lib/esm/widget/components/property-grid/PropertyGrid.js +2 -2
  66. package/lib/esm/widget/components/property-grid/PropertyGrid.js.map +1 -1
  67. package/lib/esm/widget/components/property-grid/PropertyGridWrapper.d.ts +10 -4
  68. package/lib/esm/widget/components/property-grid/PropertyGridWrapper.js +16 -6
  69. package/lib/esm/widget/components/property-grid/PropertyGridWrapper.js.map +1 -1
  70. package/lib/esm/widget/components/property-grid/PropertyView.d.ts +1 -1
  71. package/lib/esm/widget/components/property-grid/PropertyView.js +32 -30
  72. package/lib/esm/widget/components/property-grid/PropertyView.js.map +1 -1
  73. package/lib/esm/widget/components/viewerUtils.js +1 -3
  74. package/lib/esm/widget/components/viewerUtils.js.map +1 -1
  75. package/package.json +2 -2
  76. package/lib/cjs/api/GroupQueryBuilderApi.d.ts +0 -15
  77. package/lib/cjs/api/GroupQueryBuilderApi.js +0 -27
  78. package/lib/cjs/api/GroupQueryBuilderApi.js.map +0 -1
  79. package/lib/cjs/widget/components/context/GroupQueryBuilderContext.d.ts +0 -16
  80. package/lib/cjs/widget/components/context/GroupQueryBuilderContext.js.map +0 -1
  81. package/lib/esm/api/GroupQueryBuilderApi.d.ts +0 -15
  82. package/lib/esm/api/GroupQueryBuilderApi.js +0 -23
  83. package/lib/esm/api/GroupQueryBuilderApi.js.map +0 -1
  84. package/lib/esm/widget/components/context/GroupQueryBuilderContext.d.ts +0 -16
  85. package/lib/esm/widget/components/context/GroupQueryBuilderContext.js.map +0 -1
@@ -26,18 +26,46 @@ describe("QueryBuilder", () => {
26
26
  testData.testCases.forEach((testCase) => {
27
27
  it(testCase.name, async () => executeTest(sut, testCase.expectedResult, testCase.operations));
28
28
  });
29
- const createPropertyRecord = (propertyRecord, propertiesField) => {
29
+ const createFieldDescriptor = (pathToClass, fieldProperties, type, fieldName) => {
30
+ switch (type) {
31
+ case presentation_common_1.FieldDescriptorType.Properties:
32
+ const pathFromSelectToPropertyClass = (pathToClass !== null && pathToClass !== void 0 ? pathToClass : []).map((x) => ({
33
+ sourceClassName: x.sourceClassInfo.name,
34
+ targetClassName: x.targetClassInfo.name,
35
+ relationshipName: x.relationshipInfo.name,
36
+ isForwardRelationship: x.isForwardRelationship,
37
+ }));
38
+ const properties = fieldProperties.map((x) => ({
39
+ class: x.property.classInfo.name,
40
+ name: x.property.name,
41
+ }));
42
+ return {
43
+ pathFromSelectToPropertyClass,
44
+ properties,
45
+ type,
46
+ };
47
+ case presentation_common_1.FieldDescriptorType.Name:
48
+ return {
49
+ type,
50
+ fieldName: fieldName !== null && fieldName !== void 0 ? fieldName : "",
51
+ };
52
+ }
53
+ };
54
+ const createPropertyRecord = (propertyRecord, propertiesField, fieldDescriptor) => {
30
55
  const propertiesFieldMock = MockFactory_1.MockFactory.create(presentation_common_1.PropertiesField);
31
56
  MockFactory_1.MockFactory.stubProperty(propertiesFieldMock, "parent", () => propertiesField.parent);
32
57
  MockFactory_1.MockFactory.stubProperty(propertiesFieldMock, "properties", () => propertiesField.properties);
33
58
  MockFactory_1.MockFactory.stubProperty(propertiesFieldMock, "type", () => propertiesField.type);
59
+ MockFactory_1.MockFactory.stubProperty(propertiesFieldMock, "getFieldDescriptor", () => () => fieldDescriptor);
34
60
  const prop = new appui_abstract_1.PropertyRecord(propertyRecord.value, propertyRecord.property);
35
61
  dataProvider.getFieldByPropertyRecord.withArgs(prop).resolves(propertiesFieldMock);
36
62
  return prop;
37
63
  };
38
64
  const executeTest = async (queryBuilder, expectedResult, operations) => {
65
+ var _a;
39
66
  for (const op of operations) {
40
- const prop = createPropertyRecord(op.propertyRecord, op.propertiesField);
67
+ const fieldDescriptor = createFieldDescriptor((_a = op.propertiesField.parent) === null || _a === void 0 ? void 0 : _a.pathToPrimaryClass, op.propertiesField.properties, op.fieldDescriptorType, op.fieldDescriptorName);
68
+ const prop = createPropertyRecord(op.propertyRecord, op.propertiesField, fieldDescriptor);
41
69
  if (op.operationType === "addProperty") {
42
70
  const result = await queryBuilder.addProperty(prop);
43
71
  chai_1.assert.strictEqual(result, op.expectedResult);
@@ -1 +1 @@
1
- {"version":3,"file":"QueryBuilder.test.js","sourceRoot":"","sources":["../../../src/test/QueryBuilder.test.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,0DAAuD;AACvD,oEAA6D;AAC7D,4EAAkF;AAClF,+BAA8B;AAC9B,oEAAiE;AACjE,+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,CAAC,QAAQ,EA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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 { PropertiesField } from \"@itwin/presentation-common\";\nimport { PresentationPropertyDataProvider } from \"@itwin/presentation-components\";\nimport { assert } from \"chai\";\nimport { QueryBuilder } from \"../widget/components/QueryBuilder\";\nimport { MockFactory } from \"./MockFactory\";\nimport type { StubbedType } from \"./MockFactory\";\nimport type { OperationTestData, 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(\n sut,\n testCase.expectedResult,\n testCase.operations,\n ));\n });\n\n const createPropertyRecord = (propertyRecord: PropertyRecordTestData, propertiesField: PropertiesField) => {\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\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 prop = createPropertyRecord(op.propertyRecord, op.propertiesField as PropertiesField);\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":";;AAAA;;;+FAG+F;AAC/F,0DAAuD;AACvD,oEAAkF;AAElF,4EAAkF;AAClF,+BAA8B;AAC9B,oEAAiE;AACjE,+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,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F,MAAM,IAAI,GAAG,oBAAoB,CAAC,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,eAAkC,EAAE,eAAe,CAAC,CAAC;YAE7G,IAAI,EAAE,CAAC,aAAa,KAAK,aAAa,EAAE;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,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 \"../widget/components/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(\n sut,\n testCase.expectedResult,\n testCase.operations,\n ));\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"]}