@itwin/grouping-mapping-widget 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/lib/cjs/formula/FormulaTokensValidator.d.ts +1 -1
  2. package/lib/cjs/formula/FormulaTokensValidator.js +3 -1
  3. package/lib/cjs/formula/FormulaTokensValidator.js.map +1 -1
  4. package/lib/cjs/formula/FormulaValidator.d.ts +1 -1
  5. package/lib/cjs/formula/FormulaValidator.js +2 -2
  6. package/lib/cjs/formula/FormulaValidator.js.map +1 -1
  7. package/lib/cjs/grouping-mapping-widget.d.ts +4 -0
  8. package/lib/cjs/grouping-mapping-widget.js +6 -1
  9. package/lib/cjs/grouping-mapping-widget.js.map +1 -1
  10. package/lib/cjs/widget/GroupingMappingWidget.d.ts +3 -1
  11. package/lib/cjs/widget/GroupingMappingWidget.js +3 -2
  12. package/lib/cjs/widget/GroupingMappingWidget.js.map +1 -1
  13. package/lib/cjs/widget/IMappingClient.d.ts +327 -0
  14. package/lib/cjs/widget/IMappingClient.js +7 -0
  15. package/lib/cjs/widget/IMappingClient.js.map +1 -0
  16. package/lib/cjs/widget/components/BlockingOverlay.d.ts +7 -0
  17. package/lib/cjs/widget/components/BlockingOverlay.js +21 -0
  18. package/lib/cjs/widget/components/BlockingOverlay.js.map +1 -0
  19. package/lib/cjs/widget/components/BlockingOverlay.scss +26 -0
  20. package/lib/cjs/widget/components/CalculatedPropertyAction.js +3 -4
  21. package/lib/cjs/widget/components/CalculatedPropertyAction.js.map +1 -1
  22. package/lib/cjs/widget/components/CalculatedPropertyTable.js +2 -3
  23. package/lib/cjs/widget/components/CalculatedPropertyTable.js.map +1 -1
  24. package/lib/cjs/widget/components/ConfirmMappingsImport.js +2 -3
  25. package/lib/cjs/widget/components/ConfirmMappingsImport.js.map +1 -1
  26. package/lib/cjs/widget/components/CustomCalculationAction.js +4 -5
  27. package/lib/cjs/widget/components/CustomCalculationAction.js.map +1 -1
  28. package/lib/cjs/widget/components/CustomCalculationTable.js +2 -3
  29. package/lib/cjs/widget/components/CustomCalculationTable.js.map +1 -1
  30. package/lib/cjs/widget/components/GroupAction.d.ts +2 -1
  31. package/lib/cjs/widget/components/GroupAction.js +15 -10
  32. package/lib/cjs/widget/components/GroupAction.js.map +1 -1
  33. package/lib/cjs/widget/components/GroupPropertyAction.js +5 -7
  34. package/lib/cjs/widget/components/GroupPropertyAction.js.map +1 -1
  35. package/lib/cjs/widget/components/GroupPropertyTable.js +2 -3
  36. package/lib/cjs/widget/components/GroupPropertyTable.js.map +1 -1
  37. package/lib/cjs/widget/components/GroupQueryBuilderContainer.js +1 -0
  38. package/lib/cjs/widget/components/GroupQueryBuilderContainer.js.map +1 -1
  39. package/lib/cjs/widget/components/GroupQueryBuilderContext.d.ts +1 -0
  40. package/lib/cjs/widget/components/GroupQueryBuilderContext.js +1 -0
  41. package/lib/cjs/widget/components/GroupQueryBuilderContext.js.map +1 -1
  42. package/lib/cjs/widget/components/GroupTile.d.ts +13 -0
  43. package/lib/cjs/widget/components/GroupTile.js +18 -0
  44. package/lib/cjs/widget/components/GroupTile.js.map +1 -0
  45. package/lib/cjs/widget/components/GroupTile.scss +32 -0
  46. package/lib/cjs/widget/components/Grouping.js +224 -164
  47. package/lib/cjs/widget/components/Grouping.js.map +1 -1
  48. package/lib/cjs/widget/components/Grouping.scss +39 -4
  49. package/lib/cjs/widget/components/GroupingMapping.d.ts +15 -3
  50. package/lib/cjs/widget/components/GroupingMapping.js +29 -5
  51. package/lib/cjs/widget/components/GroupingMapping.js.map +1 -1
  52. package/lib/cjs/widget/components/Mapping.js +33 -12
  53. package/lib/cjs/widget/components/Mapping.js.map +1 -1
  54. package/lib/cjs/widget/components/MappingAction.js +10 -5
  55. package/lib/cjs/widget/components/MappingAction.js.map +1 -1
  56. package/lib/cjs/widget/components/PropertyMenu.js +26 -19
  57. package/lib/cjs/widget/components/PropertyMenu.js.map +1 -1
  58. package/lib/cjs/widget/components/QueryBuilder.d.ts +11 -5
  59. package/lib/cjs/widget/components/QueryBuilder.js +229 -141
  60. package/lib/cjs/widget/components/QueryBuilder.js.map +1 -1
  61. package/lib/cjs/widget/components/SelectMappings.js +5 -6
  62. package/lib/cjs/widget/components/SelectMappings.js.map +1 -1
  63. package/lib/cjs/widget/components/property-grid/PropertyView.js +5 -0
  64. package/lib/cjs/widget/components/property-grid/PropertyView.js.map +1 -1
  65. package/lib/cjs/widget/components/utils.d.ts +6 -0
  66. package/lib/cjs/widget/components/utils.js +9 -1
  67. package/lib/cjs/widget/components/utils.js.map +1 -1
  68. package/lib/cjs/widget/components/utils.scss +12 -3
  69. package/lib/cjs/widget/components/viewerUtils.d.ts +19 -0
  70. package/lib/cjs/widget/components/viewerUtils.js +224 -3
  71. package/lib/cjs/widget/components/viewerUtils.js.map +1 -1
  72. package/lib/cjs/widget/hooks/useFormulaValidation.d.ts +1 -1
  73. package/lib/cjs/widget/hooks/useFormulaValidation.js +5 -5
  74. package/lib/cjs/widget/hooks/useFormulaValidation.js.map +1 -1
  75. package/lib/esm/formula/FormulaTokensValidator.d.ts +1 -1
  76. package/lib/esm/formula/FormulaTokensValidator.js +3 -1
  77. package/lib/esm/formula/FormulaTokensValidator.js.map +1 -1
  78. package/lib/esm/formula/FormulaValidator.d.ts +1 -1
  79. package/lib/esm/formula/FormulaValidator.js +2 -2
  80. package/lib/esm/formula/FormulaValidator.js.map +1 -1
  81. package/lib/esm/grouping-mapping-widget.d.ts +4 -0
  82. package/lib/esm/grouping-mapping-widget.js +4 -0
  83. package/lib/esm/grouping-mapping-widget.js.map +1 -1
  84. package/lib/esm/widget/GroupingMappingWidget.d.ts +3 -1
  85. package/lib/esm/widget/GroupingMappingWidget.js +3 -2
  86. package/lib/esm/widget/GroupingMappingWidget.js.map +1 -1
  87. package/lib/esm/widget/IMappingClient.d.ts +327 -0
  88. package/lib/esm/widget/IMappingClient.js +6 -0
  89. package/lib/esm/widget/IMappingClient.js.map +1 -0
  90. package/lib/esm/widget/components/BlockingOverlay.d.ts +7 -0
  91. package/lib/esm/widget/components/BlockingOverlay.js +14 -0
  92. package/lib/esm/widget/components/BlockingOverlay.js.map +1 -0
  93. package/lib/esm/widget/components/BlockingOverlay.scss +26 -0
  94. package/lib/esm/widget/components/CalculatedPropertyAction.js +4 -5
  95. package/lib/esm/widget/components/CalculatedPropertyAction.js.map +1 -1
  96. package/lib/esm/widget/components/CalculatedPropertyTable.js +3 -4
  97. package/lib/esm/widget/components/CalculatedPropertyTable.js.map +1 -1
  98. package/lib/esm/widget/components/ConfirmMappingsImport.js +3 -4
  99. package/lib/esm/widget/components/ConfirmMappingsImport.js.map +1 -1
  100. package/lib/esm/widget/components/CustomCalculationAction.js +5 -6
  101. package/lib/esm/widget/components/CustomCalculationAction.js.map +1 -1
  102. package/lib/esm/widget/components/CustomCalculationTable.js +3 -4
  103. package/lib/esm/widget/components/CustomCalculationTable.js.map +1 -1
  104. package/lib/esm/widget/components/GroupAction.d.ts +2 -1
  105. package/lib/esm/widget/components/GroupAction.js +17 -12
  106. package/lib/esm/widget/components/GroupAction.js.map +1 -1
  107. package/lib/esm/widget/components/GroupPropertyAction.js +6 -8
  108. package/lib/esm/widget/components/GroupPropertyAction.js.map +1 -1
  109. package/lib/esm/widget/components/GroupPropertyTable.js +3 -4
  110. package/lib/esm/widget/components/GroupPropertyTable.js.map +1 -1
  111. package/lib/esm/widget/components/GroupQueryBuilderContainer.js +1 -0
  112. package/lib/esm/widget/components/GroupQueryBuilderContainer.js.map +1 -1
  113. package/lib/esm/widget/components/GroupQueryBuilderContext.d.ts +1 -0
  114. package/lib/esm/widget/components/GroupQueryBuilderContext.js +1 -0
  115. package/lib/esm/widget/components/GroupQueryBuilderContext.js.map +1 -1
  116. package/lib/esm/widget/components/GroupTile.d.ts +13 -0
  117. package/lib/esm/widget/components/GroupTile.js +11 -0
  118. package/lib/esm/widget/components/GroupTile.js.map +1 -0
  119. package/lib/esm/widget/components/GroupTile.scss +32 -0
  120. package/lib/esm/widget/components/Grouping.js +230 -170
  121. package/lib/esm/widget/components/Grouping.js.map +1 -1
  122. package/lib/esm/widget/components/Grouping.scss +39 -4
  123. package/lib/esm/widget/components/GroupingMapping.d.ts +15 -3
  124. package/lib/esm/widget/components/GroupingMapping.js +27 -4
  125. package/lib/esm/widget/components/GroupingMapping.js.map +1 -1
  126. package/lib/esm/widget/components/Mapping.js +35 -14
  127. package/lib/esm/widget/components/Mapping.js.map +1 -1
  128. package/lib/esm/widget/components/MappingAction.js +12 -7
  129. package/lib/esm/widget/components/MappingAction.js.map +1 -1
  130. package/lib/esm/widget/components/PropertyMenu.js +28 -21
  131. package/lib/esm/widget/components/PropertyMenu.js.map +1 -1
  132. package/lib/esm/widget/components/QueryBuilder.d.ts +11 -5
  133. package/lib/esm/widget/components/QueryBuilder.js +230 -142
  134. package/lib/esm/widget/components/QueryBuilder.js.map +1 -1
  135. package/lib/esm/widget/components/SelectMappings.js +6 -7
  136. package/lib/esm/widget/components/SelectMappings.js.map +1 -1
  137. package/lib/esm/widget/components/property-grid/PropertyView.js +5 -0
  138. package/lib/esm/widget/components/property-grid/PropertyView.js.map +1 -1
  139. package/lib/esm/widget/components/utils.d.ts +6 -0
  140. package/lib/esm/widget/components/utils.js +6 -0
  141. package/lib/esm/widget/components/utils.js.map +1 -1
  142. package/lib/esm/widget/components/utils.scss +12 -3
  143. package/lib/esm/widget/components/viewerUtils.d.ts +19 -0
  144. package/lib/esm/widget/components/viewerUtils.js +207 -3
  145. package/lib/esm/widget/components/viewerUtils.js.map +1 -1
  146. package/lib/esm/widget/hooks/useFormulaValidation.d.ts +1 -1
  147. package/lib/esm/widget/hooks/useFormulaValidation.js +5 -5
  148. package/lib/esm/widget/hooks/useFormulaValidation.js.map +1 -1
  149. package/package.json +30 -30
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockingOverlay.js","sourceRoot":"","sources":["../../../../src/widget/components/BlockingOverlay.tsx"],"names":[],"mappings":";;;;;;AAAA;;;+FAG+F;AAC/F,4DAAoC;AACpC,kDAA0B;AAC1B,mCAAyC;AACzC,kCAAgC;AAMzB,MAAM,eAAe,GAAG,CAAC,EAAE,SAAS,EAAwB,EAAE,EAAE;IACrE,OAAO,CACL,uCAAK,SAAS,EAAE,oBAAU,CAAC,gCAAgC,EAAE,SAAS,IAAI,SAAS,CAAC;QAClF,uCAAK,SAAS,EAAC,wCAAwC;YACrD,8BAAC,sBAAc,OAAG,CACd,CACF,CACP,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,eAAe,mBAQ1B","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 classnames from \"classnames\";\nimport React from \"react\";\nimport { LoadingSpinner } from \"./utils\";\nimport \"./BlockingOverlay.scss\";\n\nexport interface BlockingOverlayProps {\n isVisible: boolean;\n}\n\nexport const BlockingOverlay = ({ isVisible }: BlockingOverlayProps) => {\n return (\n <div className={classnames(\"group-mapping-blocking-overlay\", isVisible && \"visible\")}>\n <div className=\"group-mapping-blocking-overlay-spinner\">\n <LoadingSpinner />\n </div>\n </div>\n );\n};\n"]}
@@ -0,0 +1,26 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ @import '~@itwin/itwinui-css/scss/variables';
6
+
7
+ .group-mapping-blocking-overlay {
8
+ background-color: black;
9
+ position: absolute;
10
+ height: inherit;
11
+ right: 6px;
12
+ left: 6px;
13
+ opacity: 60%;
14
+ z-index: 9999;
15
+ visibility: hidden;
16
+
17
+ &.visible {
18
+ visibility: visible;
19
+ }
20
+ }
21
+
22
+ .group-mapping-blocking-overlay-spinner {
23
+ display: flex;
24
+ justify-content: center;
25
+ height: inherit;
26
+ }
@@ -35,11 +35,11 @@ const useValidator_1 = __importStar(require("../hooks/useValidator"));
35
35
  const utils_1 = require("./utils");
36
36
  const viewerUtils_1 = require("./viewerUtils");
37
37
  require("./CalculatedPropertyAction.scss");
38
- const insights_client_1 = require("@itwin/insights-client");
39
38
  const GroupingMapping_1 = require("./GroupingMapping");
40
39
  const CalculatedPropertyAction = ({ iModelId, mappingId, groupId, property, ids, returnFn, }) => {
41
40
  var _a, _b, _c;
42
41
  const apiContext = react_1.useContext(GroupingMapping_1.ApiContext);
42
+ const mappingClient = react_1.useContext(GroupingMapping_1.MappingClientContext);
43
43
  const [propertyName, setPropertyName] = react_1.useState((_a = property === null || property === void 0 ? void 0 : property.propertyName) !== null && _a !== void 0 ? _a : "");
44
44
  const [type, setType] = react_1.useState((_b = property === null || property === void 0 ? void 0 : property.type) !== null && _b !== void 0 ? _b : "");
45
45
  const [bboxDecorator, setBboxDecorator] = react_1.useState();
@@ -88,13 +88,12 @@ const CalculatedPropertyAction = ({ iModelId, mappingId, groupId, property, ids,
88
88
  }
89
89
  try {
90
90
  setIsLoading(true);
91
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
92
91
  property
93
- ? await reportingClientApi.updateCalculatedProperty(apiContext.accessToken, iModelId, mappingId, groupId, (_a = property.id) !== null && _a !== void 0 ? _a : "", {
92
+ ? await mappingClient.updateCalculatedProperty(apiContext.accessToken, iModelId, mappingId, groupId, (_a = property.id) !== null && _a !== void 0 ? _a : "", {
94
93
  propertyName,
95
94
  type,
96
95
  })
97
- : await reportingClientApi.createCalculatedProperty(apiContext.accessToken, iModelId, mappingId, groupId, {
96
+ : await mappingClient.createCalculatedProperty(apiContext.accessToken, iModelId, mappingId, groupId, {
98
97
  propertyName,
99
98
  type,
100
99
  });
@@ -1 +1 @@
1
- {"version":3,"file":"CalculatedPropertyAction.js","sourceRoot":"","sources":["../../../../src/widget/components/CalculatedPropertyAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC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["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport type {\n SelectOption,\n} from \"@itwin/itwinui-react\";\nimport {\n Fieldset,\n LabeledInput,\n LabeledSelect,\n MenuItem,\n Small,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useEffect, useState } from \"react\";\nimport ActionPanel from \"./ActionPanel\";\nimport {\n BboxDimension,\n BboxDimensionsDecorator,\n} from \"../../decorators/BboxDimensionsDecorator\";\nimport useValidator, { NAME_REQUIREMENTS } from \"../hooks/useValidator\";\nimport { handleError, WidgetHeader } from \"./utils\";\nimport { visualizeElements, zoomToElements } from \"./viewerUtils\";\nimport \"./CalculatedPropertyAction.scss\";\nimport type { CalculatedPropertyType } from \"./CalculatedPropertyTable\";\nimport { ReportingClient } from \"@itwin/insights-client\";\nimport { ApiContext } from \"./GroupingMapping\";\n\ninterface CalculatedPropertyActionProps {\n iModelId: string;\n mappingId: string;\n groupId: string;\n property?: CalculatedPropertyType;\n ids: string[];\n returnFn: (modified: boolean) => Promise<void>;\n}\n\nconst CalculatedPropertyAction = ({\n iModelId,\n mappingId,\n groupId,\n property,\n ids,\n returnFn,\n}: CalculatedPropertyActionProps) => {\n const apiContext = useContext(ApiContext);\n const [propertyName, setPropertyName] = useState<string>(\n property?.propertyName ?? \"\",\n );\n const [type, setType] = useState<string>(property?.type ?? \"\");\n const [bboxDecorator, setBboxDecorator] = useState<BboxDimensionsDecorator | undefined>();\n const [isLoading, setIsLoading] = useState<boolean>(false);\n const [inferredSpatialData, setInferredSpatialData] = useState<Map<BboxDimension, number> | undefined>();\n const [validator, showValidationMessage] = useValidator();\n\n useEffect(() => {\n const decorator = new BboxDimensionsDecorator();\n IModelApp.viewManager.addDecorator(decorator);\n setBboxDecorator(decorator);\n return () => {\n IModelApp.viewManager.dropDecorator(decorator);\n };\n }, []);\n\n useEffect(() => {\n if (ids.length === 0) {\n return;\n }\n visualizeElements([ids[0]], \"red\");\n void zoomToElements([ids[0]]);\n }, [ids]);\n\n useEffect(() => {\n if (ids.length === 0) {\n return;\n }\n const setContext = async () => {\n if (bboxDecorator) {\n await bboxDecorator.setContext(ids[0]);\n setInferredSpatialData(bboxDecorator.getInferredSpatialData());\n }\n };\n void setContext();\n }, [bboxDecorator, ids]);\n\n useEffect(() => {\n if (bboxDecorator && type && inferredSpatialData) {\n inferredSpatialData.has(BboxDimension[type as keyof typeof BboxDimension])\n ? bboxDecorator.drawContext(\n BboxDimension[type as keyof typeof BboxDimension],\n )\n : bboxDecorator.clearContext();\n }\n }, [bboxDecorator, inferredSpatialData, type]);\n\n const onSave = async () => {\n if (!validator.allValid()) {\n showValidationMessage(true);\n return;\n }\n try {\n setIsLoading(true);\n\n const reportingClientApi = new ReportingClient(apiContext.prefix);\n\n property\n ? await reportingClientApi.updateCalculatedProperty(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n property.id ?? \"\",\n {\n propertyName,\n type,\n },\n )\n : await reportingClientApi.createCalculatedProperty(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n {\n propertyName,\n type,\n },\n );\n await returnFn(true);\n } catch (error: any) {\n handleError(error.status);\n setIsLoading(false);\n }\n };\n\n const getSpatialData = (value: string) =>\n inferredSpatialData?.has(\n BboxDimension[value as keyof typeof BboxDimension],\n ) && (\n <div>\n {`${inferredSpatialData\n ?.get(BboxDimension[value as keyof typeof BboxDimension])\n ?.toPrecision(4)}m`}\n </div>\n );\n\n return (\n <>\n <WidgetHeader\n title={\n property\n ? `${property?.propertyName ?? \"\"}`\n : \"Create Calculated Property\"\n }\n returnFn={async () => returnFn(false)}\n />\n <div className='calculated-properties-action-container'>\n <Fieldset legend='Calculated Property Details' className='details-form'>\n <Small className='field-legend'>\n Asterisk * indicates mandatory fields.\n </Small>\n <LabeledInput\n value={propertyName}\n required\n name='name'\n label='Name'\n onChange={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"name\");\n }}\n message={validator.message(\"name\", propertyName, NAME_REQUIREMENTS)}\n status={\n validator.message(\"name\", propertyName, NAME_REQUIREMENTS)\n ? \"negative\"\n : undefined\n }\n onBlur={() => {\n validator.showMessageFor(\"name\");\n }}\n onBlurCapture={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"name\");\n }}\n />\n <LabeledSelect<string>\n label='Quantity Type'\n required\n options={[\n { value: \"Length\", label: \"Length\" },\n { value: \"Area\", label: \"Area\" },\n { value: \"Volume\", label: \"Volume\" },\n {\n value: \"BoundingBoxLongestEdgeLength\",\n label: \"Longest Edge Length\",\n },\n {\n value: \"BoundingBoxIntermediateEdgeLength\",\n label: \"Intermediate Edge Length\",\n },\n {\n value: \"BoundingBoxShortestEdgeLength\",\n label: \"Shortest Edge Length\",\n },\n {\n value: \"BoundingBoxDiagonalLength\",\n label: \"Diagonal Length\",\n },\n {\n value: \"BoundingBoxLongestFaceDiagonalLength\",\n label: \"Longest Face Diagonal Length\",\n },\n {\n value: \"BoundingBoxIntermediateFaceDiagonalLength\",\n label: \"Intermediate Face Diagonal Length\",\n },\n {\n value: \"BoundingBoxShortestFaceDiagonalLength\",\n label: \"Shortest Face Diagonal Length\",\n },\n ]}\n value={type}\n onChange={setType}\n itemRenderer={(option: SelectOption<string>) => (\n <MenuItem>\n <div className='gr-cp-menu-item'>\n <div>{option.label}</div>\n {getSpatialData(option.value)}\n </div>\n </MenuItem>\n )}\n selectedItemRenderer={(option: SelectOption<string>) => (\n <div className='select-item'>\n <div>{option.label}</div>\n {getSpatialData(option.value)}\n </div>\n )}\n onShow={() => { }}\n onHide={() => { }}\n />\n </Fieldset>\n </div>\n <ActionPanel\n onSave={onSave}\n onCancel={async () => returnFn(false)}\n isSavingDisabled={!(type && propertyName)}\n isLoading={isLoading}\n />\n </>\n );\n};\n\nexport default CalculatedPropertyAction;\n"]}
1
+ {"version":3,"file":"Calculated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AE,SAAS,GACpB,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,wBAAwB,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 { IModelApp } from \"@itwin/core-frontend\";\nimport type {\n SelectOption,\n} from \"@itwin/itwinui-react\";\nimport {\n Fieldset,\n LabeledInput,\n LabeledSelect,\n MenuItem,\n Small,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useEffect, useState } from \"react\";\nimport ActionPanel from \"./ActionPanel\";\nimport {\n BboxDimension,\n BboxDimensionsDecorator,\n} from \"../../decorators/BboxDimensionsDecorator\";\nimport useValidator, { NAME_REQUIREMENTS } from \"../hooks/useValidator\";\nimport { handleError, WidgetHeader } from \"./utils\";\nimport { visualizeElements, zoomToElements } from \"./viewerUtils\";\nimport \"./CalculatedPropertyAction.scss\";\nimport type { CalculatedPropertyType } from \"./CalculatedPropertyTable\";\nimport { ApiContext, MappingClientContext } from \"./GroupingMapping\";\n\ninterface CalculatedPropertyActionProps {\n iModelId: string;\n mappingId: string;\n groupId: string;\n property?: CalculatedPropertyType;\n ids: string[];\n returnFn: (modified: boolean) => Promise<void>;\n}\n\nconst CalculatedPropertyAction = ({\n iModelId,\n mappingId,\n groupId,\n property,\n ids,\n returnFn,\n}: CalculatedPropertyActionProps) => {\n const apiContext = useContext(ApiContext);\n const mappingClient = useContext(MappingClientContext);\n const [propertyName, setPropertyName] = useState<string>(\n property?.propertyName ?? \"\",\n );\n const [type, setType] = useState<string>(property?.type ?? \"\");\n const [bboxDecorator, setBboxDecorator] = useState<BboxDimensionsDecorator | undefined>();\n const [isLoading, setIsLoading] = useState<boolean>(false);\n const [inferredSpatialData, setInferredSpatialData] = useState<Map<BboxDimension, number> | undefined>();\n const [validator, showValidationMessage] = useValidator();\n\n useEffect(() => {\n const decorator = new BboxDimensionsDecorator();\n IModelApp.viewManager.addDecorator(decorator);\n setBboxDecorator(decorator);\n return () => {\n IModelApp.viewManager.dropDecorator(decorator);\n };\n }, []);\n\n useEffect(() => {\n if (ids.length === 0) {\n return;\n }\n visualizeElements([ids[0]], \"red\");\n void zoomToElements([ids[0]]);\n }, [ids]);\n\n useEffect(() => {\n if (ids.length === 0) {\n return;\n }\n const setContext = async () => {\n if (bboxDecorator) {\n await bboxDecorator.setContext(ids[0]);\n setInferredSpatialData(bboxDecorator.getInferredSpatialData());\n }\n };\n void setContext();\n }, [bboxDecorator, ids]);\n\n useEffect(() => {\n if (bboxDecorator && type && inferredSpatialData) {\n inferredSpatialData.has(BboxDimension[type as keyof typeof BboxDimension])\n ? bboxDecorator.drawContext(\n BboxDimension[type as keyof typeof BboxDimension],\n )\n : bboxDecorator.clearContext();\n }\n }, [bboxDecorator, inferredSpatialData, type]);\n\n const onSave = async () => {\n if (!validator.allValid()) {\n showValidationMessage(true);\n return;\n }\n try {\n setIsLoading(true);\n\n property\n ? await mappingClient.updateCalculatedProperty(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n property.id ?? \"\",\n {\n propertyName,\n type,\n },\n )\n : await mappingClient.createCalculatedProperty(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n {\n propertyName,\n type,\n },\n );\n await returnFn(true);\n } catch (error: any) {\n handleError(error.status);\n setIsLoading(false);\n }\n };\n\n const getSpatialData = (value: string) =>\n inferredSpatialData?.has(\n BboxDimension[value as keyof typeof BboxDimension],\n ) && (\n <div>\n {`${inferredSpatialData\n ?.get(BboxDimension[value as keyof typeof BboxDimension])\n ?.toPrecision(4)}m`}\n </div>\n );\n\n return (\n <>\n <WidgetHeader\n title={\n property\n ? `${property?.propertyName ?? \"\"}`\n : \"Create Calculated Property\"\n }\n returnFn={async () => returnFn(false)}\n />\n <div className='calculated-properties-action-container'>\n <Fieldset legend='Calculated Property Details' className='details-form'>\n <Small className='field-legend'>\n Asterisk * indicates mandatory fields.\n </Small>\n <LabeledInput\n value={propertyName}\n required\n name='name'\n label='Name'\n onChange={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"name\");\n }}\n message={validator.message(\"name\", propertyName, NAME_REQUIREMENTS)}\n status={\n validator.message(\"name\", propertyName, NAME_REQUIREMENTS)\n ? \"negative\"\n : undefined\n }\n onBlur={() => {\n validator.showMessageFor(\"name\");\n }}\n onBlurCapture={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"name\");\n }}\n />\n <LabeledSelect<string>\n label='Quantity Type'\n required\n options={[\n { value: \"Length\", label: \"Length\" },\n { value: \"Area\", label: \"Area\" },\n { value: \"Volume\", label: \"Volume\" },\n {\n value: \"BoundingBoxLongestEdgeLength\",\n label: \"Longest Edge Length\",\n },\n {\n value: \"BoundingBoxIntermediateEdgeLength\",\n label: \"Intermediate Edge Length\",\n },\n {\n value: \"BoundingBoxShortestEdgeLength\",\n label: \"Shortest Edge Length\",\n },\n {\n value: \"BoundingBoxDiagonalLength\",\n label: \"Diagonal Length\",\n },\n {\n value: \"BoundingBoxLongestFaceDiagonalLength\",\n label: \"Longest Face Diagonal Length\",\n },\n {\n value: \"BoundingBoxIntermediateFaceDiagonalLength\",\n label: \"Intermediate Face Diagonal Length\",\n },\n {\n value: \"BoundingBoxShortestFaceDiagonalLength\",\n label: \"Shortest Face Diagonal Length\",\n },\n ]}\n value={type}\n onChange={setType}\n itemRenderer={(option: SelectOption<string>) => (\n <MenuItem>\n <div className='gr-cp-menu-item'>\n <div>{option.label}</div>\n {getSpatialData(option.value)}\n </div>\n </MenuItem>\n )}\n selectedItemRenderer={(option: SelectOption<string>) => (\n <div className='select-item'>\n <div>{option.label}</div>\n {getSpatialData(option.value)}\n </div>\n )}\n onShow={() => { }}\n onHide={() => { }}\n />\n </Fieldset>\n </div>\n <ActionPanel\n onSave={onSave}\n onCancel={async () => returnFn(false)}\n isSavingDisabled={!(type && propertyName)}\n isLoading={isLoading}\n />\n </>\n );\n};\n\nexport default CalculatedPropertyAction;\n"]}
@@ -31,11 +31,11 @@ const itwinui_react_1 = require("@itwin/itwinui-react");
31
31
  const react_1 = __importStar(require("react"));
32
32
  const PropertyMenu_1 = require("./PropertyMenu");
33
33
  const DeleteModal_1 = __importDefault(require("./DeleteModal"));
34
- const insights_client_1 = require("@itwin/insights-client");
35
34
  const GroupingMapping_1 = require("./GroupingMapping");
36
35
  const CalculatedPropertyTable = ({ iModelId, mappingId, groupId, setSelectedCalculatedProperty, setGroupModifyView, onCalculatedPropertyModify, isLoadingCalculatedProperties: isLoadingGroupProperties, calculatedProperties, refreshCalculatedProperties, selectedCalculatedProperty, }) => {
37
36
  var _a;
38
37
  const apiContext = react_1.useContext(GroupingMapping_1.ApiContext);
38
+ const mappingClient = react_1.useContext(GroupingMapping_1.MappingClientContext);
39
39
  const [showCalculatedPropertyDeleteModal, setShowCalculatedPropertyDeleteModal,] = react_1.useState(false);
40
40
  const calculatedPropertiesColumns = react_1.useMemo(() => [
41
41
  {
@@ -77,8 +77,7 @@ const CalculatedPropertyTable = ({ iModelId, mappingId, groupId, setSelectedCalc
77
77
  react_1.default.createElement(itwinui_react_1.Table, { data: calculatedProperties, density: 'extra-condensed', columns: calculatedPropertiesColumns, emptyTableContent: 'No Calculated Properties', isSortable: true, isLoading: isLoadingGroupProperties }),
78
78
  react_1.default.createElement(DeleteModal_1.default, { entityName: (_a = selectedCalculatedProperty === null || selectedCalculatedProperty === void 0 ? void 0 : selectedCalculatedProperty.propertyName) !== null && _a !== void 0 ? _a : "", show: showCalculatedPropertyDeleteModal, setShow: setShowCalculatedPropertyDeleteModal, onDelete: async () => {
79
79
  var _a;
80
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
81
- await reportingClientApi.deleteCalculatedProperty(apiContext.accessToken, iModelId, mappingId, groupId, (_a = selectedCalculatedProperty === null || selectedCalculatedProperty === void 0 ? void 0 : selectedCalculatedProperty.id) !== null && _a !== void 0 ? _a : "");
80
+ await mappingClient.deleteCalculatedProperty(apiContext.accessToken, iModelId, mappingId, groupId, (_a = selectedCalculatedProperty === null || selectedCalculatedProperty === void 0 ? void 0 : selectedCalculatedProperty.id) !== null && _a !== void 0 ? _a : "");
82
81
  }, refresh: refreshCalculatedProperties })));
83
82
  };
84
83
  exports.default = CalculatedPropertyTable;
@@ -1 +1 @@
1
- {"version":3,"file":"CalculatedPropertyTable.js","sourceRoot":"","sources":["../../../../src/widget/components/CalculatedPropertyTable.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,oEAKoC;AACpC,wDAM8B;AAC9B,+CAA6D;AAE7D,iDAAkD;AAElD,gEAAwC;AAExC,4DAAyD;AACzD,uDAA+C;AAsB/C,MAAM,uBAAuB,GAAG,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,OAAO,EACP,6BAA6B,EAC7B,kBAAkB,EAClB,0BAA0B,EAC1B,6BAA6B,EAAE,wBAAwB,EACvD,oBAAoB,EACpB,2BAA2B,EAC3B,0BAA0B,GACG,EAAE,EAAE;;IACjC,MAAM,UAAU,GAAG,kBAAU,CAAC,4BAAU,CAAC,CAAC;IAC1C,MAAM,CACJ,iCAAiC,EACjC,oCAAoC,EACrC,GAAG,gBAAQ,CAAU,KAAK,CAAC,CAAC;IAE7B,MAAM,2BAA2B,GAAG,eAAO,CACzC,GAAG,EAAE,CAAC;QACJ;YACE,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP;oBACE,EAAE,EAAE,cAAc;oBAClB,MAAM,EAAE,qBAAqB;oBAC7B,QAAQ,EAAE,cAAc;oBACxB,IAAI,EAAE,CAAC,KAAwC,EAAE,EAAE,CAAC,CAClD,uCACE,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,GAAG,EAAE,CAAC,0BAA0B,CAAC,KAAK,CAAC,IAE/C,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,CAC5B,CACP;iBACF;gBACD;oBACE,EAAE,EAAE,UA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8BAAC,qBAAW,IACV,UAAU,EAAE,MAAA,0BAA0B,aAA1B,0BAA0B,uBAA1B,0BAA0B,CAAE,YAAY,mCAAI,EAAE,EAC1D,IAAI,EAAE,iCAAiC,EACvC,OAAO,EAAE,oCAAoC,EAC7C,QAAQ,EAAE,KAAK,IAAI,EAAE;;gBACnB,MAAM,kBAAkB,GAAG,IAAI,iCAAe,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gBAClE,MAAM,kBAAkB,CAAC,wBAAwB,CAC/C,UAAU,CAAC,WAAW,EACtB,QAAQ,EACR,SAAS,EACT,OAAO,EACP,MAAA,0BAA0B,aAA1B,0BAA0B,uBAA1B,0BAA0B,CAAE,EAAE,mCAAI,EAAE,CACrC,CAAC;YACJ,CAAC,EACD,OAAO,EAAE,2BAA2B,GACpC,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,uBAAuB,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 {\n SvgAdd,\n SvgDelete,\n SvgEdit,\n SvgMore,\n} from \"@itwin/itwinui-icons-react\";\nimport {\n Button,\n DropdownMenu,\n IconButton,\n MenuItem,\n Table,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useMemo, useState } from \"react\";\nimport type { CreateTypeFromInterface } from \"../utils\";\nimport { PropertyMenuView } from \"./PropertyMenu\";\nimport type { CellProps } from \"react-table\";\nimport DeleteModal from \"./DeleteModal\";\nimport type { CalculatedProperty } from \"@itwin/insights-client\";\nimport { ReportingClient } from \"@itwin/insights-client\";\nimport { ApiContext } from \"./GroupingMapping\";\n\nexport type CalculatedPropertyType =\n CreateTypeFromInterface<CalculatedProperty>;\n\ninterface CalculatedPropertyTableProps {\n iModelId: string;\n mappingId: string;\n groupId: string;\n setSelectedCalculatedProperty: React.Dispatch<\n React.SetStateAction<\n CreateTypeFromInterface<CalculatedPropertyType> | undefined\n >\n >;\n setGroupModifyView: React.Dispatch<React.SetStateAction<PropertyMenuView>>;\n onCalculatedPropertyModify: (value: CellProps<CalculatedPropertyType>) => void;\n isLoadingCalculatedProperties: boolean;\n calculatedProperties: CalculatedPropertyType[];\n refreshCalculatedProperties: () => Promise<void>;\n selectedCalculatedProperty?: CalculatedPropertyType;\n}\n\nconst CalculatedPropertyTable = ({\n iModelId,\n mappingId,\n groupId,\n setSelectedCalculatedProperty,\n setGroupModifyView,\n onCalculatedPropertyModify,\n isLoadingCalculatedProperties: isLoadingGroupProperties,\n calculatedProperties,\n refreshCalculatedProperties,\n selectedCalculatedProperty,\n}: CalculatedPropertyTableProps) => {\n const apiContext = useContext(ApiContext);\n const [\n showCalculatedPropertyDeleteModal,\n setShowCalculatedPropertyDeleteModal,\n ] = useState<boolean>(false);\n\n const calculatedPropertiesColumns = useMemo(\n () => [\n {\n Header: \"Table\",\n columns: [\n {\n id: \"propertyName\",\n Header: \"Calculated Property\",\n accessor: \"propertyName\",\n Cell: (value: CellProps<CalculatedPropertyType>) => (\n <div\n className='iui-anchor'\n onClick={() => onCalculatedPropertyModify(value)}\n >\n {value.row.original.propertyName}\n </div>\n ),\n },\n {\n id: \"dropdown\",\n Header: \"\",\n width: 80,\n Cell: (value: CellProps<CalculatedPropertyType>) => {\n return (\n <DropdownMenu\n menuItems={(close: () => void) => [\n <MenuItem\n key={0}\n onClick={() => onCalculatedPropertyModify(value)}\n icon={<SvgEdit />}\n >\n Modify\n </MenuItem>,\n <MenuItem\n key={1}\n onClick={() => {\n setSelectedCalculatedProperty(value.row.original);\n setShowCalculatedPropertyDeleteModal(true);\n close();\n }}\n icon={<SvgDelete />}\n >\n Remove\n </MenuItem>,\n ]}\n >\n <IconButton styleType='borderless'>\n <SvgMore\n style={{\n width: \"16px\",\n height: \"16px\",\n }}\n />\n </IconButton>\n </DropdownMenu>\n );\n },\n },\n ],\n },\n ],\n [onCalculatedPropertyModify, setSelectedCalculatedProperty],\n );\n\n return (\n <>\n <Button\n startIcon={<SvgAdd />}\n styleType='high-visibility'\n onClick={() => {\n setGroupModifyView(PropertyMenuView.ADD_CALCULATED_PROPERTY);\n }}\n >\n Add Calculated Property\n </Button>\n <Table<CalculatedPropertyType>\n data={calculatedProperties}\n density='extra-condensed'\n columns={calculatedPropertiesColumns}\n emptyTableContent='No Calculated Properties'\n isSortable\n isLoading={isLoadingGroupProperties}\n />\n\n <DeleteModal\n entityName={selectedCalculatedProperty?.propertyName ?? \"\"}\n show={showCalculatedPropertyDeleteModal}\n setShow={setShowCalculatedPropertyDeleteModal}\n onDelete={async () => {\n const reportingClientApi = new ReportingClient(apiContext.prefix);\n await reportingClientApi.deleteCalculatedProperty(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n selectedCalculatedProperty?.id ?? \"\",\n );\n }}\n refresh={refreshCalculatedProperties}\n />\n </>\n );\n};\n\nexport default CalculatedPropertyTable;\n"]}
1
+ {"version":3,"file":"CalculatedPropertyTable.js","sourceRoot":"","sources":["../../../../src/widget/components/CalculatedPropertyTable.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,oEAKoC;AACpC,wDAM8B;AAC9B,+CAA6D;AAE7D,iDAAkD;AAElD,gEAAwC;AAExC,uDAAqE;AAkBrE,MAAM,uBAAuB,GAAG,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,OAAO,EACP,6BAA6B,EAC7B,kBAAkB,EAClB,0BAA0B,EAC1B,6BAA6B,EAAE,wBAAwB,EACvD,oBAAoB,EACpB,2BAA2B,EAC3B,0BAA0B,GACG,EAAE,EAAE;;IACjC,MAAM,UAAU,GAAG,kBAAU,CAAC,4BAAU,CAAC,CAAC;IAC1C,MAAM,aAAa,GAAG,kBAAU,CAAC,sCAAoB,CAAC,CAAC;IACvD,MAAM,CACJ,iCAAiC,EACjC,oCAAoC,EACrC,GAAG,gBAAQ,CAAU,KAAK,CAAC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AAC,0BAA0B,EAAE,6BAA6B,CAAC,CAC5D,CAAC;IAEF,OAAO,CACL;QACE,8BAAC,sBAAM,IACL,SAAS,EAAE,8BAAC,4BAAM,OAAG,EACrB,SAAS,EAAC,iBAAiB,EAC3B,OAAO,EAAE,GAAG,EAAE;gBACZ,kBAAkB,CAAC,+BAAgB,CAAC,uBAAuB,CAAC,CAAC;YAC/D,CAAC,8BAGM;QACT,8BAAC,qBAAK,IACJ,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAC,iBAAiB,EACzB,OAAO,EAAE,2BAA2B,EACpC,iBAAiB,EAAC,0BAA0B,EAC5C,UAAU,QACV,SAAS,EAAE,wBAAwB,GACnC;QAEF,8BAAC,qBAAW,IACV,UAAU,EAAE,MAAA,0BAA0B,aAA1B,0BAA0B,uBAA1B,0BAA0B,CAAE,YAAY,mCAAI,EAAE,EAC1D,IAAI,EAAE,iCAAiC,EACvC,OAAO,EAAE,oCAAoC,EAC7C,QAAQ,EAAE,KAAK,IAAI,EAAE;;gBACnB,MAAM,aAAa,CAAC,wBAAwB,CAC1C,UAAU,CAAC,WAAW,EACtB,QAAQ,EACR,SAAS,EACT,OAAO,EACP,MAAA,0BAA0B,aAA1B,0BAA0B,uBAA1B,0BAA0B,CAAE,EAAE,mCAAI,EAAE,CACrC,CAAC;YACJ,CAAC,EACD,OAAO,EAAE,2BAA2B,GACpC,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,uBAAuB,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 {\n SvgAdd,\n SvgDelete,\n SvgEdit,\n SvgMore,\n} from \"@itwin/itwinui-icons-react\";\nimport {\n Button,\n DropdownMenu,\n IconButton,\n MenuItem,\n Table,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useMemo, useState } from \"react\";\nimport type { CreateTypeFromInterface } from \"../utils\";\nimport { PropertyMenuView } from \"./PropertyMenu\";\nimport type { CellProps } from \"react-table\";\nimport DeleteModal from \"./DeleteModal\";\nimport type { CalculatedProperty } from \"@itwin/insights-client\";\nimport { ApiContext, MappingClientContext } from \"./GroupingMapping\";\n\nexport type CalculatedPropertyType =\n CreateTypeFromInterface<CalculatedProperty>;\n\ninterface CalculatedPropertyTableProps {\n iModelId: string;\n mappingId: string;\n groupId: string;\n setSelectedCalculatedProperty: React.Dispatch<React.SetStateAction<CreateTypeFromInterface<CalculatedPropertyType> | undefined>>;\n setGroupModifyView: React.Dispatch<React.SetStateAction<PropertyMenuView>>;\n onCalculatedPropertyModify: (value: CellProps<CalculatedPropertyType>) => void;\n isLoadingCalculatedProperties: boolean;\n calculatedProperties: CalculatedPropertyType[];\n refreshCalculatedProperties: () => Promise<void>;\n selectedCalculatedProperty?: CalculatedPropertyType;\n}\n\nconst CalculatedPropertyTable = ({\n iModelId,\n mappingId,\n groupId,\n setSelectedCalculatedProperty,\n setGroupModifyView,\n onCalculatedPropertyModify,\n isLoadingCalculatedProperties: isLoadingGroupProperties,\n calculatedProperties,\n refreshCalculatedProperties,\n selectedCalculatedProperty,\n}: CalculatedPropertyTableProps) => {\n const apiContext = useContext(ApiContext);\n const mappingClient = useContext(MappingClientContext);\n const [\n showCalculatedPropertyDeleteModal,\n setShowCalculatedPropertyDeleteModal,\n ] = useState<boolean>(false);\n\n const calculatedPropertiesColumns = useMemo(\n () => [\n {\n Header: \"Table\",\n columns: [\n {\n id: \"propertyName\",\n Header: \"Calculated Property\",\n accessor: \"propertyName\",\n Cell: (value: CellProps<CalculatedPropertyType>) => (\n <div\n className='iui-anchor'\n onClick={() => onCalculatedPropertyModify(value)}\n >\n {value.row.original.propertyName}\n </div>\n ),\n },\n {\n id: \"dropdown\",\n Header: \"\",\n width: 80,\n Cell: (value: CellProps<CalculatedPropertyType>) => {\n return (\n <DropdownMenu\n menuItems={(close: () => void) => [\n <MenuItem\n key={0}\n onClick={() => onCalculatedPropertyModify(value)}\n icon={<SvgEdit />}\n >\n Modify\n </MenuItem>,\n <MenuItem\n key={1}\n onClick={() => {\n setSelectedCalculatedProperty(value.row.original);\n setShowCalculatedPropertyDeleteModal(true);\n close();\n }}\n icon={<SvgDelete />}\n >\n Remove\n </MenuItem>,\n ]}\n >\n <IconButton styleType='borderless'>\n <SvgMore\n style={{\n width: \"16px\",\n height: \"16px\",\n }}\n />\n </IconButton>\n </DropdownMenu>\n );\n },\n },\n ],\n },\n ],\n [onCalculatedPropertyModify, setSelectedCalculatedProperty],\n );\n\n return (\n <>\n <Button\n startIcon={<SvgAdd />}\n styleType='high-visibility'\n onClick={() => {\n setGroupModifyView(PropertyMenuView.ADD_CALCULATED_PROPERTY);\n }}\n >\n Add Calculated Property\n </Button>\n <Table<CalculatedPropertyType>\n data={calculatedProperties}\n density='extra-condensed'\n columns={calculatedPropertiesColumns}\n emptyTableContent='No Calculated Properties'\n isSortable\n isLoading={isLoadingGroupProperties}\n />\n\n <DeleteModal\n entityName={selectedCalculatedProperty?.propertyName ?? \"\"}\n show={showCalculatedPropertyDeleteModal}\n setShow={setShowCalculatedPropertyDeleteModal}\n onDelete={async () => {\n await mappingClient.deleteCalculatedProperty(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n selectedCalculatedProperty?.id ?? \"\",\n );\n }}\n refresh={refreshCalculatedProperties}\n />\n </>\n );\n};\n\nexport default CalculatedPropertyTable;\n"]}
@@ -30,12 +30,12 @@ const appui_react_1 = require("@itwin/appui-react");
30
30
  const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
31
31
  const useValidator_1 = __importStar(require("../hooks/useValidator"));
32
32
  const utils_1 = require("./utils");
33
- const insights_client_1 = require("@itwin/insights-client");
34
33
  const GroupingMapping_1 = require("./GroupingMapping");
35
34
  const ConfirmMappingImport = ({ sourceiModelId, selectedMappings, importing, setImporting, setSelectedMappings, backFn, onCancel, onFinish, }) => {
36
35
  var _a;
37
36
  const iModelId = (_a = appui_react_1.useActiveIModelConnection()) === null || _a === void 0 ? void 0 : _a.iModelId;
38
37
  const apiContext = react_1.useContext(GroupingMapping_1.ApiContext);
38
+ const mappingClient = react_1.useContext(GroupingMapping_1.MappingClientContext);
39
39
  const [importCount, setImportCount] = react_1.useState(0);
40
40
  const [currentlyImporting, setCurrentlyImporting] = react_1.useState("");
41
41
  const [validator, showValidationMessage] = useValidator_1.default();
@@ -62,10 +62,9 @@ const ConfirmMappingImport = ({ sourceiModelId, selectedMappings, importing, set
62
62
  }
63
63
  setImporting(true);
64
64
  try {
65
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
66
65
  for (const selectedMapping of selectedMappings) {
67
66
  setCurrentlyImporting((_a = selectedMapping.mappingName) !== null && _a !== void 0 ? _a : "");
68
- await reportingClientApi.copyMapping(apiContext.accessToken, sourceiModelId, (_b = selectedMapping.id) !== null && _b !== void 0 ? _b : "", {
67
+ await mappingClient.copyMapping(apiContext.accessToken, sourceiModelId, (_b = selectedMapping.id) !== null && _b !== void 0 ? _b : "", {
69
68
  targetIModelId: iModelId !== null && iModelId !== void 0 ? iModelId : "",
70
69
  mappingName: (_c = selectedMapping.mappingName) !== null && _c !== void 0 ? _c : "",
71
70
  });
@@ -1 +1 @@
1
- {"version":3,"file":"ConfirmMappingsImport.js","sourceRoot":"","sources":["../../../../src/widget/components/ConfirmMappingsImport.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,wDAM8B;AAC9B,+CAA+D;AAE/D,wCAAsC;AACtC,oDAA+D;AAC/D,oEAAoE;AACpE,sEAAwE;AACxE,mCAAsC;AACtC,4DAAyD;AACzD,uDAA+C;AAa/C,MAAM,oBAAoB,GAAG,CAAC,EAC5B,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,QAAQ,GACkB,EAAE,EAAE;;IAC9B,MAAM,QA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O,CAC5B;gBACN,uCAAK,SAAS,EAAC,YAAY,GAAG,CAC1B,CACP,CAAC,CACE,CACF;QACN,uCAAK,SAAS,EAAC,qBAAqB;YAClC,8BAAC,sBAAM,IAAC,OAAO,EAAE,MAAM,WAAe;YACtC,8BAAC,sBAAM,IAAC,SAAS,EAAC,iBAAiB,EAAC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,QAAQ,EAAE,aAE1D;YACT,8BAAC,sBAAM,IAAC,OAAO,EAAE,QAAQ,aAAiB,CACtC,CACF,CACP,CACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,oBAAoB,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 {\n Button,\n LabeledInput,\n MiddleTextTruncation,\n ProgressLinear,\n Text,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useEffect, useState } from \"react\";\nimport type { MappingType } from \"./Mapping\";\nimport \"./ConfirmMappingsImport.scss\";\nimport { useActiveIModelConnection } from \"@itwin/appui-react\";\nimport { SvgStatusSuccessHollow } from \"@itwin/itwinui-icons-react\";\nimport useValidator, { NAME_REQUIREMENTS } from \"../hooks/useValidator\";\nimport { handleError } from \"./utils\";\nimport { ReportingClient } from \"@itwin/insights-client\";\nimport { ApiContext } from \"./GroupingMapping\";\n\ninterface ConfirmMappingImportProps {\n sourceiModelId: string;\n selectedMappings: MappingType[];\n importing: boolean;\n setImporting: React.Dispatch<React.SetStateAction<boolean>>;\n setSelectedMappings: React.Dispatch<React.SetStateAction<MappingType[]>>;\n backFn: () => void;\n onCancel: () => void;\n onFinish: () => void;\n}\n\nconst ConfirmMappingImport = ({\n sourceiModelId,\n selectedMappings,\n importing,\n setImporting,\n setSelectedMappings,\n backFn,\n onCancel,\n onFinish,\n}: ConfirmMappingImportProps) => {\n const iModelId = useActiveIModelConnection()?.iModelId;\n const apiContext = useContext(ApiContext);\n\n const [importCount, setImportCount] = useState<number>(0);\n const [currentlyImporting, setCurrentlyImporting] = useState<string>(\"\");\n const [validator, showValidationMessage] = useValidator();\n const [errored, setErrored] = useState<boolean>(false);\n\n useEffect(() => {\n setSelectedMappings((selectedMappings) =>\n selectedMappings.map((mapping) => ({\n ...mapping,\n mappingName: `${mapping.mappingName}_Copy`,\n })),\n );\n }, [setSelectedMappings]);\n\n const handleChange = (\n e: React.ChangeEvent<HTMLInputElement>,\n index: number,\n ) => {\n const newState = [...selectedMappings];\n newState[index] = {\n ...newState[index],\n mappingName: e.target.value,\n };\n setSelectedMappings(newState);\n };\n\n const onImport = async () => {\n if (!validator.allValid()) {\n showValidationMessage(true);\n return;\n }\n setImporting(true);\n try {\n const reportingClientApi = new ReportingClient(apiContext.prefix);\n for (const selectedMapping of selectedMappings) {\n setCurrentlyImporting(selectedMapping.mappingName ?? \"\");\n await reportingClientApi.copyMapping(\n apiContext.accessToken,\n sourceiModelId,\n selectedMapping.id ?? \"\",\n {\n targetIModelId: iModelId ?? \"\",\n mappingName: selectedMapping.mappingName ?? \"\",\n },\n );\n setImportCount((importCount) => importCount + 1);\n }\n } catch (error: any) {\n handleError(error);\n setErrored(true);\n }\n };\n\n return (\n <>\n {importing ? (\n <div className='import-progress-container'>\n <div className='import-progress-bar'>\n <div className='import-progress-bar-description'>\n {\n !errored ? importCount !== selectedMappings.length ? (\n <>\n <Text variant='title'>Importing</Text>\n <Text>We are currently importing the mappings.</Text>\n </>\n ) : (\n <>\n <Text variant='title'>Done!</Text>\n <Text>Your mapping(s) are ready.</Text>\n </>\n ) :\n <>\n <Text variant='title'>Error!</Text>\n <Text>Sorry, there was an error importing some or all mappings.</Text>\n </>}\n </div>\n <ProgressLinear\n value={(importCount / selectedMappings.length) * 100}\n labels={\n importCount === selectedMappings.length\n ? [\"Import done!\", <SvgStatusSuccessHollow key='0' />]\n : [\n <>\n <Text>Copying</Text>\n <MiddleTextTruncation text={currentlyImporting} />\n </>,\n `${importCount}/${selectedMappings.length}`,\n ]\n }\n status={\n !errored ?\n importCount === selectedMappings.length ? \"positive\" : undefined : \"negative\"\n }\n />\n </div>\n <div className='import-action-panel'>\n <Button\n disabled={!errored && importCount !== selectedMappings.length}\n onClick={() => {\n setImporting(false);\n setImportCount(0);\n setCurrentlyImporting(\"\");\n setErrored(false);\n }}\n >\n Back\n </Button>\n <Button\n styleType='high-visibility'\n disabled={!errored && importCount !== selectedMappings.length}\n onClick={() => onFinish()}\n >\n Close\n </Button>\n </div>\n </div>\n ) : (\n <div className='rename-confirm-container '>\n <div className='mapping-rename-container'>\n <div className='mapping-row-header-container'>\n <div className='mapping-row'>\n <Text variant='leading'>Mapping </Text>\n <Text variant='leading'>Description</Text>\n </div>\n </div>\n <div className='mapping-row-body'>\n {selectedMappings.map((mapping, index) => (\n <div className='mapping-row-container' key={mapping.id}>\n <div className='mapping-row'>\n <LabeledInput\n value={mapping.mappingName}\n name={`mapping_${mapping.id}`}\n required\n onChange={(event) => {\n handleChange(event, index);\n validator.showMessageFor(`mapping_${mapping.id}`);\n }}\n message={validator.message(\n `mapping_${mapping.id}`,\n mapping.mappingName,\n NAME_REQUIREMENTS,\n )}\n status={\n validator.message(\n `mapping_${mapping.id}`,\n mapping.mappingName,\n NAME_REQUIREMENTS,\n )\n ? \"negative\"\n : undefined\n }\n onBlur={() => {\n validator.showMessageFor(`mapping_${mapping.id}`);\n }}\n onBlurCapture={(event) => {\n handleChange(event, index);\n validator.showMessageFor(`mapping_${mapping.id}`);\n }}\n />\n <div>{mapping.description}</div>\n </div>\n <div className='border-div' />\n </div>\n ))}\n </div>\n </div>\n <div className='import-action-panel'>\n <Button onClick={backFn}>Back</Button>\n <Button styleType='high-visibility' onClick={async () => onImport()}>\n Import\n </Button>\n <Button onClick={onCancel}>Cancel</Button>\n </div>\n </div>\n )}\n </>\n );\n};\n\nexport default ConfirmMappingImport;\n"]}
1
+ {"version":3,"file":"ConfirmMappingsImport.js","sour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CAAC,UAAU;4BACZ,CAAC,CAAC,SAAS,EAEf,MAAM,EAAE,GAAG,EAAE;4BACX,SAAS,CAAC,cAAc,CAAC,WAAW,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;wBACpD,CAAC,EACD,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;4BACvB,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;4BAC3B,SAAS,CAAC,cAAc,CAAC,WAAW,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;wBACpD,CAAC,GACD;oBACF,2CAAM,OAAO,CAAC,WAAW,CAAO,CAC5B;gBACN,uCAAK,SAAS,EAAC,YAAY,GAAG,CAC1B,CACP,CAAC,CACE,CACF;QACN,uCAAK,SAAS,EAAC,qBAAqB;YAClC,8BAAC,sBAAM,IAAC,OAAO,EAAE,MAAM,WAAe;YACtC,8BAAC,sBAAM,IAAC,SAAS,EAAC,iBAAiB,EAAC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,QAAQ,EAAE,aAE1D;YACT,8BAAC,sBAAM,IAAC,OAAO,EAAE,QAAQ,aAAiB,CACtC,CACF,CACP,CACA,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,oBAAoB,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 {\n Button,\n LabeledInput,\n MiddleTextTruncation,\n ProgressLinear,\n Text,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useEffect, useState } from \"react\";\nimport type { MappingType } from \"./Mapping\";\nimport \"./ConfirmMappingsImport.scss\";\nimport { useActiveIModelConnection } from \"@itwin/appui-react\";\nimport { SvgStatusSuccessHollow } from \"@itwin/itwinui-icons-react\";\nimport useValidator, { NAME_REQUIREMENTS } from \"../hooks/useValidator\";\nimport { handleError } from \"./utils\";\nimport { ApiContext, MappingClientContext } from \"./GroupingMapping\";\n\ninterface ConfirmMappingImportProps {\n sourceiModelId: string;\n selectedMappings: MappingType[];\n importing: boolean;\n setImporting: React.Dispatch<React.SetStateAction<boolean>>;\n setSelectedMappings: React.Dispatch<React.SetStateAction<MappingType[]>>;\n backFn: () => void;\n onCancel: () => void;\n onFinish: () => void;\n}\n\nconst ConfirmMappingImport = ({\n sourceiModelId,\n selectedMappings,\n importing,\n setImporting,\n setSelectedMappings,\n backFn,\n onCancel,\n onFinish,\n}: ConfirmMappingImportProps) => {\n const iModelId = useActiveIModelConnection()?.iModelId;\n const apiContext = useContext(ApiContext);\n const mappingClient = useContext(MappingClientContext);\n\n const [importCount, setImportCount] = useState<number>(0);\n const [currentlyImporting, setCurrentlyImporting] = useState<string>(\"\");\n const [validator, showValidationMessage] = useValidator();\n const [errored, setErrored] = useState<boolean>(false);\n\n useEffect(() => {\n setSelectedMappings((selectedMappings) =>\n selectedMappings.map((mapping) => ({\n ...mapping,\n mappingName: `${mapping.mappingName}_Copy`,\n })),\n );\n }, [setSelectedMappings]);\n\n const handleChange = (\n e: React.ChangeEvent<HTMLInputElement>,\n index: number,\n ) => {\n const newState = [...selectedMappings];\n newState[index] = {\n ...newState[index],\n mappingName: e.target.value,\n };\n setSelectedMappings(newState);\n };\n\n const onImport = async () => {\n if (!validator.allValid()) {\n showValidationMessage(true);\n return;\n }\n setImporting(true);\n try {\n for (const selectedMapping of selectedMappings) {\n setCurrentlyImporting(selectedMapping.mappingName ?? \"\");\n await mappingClient.copyMapping(\n apiContext.accessToken,\n sourceiModelId,\n selectedMapping.id ?? \"\",\n {\n targetIModelId: iModelId ?? \"\",\n mappingName: selectedMapping.mappingName ?? \"\",\n },\n );\n setImportCount((importCount) => importCount + 1);\n }\n } catch (error: any) {\n handleError(error);\n setErrored(true);\n }\n };\n\n return (\n <>\n {importing ? (\n <div className='import-progress-container'>\n <div className='import-progress-bar'>\n <div className='import-progress-bar-description'>\n {\n !errored ? importCount !== selectedMappings.length ? (\n <>\n <Text variant='title'>Importing</Text>\n <Text>We are currently importing the mappings.</Text>\n </>\n ) : (\n <>\n <Text variant='title'>Done!</Text>\n <Text>Your mapping(s) are ready.</Text>\n </>\n ) :\n <>\n <Text variant='title'>Error!</Text>\n <Text>Sorry, there was an error importing some or all mappings.</Text>\n </>}\n </div>\n <ProgressLinear\n value={(importCount / selectedMappings.length) * 100}\n labels={\n importCount === selectedMappings.length\n ? [\"Import done!\", <SvgStatusSuccessHollow key='0' />]\n : [\n <>\n <Text>Copying</Text>\n <MiddleTextTruncation text={currentlyImporting} />\n </>,\n `${importCount}/${selectedMappings.length}`,\n ]\n }\n status={\n !errored ?\n importCount === selectedMappings.length ? \"positive\" : undefined : \"negative\"\n }\n />\n </div>\n <div className='import-action-panel'>\n <Button\n disabled={!errored && importCount !== selectedMappings.length}\n onClick={() => {\n setImporting(false);\n setImportCount(0);\n setCurrentlyImporting(\"\");\n setErrored(false);\n }}\n >\n Back\n </Button>\n <Button\n styleType='high-visibility'\n disabled={!errored && importCount !== selectedMappings.length}\n onClick={() => onFinish()}\n >\n Close\n </Button>\n </div>\n </div>\n ) : (\n <div className='rename-confirm-container '>\n <div className='mapping-rename-container'>\n <div className='mapping-row-header-container'>\n <div className='mapping-row'>\n <Text variant='leading'>Mapping </Text>\n <Text variant='leading'>Description</Text>\n </div>\n </div>\n <div className='mapping-row-body'>\n {selectedMappings.map((mapping, index) => (\n <div className='mapping-row-container' key={mapping.id}>\n <div className='mapping-row'>\n <LabeledInput\n value={mapping.mappingName}\n name={`mapping_${mapping.id}`}\n required\n onChange={(event) => {\n handleChange(event, index);\n validator.showMessageFor(`mapping_${mapping.id}`);\n }}\n message={validator.message(\n `mapping_${mapping.id}`,\n mapping.mappingName,\n NAME_REQUIREMENTS,\n )}\n status={\n validator.message(\n `mapping_${mapping.id}`,\n mapping.mappingName,\n NAME_REQUIREMENTS,\n )\n ? \"negative\"\n : undefined\n }\n onBlur={() => {\n validator.showMessageFor(`mapping_${mapping.id}`);\n }}\n onBlurCapture={(event) => {\n handleChange(event, index);\n validator.showMessageFor(`mapping_${mapping.id}`);\n }}\n />\n <div>{mapping.description}</div>\n </div>\n <div className='border-div' />\n </div>\n ))}\n </div>\n </div>\n <div className='import-action-panel'>\n <Button onClick={backFn}>Back</Button>\n <Button styleType='high-visibility' onClick={async () => onImport()}>\n Import\n </Button>\n <Button onClick={onCancel}>Cancel</Button>\n </div>\n </div>\n )}\n </>\n );\n};\n\nexport default ConfirmMappingImport;\n"]}
@@ -35,18 +35,18 @@ require("./CalculatedPropertyAction.scss");
35
35
  require("./CustomCalculationAction.scss");
36
36
  const GroupPropertyAction_1 = require("./GroupPropertyAction");
37
37
  const useFormulaValidation_1 = require("../hooks/useFormulaValidation");
38
- const insights_client_1 = require("@itwin/insights-client");
39
38
  const GroupingMapping_1 = require("./GroupingMapping");
40
39
  const CustomCalculationAction = ({ iModelId, mappingId, groupId, properties, customCalculation, returnFn, }) => {
41
40
  var _a, _b, _c, _d;
42
41
  const apiContext = react_1.useContext(GroupingMapping_1.ApiContext);
42
+ const mappingClient = react_1.useContext(GroupingMapping_1.MappingClientContext);
43
43
  const [propertyName, setPropertyName] = react_1.useState((_a = customCalculation === null || customCalculation === void 0 ? void 0 : customCalculation.propertyName) !== null && _a !== void 0 ? _a : "");
44
44
  const [formula, setFormula] = react_1.useState((_b = customCalculation === null || customCalculation === void 0 ? void 0 : customCalculation.formula) !== null && _b !== void 0 ? _b : "");
45
45
  const [quantityType, setQuantityType] = react_1.useState((_c = customCalculation === null || customCalculation === void 0 ? void 0 : customCalculation.quantityType) !== null && _c !== void 0 ? _c : "Undefined");
46
46
  const [isLoading, setIsLoading] = react_1.useState(false);
47
47
  const [formulaErrorMessage, setFormulaErrorMessage] = react_1.useState("");
48
48
  const [validator, showValidationMessage] = useValidator_1.default();
49
- const { isValid, forceValidation } = useFormulaValidation_1.useFormulaValidation(formula, properties, setFormulaErrorMessage);
49
+ const { isValid, forceValidation } = useFormulaValidation_1.useFormulaValidation(propertyName.toLowerCase(), formula, properties, setFormulaErrorMessage);
50
50
  const onSave = async () => {
51
51
  var _a;
52
52
  if (!validator.allValid()) {
@@ -58,14 +58,13 @@ const CustomCalculationAction = ({ iModelId, mappingId, groupId, properties, cus
58
58
  }
59
59
  try {
60
60
  setIsLoading(true);
61
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
62
61
  customCalculation
63
- ? await reportingClientApi.updateCustomCalculation(apiContext.accessToken, iModelId, mappingId, groupId, (_a = customCalculation.id) !== null && _a !== void 0 ? _a : "", {
62
+ ? await mappingClient.updateCustomCalculation(apiContext.accessToken, iModelId, mappingId, groupId, (_a = customCalculation.id) !== null && _a !== void 0 ? _a : "", {
64
63
  propertyName,
65
64
  formula,
66
65
  quantityType,
67
66
  })
68
- : await reportingClientApi.createCustomCalculation(apiContext.accessToken, iModelId, mappingId, groupId, {
67
+ : await mappingClient.createCustomCalculation(apiContext.accessToken, iModelId, mappingId, groupId, {
69
68
  propertyName,
70
69
  formula,
71
70
  quantityType,
@@ -1 +1 @@
1
- {"version":3,"file":"CustomCalculationAction.js","sourceRoot":"","sources":["../../../../src/widget/components/CustomCalculationAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,wDAM8B;AAC9B,+CAAoD;AACpD,gEAAwC;AACxC,sEAAwE;AACxE,mCAAoD;AACpD,2CAAyC;AAEzC,0CAAwC;AACxC,+DAAsE;AACtE,wEAAqE;AAErE,4DAAyD;AACzD,uDAA+C;AAW/C,MAAM,uBAAuB,GAAG,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,QAAQ,GACsB,EAAE,EAAE;;IAClC,MAAM,UAAU,GAAG,kBAAU,CAAC,4BAAU,CAAC,CAAC;IAC1C,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,gBAAQ,CAC9C,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iB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,CAAC,GACjB,CACO,CACP;QACN,8BAAC,qBAAW,IACV,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EACrC,gBAAgB,EAAE,CAAC,CAAC,OAAO,IAAI,YAAY,IAAI,OAAO,CAAC,EACvD,SAAS,EAAE,SAAS,GACpB,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,uBAAuB,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 {\n Fieldset,\n LabeledInput,\n LabeledSelect,\n LabeledTextarea,\n Small,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useState } from \"react\";\nimport ActionPanel from \"./ActionPanel\";\nimport useValidator, { NAME_REQUIREMENTS } from \"../hooks/useValidator\";\nimport { handleError, WidgetHeader } from \"./utils\";\nimport \"./CalculatedPropertyAction.scss\";\nimport type { CustomCalculationType } from \"./CustomCalculationTable\";\nimport \"./CustomCalculationAction.scss\";\nimport { quantityTypesSelectionOptions } from \"./GroupPropertyAction\";\nimport { useFormulaValidation } from \"../hooks/useFormulaValidation\";\nimport type { PropertyMap } from \"../../formula/Types\";\nimport { ReportingClient } from \"@itwin/insights-client\";\nimport { ApiContext } from \"./GroupingMapping\";\n\ninterface CalculatedPropertyActionProps {\n iModelId: string;\n mappingId: string;\n groupId: string;\n properties: PropertyMap;\n customCalculation?: CustomCalculationType;\n returnFn: (modified: boolean) => Promise<void>;\n}\n\nconst CustomCalculationAction = ({\n iModelId,\n mappingId,\n groupId,\n properties,\n customCalculation,\n returnFn,\n}: CalculatedPropertyActionProps) => {\n const apiContext = useContext(ApiContext);\n const [propertyName, setPropertyName] = useState<string>(\n customCalculation?.propertyName ?? \"\",\n );\n const [formula, setFormula] = useState<string>(\n customCalculation?.formula ?? \"\",\n );\n const [quantityType, setQuantityType] = useState<string>(customCalculation?.quantityType ?? \"Undefined\");\n const [isLoading, setIsLoading] = useState<boolean>(false);\n const [formulaErrorMessage, setFormulaErrorMessage] = useState<string>(\"\");\n const [validator, showValidationMessage] = useValidator();\n const { isValid, forceValidation } = useFormulaValidation(formula, properties, setFormulaErrorMessage);\n\n const onSave = async () => {\n if (!validator.allValid()) {\n showValidationMessage(true);\n return;\n }\n if (!forceValidation()) {\n return;\n }\n try {\n setIsLoading(true);\n const reportingClientApi = new ReportingClient(apiContext.prefix);\n\n customCalculation\n ? await reportingClientApi.updateCustomCalculation(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n customCalculation.id ?? \"\",\n {\n propertyName,\n formula,\n quantityType,\n }\n )\n : await reportingClientApi.createCustomCalculation(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n {\n propertyName,\n formula,\n quantityType,\n }\n );\n await returnFn(true);\n } catch (error: any) {\n // error instanceof Response refuses to be true when it should be.\n if (error.status === 422) {\n error = error as Response;\n const erroredResponse = await error.json();\n if (\n erroredResponse.error.code === \"InvalidInsightsRequest\" &&\n erroredResponse.error.target === \"formula\"\n ) {\n setFormulaErrorMessage(erroredResponse.error.message);\n }\n } else {\n handleError(error.status);\n }\n setIsLoading(false);\n }\n };\n\n return (\n <>\n <WidgetHeader\n title={\n customCalculation\n ? `${customCalculation?.propertyName ?? \"\"}`\n : \"Create Custom Calculation\"\n }\n returnFn={async () => returnFn(false)}\n />\n <div className='custom-calculation-action-container'>\n <Fieldset legend='Custom Calculation Details' className='details-form'>\n <Small className='field-legend'>\n Asterisk * indicates mandatory fields.\n </Small>\n <LabeledInput\n value={propertyName}\n required\n name='name'\n label='Name'\n disabled={isLoading}\n onChange={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"name\");\n }}\n message={validator.message(\"name\", propertyName, NAME_REQUIREMENTS)}\n status={\n validator.message(\"name\", propertyName, NAME_REQUIREMENTS)\n ? \"negative\"\n : undefined\n }\n onBlur={() => {\n validator.showMessageFor(\"name\");\n }}\n onBlurCapture={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"name\");\n }}\n />\n <LabeledTextarea\n value={formula}\n required\n name='formula'\n label='Formula'\n disabled={isLoading}\n onChange={(event) => {\n setFormula(event.target.value);\n }}\n message={formulaErrorMessage}\n status={formulaErrorMessage ? \"negative\" : undefined}\n />\n <LabeledSelect<string>\n label='Quantity Type'\n disabled={isLoading}\n options={quantityTypesSelectionOptions}\n value={quantityType}\n onChange={setQuantityType}\n onShow={() => { }}\n onHide={() => { }}\n />\n </Fieldset>\n </div>\n <ActionPanel\n onSave={onSave}\n onCancel={async () => returnFn(false)}\n isSavingDisabled={!(formula && propertyName && isValid)}\n isLoading={isLoading}\n />\n </>\n );\n};\n\nexport default CustomCalculationAction;\n"]}
1
+ {"version":3,"file":"CustomCalculationAction.js","sourceRoot":"","sources":["../../../../src/widget/components/CustomCalculationAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,wDAM8B;AAC9B,+CAAoD;AACpD,gEAAwC;AACxC,sEAAwE;AACxE,mCAAoD;AACpD,2CAAyC;AAEzC,0CAAwC;AACxC,+DAAsE;AACtE,wEAAqE;AAErE,uDAAqE;AAWrE,MAAM,uBAAuB,GAAG,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,QAAQ,GACsB,EAAE,EAAE;;IAClC,MAAM,UAAU,GAAG,kBAAU,CAAC,4BAAU,CAAC,CAAC;IAC1C,MAAM,aAAa,GAAG,kBAAU,CAAC,sCAAoB,CAAC,CAAC;IACvD,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,gBAAQ,CAC9C,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,YAAY,mCAAI,EAAE,CACtC,CAAC;IACF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,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,EACrC,gBAAgB,EAAE,CAAC,CAAC,OAAO,IAAI,YAAY,IAAI,OAAO,CAAC,EACvD,SAAS,EAAE,SAAS,GACpB,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,uBAAuB,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 {\n Fieldset,\n LabeledInput,\n LabeledSelect,\n LabeledTextarea,\n Small,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useState } from \"react\";\nimport ActionPanel from \"./ActionPanel\";\nimport useValidator, { NAME_REQUIREMENTS } from \"../hooks/useValidator\";\nimport { handleError, WidgetHeader } from \"./utils\";\nimport \"./CalculatedPropertyAction.scss\";\nimport type { CustomCalculationType } from \"./CustomCalculationTable\";\nimport \"./CustomCalculationAction.scss\";\nimport { quantityTypesSelectionOptions } from \"./GroupPropertyAction\";\nimport { useFormulaValidation } from \"../hooks/useFormulaValidation\";\nimport type { PropertyMap } from \"../../formula/Types\";\nimport { ApiContext, MappingClientContext } from \"./GroupingMapping\";\n\ninterface CalculatedPropertyActionProps {\n iModelId: string;\n mappingId: string;\n groupId: string;\n properties: PropertyMap;\n customCalculation?: CustomCalculationType;\n returnFn: (modified: boolean) => Promise<void>;\n}\n\nconst CustomCalculationAction = ({\n iModelId,\n mappingId,\n groupId,\n properties,\n customCalculation,\n returnFn,\n}: CalculatedPropertyActionProps) => {\n const apiContext = useContext(ApiContext);\n const mappingClient = useContext(MappingClientContext);\n const [propertyName, setPropertyName] = useState<string>(\n customCalculation?.propertyName ?? \"\",\n );\n const [formula, setFormula] = useState<string>(\n customCalculation?.formula ?? \"\",\n );\n const [quantityType, setQuantityType] = useState<string>(customCalculation?.quantityType ?? \"Undefined\");\n const [isLoading, setIsLoading] = useState<boolean>(false);\n const [formulaErrorMessage, setFormulaErrorMessage] = useState<string>(\"\");\n const [validator, showValidationMessage] = useValidator();\n const { isValid, forceValidation } = useFormulaValidation(propertyName.toLowerCase(), formula, properties, setFormulaErrorMessage);\n\n const onSave = async () => {\n if (!validator.allValid()) {\n showValidationMessage(true);\n return;\n }\n if (!forceValidation()) {\n return;\n }\n try {\n setIsLoading(true);\n\n customCalculation\n ? await mappingClient.updateCustomCalculation(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n customCalculation.id ?? \"\",\n {\n propertyName,\n formula,\n quantityType,\n }\n )\n : await mappingClient.createCustomCalculation(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n {\n propertyName,\n formula,\n quantityType,\n }\n );\n await returnFn(true);\n } catch (error: any) {\n // error instanceof Response refuses to be true when it should be.\n if (error.status === 422) {\n error = error as Response;\n const erroredResponse = await error.json();\n if (\n erroredResponse.error.code === \"InvalidInsightsRequest\" &&\n erroredResponse.error.target === \"formula\"\n ) {\n setFormulaErrorMessage(erroredResponse.error.message);\n }\n } else {\n handleError(error.status);\n }\n setIsLoading(false);\n }\n };\n\n return (\n <>\n <WidgetHeader\n title={\n customCalculation\n ? `${customCalculation?.propertyName ?? \"\"}`\n : \"Create Custom Calculation\"\n }\n returnFn={async () => returnFn(false)}\n />\n <div className='custom-calculation-action-container'>\n <Fieldset legend='Custom Calculation Details' className='details-form'>\n <Small className='field-legend'>\n Asterisk * indicates mandatory fields.\n </Small>\n <LabeledInput\n value={propertyName}\n required\n name='name'\n label='Name'\n disabled={isLoading}\n onChange={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"name\");\n }}\n message={validator.message(\"name\", propertyName, NAME_REQUIREMENTS)}\n status={\n validator.message(\"name\", propertyName, NAME_REQUIREMENTS)\n ? \"negative\"\n : undefined\n }\n onBlur={() => {\n validator.showMessageFor(\"name\");\n }}\n onBlurCapture={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"name\");\n }}\n />\n <LabeledTextarea\n value={formula}\n required\n name='formula'\n label='Formula'\n disabled={isLoading}\n onChange={(event) => {\n setFormula(event.target.value);\n }}\n message={formulaErrorMessage}\n status={formulaErrorMessage ? \"negative\" : undefined}\n />\n <LabeledSelect<string>\n label='Quantity Type'\n disabled={isLoading}\n options={quantityTypesSelectionOptions}\n value={quantityType}\n onChange={setQuantityType}\n onShow={() => { }}\n onHide={() => { }}\n />\n </Fieldset>\n </div>\n <ActionPanel\n onSave={onSave}\n onCancel={async () => returnFn(false)}\n isSavingDisabled={!(formula && propertyName && isValid)}\n isLoading={isLoading}\n />\n </>\n );\n};\n\nexport default CustomCalculationAction;\n"]}
@@ -31,11 +31,11 @@ const itwinui_react_1 = require("@itwin/itwinui-react");
31
31
  const react_1 = __importStar(require("react"));
32
32
  const PropertyMenu_1 = require("./PropertyMenu");
33
33
  const DeleteModal_1 = __importDefault(require("./DeleteModal"));
34
- const insights_client_1 = require("@itwin/insights-client");
35
34
  const GroupingMapping_1 = require("./GroupingMapping");
36
35
  const CustomCalculationTable = ({ iModelId, mappingId, groupId, setSelectedCustomCalculation, setGroupModifyView, onCustomCalculationModify, isLoadingCustomCalculations, customCalculations, refreshCustomCalculations, selectedCustomCalculation, }) => {
37
36
  var _a;
38
37
  const apiContext = react_1.useContext(GroupingMapping_1.ApiContext);
38
+ const mappingClient = react_1.useContext(GroupingMapping_1.MappingClientContext);
39
39
  const [showCustomCalculationDeleteModal, setShowCustomCalculationDeleteModal,] = react_1.useState(false);
40
40
  const CustomCalculationsColumns = react_1.useMemo(() => [
41
41
  {
@@ -82,8 +82,7 @@ const CustomCalculationTable = ({ iModelId, mappingId, groupId, setSelectedCusto
82
82
  react_1.default.createElement(itwinui_react_1.Table, { data: customCalculations, density: 'extra-condensed', columns: CustomCalculationsColumns, emptyTableContent: 'No Custom Calculations', isSortable: true, isLoading: isLoadingCustomCalculations }),
83
83
  react_1.default.createElement(DeleteModal_1.default, { entityName: (_a = selectedCustomCalculation === null || selectedCustomCalculation === void 0 ? void 0 : selectedCustomCalculation.propertyName) !== null && _a !== void 0 ? _a : "", show: showCustomCalculationDeleteModal, setShow: setShowCustomCalculationDeleteModal, onDelete: async () => {
84
84
  var _a;
85
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
86
- await reportingClientApi.deleteCustomCalculation(apiContext.accessToken, iModelId, mappingId, groupId, (_a = selectedCustomCalculation === null || selectedCustomCalculation === void 0 ? void 0 : selectedCustomCalculation.id) !== null && _a !== void 0 ? _a : "");
85
+ await mappingClient.deleteCustomCalculation(apiContext.accessToken, iModelId, mappingId, groupId, (_a = selectedCustomCalculation === null || selectedCustomCalculation === void 0 ? void 0 : selectedCustomCalculation.id) !== null && _a !== void 0 ? _a : "");
87
86
  }, refresh: refreshCustomCalculations })));
88
87
  };
89
88
  exports.default = CustomCalculationTable;
@@ -1 +1 @@
1
- {"version":3,"file":"CustomCalculationTable.js","sourceRoot":"","sources":["../../../../src/widget/components/CustomCalculationTable.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,oEAKoC;AACpC,wDAM8B;AAC9B,+CAA6D;AAE7D,iDAAkD;AAElD,gEAAwC;AAExC,4DAAyD;AACzD,uDAA+C;AAsB/C,MAAM,sBAAsB,GAAG,CAAC,EAC9B,QAAQ,EACR,SAAS,EACT,OAAO,EACP,4BAA4B,EAC5B,kBAAkB,EAClB,yBAAyB,EACzB,2BAA2B,EAC3B,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,GACG,EAAE,EAAE;;IAChC,MAAM,UAAU,GAAG,kBAAU,CAAC,4BAAU,CAAC,CAAC;IAC1C,MAAM,CACJ,gCAAgC,EAChC,mCAAmC,EACpC,GAAG,gBAAQ,CAAU,KAAK,CAAC,CAAC;IAE7B,MAAM,yBAAyB,GAAG,eAAO,CACvC,GAAG,EAAE,CAAC;QACJ;YACE,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP;oBACE,EAAE,EAAE,cAAc;oBAClB,MAAM,EAAE,oBAAoB;oBAC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ACL,SAAS,EAAE,8BAAC,4BAAM,OAAG,EACrB,SAAS,EAAC,iBAAiB,EAC3B,OAAO,EAAE,GAAG,EAAE;gBACZ,kBAAkB,CAAC,+BAAgB,CAAC,sBAAsB,CAAC,CAAC;YAC9D,CAAC,6BAGM;QACT,8BAAC,qBAAK,IACJ,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAC,iBAAiB,EACzB,OAAO,EAAE,yBAAyB,EAClC,iBAAiB,EAAC,wBAAwB,EAC1C,UAAU,QACV,SAAS,EAAE,2BAA2B,GACtC;QAEF,8BAAC,qBAAW,IACV,UAAU,EAAE,MAAA,yBAAyB,aAAzB,yBAAyB,uBAAzB,yBAAyB,CAAE,YAAY,mCAAI,EAAE,EACzD,IAAI,EAAE,gCAAgC,EACtC,OAAO,EAAE,mCAAmC,EAC5C,QAAQ,EAAE,KAAK,IAAI,EAAE;;gBACnB,MAAM,kBAAkB,GAAG,IAAI,iCAAe,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gBAClE,MAAM,kBAAkB,CAAC,uBAAuB,CAC9C,UAAU,CAAC,WAAW,EACtB,QAAQ,EACR,SAAS,EACT,OAAO,EACP,MAAA,yBAAyB,aAAzB,yBAAyB,uBAAzB,yBAAyB,CAAE,EAAE,mCAAI,EAAE,CACpC,CAAC;YACJ,CAAC,EACD,OAAO,EAAE,yBAAyB,GAClC,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,sBAAsB,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 {\n SvgAdd,\n SvgDelete,\n SvgEdit,\n SvgMore,\n} from \"@itwin/itwinui-icons-react\";\nimport {\n Button,\n DropdownMenu,\n IconButton,\n MenuItem,\n Table,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useMemo, useState } from \"react\";\nimport type { CreateTypeFromInterface } from \"../utils\";\nimport { PropertyMenuView } from \"./PropertyMenu\";\nimport type { CellProps } from \"react-table\";\nimport DeleteModal from \"./DeleteModal\";\nimport type { CustomCalculation } from \"@itwin/insights-client\";\nimport { ReportingClient } from \"@itwin/insights-client\";\nimport { ApiContext } from \"./GroupingMapping\";\n\nexport type CustomCalculationType =\n CreateTypeFromInterface<CustomCalculation>;\n\ninterface CustomCalculationTableProps {\n iModelId: string;\n mappingId: string;\n groupId: string;\n setSelectedCustomCalculation: React.Dispatch<\n React.SetStateAction<\n CreateTypeFromInterface<CustomCalculationType> | undefined\n >\n >;\n setGroupModifyView: React.Dispatch<React.SetStateAction<PropertyMenuView>>;\n onCustomCalculationModify: (value: CellProps<CustomCalculationType>) => void;\n isLoadingCustomCalculations: boolean;\n customCalculations: CustomCalculationType[];\n refreshCustomCalculations: () => Promise<void>;\n selectedCustomCalculation?: CustomCalculationType;\n}\n\nconst CustomCalculationTable = ({\n iModelId,\n mappingId,\n groupId,\n setSelectedCustomCalculation,\n setGroupModifyView,\n onCustomCalculationModify,\n isLoadingCustomCalculations,\n customCalculations,\n refreshCustomCalculations,\n selectedCustomCalculation,\n}: CustomCalculationTableProps) => {\n const apiContext = useContext(ApiContext);\n const [\n showCustomCalculationDeleteModal,\n setShowCustomCalculationDeleteModal,\n ] = useState<boolean>(false);\n\n const CustomCalculationsColumns = useMemo(\n () => [\n {\n Header: \"Table\",\n columns: [\n {\n id: \"propertyName\",\n Header: \"Custom Calculation\",\n accessor: \"propertyName\",\n Cell: (value: CellProps<CustomCalculationType>) => (\n <div\n className='iui-anchor'\n onClick={() => onCustomCalculationModify(value)}\n >\n {value.row.original.propertyName}\n </div>\n ),\n },\n {\n id: \"formula\",\n Header: \"Formula\",\n accessor: \"formula\",\n },\n {\n id: \"dropdown\",\n Header: \"\",\n width: 80,\n Cell: (value: CellProps<CustomCalculationType>) => {\n return (\n <DropdownMenu\n menuItems={(close: () => void) => [\n <MenuItem\n key={0}\n onClick={() => onCustomCalculationModify(value)}\n icon={<SvgEdit />}\n >\n Modify\n </MenuItem>,\n <MenuItem\n key={1}\n onClick={() => {\n setSelectedCustomCalculation(value.row.original);\n setShowCustomCalculationDeleteModal(true);\n close();\n }}\n icon={<SvgDelete />}\n >\n Remove\n </MenuItem>,\n ]}\n >\n <IconButton styleType='borderless'>\n <SvgMore\n style={{\n width: \"16px\",\n height: \"16px\",\n }}\n />\n </IconButton>\n </DropdownMenu>\n );\n },\n },\n ],\n },\n ],\n [onCustomCalculationModify, setSelectedCustomCalculation],\n );\n\n return (\n <>\n <Button\n startIcon={<SvgAdd />}\n styleType='high-visibility'\n onClick={() => {\n setGroupModifyView(PropertyMenuView.ADD_CUSTOM_CALCULATION);\n }}\n >\n Add Custom Calculation\n </Button>\n <Table<CustomCalculationType>\n data={customCalculations}\n density='extra-condensed'\n columns={CustomCalculationsColumns}\n emptyTableContent='No Custom Calculations'\n isSortable\n isLoading={isLoadingCustomCalculations}\n />\n\n <DeleteModal\n entityName={selectedCustomCalculation?.propertyName ?? \"\"}\n show={showCustomCalculationDeleteModal}\n setShow={setShowCustomCalculationDeleteModal}\n onDelete={async () => {\n const reportingClientApi = new ReportingClient(apiContext.prefix);\n await reportingClientApi.deleteCustomCalculation(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n selectedCustomCalculation?.id ?? \"\",\n );\n }}\n refresh={refreshCustomCalculations}\n />\n </>\n );\n};\n\nexport default CustomCalculationTable;\n"]}
1
+ {"version":3,"file":"CustomCalculationTable.js","sourceRoot":"","sources":["../../../../src/widget/components/CustomCalculationTable.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,oEAKoC;AACpC,wDAM8B;AAC9B,+CAA6D;AAE7D,iDAAkD;AAElD,gEAAwC;AAExC,uDAAqE;AAkBrE,MAAM,sBAAsB,GAAG,CAAC,EAC9B,QAAQ,EACR,SAAS,EACT,OAAO,EACP,4BAA4B,EAC5B,kBAAkB,EA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ACJ,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,sBAAsB,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 {\n SvgAdd,\n SvgDelete,\n SvgEdit,\n SvgMore,\n} from \"@itwin/itwinui-icons-react\";\nimport {\n Button,\n DropdownMenu,\n IconButton,\n MenuItem,\n Table,\n} from \"@itwin/itwinui-react\";\nimport React, { useContext, useMemo, useState } from \"react\";\nimport type { CreateTypeFromInterface } from \"../utils\";\nimport { PropertyMenuView } from \"./PropertyMenu\";\nimport type { CellProps } from \"react-table\";\nimport DeleteModal from \"./DeleteModal\";\nimport type { CustomCalculation } from \"@itwin/insights-client\";\nimport { ApiContext, MappingClientContext } from \"./GroupingMapping\";\n\nexport type CustomCalculationType =\n CreateTypeFromInterface<CustomCalculation>;\n\ninterface CustomCalculationTableProps {\n iModelId: string;\n mappingId: string;\n groupId: string;\n setSelectedCustomCalculation: React.Dispatch<React.SetStateAction<CreateTypeFromInterface<CustomCalculationType> | undefined>>;\n setGroupModifyView: React.Dispatch<React.SetStateAction<PropertyMenuView>>;\n onCustomCalculationModify: (value: CellProps<CustomCalculationType>) => void;\n isLoadingCustomCalculations: boolean;\n customCalculations: CustomCalculationType[];\n refreshCustomCalculations: () => Promise<void>;\n selectedCustomCalculation?: CustomCalculationType;\n}\n\nconst CustomCalculationTable = ({\n iModelId,\n mappingId,\n groupId,\n setSelectedCustomCalculation,\n setGroupModifyView,\n onCustomCalculationModify,\n isLoadingCustomCalculations,\n customCalculations,\n refreshCustomCalculations,\n selectedCustomCalculation,\n}: CustomCalculationTableProps) => {\n const apiContext = useContext(ApiContext);\n const mappingClient = useContext(MappingClientContext);\n const [\n showCustomCalculationDeleteModal,\n setShowCustomCalculationDeleteModal,\n ] = useState<boolean>(false);\n\n const CustomCalculationsColumns = useMemo(\n () => [\n {\n Header: \"Table\",\n columns: [\n {\n id: \"propertyName\",\n Header: \"Custom Calculation\",\n accessor: \"propertyName\",\n Cell: (value: CellProps<CustomCalculationType>) => (\n <div\n className='iui-anchor'\n onClick={() => onCustomCalculationModify(value)}\n >\n {value.row.original.propertyName}\n </div>\n ),\n },\n {\n id: \"formula\",\n Header: \"Formula\",\n accessor: \"formula\",\n },\n {\n id: \"dropdown\",\n Header: \"\",\n width: 80,\n Cell: (value: CellProps<CustomCalculationType>) => {\n return (\n <DropdownMenu\n menuItems={(close: () => void) => [\n <MenuItem\n key={0}\n onClick={() => onCustomCalculationModify(value)}\n icon={<SvgEdit />}\n >\n Modify\n </MenuItem>,\n <MenuItem\n key={1}\n onClick={() => {\n setSelectedCustomCalculation(value.row.original);\n setShowCustomCalculationDeleteModal(true);\n close();\n }}\n icon={<SvgDelete />}\n >\n Remove\n </MenuItem>,\n ]}\n >\n <IconButton styleType='borderless'>\n <SvgMore\n style={{\n width: \"16px\",\n height: \"16px\",\n }}\n />\n </IconButton>\n </DropdownMenu>\n );\n },\n },\n ],\n },\n ],\n [onCustomCalculationModify, setSelectedCustomCalculation],\n );\n\n return (\n <>\n <Button\n startIcon={<SvgAdd />}\n styleType='high-visibility'\n onClick={() => {\n setGroupModifyView(PropertyMenuView.ADD_CUSTOM_CALCULATION);\n }}\n >\n Add Custom Calculation\n </Button>\n <Table<CustomCalculationType>\n data={customCalculations}\n density='extra-condensed'\n columns={CustomCalculationsColumns}\n emptyTableContent='No Custom Calculations'\n isSortable\n isLoading={isLoadingCustomCalculations}\n />\n\n <DeleteModal\n entityName={selectedCustomCalculation?.propertyName ?? \"\"}\n show={showCustomCalculationDeleteModal}\n setShow={setShowCustomCalculationDeleteModal}\n onDelete={async () => {\n await mappingClient.deleteCustomCalculation(\n apiContext.accessToken,\n iModelId,\n mappingId,\n groupId,\n selectedCustomCalculation?.id ?? \"\",\n );\n }}\n refresh={refreshCustomCalculations}\n />\n </>\n );\n};\n\nexport default CustomCalculationTable;\n"]}
@@ -6,7 +6,8 @@ interface GroupActionProps {
6
6
  mappingId: string;
7
7
  group?: GroupType;
8
8
  goBack: () => Promise<void>;
9
+ resetView: () => Promise<void>;
9
10
  }
10
- declare const GroupAction: ({ iModelId, mappingId, group, goBack, }: GroupActionProps) => JSX.Element;
11
+ declare const GroupAction: ({ iModelId, mappingId, group, goBack, resetView, }: GroupActionProps) => JSX.Element;
11
12
  export default GroupAction;
12
13
  //# sourceMappingURL=GroupAction.d.ts.map
@@ -35,12 +35,12 @@ const GroupQueryBuilderContext_1 = require("./GroupQueryBuilderContext");
35
35
  const QueryBuilder_1 = require("./QueryBuilder");
36
36
  const viewerUtils_1 = require("./viewerUtils");
37
37
  const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
38
- const insights_client_1 = require("@itwin/insights-client");
39
38
  const GroupingMapping_1 = require("./GroupingMapping");
40
- const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
39
+ const GroupAction = ({ iModelId, mappingId, group, goBack, resetView, }) => {
41
40
  var _a, _b, _c;
42
41
  const iModelConnection = appui_react_1.useActiveIModelConnection();
43
42
  const apiContext = react_1.useContext(GroupingMapping_1.ApiContext);
43
+ const mappingClient = react_1.useContext(GroupingMapping_1.MappingClientContext);
44
44
  const [details, setDetails] = react_1.useState({
45
45
  groupName: (_a = group === null || group === void 0 ? void 0 : group.groupName) !== null && _a !== void 0 ? _a : "",
46
46
  description: (_b = group === null || group === void 0 ? void 0 : group.description) !== null && _b !== void 0 ? _b : "",
@@ -54,11 +54,12 @@ const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
54
54
  const [queryBuilder, setQueryBuilder] = react_1.default.useState(new QueryBuilder_1.QueryBuilder(undefined));
55
55
  const [groupByType, setGroupByType] = react_1.default.useState("Selection");
56
56
  const [searchInput, setSearchInput] = react_1.default.useState("");
57
- const changeGroupByType = (event) => {
57
+ const changeGroupByType = async (event) => {
58
58
  const { target: { value }, } = event;
59
59
  setGroupByType(value);
60
60
  presentation_frontend_1.Presentation.selection.clearSelection("GroupingMappingWidget", iModelConnection);
61
61
  setQuery("");
62
+ await resetView();
62
63
  };
63
64
  react_1.useEffect(() => {
64
65
  const removeListener = presentation_frontend_1.Presentation.selection.selectionChange.addListener(async (evt, selectionProvider) => {
@@ -73,11 +74,14 @@ const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
73
74
  react_1.useEffect(() => {
74
75
  const reemphasize = async () => {
75
76
  try {
76
- viewerUtils_1.clearEmphasizedElements();
77
77
  if (!query || query === "") {
78
78
  return;
79
79
  }
80
+ if (groupByType === "Selection" && currentPropertyList.length === 0) {
81
+ return;
82
+ }
80
83
  setIsRendering(true);
84
+ viewerUtils_1.transparentOverriddenElements();
81
85
  const ids = await utils_1.fetchIdsFromQuery(query !== null && query !== void 0 ? query : "", iModelConnection);
82
86
  const resolvedHiliteIds = await viewerUtils_1.visualizeElementsById(ids, "red", iModelConnection);
83
87
  await viewerUtils_1.zoomToElements(resolvedHiliteIds);
@@ -90,7 +94,7 @@ const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
90
94
  }
91
95
  };
92
96
  void reemphasize();
93
- }, [iModelConnection, query]);
97
+ }, [iModelConnection, query, currentPropertyList, groupByType]);
94
98
  react_1.useEffect(() => {
95
99
  presentation_frontend_1.Presentation.selection.clearSelection("GroupingMappingWidget", iModelConnection);
96
100
  }, [iModelConnection]);
@@ -122,10 +126,9 @@ const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
122
126
  try {
123
127
  setIsLoading(true);
124
128
  const currentQuery = query || simpleQuery;
125
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
126
129
  group
127
- ? await reportingClientApi.updateGroup(apiContext.accessToken, iModelId, mappingId, (_a = group.id) !== null && _a !== void 0 ? _a : "", { ...details, query: currentQuery })
128
- : await reportingClientApi.createGroup(apiContext.accessToken, iModelId, mappingId, {
130
+ ? await mappingClient.updateGroup(apiContext.accessToken, iModelId, mappingId, (_a = group.id) !== null && _a !== void 0 ? _a : "", { ...details, query: currentQuery })
131
+ : await mappingClient.createGroup(apiContext.accessToken, iModelId, mappingId, {
129
132
  ...details,
130
133
  query: currentQuery,
131
134
  });
@@ -148,7 +151,7 @@ const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
148
151
  simpleQuery,
149
152
  validator,
150
153
  apiContext.accessToken,
151
- apiContext.prefix,
154
+ mappingClient,
152
155
  ]);
153
156
  const isBlockingActions = !(details.groupName && (query || simpleQuery) && !isRendering && !isLoading);
154
157
  return (react_1.default.createElement(react_1.default.Fragment, null,
@@ -187,6 +190,7 @@ const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
187
190
  setQueryBuilder,
188
191
  isLoading,
189
192
  isRendering,
193
+ resetView,
190
194
  } },
191
195
  react_1.default.createElement(GroupQueryBuilderContainer_1.GroupQueryBuilderContainer, null)) :
192
196
  react_1.default.createElement("div", { className: "search-form" },
@@ -196,9 +200,10 @@ const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
196
200
  isRendering &&
197
201
  react_1.default.createElement(utils_1.LoadingSpinner, null),
198
202
  react_1.default.createElement(itwinui_react_1.Button, { disabled: isLoading || isRendering, onClick: () => generateSearchQuery(searchInput ? searchInput.replace(/(\r\n|\n|\r)/gm, "").trim().split(" ") : []) }, "Apply"),
199
- react_1.default.createElement(itwinui_react_1.Button, { disabled: isLoading || isRendering, onClick: () => {
203
+ react_1.default.createElement(itwinui_react_1.Button, { disabled: isLoading || isRendering, onClick: async () => {
200
204
  setQuery("");
201
205
  setSearchInput("");
206
+ await resetView();
202
207
  } }, "Clear"))))),
203
208
  react_1.default.createElement(ActionPanel_1.default, { onSave: async () => {
204
209
  await save();