@itwin/grouping-mapping-widget 0.26.1 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/WidgetShell/Router/GroupingMappingRouter.js +1 -15
- package/lib/cjs/WidgetShell/Router/GroupingMappingRouter.js.map +1 -1
- package/lib/cjs/components/Groups/hooks/useKeySetHiliteQueries.d.ts +1 -1
- package/lib/cjs/components/Mappings/MappingViewActionGroup.d.ts +1 -1
- package/lib/cjs/components/Mappings/MappingViewActionGroup.js +1 -2
- package/lib/cjs/components/Mappings/MappingViewActionGroup.js.map +1 -1
- package/lib/cjs/components/Mappings/MappingsView.js +1 -1
- package/lib/cjs/components/Mappings/MappingsView.js.map +1 -1
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyAction.d.ts +2 -0
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyAction.js +2 -1
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyAction.js.map +1 -1
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.d.ts +7 -8
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.js +21 -61
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.js.map +1 -1
- package/lib/cjs/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.d.ts +5 -9
- package/lib/cjs/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.js +3 -12
- package/lib/cjs/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.js.map +1 -1
- package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationAction.d.ts +8 -9
- package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationAction.js +17 -164
- package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationAction.js.map +1 -1
- package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationAction.scss +4 -3
- package/lib/cjs/components/Properties/GroupProperties/GroupPropertyAction.js +76 -19
- package/lib/cjs/components/Properties/GroupProperties/GroupPropertyAction.js.map +1 -1
- package/lib/cjs/components/Properties/GroupProperties/GroupPropertyAction.scss +3 -2
- package/lib/cjs/components/Properties/GroupProperties/GroupPropertyTable.js +10 -2
- package/lib/cjs/components/Properties/GroupProperties/GroupPropertyTable.js.map +1 -1
- package/lib/cjs/components/Properties/PropertyMenu.d.ts +1 -1
- package/lib/cjs/components/Properties/PropertyMenu.js +2 -7
- package/lib/cjs/components/Properties/PropertyMenu.js.map +1 -1
- package/lib/cjs/components/Properties/ScrollableExpandableBlock.d.ts +11 -0
- package/lib/cjs/components/Properties/ScrollableExpandableBlock.js +55 -0
- package/lib/cjs/components/Properties/ScrollableExpandableBlock.js.map +1 -0
- package/lib/cjs/components/Properties/hooks/useFormulaValidation.d.ts +6 -3
- package/lib/cjs/components/Properties/hooks/useFormulaValidation.js +59 -13
- package/lib/cjs/components/Properties/hooks/useFormulaValidation.js.map +1 -1
- package/lib/cjs/components/Properties/hooks/useForwardRef.d.ts +3 -0
- package/lib/cjs/components/Properties/hooks/useForwardRef.js +20 -0
- package/lib/cjs/components/Properties/hooks/useForwardRef.js.map +1 -0
- package/lib/cjs/components/SharedComponents/ActionPanel.d.ts +3 -1
- package/lib/cjs/components/SharedComponents/ActionPanel.js +3 -3
- package/lib/cjs/components/SharedComponents/ActionPanel.js.map +1 -1
- package/lib/cjs/formula/FormulaDataTypeResolver.d.ts +3 -2
- package/lib/cjs/formula/FormulaDataTypeResolver.js +10 -6
- package/lib/cjs/formula/FormulaDataTypeResolver.js.map +1 -1
- package/lib/cjs/grouping-mapping-widget.d.ts +0 -2
- package/lib/cjs/grouping-mapping-widget.js +1 -5
- package/lib/cjs/grouping-mapping-widget.js.map +1 -1
- package/lib/esm/WidgetShell/Router/GroupingMappingRouter.js +1 -15
- package/lib/esm/WidgetShell/Router/GroupingMappingRouter.js.map +1 -1
- package/lib/esm/components/Groups/hooks/useKeySetHiliteQueries.d.ts +1 -1
- package/lib/esm/components/Mappings/MappingViewActionGroup.d.ts +1 -1
- package/lib/esm/components/Mappings/MappingViewActionGroup.js +1 -2
- package/lib/esm/components/Mappings/MappingViewActionGroup.js.map +1 -1
- package/lib/esm/components/Mappings/MappingsView.js +1 -1
- package/lib/esm/components/Mappings/MappingsView.js.map +1 -1
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyAction.d.ts +2 -0
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyAction.js +2 -1
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyAction.js.map +1 -1
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.d.ts +7 -8
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.js +23 -60
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.js.map +1 -1
- package/lib/esm/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.d.ts +5 -9
- package/lib/esm/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.js +4 -13
- package/lib/esm/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.js.map +1 -1
- package/lib/esm/components/Properties/CustomCalculations/CustomCalculationAction.d.ts +8 -9
- package/lib/esm/components/Properties/CustomCalculations/CustomCalculationAction.js +18 -142
- package/lib/esm/components/Properties/CustomCalculations/CustomCalculationAction.js.map +1 -1
- package/lib/esm/components/Properties/CustomCalculations/CustomCalculationAction.scss +4 -3
- package/lib/esm/components/Properties/GroupProperties/GroupPropertyAction.js +79 -22
- package/lib/esm/components/Properties/GroupProperties/GroupPropertyAction.js.map +1 -1
- package/lib/esm/components/Properties/GroupProperties/GroupPropertyAction.scss +3 -2
- package/lib/esm/components/Properties/GroupProperties/GroupPropertyTable.js +12 -4
- package/lib/esm/components/Properties/GroupProperties/GroupPropertyTable.js.map +1 -1
- package/lib/esm/components/Properties/PropertyMenu.d.ts +1 -1
- package/lib/esm/components/Properties/PropertyMenu.js +2 -7
- package/lib/esm/components/Properties/PropertyMenu.js.map +1 -1
- package/lib/esm/components/Properties/ScrollableExpandableBlock.d.ts +11 -0
- package/lib/esm/components/Properties/ScrollableExpandableBlock.js +29 -0
- package/lib/esm/components/Properties/ScrollableExpandableBlock.js.map +1 -0
- package/lib/esm/components/Properties/hooks/useFormulaValidation.d.ts +6 -3
- package/lib/esm/components/Properties/hooks/useFormulaValidation.js +57 -12
- package/lib/esm/components/Properties/hooks/useFormulaValidation.js.map +1 -1
- package/lib/esm/components/Properties/hooks/useForwardRef.d.ts +3 -0
- package/lib/esm/components/Properties/hooks/useForwardRef.js +16 -0
- package/lib/esm/components/Properties/hooks/useForwardRef.js.map +1 -0
- package/lib/esm/components/SharedComponents/ActionPanel.d.ts +3 -1
- package/lib/esm/components/SharedComponents/ActionPanel.js +3 -3
- package/lib/esm/components/SharedComponents/ActionPanel.js.map +1 -1
- package/lib/esm/formula/FormulaDataTypeResolver.d.ts +3 -2
- package/lib/esm/formula/FormulaDataTypeResolver.js +10 -6
- package/lib/esm/formula/FormulaDataTypeResolver.js.map +1 -1
- package/lib/esm/grouping-mapping-widget.d.ts +0 -2
- package/lib/esm/grouping-mapping-widget.js +0 -2
- package/lib/esm/grouping-mapping-widget.js.map +1 -1
- package/package.json +1 -1
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyTable.d.ts +0 -14
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyTable.js +0 -87
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyTable.js.map +0 -1
- package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyTable.scss +0 -9
- package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationTable.d.ts +0 -13
- package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationTable.js +0 -91
- package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationTable.js.map +0 -1
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyTable.d.ts +0 -14
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyTable.js +0 -60
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyTable.js.map +0 -1
- package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyTable.scss +0 -9
- package/lib/esm/components/Properties/CustomCalculations/CustomCalculationTable.d.ts +0 -13
- package/lib/esm/components/Properties/CustomCalculations/CustomCalculationTable.js +0 -64
- package/lib/esm/components/Properties/CustomCalculations/CustomCalculationTable.js.map +0 -1
package/lib/cjs/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharedCalculatedPropertyForms.js","sourceRoot":"","sources":["../../../../../src/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,4DAAgE;AAChE,+CAA2C;
|
|
1
|
+
{"version":3,"file":"SharedCalculatedPropertyForms.js","sourceRoot":"","sources":["../../../../../src/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,4DAAgE;AAChE,+CAA2C;AAE3C,wDAAqD;AAS9C,MAAM,6BAA6B,GAAG,CAAC,EAC5C,sBAAsB,EACtB,yBAAyB,EACzB,YAAY,EACZ,oBAAoB,GACe,EAAE,EAAE;IACvC,MAAM,yCAAyC,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QACjE,MAAM,OAAO,GAAuD,EAAE,CAAC;QACvE,MAAM,aAAa,GAAG,wCAA8D,CAAC;QAErF,OAAO,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,6BAA6B,EAAC,CAAC,CAAC;QACvE,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;YAC/B,IAAI,OAAO,aAAa,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,GAAG,KAAK,WAAW,EAAE;gBACjE,mDAAmD;gBACnD,MAAM,KAAK,GAAG,GAAG;qBACd,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;qBAC1B,IAAI,EAAE;qBACN,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;gBAC1C,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,GAAG,CAA2B,EAAE,KAAK,EAAE,CAAC,CAAC;aAC9E;SACF;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL;QACE,8BAAC,6BAAa,IACZ,KAAK,EAAC,0BAA0B,EAChC,OAAO,EAAE,yCAAyC,EAAE,EACpD,KAAK,EAAE,sBAAsB,EAC7B,QAAQ,EAAE,yBAAyB,EACnC,YAAY,EAAE,YAAY,EAC1B,oBAAoB,EAAE,oBAAoB,EAC1C,WAAW,EAAG,6BAA6B,EAC3C,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EACjB,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,GACjB,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AAvCW,QAAA,6BAA6B,iCAuCxC","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 { CalculatedPropertyType } from \"@itwin/insights-client\";\nimport React, { useCallback } from \"react\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { LabeledSelect } from \"@itwin/itwinui-react\";\n\ninterface SharedCalculatedPropertyFormsProps {\n calculatedPropertyType: CalculatedPropertyType | undefined;\n setCalculatedPropertyType: (value: CalculatedPropertyType | undefined) => void;\n itemRenderer?: (option: SelectOption<string | undefined>) => JSX.Element;\n selectedItemRenderer?: (option: SelectOption<string | undefined>) => JSX.Element;\n}\n\nexport const SharedCalculatedPropertyForms = ({\n calculatedPropertyType,\n setCalculatedPropertyType,\n itemRenderer,\n selectedItemRenderer,\n}: SharedCalculatedPropertyFormsProps) => {\n const generateOptionsFromCalculatedPropertyType = useCallback(() => {\n const options: SelectOption<CalculatedPropertyType | undefined>[] = [];\n const indexableEnum = CalculatedPropertyType as unknown as { [key: string]: string };\n \n options.push({value: undefined, label: \"No Calculated Property Type\"});\n for (const key in indexableEnum) {\n if (typeof indexableEnum[key] === \"string\" && key !== \"Undefined\") {\n // Generate labels by adding space between capitals\n const label = key\n .replace(/([A-Z])/g, \" $1\")\n .trim()\n .replace(/^\\w/, (c) => c.toUpperCase());\n options.push({ value: indexableEnum[key] as CalculatedPropertyType, label });\n }\n }\n return options;\n }, []);\n\n return (\n <>\n <LabeledSelect<CalculatedPropertyType | undefined>\n label=\"Calculated Property Type\"\n options={generateOptionsFromCalculatedPropertyType()}\n value={calculatedPropertyType}\n onChange={setCalculatedPropertyType}\n itemRenderer={itemRenderer}\n selectedItemRenderer={selectedItemRenderer}\n placeholder = 'No Calculated Property Type'\n onShow={() => { }}\n onHide={() => { }}\n />\n </>\n );\n};\n"]}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import "./CustomCalculationAction.scss";
|
|
3
|
-
import type { Property } from "@itwin/insights-client";
|
|
4
3
|
/**
|
|
5
4
|
* Props for the {@link CustomCalculationAction} component.
|
|
6
|
-
* @
|
|
5
|
+
* @internal
|
|
7
6
|
*/
|
|
8
7
|
export interface CustomCalculationActionProps {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
formula?: string;
|
|
9
|
+
setFormula: (formula: string | undefined) => void;
|
|
10
|
+
formulaErrorMessage?: string;
|
|
11
|
+
forceValidation: () => void;
|
|
12
|
+
disabled?: boolean;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* Component to create or update a custom calculation property.
|
|
17
|
-
* @
|
|
16
|
+
* @internal
|
|
18
17
|
*/
|
|
19
|
-
export declare const CustomCalculationAction: ({
|
|
18
|
+
export declare const CustomCalculationAction: ({ formula, setFormula, formulaErrorMessage, forceValidation, disabled }: CustomCalculationActionProps) => JSX.Element;
|
|
20
19
|
//# sourceMappingURL=CustomCalculationAction.d.ts.map
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
@@ -32,151 +9,27 @@ exports.CustomCalculationAction = void 0;
|
|
|
32
9
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
33
10
|
*--------------------------------------------------------------------------------------------*/
|
|
34
11
|
const itwinui_react_1 = require("@itwin/itwinui-react");
|
|
35
|
-
const react_1 =
|
|
36
|
-
const ActionPanel_1 = __importDefault(require("../../SharedComponents/ActionPanel"));
|
|
37
|
-
const useValidator_1 = __importStar(require("../hooks/useValidator"));
|
|
38
|
-
const utils_1 = require("../../../common/utils");
|
|
12
|
+
const react_1 = __importDefault(require("react"));
|
|
39
13
|
require("./CustomCalculationAction.scss");
|
|
40
|
-
const GroupPropertyAction_1 = require("../GroupProperties/GroupPropertyAction");
|
|
41
|
-
const useFormulaValidation_1 = require("../hooks/useFormulaValidation");
|
|
42
|
-
const GroupingApiConfigContext_1 = require("../../context/GroupingApiConfigContext");
|
|
43
|
-
const insights_client_1 = require("@itwin/insights-client");
|
|
44
|
-
const usePropertiesQuery_1 = require("../hooks/usePropertiesQuery");
|
|
45
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
46
|
-
const PropertiesClientContext_1 = require("../../context/PropertiesClientContext");
|
|
47
|
-
const stringToPossibleDataType = (str) => {
|
|
48
|
-
switch (str?.toLowerCase()) {
|
|
49
|
-
case "double":
|
|
50
|
-
return "Double";
|
|
51
|
-
case "integer":
|
|
52
|
-
return "Integer";
|
|
53
|
-
case "string":
|
|
54
|
-
return "String";
|
|
55
|
-
case "boolean":
|
|
56
|
-
return "Boolean";
|
|
57
|
-
default:
|
|
58
|
-
return "Undefined";
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const convertToPropertyMap = (properties, selectedPropertyName) => {
|
|
62
|
-
const map = {};
|
|
63
|
-
const selectedLowerName = selectedPropertyName?.toLowerCase();
|
|
64
|
-
properties.forEach((p) => {
|
|
65
|
-
const lowerName = p.propertyName?.toLowerCase();
|
|
66
|
-
if (lowerName && lowerName !== selectedLowerName)
|
|
67
|
-
map[lowerName] = stringToPossibleDataType(p.dataType);
|
|
68
|
-
});
|
|
69
|
-
return map;
|
|
70
|
-
};
|
|
71
|
-
const inferToPropertyDataType = (value) => {
|
|
72
|
-
switch (value) {
|
|
73
|
-
case "Double":
|
|
74
|
-
return insights_client_1.DataType.Double;
|
|
75
|
-
case "Integer":
|
|
76
|
-
return insights_client_1.DataType.Integer;
|
|
77
|
-
case "String":
|
|
78
|
-
return insights_client_1.DataType.String;
|
|
79
|
-
case "Boolean":
|
|
80
|
-
return insights_client_1.DataType.Boolean;
|
|
81
|
-
default:
|
|
82
|
-
return insights_client_1.DataType.String;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
14
|
/**
|
|
86
15
|
* Component to create or update a custom calculation property.
|
|
87
|
-
* @
|
|
16
|
+
* @internal
|
|
88
17
|
*/
|
|
89
|
-
const CustomCalculationAction = ({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}, [groupProperties]);
|
|
105
|
-
const { mutate: saveMutation, isLoading: isSaving } = (0, react_query_1.useMutation)(async () => {
|
|
106
|
-
const accessToken = await getAccessToken();
|
|
107
|
-
if (customCalculation) {
|
|
108
|
-
return propertiesClient.updateProperty(accessToken, mappingId, groupId, customCalculation.id, {
|
|
109
|
-
propertyName,
|
|
110
|
-
dataType: customCalculation.dataType,
|
|
111
|
-
formula,
|
|
112
|
-
quantityType,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
if (inferredDataType) {
|
|
116
|
-
return propertiesClient.createProperty(accessToken, mappingId, groupId, {
|
|
117
|
-
propertyName,
|
|
118
|
-
dataType: inferToPropertyDataType(inferredDataType),
|
|
119
|
-
formula,
|
|
120
|
-
quantityType,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return;
|
|
124
|
-
}, {
|
|
125
|
-
onSuccess: async () => {
|
|
126
|
-
await queryClient.invalidateQueries({ queryKey: ["properties", iModelId, mappingId, groupId] });
|
|
127
|
-
onSaveSuccess();
|
|
128
|
-
setPropertyName("");
|
|
129
|
-
setFormula("");
|
|
130
|
-
setQuantityType(undefined);
|
|
131
|
-
},
|
|
132
|
-
onError: async (error) => {
|
|
133
|
-
if (error.status === 422) {
|
|
134
|
-
const erroredResponse = await error.json();
|
|
135
|
-
if (erroredResponse.error.code === "InvalidInsightsRequest" && erroredResponse.error.target === "formula") {
|
|
136
|
-
setFormulaErrorMessage(erroredResponse.error.message);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
(0, utils_1.handleError)(error.status);
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
const onSave = () => {
|
|
145
|
-
if (!validator.allValid()) {
|
|
146
|
-
showValidationMessage(true);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (!forceValidation()) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
saveMutation();
|
|
153
|
-
};
|
|
154
|
-
const isLoading = isSaving || isLoadingGroupProperties;
|
|
155
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
156
|
-
react_1.default.createElement("div", { className: "gmw-custom-calculation-action-container" },
|
|
157
|
-
react_1.default.createElement(itwinui_react_1.Fieldset, { legend: "Custom Calculation Details", className: "gmw-details-form" },
|
|
158
|
-
react_1.default.createElement(itwinui_react_1.Text, { variant: "small", as: "small", className: "gmw-field-legend" }, "Asterisk * indicates mandatory fields."),
|
|
159
|
-
react_1.default.createElement(itwinui_react_1.LabeledInput, { value: propertyName, required: true, name: "name", label: "Name", disabled: isLoading, onChange: (event) => {
|
|
160
|
-
setPropertyName(event.target.value);
|
|
161
|
-
validator.showMessageFor("name");
|
|
162
|
-
}, message: validator.message("name", propertyName, useValidator_1.NAME_REQUIREMENTS), status: validator.message("name", propertyName, useValidator_1.NAME_REQUIREMENTS) ? "negative" : undefined, onBlur: () => {
|
|
163
|
-
validator.showMessageFor("name");
|
|
164
|
-
}, onBlurCapture: (event) => {
|
|
165
|
-
setPropertyName(event.target.value);
|
|
166
|
-
validator.showMessageFor("name");
|
|
167
|
-
} }),
|
|
168
|
-
react_1.default.createElement(itwinui_react_1.Alert, { type: "informational", clickableText: "Click here.", clickableTextProps: {
|
|
169
|
-
href: "https://developer.bentley.com/apis/grouping-and-mapping/operations/create-property/#customcalculations",
|
|
170
|
-
target: "_blank",
|
|
171
|
-
rel: "noreferrer",
|
|
172
|
-
} }, "To learn more about creating custom calculation formulas, view the documentation."),
|
|
173
|
-
react_1.default.createElement(itwinui_react_1.LabeledTextarea, { value: formula, required: true, name: "formula", label: "Formula", disabled: isLoading, onChange: (event) => {
|
|
174
|
-
setFormula(event.target.value);
|
|
175
|
-
}, message: formulaErrorMessage, status: formulaErrorMessage ? "negative" : undefined, onBlurCapture: () => {
|
|
176
|
-
forceValidation();
|
|
177
|
-
} }),
|
|
178
|
-
react_1.default.createElement(itwinui_react_1.LabeledSelect, { label: "Quantity Type", disabled: isLoading, options: GroupPropertyAction_1.quantityTypesSelectionOptions, value: quantityType, onChange: setQuantityType, onShow: () => { }, onHide: () => { }, placeholder: "No Quantity Type" }))),
|
|
179
|
-
react_1.default.createElement(ActionPanel_1.default, { onSave: onSave, onCancel: onClickCancel, isSavingDisabled: !(formula && propertyName && isValid), isLoading: isLoading })));
|
|
18
|
+
const CustomCalculationAction = ({ formula, setFormula, formulaErrorMessage, forceValidation, disabled }) => {
|
|
19
|
+
return (react_1.default.createElement(itwinui_react_1.InputGroup, { className: "gmw-custom-calculation-action-container" },
|
|
20
|
+
react_1.default.createElement(itwinui_react_1.Alert, { type: "informational", clickableText: "Click here.", clickableTextProps: {
|
|
21
|
+
href: "https://developer.bentley.com/apis/grouping-and-mapping/operations/create-property/#customcalculations",
|
|
22
|
+
target: "_blank",
|
|
23
|
+
rel: "noreferrer",
|
|
24
|
+
} }, "To learn more about creating custom calculation formulas, view the documentation."),
|
|
25
|
+
react_1.default.createElement(itwinui_react_1.LabeledTextarea, { className: "gmw-details-form", value: formula, name: "formula", label: "Formula", disabled: disabled, onChange: (event) => {
|
|
26
|
+
setFormula(event.target.value);
|
|
27
|
+
}, message: formulaErrorMessage, status: formulaErrorMessage ? "negative" : undefined, onBlur: (event) => {
|
|
28
|
+
if (event.target.textLength === 0)
|
|
29
|
+
setFormula(undefined);
|
|
30
|
+
}, onBlurCapture: () => {
|
|
31
|
+
forceValidation();
|
|
32
|
+
} })));
|
|
180
33
|
};
|
|
181
34
|
exports.CustomCalculationAction = CustomCalculationAction;
|
|
182
35
|
//# sourceMappingURL=CustomCalculationAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomCalculationAction.js","sourceRoot":"","sources":["../../../../../src/components/Properties/CustomCalculations/CustomCalculationAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,wDAA2G;AAC3G,+CAAmD;AACnD,qFAA6D;AAC7D,sEAAwE;AACxE,iDAAoD;AACpD,0CAAwC;AACxC,gFAAuF;AACvF,wEAAqE;AAErE,qFAAqF;AAErF,4DAAkD;AAElD,oEAAiE;AACjE,uDAAoE;AACpE,mFAA4E;AAc5E,MAAM,wBAAwB,GAAG,CAAC,GAAY,EAAoB,EAAE;IAClE,QAAQ,GAAG,EAAE,WAAW,EAAE,EAAE;QAC1B,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,WAAW,CAAC;KACtB;AACH,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,UAAsB,EAAE,oBAA6B,EAAe,EAAE;IAClG,MAAM,GAAG,GAAgB,EAAE,CAAC;IAC5B,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wBAClB,IAAI,EAAE,wGAAwG;wBAC9G,MAAM,EAAE,QAAQ;wBAChB,GAAG,EAAE,YAAY;qBAClB,wFAGK;gBACR,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,EACpD,aAAa,EAAE,GAAG,EAAE;wBAClB,eAAe,EAAE,CAAC;oBACpB,CAAC,GACD;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,GAAE,CAAC,EAChB,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC,EAChB,WAAW,EAAC,kBAAkB,GAC9B,CACO,CACP;QACN,8BAAC,qBAAW,IAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC,CAAC,OAAO,IAAI,YAAY,IAAI,OAAO,CAAC,EAAE,SAAS,EAAE,SAAS,GAAI,CACtI,CACJ,CAAC;AACJ,CAAC,CAAC;AAhJW,QAAA,uBAAuB,2BAgJlC","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 { Alert, Fieldset, LabeledInput, LabeledSelect, LabeledTextarea, Text } from \"@itwin/itwinui-react\";\nimport React, { useEffect, useState } from \"react\";\nimport ActionPanel from \"../../SharedComponents/ActionPanel\";\nimport useValidator, { NAME_REQUIREMENTS } from \"../hooks/useValidator\";\nimport { handleError } from \"../../../common/utils\";\nimport \"./CustomCalculationAction.scss\";\nimport { quantityTypesSelectionOptions } from \"../GroupProperties/GroupPropertyAction\";\nimport { useFormulaValidation } from \"../hooks/useFormulaValidation\";\nimport type { PossibleDataType, PropertyMap } from \"../../../formula/Types\";\nimport { useGroupingMappingApiConfig } from \"../../context/GroupingApiConfigContext\";\nimport type { Property, QuantityType } from \"@itwin/insights-client\";\nimport { DataType } from \"@itwin/insights-client\";\nimport type { DataType as FormulaDataType } from \"../../../formula/Types\";\nimport { usePropertiesQuery } from \"../hooks/usePropertiesQuery\";\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { usePropertiesClient } from \"../../context/PropertiesClientContext\";\n\n/**\n * Props for the {@link CustomCalculationAction} component.\n * @public\n */\nexport interface CustomCalculationActionProps {\n mappingId: string;\n groupId: string;\n customCalculation?: Property;\n onSaveSuccess: () => void;\n onClickCancel?: () => void;\n}\n\nconst stringToPossibleDataType = (str?: string): PossibleDataType => {\n switch (str?.toLowerCase()) {\n case \"double\":\n return \"Double\";\n case \"integer\":\n return \"Integer\";\n case \"string\":\n return \"String\";\n case \"boolean\":\n return \"Boolean\";\n default:\n return \"Undefined\";\n }\n};\n\nconst convertToPropertyMap = (properties: Property[], selectedPropertyName?: string): PropertyMap => {\n const map: PropertyMap = {};\n const selectedLowerName = selectedPropertyName?.toLowerCase();\n\n properties.forEach((p) => {\n const lowerName = p.propertyName?.toLowerCase();\n if (lowerName && lowerName !== selectedLowerName) map[lowerName] = stringToPossibleDataType(p.dataType);\n });\n\n return map;\n};\n\nconst inferToPropertyDataType = (value: FormulaDataType): DataType => {\n switch (value) {\n case \"Double\":\n return DataType.Double;\n case \"Integer\":\n return DataType.Integer;\n case \"String\":\n return DataType.String;\n case \"Boolean\":\n return DataType.Boolean;\n default:\n return DataType.String;\n }\n};\n\n/**\n * Component to create or update a custom calculation property.\n * @public\n */\nexport const CustomCalculationAction = ({ mappingId, groupId, customCalculation, onSaveSuccess, onClickCancel }: CustomCalculationActionProps) => {\n const { getAccessToken, iModelId } = useGroupingMappingApiConfig();\n const propertiesClient = usePropertiesClient();\n const [propertyName, setPropertyName] = useState<string>(customCalculation?.propertyName ?? \"\");\n const [formula, setFormula] = useState<string>(customCalculation?.formula ?? \"\");\n const [quantityType, setQuantityType] = useState<QuantityType | undefined>(customCalculation?.quantityType ?? undefined);\n const [formulaErrorMessage, setFormulaErrorMessage] = useState<string>(\"\");\n const [validator, showValidationMessage] = useValidator();\n const [properties, setProperties] = useState<PropertyMap>({});\n const { isValid, forceValidation, inferredDataType } = useFormulaValidation(propertyName.toLowerCase(), formula, properties, setFormulaErrorMessage);\n const queryClient = useQueryClient();\n\n const { data: groupProperties, isFetching: isLoadingGroupProperties } = usePropertiesQuery(iModelId, mappingId, groupId, getAccessToken, propertiesClient);\n\n useEffect(() => {\n const propertiesMap = convertToPropertyMap(groupProperties?.properties ?? []);\n setProperties(propertiesMap);\n }, [groupProperties]);\n\n const { mutate: saveMutation, isLoading: isSaving } = useMutation(\n async () => {\n const accessToken = await getAccessToken();\n\n if (customCalculation) {\n return propertiesClient.updateProperty(accessToken, mappingId, groupId, customCalculation.id, {\n propertyName,\n dataType: customCalculation.dataType,\n formula,\n quantityType,\n });\n }\n\n if (inferredDataType) {\n return propertiesClient.createProperty(accessToken, mappingId, groupId, {\n propertyName,\n dataType: inferToPropertyDataType(inferredDataType),\n formula,\n quantityType,\n });\n }\n return;\n },\n {\n onSuccess: async () => {\n await queryClient.invalidateQueries({ queryKey: [\"properties\", iModelId, mappingId, groupId] });\n onSaveSuccess();\n setPropertyName(\"\");\n setFormula(\"\");\n setQuantityType(undefined);\n },\n onError: async (error: any) => {\n if (error.status === 422) {\n const erroredResponse = await error.json();\n if (erroredResponse.error.code === \"InvalidInsightsRequest\" && erroredResponse.error.target === \"formula\") {\n setFormulaErrorMessage(erroredResponse.error.message);\n }\n } else {\n handleError(error.status);\n }\n },\n },\n );\n\n const onSave = () => {\n if (!validator.allValid()) {\n showValidationMessage(true);\n return;\n }\n if (!forceValidation()) {\n return;\n }\n saveMutation();\n };\n\n const isLoading = isSaving || isLoadingGroupProperties;\n\n return (\n <>\n <div className=\"gmw-custom-calculation-action-container\">\n <Fieldset legend=\"Custom Calculation Details\" className=\"gmw-details-form\">\n <Text variant=\"small\" as=\"small\" className=\"gmw-field-legend\">\n Asterisk * indicates mandatory fields.\n </Text>\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={validator.message(\"name\", propertyName, NAME_REQUIREMENTS) ? \"negative\" : undefined}\n onBlur={() => {\n validator.showMessageFor(\"name\");\n }}\n onBlurCapture={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"name\");\n }}\n />\n <Alert\n type=\"informational\"\n clickableText=\"Click here.\"\n clickableTextProps={{\n href: \"https://developer.bentley.com/apis/grouping-and-mapping/operations/create-property/#customcalculations\",\n target: \"_blank\",\n rel: \"noreferrer\",\n }}\n >\n To learn more about creating custom calculation formulas, view the documentation.\n </Alert>\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 onBlurCapture={() => {\n forceValidation();\n }}\n />\n <LabeledSelect<QuantityType | undefined>\n label=\"Quantity Type\"\n disabled={isLoading}\n options={quantityTypesSelectionOptions}\n value={quantityType}\n onChange={setQuantityType}\n onShow={() => {}}\n onHide={() => {}}\n placeholder=\"No Quantity Type\"\n />\n </Fieldset>\n </div>\n <ActionPanel onSave={onSave} onCancel={onClickCancel} isSavingDisabled={!(formula && propertyName && isValid)} isLoading={isLoading} />\n </>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"CustomCalculationAction.js","sourceRoot":"","sources":["../../../../../src/components/Properties/CustomCalculations/CustomCalculationAction.tsx"],"names":[],"mappings":";;;;;;AAAA;;;gGAGgG;AAChG,wDAA0E;AAC1E,kDAA0B;AAC1B,0CAAwC;AAcxC;;;GAGG;AACI,MAAM,uBAAuB,GAAG,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,QAAQ,EAAgC,EAAE,EAAE;IAC/I,OAAO,CACL,8BAAC,0BAAU,IAAC,SAAS,EAAC,yCAAyC;QAC7D,8BAAC,qBAAK,IACJ,IAAI,EAAC,eAAe,EACpB,aAAa,EAAC,aAAa,EAC3B,kBAAkB,EAAE;gBAClB,IAAI,EAAE,wGAAwG;gBAC9G,MAAM,EAAE,QAAQ;gBAChB,GAAG,EAAE,YAAY;aAClB,wFAGK;QACR,8BAAC,+BAAe,IACd,SAAS,EAAC,kBAAkB,EAC5B,KAAK,EAAE,OAAO,EACd,IAAI,EAAC,SAAS,EACd,KAAK,EAAC,SAAS,EACf,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;gBAClB,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACjC,CAAC,EACD,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,EACpD,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;gBAChB,IAAI,KAAK,CAAC,MAAM,CAAC,UAAU,KAAK,CAAC;oBAAE,UAAU,CAAC,SAAS,CAAC,CAAC;YAC3D,CAAC,EACD,aAAa,EAAE,GAAG,EAAE;gBAClB,eAAe,EAAE,CAAC;YACpB,CAAC,GACD,CACS,CACd,CAAC;AACJ,CAAC,CAAC;AAlCW,QAAA,uBAAuB,2BAkClC","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 { Alert, InputGroup, LabeledTextarea } from \"@itwin/itwinui-react\";\nimport React from \"react\";\nimport \"./CustomCalculationAction.scss\";\n\n/**\n * Props for the {@link CustomCalculationAction} component.\n * @internal\n */\nexport interface CustomCalculationActionProps {\n formula?: string;\n setFormula: (formula: string | undefined) => void;\n formulaErrorMessage?: string;\n forceValidation: () => void;\n disabled?: boolean;\n}\n\n/**\n * Component to create or update a custom calculation property.\n * @internal\n */\nexport const CustomCalculationAction = ({ formula, setFormula, formulaErrorMessage, forceValidation, disabled }: CustomCalculationActionProps) => {\n return (\n <InputGroup className=\"gmw-custom-calculation-action-container\">\n <Alert\n type=\"informational\"\n clickableText=\"Click here.\"\n clickableTextProps={{\n href: \"https://developer.bentley.com/apis/grouping-and-mapping/operations/create-property/#customcalculations\",\n target: \"_blank\",\n rel: \"noreferrer\",\n }}\n >\n To learn more about creating custom calculation formulas, view the documentation.\n </Alert>\n <LabeledTextarea\n className=\"gmw-details-form\"\n value={formula}\n name=\"formula\"\n label=\"Formula\"\n disabled={disabled}\n onChange={(event) => {\n setFormula(event.target.value);\n }}\n message={formulaErrorMessage}\n status={formulaErrorMessage ? \"negative\" : undefined}\n onBlur={(event) => {\n if (event.target.textLength === 0) setFormula(undefined);\n }}\n onBlurCapture={() => {\n forceValidation();\n }}\n />\n </InputGroup>\n );\n};\n"]}
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
|
|
6
6
|
.gmw-custom-calculation-action-container {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
7
9
|
overflow-x: auto;
|
|
8
10
|
height: 100%;
|
|
11
|
+
gap: var(--iui-size-s);
|
|
9
12
|
|
|
10
13
|
.gmw-details-form {
|
|
11
|
-
|
|
12
|
-
flex-direction: column;
|
|
13
|
-
gap: var(--iui-size-s);
|
|
14
|
+
padding-top: var(--iui-size-s);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -46,6 +46,13 @@ const GroupsPropertiesSelectionModal_1 = require("./GroupsPropertiesSelectionMod
|
|
|
46
46
|
const react_query_1 = require("@tanstack/react-query");
|
|
47
47
|
const GroupPropertyListItem_1 = require("./GroupPropertyListItem");
|
|
48
48
|
const PropertiesClientContext_1 = require("../../context/PropertiesClientContext");
|
|
49
|
+
const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
|
|
50
|
+
const CalculatedPropertyActionWithVisuals_1 = require("../CalculatedProperties/CalculatedPropertyActionWithVisuals");
|
|
51
|
+
const utils_1 = require("../../../common/utils");
|
|
52
|
+
const CustomCalculationAction_1 = require("../CustomCalculations/CustomCalculationAction");
|
|
53
|
+
const usePropertiesQuery_1 = require("../hooks/usePropertiesQuery");
|
|
54
|
+
const useFormulaValidation_1 = require("../hooks/useFormulaValidation");
|
|
55
|
+
const ScrollableExpandableBlock_1 = require("../ScrollableExpandableBlock");
|
|
49
56
|
exports.quantityTypesSelectionOptions = [
|
|
50
57
|
{ value: insights_client_1.QuantityType.Area, label: "Area" },
|
|
51
58
|
{ value: insights_client_1.QuantityType.Distance, label: "Distance" },
|
|
@@ -61,23 +68,35 @@ exports.quantityTypesSelectionOptions = [
|
|
|
61
68
|
* @public
|
|
62
69
|
*/
|
|
63
70
|
const GroupPropertyAction = ({ mappingId, group, groupProperty, onSaveSuccess, onClickCancel }) => {
|
|
64
|
-
const
|
|
71
|
+
const actionContainerRef = (0, react_1.useRef)(null);
|
|
72
|
+
const calculatedPropertyActionRef = (0, react_1.useRef)(null);
|
|
73
|
+
const customCalculationActionRef = (0, react_1.useRef)(null);
|
|
65
74
|
const propertiesClient = (0, PropertiesClientContext_1.usePropertiesClient)();
|
|
75
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
66
76
|
const [propertyName, setPropertyName] = (0, react_1.useState)("");
|
|
67
77
|
const [oldPropertyName, setOldPropertyName] = (0, react_1.useState)("");
|
|
68
|
-
const [dataType, setDataType] = (0, react_1.useState)(insights_client_1.DataType.String);
|
|
69
|
-
const [quantityType, setQuantityType] = (0, react_1.useState)();
|
|
78
|
+
const [dataType, setDataType] = (0, react_1.useState)(groupProperty?.dataType ?? insights_client_1.DataType.String);
|
|
79
|
+
const [quantityType, setQuantityType] = (0, react_1.useState)(groupProperty?.quantityType ?? undefined);
|
|
70
80
|
const [selectedProperties, setSelectedProperties] = (0, react_1.useState)([]);
|
|
71
81
|
const [propertiesMetaData, setPropertiesMetaData] = (0, react_1.useState)([]);
|
|
72
82
|
const [propertiesNotFoundAlert, setPropertiesNotFoundAlert] = (0, react_1.useState)(false);
|
|
73
83
|
const [validator, showValidationMessage] = (0, useValidator_1.default)();
|
|
74
84
|
const [showPropertiesSelectionModal, setShowPropertiesSelectionModal] = (0, react_1.useState)(false);
|
|
75
85
|
const [showSaveConfirmationModal, setShowSaveConfirmationModal] = (0, react_1.useState)(false);
|
|
76
|
-
const
|
|
86
|
+
const [calculatedPropertyType, setCalculatedPropertyType] = (0, react_1.useState)(groupProperty?.calculatedPropertyType ?? undefined);
|
|
87
|
+
const [isCalculatedBlockExpanded, setIsCalculatedBlockExpanded] = (0, react_1.useState)(!!calculatedPropertyType);
|
|
88
|
+
const [formula, setFormula] = (0, react_1.useState)(groupProperty?.formula ?? undefined);
|
|
89
|
+
const [formulaErrorMessage, setFormulaErrorMessage] = (0, react_1.useState)(undefined);
|
|
90
|
+
const { getAccessToken, iModelId, iModelConnection } = (0, GroupingApiConfigContext_1.useGroupingMappingApiConfig)();
|
|
91
|
+
const { data: groupProperties, isFetching: isLoadingGroupProperties } = (0, usePropertiesQuery_1.usePropertiesQuery)(iModelId, mappingId, group.id, getAccessToken, propertiesClient);
|
|
92
|
+
const { forceValidation } = (0, useFormulaValidation_1.useFormulaValidation)(propertyName.toLowerCase(), formula, groupProperties?.properties ?? [], setFormulaErrorMessage, dataType);
|
|
77
93
|
const reset = (0, react_1.useCallback)(() => {
|
|
78
94
|
setPropertyName("");
|
|
79
95
|
setDataType(insights_client_1.DataType.String);
|
|
96
|
+
setQuantityType(undefined);
|
|
80
97
|
setSelectedProperties([]);
|
|
98
|
+
setCalculatedPropertyType(undefined);
|
|
99
|
+
setFormula(undefined);
|
|
81
100
|
}, []);
|
|
82
101
|
const fetchPropertiesMetadata = (0, react_1.useCallback)(async () => {
|
|
83
102
|
if (!iModelConnection)
|
|
@@ -95,6 +114,16 @@ const GroupPropertyAction = ({ mappingId, group, groupProperty, onSaveSuccess, o
|
|
|
95
114
|
}
|
|
96
115
|
return { propertiesMetaData, groupPropertyDetails };
|
|
97
116
|
}, [getAccessToken, group.id, group.query, groupProperty, iModelConnection, mappingId, propertiesClient]);
|
|
117
|
+
const scrollToFormulaErrorMessage = (0, react_1.useCallback)(() => {
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
if (actionContainerRef.current && customCalculationActionRef.current) {
|
|
120
|
+
actionContainerRef.current.scrollTo({
|
|
121
|
+
top: customCalculationActionRef.current.offsetTop,
|
|
122
|
+
behavior: "smooth",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}, 500);
|
|
126
|
+
}, [actionContainerRef]);
|
|
98
127
|
const { data, isFetching: isLoadingProperties, isSuccess: isLoadingPropertiesSuccessful, } = (0, react_query_1.useQuery)(["properties", iModelId, mappingId, group.id, groupProperty?.id, "metadata"], fetchPropertiesMetadata);
|
|
99
128
|
(0, react_1.useEffect)(() => {
|
|
100
129
|
if (isLoadingPropertiesSuccessful && data?.propertiesMetaData) {
|
|
@@ -105,14 +134,29 @@ const GroupPropertyAction = ({ mappingId, group, groupProperty, onSaveSuccess, o
|
|
|
105
134
|
setDataType(data.groupPropertyDetails.dataType);
|
|
106
135
|
if (data.groupPropertyDetails.quantityType)
|
|
107
136
|
setQuantityType(data.groupPropertyDetails.quantityType);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
137
|
+
if (data.groupPropertyDetails.ecProperties) {
|
|
138
|
+
const properties = (0, GroupPropertyUtils_1.findProperties)(data.groupPropertyDetails.ecProperties, data.propertiesMetaData);
|
|
139
|
+
if (properties.length === 0) {
|
|
140
|
+
setPropertiesNotFoundAlert(true);
|
|
141
|
+
}
|
|
142
|
+
setSelectedProperties(properties);
|
|
111
143
|
}
|
|
112
|
-
setSelectedProperties(properties);
|
|
113
144
|
}
|
|
114
145
|
}
|
|
115
146
|
}, [data, isLoadingPropertiesSuccessful]);
|
|
147
|
+
(0, react_1.useEffect)(() => {
|
|
148
|
+
if (calculatedPropertyType) {
|
|
149
|
+
setDataType(insights_client_1.DataType.Double);
|
|
150
|
+
}
|
|
151
|
+
if (isCalculatedBlockExpanded === false || !calculatedPropertyType) {
|
|
152
|
+
(0, viewerUtils_1.clearAll)();
|
|
153
|
+
}
|
|
154
|
+
}, [calculatedPropertyType, isCalculatedBlockExpanded]);
|
|
155
|
+
(0, react_1.useEffect)(() => {
|
|
156
|
+
if (formulaErrorMessage) {
|
|
157
|
+
scrollToFormulaErrorMessage();
|
|
158
|
+
}
|
|
159
|
+
}, [formulaErrorMessage, scrollToFormulaErrorMessage]);
|
|
116
160
|
const { mutate: onSave, isLoading: isSaving } = (0, react_query_1.useMutation)({
|
|
117
161
|
mutationFn: async () => {
|
|
118
162
|
const accessToken = await getAccessToken();
|
|
@@ -121,6 +165,8 @@ const GroupPropertyAction = ({ mappingId, group, groupProperty, onSaveSuccess, o
|
|
|
121
165
|
dataType,
|
|
122
166
|
quantityType,
|
|
123
167
|
ecProperties: selectedProperties.map((p) => (0, GroupPropertyUtils_1.convertToECProperties)(p)).flat(),
|
|
168
|
+
calculatedPropertyType,
|
|
169
|
+
formula,
|
|
124
170
|
};
|
|
125
171
|
return groupProperty
|
|
126
172
|
? propertiesClient.updateProperty(accessToken, mappingId, group.id, groupProperty.id, newGroupProperty)
|
|
@@ -131,6 +177,9 @@ const GroupPropertyAction = ({ mappingId, group, groupProperty, onSaveSuccess, o
|
|
|
131
177
|
reset();
|
|
132
178
|
await queryClient.invalidateQueries(["properties", iModelId, mappingId, group.id]);
|
|
133
179
|
},
|
|
180
|
+
onError(error) {
|
|
181
|
+
(0, utils_1.handleError)(error.status);
|
|
182
|
+
},
|
|
134
183
|
});
|
|
135
184
|
const handleSaveClick = async () => {
|
|
136
185
|
if (!validator.allValid()) {
|
|
@@ -147,9 +196,9 @@ const GroupPropertyAction = ({ mappingId, group, groupProperty, onSaveSuccess, o
|
|
|
147
196
|
const handleCloseSaveModal = () => {
|
|
148
197
|
setShowSaveConfirmationModal(false);
|
|
149
198
|
};
|
|
150
|
-
const isLoading = isLoadingProperties || isSaving;
|
|
199
|
+
const isLoading = isLoadingProperties || isSaving || isLoadingGroupProperties;
|
|
151
200
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
152
|
-
react_1.default.createElement("div", { className: "gmw-group-property-action-container" },
|
|
201
|
+
react_1.default.createElement("div", { className: "gmw-group-property-action-container", ref: actionContainerRef },
|
|
153
202
|
react_1.default.createElement(itwinui_react_1.Fieldset, { disabled: isLoading, className: "gmw-property-options", legend: "Property Details" },
|
|
154
203
|
react_1.default.createElement(itwinui_react_1.Text, { variant: "small", as: "small", className: "gmw-field-legend" }, "Asterisk * indicates mandatory fields."),
|
|
155
204
|
react_1.default.createElement(itwinui_react_1.LabeledInput, { id: "propertyName", label: "Property Name", value: propertyName, required: true, onChange: (event) => {
|
|
@@ -163,21 +212,29 @@ const GroupPropertyAction = ({ mappingId, group, groupProperty, onSaveSuccess, o
|
|
|
163
212
|
{ value: insights_client_1.DataType.Integer, label: "Integer" },
|
|
164
213
|
{ value: insights_client_1.DataType.Double, label: "Double" },
|
|
165
214
|
{ value: insights_client_1.DataType.String, label: "String" },
|
|
166
|
-
], required: true, value: dataType, onChange: (value) => {
|
|
215
|
+
], required: true, value: calculatedPropertyType ? insights_client_1.DataType.Double : dataType, onChange: (value) => {
|
|
167
216
|
validator.showMessageFor("dataType");
|
|
168
217
|
setDataType(value);
|
|
169
218
|
}, message: validator.message("dataType", propertyName, "required"), status: validator.message("dataType", propertyName, "required") ? "negative" : undefined, onBlur: () => {
|
|
170
219
|
validator.showMessageFor("dataType");
|
|
171
|
-
}, onShow: () => { }, onHide: () => { } }),
|
|
220
|
+
}, disabled: calculatedPropertyType ? true : false, onShow: () => { }, onHide: () => { } }),
|
|
172
221
|
react_1.default.createElement(itwinui_react_1.LabeledSelect, { label: "Quantity Type", options: exports.quantityTypesSelectionOptions, value: quantityType, onChange: setQuantityType, onShow: () => { }, onHide: () => { }, placeholder: "No Quantity Type" })),
|
|
173
222
|
propertiesNotFoundAlert && (react_1.default.createElement(itwinui_react_1.Alert, { type: "warning" }, "Warning: Could not match saved properties from the current generated list. It does not confirm or deny validity. Overwriting will occur if a new selection is made and saved.")),
|
|
174
|
-
react_1.default.createElement(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
react_1.default.createElement(
|
|
180
|
-
|
|
223
|
+
react_1.default.createElement(ScrollableExpandableBlock_1.ScrollableExpandableBlock, { title: "Mapped Properties", endIcon: react_1.default.createElement(itwinui_react_1.Icon, { fill: selectedProperties.length > 0 ? "informational" : "default" },
|
|
224
|
+
react_1.default.createElement(itwinui_icons_react_1.SvgLabel, null)), isExpanded: selectedProperties.length > 0, setIsExpanded: () => { } },
|
|
225
|
+
react_1.default.createElement("div", { className: "gmw-property-view-container" },
|
|
226
|
+
react_1.default.createElement("div", { className: "gmw-property-view-button" },
|
|
227
|
+
react_1.default.createElement(itwinui_react_1.Button, { onClick: async () => setShowPropertiesSelectionModal(true), disabled: isLoading }, "Select Properties")),
|
|
228
|
+
react_1.default.createElement("div", { className: "gmw-properties-list" }, selectedProperties.length === 0 && !isLoading ? (react_1.default.createElement("div", { className: "gmw-empty-selection" },
|
|
229
|
+
react_1.default.createElement(itwinui_react_1.Text, null, "No properties selected."),
|
|
230
|
+
react_1.default.createElement(itwinui_react_1.Text, null, "Press the \"Select Properties\" button for options."))) : (selectedProperties.map((property) => (react_1.default.createElement(GroupPropertyListItem_1.GroupPropertyListItem, { key: property.key, content: `${property.displayLabel}`, title: `${property.actualECClassName}`, description: property.categoryLabel }))))))),
|
|
231
|
+
react_1.default.createElement(ScrollableExpandableBlock_1.ScrollableExpandableBlock, { parentRef: actionContainerRef, ref: calculatedPropertyActionRef, title: "Calculated Property", endIcon: react_1.default.createElement(itwinui_react_1.Icon, { fill: calculatedPropertyType ? "informational" : "default" },
|
|
232
|
+
react_1.default.createElement(itwinui_icons_react_1.SvgMeasure, null)), isExpanded: !!calculatedPropertyType, setIsExpanded: setIsCalculatedBlockExpanded },
|
|
233
|
+
react_1.default.createElement(CalculatedPropertyActionWithVisuals_1.CalculatedPropertyActionWithVisuals, { group: group, calculatedPropertyType: calculatedPropertyType, setCalculatedPropertyType: setCalculatedPropertyType })),
|
|
234
|
+
react_1.default.createElement(ScrollableExpandableBlock_1.ScrollableExpandableBlock, { parentRef: actionContainerRef, ref: customCalculationActionRef, title: "Custom Calculation", endIcon: react_1.default.createElement(itwinui_react_1.Icon, { fill: formula ? "informational" : "default" },
|
|
235
|
+
react_1.default.createElement(itwinui_icons_react_1.SvgFunction, null)), isExpanded: formula !== undefined, setIsExpanded: () => { } },
|
|
236
|
+
react_1.default.createElement(CustomCalculationAction_1.CustomCalculationAction, { formula: formula, setFormula: setFormula, formulaErrorMessage: formulaErrorMessage, forceValidation: forceValidation, disabled: isLoading }))),
|
|
237
|
+
react_1.default.createElement(ActionPanel_1.default, { onSave: handleSaveClick, onCancel: onClickCancel, onSaveCapture: viewerUtils_1.clearAll, onCancelCapture: viewerUtils_1.clearAll, isLoading: isLoading, isSavingDisabled: !propertyName || dataType === undefined || formulaErrorMessage !== undefined }),
|
|
181
238
|
react_1.default.createElement(GroupsPropertiesSelectionModal_1.GroupsPropertiesSelectionModal, { showModal: showPropertiesSelectionModal, setShowModal: setShowPropertiesSelectionModal, selectedProperties: selectedProperties, setSelectedProperties: setSelectedProperties, propertiesMetaData: propertiesMetaData }),
|
|
182
239
|
react_1.default.createElement(SaveModal_1.SaveModal, { onSave: onSave, onClose: handleCloseSaveModal, showSaveModal: showSaveConfirmationModal })));
|
|
183
240
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupPropertyAction.js","sourceRoot":"","sources":["../../../../../src/components/Properties/GroupProperties/GroupPropertyAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,oEAAiE;AAEjE,wDAAkG;AAClG,+CAAgE;AAChE,qFAA6D;AAC7D,sEAAwE;AACxE,qFAAqF;AACrF,4DAAgE;AAEhE,sCAAoC;AAEpC,6DAAqI;AACrI,6DAA8D;AAC9D,2CAAwC;AACxC,qFAAkF;AAClF,uDAA8E;AAC9E,mEAAgE;AAChE,mFAA4E;AAc/D,QAAA,6BAA6B,GAA6C;IACrF,EAAE,KAAK,EAAE,8BAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;IAC3C,EAAE,KAAK,EAAE,8BAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE;IACnD,EAAE,KAAK,EAAE,8BAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE;IAC7C,EAAE,KAAK,EAAE,8BAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;IAC3C,EAAE,KAAK,EAAE,8BAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE;IACnD,EAAE,KAAK,EAAE,8BAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;IAC3C,EAAE,KAAK,EAAE,8BAAY,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE;IAC/C,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,kBAAkB,EAAE;CAChD,CAAC;AAEF;;;GAGG;A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C,oBAAI,kCAA+B;oBACpC,8BAAC,oBAAI,8DAAmE,CACpE,CACP,CAAC,CAAC,CAAC,CACF,kBAAkB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CACnC,8BAAC,6CAAqB,IACpB,GAAG,EAAE,QAAQ,CAAC,GAAG,EACjB,OAAO,EAAE,GAAG,QAAQ,CAAC,YAAY,EAAE,EACnC,KAAK,EAAE,GAAG,QAAQ,CAAC,iBAAiB,EAAE,EACtC,WAAW,EAAE,QAAQ,CAAC,aAAa,GACnC,CACH,CAAC,CACH,CACG,CACG,CACP;QACN,8BAAC,qBAAW,IACV,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,EACvB,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,kBAAkB,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,YAAY,IAAI,QAAQ,KAAK,SAAS,GAC5F;QACF,8BAAC,+DAA8B,IAC7B,SAAS,EAAE,4BAA4B,EACvC,YAAY,EAAE,+BAA+B,EAC7C,kBAAkB,EAAE,kBAAkB,EACtC,qBAAqB,EAAE,qBAAqB,EAC5C,kBAAkB,EAAE,kBAAkB,GACtC;QACF,8BAAC,qBAAS,IAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,yBAAyB,GAAI,CACrG,CACJ,CAAC;AACJ,CAAC,CAAC;AAlNW,QAAA,mBAAmB,uBAkN9B","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 { PropertyValueFormat } from \"@itwin/presentation-common\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { Alert, Button, Fieldset, LabeledInput, LabeledSelect, Text } from \"@itwin/itwinui-react\";\nimport React, { useCallback, useEffect, useState } from \"react\";\nimport ActionPanel from \"../../SharedComponents/ActionPanel\";\nimport useValidator, { NAME_REQUIREMENTS } from \"../hooks/useValidator\";\nimport { useGroupingMappingApiConfig } from \"../../context/GroupingApiConfigContext\";\nimport { DataType, QuantityType } from \"@itwin/insights-client\";\nimport type { GroupMinimal, Property, PropertyModify } from \"@itwin/insights-client\";\nimport \"./GroupPropertyAction.scss\";\nimport type { PropertyMetaData } from \"./GroupPropertyUtils\";\nimport { convertPresentationFields, convertToECProperties, fetchPresentationDescriptor, findProperties } from \"./GroupPropertyUtils\";\nimport { manufactureKeys } from \"../../../common/viewerUtils\";\nimport { SaveModal } from \"./SaveModal\";\nimport { GroupsPropertiesSelectionModal } from \"./GroupsPropertiesSelectionModal\";\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { GroupPropertyListItem } from \"./GroupPropertyListItem\";\nimport { usePropertiesClient } from \"../../context/PropertiesClientContext\";\n\n/**\n * Props for the {@link GroupPropertyAction} component.\n * @public\n */\nexport interface GroupPropertyActionProps {\n mappingId: string;\n group: GroupMinimal;\n groupProperty?: Property;\n onSaveSuccess: () => void;\n onClickCancel?: () => void;\n}\n\nexport const quantityTypesSelectionOptions: SelectOption<QuantityType | undefined>[] = [\n { value: QuantityType.Area, label: \"Area\" },\n { value: QuantityType.Distance, label: \"Distance\" },\n { value: QuantityType.Force, label: \"Force\" },\n { value: QuantityType.Mass, label: \"Mass\" },\n { value: QuantityType.Monetary, label: \"Monetary\" },\n { value: QuantityType.Time, label: \"Time\" },\n { value: QuantityType.Volume, label: \"Volume\" },\n { value: undefined, label: \"No Quantity Type\" },\n];\n\n/**\n * Component to create or update a group.\n * @public\n */\nexport const GroupPropertyAction = ({ mappingId, group, groupProperty, onSaveSuccess, onClickCancel }: GroupPropertyActionProps) => {\n const { getAccessToken, iModelId, iModelConnection } = useGroupingMappingApiConfig();\n const propertiesClient = usePropertiesClient();\n const [propertyName, setPropertyName] = useState<string>(\"\");\n const [oldPropertyName, setOldPropertyName] = useState<string>(\"\");\n const [dataType, setDataType] = useState<DataType>(DataType.String);\n const [quantityType, setQuantityType] = useState<QuantityType>();\n const [selectedProperties, setSelectedProperties] = useState<PropertyMetaData[]>([]);\n const [propertiesMetaData, setPropertiesMetaData] = useState<PropertyMetaData[]>([]);\n const [propertiesNotFoundAlert, setPropertiesNotFoundAlert] = useState<boolean>(false);\n const [validator, showValidationMessage] = useValidator();\n const [showPropertiesSelectionModal, setShowPropertiesSelectionModal] = useState<boolean>(false);\n const [showSaveConfirmationModal, setShowSaveConfirmationModal] = useState<boolean>(false);\n const queryClient = useQueryClient();\n\n const reset = useCallback(() => {\n setPropertyName(\"\");\n setDataType(DataType.String);\n setSelectedProperties([]);\n }, []);\n\n const fetchPropertiesMetadata = useCallback(async () => {\n if (!iModelConnection) return;\n\n const result = await manufactureKeys(group.query, iModelConnection);\n const descriptor = await fetchPresentationDescriptor(iModelConnection, result);\n\n // Only allow primitives and structs\n const propertyFields =\n descriptor?.fields.filter((field) => field.type.valueFormat === PropertyValueFormat.Primitive || field.type.valueFormat === PropertyValueFormat.Struct) ??\n [];\n\n const propertiesMetaData = convertPresentationFields(propertyFields);\n\n let groupPropertyDetails = null;\n if (groupProperty) {\n const accessToken = await getAccessToken();\n groupPropertyDetails = await propertiesClient.getProperty(accessToken, mappingId, group.id, groupProperty.id);\n }\n\n return { propertiesMetaData, groupPropertyDetails };\n }, [getAccessToken, group.id, group.query, groupProperty, iModelConnection, mappingId, propertiesClient]);\n\n const {\n data,\n isFetching: isLoadingProperties,\n isSuccess: isLoadingPropertiesSuccessful,\n } = useQuery([\"properties\", iModelId, mappingId, group.id, groupProperty?.id, \"metadata\"], fetchPropertiesMetadata);\n\n useEffect(() => {\n if (isLoadingPropertiesSuccessful && data?.propertiesMetaData) {\n setPropertiesMetaData(data.propertiesMetaData);\n\n if (data.groupPropertyDetails) {\n setPropertyName(data.groupPropertyDetails.propertyName);\n setOldPropertyName(data.groupPropertyDetails.propertyName);\n setDataType(data.groupPropertyDetails.dataType);\n if (data.groupPropertyDetails.quantityType) setQuantityType(data.groupPropertyDetails.quantityType);\n\n const properties = findProperties(data.groupPropertyDetails.ecProperties ?? [], data.propertiesMetaData);\n if (properties.length === 0) {\n setPropertiesNotFoundAlert(true);\n }\n\n setSelectedProperties(properties);\n }\n }\n }, [data, isLoadingPropertiesSuccessful]);\n\n const { mutate: onSave, isLoading: isSaving } = useMutation({\n mutationFn: async () => {\n const accessToken = await getAccessToken();\n const newGroupProperty: PropertyModify = {\n propertyName,\n dataType,\n quantityType,\n ecProperties: selectedProperties.map((p) => convertToECProperties(p)).flat(),\n };\n\n return groupProperty\n ? propertiesClient.updateProperty(accessToken, mappingId, group.id, groupProperty.id, newGroupProperty)\n : propertiesClient.createProperty(accessToken, mappingId, group.id, newGroupProperty);\n },\n onSuccess: async () => {\n onSaveSuccess();\n reset();\n await queryClient.invalidateQueries([\"properties\", iModelId, mappingId, group.id]);\n },\n });\n\n const handleSaveClick = async () => {\n if (!validator.allValid()) {\n showValidationMessage(true);\n return;\n }\n if (oldPropertyName !== propertyName && oldPropertyName !== \"\") {\n setShowSaveConfirmationModal(true);\n } else {\n onSave();\n }\n };\n\n const handleCloseSaveModal = () => {\n setShowSaveConfirmationModal(false);\n };\n\n const isLoading = isLoadingProperties || isSaving;\n\n return (\n <>\n <div className=\"gmw-group-property-action-container\">\n <Fieldset disabled={isLoading} className=\"gmw-property-options\" legend=\"Property Details\">\n <Text variant=\"small\" as=\"small\" className=\"gmw-field-legend\">\n Asterisk * indicates mandatory fields.\n </Text>\n <LabeledInput\n id=\"propertyName\"\n label=\"Property Name\"\n value={propertyName}\n required\n onChange={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"propertyName\");\n }}\n message={validator.message(\"propertyName\", propertyName, NAME_REQUIREMENTS)}\n status={validator.message(\"propertyName\", propertyName, NAME_REQUIREMENTS) ? \"negative\" : undefined}\n onBlur={() => {\n validator.showMessageFor(\"propertyName\");\n }}\n />\n <LabeledSelect<DataType>\n label={\"Data Type\"}\n id=\"dataType\"\n options={[\n { value: DataType.Boolean, label: \"Boolean\" },\n { value: DataType.Integer, label: \"Integer\" },\n { value: DataType.Double, label: \"Double\" },\n { value: DataType.String, label: \"String\" },\n ]}\n required\n value={dataType}\n onChange={(value) => {\n validator.showMessageFor(\"dataType\");\n setDataType(value);\n }}\n message={validator.message(\"dataType\", propertyName, \"required\")}\n status={validator.message(\"dataType\", propertyName, \"required\") ? \"negative\" : undefined}\n onBlur={() => {\n validator.showMessageFor(\"dataType\");\n }}\n onShow={() => {}}\n onHide={() => {}}\n />\n <LabeledSelect<QuantityType | undefined>\n label=\"Quantity Type\"\n options={quantityTypesSelectionOptions}\n value={quantityType}\n onChange={setQuantityType}\n onShow={() => {}}\n onHide={() => {}}\n placeholder=\"No Quantity Type\"\n />\n </Fieldset>\n {propertiesNotFoundAlert && (\n <Alert type=\"warning\">\n Warning: Could not match saved properties from the current generated list. It does not confirm or deny validity. Overwriting will occur if a new\n selection is made and saved.\n </Alert>\n )}\n <Fieldset className=\"gmw-property-view-container\" legend=\"Mapped Properties\">\n <div className=\"gmw-property-view-button\">\n <Button onClick={async () => setShowPropertiesSelectionModal(true)} disabled={isLoading}>\n Select Properties\n </Button>\n </div>\n <div className=\"gmw-properties-list\">\n {selectedProperties.length === 0 && !isLoading ? (\n <div className=\"gmw-empty-selection\">\n <Text>No properties selected.</Text>\n <Text>Press the "Select Properties" button for options.</Text>\n </div>\n ) : (\n selectedProperties.map((property) => (\n <GroupPropertyListItem\n key={property.key}\n content={`${property.displayLabel}`}\n title={`${property.actualECClassName}`}\n description={property.categoryLabel}\n />\n ))\n )}\n </div>\n </Fieldset>\n </div>\n <ActionPanel\n onSave={handleSaveClick}\n onCancel={onClickCancel}\n isLoading={isLoading}\n isSavingDisabled={selectedProperties.length === 0 || !propertyName || dataType === undefined}\n />\n <GroupsPropertiesSelectionModal\n showModal={showPropertiesSelectionModal}\n setShowModal={setShowPropertiesSelectionModal}\n selectedProperties={selectedProperties}\n setSelectedProperties={setSelectedProperties}\n propertiesMetaData={propertiesMetaData}\n />\n <SaveModal onSave={onSave} onClose={handleCloseSaveModal} showSaveModal={showSaveConfirmationModal} />\n </>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"GroupPropertyAction.js","sourceRoot":"","sources":["../../../../../src/components/Properties/GroupProperties/GroupPropertyAction.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,oEAAiE;AAEjE,wDAAwG;AACxG,+CAAwE;AACxE,qFAA6D;AAC7D,sEAAwE;AACxE,qFAAqF;AACrF,4DAAgE;AAEhE,sCAAoC;AAEpC,6DAAqI;AACrI,6DAAwE;AACxE,2CAAwC;AACxC,qFAAkF;AAClF,uDAA8E;AAC9E,mEAAgE;AAChE,mFAA4E;AAC5E,oEAA+E;AAC/E,qHAAkH;AAClH,iDAAoD;AACpD,2FAAwF;AACxF,oEAAiE;AACjE,wEAAqE;AACrE,4EAAyE;AAc5D,QAAA,6BAA6B,GAA6C;IACrF,EAAE,KAAK,EAAE,8BAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;IAC3C,EAAE,KAAK,EAAE,8BAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE;IACnD,EAAE,KAAK,EAAE,8BAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE;IAC7C,EAAE,KAAK,EAAE,8BAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;IAC3C,EAAE,KAAK,EAAE,8BAAY,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE;IACnD,EAAE,KAAK,EAAE,8BAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;IAC3C,EAAE,KAAK,EAAE,8BAAY,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE;IAC/C,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,kBAAkB,EAAE;CAChD,CAAC;AAEF;;;GAG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E,GAAG,EAAE,GAAE,CAAC;gBAEvB,8BAAC,iDAAuB,IACtB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,EACtB,mBAAmB,EAAE,mBAAmB,EACxC,eAAe,EAAE,eAAe,EAChC,QAAQ,EAAE,SAAS,GACnB,CACwB,CACxB;QACN,8BAAC,qBAAW,IACV,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,sBAAQ,EACvB,eAAe,EAAE,sBAAQ,EACzB,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,CAAC,YAAY,IAAI,QAAQ,KAAK,SAAS,IAAI,mBAAmB,KAAK,SAAS,GAC9F;QACF,8BAAC,+DAA8B,IAC7B,SAAS,EAAE,4BAA4B,EACvC,YAAY,EAAE,+BAA+B,EAC7C,kBAAkB,EAAE,kBAAkB,EACtC,qBAAqB,EAAE,qBAAqB,EAC5C,kBAAkB,EAAE,kBAAkB,GACtC;QACF,8BAAC,qBAAS,IAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,yBAAyB,GAAI,CACrG,CACJ,CAAC;AACJ,CAAC,CAAC;AArTW,QAAA,mBAAmB,uBAqT9B","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 { PropertyValueFormat } from \"@itwin/presentation-common\";\nimport type { SelectOption } from \"@itwin/itwinui-react\";\nimport { Alert, Button, Fieldset, Icon, LabeledInput, LabeledSelect, Text } from \"@itwin/itwinui-react\";\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport ActionPanel from \"../../SharedComponents/ActionPanel\";\nimport useValidator, { NAME_REQUIREMENTS } from \"../hooks/useValidator\";\nimport { useGroupingMappingApiConfig } from \"../../context/GroupingApiConfigContext\";\nimport { DataType, QuantityType } from \"@itwin/insights-client\";\nimport type { CalculatedPropertyType, GroupMinimal, Property, PropertyModify } from \"@itwin/insights-client\";\nimport \"./GroupPropertyAction.scss\";\nimport type { PropertyMetaData } from \"./GroupPropertyUtils\";\nimport { convertPresentationFields, convertToECProperties, fetchPresentationDescriptor, findProperties } from \"./GroupPropertyUtils\";\nimport { clearAll, manufactureKeys } from \"../../../common/viewerUtils\";\nimport { SaveModal } from \"./SaveModal\";\nimport { GroupsPropertiesSelectionModal } from \"./GroupsPropertiesSelectionModal\";\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { GroupPropertyListItem } from \"./GroupPropertyListItem\";\nimport { usePropertiesClient } from \"../../context/PropertiesClientContext\";\nimport { SvgFunction, SvgLabel, SvgMeasure } from \"@itwin/itwinui-icons-react\";\nimport { CalculatedPropertyActionWithVisuals } from \"../CalculatedProperties/CalculatedPropertyActionWithVisuals\";\nimport { handleError } from \"../../../common/utils\";\nimport { CustomCalculationAction } from \"../CustomCalculations/CustomCalculationAction\";\nimport { usePropertiesQuery } from \"../hooks/usePropertiesQuery\";\nimport { useFormulaValidation } from \"../hooks/useFormulaValidation\";\nimport { ScrollableExpandableBlock } from \"../ScrollableExpandableBlock\";\n\n/**\n * Props for the {@link GroupPropertyAction} component.\n * @public\n */\nexport interface GroupPropertyActionProps {\n mappingId: string;\n group: GroupMinimal;\n groupProperty?: Property;\n onSaveSuccess: () => void;\n onClickCancel?: () => void;\n}\n\nexport const quantityTypesSelectionOptions: SelectOption<QuantityType | undefined>[] = [\n { value: QuantityType.Area, label: \"Area\" },\n { value: QuantityType.Distance, label: \"Distance\" },\n { value: QuantityType.Force, label: \"Force\" },\n { value: QuantityType.Mass, label: \"Mass\" },\n { value: QuantityType.Monetary, label: \"Monetary\" },\n { value: QuantityType.Time, label: \"Time\" },\n { value: QuantityType.Volume, label: \"Volume\" },\n { value: undefined, label: \"No Quantity Type\" },\n];\n\n/**\n * Component to create or update a group.\n * @public\n */\nexport const GroupPropertyAction = ({ mappingId, group, groupProperty, onSaveSuccess, onClickCancel }: GroupPropertyActionProps) => {\n const actionContainerRef = useRef<HTMLDivElement>(null);\n const calculatedPropertyActionRef = useRef<HTMLDivElement>(null);\n const customCalculationActionRef = useRef<HTMLDivElement>(null);\n const propertiesClient = usePropertiesClient();\n const queryClient = useQueryClient();\n\n const [propertyName, setPropertyName] = useState<string>(\"\");\n const [oldPropertyName, setOldPropertyName] = useState<string>(\"\");\n const [dataType, setDataType] = useState<DataType>(groupProperty?.dataType ?? DataType.String);\n const [quantityType, setQuantityType] = useState<QuantityType | undefined>(groupProperty?.quantityType ?? undefined);\n const [selectedProperties, setSelectedProperties] = useState<PropertyMetaData[]>([]);\n const [propertiesMetaData, setPropertiesMetaData] = useState<PropertyMetaData[]>([]);\n const [propertiesNotFoundAlert, setPropertiesNotFoundAlert] = useState<boolean>(false);\n const [validator, showValidationMessage] = useValidator();\n const [showPropertiesSelectionModal, setShowPropertiesSelectionModal] = useState<boolean>(false);\n const [showSaveConfirmationModal, setShowSaveConfirmationModal] = useState<boolean>(false);\n const [calculatedPropertyType, setCalculatedPropertyType] = useState<CalculatedPropertyType | undefined>(groupProperty?.calculatedPropertyType ?? undefined);\n const [isCalculatedBlockExpanded, setIsCalculatedBlockExpanded] = useState<boolean>(!!calculatedPropertyType);\n const [formula, setFormula] = useState<string | undefined>(groupProperty?.formula ?? undefined);\n const [formulaErrorMessage, setFormulaErrorMessage] = useState<string | undefined>(undefined);\n\n const { getAccessToken, iModelId, iModelConnection } = useGroupingMappingApiConfig();\n const { data: groupProperties, isFetching: isLoadingGroupProperties } = usePropertiesQuery(iModelId, mappingId, group.id, getAccessToken, propertiesClient);\n const { forceValidation } = useFormulaValidation(propertyName.toLowerCase(), formula, groupProperties?.properties ?? [], setFormulaErrorMessage, dataType);\n\n const reset = useCallback(() => {\n setPropertyName(\"\");\n setDataType(DataType.String);\n setQuantityType(undefined);\n setSelectedProperties([]);\n setCalculatedPropertyType(undefined);\n setFormula(undefined);\n }, []);\n\n const fetchPropertiesMetadata = useCallback(async () => {\n if (!iModelConnection) return;\n\n const result = await manufactureKeys(group.query, iModelConnection);\n const descriptor = await fetchPresentationDescriptor(iModelConnection, result);\n\n // Only allow primitives and structs\n const propertyFields =\n descriptor?.fields.filter((field) => field.type.valueFormat === PropertyValueFormat.Primitive || field.type.valueFormat === PropertyValueFormat.Struct) ??\n [];\n\n const propertiesMetaData = convertPresentationFields(propertyFields);\n\n let groupPropertyDetails = null;\n if (groupProperty) {\n const accessToken = await getAccessToken();\n groupPropertyDetails = await propertiesClient.getProperty(accessToken, mappingId, group.id, groupProperty.id);\n }\n\n return { propertiesMetaData, groupPropertyDetails };\n }, [getAccessToken, group.id, group.query, groupProperty, iModelConnection, mappingId, propertiesClient]);\n\n const scrollToFormulaErrorMessage = useCallback(() => {\n setTimeout(() => {\n if (actionContainerRef.current && customCalculationActionRef.current) {\n actionContainerRef.current.scrollTo({\n top: customCalculationActionRef.current.offsetTop,\n behavior: \"smooth\",\n });\n }\n }, 500);\n }, [actionContainerRef]);\n\n const {\n data,\n isFetching: isLoadingProperties,\n isSuccess: isLoadingPropertiesSuccessful,\n } = useQuery([\"properties\", iModelId, mappingId, group.id, groupProperty?.id, \"metadata\"], fetchPropertiesMetadata);\n\n useEffect(() => {\n if (isLoadingPropertiesSuccessful && data?.propertiesMetaData) {\n setPropertiesMetaData(data.propertiesMetaData);\n\n if (data.groupPropertyDetails) {\n setPropertyName(data.groupPropertyDetails.propertyName);\n setOldPropertyName(data.groupPropertyDetails.propertyName);\n setDataType(data.groupPropertyDetails.dataType);\n if (data.groupPropertyDetails.quantityType) setQuantityType(data.groupPropertyDetails.quantityType);\n\n if (data.groupPropertyDetails.ecProperties) {\n const properties = findProperties(data.groupPropertyDetails.ecProperties, data.propertiesMetaData);\n if (properties.length === 0) {\n setPropertiesNotFoundAlert(true);\n }\n setSelectedProperties(properties);\n }\n }\n }\n }, [data, isLoadingPropertiesSuccessful]);\n\n useEffect(() => {\n if (calculatedPropertyType) {\n setDataType(DataType.Double);\n }\n\n if (isCalculatedBlockExpanded === false || !calculatedPropertyType) {\n clearAll();\n }\n }, [calculatedPropertyType, isCalculatedBlockExpanded]);\n\n useEffect(() => {\n if (formulaErrorMessage) {\n scrollToFormulaErrorMessage();\n }\n }, [formulaErrorMessage, scrollToFormulaErrorMessage]);\n\n const { mutate: onSave, isLoading: isSaving } = useMutation({\n mutationFn: async () => {\n const accessToken = await getAccessToken();\n const newGroupProperty: PropertyModify = {\n propertyName,\n dataType,\n quantityType,\n ecProperties: selectedProperties.map((p) => convertToECProperties(p)).flat(),\n calculatedPropertyType,\n formula,\n };\n\n return groupProperty\n ? propertiesClient.updateProperty(accessToken, mappingId, group.id, groupProperty.id, newGroupProperty)\n : propertiesClient.createProperty(accessToken, mappingId, group.id, newGroupProperty);\n },\n onSuccess: async () => {\n onSaveSuccess();\n reset();\n await queryClient.invalidateQueries([\"properties\", iModelId, mappingId, group.id]);\n },\n onError(error: any) {\n handleError(error.status);\n },\n });\n\n const handleSaveClick = async () => {\n if (!validator.allValid()) {\n showValidationMessage(true);\n return;\n }\n if (oldPropertyName !== propertyName && oldPropertyName !== \"\") {\n setShowSaveConfirmationModal(true);\n } else {\n onSave();\n }\n };\n\n const handleCloseSaveModal = () => {\n setShowSaveConfirmationModal(false);\n };\n\n const isLoading = isLoadingProperties || isSaving || isLoadingGroupProperties;\n\n return (\n <>\n <div className=\"gmw-group-property-action-container\" ref={actionContainerRef}>\n <Fieldset disabled={isLoading} className=\"gmw-property-options\" legend=\"Property Details\">\n <Text variant=\"small\" as=\"small\" className=\"gmw-field-legend\">\n Asterisk * indicates mandatory fields.\n </Text>\n <LabeledInput\n id=\"propertyName\"\n label=\"Property Name\"\n value={propertyName}\n required\n onChange={(event) => {\n setPropertyName(event.target.value);\n validator.showMessageFor(\"propertyName\");\n }}\n message={validator.message(\"propertyName\", propertyName, NAME_REQUIREMENTS)}\n status={validator.message(\"propertyName\", propertyName, NAME_REQUIREMENTS) ? \"negative\" : undefined}\n onBlur={() => {\n validator.showMessageFor(\"propertyName\");\n }}\n />\n <LabeledSelect<DataType>\n label={\"Data Type\"}\n id=\"dataType\"\n options={[\n { value: DataType.Boolean, label: \"Boolean\" },\n { value: DataType.Integer, label: \"Integer\" },\n { value: DataType.Double, label: \"Double\" },\n { value: DataType.String, label: \"String\" },\n ]}\n required\n value={calculatedPropertyType ? DataType.Double : dataType}\n onChange={(value) => {\n validator.showMessageFor(\"dataType\");\n setDataType(value);\n }}\n message={validator.message(\"dataType\", propertyName, \"required\")}\n status={validator.message(\"dataType\", propertyName, \"required\") ? \"negative\" : undefined}\n onBlur={() => {\n validator.showMessageFor(\"dataType\");\n }}\n disabled={calculatedPropertyType ? true : false}\n onShow={() => {}}\n onHide={() => {}}\n />\n <LabeledSelect<QuantityType | undefined>\n label=\"Quantity Type\"\n options={quantityTypesSelectionOptions}\n value={quantityType}\n onChange={setQuantityType}\n onShow={() => {}}\n onHide={() => {}}\n placeholder=\"No Quantity Type\"\n />\n </Fieldset>\n {propertiesNotFoundAlert && (\n <Alert type=\"warning\">\n Warning: Could not match saved properties from the current generated list. It does not confirm or deny validity. Overwriting will occur if a new\n selection is made and saved.\n </Alert>\n )}\n <ScrollableExpandableBlock\n title={\"Mapped Properties\"}\n endIcon={\n <Icon fill={selectedProperties.length > 0 ? \"informational\" : \"default\"}>\n <SvgLabel />\n </Icon>\n }\n isExpanded={selectedProperties.length > 0}\n setIsExpanded={() => {}}\n >\n <div className=\"gmw-property-view-container\">\n <div className=\"gmw-property-view-button\">\n <Button onClick={async () => setShowPropertiesSelectionModal(true)} disabled={isLoading}>\n Select Properties\n </Button>\n </div>\n <div className=\"gmw-properties-list\">\n {selectedProperties.length === 0 && !isLoading ? (\n <div className=\"gmw-empty-selection\">\n <Text>No properties selected.</Text>\n <Text>Press the "Select Properties" button for options.</Text>\n </div>\n ) : (\n selectedProperties.map((property) => (\n <GroupPropertyListItem\n key={property.key}\n content={`${property.displayLabel}`}\n title={`${property.actualECClassName}`}\n description={property.categoryLabel}\n />\n ))\n )}\n </div>\n </div>\n </ScrollableExpandableBlock>\n <ScrollableExpandableBlock\n parentRef={actionContainerRef}\n ref={calculatedPropertyActionRef}\n title={\"Calculated Property\"}\n endIcon={\n <Icon fill={calculatedPropertyType ? \"informational\" : \"default\"}>\n <SvgMeasure />\n </Icon>\n }\n isExpanded={!!calculatedPropertyType}\n setIsExpanded={setIsCalculatedBlockExpanded}\n >\n <CalculatedPropertyActionWithVisuals\n group={group}\n calculatedPropertyType={calculatedPropertyType}\n setCalculatedPropertyType={setCalculatedPropertyType}\n />\n </ScrollableExpandableBlock>\n <ScrollableExpandableBlock\n parentRef={actionContainerRef}\n ref={customCalculationActionRef}\n title={\"Custom Calculation\"}\n endIcon={\n <Icon fill={formula ? \"informational\" : \"default\"}>\n <SvgFunction />\n </Icon>\n }\n isExpanded={formula !== undefined}\n setIsExpanded={() => {}}\n >\n <CustomCalculationAction\n formula={formula}\n setFormula={setFormula}\n formulaErrorMessage={formulaErrorMessage}\n forceValidation={forceValidation}\n disabled={isLoading}\n />\n </ScrollableExpandableBlock>\n </div>\n <ActionPanel\n onSave={handleSaveClick}\n onCancel={onClickCancel}\n onSaveCapture={clearAll}\n onCancelCapture={clearAll}\n isLoading={isLoading}\n isSavingDisabled={!propertyName || dataType === undefined || formulaErrorMessage !== undefined}\n />\n <GroupsPropertiesSelectionModal\n showModal={showPropertiesSelectionModal}\n setShowModal={setShowPropertiesSelectionModal}\n selectedProperties={selectedProperties}\n setSelectedProperties={setSelectedProperties}\n propertiesMetaData={propertiesMetaData}\n />\n <SaveModal onSave={onSave} onClose={handleCloseSaveModal} showSaveModal={showSaveConfirmationModal} />\n </>\n );\n};\n"]}
|