@itwin/grouping-mapping-widget 0.3.4 → 0.3.5

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 (77) 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/widget/components/CalculatedPropertyAction.js +1 -2
  8. package/lib/cjs/widget/components/CalculatedPropertyAction.js.map +1 -1
  9. package/lib/cjs/widget/components/CalculatedPropertyTable.js +2 -2
  10. package/lib/cjs/widget/components/CalculatedPropertyTable.js.map +1 -1
  11. package/lib/cjs/widget/components/ConfirmMappingsImport.js +1 -2
  12. package/lib/cjs/widget/components/ConfirmMappingsImport.js.map +1 -1
  13. package/lib/cjs/widget/components/CustomCalculationAction.js +2 -3
  14. package/lib/cjs/widget/components/CustomCalculationAction.js.map +1 -1
  15. package/lib/cjs/widget/components/CustomCalculationTable.js +2 -2
  16. package/lib/cjs/widget/components/CustomCalculationTable.js.map +1 -1
  17. package/lib/cjs/widget/components/GroupAction.js +1 -2
  18. package/lib/cjs/widget/components/GroupAction.js.map +1 -1
  19. package/lib/cjs/widget/components/GroupPropertyAction.js +2 -3
  20. package/lib/cjs/widget/components/GroupPropertyAction.js.map +1 -1
  21. package/lib/cjs/widget/components/GroupPropertyTable.js +2 -2
  22. package/lib/cjs/widget/components/GroupPropertyTable.js.map +1 -1
  23. package/lib/cjs/widget/components/Grouping.js +2 -3
  24. package/lib/cjs/widget/components/Grouping.js.map +1 -1
  25. package/lib/cjs/widget/components/Mapping.js +3 -4
  26. package/lib/cjs/widget/components/Mapping.js.map +1 -1
  27. package/lib/cjs/widget/components/MappingAction.js +2 -3
  28. package/lib/cjs/widget/components/MappingAction.js.map +1 -1
  29. package/lib/cjs/widget/components/PropertyMenu.js +21 -12
  30. package/lib/cjs/widget/components/PropertyMenu.js.map +1 -1
  31. package/lib/cjs/widget/components/SelectMappings.js +1 -2
  32. package/lib/cjs/widget/components/SelectMappings.js.map +1 -1
  33. package/lib/cjs/widget/components/utils.d.ts +2 -0
  34. package/lib/cjs/widget/components/utils.js +13 -1
  35. package/lib/cjs/widget/components/utils.js.map +1 -1
  36. package/lib/cjs/widget/hooks/useFormulaValidation.d.ts +1 -1
  37. package/lib/cjs/widget/hooks/useFormulaValidation.js +5 -5
  38. package/lib/cjs/widget/hooks/useFormulaValidation.js.map +1 -1
  39. package/lib/esm/formula/FormulaTokensValidator.d.ts +1 -1
  40. package/lib/esm/formula/FormulaTokensValidator.js +3 -1
  41. package/lib/esm/formula/FormulaTokensValidator.js.map +1 -1
  42. package/lib/esm/formula/FormulaValidator.d.ts +1 -1
  43. package/lib/esm/formula/FormulaValidator.js +2 -2
  44. package/lib/esm/formula/FormulaValidator.js.map +1 -1
  45. package/lib/esm/widget/components/CalculatedPropertyAction.js +2 -3
  46. package/lib/esm/widget/components/CalculatedPropertyAction.js.map +1 -1
  47. package/lib/esm/widget/components/CalculatedPropertyTable.js +2 -2
  48. package/lib/esm/widget/components/CalculatedPropertyTable.js.map +1 -1
  49. package/lib/esm/widget/components/ConfirmMappingsImport.js +2 -3
  50. package/lib/esm/widget/components/ConfirmMappingsImport.js.map +1 -1
  51. package/lib/esm/widget/components/CustomCalculationAction.js +3 -4
  52. package/lib/esm/widget/components/CustomCalculationAction.js.map +1 -1
  53. package/lib/esm/widget/components/CustomCalculationTable.js +2 -2
  54. package/lib/esm/widget/components/CustomCalculationTable.js.map +1 -1
  55. package/lib/esm/widget/components/GroupAction.js +2 -3
  56. package/lib/esm/widget/components/GroupAction.js.map +1 -1
  57. package/lib/esm/widget/components/GroupPropertyAction.js +3 -4
  58. package/lib/esm/widget/components/GroupPropertyAction.js.map +1 -1
  59. package/lib/esm/widget/components/GroupPropertyTable.js +2 -2
  60. package/lib/esm/widget/components/GroupPropertyTable.js.map +1 -1
  61. package/lib/esm/widget/components/Grouping.js +3 -4
  62. package/lib/esm/widget/components/Grouping.js.map +1 -1
  63. package/lib/esm/widget/components/Mapping.js +4 -5
  64. package/lib/esm/widget/components/Mapping.js.map +1 -1
  65. package/lib/esm/widget/components/MappingAction.js +3 -4
  66. package/lib/esm/widget/components/MappingAction.js.map +1 -1
  67. package/lib/esm/widget/components/PropertyMenu.js +22 -13
  68. package/lib/esm/widget/components/PropertyMenu.js.map +1 -1
  69. package/lib/esm/widget/components/SelectMappings.js +2 -3
  70. package/lib/esm/widget/components/SelectMappings.js.map +1 -1
  71. package/lib/esm/widget/components/utils.d.ts +2 -0
  72. package/lib/esm/widget/components/utils.js +11 -0
  73. package/lib/esm/widget/components/utils.js.map +1 -1
  74. package/lib/esm/widget/hooks/useFormulaValidation.d.ts +1 -1
  75. package/lib/esm/widget/hooks/useFormulaValidation.js +5 -5
  76. package/lib/esm/widget/hooks/useFormulaValidation.js.map +1 -1
  77. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  import type { Token } from "./InfixToPostfixConverter";
2
2
  import type { Queue } from "./Queue";
3
3
  import type { PropertyMap } from "./Types";
4
- export declare function validateTokens(tokens: Queue<Token>, properties: PropertyMap): string;
4
+ export declare function validateTokens(formulaName: string, tokens: Queue<Token>, properties: PropertyMap): string;
5
5
  //# sourceMappingURL=FormulaTokensValidator.d.ts.map
@@ -21,7 +21,7 @@ function isNumericalConstant(name) {
21
21
  "sqrt2",
22
22
  ].includes(name.toLowerCase());
23
23
  }
24
- function validateTokens(tokens, properties) {
24
+ function validateTokens(formulaName, tokens, properties) {
25
25
  if (tokens.length === 0)
26
26
  return "Formula cannot be empty.";
27
27
  const argStack = new Stack_1.Stack();
@@ -46,6 +46,8 @@ function validateTokens(tokens, properties) {
46
46
  argStack.push("number");
47
47
  }
48
48
  else {
49
+ if (token.value === formulaName)
50
+ return "Formula cannot reference itself.";
49
51
  const prop = properties[token.value];
50
52
  if (!prop)
51
53
  return `Variable "${token.value}" is not available.`;
@@ -1 +1 @@
1
- {"version":3,"file":"FormulaTokensValidator.js","sourceRoot":"","sources":["../../../src/formula/FormulaTokensValidator.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,uEAAsF;AACtF,yEAA+G;AAE/G,uEAAsD;AAEtD,mCAAgC;AAGhC,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO;QACL,GAAG;QACH,KAAK;QACL,MAAM;QACN,OAAO;QACP,QAAQ;QACR,IAAI;QACJ,SAAS;QACT,OAAO;KACR,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,SAAgB,cAAc,CAAC,MAAoB,EAAE,UAAuB;IAC1E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QACrB,OAAO,0BAA0B,CAAC;IAEpC,MAAM,QAAQ,GAAG,IAAI,aAAK,EAAoB,CAAC;IAE/C,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACxB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,EAAG,CAAC;QAEhC,QAAQ,KAAK,CAAC,IAAI,EAAE;YAClB,KAAK,mCAAS,CAAC,MAAM;gBACnB,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACxB,MAAM;YACR,KAAK,mCAAS,CAAC,MAAM;gBACnB,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACxB,MAAM;YACR,KAAK,mCAAS,CAAC,OAAO;gBACpB,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACzB,MAAM;YACR,KAAK,mCAAS,CAAC,IAAI;gBACjB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBAC3B,MAAM;YACR,KAAK,mCAAS,CAAC,QAAQ;gBACrB,MAAM,UAAU,GAAG,m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qB,CAAC;KAC9B;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC;IAClC,IAAI,CAAC,UAAU,IAAI,UAAU,KAAK,WAAW,EAAE;QAC7C,OAAO,oCAAoC,CAAC;KAC7C;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AArHD,wCAqHC","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 { getFormulaFunctionReturnType, getFunction } from \"./FormulaFunctionProvider\";\nimport { getOperatorArgumentCountBounds, getOperatorReturnType, isOperator } from \"./FormulaOperatorsProvider\";\nimport type { Token } from \"./InfixToPostfixConverter\";\nimport { TokenType } from \"./InfixToPostfixConverter\";\nimport type { Queue } from \"./Queue\";\nimport { Stack } from \"./Stack\";\nimport type { PossibleDataType, PropertyMap } from \"./Types\";\n\nfunction isNumericalConstant(name: string): boolean {\n return [\n \"e\",\n \"ln2\",\n \"ln10\",\n \"log2e\",\n \"log10e\",\n \"pi\",\n \"sqrt1_2\",\n \"sqrt2\",\n ].includes(name.toLowerCase());\n}\n\nexport function validateTokens(tokens: Queue<Token>, properties: PropertyMap): string {\n if (tokens.length === 0)\n return \"Formula cannot be empty.\";\n\n const argStack = new Stack<PossibleDataType>();\n\n while (tokens.length > 0) {\n const token = tokens.dequeue()!;\n\n switch (token.type) {\n case TokenType.Number:\n argStack.push(\"number\");\n break;\n case TokenType.String:\n argStack.push(\"string\");\n break;\n case TokenType.Boolean:\n argStack.push(\"boolean\");\n break;\n case TokenType.Null:\n argStack.push(\"undefined\");\n break;\n case TokenType.Variable:\n const isConstant = isNumericalConstant(token.value);\n if (isConstant) {\n argStack.push(\"number\");\n } else {\n const prop = properties[token.value];\n if (!prop)\n return `Variable \"${token.value}\" is not available.`;\n argStack.push(prop);\n }\n break;\n case TokenType.Operator:\n if (!isOperator(token.value))\n return `Operator \"${token.value}\" is not supported.`;\n\n const operatorBounds = getOperatorArgumentCountBounds(token.value);\n if (!operatorBounds)\n return `Operator \"${token.value}\" is not supported.`;\n\n if (operatorBounds[0] === 2 && token.argCount === 1)\n return `Unary operator \"${token.value}\" is not supported.`;\n\n if (argStack.length < token.argCount) {\n return `Too few arguments given for ${token.argCount === 1 ? \"unary\" : \"binary\"} operator \"${token.value}\".`;\n }\n const opArgs = argStack.popN(token.argCount).reverse();\n let operationResult;\n if (opArgs.length === 1)\n operationResult = getOperatorReturnType(token.value, opArgs[0]);\n else if (opArgs.length === 2)\n operationResult = getOperatorReturnType(token.value, opArgs[0], opArgs[1]);\n else\n return `Operator \"${token.value}\" does not support ${token.argCount} operands.`;\n\n if (operationResult.errorMessage)\n return operationResult.errorMessage;\n else\n argStack.push(operationResult.value!);\n\n break;\n case TokenType.Function:\n const fnArg = getFunction(token.value);\n if (!fnArg)\n return `Function \"${token.value}\" is not supported.`;\n\n const fnArgBounds = fnArg.argumentCountBounds;\n if (fnArgBounds[0] === 0 && fnArgBounds[1] === 0 && token.argCount > 0) {\n return `Function \"${token.value}\" does not accept any arguments.`;\n } else if (fnArgBounds[1] === -1 && token.argCount < fnArgBounds[0]) {\n if (fnArgBounds[0] === 1) {\n return `Function \"${token.value}\" requires at least 1 argument.`;\n } else {\n if (token.argCount === 1) {\n return `Function \"${token.value}\" requires at least ${fnArgBounds[0]} arguments, but only 1 argument was given.`;\n } else {\n return `Function \"${token.value}\" requires at least ${fnArgBounds[0]} arguments, but only ${token.argCount} arguments were given.`;\n }\n }\n } else if (fnArgBounds[0] === fnArgBounds[1] && token.argCount !== fnArgBounds[0]) {\n if (fnArgBounds[0] === 1) {\n return `Function \"${token.value}\" requires exactly 1 argument, but ${token.argCount} arguments were given.`;\n } else {\n if (token.argCount === 1) {\n return `Function \"${token.value}\" requires exactly ${fnArgBounds[0]} arguments, but 1 argument was given.`;\n } else {\n return `Function \"${token.value}\" requires exactly ${fnArgBounds[0]} arguments, but ${token.argCount} arguments were given.`;\n }\n }\n }\n\n const fArgs = argStack.popN(token.argCount).reverse();\n if (fArgs.length < token.argCount) {\n return `Too few arguments given for function \"${token.value}\".`;\n }\n\n const functionResult = getFormulaFunctionReturnType(fnArg, fArgs);\n if (functionResult.errorMessage)\n return `Function \"${token.value}\" is invalid. ${functionResult.errorMessage}`;\n else\n argStack.push(functionResult.value!);\n\n break;\n }\n }\n\n if (argStack.length !== 1) {\n return \"Formula is invalid.\";\n }\n\n const resultType = argStack.pop();\n if (!resultType || resultType === \"undefined\") {\n return \"Formula cannot always return null.\";\n }\n\n return \"\";\n}\n\n"]}
1
+ {"version":3,"file":"FormulaTokensValidator.js","sourceRoot":"","sources":["../../../src/formula/FormulaTokensValidator.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,uEAAsF;AACtF,yEAA+G;AAE/G,uEAAsD;AAEtD,mCAAgC;AAGhC,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO;QACL,GAAG;QACH,KAAK;QACL,MAAM;QACN,OAAO;QACP,QAAQ;QACR,IAAI;QACJ,SAAS;QACT,OAAO;KACR,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,SAAgB,cAAc,CAAC,WAAmB,EAAE,MAAoB,EAAE,UAAuB;IAC/F,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QACrB,OAAO,0BAA0B,CAAC;IAEpC,MAAM,QAAQ,GAAG,IAAI,aAAK,EAAoB,CAAC;IAE/C,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACxB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,EAAG,CAAC;QAEhC,QAAQ,KAAK,CAAC,IAAI,EAAE;YAClB,KAAK,mCAAS,CAAC,MAAM;gBACnB,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACxB,MAAM;YACR,KAAK,mCAAS,CAAC,MAAM;gBACnB,QAAQ,CAAC,IAAI,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AC,KAAK,IAAI,CAAC;iBACjE;gBAED,MAAM,cAAc,GAAG,sDAA4B,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAClE,IAAI,cAAc,CAAC,YAAY;oBAC7B,OAAO,aAAa,KAAK,CAAC,KAAK,iBAAiB,cAAc,CAAC,YAAY,EAAE,CAAC;;oBAE9E,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,KAAM,CAAC,CAAC;gBAEvC,MAAM;SACT;KACF;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QACzB,OAAO,qBAAqB,CAAC;KAC9B;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC;IAClC,IAAI,CAAC,UAAU,IAAI,UAAU,KAAK,WAAW,EAAE;QAC7C,OAAO,oCAAoC,CAAC;KAC7C;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAzHD,wCAyHC","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 { getFormulaFunctionReturnType, getFunction } from \"./FormulaFunctionProvider\";\nimport { getOperatorArgumentCountBounds, getOperatorReturnType, isOperator } from \"./FormulaOperatorsProvider\";\nimport type { Token } from \"./InfixToPostfixConverter\";\nimport { TokenType } from \"./InfixToPostfixConverter\";\nimport type { Queue } from \"./Queue\";\nimport { Stack } from \"./Stack\";\nimport type { PossibleDataType, PropertyMap } from \"./Types\";\n\nfunction isNumericalConstant(name: string): boolean {\n return [\n \"e\",\n \"ln2\",\n \"ln10\",\n \"log2e\",\n \"log10e\",\n \"pi\",\n \"sqrt1_2\",\n \"sqrt2\",\n ].includes(name.toLowerCase());\n}\n\nexport function validateTokens(formulaName: string, tokens: Queue<Token>, properties: PropertyMap): string {\n if (tokens.length === 0)\n return \"Formula cannot be empty.\";\n\n const argStack = new Stack<PossibleDataType>();\n\n while (tokens.length > 0) {\n const token = tokens.dequeue()!;\n\n switch (token.type) {\n case TokenType.Number:\n argStack.push(\"number\");\n break;\n case TokenType.String:\n argStack.push(\"string\");\n break;\n case TokenType.Boolean:\n argStack.push(\"boolean\");\n break;\n case TokenType.Null:\n argStack.push(\"undefined\");\n break;\n case TokenType.Variable:\n const isConstant = isNumericalConstant(token.value);\n if (isConstant) {\n argStack.push(\"number\");\n } else {\n if (token.value === formulaName)\n return \"Formula cannot reference itself.\";\n\n const prop = properties[token.value];\n if (!prop)\n return `Variable \"${token.value}\" is not available.`;\n\n argStack.push(prop);\n }\n break;\n case TokenType.Operator:\n if (!isOperator(token.value))\n return `Operator \"${token.value}\" is not supported.`;\n\n const operatorBounds = getOperatorArgumentCountBounds(token.value);\n if (!operatorBounds)\n return `Operator \"${token.value}\" is not supported.`;\n\n if (operatorBounds[0] === 2 && token.argCount === 1)\n return `Unary operator \"${token.value}\" is not supported.`;\n\n if (argStack.length < token.argCount) {\n return `Too few arguments given for ${token.argCount === 1 ? \"unary\" : \"binary\"} operator \"${token.value}\".`;\n }\n const opArgs = argStack.popN(token.argCount).reverse();\n let operationResult;\n if (opArgs.length === 1)\n operationResult = getOperatorReturnType(token.value, opArgs[0]);\n else if (opArgs.length === 2)\n operationResult = getOperatorReturnType(token.value, opArgs[0], opArgs[1]);\n else\n return `Operator \"${token.value}\" does not support ${token.argCount} operands.`;\n\n if (operationResult.errorMessage)\n return operationResult.errorMessage;\n else\n argStack.push(operationResult.value!);\n\n break;\n case TokenType.Function:\n const fnArg = getFunction(token.value);\n if (!fnArg)\n return `Function \"${token.value}\" is not supported.`;\n\n const fnArgBounds = fnArg.argumentCountBounds;\n if (fnArgBounds[0] === 0 && fnArgBounds[1] === 0 && token.argCount > 0) {\n return `Function \"${token.value}\" does not accept any arguments.`;\n } else if (fnArgBounds[1] === -1 && token.argCount < fnArgBounds[0]) {\n if (fnArgBounds[0] === 1) {\n return `Function \"${token.value}\" requires at least 1 argument.`;\n } else {\n if (token.argCount === 1) {\n return `Function \"${token.value}\" requires at least ${fnArgBounds[0]} arguments, but only 1 argument was given.`;\n } else {\n return `Function \"${token.value}\" requires at least ${fnArgBounds[0]} arguments, but only ${token.argCount} arguments were given.`;\n }\n }\n } else if (fnArgBounds[0] === fnArgBounds[1] && token.argCount !== fnArgBounds[0]) {\n if (fnArgBounds[0] === 1) {\n return `Function \"${token.value}\" requires exactly 1 argument, but ${token.argCount} arguments were given.`;\n } else {\n if (token.argCount === 1) {\n return `Function \"${token.value}\" requires exactly ${fnArgBounds[0]} arguments, but 1 argument was given.`;\n } else {\n return `Function \"${token.value}\" requires exactly ${fnArgBounds[0]} arguments, but ${token.argCount} arguments were given.`;\n }\n }\n }\n\n const fArgs = argStack.popN(token.argCount).reverse();\n if (fArgs.length < token.argCount) {\n return `Too few arguments given for function \"${token.value}\".`;\n }\n\n const functionResult = getFormulaFunctionReturnType(fnArg, fArgs);\n if (functionResult.errorMessage)\n return `Function \"${token.value}\" is invalid. ${functionResult.errorMessage}`;\n else\n argStack.push(functionResult.value!);\n\n break;\n }\n }\n\n if (argStack.length !== 1) {\n return \"Formula is invalid.\";\n }\n\n const resultType = argStack.pop();\n if (!resultType || resultType === \"undefined\") {\n return \"Formula cannot always return null.\";\n }\n\n return \"\";\n}\n\n"]}
@@ -1,3 +1,3 @@
1
1
  import type { PropertyMap } from "./Types";
2
- export declare function validateFormula(formula: string, properties: PropertyMap): string;
2
+ export declare function validateFormula(formulaName: string, formula: string, properties: PropertyMap): string;
3
3
  //# sourceMappingURL=FormulaValidator.d.ts.map
@@ -9,7 +9,7 @@ const FormulaSplitter_1 = require("./FormulaSplitter");
9
9
  const FormulaTokensValidator_1 = require("./FormulaTokensValidator");
10
10
  const InfixToPostfixConverter_1 = require("./InfixToPostfixConverter");
11
11
  const ParenthesisValidator_1 = require("./ParenthesisValidator");
12
- function validateFormula(formula, properties) {
12
+ function validateFormula(formulaName, formula, properties) {
13
13
  var _a;
14
14
  const parenthesisState = ParenthesisValidator_1.validateParenthesis(formula);
15
15
  if (ParenthesisValidator_1.ParenthesisState.NotClosed === parenthesisState) {
@@ -29,7 +29,7 @@ function validateFormula(formula, properties) {
29
29
  if (undefined === postfixFormulaTokens.value) {
30
30
  return (_a = postfixFormulaTokens.errorMessage) !== null && _a !== void 0 ? _a : "Unknown error";
31
31
  }
32
- return FormulaTokensValidator_1.validateTokens(postfixFormulaTokens.value, properties);
32
+ return FormulaTokensValidator_1.validateTokens(formulaName, postfixFormulaTokens.value, properties);
33
33
  }
34
34
  exports.validateFormula = validateFormula;
35
35
  //# sourceMappingURL=FormulaValidator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormulaValidator.js","sourceRoot":"","sources":["../../../src/formula/FormulaValidator.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,uDAAiD;AACjD,qEAA0D;AAC1D,uEAAkE;AAClE,iEAA+E;AAG/E,SAAgB,eAAe,CAAC,OAAe,EAAE,UAAuB;;IACtE,MAAM,gBAAgB,GAAG,0CAAmB,CAAC,OAAO,CAAC,CAAC;IACtD,IAAI,uCAAgB,CAAC,SAAS,KAAK,gBAAgB,EAAE;QACnD,OAAO,0CAA0C,CAAC;KACnD;SAAM,IAAI,uCAAgB,CAAC,SAAS,KAAK,gBAAgB,EAAE;QAC1D,OAAO,0CAA0C,CAAC;KACnD;IAED,IAAI,kBAAkB,CAAC;IACvB,IAAI;QACF,kBAAkB,GAAG,8BAAY,CAAC,OAAO,CAAC,CAAC;KAC5C;IAAC,OAAO,EAAE,EAAE;QACX,OAAQ,EAAY,CAAC,OAAO,CAAC;KAC9B;IAED,MAAM,oBAAoB,GAAG,+CAAqB,CAAC,kBAAkB,CAAC,CAAC;IAEvE,IAAI,SAAS,KAAK,oBAAoB,CAAC,KAAK,EAAE;QAC5C,OAAO,MAAA,oBAAoB,CAAC,YAAY,mCAAI,eAAe,CAAC;KAC7D;IAED,OAAO,uCAAc,CAAC,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AAChE,CAAC;AAtBD,0CAsBC","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 { splitFormula } from \"./FormulaSplitter\";\nimport { validateTokens } from \"./FormulaTokensValidator\";\nimport { convertInfixToPostfix } from \"./InfixToPostfixConverter\";\nimport { ParenthesisState, validateParenthesis } from \"./ParenthesisValidator\";\nimport type { PropertyMap } from \"./Types\";\n\nexport function validateFormula(formula: string, properties: PropertyMap): string {\n const parenthesisState = validateParenthesis(formula);\n if (ParenthesisState.NotClosed === parenthesisState) {\n return \"Opened but not closed parenthesis found.\";\n } else if (ParenthesisState.NotOpened === parenthesisState) {\n return \"Closed but not opened parenthesis found.\";\n }\n\n let infixFormulaTokens;\n try {\n infixFormulaTokens = splitFormula(formula);\n } catch (ex) {\n return (ex as Error).message;\n }\n\n const postfixFormulaTokens = convertInfixToPostfix(infixFormulaTokens);\n\n if (undefined === postfixFormulaTokens.value) {\n return postfixFormulaTokens.errorMessage ?? \"Unknown error\";\n }\n\n return validateTokens(postfixFormulaTokens.value, properties);\n}\n"]}
1
+ {"version":3,"file":"FormulaValidator.js","sourceRoot":"","sources":["../../../src/formula/FormulaValidator.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,uDAAiD;AACjD,qEAA0D;AAC1D,uEAAkE;AAClE,iEAA+E;AAG/E,SAAgB,eAAe,CAAC,WAAmB,EAAE,OAAe,EAAE,UAAuB;;IAC3F,MAAM,gBAAgB,GAAG,0CAAmB,CAAC,OAAO,CAAC,CAAC;IACtD,IAAI,uCAAgB,CAAC,SAAS,KAAK,gBAAgB,EAAE;QACnD,OAAO,0CAA0C,CAAC;KACnD;SAAM,IAAI,uCAAgB,CAAC,SAAS,KAAK,gBAAgB,EAAE;QAC1D,OAAO,0CAA0C,CAAC;KACnD;IAED,IAAI,kBAAkB,CAAC;IACvB,IAAI;QACF,kBAAkB,GAAG,8BAAY,CAAC,OAAO,CAAC,CAAC;KAC5C;IAAC,OAAO,EAAE,EAAE;QACX,OAAQ,EAAY,CAAC,OAAO,CAAC;KAC9B;IAED,MAAM,oBAAoB,GAAG,+CAAqB,CAAC,kBAAkB,CAAC,CAAC;IAEvE,IAAI,SAAS,KAAK,oBAAoB,CAAC,KAAK,EAAE;QAC5C,OAAO,MAAA,oBAAoB,CAAC,YAAY,mCAAI,eAAe,CAAC;KAC7D;IAED,OAAO,uCAAc,CAAC,WAAW,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AAC7E,CAAC;AAtBD,0CAsBC","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 { splitFormula } from \"./FormulaSplitter\";\nimport { validateTokens } from \"./FormulaTokensValidator\";\nimport { convertInfixToPostfix } from \"./InfixToPostfixConverter\";\nimport { ParenthesisState, validateParenthesis } from \"./ParenthesisValidator\";\nimport type { PropertyMap } from \"./Types\";\n\nexport function validateFormula(formulaName: string, formula: string, properties: PropertyMap): string {\n const parenthesisState = validateParenthesis(formula);\n if (ParenthesisState.NotClosed === parenthesisState) {\n return \"Opened but not closed parenthesis found.\";\n } else if (ParenthesisState.NotOpened === parenthesisState) {\n return \"Closed but not opened parenthesis found.\";\n }\n\n let infixFormulaTokens;\n try {\n infixFormulaTokens = splitFormula(formula);\n } catch (ex) {\n return (ex as Error).message;\n }\n\n const postfixFormulaTokens = convertInfixToPostfix(infixFormulaTokens);\n\n if (undefined === postfixFormulaTokens.value) {\n return postfixFormulaTokens.errorMessage ?? \"Unknown error\";\n }\n\n return validateTokens(formulaName, postfixFormulaTokens.value, properties);\n}\n"]}
@@ -35,7 +35,6 @@ 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;
@@ -88,7 +87,7 @@ const CalculatedPropertyAction = ({ iModelId, mappingId, groupId, property, ids,
88
87
  }
89
88
  try {
90
89
  setIsLoading(true);
91
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
90
+ const reportingClientApi = utils_1.getReportingClient(apiContext.prefix);
92
91
  property
93
92
  ? await reportingClientApi.updateCalculatedProperty(apiContext.accessToken, iModelId, mappingId, groupId, (_a = property.id) !== null && _a !== void 0 ? _a : "", {
94
93
  propertyName,
@@ -1 +1 @@
1
- {"version":3,"file":"CalculatedPropertyAction.js","sourceRoot":"","sources":["../../../../src/widget/components/CalculatedPropertyAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,wDAAiD;AAIjD,wDAM8B;AAC9B,+CAA+D;AAC/D,gEAAwC;AACxC,sFAGkD;AAClD,sEAAwE;AACxE,mCAAoD;AACpD,+CAAkE;AAClE,2CAAyC;AAEzC,4DAAyD;AACzD,uDAA+C;AAW/C,MAAM,wBAAwB,GAAG,CAAC,EAChC,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,EACR,GAAG,EACH,QAAQ,GACsB,EAAE,EAAE;;IAClC,MAAM,UAAU,GAAG,kBAAU,CAAC,4BAAU,CAAC,CAAC;IAC1C,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,gBAAQ,CAC9C,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,YAAY,mCAAI,EAAE,CAC7B,CAAC;IACF,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,gBAAQ,CAAS,MAAA,QAAQ,aAAR,QAAQ,uBAAR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AC,iBAAiB;4BAC9B,2CAAM,MAAM,CAAC,KAAK,CAAO;4BACxB,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CACzB,CACG,CACZ,EACD,oBAAoB,EAAE,CAAC,MAA4B,EAAE,EAAE,CAAC,CACtD,uCAAK,SAAS,EAAC,aAAa;wBAC1B,2CAAM,MAAM,CAAC,KAAK,CAAO;wBACxB,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CACzB,CACP,EACD,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EACjB,MAAM,EAAE,GAAG,EAAE,GAAG,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,IAAI,IAAI,YAAY,CAAC,EACzC,SAAS,EAAE,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 { 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":"CalculatedPropertyAction.js","sourceRoot":"","sources":["../../../../src/widget/components/CalculatedPropertyAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,wDAAiD;AAIjD,wDAM8B;AAC9B,+CAA+D;AAC/D,gEAAwC;AACxC,sFAGkD;AAClD,sEAAwE;AACxE,mCAAwE;AACxE,+CAAkE;AAClE,2CAAyC;AAEzC,uDAA+C;AAW/C,MAAM,wBAAwB,GAAG,CAAC,EAChC,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,EACR,GAAG,EACH,QAAQ,GACsB,EAAE,EAAE;;IAClC,MAAM,UAAU,GAAG,kBAAU,CAAC,4BAAU,CAAC,CAAC;IAC1C,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,gBAAQ,CAC9C,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,YAAY,mCAAI,EAAE,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AE,OAAO,EACjB,YAAY,EAAE,CAAC,MAA4B,EAAE,EAAE,CAAC,CAC9C,8BAAC,wBAAQ;wBACP,uCAAK,SAAS,EAAC,iBAAiB;4BAC9B,2CAAM,MAAM,CAAC,KAAK,CAAO;4BACxB,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CACzB,CACG,CACZ,EACD,oBAAoB,EAAE,CAAC,MAA4B,EAAE,EAAE,CAAC,CACtD,uCAAK,SAAS,EAAC,aAAa;wBAC1B,2CAAM,MAAM,CAAC,KAAK,CAAO;wBACxB,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CACzB,CACP,EACD,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EACjB,MAAM,EAAE,GAAG,EAAE,GAAG,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,IAAI,IAAI,YAAY,CAAC,EACzC,SAAS,EAAE,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 { getReportingClient, handleError, WidgetHeader } from \"./utils\";\nimport { visualizeElements, zoomToElements } from \"./viewerUtils\";\nimport \"./CalculatedPropertyAction.scss\";\nimport type { CalculatedPropertyType } from \"./CalculatedPropertyTable\";\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 = getReportingClient(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"]}
@@ -31,8 +31,8 @@ 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");
35
+ const utils_1 = require("./utils");
36
36
  const CalculatedPropertyTable = ({ iModelId, mappingId, groupId, setSelectedCalculatedProperty, setGroupModifyView, onCalculatedPropertyModify, isLoadingCalculatedProperties: isLoadingGroupProperties, calculatedProperties, refreshCalculatedProperties, selectedCalculatedProperty, }) => {
37
37
  var _a;
38
38
  const apiContext = react_1.useContext(GroupingMapping_1.ApiContext);
@@ -77,7 +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);
80
+ const reportingClientApi = utils_1.getReportingClient(apiContext.prefix);
81
81
  await reportingClientApi.deleteCalculatedProperty(apiContext.accessToken, iModelId, mappingId, groupId, (_a = selectedCalculatedProperty === null || selectedCalculatedProperty === void 0 ? void 0 : selectedCalculatedProperty.id) !== null && _a !== void 0 ? _a : "");
82
82
  }, refresh: refreshCalculatedProperties })));
83
83
  };
@@ -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,MAA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,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,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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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 } from \"./GroupingMapping\";\nimport { getReportingClient } from \"./utils\";\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 = getReportingClient(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"]}
@@ -30,7 +30,6 @@ 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;
@@ -62,7 +61,7 @@ const ConfirmMappingImport = ({ sourceiModelId, selectedMappings, importing, set
62
61
  }
63
62
  setImporting(true);
64
63
  try {
65
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
64
+ const reportingClientApi = utils_1.getReportingClient(apiContext.prefix);
66
65
  for (const selectedMapping of selectedMappings) {
67
66
  setCurrentlyImporting((_a = selectedMapping.mappingName) !== null && _a !== void 0 ? _a : "");
68
67
  await reportingClientApi.copyMapping(apiContext.accessToken, sourceiModelId, (_b = selectedMapping.id) !== null && _b !== void 0 ? _b : "", {
@@ -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,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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 { 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","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,mCAA0D;AAC1D,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,QAAQ,GAAG,MAAA,uCAAyB,EAAE,0CAAE,QAAQ,CAAC;IACvD,MAAM,UAAU,GAAG,kBAAU,CAAC,4BAAU,CAAC,CAAC;IAE1C,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,gBAAQ,CAAS,CAAC,CAAC,CAAC;IAC1D,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,gBAAQ,CAAS,EAAE,CAAC,CAAC;IACzE,MAAM,CAAC,SAAS,EAAE,qBAAqB,CAAC,GAAG,sBAAY,EAAE,CAAC;IAC1D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,gBAAQ,CAAU,KAAK,CAAC,CAAC;IAEvD,iBAAS,CAAC,GAAG,EAAE;QACb,mBAAmB,CAAC,CAAC,gBAAgB,EAAE,EAAE,CACvC,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACjC,GAAG,OAAO;YACV,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,OAAO;SAC3C,CAAC,CAAC,CACJ,CAAC;IACJ,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAE1B,MAAM,YAAY,GAAG,CACnB,CAAsC,EACtC,KAAa,EACb,EAAE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CAAC,EAAE,EAAE,EACvB,OAAO,CAAC,WAAW,EACnB,gCAAiB,CAClB;4BACC,CAAC,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 { getReportingClient, handleError } from \"./utils\";\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 = getReportingClient(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"]}
@@ -35,7 +35,6 @@ 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;
@@ -46,7 +45,7 @@ const CustomCalculationAction = ({ iModelId, mappingId, groupId, properties, cus
46
45
  const [isLoading, setIsLoading] = react_1.useState(false);
47
46
  const [formulaErrorMessage, setFormulaErrorMessage] = react_1.useState("");
48
47
  const [validator, showValidationMessage] = useValidator_1.default();
49
- const { isValid, forceValidation } = useFormulaValidation_1.useFormulaValidation(formula, properties, setFormulaErrorMessage);
48
+ const { isValid, forceValidation } = useFormulaValidation_1.useFormulaValidation(propertyName.toLowerCase(), formula, properties, setFormulaErrorMessage);
50
49
  const onSave = async () => {
51
50
  var _a;
52
51
  if (!validator.allValid()) {
@@ -58,7 +57,7 @@ const CustomCalculationAction = ({ iModelId, mappingId, groupId, properties, cus
58
57
  }
59
58
  try {
60
59
  setIsLoading(true);
61
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
60
+ const reportingClientApi = utils_1.getReportingClient(apiContext.prefix);
62
61
  customCalculation
63
62
  ? await reportingClientApi.updateCustomCalculation(apiContext.accessToken, iModelId, mappingId, groupId, (_a = customCalculation.id) !== null && _a !== void 0 ? _a : "", {
64
63
  propertyName,
@@ -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,iBAAiB,CAAE,YAAY,mCAAI,EAAE,CACtC,CAAC;IACF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,gBAAQ,CACpC,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,OAAO,mCAAI,EAAE,CACjC,CAAC;IACF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,gBAAQ,CAAS,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,YAAY,mCAAI,WAAW,CAAC,CAAC;IACzG,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,gBAAQ,CAAU,KAAK,CAAC,CAAC;IAC3D,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,gBAAQ,CAAS,EAAE,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EACD,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;wBACvB,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;wBACpC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;oBACnC,CAAC,GACD;gBACF,8BAAC,+BAAe,IACd,KAAK,EAAE,OAAO,EACd,QAAQ,QACR,IAAI,EAAC,SAAS,EACd,KAAK,EAAC,SAAS,EACf,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;wBAClB,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACjC,CAAC,EACD,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,GACpD;gBACF,8BAAC,6BAAa,IACZ,KAAK,EAAC,eAAe,EACrB,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,mDAA6B,EACtC,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EACjB,MAAM,EAAE,GAAG,EAAE,GAAG,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,mCAAwE;AACxE,2CAAyC;AAEzC,0CAAwC;AACxC,+DAAsE;AACtE,wEAAqE;AAErE,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,iBAAiB,CAAE,YAAY,mCAAI,EAAE,CACtC,CAAC;IACF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,gBAAQ,CACpC,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,OAAO,mCAAI,EAAE,CACjC,CAAC;IACF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,gBAAQ,CAAS,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,YAAY,mCAAI,WAAW,CAAC,CAAC;IACzG,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,gBAAQ,CAAU,KAAK,CAAC,CAAC;IAC3D,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,gBAAQ,CAAS,EAAE,CAAC,CAAC;IAC3E,MAAM,CAAC,SAAS,EAAE,qBAAqB,CAAC,GAAG,sBAAY,EAAE,CAAC;IAC1D,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,2CAAoB,C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CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;oBACnC,CAAC,GACD;gBACF,8BAAC,+BAAe,IACd,KAAK,EAAE,OAAO,EACd,QAAQ,QACR,IAAI,EAAC,SAAS,EACd,KAAK,EAAC,SAAS,EACf,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;wBAClB,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACjC,CAAC,EACD,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,GACpD;gBACF,8BAAC,6BAAa,IACZ,KAAK,EAAC,eAAe,EACrB,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,mDAA6B,EACtC,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EACjB,MAAM,EAAE,GAAG,EAAE,GAAG,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 { getReportingClient, 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 } 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(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 const reportingClientApi = getReportingClient(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"]}
@@ -31,8 +31,8 @@ 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");
35
+ const utils_1 = require("./utils");
36
36
  const CustomCalculationTable = ({ iModelId, mappingId, groupId, setSelectedCustomCalculation, setGroupModifyView, onCustomCalculationModify, isLoadingCustomCalculations, customCalculations, refreshCustomCalculations, selectedCustomCalculation, }) => {
37
37
  var _a;
38
38
  const apiContext = react_1.useContext(GroupingMapping_1.ApiContext);
@@ -82,7 +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);
85
+ const reportingClientApi = utils_1.getReportingClient(apiContext.prefix);
86
86
  await reportingClientApi.deleteCustomCalculation(apiContext.accessToken, iModelId, mappingId, groupId, (_a = selectedCustomCalculation === null || selectedCustomCalculation === void 0 ? void 0 : selectedCustomCalculation.id) !== null && _a !== void 0 ? _a : "");
87
87
  }, refresh: refreshCustomCalculations })));
88
88
  };
@@ -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;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,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,uDAA+C;AAC/C,mCAA6C;AAsB7C,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;oBAC5B,QAAQ,EAAE,cAAc;oBACxB,IAAI,EAAE,CAAC,KAAuC,EAAE,EAAE,CAAC,CACjD,uCACE,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,GAAG,EAAE,CAAC,yBAAyB,CAAC,KAAK,CAAC,IAE9C,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,CAC5B,CACP;iBACF;gBACD;oBACE,EAAE,EAAE,SAAS;oBACb,MAAM,EAAE,SAAS;oBACjB,QAAQ,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C,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,0BAAkB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gBACjE,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 { ApiContext } from \"./GroupingMapping\";\nimport { getReportingClient } from \"./utils\";\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 = getReportingClient(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"]}
@@ -35,7 +35,6 @@ 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
39
  const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
41
40
  var _a, _b, _c;
@@ -122,7 +121,7 @@ const GroupAction = ({ iModelId, mappingId, group, goBack, }) => {
122
121
  try {
123
122
  setIsLoading(true);
124
123
  const currentQuery = query || simpleQuery;
125
- const reportingClientApi = new insights_client_1.ReportingClient(apiContext.prefix);
124
+ const reportingClientApi = utils_1.getReportingClient(apiContext.prefix);
126
125
  group
127
126
  ? await reportingClientApi.updateGroup(apiContext.accessToken, iModelId, mappingId, (_a = group.id) !== null && _a !== void 0 ? _a : "", { ...details, query: currentQuery })
128
127
  : await reportingClientApi.createGroup(apiContext.accessToken, iModelId, mappingId, {