@gridsuite/commons-ui 0.280.0 → 0.281.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 (110) hide show
  1. package/dist/components/ui/dialogs/elementSaveDialog/ElementSaveDialog.d.ts +6 -1
  2. package/dist/components/ui/dialogs/elementSaveDialog/ElementSaveDialog.js +29 -5
  3. package/dist/components/ui/reactHookForm/booleans/RadioInput.d.ts +1 -0
  4. package/dist/components/ui/reactHookForm/booleans/RadioInput.js +2 -1
  5. package/dist/features/index.js +80 -3
  6. package/dist/features/network-modifications/index.d.ts +1 -0
  7. package/dist/features/network-modifications/index.js +78 -3
  8. package/dist/features/network-modifications/tabular/TabularForm.d.ts +22 -0
  9. package/dist/features/network-modifications/tabular/TabularForm.js +536 -0
  10. package/dist/features/network-modifications/tabular/index.d.ts +7 -0
  11. package/dist/features/network-modifications/tabular/index.js +65 -0
  12. package/dist/features/network-modifications/tabular/properties/DefineTabularPropertiesDialog.d.ts +12 -0
  13. package/dist/features/network-modifications/tabular/properties/DefineTabularPropertiesDialog.js +123 -0
  14. package/dist/features/network-modifications/tabular/properties/TabularPropertiesForm.d.ts +1 -0
  15. package/dist/features/network-modifications/tabular/properties/TabularPropertiesForm.js +87 -0
  16. package/dist/features/network-modifications/tabular/properties/TabularPropertyForm.d.ts +5 -0
  17. package/dist/features/network-modifications/tabular/properties/TabularPropertyForm.js +91 -0
  18. package/dist/features/network-modifications/tabular/properties/index.d.ts +4 -0
  19. package/dist/features/network-modifications/tabular/properties/index.js +13 -0
  20. package/dist/features/network-modifications/tabular/properties/tabularProperty.utils.d.ts +26 -0
  21. package/dist/features/network-modifications/tabular/properties/tabularProperty.utils.js +50 -0
  22. package/dist/features/network-modifications/tabular/tabular.constants.d.ts +59 -0
  23. package/dist/features/network-modifications/tabular/tabular.constants.js +75 -0
  24. package/dist/features/network-modifications/tabular/tabular.types.d.ts +41 -0
  25. package/dist/features/network-modifications/tabular/tabular.types.js +8 -0
  26. package/dist/features/network-modifications/tabular/tabular.utils.d.ts +68 -0
  27. package/dist/features/network-modifications/tabular/tabular.utils.js +301 -0
  28. package/dist/features/network-modifications/tabular/tabularCreation.utils.d.ts +25 -0
  29. package/dist/features/network-modifications/tabular/tabularCreation.utils.js +276 -0
  30. package/dist/features/network-modifications/tabular/tabularModification.utils.d.ts +43 -0
  31. package/dist/features/network-modifications/tabular/tabularModification.utils.js +406 -0
  32. package/dist/features/network-modifications/voltageLevel/index.d.ts +2 -1
  33. package/dist/features/network-modifications/voltageLevel/index.js +15 -3
  34. package/dist/features/network-modifications/voltageLevel/topology/{CreateVoltageLevelTopologyForm.d.ts → creation/CreateVoltageLevelTopologyForm.d.ts} +1 -1
  35. package/dist/features/network-modifications/voltageLevel/topology/{CreateVoltageLevelTopologyForm.js → creation/CreateVoltageLevelTopologyForm.js} +38 -38
  36. package/dist/features/network-modifications/voltageLevel/topology/{voltageLevelTopologyCreation.types.d.ts → creation/voltageLevelTopologyCreation.types.d.ts} +1 -1
  37. package/dist/features/network-modifications/voltageLevel/topology/{voltageLevelTopologyCreation.utils.d.ts → creation/voltageLevelTopologyCreation.utils.d.ts} +1 -1
  38. package/dist/features/network-modifications/voltageLevel/topology/{voltageLevelTopologyCreation.utils.js → creation/voltageLevelTopologyCreation.utils.js} +5 -5
  39. package/dist/features/network-modifications/voltageLevel/topology/modification/ConnectionCellRender.d.ts +6 -0
  40. package/dist/features/network-modifications/voltageLevel/topology/modification/ConnectionCellRender.js +80 -0
  41. package/dist/features/network-modifications/voltageLevel/topology/modification/VoltageLevelTopologyModificationForm.d.ts +10 -0
  42. package/dist/features/network-modifications/voltageLevel/topology/modification/VoltageLevelTopologyModificationForm.js +284 -0
  43. package/dist/features/network-modifications/voltageLevel/topology/modification/constants.d.ts +10 -0
  44. package/dist/features/network-modifications/voltageLevel/topology/modification/constants.js +10 -0
  45. package/dist/features/network-modifications/voltageLevel/topology/modification/index.d.ts +10 -0
  46. package/dist/features/network-modifications/voltageLevel/topology/modification/index.js +14 -0
  47. package/dist/features/network-modifications/voltageLevel/topology/modification/voltageLevelTopologyModification.types.d.ts +28 -0
  48. package/dist/features/network-modifications/voltageLevel/topology/modification/voltageLevelTopologyModification.types.js +1 -0
  49. package/dist/features/network-modifications/voltageLevel/topology/modification/voltageLevelTopologyModification.utils.d.ts +29 -0
  50. package/dist/features/network-modifications/voltageLevel/topology/modification/voltageLevelTopologyModification.utils.js +124 -0
  51. package/dist/features/parameters/common/index.d.ts +1 -0
  52. package/dist/features/parameters/common/index.js +2 -0
  53. package/dist/features/parameters/common/parameter-field.d.ts +2 -2
  54. package/dist/features/parameters/common/parameter-field.js +1 -1
  55. package/dist/features/parameters/dynamic-margin-calculation/dynamic-margin-calculation-form.js +1 -1
  56. package/dist/features/parameters/dynamic-margin-calculation/dynamic-margin-calculation-inline.js +6 -6
  57. package/dist/features/parameters/dynamic-margin-calculation/loads-variations-parameters.js +1 -1
  58. package/dist/features/parameters/dynamic-margin-calculation/time-delay-parameters.js +1 -1
  59. package/dist/features/parameters/dynamic-security-analysis/contingency-parameters.js +1 -1
  60. package/dist/features/parameters/dynamic-security-analysis/dynamic-security-analysis-inline.js +6 -6
  61. package/dist/features/parameters/dynamic-security-analysis/dynamic-security-analysis-parameters-form.js +1 -1
  62. package/dist/features/parameters/dynamic-security-analysis/scenario-parameters.js +1 -1
  63. package/dist/features/parameters/dynamic-simulation/dynamic-simulation-inline.js +6 -6
  64. package/dist/features/parameters/dynamic-simulation/dynamic-simulation-parameters-form.js +1 -1
  65. package/dist/features/parameters/dynamic-simulation/network/network-parameters.js +1 -1
  66. package/dist/features/parameters/dynamic-simulation/solver/common-solver/common-solver-parameters.js +1 -1
  67. package/dist/features/parameters/dynamic-simulation/solver/ida-solver/ida-solver-parameters.js +1 -1
  68. package/dist/features/parameters/dynamic-simulation/solver/sim-solver/simplified-solver-parameters.js +1 -1
  69. package/dist/features/parameters/dynamic-simulation/solver/solver-parameters.js +1 -1
  70. package/dist/features/parameters/dynamic-simulation/time-delay/time-delay-parameters.js +1 -1
  71. package/dist/features/parameters/index.js +2 -0
  72. package/dist/features/parameters/loadflow/load-flow-advanced-parameters.js +1 -1
  73. package/dist/features/parameters/loadflow/load-flow-general-parameters.js +1 -1
  74. package/dist/features/parameters/loadflow/load-flow-parameters-inline.js +5 -5
  75. package/dist/features/parameters/loadflow/load-flow-provider-specific-parameters.js +1 -1
  76. package/dist/features/parameters/network-visualizations/network-visualizations-parameters-inline.js +5 -5
  77. package/dist/features/parameters/pcc-min/pcc-min-parameters-inline.js +5 -5
  78. package/dist/features/parameters/security-analysis/security-analysis-parameters-inline.js +6 -6
  79. package/dist/features/parameters/sensi/sensitivity-analysis-parameters-inline.js +6 -6
  80. package/dist/features/parameters/short-circuit/short-circuit-parameters-inline.js +5 -5
  81. package/dist/features/parameters/voltage-init/voltage-init-parameters-inline.js +5 -5
  82. package/dist/features/side-bar/AppSideBarHeader.js +20 -5
  83. package/dist/features/side-bar/EnvironmentChip.d.ts +13 -0
  84. package/dist/features/side-bar/EnvironmentChip.js +49 -0
  85. package/dist/index.js +84 -5
  86. package/dist/services/appsMetadata.d.ts +2 -0
  87. package/dist/services/directory.d.ts +1 -1
  88. package/dist/services/directory.js +6 -2
  89. package/dist/services/index.js +2 -1
  90. package/dist/services/userAdmin.d.ts +2 -1
  91. package/dist/services/userAdmin.js +9 -1
  92. package/dist/translations/en/businessErrorsEn.d.ts +1 -0
  93. package/dist/translations/en/businessErrorsEn.js +1 -0
  94. package/dist/translations/en/networkModificationsEn.d.ts +85 -0
  95. package/dist/translations/en/networkModificationsEn.js +91 -1
  96. package/dist/translations/fr/businessErrorsFr.d.ts +1 -0
  97. package/dist/translations/fr/businessErrorsFr.js +1 -0
  98. package/dist/translations/fr/networkModificationsFr.d.ts +85 -0
  99. package/dist/translations/fr/networkModificationsFr.js +91 -1
  100. package/dist/utils/constants/index.js +2 -1
  101. package/dist/utils/constants/notificationsProvider.d.ts +1 -0
  102. package/dist/utils/constants/notificationsProvider.js +1 -0
  103. package/dist/utils/constants/translationKeys.d.ts +1 -0
  104. package/dist/utils/constants/translationKeys.js +2 -0
  105. package/dist/utils/index.js +2 -1
  106. package/dist/utils/types/types.d.ts +4 -0
  107. package/package.json +1 -1
  108. /package/dist/features/network-modifications/voltageLevel/topology/{index.d.ts → creation/index.d.ts} +0 -0
  109. /package/dist/features/network-modifications/voltageLevel/topology/{index.js → creation/index.js} +0 -0
  110. /package/dist/features/network-modifications/voltageLevel/topology/{voltageLevelTopologyCreation.types.js → creation/voltageLevelTopologyCreation.types.js} +0 -0
@@ -0,0 +1,22 @@
1
+ import { ReactNode } from 'react';
2
+ import { EquipmentType } from '../../../utils';
3
+ import { PredefinedEquipmentProperties, TabularModificationType } from './tabular.types';
4
+ /** Context handed over to the host application when it renders its own actions in the form. */
5
+ export interface TabularFormActionsContext {
6
+ dialogMode: TabularModificationType;
7
+ equipmentType: EquipmentType;
8
+ csvColumns: string[];
9
+ commentLines: string[][];
10
+ predefinedEquipmentProperties: PredefinedEquipmentProperties;
11
+ }
12
+ export interface TabularFormProps {
13
+ dialogMode: TabularModificationType;
14
+ dataFetching?: boolean;
15
+ /**
16
+ * Application specific actions rendered next to the CSV template buttons.
17
+ */
18
+ renderActions?: (context: TabularFormActionsContext) => ReactNode;
19
+ /** Display the name of the CSV file the table was imported from. */
20
+ showCsvFileName?: boolean;
21
+ }
22
+ export declare function TabularForm({ dialogMode, dataFetching, renderActions, showCsvFileName, }: Readonly<TabularFormProps>): import("react").JSX.Element;
@@ -0,0 +1,536 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback, useMemo, useEffect } from "react";
3
+ import { useIntl, FormattedMessage } from "react-intl";
4
+ import { useFormContext, useWatch } from "react-hook-form";
5
+ import { Stack, Grid, Button, Alert } from "@mui/material";
6
+ import { v4 } from "uuid";
7
+ import "@mui/icons-material";
8
+ import "../../../components/ui/overflowableText/OverflowableText.js";
9
+ import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
10
+ import "../../../utils/conversionUtils.js";
11
+ import { EquipmentType } from "../../../utils/types/equipmentType.js";
12
+ import { hasNonEmptyRows } from "../../../utils/functions.js";
13
+ import { transformIfFrenchNumber } from "../../../utils/langs.js";
14
+ import { useStateBoolean } from "../../../hooks/customStates/useStateBoolean.js";
15
+ import { fetchStudyMetadata } from "../../../services/appsMetadata.js";
16
+ import "localized-countries";
17
+ import "localized-countries/data/fr";
18
+ import "localized-countries/data/en";
19
+ import { useSnackMessage } from "../../../hooks/useSnackMessage.js";
20
+ import "../../../components/ui/reactHookForm/provider/CustomFormProvider.js";
21
+ import "yup";
22
+ import "../../../components/ui/treeViewFinder/TreeViewFinder.js";
23
+ import { AutocompleteInput } from "../../../components/ui/reactHookForm/autocompleteInputs/AutocompleteInput.js";
24
+ import "../../../components/ui/reactHookForm/numbers/RangeInput.js";
25
+ import { InputWithPopupConfirmation } from "../../../components/ui/reactHookForm/selectInputs/InputWithPopupConfirmation.js";
26
+ import "@material-symbols/svg-400/outlined/left_panel_open.svg?react";
27
+ import "@material-symbols/svg-400/outlined/arrows_output.svg?react";
28
+ import "@material-symbols/svg-400/outlined/arrows_input.svg?react";
29
+ import "@material-symbols/svg-400/outlined/left_panel_close.svg?react";
30
+ import "@material-symbols/svg-400/outlined/add_notes-fill.svg?react";
31
+ import "../../../components/ui/dialogs/descriptionModificationDialog/DescriptionModificationDialog.js";
32
+ import "../../../components/ui/reactHookForm/expandableInput/ExpandableInput.js";
33
+ import "../../../components/ui/reactHookForm/directory-item-input/directory-item-utils.js";
34
+ import "@hello-pangea/dnd";
35
+ import "../../../components/ui/dialogs/elementSaveDialog/ElementSaveDialog.js";
36
+ import "../../../components/ui/snackbarProvider/SnackbarProvider.js";
37
+ import "mui-nested-menu";
38
+ import "react-resizable-panels";
39
+ import { CsvDownloadButton } from "../../../components/ui/csvDownloader/csv-download-button.js";
40
+ import { CsvPicker } from "../../../components/ui/csvPicker/csv-picker.js";
41
+ import "react-dom";
42
+ import "autosuggest-highlight/match";
43
+ import "autosuggest-highlight/parse";
44
+ import "clsx";
45
+ import "../../../components/composite/filter/FilterCreationDialog.js";
46
+ import "../../../components/composite/filter/HeaderFilterForm.js";
47
+ import "../../../components/composite/filter/explicitNaming/ExplicitNamingFilterForm.js";
48
+ import "../../../components/composite/filter/expert/ExpertFilterForm.js";
49
+ import "../../../components/composite/filter/expert/ExpertFilterEditionDialog.js";
50
+ import "../../../components/composite/filter/expert/expertFilterConstants.js";
51
+ import "react-querybuilder";
52
+ import "../../../components/composite/filter/explicitNaming/ExplicitNamingFilterEditionDialog.js";
53
+ import "../../../components/composite/filter/utils/filterFormUtils.js";
54
+ import "@react-querybuilder/material";
55
+ import "../../../components/composite/reactQueryBuilder/CustomReactQueryBuilder.js";
56
+ import "../../../components/composite/reactQueryBuilder/PropertyValueEditor.js";
57
+ import "../../../components/composite/agGridTable/BottomTableButtons.js";
58
+ import { CustomAgGridTable } from "../../../components/composite/agGridTable/CustomAgGridTable.js";
59
+ import { NumericEditor, suppressNonNumericKeyboardEvent } from "../../../components/composite/agGridTable/cellEditors/numericEditor.js";
60
+ import "../../../components/composite/customAGGrid/customAggrid.js";
61
+ import { DefaultCellRenderer } from "../../../components/composite/customAGGrid/cell-renderers.js";
62
+ import "../../../components/composite/customAGGrid/context/custom-aggrid-context.js";
63
+ import "mathjs";
64
+ import "../../../components/composite/report/report-viewer/log-table/log-table.js";
65
+ import "react-window";
66
+ import "../../../components/composite/report/report-treeview/treeview-item.js";
67
+ import "../../../components/composite/report/report-viewer/context/report-viewer-context.js";
68
+ import { AGGRID_LOCALES } from "../../../translations/not-intl/aggrid-locales.js";
69
+ import { DefineTabularPropertiesDialog } from "./properties/DefineTabularPropertiesDialog.js";
70
+ import { TabularFieldConstants, PROPERTY_CSV_COLUMN_PREFIX, TABULAR_BOOLEAN, TABULAR_ENUM, TABULAR_NUMBER } from "./tabular.constants.js";
71
+ import "../common/properties/propertyUtils.js";
72
+ import "../common/regulatingTerminal/RegulatingTerminalForm.js";
73
+ import "@mui/material/colors";
74
+ import "@mui/x-charts";
75
+ import "../common/currentLimits/limitsPane.utils.js";
76
+ import "./properties/tabularProperty.utils.js";
77
+ import { TABULAR_CREATION_FIELDS } from "./tabularCreation.utils.js";
78
+ import { TABULAR_MODIFICATION_FIELDS } from "./tabularModification.utils.js";
79
+ import { TabularModificationType } from "./tabular.types.js";
80
+ import { isFieldTypeOk, setFieldTypeError, getSelectedTabularPropertyNames, generateCommentLines, sanitizeRowValue } from "./tabular.utils.js";
81
+ function TabularForm({
82
+ dialogMode,
83
+ dataFetching = false,
84
+ renderActions,
85
+ showCsvFileName = true
86
+ }) {
87
+ const intl = useIntl();
88
+ const language = intl.locale;
89
+ const { snackWarning } = useSnackMessage();
90
+ const [isFetching, setIsFetching] = useState(dataFetching);
91
+ const { setValue, clearErrors, setError, getValues } = useFormContext();
92
+ const tableRef = useRef(null);
93
+ const propertiesDialogOpen = useStateBoolean(false);
94
+ const [predefinedEquipmentProperties, setPredefinedEquipmentProperties] = useState(
95
+ {}
96
+ );
97
+ const getTypeLabel = useCallback((type) => intl.formatMessage({ id: type }), [intl]);
98
+ const equipmentType = useWatch({
99
+ name: FieldConstants.TYPE
100
+ });
101
+ const tabularProperties = useWatch({
102
+ name: TabularFieldConstants.TABULAR_PROPERTIES
103
+ });
104
+ const watchFileName = useWatch({
105
+ name: TabularFieldConstants.CSV_FILENAME
106
+ });
107
+ const csvFields = useMemo(() => {
108
+ const fields = dialogMode === TabularModificationType.CREATION ? TABULAR_CREATION_FIELDS : TABULAR_MODIFICATION_FIELDS;
109
+ return fields[equipmentType] ?? [];
110
+ }, [equipmentType, dialogMode]);
111
+ const [selectedFile, setSelectedFile] = useState();
112
+ const [fileErrorMessage, setFileErrorMessage] = useState();
113
+ const [fileWarningMessage, setFileWarningMessage] = useState();
114
+ const parseConfig = useMemo(
115
+ () => ({
116
+ dynamicTyping: (field) => (
117
+ // "property_*" (user added property) columns should remain as strings
118
+ typeof field !== "string" || !field.startsWith(PROPERTY_CSV_COLUMN_PREFIX)
119
+ ),
120
+ transform: (value, field) => {
121
+ if (typeof field === "string" && field.startsWith(PROPERTY_CSV_COLUMN_PREFIX)) {
122
+ return value;
123
+ }
124
+ return transformIfFrenchNumber(value, language);
125
+ }
126
+ }),
127
+ [language]
128
+ );
129
+ const handleBooleanValue = useCallback(
130
+ (key, value, fieldDef) => {
131
+ if (fieldDef?.type !== TABULAR_BOOLEAN) {
132
+ return false;
133
+ }
134
+ if (fieldDef.required && typeof value !== "boolean") {
135
+ setFileWarningMessage(
136
+ intl.formatMessage({ id: "WrongBooleanValueWarning" }, { field: intl.formatMessage({ id: key }) })
137
+ );
138
+ }
139
+ return true;
140
+ },
141
+ [intl]
142
+ );
143
+ const handleTabularCreationParsingError = useCallback(
144
+ (results) => {
145
+ let requiredFieldNameInError = "";
146
+ let requiredDependantFieldNameInError = "";
147
+ let dependantFieldNameInError = "";
148
+ let fieldTypeInError = "";
149
+ let expectedTypeForFieldInError = "";
150
+ let expectedValues;
151
+ if (results.data.flatMap(
152
+ (result) => Object.entries(result).map(([key, value]) => [
153
+ result,
154
+ key,
155
+ value
156
+ ])
157
+ ).some(([result, key, value]) => {
158
+ const fieldDef = csvFields.find((field) => field.id === key);
159
+ if (handleBooleanValue(key, value, fieldDef)) {
160
+ return false;
161
+ }
162
+ if (fieldDef !== void 0 && fieldDef.required && (value === void 0 || value === null)) {
163
+ requiredFieldNameInError = key;
164
+ return true;
165
+ }
166
+ if (fieldDef?.requiredIf) {
167
+ const dependentValue = result[fieldDef.requiredIf.id];
168
+ if (dependentValue !== void 0 && dependentValue !== null && (value === void 0 || value === null)) {
169
+ dependantFieldNameInError = key;
170
+ requiredDependantFieldNameInError = fieldDef.requiredIf.id;
171
+ return true;
172
+ }
173
+ }
174
+ if (!isFieldTypeOk(value, fieldDef)) {
175
+ fieldTypeInError = key;
176
+ expectedTypeForFieldInError = fieldDef?.type ?? "";
177
+ expectedValues = fieldDef?.options;
178
+ return true;
179
+ }
180
+ return false;
181
+ })) {
182
+ if (requiredFieldNameInError !== "") {
183
+ setError(TabularFieldConstants.MODIFICATIONS_TABLE, {
184
+ type: "custom",
185
+ message: intl.formatMessage(
186
+ { id: "FieldRequired" },
187
+ { requiredFieldNameInError: intl.formatMessage({ id: requiredFieldNameInError }) }
188
+ )
189
+ });
190
+ } else if (dependantFieldNameInError !== "" && requiredDependantFieldNameInError !== "") {
191
+ setError(TabularFieldConstants.MODIFICATIONS_TABLE, {
192
+ type: "custom",
193
+ message: intl.formatMessage(
194
+ { id: "DependantFieldMissing" },
195
+ {
196
+ requiredField: intl.formatMessage({ id: dependantFieldNameInError }),
197
+ dependantField: intl.formatMessage({ id: requiredDependantFieldNameInError })
198
+ }
199
+ )
200
+ });
201
+ } else if (fieldTypeInError !== "") {
202
+ setFieldTypeError(
203
+ intl.formatMessage({ id: fieldTypeInError }),
204
+ expectedTypeForFieldInError,
205
+ TabularFieldConstants.MODIFICATIONS_TABLE,
206
+ setError,
207
+ intl,
208
+ expectedValues
209
+ );
210
+ }
211
+ }
212
+ if (equipmentType === EquipmentType.SHUNT_COMPENSATOR && results.data.some(
213
+ (creation) => creation.maxSusceptance != null && (creation.shuntCompensatorType || creation.maxQAtNominalV != null)
214
+ )) {
215
+ snackWarning({
216
+ messageId: "TabularCreationShuntWarning"
217
+ });
218
+ }
219
+ },
220
+ [csvFields, equipmentType, handleBooleanValue, intl, setError, snackWarning]
221
+ );
222
+ const handleTabularModificationParsingError = useCallback(
223
+ (results) => {
224
+ let fieldTypeInError = "";
225
+ let expectedTypeForFieldInError = "";
226
+ let expectedValues;
227
+ if (results.data.flatMap(Object.entries).some(([key, value]) => {
228
+ const fieldDef = csvFields.find((field) => field.id === key);
229
+ if (handleBooleanValue(key, value, fieldDef)) {
230
+ return false;
231
+ }
232
+ if (!isFieldTypeOk(value, fieldDef)) {
233
+ fieldTypeInError = key;
234
+ expectedTypeForFieldInError = fieldDef?.type ?? "";
235
+ expectedValues = fieldDef?.options;
236
+ return true;
237
+ }
238
+ return false;
239
+ })) {
240
+ setFieldTypeError(
241
+ intl.formatMessage({ id: fieldTypeInError }),
242
+ expectedTypeForFieldInError,
243
+ TabularFieldConstants.MODIFICATIONS_TABLE,
244
+ setError,
245
+ intl,
246
+ expectedValues
247
+ );
248
+ }
249
+ if (equipmentType === EquipmentType.SHUNT_COMPENSATOR && results.data.some(
250
+ (modification) => modification.maxSusceptance != null && (modification.shuntCompensatorType || modification.maxQAtNominalV != null)
251
+ )) {
252
+ snackWarning({ messageId: "TabularModificationShuntWarning" });
253
+ }
254
+ },
255
+ [equipmentType, csvFields, handleBooleanValue, setError, intl, snackWarning]
256
+ );
257
+ const selectedProperties = useMemo(
258
+ () => getSelectedTabularPropertyNames(tabularProperties),
259
+ [tabularProperties]
260
+ );
261
+ const csvColumns = useMemo(() => {
262
+ return csvFields.map((field) => field.id).concat(selectedProperties.map((propertyName) => PROPERTY_CSV_COLUMN_PREFIX + propertyName));
263
+ }, [csvFields, selectedProperties]);
264
+ const requiredColumns = useMemo(
265
+ () => csvFields.filter((field) => field.required).map((field) => field.id),
266
+ [csvFields]
267
+ );
268
+ const commentLines = useMemo(() => {
269
+ return generateCommentLines({
270
+ fields: csvFields,
271
+ selectedProperties,
272
+ intl,
273
+ equipmentType,
274
+ language,
275
+ formType: dialogMode,
276
+ predefinedEquipmentProperties
277
+ });
278
+ }, [csvFields, selectedProperties, intl, equipmentType, language, dialogMode, predefinedEquipmentProperties]);
279
+ const getTemplateData = useCallback(() => [csvColumns, ...commentLines], [csvColumns, commentLines]);
280
+ const getTableData = useCallback(() => {
281
+ const rows = getValues(TabularFieldConstants.MODIFICATIONS_TABLE) ?? [];
282
+ return [...getTemplateData(), ...rows.map((row) => csvColumns.map((col) => row[col] ?? ""))];
283
+ }, [csvColumns, getValues, getTemplateData]);
284
+ const csvProps = useMemo(
285
+ () => ({
286
+ fileName: `${equipmentType}${dialogMode === TabularModificationType.CREATION ? "_creation" : "_modification"}_template`,
287
+ language,
288
+ getTableData
289
+ }),
290
+ [equipmentType, dialogMode, language, getTableData]
291
+ );
292
+ const getDataFromCsvFile = useCallback(
293
+ (results, file) => {
294
+ clearErrors(TabularFieldConstants.MODIFICATIONS_TABLE);
295
+ setFileWarningMessage(void 0);
296
+ if (dialogMode === TabularModificationType.CREATION) {
297
+ handleTabularCreationParsingError(results);
298
+ } else {
299
+ handleTabularModificationParsingError(results);
300
+ }
301
+ setValue(TabularFieldConstants.CSV_FILENAME, file.name);
302
+ return results.data.map((row) => {
303
+ const sanitizedRow = {
304
+ [FieldConstants.AG_GRID_ROW_UUID]: v4()
305
+ };
306
+ Object.entries(row).forEach(([key, value]) => {
307
+ sanitizedRow[key] = sanitizeRowValue(
308
+ value,
309
+ csvFields.find((field) => field.id === key)
310
+ );
311
+ });
312
+ return sanitizedRow;
313
+ });
314
+ },
315
+ [
316
+ clearErrors,
317
+ csvFields,
318
+ dialogMode,
319
+ handleTabularCreationParsingError,
320
+ handleTabularModificationParsingError,
321
+ setValue
322
+ ]
323
+ );
324
+ useEffect(() => {
325
+ fetchStudyMetadata().then((studyMetadata) => {
326
+ setPredefinedEquipmentProperties(studyMetadata?.predefinedEquipmentProperties ?? {});
327
+ });
328
+ }, []);
329
+ useEffect(() => {
330
+ if (!showCsvFileName) {
331
+ return;
332
+ }
333
+ setSelectedFile(watchFileName ? new File([], watchFileName) : void 0);
334
+ }, [watchFileName, showCsvFileName]);
335
+ useEffect(() => {
336
+ setIsFetching(dataFetching);
337
+ }, [dataFetching]);
338
+ const typesOptions = useMemo(() => {
339
+ return Object.keys(
340
+ dialogMode === TabularModificationType.CREATION ? TABULAR_CREATION_FIELDS : TABULAR_MODIFICATION_FIELDS
341
+ );
342
+ }, [dialogMode]);
343
+ const resetOnTypeChange = useCallback(() => {
344
+ setValue(TabularFieldConstants.CSV_FILENAME, void 0);
345
+ setValue(TabularFieldConstants.TABULAR_PROPERTIES, []);
346
+ setSelectedFile(void 0);
347
+ setFileErrorMessage(void 0);
348
+ setFileWarningMessage(void 0);
349
+ clearErrors(TabularFieldConstants.MODIFICATIONS_TABLE);
350
+ tableRef.current?.replace([]);
351
+ }, [clearErrors, setValue]);
352
+ const equipmentTypeField = /* @__PURE__ */ jsx(
353
+ InputWithPopupConfirmation,
354
+ {
355
+ Input: AutocompleteInput,
356
+ name: FieldConstants.TYPE,
357
+ label: "Type",
358
+ options: typesOptions,
359
+ getOptionLabel: (option) => getTypeLabel(option),
360
+ size: "small",
361
+ formProps: { variant: "outlined" },
362
+ shouldOpenPopup: () => hasNonEmptyRows(getValues(TabularFieldConstants.MODIFICATIONS_TABLE)),
363
+ onValueChange: resetOnTypeChange,
364
+ message: "changeTypeMessage",
365
+ validateButtonLabel: "button.changeType"
366
+ }
367
+ );
368
+ const defaultColDef = useMemo(
369
+ () => ({
370
+ sortable: true,
371
+ resizable: false,
372
+ lockPinned: true,
373
+ wrapHeaderText: true,
374
+ autoHeaderHeight: true,
375
+ cellRenderer: DefaultCellRenderer
376
+ }),
377
+ []
378
+ );
379
+ const columnDefs = useMemo(() => {
380
+ return csvFields.map((field) => {
381
+ const columnDef = {
382
+ field: field.id,
383
+ headerName: intl.formatMessage({ id: field.id }) + (field.required ? " (*)" : ""),
384
+ editable: true,
385
+ singleClickEdit: true
386
+ };
387
+ if (field.id === TabularFieldConstants.EQUIPMENT_ID) {
388
+ columnDef.pinned = true;
389
+ }
390
+ switch (field.type) {
391
+ case TABULAR_BOOLEAN:
392
+ columnDef.cellDataType = TABULAR_BOOLEAN;
393
+ break;
394
+ case TABULAR_NUMBER:
395
+ columnDef.cellDataType = TABULAR_NUMBER;
396
+ columnDef.cellEditor = NumericEditor;
397
+ columnDef.cellEditorParams = { allowNegativeValues: true };
398
+ columnDef.suppressKeyboardEvent = suppressNonNumericKeyboardEvent;
399
+ break;
400
+ case TABULAR_ENUM:
401
+ columnDef.cellDataType = "text";
402
+ columnDef.cellEditor = "agSelectCellEditor";
403
+ columnDef.cellEditorParams = { values: [null, ...field.options ?? []] };
404
+ break;
405
+ }
406
+ return columnDef;
407
+ }).concat(
408
+ selectedProperties.map((propertyName) => ({
409
+ field: PROPERTY_CSV_COLUMN_PREFIX + propertyName,
410
+ headerName: propertyName,
411
+ // property values are always kept as strings (see parseConfig)
412
+ cellDataType: "text",
413
+ editable: true,
414
+ singleClickEdit: true
415
+ }))
416
+ );
417
+ }, [csvFields, selectedProperties, intl]);
418
+ const makeDefaultRowData = useCallback(() => {
419
+ const row = { [FieldConstants.AG_GRID_ROW_UUID]: v4() };
420
+ csvFields.forEach((field) => {
421
+ row[field.id] = null;
422
+ });
423
+ selectedProperties.forEach((propertyName) => {
424
+ row[PROPERTY_CSV_COLUMN_PREFIX + propertyName] = null;
425
+ });
426
+ return row;
427
+ }, [csvFields, selectedProperties]);
428
+ const onPropertiesChange = (formData) => {
429
+ const newSelectedProperties = getSelectedTabularPropertyNames(
430
+ formData[TabularFieldConstants.TABULAR_PROPERTIES]
431
+ );
432
+ if (newSelectedProperties.toString() !== selectedProperties.toString()) {
433
+ clearErrors(TabularFieldConstants.MODIFICATIONS_TABLE);
434
+ const removedPropertyColumns = selectedProperties.filter((name) => !newSelectedProperties.includes(name)).map((name) => PROPERTY_CSV_COLUMN_PREFIX + name);
435
+ const addedPropertyColumns = newSelectedProperties.filter((name) => !selectedProperties.includes(name)).map((name) => PROPERTY_CSV_COLUMN_PREFIX + name);
436
+ const currentRows = getValues(TabularFieldConstants.MODIFICATIONS_TABLE) ?? [];
437
+ const updatedRows = currentRows.map((row) => {
438
+ const newRow = { ...row };
439
+ removedPropertyColumns.forEach((col) => {
440
+ delete newRow[col];
441
+ });
442
+ addedPropertyColumns.forEach((col) => {
443
+ newRow[col] = null;
444
+ });
445
+ return newRow;
446
+ });
447
+ tableRef.current?.replace(updatedRows);
448
+ }
449
+ setValue(TabularFieldConstants.TABULAR_PROPERTIES, formData[TabularFieldConstants.TABULAR_PROPERTIES], {
450
+ shouldDirty: true
451
+ });
452
+ };
453
+ return /* @__PURE__ */ jsxs(Stack, { spacing: 2, paddingTop: 1, sx: { height: "100%" }, children: [
454
+ /* @__PURE__ */ jsx(Grid, { sx: { width: 400, maxWidth: "100%" }, children: equipmentTypeField }),
455
+ equipmentType && /* @__PURE__ */ jsxs(Fragment, { children: [
456
+ /* @__PURE__ */ jsxs(Grid, { container: true, spacing: 2, justifyContent: "space-between", alignItems: "center", children: [
457
+ /* @__PURE__ */ jsxs(Grid, { container: true, alignItems: "center", children: [
458
+ /* @__PURE__ */ jsx(Grid, { children: /* @__PURE__ */ jsx(
459
+ Button,
460
+ {
461
+ variant: "contained",
462
+ onClick: () => {
463
+ propertiesDialogOpen.setTrue();
464
+ },
465
+ children: /* @__PURE__ */ jsx(FormattedMessage, { id: "DefinePropertiesButton" })
466
+ }
467
+ ) }),
468
+ /* @__PURE__ */ jsx(Grid, { children: /* @__PURE__ */ jsx(
469
+ CsvDownloadButton,
470
+ {
471
+ data: getTemplateData,
472
+ fileName: csvProps.fileName,
473
+ language,
474
+ labelId: "GenerateCSV",
475
+ variant: "contained"
476
+ }
477
+ ) }),
478
+ renderActions?.({
479
+ dialogMode,
480
+ equipmentType,
481
+ csvColumns,
482
+ commentLines,
483
+ predefinedEquipmentProperties
484
+ })
485
+ ] }),
486
+ /* @__PURE__ */ jsx(Grid, { sx: { flex: 1, minWidth: 0 }, children: /* @__PURE__ */ jsx(
487
+ CsvPicker,
488
+ {
489
+ label: "UploadCSV",
490
+ requiredColumns,
491
+ language,
492
+ parseConfig,
493
+ selectedFile: showCsvFileName ? selectedFile : void 0,
494
+ onFileChange: setSelectedFile,
495
+ onFileError: setFileErrorMessage,
496
+ getTableData: () => getValues(TabularFieldConstants.MODIFICATIONS_TABLE),
497
+ onReplace: (results, file) => tableRef.current?.replace(getDataFromCsvFile(results, file)),
498
+ onAppend: (results, file) => tableRef.current?.append(getDataFromCsvFile(results, file))
499
+ }
500
+ ) })
501
+ ] }),
502
+ fileErrorMessage && /* @__PURE__ */ jsx(Grid, { children: /* @__PURE__ */ jsx(Alert, { severity: "error", children: fileErrorMessage }) }),
503
+ fileWarningMessage && /* @__PURE__ */ jsx(Grid, { children: /* @__PURE__ */ jsx(Alert, { severity: "warning", children: fileWarningMessage }) }),
504
+ /* @__PURE__ */ jsx(Grid, { sx: { flexGrow: 1, minHeight: 0, display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ jsx(
505
+ CustomAgGridTable,
506
+ {
507
+ ref: tableRef,
508
+ name: TabularFieldConstants.MODIFICATIONS_TABLE,
509
+ columnDefs,
510
+ defaultColDef,
511
+ makeDefaultRowData,
512
+ loading: isFetching,
513
+ pagination: true,
514
+ rowSelection: {
515
+ mode: "multiRow"
516
+ },
517
+ overrideLocales: AGGRID_LOCALES,
518
+ csvProps
519
+ }
520
+ ) })
521
+ ] }),
522
+ /* @__PURE__ */ jsx(
523
+ DefineTabularPropertiesDialog,
524
+ {
525
+ open: propertiesDialogOpen,
526
+ equipmentType,
527
+ currentProperties: tabularProperties,
528
+ predefinedEquipmentProperties,
529
+ onValidate: onPropertiesChange
530
+ }
531
+ )
532
+ ] });
533
+ }
534
+ export {
535
+ TabularForm
536
+ };
@@ -0,0 +1,7 @@
1
+ export * from './properties';
2
+ export * from './tabular.constants';
3
+ export * from './tabular.types';
4
+ export * from './tabular.utils';
5
+ export * from './tabularCreation.utils';
6
+ export * from './tabularModification.utils';
7
+ export * from './TabularForm';
@@ -0,0 +1,65 @@
1
+ import { DefineTabularPropertiesDialog } from "./properties/DefineTabularPropertiesDialog.js";
2
+ import { TabularPropertiesForm } from "./properties/TabularPropertiesForm.js";
3
+ import { TabularPropertyForm } from "./properties/TabularPropertyForm.js";
4
+ import { buildPredefinedTabularProperties, emptyTabularProperties, initializedTabularProperty, tabularPropertiesSchema } from "./properties/tabularProperty.utils.js";
5
+ import { LOAD_TYPES_FOR_LOAD_TABULAR_CREATION_MODIFICATION, PROPERTY_CSV_COLUMN_PREFIX, REGULATING_TERMINAL_TYPES, TABULAR_BOOLEAN, TABULAR_ENUM, TABULAR_NUMBER, TabularFieldConstants } from "./tabular.constants.js";
6
+ import { TabularModificationType } from "./tabular.types.js";
7
+ import { addPropertiesFromBack, convertReactiveCapabilityCurvePointsFromBackToFront, convertReactiveCapabilityCurvePointsFromFrontToBack, formatModification, generateCommentLines, getEmptyTabularFormData, getSelectedTabularPropertyNames, isFieldTypeOk, sanitizeRowValue, setFieldTypeError, tabularFormSchema, transformProperties } from "./tabular.utils.js";
8
+ import { TABULAR_CREATION_FIELDS, TABULAR_CREATION_TYPES, convertCreationFieldFromBackToFront, convertCreationFieldFromFrontToBack, convertCreations, getEquipmentTypeFromCreationType, tabularCreationDtoToForm, tabularCreationFormToDto, transformCreationsTable, transformRowToBackEndCreation } from "./tabularCreation.utils.js";
9
+ import { MODIFICATION_TRANSFORMATION_STRATEGIES, TABULAR_MODIFICATION_FIELDS, TABULAR_MODIFICATION_TYPES, TWT_TAP_CHANGER_FIELDS, convertGeneratorOrBatteryModificationFromBackToFront, convertGeneratorOrBatteryModificationFromFrontToBack, convertInputValues, convertOutputValues, convertTWTTapChangerModificationFromFrontToBack, getEquipmentTypeFromModificationType, getTabularFieldType, tabularModificationDtoToForm, tabularModificationFormToDto, transformModificationsTable, transformRowToBackEndModification } from "./tabularModification.utils.js";
10
+ import { TabularForm } from "./TabularForm.js";
11
+ export {
12
+ DefineTabularPropertiesDialog,
13
+ LOAD_TYPES_FOR_LOAD_TABULAR_CREATION_MODIFICATION,
14
+ MODIFICATION_TRANSFORMATION_STRATEGIES,
15
+ PROPERTY_CSV_COLUMN_PREFIX,
16
+ REGULATING_TERMINAL_TYPES,
17
+ TABULAR_BOOLEAN,
18
+ TABULAR_CREATION_FIELDS,
19
+ TABULAR_CREATION_TYPES,
20
+ TABULAR_ENUM,
21
+ TABULAR_MODIFICATION_FIELDS,
22
+ TABULAR_MODIFICATION_TYPES,
23
+ TABULAR_NUMBER,
24
+ TWT_TAP_CHANGER_FIELDS,
25
+ TabularFieldConstants,
26
+ TabularForm,
27
+ TabularModificationType,
28
+ TabularPropertiesForm,
29
+ TabularPropertyForm,
30
+ addPropertiesFromBack,
31
+ buildPredefinedTabularProperties,
32
+ convertCreationFieldFromBackToFront,
33
+ convertCreationFieldFromFrontToBack,
34
+ convertCreations,
35
+ convertGeneratorOrBatteryModificationFromBackToFront,
36
+ convertGeneratorOrBatteryModificationFromFrontToBack,
37
+ convertInputValues,
38
+ convertOutputValues,
39
+ convertReactiveCapabilityCurvePointsFromBackToFront,
40
+ convertReactiveCapabilityCurvePointsFromFrontToBack,
41
+ convertTWTTapChangerModificationFromFrontToBack,
42
+ emptyTabularProperties,
43
+ formatModification,
44
+ generateCommentLines,
45
+ getEmptyTabularFormData,
46
+ getEquipmentTypeFromCreationType,
47
+ getEquipmentTypeFromModificationType,
48
+ getSelectedTabularPropertyNames,
49
+ getTabularFieldType,
50
+ initializedTabularProperty,
51
+ isFieldTypeOk,
52
+ sanitizeRowValue,
53
+ setFieldTypeError,
54
+ tabularCreationDtoToForm,
55
+ tabularCreationFormToDto,
56
+ tabularFormSchema,
57
+ tabularModificationDtoToForm,
58
+ tabularModificationFormToDto,
59
+ tabularPropertiesSchema,
60
+ transformCreationsTable,
61
+ transformModificationsTable,
62
+ transformProperties,
63
+ transformRowToBackEndCreation,
64
+ transformRowToBackEndModification
65
+ };
@@ -0,0 +1,12 @@
1
+ import { EquipmentType } from '../../../../utils';
2
+ import { UseStateBooleanReturn } from '../../../../hooks';
3
+ import { PredefinedEquipmentProperties } from '../tabular.types';
4
+ import { TabularPropertiesFormType, TabularProperty } from './tabularProperty.utils';
5
+ export interface DefineTabularPropertiesDialogProps {
6
+ open: UseStateBooleanReturn;
7
+ equipmentType: EquipmentType;
8
+ currentProperties: TabularProperty[];
9
+ predefinedEquipmentProperties: PredefinedEquipmentProperties;
10
+ onValidate: (formData: TabularPropertiesFormType) => void;
11
+ }
12
+ export declare function DefineTabularPropertiesDialog({ open, equipmentType, currentProperties, predefinedEquipmentProperties, onValidate, }: Readonly<DefineTabularPropertiesDialogProps>): import("react").JSX.Element;