@gridsuite/commons-ui 0.150.0 → 0.152.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/components/dialogs/elementSaveDialog/index.d.ts +1 -0
  2. package/dist/components/dialogs/elementSaveDialog/index.js +3 -1
  3. package/dist/components/dialogs/index.js +2 -0
  4. package/dist/components/filter/FilterForm.js +4 -4
  5. package/dist/components/filter/expert/ExpertFilterForm.js +4 -4
  6. package/dist/components/filter/explicitNaming/ExplicitNamingFilterForm.js +2 -2
  7. package/dist/components/index.js +2 -0
  8. package/dist/components/parameters/loadflow/load-flow-parameters-dialog.js +7 -7
  9. package/dist/components/parameters/network-visualizations/network-visualizations-parameters-dialog.js +5 -5
  10. package/dist/components/parameters/sensi/constants.d.ts +6 -1
  11. package/dist/components/parameters/sensi/constants.js +6 -2
  12. package/dist/components/parameters/sensi/sensitivity-analysis-parameters-factor-count.d.ts +8 -0
  13. package/dist/components/parameters/sensi/sensitivity-analysis-parameters-factor-count.js +53 -0
  14. package/dist/components/parameters/sensi/sensitivity-analysis-parameters-form.js +2 -3
  15. package/dist/components/parameters/sensi/sensitivity-analysis-parameters-inline.js +3 -3
  16. package/dist/components/parameters/sensi/sensitivity-parameters-selector.d.ts +5 -11
  17. package/dist/components/parameters/sensi/sensitivity-parameters-selector.js +64 -99
  18. package/dist/components/parameters/sensi/sensitivity-table.d.ts +2 -3
  19. package/dist/components/parameters/sensi/sensitivity-table.js +27 -37
  20. package/dist/components/parameters/sensi/table-cell.d.ts +1 -1
  21. package/dist/components/parameters/sensi/table-cell.js +2 -8
  22. package/dist/components/parameters/sensi/table-row.d.ts +2 -2
  23. package/dist/components/parameters/sensi/table-row.js +4 -6
  24. package/dist/components/parameters/sensi/use-sensitivity-analysis-parameters.d.ts +7 -10
  25. package/dist/components/parameters/sensi/use-sensitivity-analysis-parameters.js +67 -114
  26. package/dist/components/parameters/sensi/utils.d.ts +6 -15
  27. package/dist/components/parameters/sensi/utils.js +21 -4
  28. package/dist/components/parameters/short-circuit/short-circuit-parameters-dialog.js +6 -6
  29. package/dist/components/parameters/voltage-init/voltage-init-parameters-dialog.js +5 -5
  30. package/dist/hooks/use-create-row-data-sensi.js +1 -2
  31. package/dist/index.js +2 -0
  32. package/dist/services/sensitivity-analysis.d.ts +2 -2
  33. package/dist/services/sensitivity-analysis.js +8 -9
  34. package/dist/translations/en/businessErrorsEn.d.ts +1 -0
  35. package/dist/translations/en/businessErrorsEn.js +2 -1
  36. package/dist/translations/en/parameters.d.ts +3 -3
  37. package/dist/translations/en/parameters.js +3 -3
  38. package/dist/translations/fr/businessErrorsFr.d.ts +1 -0
  39. package/dist/translations/fr/businessErrorsFr.js +2 -1
  40. package/dist/translations/fr/parameters.d.ts +3 -3
  41. package/dist/translations/fr/parameters.js +3 -3
  42. package/dist/utils/types/sensitivity-analysis.type.d.ts +4 -7
  43. package/package.json +1 -1
@@ -1,11 +1,10 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { TableContainer, Table, TableHead, TableRow, TableCell, Box, Tooltip, IconButton, TableBody } from "@mui/material";
3
3
  import { AddCircle } from "@mui/icons-material";
4
- import { useCallback } from "react";
4
+ import { useRef, useCallback } from "react";
5
5
  import { useIntl } from "react-intl";
6
6
  import { useFormContext } from "react-hook-form";
7
7
  import { TableRowComponent } from "./table-row.js";
8
- import { ACTIVATED, MONITORED_BRANCHES, INJECTIONS, HVDC_LINES, PSTS, COUNT } from "./constants.js";
9
8
  import "@hello-pangea/dnd";
10
9
  import { MAX_ROWS_NUMBER } from "../../dnd-table/dnd-table.type.js";
11
10
  import "../../overflowableText/OverflowableText.js";
@@ -31,6 +30,7 @@ import "../../inputs/reactQueryBuilder/CustomReactQueryBuilder.js";
31
30
  import "uuid";
32
31
  import "../../inputs/reactQueryBuilder/PropertyValueEditor.js";
33
32
  import "react-querybuilder";
33
+ import { isValidSensiParameterRow } from "./utils.js";
34
34
  function SensitivityTable({
35
35
  arrayFormName,
36
36
  useFieldArrayOutput,
@@ -39,55 +39,45 @@ function SensitivityTable({
39
39
  createRows,
40
40
  disableAdd,
41
41
  disableDelete = false,
42
- onFormChanged,
43
- onChangeParams
42
+ onFormChanged
44
43
  }) {
45
44
  const intl = useIntl();
46
45
  const { getValues } = useFormContext();
47
46
  const { fields: currentRows, append, remove } = useFieldArrayOutput;
47
+ const validRowCountRef = useRef(
48
+ (getValues(arrayFormName) || []).filter((row) => isValidSensiParameterRow(row)).length
49
+ );
50
+ const handleRowChanged = useCallback(
51
+ (index) => {
52
+ const currentRowValues = getValues(arrayFormName);
53
+ const row = currentRowValues[index];
54
+ const currentValidRowCount = currentRowValues.filter(
55
+ (r) => isValidSensiParameterRow(r)
56
+ ).length;
57
+ const previousValidRowCount = validRowCountRef.current;
58
+ validRowCountRef.current = currentValidRowCount;
59
+ if (currentValidRowCount !== previousValidRowCount || isValidSensiParameterRow(row)) {
60
+ onFormChanged();
61
+ }
62
+ },
63
+ [getValues, arrayFormName, onFormChanged]
64
+ );
48
65
  const handleAddRowsButton = useCallback(() => {
49
66
  if (currentRows.length >= MAX_ROWS_NUMBER) {
50
67
  return;
51
68
  }
52
69
  append(createRows(1));
53
70
  }, [append, createRows, currentRows.length]);
54
- const fetchCount = useCallback(
55
- (providedArrayFormName, index, source) => {
56
- const row = getValues(providedArrayFormName)[index];
57
- const isActivated = row[ACTIVATED];
58
- const hasMonitoredBranches = row[MONITORED_BRANCHES]?.length > 0;
59
- const hasInjections = row[INJECTIONS]?.length > 0 || row[HVDC_LINES]?.length > 0 || row[PSTS]?.length > 0;
60
- if (source === "switch" && hasMonitoredBranches && hasInjections) {
61
- if (isActivated) {
62
- onChangeParams(row, providedArrayFormName, index);
63
- } else {
64
- onFormChanged(true);
65
- }
66
- }
67
- if (source === "directory" && isActivated) {
68
- if (hasMonitoredBranches && hasInjections) {
69
- onChangeParams(row, providedArrayFormName, index);
70
- } else if ((!hasMonitoredBranches || !hasInjections) && row.count === 0) {
71
- onFormChanged(false);
72
- } else if (!hasMonitoredBranches || !hasInjections) {
73
- onFormChanged(true);
74
- }
75
- }
76
- },
77
- [onChangeParams, onFormChanged, getValues]
78
- );
79
71
  const handleDeleteButton = useCallback(
80
72
  (index) => {
81
73
  const currentRowsValues = getValues(arrayFormName);
82
- let isFormChanged = false;
83
74
  if (index >= 0 && index < currentRowsValues.length) {
84
- if (currentRowsValues[index][COUNT] && currentRowsValues[index][ACTIVATED]) {
85
- isFormChanged = true;
86
- }
75
+ const wasValid = isValidSensiParameterRow(currentRowsValues[index]);
87
76
  remove(index);
88
- }
89
- if (isFormChanged) {
90
- onFormChanged(true);
77
+ if (wasValid) {
78
+ validRowCountRef.current -= 1;
79
+ onFormChanged();
80
+ }
91
81
  }
92
82
  },
93
83
  [arrayFormName, getValues, onFormChanged, remove]
@@ -120,7 +110,7 @@ function SensitivityTable({
120
110
  index,
121
111
  handleDeleteButton,
122
112
  disableDelete,
123
- fetchCount
113
+ handleRowChanged
124
114
  },
125
115
  row.id
126
116
  )) })
@@ -4,5 +4,5 @@
4
4
  * License, v. 2.0. If a copy of the MPL was not distributed with this
5
5
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
  */
7
- declare function EditableTableCell(arrayFormName: string, rowIndex: number, column: any, onRowChanged: (a: boolean, source: string) => void): import("react/jsx-runtime").JSX.Element;
7
+ declare function EditableTableCell(arrayFormName: string, rowIndex: number, column: any, onRowChanged: () => void): import("react/jsx-runtime").JSX.Element;
8
8
  export default EditableTableCell;
@@ -32,12 +32,6 @@ import "uuid";
32
32
  import "../../inputs/reactQueryBuilder/PropertyValueEditor.js";
33
33
  import "react-querybuilder";
34
34
  function EditableTableCell(arrayFormName, rowIndex, column, onRowChanged) {
35
- const handleDirectoryItemsChange = () => {
36
- onRowChanged(true, "directory");
37
- };
38
- const handleSwitchInputChange = () => {
39
- onRowChanged(true, "switch");
40
- };
41
35
  return /* @__PURE__ */ jsxs(
42
36
  TableCell,
43
37
  {
@@ -55,7 +49,7 @@ function EditableTableCell(arrayFormName, rowIndex, column, onRowChanged) {
55
49
  hideErrorMessage: true,
56
50
  label: void 0,
57
51
  itemFilter: void 0,
58
- onRowChanged: handleDirectoryItemsChange
52
+ onRowChanged
59
53
  }
60
54
  ),
61
55
  column.menuItems && /* @__PURE__ */ jsx(
@@ -67,7 +61,7 @@ function EditableTableCell(arrayFormName, rowIndex, column, onRowChanged) {
67
61
  fullWidth: true
68
62
  }
69
63
  ),
70
- column.checkboxItems && /* @__PURE__ */ jsx("span", { onChange: handleSwitchInputChange, children: /* @__PURE__ */ jsx(SwitchInput, { name: `${arrayFormName}[${rowIndex}].${column.dataKey}` }) }),
64
+ column.checkboxItems && /* @__PURE__ */ jsx("span", { onChange: onRowChanged, children: /* @__PURE__ */ jsx(SwitchInput, { name: `${arrayFormName}[${rowIndex}].${column.dataKey}` }) }),
71
65
  column.floatItems && /* @__PURE__ */ jsx(FloatInput, { name: `${arrayFormName}[${rowIndex}].${column.dataKey}` }),
72
66
  column.textItems && /* @__PURE__ */ jsx(
73
67
  TextInput,
@@ -5,7 +5,7 @@ interface TableRowComponentProps {
5
5
  index: number;
6
6
  handleDeleteButton: (index: number) => void;
7
7
  disableDelete: boolean;
8
- fetchCount: (a: string, b: number, c: string) => void;
8
+ handleRowChanged: (a: number) => void;
9
9
  }
10
- export declare function TableRowComponent({ arrayFormName, columnsDefinition, index, handleDeleteButton, disableDelete, fetchCount, }: Readonly<TableRowComponentProps>): import("react/jsx-runtime").JSX.Element;
10
+ export declare function TableRowComponent({ arrayFormName, columnsDefinition, index, handleDeleteButton, disableDelete, handleRowChanged, }: Readonly<TableRowComponentProps>): import("react/jsx-runtime").JSX.Element;
11
11
  export {};
@@ -10,21 +10,19 @@ function TableRowComponent({
10
10
  index,
11
11
  handleDeleteButton,
12
12
  disableDelete = false,
13
- fetchCount
13
+ handleRowChanged
14
14
  }) {
15
15
  const [isHover, setIsHover] = useState(false);
16
16
  const intl = useIntl();
17
17
  function handleHover(enter) {
18
18
  return setIsHover(enter);
19
19
  }
20
- const handleRowChanged = (isChanged, source) => {
21
- if (isChanged) {
22
- fetchCount(arrayFormName, index, source);
23
- }
20
+ const handleCellChanged = () => {
21
+ handleRowChanged(index);
24
22
  };
25
23
  return /* @__PURE__ */ jsxs(TableRow, { onMouseEnter: () => handleHover(true), onMouseLeave: () => handleHover(false), children: [
26
24
  columnsDefinition.map(
27
- (column) => EditableTableCell(arrayFormName, index, column, handleRowChanged)
25
+ (column) => EditableTableCell(arrayFormName, index, column, handleCellChanged)
28
26
  ),
29
27
  !disableDelete && /* @__PURE__ */ jsx(TableCell, { sx: { width: "5rem", textAlign: "center" }, children: isHover && /* @__PURE__ */ jsx(
30
28
  Tooltip,
@@ -1,10 +1,8 @@
1
1
  import { UseFormReturn } from 'react-hook-form';
2
2
  import { ObjectSchema } from 'yup';
3
- import { Dispatch, SetStateAction } from 'react';
4
3
  import { UUID } from 'node:crypto';
5
4
  import { ComputingType } from '../common';
6
- import { SensitivityAnalysisParametersInfos, UseParametersBackendReturnProps } from '../../../utils';
7
- type SubTabsValues = 'sensitivityInjectionsSet' | 'sensitivityInjection' | 'sensitivityHVDC' | 'sensitivityPST';
5
+ import { FactorsCount, SensitivityAnalysisParametersInfos, UseParametersBackendReturnProps } from '../../../utils';
8
6
  export interface UseSensitivityAnalysisParametersReturn {
9
7
  formMethods: UseFormReturn<any>;
10
8
  formSchema: ObjectSchema<any>;
@@ -19,14 +17,13 @@ export interface UseSensitivityAnalysisParametersReturn {
19
17
  isStudyLinked: boolean;
20
18
  onSaveInline: (formData: Record<string, any>) => void;
21
19
  onSaveDialog: (formData: Record<string, any>) => void;
22
- isMaxReached: boolean;
23
- launchLoader: boolean;
24
- initRowsCount: () => void;
25
- onFormChanged: (formChanged: boolean) => void;
26
- onChangeParams: (row: any, arrayFormName: SubTabsValues, index: number) => void;
20
+ isMaxResultsReached: boolean;
21
+ isMaxVariablesReached: boolean;
22
+ isLoading: boolean;
23
+ onFormChanged: () => void;
27
24
  emptyFormData: Record<string, unknown>;
28
- analysisComputeComplexity: number;
29
- setAnalysisComputeComplexity: Dispatch<SetStateAction<number>>;
25
+ factorsCount: FactorsCount;
26
+ resetFactorsCount: () => void;
30
27
  }
31
28
  type UseSensitivityAnalysisParametersFormProps = {
32
29
  name: string;
@@ -17,7 +17,6 @@ import "localized-countries";
17
17
  import "localized-countries/data/fr";
18
18
  import "localized-countries/data/en";
19
19
  import { useSnackMessage } from "../../../hooks/useSnackMessage.js";
20
- import { PARAMETER_SENSI_NODES, PARAMETER_SENSI_PST, PARAMETER_SENSI_HVDC, PARAMETER_SENSI_INJECTION, PARAMETER_SENSI_INJECTIONS_SET, FLOW_VOLTAGE_SENSITIVITY_VALUE_THRESHOLD, ANGLE_FLOW_SENSITIVITY_VALUE_THRESHOLD, FLOW_FLOW_SENSITIVITY_VALUE_THRESHOLD, ACTIVATED, MONITORED_BRANCHES, INJECTIONS, PSTS, HVDC_LINES, COUNT, SENSI_INJECTIONS_SET, CONTINGENCIES, CONTAINER_NAME, CONTAINER_ID, EQUIPMENTS_IN_VOLTAGE_REGULATION, SUPERVISED_VOLTAGE_LEVELS, SENSITIVITY_TYPE, DISTRIBUTION_TYPE } from "./constants.js";
21
20
  import "../../inputs/reactHookForm/provider/CustomFormProvider.js";
22
21
  import "../../dialogs/descriptionModificationDialog/DescriptionModificationDialog.js";
23
22
  import "../../dialogs/elementSaveDialog/ElementSaveDialog.js";
@@ -38,11 +37,11 @@ import "../../inputs/reactQueryBuilder/PropertyValueEditor.js";
38
37
  import "react-querybuilder";
39
38
  import "../common/widget/parameter-line-slider.js";
40
39
  import "../common/limitreductions/columns-definitions.js";
41
- import { getFormSchema, getSensiNodesformatNewParams, getSensiPstformatNewParams, getSensiHvdcformatNewParams, getSensiInjectionsformatNewParams, getSensiInjectionsSetformatNewParams, getGenericRowNewParams } from "./utils.js";
40
+ import { getFormSchema, getSensiNodesformatNewParams, getSensiPstformatNewParams, getSensiHvdcformatNewParams, getSensiInjectionsformatNewParams, getSensiInjectionsSetformatNewParams, filterSensiParameterRows } from "./utils.js";
41
+ import { DEFAULT_FACTOR_COUNT, PARAMETER_SENSI_NODES, PARAMETER_SENSI_PST, PARAMETER_SENSI_HVDC, PARAMETER_SENSI_INJECTION, PARAMETER_SENSI_INJECTIONS_SET, FLOW_VOLTAGE_SENSITIVITY_VALUE_THRESHOLD, ANGLE_FLOW_SENSITIVITY_VALUE_THRESHOLD, FLOW_FLOW_SENSITIVITY_VALUE_THRESHOLD, ACTIVATED, CONTINGENCIES, CONTAINER_NAME, CONTAINER_ID, EQUIPMENTS_IN_VOLTAGE_REGULATION, SUPERVISED_VOLTAGE_LEVELS, SENSITIVITY_TYPE, PSTS, MONITORED_BRANCHES, HVDC_LINES, INJECTIONS, DISTRIBUTION_TYPE, MAX_RESULTS_COUNT, MAX_VARIABLES_COUNT } from "./constants.js";
42
42
  import { getSensitivityAnalysisFactorsCount, setSensitivityAnalysisParameters } from "../../../services/sensitivity-analysis.js";
43
43
  import "../../filter/HeaderFilterForm.js";
44
44
  import { getNameElementEditorEmptyFormData } from "../common/name-element-editor/name-element-editor-utils.js";
45
- const numberMax = 5e5;
46
45
  const useSensitivityAnalysisParametersForm = ({
47
46
  studyUuid,
48
47
  currentNodeUuid,
@@ -55,8 +54,8 @@ const useSensitivityAnalysisParametersForm = ({
55
54
  const [providers, , , , , params, , updateParameters] = parametersBackend;
56
55
  const [sensitivityAnalysisParams, setSensitivityAnalysisParams] = useState(params);
57
56
  const { snackError } = useSnackMessage();
58
- const [analysisComputeComplexity, setAnalysisComputeComplexity] = useState(0);
59
- const [launchLoader, setLaunchLoader] = useState(false);
57
+ const [factorsCount, setFactorsCount] = useState(DEFAULT_FACTOR_COUNT);
58
+ const [isLoading, setIsLoading] = useState(false);
60
59
  const [isSubmitAction, setIsSubmitAction] = useState(false);
61
60
  const emptyFormData = useMemo(() => {
62
61
  return {
@@ -82,7 +81,7 @@ const useSensitivityAnalysisParametersForm = ({
82
81
  defaultValues: emptyFormData,
83
82
  resolver: yupResolver(formSchema)
84
83
  });
85
- const { reset, getValues, setValue } = formMethods;
84
+ const { reset, getValues } = formMethods;
86
85
  const formattedProviders = Object.keys(providers).map((key) => ({
87
86
  id: key,
88
87
  label: providers[key]
@@ -100,72 +99,56 @@ const useSensitivityAnalysisParametersForm = ({
100
99
  ...getSensiNodesformatNewParams(newParams)
101
100
  };
102
101
  }, []);
103
- const formatFilteredParams = useCallback((row) => {
104
- return getGenericRowNewParams(row);
102
+ const resetFactorsCount = useCallback(() => {
103
+ setIsLoading(false);
104
+ setFactorsCount(DEFAULT_FACTOR_COUNT);
105
105
  }, []);
106
- const getResultCount = useCallback(() => {
107
- const values = getValues();
108
- let totalResultCount = 0;
109
- const tabsToCheck = [
110
- "sensitivityInjectionsSet",
111
- "sensitivityInjection",
112
- "sensitivityHVDC",
113
- "sensitivityPST"
114
- ];
115
- tabsToCheck.forEach((tab) => {
116
- const tabToCheck = values[tab];
117
- if (tabToCheck) {
118
- const count = tabToCheck.filter((entry) => entry[ACTIVATED]).filter((entry) => entry[MONITORED_BRANCHES].length > 0).filter(
119
- (entry) => entry[INJECTIONS]?.length > 0 || entry[PSTS]?.length > 0 || entry[HVDC_LINES]?.length > 0
120
- ).map((entry) => entry[COUNT]).reduce((a, b) => a + b, 0);
121
- totalResultCount += count;
122
- }
106
+ const updateFactorCount = useCallback(() => {
107
+ if (!currentNodeUuid || !currentRootNetworkUuid) {
108
+ return;
109
+ }
110
+ const formValues = getValues();
111
+ const filteredInjectionsSet = filterSensiParameterRows(formValues[PARAMETER_SENSI_INJECTIONS_SET]);
112
+ const filteredInjection = filterSensiParameterRows(formValues[PARAMETER_SENSI_INJECTION]);
113
+ const filteredHvdc = filterSensiParameterRows(formValues[PARAMETER_SENSI_HVDC]);
114
+ const filteredPst = filterSensiParameterRows(formValues[PARAMETER_SENSI_PST]);
115
+ const filteredNodes = filterSensiParameterRows(formValues[PARAMETER_SENSI_NODES]);
116
+ const hasAnyEntries = filteredInjectionsSet.length > 0 || filteredInjection.length > 0 || filteredHvdc.length > 0 || filteredPst.length > 0 || filteredNodes.length > 0;
117
+ if (!hasAnyEntries) {
118
+ resetFactorsCount();
119
+ return;
120
+ }
121
+ const filteredFormValues = {
122
+ ...formValues,
123
+ [PARAMETER_SENSI_INJECTIONS_SET]: filteredInjectionsSet,
124
+ [PARAMETER_SENSI_INJECTION]: filteredInjection,
125
+ [PARAMETER_SENSI_HVDC]: filteredHvdc,
126
+ [PARAMETER_SENSI_PST]: filteredPst,
127
+ [PARAMETER_SENSI_NODES]: filteredNodes
128
+ };
129
+ setIsLoading(true);
130
+ getSensitivityAnalysisFactorsCount(
131
+ studyUuid,
132
+ currentNodeUuid,
133
+ currentRootNetworkUuid,
134
+ formatNewParams(filteredFormValues)
135
+ ).then((factorsCountResponse) => {
136
+ setFactorsCount(factorsCountResponse);
137
+ const timeoutId = setTimeout(() => {
138
+ setIsLoading(false);
139
+ }, 500);
140
+ return () => clearTimeout(timeoutId);
141
+ }).catch((error) => {
142
+ setIsLoading(false);
143
+ snackWithFallback(snackError, error, { headerId: "getSensitivityAnalysisFactorsCountError" });
123
144
  });
124
- setAnalysisComputeComplexity(totalResultCount);
125
- const timeoutId = setTimeout(() => {
126
- setLaunchLoader(false);
127
- }, 500);
128
- return () => clearTimeout(timeoutId);
129
- }, [getValues]);
130
- const onFormChanged = useCallback(
131
- (formChanged) => {
132
- if (formChanged) {
133
- setLaunchLoader(true);
134
- getResultCount();
135
- }
136
- },
137
- [getResultCount]
138
- );
139
- const onChangeParams = useCallback(
140
- (row, arrayFormName, index) => {
141
- if (!currentNodeUuid || !currentRootNetworkUuid) {
142
- return;
143
- }
144
- setLaunchLoader(true);
145
- getSensitivityAnalysisFactorsCount(
146
- studyUuid,
147
- currentNodeUuid,
148
- currentRootNetworkUuid,
149
- arrayFormName === SENSI_INJECTIONS_SET,
150
- formatFilteredParams(row)
151
- ).then((response) => {
152
- response.text().then((value) => {
153
- setValue(
154
- `${arrayFormName}.${index}.${COUNT}`,
155
- !Number.isNaN(Number(value)) ? parseInt(value, 10) : 0
156
- );
157
- getResultCount();
158
- });
159
- }).catch((error) => {
160
- setLaunchLoader(false);
161
- snackWithFallback(snackError, error, { headerId: "getSensitivityAnalysisFactorsCountError" });
162
- });
163
- },
164
- [snackError, studyUuid, currentRootNetworkUuid, formatFilteredParams, setValue, getResultCount, currentNodeUuid]
165
- );
145
+ }, [snackError, studyUuid, currentRootNetworkUuid, formatNewParams, currentNodeUuid, getValues, resetFactorsCount]);
146
+ const onFormChanged = useCallback(() => {
147
+ updateFactorCount();
148
+ }, [updateFactorCount]);
166
149
  const fromSensitivityAnalysisParamsDataToFormValues = useCallback(
167
150
  (parameters) => {
168
- const values = {
151
+ return {
169
152
  [PROVIDER]: parameters[PROVIDER],
170
153
  [FLOW_FLOW_SENSITIVITY_VALUE_THRESHOLD]: parameters.flowFlowSensitivityValueThreshold,
171
154
  [ANGLE_FLOW_SENSITIVITY_VALUE_THRESHOLD]: parameters.angleFlowSensitivityValueThreshold,
@@ -191,8 +174,7 @@ const useSensitivityAnalysisParametersForm = ({
191
174
  [FieldConstants.NAME]: sensiInjection[CONTAINER_NAME]
192
175
  };
193
176
  }) ?? [],
194
- [ACTIVATED]: sensiInjectionsSet[ACTIVATED] ?? false,
195
- [COUNT]: 0
177
+ [ACTIVATED]: sensiInjectionsSet[ACTIVATED] ?? false
196
178
  };
197
179
  }) ?? [],
198
180
  [PARAMETER_SENSI_INJECTION]: parameters.sensitivityInjection?.map((sensiInjections) => {
@@ -215,8 +197,7 @@ const useSensitivityAnalysisParametersForm = ({
215
197
  [FieldConstants.NAME]: sensiInjection[CONTAINER_NAME]
216
198
  };
217
199
  }) ?? [],
218
- [ACTIVATED]: sensiInjections[ACTIVATED] ?? false,
219
- [COUNT]: 0
200
+ [ACTIVATED]: sensiInjections[ACTIVATED] ?? false
220
201
  };
221
202
  }) ?? [],
222
203
  [PARAMETER_SENSI_HVDC]: parameters.sensitivityHVDC?.map((sensiInjectionsSet) => {
@@ -240,8 +221,7 @@ const useSensitivityAnalysisParametersForm = ({
240
221
  [FieldConstants.NAME]: sensiInjection[CONTAINER_NAME]
241
222
  };
242
223
  }) ?? [],
243
- [ACTIVATED]: sensiInjectionsSet[ACTIVATED] ?? false,
244
- [COUNT]: 0
224
+ [ACTIVATED]: sensiInjectionsSet[ACTIVATED] ?? false
245
225
  };
246
226
  }) ?? [],
247
227
  [PARAMETER_SENSI_PST]: parameters.sensitivityPST?.map((sensiInjectionsSet) => {
@@ -265,8 +245,7 @@ const useSensitivityAnalysisParametersForm = ({
265
245
  [FieldConstants.NAME]: sensiInjection[CONTAINER_NAME]
266
246
  };
267
247
  }) ?? [],
268
- [ACTIVATED]: sensiInjectionsSet[ACTIVATED] ?? false,
269
- [COUNT]: 0
248
+ [ACTIVATED]: sensiInjectionsSet[ACTIVATED] ?? false
270
249
  };
271
250
  }) ?? [],
272
251
  [PARAMETER_SENSI_NODES]: parameters.sensitivityNodes?.map((sensiInjectionsSet) => {
@@ -289,38 +268,13 @@ const useSensitivityAnalysisParametersForm = ({
289
268
  [FieldConstants.NAME]: sensiInjection[CONTAINER_NAME]
290
269
  };
291
270
  }) ?? [],
292
- [ACTIVATED]: sensiInjectionsSet[ACTIVATED] ?? false,
293
- [COUNT]: 0
271
+ [ACTIVATED]: sensiInjectionsSet[ACTIVATED] ?? false
294
272
  };
295
273
  }) ?? []
296
274
  };
297
- return values;
298
275
  },
299
276
  []
300
277
  );
301
- const initRowsCount = useCallback(() => {
302
- const handleEntries = (entries, parameter) => {
303
- if (!entries) {
304
- return;
305
- }
306
- const entriesWithIndices = entries.map((entry, index) => ({
307
- entry,
308
- index
309
- }));
310
- const filteredInitEntries = entries.filter(
311
- (entry) => entry[ACTIVATED] && entry[MONITORED_BRANCHES].length > 0 && (entry[INJECTIONS]?.length > 0 || entry[PSTS]?.length > 0 || entry[HVDC_LINES]?.length > 0)
312
- );
313
- filteredInitEntries.forEach((entry) => {
314
- const originalIndex = entriesWithIndices.findIndex((obj) => obj.entry === entry);
315
- onChangeParams(entry, parameter, originalIndex);
316
- });
317
- };
318
- const values = getValues();
319
- handleEntries(values[PARAMETER_SENSI_INJECTIONS_SET], PARAMETER_SENSI_INJECTIONS_SET);
320
- handleEntries(values[PARAMETER_SENSI_INJECTION], PARAMETER_SENSI_INJECTION);
321
- handleEntries(values[PARAMETER_SENSI_HVDC], PARAMETER_SENSI_HVDC);
322
- handleEntries(values[PARAMETER_SENSI_PST], PARAMETER_SENSI_PST);
323
- }, [onChangeParams, getValues]);
324
278
  const onSaveInline = useCallback(
325
279
  (newParams) => {
326
280
  setIsSubmitAction(true);
@@ -328,12 +282,11 @@ const useSensitivityAnalysisParametersForm = ({
328
282
  const formattedParams = formatNewParams(newParams);
329
283
  setSensitivityAnalysisParams(formattedParams);
330
284
  updateParameters(formattedParams);
331
- initRowsCount();
332
285
  }).catch((error) => {
333
286
  snackWithFallback(snackError, error, { headerId: "updateSensitivityAnalysisParametersError" });
334
287
  });
335
288
  },
336
- [setSensitivityAnalysisParams, snackError, studyUuid, formatNewParams, initRowsCount, updateParameters]
289
+ [setSensitivityAnalysisParams, snackError, studyUuid, formatNewParams, updateParameters]
337
290
  );
338
291
  const onSaveDialog = useCallback(
339
292
  (formData) => {
@@ -355,22 +308,23 @@ const useSensitivityAnalysisParametersForm = ({
355
308
  if (sensitivityAnalysisParams) {
356
309
  reset(fromSensitivityAnalysisParamsDataToFormValues(sensitivityAnalysisParams));
357
310
  if (!isSubmitAction) {
358
- initRowsCount();
311
+ onFormChanged();
359
312
  }
360
313
  }
361
314
  }, [
362
315
  fromSensitivityAnalysisParamsDataToFormValues,
363
316
  sensitivityAnalysisParams,
364
- initRowsCount,
365
317
  isSubmitAction,
366
- reset
318
+ reset,
319
+ onFormChanged
367
320
  ]);
368
321
  useEffect(() => {
369
322
  if (params) {
370
323
  reset(fromSensitivityAnalysisParamsDataToFormValues(params));
371
324
  }
372
325
  }, [params, reset, fromSensitivityAnalysisParamsDataToFormValues]);
373
- const isMaxReached = useMemo(() => analysisComputeComplexity > numberMax, [analysisComputeComplexity]);
326
+ const isMaxResultsReached = useMemo(() => factorsCount.resultCount > MAX_RESULTS_COUNT, [factorsCount]);
327
+ const isMaxVariablesReached = useMemo(() => factorsCount.variableCount > MAX_VARIABLES_COUNT, [factorsCount]);
374
328
  const paramsLoaded = useMemo(() => !!params, [params]);
375
329
  return {
376
330
  formMethods,
@@ -383,14 +337,13 @@ const useSensitivityAnalysisParametersForm = ({
383
337
  isStudyLinked,
384
338
  onSaveInline,
385
339
  onSaveDialog,
386
- isMaxReached,
387
- launchLoader,
388
- initRowsCount,
340
+ isMaxResultsReached,
341
+ isMaxVariablesReached,
342
+ isLoading,
389
343
  onFormChanged,
390
- onChangeParams,
391
344
  emptyFormData,
392
- analysisComputeComplexity,
393
- setAnalysisComputeComplexity
345
+ factorsCount,
346
+ resetFactorsCount
394
347
  };
395
348
  };
396
349
  export {
@@ -1,3 +1,4 @@
1
+ import { FieldValues } from 'react-hook-form';
1
2
  import { default as yup } from '../../../utils/yupConfig';
2
3
  import { CONTINGENCIES, HVDC_LINES, INJECTIONS, MONITORED_BRANCHES, PSTS } from './constants';
3
4
  import { DistributionType, SensitivityType } from '../../../utils';
@@ -10,7 +11,6 @@ export declare const getSensiHVDCsFormSchema: () => {
10
11
  name: string;
11
12
  }[] | undefined;
12
13
  sensitivityType?: SensitivityType | undefined;
13
- count?: number | null | undefined;
14
14
  activated: NonNullable<boolean | undefined>;
15
15
  monitoredBranches: {
16
16
  id: string;
@@ -46,7 +46,6 @@ export declare const getSensiInjectionsFormSchema: () => {
46
46
  id: string;
47
47
  name: string;
48
48
  }[] | undefined;
49
- count?: number | null | undefined;
50
49
  activated: NonNullable<boolean | undefined>;
51
50
  monitoredBranches: {
52
51
  id: string;
@@ -82,7 +81,6 @@ export declare const getSensiInjectionsSetFormSchema: () => {
82
81
  name: string;
83
82
  }[] | undefined;
84
83
  distributionType?: DistributionType | undefined;
85
- count?: number | null | undefined;
86
84
  activated: NonNullable<boolean | undefined>;
87
85
  monitoredBranches: {
88
86
  id: string;
@@ -155,7 +153,6 @@ export declare const getSensiNodesFormSchema: () => {
155
153
  id: string;
156
154
  name: string;
157
155
  }[] | undefined;
158
- count?: number | null | undefined;
159
156
  activated: NonNullable<boolean | undefined>;
160
157
  }[] | undefined, yup.AnyObject, "", "">;
161
158
  };
@@ -183,7 +180,6 @@ export declare const getSensiPSTsFormSchema: () => {
183
180
  name: string;
184
181
  }[] | undefined;
185
182
  sensitivityType?: SensitivityType | undefined;
186
- count?: number | null | undefined;
187
183
  activated: NonNullable<boolean | undefined>;
188
184
  monitoredBranches: {
189
185
  id: string;
@@ -213,6 +209,11 @@ export declare const getSensiPstformatNewParams: (newParams: SensitivityAnalysis
213
209
  activated: NonNullable<boolean | undefined>;
214
210
  }[] | undefined;
215
211
  };
212
+ export declare const hasVariables: (row: any) => boolean;
213
+ export declare const hasMonitoredEquipments: (row: any) => boolean;
214
+ export declare const isActivatedSensiParameterRow: (entry: FieldValues) => any;
215
+ export declare const isValidSensiParameterRow: (entry: FieldValues) => any;
216
+ export declare const filterSensiParameterRows: (entries?: FieldValues[]) => FieldValues[];
216
217
  export declare const formSchema: yup.ObjectSchema<{
217
218
  sensitivityNodes: {
218
219
  contingencies?: {
@@ -227,7 +228,6 @@ export declare const formSchema: yup.ObjectSchema<{
227
228
  id: string;
228
229
  name: string;
229
230
  }[] | undefined;
230
- count?: number | null | undefined;
231
231
  activated: NonNullable<boolean | undefined>;
232
232
  }[] | undefined;
233
233
  sensitivityPST: {
@@ -236,7 +236,6 @@ export declare const formSchema: yup.ObjectSchema<{
236
236
  name: string;
237
237
  }[] | undefined;
238
238
  sensitivityType?: SensitivityType | undefined;
239
- count?: number | null | undefined;
240
239
  activated: NonNullable<boolean | undefined>;
241
240
  monitoredBranches: {
242
241
  id: string;
@@ -253,7 +252,6 @@ export declare const formSchema: yup.ObjectSchema<{
253
252
  name: string;
254
253
  }[] | undefined;
255
254
  sensitivityType?: SensitivityType | undefined;
256
- count?: number | null | undefined;
257
255
  activated: NonNullable<boolean | undefined>;
258
256
  monitoredBranches: {
259
257
  id: string;
@@ -269,7 +267,6 @@ export declare const formSchema: yup.ObjectSchema<{
269
267
  id: string;
270
268
  name: string;
271
269
  }[] | undefined;
272
- count?: number | null | undefined;
273
270
  activated: NonNullable<boolean | undefined>;
274
271
  monitoredBranches: {
275
272
  id: string;
@@ -286,7 +283,6 @@ export declare const formSchema: yup.ObjectSchema<{
286
283
  name: string;
287
284
  }[] | undefined;
288
285
  distributionType?: DistributionType | undefined;
289
- count?: number | null | undefined;
290
286
  activated: NonNullable<boolean | undefined>;
291
287
  monitoredBranches: {
292
288
  id: string;
@@ -327,7 +323,6 @@ export declare const getFormSchema: (name: string | null) => yup.ObjectSchema<{
327
323
  id: string;
328
324
  name: string;
329
325
  }[] | undefined;
330
- count?: number | null | undefined;
331
326
  activated: NonNullable<boolean | undefined>;
332
327
  }[] | undefined;
333
328
  sensitivityPST: {
@@ -336,7 +331,6 @@ export declare const getFormSchema: (name: string | null) => yup.ObjectSchema<{
336
331
  name: string;
337
332
  }[] | undefined;
338
333
  sensitivityType?: SensitivityType | undefined;
339
- count?: number | null | undefined;
340
334
  activated: NonNullable<boolean | undefined>;
341
335
  monitoredBranches: {
342
336
  id: string;
@@ -353,7 +347,6 @@ export declare const getFormSchema: (name: string | null) => yup.ObjectSchema<{
353
347
  name: string;
354
348
  }[] | undefined;
355
349
  sensitivityType?: SensitivityType | undefined;
356
- count?: number | null | undefined;
357
350
  activated: NonNullable<boolean | undefined>;
358
351
  monitoredBranches: {
359
352
  id: string;
@@ -369,7 +362,6 @@ export declare const getFormSchema: (name: string | null) => yup.ObjectSchema<{
369
362
  id: string;
370
363
  name: string;
371
364
  }[] | undefined;
372
- count?: number | null | undefined;
373
365
  activated: NonNullable<boolean | undefined>;
374
366
  monitoredBranches: {
375
367
  id: string;
@@ -386,7 +378,6 @@ export declare const getFormSchema: (name: string | null) => yup.ObjectSchema<{
386
378
  name: string;
387
379
  }[] | undefined;
388
380
  distributionType?: DistributionType | undefined;
389
- count?: number | null | undefined;
390
381
  activated: NonNullable<boolean | undefined>;
391
382
  monitoredBranches: {
392
383
  id: string;