@gridsuite/commons-ui 0.194.0 → 0.195.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/dist/components/network-modifications/by-filter/assignment/assignment/assignment-form.js +72 -53
- package/dist/components/network-modifications/by-filter/assignment/assignment/assignment-utils.d.ts +1 -0
- package/dist/components/network-modifications/by-filter/assignment/assignment/assignment-utils.js +8 -5
- package/dist/components/network-modifications/by-filter/assignment/modificationByAssignment.utils.js +5 -5
- package/dist/components/parameters/common/parameter-table-field/parameter-table-field.js +1 -1
- package/dist/components/parameters/dynamic-margin-calculation/loads-variations-parameters.js +1 -2
- package/package.json +1 -1
package/dist/components/network-modifications/by-filter/assignment/assignment/assignment-form.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo, useCallback } from "react";
|
|
2
|
+
import { useMemo, useRef, useState, useEffect, useCallback } from "react";
|
|
3
3
|
import { DensityLarge } from "@mui/icons-material";
|
|
4
4
|
import { useFormContext, useWatch } from "react-hook-form";
|
|
5
5
|
import { useIntl } from "react-intl";
|
|
@@ -8,14 +8,13 @@ import "../../../../../utils/conversionUtils.js";
|
|
|
8
8
|
import { ElementType } from "../../../../../utils/types/elementType.js";
|
|
9
9
|
import "../../../../../utils/types/equipmentType.js";
|
|
10
10
|
import { FieldType } from "../../../../../utils/types/fieldType.js";
|
|
11
|
-
import {
|
|
11
|
+
import { getIdOrValue, areIdsEqual } from "../../../../../utils/ts-utils.js";
|
|
12
12
|
import "../../../../../utils/yupConfig.js";
|
|
13
13
|
import "@mui/material";
|
|
14
14
|
import "localized-countries";
|
|
15
15
|
import "localized-countries/data/fr";
|
|
16
16
|
import "localized-countries/data/en";
|
|
17
17
|
import { usePredefinedProperties } from "../../../../../hooks/usePredefinedProperties.js";
|
|
18
|
-
import { usePrevious } from "../../../../../hooks/usePrevious.js";
|
|
19
18
|
import "notistack";
|
|
20
19
|
import { useFormatLabelWithUnit } from "../../../../../hooks/useFormatLabelWithUnit.js";
|
|
21
20
|
import "../../../../overflowableText/OverflowableText.js";
|
|
@@ -49,6 +48,7 @@ import "react-querybuilder";
|
|
|
49
48
|
import { DataType } from "./assignment.type.js";
|
|
50
49
|
import GridItem from "../../../../grid/grid-item.js";
|
|
51
50
|
import { EQUIPMENTS_FIELDS } from "./assignment-constants.js";
|
|
51
|
+
import { EMPTY_FIELD_VALUE } from "./assignment-utils.js";
|
|
52
52
|
const comparatorStrIgnoreCase = (str1, str2) => {
|
|
53
53
|
return str1?.toLowerCase()?.localeCompare(str2?.toLowerCase());
|
|
54
54
|
};
|
|
@@ -94,24 +94,31 @@ function AssignmentForm(props) {
|
|
|
94
94
|
const options = useMemo(() => {
|
|
95
95
|
return equipmentFields?.find((fieldOption) => fieldOption?.id === watchEditedField)?.values ?? [];
|
|
96
96
|
}, [watchEditedField, equipmentFields]);
|
|
97
|
-
const
|
|
98
|
-
if (prevDataType && prevDataType !== dataType) {
|
|
99
|
-
setValue(`${name}.${index}.${FieldConstants.VALUE}`, dataType === DataType.BOOLEAN ? false : null);
|
|
100
|
-
}
|
|
101
|
-
const emptyValueStr = useMemo(() => {
|
|
97
|
+
const emptyFieldLabel = useMemo(() => {
|
|
102
98
|
return intl.formatMessage({ id: "EmptyField" });
|
|
103
99
|
}, [intl]);
|
|
104
100
|
const formatLabelWithUnit = useFormatLabelWithUnit();
|
|
101
|
+
const prevEditedField = useRef(watchEditedField);
|
|
102
|
+
const [editedFieldKey, setEditedFieldKey] = useState(watchEditedField);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (prevEditedField.current !== watchEditedField) {
|
|
105
|
+
prevEditedField.current = watchEditedField;
|
|
106
|
+
setValue(`${name}.${index}.${FieldConstants.VALUE}`, dataType === DataType.BOOLEAN ? false : null);
|
|
107
|
+
setValue(`${name}.${index}.${FieldConstants.PROPERTY_NAME}`, null);
|
|
108
|
+
setEditedFieldKey(watchEditedField);
|
|
109
|
+
}
|
|
110
|
+
}, [dataType, index, name, setValue, watchEditedField]);
|
|
105
111
|
const renderAutoCompleteSettableToNone = useCallback(
|
|
106
112
|
(numberOnly) => /* @__PURE__ */ jsx(
|
|
107
113
|
AutocompleteInput,
|
|
108
114
|
{
|
|
109
115
|
name: `${name}.${index}.${FieldConstants.VALUE}`,
|
|
110
116
|
label: "ValueOrEmptyField",
|
|
111
|
-
options: [
|
|
117
|
+
options: [emptyFieldLabel],
|
|
112
118
|
size: "small",
|
|
113
119
|
onCheckNewValue: numberOnly ? (option) => {
|
|
114
|
-
|
|
120
|
+
const optionValue = getIdOrValue(option);
|
|
121
|
+
if (optionValue && optionValue !== emptyFieldLabel && optionValue !== EMPTY_FIELD_VALUE && Number.isNaN(Number(optionValue))) {
|
|
115
122
|
setError(`${name}.${index}.${FieldConstants.VALUE}`, {
|
|
116
123
|
message: "NumericValueOrEmptyField"
|
|
117
124
|
});
|
|
@@ -123,10 +130,19 @@ function AssignmentForm(props) {
|
|
|
123
130
|
return true;
|
|
124
131
|
} : void 0,
|
|
125
132
|
getOptionLabel: (option) => typeof option !== "string" ? option?.label ?? option : option,
|
|
133
|
+
inputTransform: (value) => value === EMPTY_FIELD_VALUE ? emptyFieldLabel : value,
|
|
134
|
+
outputTransform: (value) => {
|
|
135
|
+
const optionValue = getIdOrValue(value);
|
|
136
|
+
if (optionValue === emptyFieldLabel) {
|
|
137
|
+
return EMPTY_FIELD_VALUE;
|
|
138
|
+
}
|
|
139
|
+
return optionValue ?? null;
|
|
140
|
+
},
|
|
126
141
|
allowNewValue: true
|
|
127
|
-
}
|
|
142
|
+
},
|
|
143
|
+
editedFieldKey
|
|
128
144
|
),
|
|
129
|
-
[
|
|
145
|
+
[emptyFieldLabel, index, name, setError, editedFieldKey]
|
|
130
146
|
);
|
|
131
147
|
const filtersField = /* @__PURE__ */ jsx(
|
|
132
148
|
DirectoryItemsInput,
|
|
@@ -162,47 +178,50 @@ function AssignmentForm(props) {
|
|
|
162
178
|
allowNewValue: true
|
|
163
179
|
}
|
|
164
180
|
);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
181
|
+
let valueField;
|
|
182
|
+
if (dataType === DataType.PROPERTY) {
|
|
183
|
+
valueField = /* @__PURE__ */ jsx(
|
|
184
|
+
AutocompleteInput,
|
|
185
|
+
{
|
|
186
|
+
name: `${name}.${index}.${FieldConstants.VALUE}`,
|
|
187
|
+
label: "PropertyValue",
|
|
188
|
+
options: predefinedPropertiesValues,
|
|
189
|
+
size: "small",
|
|
190
|
+
allowNewValue: true
|
|
191
|
+
},
|
|
192
|
+
editedFieldKey
|
|
193
|
+
);
|
|
194
|
+
} else if (dataType === DataType.INTEGER) {
|
|
195
|
+
valueField = /* @__PURE__ */ jsx(IntegerInput, { name: `${name}.${index}.${FieldConstants.VALUE}`, label: "Value" }, editedFieldKey);
|
|
196
|
+
} else if (dataType === DataType.BOOLEAN) {
|
|
197
|
+
valueField = /* @__PURE__ */ jsx(
|
|
198
|
+
SwitchInput,
|
|
199
|
+
{
|
|
200
|
+
name: `${name}.${index}.${FieldConstants.VALUE}`,
|
|
201
|
+
formProps: { value: false }
|
|
202
|
+
},
|
|
203
|
+
editedFieldKey
|
|
204
|
+
);
|
|
205
|
+
} else if (dataType === DataType.ENUM) {
|
|
206
|
+
valueField = /* @__PURE__ */ jsx(
|
|
207
|
+
SelectInput,
|
|
208
|
+
{
|
|
209
|
+
name: `${name}.${index}.${FieldConstants.VALUE}`,
|
|
210
|
+
label: "Value",
|
|
211
|
+
options,
|
|
212
|
+
size: "small"
|
|
213
|
+
},
|
|
214
|
+
editedFieldKey
|
|
215
|
+
);
|
|
216
|
+
} else if (dataType === DataType.STRING && settableToNone) {
|
|
217
|
+
valueField = renderAutoCompleteSettableToNone();
|
|
218
|
+
} else if (dataType === DataType.STRING) {
|
|
219
|
+
valueField = /* @__PURE__ */ jsx(TextInput, { name: `${name}.${index}.${FieldConstants.VALUE}`, label: "Value", clearable: true }, editedFieldKey);
|
|
220
|
+
} else if (dataType === DataType.DOUBLE && settableToNone) {
|
|
221
|
+
valueField = renderAutoCompleteSettableToNone(true);
|
|
222
|
+
} else {
|
|
223
|
+
valueField = /* @__PURE__ */ jsx(FloatInput, { name: `${name}.${index}.${FieldConstants.VALUE}`, label: "Value" }, editedFieldKey);
|
|
224
|
+
}
|
|
206
225
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
207
226
|
/* @__PURE__ */ jsx(GridItem, { size: 3.25, children: filtersField }),
|
|
208
227
|
/* @__PURE__ */ jsx(GridItem, { size: 3, children: editedField }),
|
package/dist/components/network-modifications/by-filter/assignment/assignment/assignment-utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { yupConfig as yup } from '../../../../../utils';
|
|
2
2
|
import { Assignment, DataType, FieldOptionType, FieldValue } from './assignment.type';
|
|
3
|
+
export declare const EMPTY_FIELD_VALUE = "\u2014";
|
|
3
4
|
export declare const getFieldOption: (fieldName?: string | null) => FieldOptionType | undefined;
|
|
4
5
|
export declare const getDataType: (fieldName?: string | null) => DataType | undefined;
|
|
5
6
|
export declare const getUnsettable: (fieldName?: string | null) => boolean | undefined;
|
package/dist/components/network-modifications/by-filter/assignment/assignment/assignment-utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FieldConstants } from "../../../../../utils/constants/fieldConstants.js";
|
|
2
|
+
import { YUP_REQUIRED } from "../../../../../utils/constants/translationKeys.js";
|
|
2
3
|
import "../../../../../utils/conversionUtils.js";
|
|
3
4
|
import "../../../../../utils/types/equipmentType.js";
|
|
4
5
|
import "react/jsx-runtime";
|
|
@@ -7,6 +8,7 @@ import "../../../../../utils/yupConfig.js";
|
|
|
7
8
|
import { DataType } from "./assignment.type.js";
|
|
8
9
|
import { FIELD_OPTIONS } from "./assignment-constants.js";
|
|
9
10
|
import * as yup from "yup";
|
|
11
|
+
const EMPTY_FIELD_VALUE = "—";
|
|
10
12
|
const getFieldOption = (fieldName) => {
|
|
11
13
|
return Object.values(FIELD_OPTIONS).find((fieldOption) => fieldOption.id === fieldName);
|
|
12
14
|
};
|
|
@@ -40,7 +42,7 @@ function getValueSchema(emptyValueStr, dataType, settable_to_none) {
|
|
|
40
42
|
default:
|
|
41
43
|
schema = yup.number();
|
|
42
44
|
}
|
|
43
|
-
return schema.required();
|
|
45
|
+
return schema.required(YUP_REQUIRED);
|
|
44
46
|
}
|
|
45
47
|
const getAssignmentInitialValue = () => ({
|
|
46
48
|
[FieldConstants.FILTERS]: [],
|
|
@@ -56,12 +58,12 @@ function getAssignmentsSchema(emptyValueStr) {
|
|
|
56
58
|
[FieldConstants.ID]: yup.string().required(),
|
|
57
59
|
[FieldConstants.NAME]: yup.string().required()
|
|
58
60
|
})
|
|
59
|
-
).required().min(1,
|
|
60
|
-
[FieldConstants.EDITED_FIELD]: yup.string().required(),
|
|
61
|
+
).required().min(1, YUP_REQUIRED),
|
|
62
|
+
[FieldConstants.EDITED_FIELD]: yup.string().required(YUP_REQUIRED),
|
|
61
63
|
[FieldConstants.PROPERTY_NAME]: yup.string().when([FieldConstants.EDITED_FIELD], ([editedField], schema) => {
|
|
62
64
|
const dataType = getDataType(editedField);
|
|
63
65
|
if (dataType === DataType.PROPERTY) {
|
|
64
|
-
return schema.required();
|
|
66
|
+
return schema.required(YUP_REQUIRED);
|
|
65
67
|
}
|
|
66
68
|
return schema.nullable();
|
|
67
69
|
}),
|
|
@@ -69,7 +71,7 @@ function getAssignmentsSchema(emptyValueStr) {
|
|
|
69
71
|
const dataType = getDataType(editedField);
|
|
70
72
|
const unsettable = getUnsettable(editedField);
|
|
71
73
|
return getValueSchema(emptyValueStr, dataType, unsettable);
|
|
72
|
-
}).required()
|
|
74
|
+
}).required(YUP_REQUIRED)
|
|
73
75
|
})
|
|
74
76
|
).required();
|
|
75
77
|
}
|
|
@@ -80,6 +82,7 @@ function getAssignmentFromEditData(assignment) {
|
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
export {
|
|
85
|
+
EMPTY_FIELD_VALUE,
|
|
83
86
|
getAssignmentFromEditData,
|
|
84
87
|
getAssignmentInitialValue,
|
|
85
88
|
getAssignmentsSchema,
|
package/dist/components/network-modifications/by-filter/assignment/modificationByAssignment.utils.js
CHANGED
|
@@ -8,12 +8,11 @@ import { FieldType } from "../../../../utils/types/fieldType.js";
|
|
|
8
8
|
import "react/jsx-runtime";
|
|
9
9
|
import "@mui/icons-material";
|
|
10
10
|
import "../../../../utils/yupConfig.js";
|
|
11
|
-
import { getAssignmentsSchema, getAssignmentInitialValue, getAssignmentFromEditData, getDataType } from "./assignment/assignment-utils.js";
|
|
11
|
+
import { getAssignmentsSchema, getAssignmentInitialValue, getAssignmentFromEditData, getUnsettable, EMPTY_FIELD_VALUE, getDataType } from "./assignment/assignment-utils.js";
|
|
12
12
|
import { DataType } from "./assignment/assignment.type.js";
|
|
13
|
-
const emptyValueStr = "—";
|
|
14
13
|
const modificationByAssignmentFormSchema = yup.object().shape({
|
|
15
14
|
[FieldConstants.EQUIPMENT_TYPE]: mixed().oneOf(Object.values(EquipmentType)).required(),
|
|
16
|
-
[FieldConstants.ASSIGNMENTS]: getAssignmentsSchema(
|
|
15
|
+
[FieldConstants.ASSIGNMENTS]: getAssignmentsSchema(EMPTY_FIELD_VALUE)
|
|
17
16
|
}).required();
|
|
18
17
|
const emptyModificationByAssignmentFormData = {
|
|
19
18
|
[FieldConstants.EQUIPMENT_TYPE]: null,
|
|
@@ -27,9 +26,10 @@ const modificationByAssignmentDtoToForm = (dto) => ({
|
|
|
27
26
|
const field = FieldType[fieldKey];
|
|
28
27
|
const { value } = assignment;
|
|
29
28
|
const valueConverted = convertInputValue(field, value);
|
|
29
|
+
const unsettable = getUnsettable(assignment.editedField);
|
|
30
30
|
return {
|
|
31
31
|
...assignment,
|
|
32
|
-
value: valueConverted !== 0 && !valueConverted ?
|
|
32
|
+
value: unsettable && valueConverted !== 0 && !valueConverted ? EMPTY_FIELD_VALUE : valueConverted
|
|
33
33
|
};
|
|
34
34
|
}) ?? [getAssignmentInitialValue()]
|
|
35
35
|
});
|
|
@@ -39,7 +39,7 @@ const modificationByAssignmentFormToDto = (formData) => ({
|
|
|
39
39
|
assignmentInfosList: formData.assignments.map((assignment) => {
|
|
40
40
|
const fieldKey = assignment.editedField;
|
|
41
41
|
const field = FieldType[fieldKey];
|
|
42
|
-
const value = assignment.value ===
|
|
42
|
+
const value = assignment.value === EMPTY_FIELD_VALUE ? "" : assignment.value;
|
|
43
43
|
return {
|
|
44
44
|
...assignment,
|
|
45
45
|
dataType: getDataType(assignment.editedField) ?? DataType.STRING,
|
|
@@ -50,7 +50,7 @@ function ParameterTableField({
|
|
|
50
50
|
});
|
|
51
51
|
const { getValues } = useFormContext();
|
|
52
52
|
const validRowCountRef = useRef(
|
|
53
|
-
getValues(name)
|
|
53
|
+
getValues(name)?.filter((row) => isValidRow ? isValidRow(row) : true).length
|
|
54
54
|
);
|
|
55
55
|
const newDefaultRowData = useMemo(() => {
|
|
56
56
|
return getDefaultRowData(columnsDefinition);
|
package/dist/components/parameters/dynamic-margin-calculation/loads-variations-parameters.js
CHANGED
|
@@ -145,8 +145,7 @@ function LoadsVariationsParameters({ path }) {
|
|
|
145
145
|
label: "DynamicMarginCalculationLoadsVariations",
|
|
146
146
|
tooltipProps: { title: "DynamicMarginCalculationLoadsVariations" },
|
|
147
147
|
columnsDefinition,
|
|
148
|
-
tableHeight: 270
|
|
149
|
-
disableDragAndDrop: true
|
|
148
|
+
tableHeight: 270
|
|
150
149
|
}
|
|
151
150
|
)
|
|
152
151
|
] });
|