@gridsuite/commons-ui 0.135.0 → 0.136.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 (25) hide show
  1. package/dist/components/csvDownloader/csv-export.d.ts +1 -1
  2. package/dist/components/csvDownloader/csv-export.js +20 -2
  3. package/dist/components/csvDownloader/csv-export.type.d.ts +1 -0
  4. package/dist/components/csvDownloader/use-csv-export.js +1 -0
  5. package/dist/components/filter/expert/expertFilterUtils.js +1 -2
  6. package/dist/components/filter/index.d.ts +0 -1
  7. package/dist/components/filter/index.js +0 -5
  8. package/dist/components/filter/utils/filterFormUtils.d.ts +3 -12
  9. package/dist/components/filter/utils/filterFormUtils.js +15 -74
  10. package/dist/components/index.js +0 -5
  11. package/dist/components/inputs/reactHookForm/DirectoryItemsInput.js +67 -36
  12. package/dist/components/inputs/reactHookForm/text/TextInput.d.ts +2 -0
  13. package/dist/components/inputs/reactHookForm/text/TextInput.js +6 -3
  14. package/dist/hooks/useSnackMessage.d.ts +2 -1
  15. package/dist/hooks/useSnackMessage.js +2 -1
  16. package/dist/index.js +0 -5
  17. package/dist/utils/constants/fieldConstants.d.ts +0 -1
  18. package/dist/utils/constants/fieldConstants.js +0 -1
  19. package/package.json +1 -1
  20. package/dist/components/contingencyList/criteriaBased/CriteriaBasedForm.d.ts +0 -8
  21. package/dist/components/contingencyList/criteriaBased/CriteriaBasedForm.js +0 -66
  22. package/dist/components/contingencyList/criteriaBased/criteriaBasedUtils.d.ts +0 -60
  23. package/dist/components/contingencyList/criteriaBased/criteriaBasedUtils.js +0 -36
  24. package/dist/components/contingencyList/criteriaBased/index.d.ts +0 -8
  25. package/dist/components/contingencyList/criteriaBased/index.js +0 -7
@@ -1,2 +1,2 @@
1
1
  import { CsvExportProps } from './csv-export.type';
2
- export declare function CsvExport({ columns, tableNamePrefix, tableName, disabled, skipColumnHeaders, language, exportDataAsCsv, }: CsvExportProps): JSX.Element;
2
+ export declare function CsvExport({ columns, tableNamePrefix, tableName, disabled, skipColumnHeaders, skipPinnedBottom, language, exportDataAsCsv, }: CsvExportProps): JSX.Element;
@@ -8,13 +8,31 @@ function CsvExport({
8
8
  tableName,
9
9
  disabled,
10
10
  skipColumnHeaders = false,
11
+ skipPinnedBottom = false,
11
12
  language,
12
13
  exportDataAsCsv
13
14
  }) {
14
15
  const { downloadCSVData } = useCsvExport();
15
16
  const download = useCallback(() => {
16
- downloadCSVData({ columns, tableName, tableNamePrefix, skipColumnHeaders, language, exportDataAsCsv });
17
- }, [downloadCSVData, columns, tableName, tableNamePrefix, skipColumnHeaders, language, exportDataAsCsv]);
17
+ downloadCSVData({
18
+ columns,
19
+ tableName,
20
+ tableNamePrefix,
21
+ skipColumnHeaders,
22
+ skipPinnedBottom,
23
+ language,
24
+ exportDataAsCsv
25
+ });
26
+ }, [
27
+ downloadCSVData,
28
+ columns,
29
+ tableName,
30
+ tableNamePrefix,
31
+ skipColumnHeaders,
32
+ skipPinnedBottom,
33
+ language,
34
+ exportDataAsCsv
35
+ ]);
18
36
  return /* @__PURE__ */ jsx(ExportCsvButton, { disabled, onClick: download });
19
37
  }
20
38
  export {
@@ -5,6 +5,7 @@ export type CsvDownloadProps = {
5
5
  tableName: string;
6
6
  tableNamePrefix?: string;
7
7
  skipColumnHeaders?: boolean;
8
+ skipPinnedBottom?: boolean;
8
9
  language: GsLang;
9
10
  exportDataAsCsv: (params?: CsvExportParams) => void;
10
11
  };
@@ -32,6 +32,7 @@ const useCsvExport = () => {
32
32
  const prefix = props.tableNamePrefix ?? "";
33
33
  props.exportDataAsCsv({
34
34
  suppressQuotes: false,
35
+ skipPinnedBottom: props.skipPinnedBottom,
35
36
  columnSeparator: props.language === LANG_FRENCH ? ";" : ",",
36
37
  columnKeys: props.columns.map((col) => col.colId).filter(hasColId),
37
38
  skipColumnHeaders: props.skipColumnHeaders,
@@ -188,8 +188,7 @@ function importExpertRules(query) {
188
188
  }
189
189
  return rule.values.sort();
190
190
  }
191
- convertInputValue(rule.field, parseFloat(rule.value));
192
- return rule.value;
191
+ return convertInputValue(rule.field, parseFloat(rule.value));
193
192
  }
194
193
  function transformRule(rule) {
195
194
  return {
@@ -8,7 +8,6 @@ export * from './filter.type';
8
8
  export * from './FilterCreationDialog';
9
9
  export * from './FilterForm';
10
10
  export * from './constants/FilterConstants';
11
- export * from '../contingencyList/criteriaBased';
12
11
  export * from './expert';
13
12
  export * from './explicitNaming';
14
13
  export * from './utils';
@@ -1,8 +1,6 @@
1
1
  import { FilterCreationDialog } from "./FilterCreationDialog.js";
2
2
  import { FilterForm } from "./FilterForm.js";
3
3
  import { DISTRIBUTION_KEY, FilterType, NO_ITEM_SELECTION_FOR_COPY } from "./constants/FilterConstants.js";
4
- import { CriteriaBasedForm } from "../contingencyList/criteriaBased/CriteriaBasedForm.js";
5
- import { getCriteriaBasedFormData, getCriteriaBasedSchema } from "../contingencyList/criteriaBased/criteriaBasedUtils.js";
6
4
  import { ExpertFilterEditionDialog } from "./expert/ExpertFilterEditionDialog.js";
7
5
  import { ExpertFilterForm, expertFilterSchema, getExpertFilterEmptyFormData } from "./expert/ExpertFilterForm.js";
8
6
  import { CombinatorType, DataType, OperatorType } from "./expert/expertFilter.type.js";
@@ -18,7 +16,6 @@ export {
18
16
  CONTINGENCY_LIST_EQUIPMENTS,
19
17
  CONVERTERS_MODE_OPTIONS,
20
18
  CombinatorType,
21
- CriteriaBasedForm,
22
19
  DISTRIBUTION_KEY,
23
20
  DataType,
24
21
  ENERGY_SOURCE_OPTIONS,
@@ -49,8 +46,6 @@ export {
49
46
  expertFilterSchema,
50
47
  explicitNamingFilterSchema,
51
48
  exportExpertRules,
52
- getCriteriaBasedFormData,
53
- getCriteriaBasedSchema,
54
49
  getExpertFilterEmptyFormData,
55
50
  getExplicitNamingFilterEmptyFormData,
56
51
  getFilterEquipmentTypeLabel,
@@ -1,18 +1,9 @@
1
- import { FunctionComponent } from 'react';
2
- import { EquipmentType } from '../../../utils/types/equipmentType';
3
- export type FormField = {
4
- renderer: FunctionComponent<any>;
5
- props: {
6
- label: string;
7
- name: string;
8
- };
9
- };
10
- export type FormEquipment = {
1
+ import { EquipmentType } from '../../../utils';
2
+ export type ContingencyListEquipment = {
11
3
  id: string;
12
4
  label: string;
13
- fields: FormField[];
14
5
  };
15
- export declare const CONTINGENCY_LIST_EQUIPMENTS: Record<EquipmentType.BUSBAR_SECTION | EquipmentType.LINE | EquipmentType.TWO_WINDINGS_TRANSFORMER | EquipmentType.THREE_WINDINGS_TRANSFORMER | EquipmentType.GENERATOR | EquipmentType.BATTERY | EquipmentType.LOAD | EquipmentType.SHUNT_COMPENSATOR | EquipmentType.STATIC_VAR_COMPENSATOR | EquipmentType.HVDC_LINE | EquipmentType.DANGLING_LINE, FormEquipment>;
6
+ export declare const CONTINGENCY_LIST_EQUIPMENTS: Record<EquipmentType.BUSBAR_SECTION | EquipmentType.LINE | EquipmentType.TWO_WINDINGS_TRANSFORMER | EquipmentType.THREE_WINDINGS_TRANSFORMER | EquipmentType.GENERATOR | EquipmentType.BATTERY | EquipmentType.LOAD | EquipmentType.SHUNT_COMPENSATOR | EquipmentType.STATIC_VAR_COMPENSATOR | EquipmentType.HVDC_LINE | EquipmentType.DANGLING_LINE, ContingencyListEquipment>;
16
7
  export declare const FILTER_EQUIPMENTS: Partial<Record<EquipmentType, {
17
8
  id: EquipmentType;
18
9
  label: string;
@@ -1,111 +1,52 @@
1
- import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
2
- import { RangeInput } from "../../inputs/reactHookForm/numbers/RangeInput.js";
3
- import { CountriesInput } from "../../inputs/reactHookForm/selectInputs/CountriesInput.js";
1
+ import "../../../utils/conversionUtils.js";
2
+ import "react/jsx-runtime";
3
+ import "@mui/icons-material";
4
4
  import { EquipmentType, BASE_EQUIPMENTS } from "../../../utils/types/equipmentType.js";
5
- const countries = {
6
- renderer: CountriesInput,
7
- props: {
8
- label: "Countries",
9
- name: `${FieldConstants.CRITERIA_BASED}.${FieldConstants.COUNTRIES}`
10
- }
11
- };
12
- const countries1 = {
13
- renderer: CountriesInput,
14
- props: {
15
- label: "Countries1",
16
- name: `${FieldConstants.CRITERIA_BASED}.${FieldConstants.COUNTRIES_1}`
17
- }
18
- };
19
- const countries2 = {
20
- renderer: CountriesInput,
21
- props: {
22
- label: "Countries2",
23
- name: `${FieldConstants.CRITERIA_BASED}.${FieldConstants.COUNTRIES_2}`
24
- }
25
- };
26
- const nominalVoltage = {
27
- renderer: RangeInput,
28
- props: {
29
- label: "nominalVoltage",
30
- name: `${FieldConstants.CRITERIA_BASED}.${FieldConstants.NOMINAL_VOLTAGE}`
31
- }
32
- };
33
- const nominalVoltage1 = {
34
- renderer: RangeInput,
35
- props: {
36
- label: "nominalVoltage1",
37
- name: `${FieldConstants.CRITERIA_BASED}.${FieldConstants.NOMINAL_VOLTAGE_1}`
38
- }
39
- };
40
- const nominalVoltage2 = {
41
- renderer: RangeInput,
42
- props: {
43
- label: "nominalVoltage2",
44
- name: `${FieldConstants.CRITERIA_BASED}.${FieldConstants.NOMINAL_VOLTAGE_2}`
45
- }
46
- };
47
- const nominalVoltage3 = {
48
- renderer: RangeInput,
49
- props: {
50
- label: "nominalVoltage3",
51
- name: `${FieldConstants.CRITERIA_BASED}.${FieldConstants.NOMINAL_VOLTAGE_3}`
52
- }
53
- };
5
+ import "../../../utils/yupConfig.js";
54
6
  const CONTINGENCY_LIST_EQUIPMENTS = {
55
7
  BUSBAR_SECTION: {
56
8
  id: "BUSBAR_SECTION",
57
- label: "BusBarSections",
58
- fields: [countries, nominalVoltage]
9
+ label: "BusBarSections"
59
10
  },
60
11
  LINE: {
61
12
  id: "LINE",
62
- label: "Lines",
63
- fields: [countries1, countries2, nominalVoltage1, nominalVoltage2]
13
+ label: "Lines"
64
14
  },
65
15
  TWO_WINDINGS_TRANSFORMER: {
66
16
  id: "TWO_WINDINGS_TRANSFORMER",
67
- label: "TwoWindingsTransformers",
68
- fields: [countries, nominalVoltage1, nominalVoltage2]
17
+ label: "TwoWindingsTransformers"
69
18
  },
70
19
  THREE_WINDINGS_TRANSFORMER: {
71
20
  id: "THREE_WINDINGS_TRANSFORMER",
72
- label: "ThreeWindingsTransformers",
73
- fields: [countries, nominalVoltage1, nominalVoltage2, nominalVoltage3]
21
+ label: "ThreeWindingsTransformers"
74
22
  },
75
23
  GENERATOR: {
76
24
  id: "GENERATOR",
77
- label: "Generators",
78
- fields: [countries, nominalVoltage]
25
+ label: "Generators"
79
26
  },
80
27
  BATTERY: {
81
28
  id: "BATTERY",
82
- label: "Batteries",
83
- fields: [countries, nominalVoltage]
29
+ label: "Batteries"
84
30
  },
85
31
  LOAD: {
86
32
  id: "LOAD",
87
- label: "Loads",
88
- fields: [countries, nominalVoltage]
33
+ label: "Loads"
89
34
  },
90
35
  SHUNT_COMPENSATOR: {
91
36
  id: "SHUNT_COMPENSATOR",
92
- label: "ShuntCompensators",
93
- fields: [countries, nominalVoltage]
37
+ label: "ShuntCompensators"
94
38
  },
95
39
  STATIC_VAR_COMPENSATOR: {
96
40
  id: "STATIC_VAR_COMPENSATOR",
97
- label: "StaticVarCompensators",
98
- fields: [countries, nominalVoltage]
41
+ label: "StaticVarCompensators"
99
42
  },
100
43
  HVDC_LINE: {
101
44
  id: "HVDC_LINE",
102
- label: "HvdcLines",
103
- fields: [countries1, countries2, nominalVoltage]
45
+ label: "HvdcLines"
104
46
  },
105
47
  DANGLING_LINE: {
106
48
  id: "DANGLING_LINE",
107
- label: "DanglingLines",
108
- fields: [countries, nominalVoltage]
49
+ label: "DanglingLines"
109
50
  }
110
51
  };
111
52
  const FILTER_EQUIPMENTS = {
@@ -39,8 +39,6 @@ import { TagRenderer } from "./elementSearch/tagRenderer/TagRenderer.js";
39
39
  import { FilterCreationDialog } from "./filter/FilterCreationDialog.js";
40
40
  import { FilterForm } from "./filter/FilterForm.js";
41
41
  import { DISTRIBUTION_KEY, FilterType, NO_ITEM_SELECTION_FOR_COPY } from "./filter/constants/FilterConstants.js";
42
- import { CriteriaBasedForm } from "./contingencyList/criteriaBased/CriteriaBasedForm.js";
43
- import { getCriteriaBasedFormData, getCriteriaBasedSchema } from "./contingencyList/criteriaBased/criteriaBasedUtils.js";
44
42
  import { ExpertFilterEditionDialog } from "./filter/expert/ExpertFilterEditionDialog.js";
45
43
  import { ExpertFilterForm, expertFilterSchema, getExpertFilterEmptyFormData } from "./filter/expert/ExpertFilterForm.js";
46
44
  import { CombinatorType, DataType, OperatorType } from "./filter/expert/expertFilter.type.js";
@@ -211,7 +209,6 @@ export {
211
209
  CountriesInput,
212
210
  CountryValueEditor,
213
211
  CreateParameterDialog,
214
- CriteriaBasedForm,
215
212
  CsvExport,
216
213
  CsvUploader,
217
214
  CustomAGGrid,
@@ -486,8 +483,6 @@ export {
486
483
  formatComputingTypeLabel,
487
484
  genHelperError,
488
485
  generateTreeViewFinderClass,
489
- getCriteriaBasedFormData,
490
- getCriteriaBasedSchema,
491
486
  getExpertFilterEmptyFormData,
492
487
  getExplicitNamingFilterEmptyFormData,
493
488
  getFilterEquipmentTypeLabel,
@@ -1,8 +1,8 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
2
  import { FormControl, Box, Chip, FormHelperText, Grid, Tooltip, IconButton } from "@mui/material";
3
3
  import { Folder } from "@mui/icons-material";
4
- import { useState, useMemo, useCallback } from "react";
5
- import { useFieldArray, useController } from "react-hook-form";
4
+ import { useState, useMemo, useCallback, useEffect } from "react";
5
+ import { useFieldArray, useWatch, useController } from "react-hook-form";
6
6
  import { useIntl, FormattedMessage } from "react-intl";
7
7
  import { RawReadOnlyInput } from "./RawReadOnlyInput.js";
8
8
  import { FieldLabel } from "./utils/FieldLabel.js";
@@ -86,7 +86,8 @@ function DirectoryItemsInput({
86
86
  name
87
87
  });
88
88
  const formContext = useCustomFormContext();
89
- const { getValues, validationSchema } = formContext;
89
+ const { getValues, validationSchema, setError, clearErrors, getFieldState } = formContext;
90
+ const watchedElements = useWatch({ name });
90
91
  const {
91
92
  fieldState: { error }
92
93
  } = useController({
@@ -148,6 +149,24 @@ function DirectoryItemsInput({
148
149
  const shouldReplaceElement = useMemo(() => {
149
150
  return allowMultiSelect === false && elements?.length === 1;
150
151
  }, [allowMultiSelect, elements]);
152
+ const hasElementsWithoutName = useMemo(() => {
153
+ const elementsToCheck = watchedElements ?? elements;
154
+ return (elementsToCheck ?? []).some((item) => !item?.[NAME]);
155
+ }, [elements, watchedElements]);
156
+ useEffect(() => {
157
+ const errorMessage = intl.formatMessage({ id: "elementNotFound" });
158
+ const fieldState = getFieldState(name);
159
+ if (hasElementsWithoutName) {
160
+ if (fieldState.error?.message !== errorMessage) {
161
+ setError(name, {
162
+ type: "manual",
163
+ message: errorMessage
164
+ });
165
+ }
166
+ } else if (fieldState.error?.type === "manual" && fieldState.error?.message === errorMessage) {
167
+ clearErrors(name);
168
+ }
169
+ }, [clearErrors, getFieldState, hasElementsWithoutName, intl, name, setError]);
151
170
  return /* @__PURE__ */ jsxs(Fragment, { children: [
152
171
  /* @__PURE__ */ jsxs(
153
172
  FormControl,
@@ -166,39 +185,51 @@ function DirectoryItemsInput({
166
185
  optional: labelRequiredFromContext && !isFieldRequired(name, validationSchema, getValues())
167
186
  }
168
187
  ),
169
- elements?.length > 0 && /* @__PURE__ */ jsx(FormControl, { sx: styles.formDirectoryElements2, children: elements.map((item, index) => /* @__PURE__ */ jsxs(
170
- Box,
171
- {
172
- sx: { display: "flex", alignItems: "center", flexDirection: "column", gap: 1 },
173
- children: [
174
- /* @__PURE__ */ jsx(
175
- Chip,
176
- {
177
- size: "small",
178
- sx: {
179
- backgroundColor: item?.specificMetadata?.equipmentType && equipmentColorsMap?.get(item?.specificMetadata?.equipmentType)
180
- },
181
- onDelete: () => removeElements(index),
182
- onClick: () => handleChipClick(index),
183
- label: /* @__PURE__ */ jsx(
184
- OverflowableText,
185
- {
186
- text: getValues(`${name}.${index}.${NAME}`) ? /* @__PURE__ */ jsx(RawReadOnlyInput, { name: `${name}.${index}.${NAME}` }) : intl.formatMessage({ id: "elementNotFound" }),
187
- sx: { width: "100%" }
188
- }
189
- )
190
- }
191
- ),
192
- equipmentColorsMap && /* @__PURE__ */ jsx(FormHelperText, { children: item?.specificMetadata?.equipmentType ? /* @__PURE__ */ jsx(
193
- FormattedMessage,
194
- {
195
- id: getFilterEquipmentTypeLabel(item.specificMetadata.equipmentType)
196
- }
197
- ) : "" })
198
- ]
199
- },
200
- item.id
201
- )) }),
188
+ elements?.length > 0 && /* @__PURE__ */ jsx(FormControl, { sx: styles.formDirectoryElements2, children: elements.map((item, index) => {
189
+ const elementName = watchedElements?.[index]?.[NAME] ?? getValues(`${name}.${index}.${NAME}`) ?? item?.[NAME];
190
+ return /* @__PURE__ */ jsxs(
191
+ Box,
192
+ {
193
+ sx: { display: "flex", alignItems: "center", flexDirection: "column", gap: 1 },
194
+ children: [
195
+ /* @__PURE__ */ jsx(
196
+ Chip,
197
+ {
198
+ size: "small",
199
+ sx: mergeSx(
200
+ {
201
+ backgroundColor: item?.specificMetadata?.equipmentType && equipmentColorsMap?.get(item?.specificMetadata?.equipmentType)
202
+ },
203
+ !elementName ? (theme) => ({
204
+ backgroundColor: theme.palette.error.light,
205
+ borderColor: theme.palette.error.main,
206
+ color: theme.palette.error.contrastText
207
+ }) : void 0
208
+ ),
209
+ onDelete: () => removeElements(index),
210
+ onClick: () => handleChipClick(index),
211
+ label: /* @__PURE__ */ jsx(
212
+ OverflowableText,
213
+ {
214
+ text: elementName ? /* @__PURE__ */ jsx(RawReadOnlyInput, { name: `${name}.${index}.${NAME}` }) : intl.formatMessage({ id: "elementNotFound" }),
215
+ sx: { width: "100%" }
216
+ }
217
+ )
218
+ }
219
+ ),
220
+ equipmentColorsMap && /* @__PURE__ */ jsx(FormHelperText, { children: item?.specificMetadata?.equipmentType ? /* @__PURE__ */ jsx(
221
+ FormattedMessage,
222
+ {
223
+ id: getFilterEquipmentTypeLabel(
224
+ item.specificMetadata.equipmentType
225
+ )
226
+ }
227
+ ) : "" })
228
+ ]
229
+ },
230
+ item.id
231
+ );
232
+ }) }),
202
233
  /* @__PURE__ */ jsx(Grid, { item: true, xs: true, children: /* @__PURE__ */ jsx(Grid, { container: true, direction: "row-reverse", children: /* @__PURE__ */ jsx(Tooltip, { title: intl.formatMessage({ id: titleId }), children: /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(
203
234
  IconButton,
204
235
  {
@@ -15,6 +15,7 @@ export interface TextInputProps {
15
15
  outputTransform?: (value: string) => Input | null;
16
16
  inputTransform?: (value: Input) => string;
17
17
  acceptValue?: (value: string) => boolean;
18
+ onChange?: (value: string) => void;
18
19
  previousValue?: Input;
19
20
  clearable?: boolean;
20
21
  formProps?: Omit<TextFieldWithAdornmentProps | TextFieldProps, 'value' | 'onChange' | 'inputRef' | 'inputProps' | 'InputProps'>;
@@ -25,5 +26,6 @@ export declare function TextInput({ name, label, labelValues, // this prop is us
25
26
  id, adornment, customAdornment, outputTransform, // transform materialUi input value before sending it to react hook form, mostly used to deal with number fields
26
27
  inputTransform, // transform react hook form value before sending it to materialUi input, mostly used to deal with number fields
27
28
  acceptValue, // used to check user entry before committing the input change, used mostly to prevent user from typing a character in number field
29
+ onChange, // method called when input value changed, if you want to manually trigger validation for example (do not update the form here unless you know what you do, it's already done by RHF)
28
30
  previousValue, clearable, formProps, disabledTooltip, // In case we don't want to show tooltip on the value and warning/info icons
29
31
  disabled, }: TextInputProps): import("react/jsx-runtime").JSX.Element;
@@ -21,6 +21,8 @@ function TextInput({
21
21
  // transform react hook form value before sending it to materialUi input, mostly used to deal with number fields
22
22
  acceptValue = () => true,
23
23
  // used to check user entry before committing the input change, used mostly to prevent user from typing a character in number field
24
+ onChange,
25
+ // method called when input value changed, if you want to manually trigger validation for example (do not update the form here unless you know what you do, it's already done by RHF)
24
26
  previousValue,
25
27
  clearable,
26
28
  formProps,
@@ -30,7 +32,7 @@ function TextInput({
30
32
  }) {
31
33
  const { validationSchema, getValues, removeOptional, isNodeBuilt, isUpdate } = useCustomFormContext();
32
34
  const {
33
- field: { onChange, value, ref },
35
+ field: { onChange: onChangeRhf, value, ref },
34
36
  fieldState: { error }
35
37
  } = useController({ name });
36
38
  const Field = adornment ? TextFieldWithAdornment : TextField;
@@ -39,11 +41,12 @@ function TextInput({
39
41
  adornmentText: adornment?.text ?? ""
40
42
  };
41
43
  const handleClearValue = () => {
42
- onChange(outputTransform(""));
44
+ onChangeRhf(outputTransform(""));
43
45
  };
44
46
  const handleValueChanged = (e) => {
45
47
  if (acceptValue(e.target.value)) {
46
- onChange(outputTransform(e.target.value));
48
+ onChangeRhf(outputTransform(e.target.value));
49
+ onChange?.(e.target.value);
47
50
  }
48
51
  };
49
52
  const transformedValue = inputTransform(value);
@@ -1,4 +1,4 @@
1
- import { OptionsObject, closeSnackbar as closeSnackbarFromNotistack } from 'notistack';
1
+ import { closeSnackbar as closeSnackbarFromNotistack, OptionsObject } from 'notistack';
2
2
  interface SnackInputs extends Omit<OptionsObject, 'variant' | 'style'> {
3
3
  messageTxt?: string;
4
4
  messageId?: string;
@@ -11,6 +11,7 @@ export interface UseSnackMessageReturn {
11
11
  snackError: (snackInputs: SnackInputs) => void;
12
12
  snackWarning: (snackInputs: SnackInputs) => void;
13
13
  snackInfo: (snackInputs: SnackInputs) => void;
14
+ snackSuccess: (snackInputs: SnackInputs) => void;
14
15
  closeSnackbar: typeof closeSnackbarFromNotistack;
15
16
  }
16
17
  export declare function useSnackMessage(): UseSnackMessageReturn;
@@ -63,7 +63,8 @@ function useSnackMessage() {
63
63
  );
64
64
  const snackWarning = useCallback((snackInputs) => enqueue(snackInputs, "warning"), [enqueue]);
65
65
  const snackInfo = useCallback((snackInputs) => enqueue(snackInputs, "info"), [enqueue]);
66
- return { snackError, snackInfo, snackWarning, closeSnackbar };
66
+ const snackSuccess = useCallback((snackInputs) => enqueue(snackInputs, "success"), [enqueue]);
67
+ return { snackError, snackInfo, snackWarning, snackSuccess, closeSnackbar };
67
68
  }
68
69
  export {
69
70
  useSnackMessage
package/dist/index.js CHANGED
@@ -40,8 +40,6 @@ import { TagRenderer } from "./components/elementSearch/tagRenderer/TagRenderer.
40
40
  import { FilterCreationDialog } from "./components/filter/FilterCreationDialog.js";
41
41
  import { FilterForm } from "./components/filter/FilterForm.js";
42
42
  import { DISTRIBUTION_KEY, FilterType, NO_ITEM_SELECTION_FOR_COPY } from "./components/filter/constants/FilterConstants.js";
43
- import { CriteriaBasedForm } from "./components/contingencyList/criteriaBased/CriteriaBasedForm.js";
44
- import { getCriteriaBasedFormData, getCriteriaBasedSchema } from "./components/contingencyList/criteriaBased/criteriaBasedUtils.js";
45
43
  import { ExpertFilterEditionDialog } from "./components/filter/expert/ExpertFilterEditionDialog.js";
46
44
  import { ExpertFilterForm, expertFilterSchema, getExpertFilterEmptyFormData } from "./components/filter/expert/ExpertFilterForm.js";
47
45
  import { CombinatorType, DataType, OperatorType } from "./components/filter/expert/expertFilter.type.js";
@@ -327,7 +325,6 @@ export {
327
325
  CountriesInput,
328
326
  CountryValueEditor,
329
327
  CreateParameterDialog,
330
- CriteriaBasedForm,
331
328
  CsvExport,
332
329
  CsvUploader,
333
330
  CustomAGGrid,
@@ -737,8 +734,6 @@ export {
737
734
  getAppName,
738
735
  getAvailableComponentLibraries,
739
736
  getComputedLanguage,
740
- getCriteriaBasedFormData,
741
- getCriteriaBasedSchema,
742
737
  getDefaultLoadFlowProvider,
743
738
  getEquipmentsInfosForSearchBar,
744
739
  getExpertFilterEmptyFormData,
@@ -16,7 +16,6 @@ export declare enum FieldConstants {
16
16
  COUNTRIES_1 = "countries1",
17
17
  COUNTRIES_2 = "countries2",
18
18
  COUNTRIES = "countries",
19
- CRITERIA_BASED = "criteriaBased",
20
19
  CURRENT_PARAMETERS = "currentParameters",
21
20
  DESCRIPTION = "description",
22
21
  DIRECTORY = "directory",
@@ -10,7 +10,6 @@ var FieldConstants = /* @__PURE__ */ ((FieldConstants2) => {
10
10
  FieldConstants2["COUNTRIES_1"] = "countries1";
11
11
  FieldConstants2["COUNTRIES_2"] = "countries2";
12
12
  FieldConstants2["COUNTRIES"] = "countries";
13
- FieldConstants2["CRITERIA_BASED"] = "criteriaBased";
14
13
  FieldConstants2["CURRENT_PARAMETERS"] = "currentParameters";
15
14
  FieldConstants2["DESCRIPTION"] = "description";
16
15
  FieldConstants2["DIRECTORY"] = "directory";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.135.0",
3
+ "version": "0.136.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "author": "gridsuite team",
6
6
  "homepage": "https://github.com/gridsuite",
@@ -1,8 +0,0 @@
1
- import { ReactElement } from 'react';
2
- import { FormEquipment } from '../../filter/utils/filterFormUtils';
3
- export interface CriteriaBasedFormProps {
4
- equipments: Record<string, FormEquipment>;
5
- defaultValues: Record<string, any>;
6
- children?: ReactElement;
7
- }
8
- export declare function CriteriaBasedForm({ equipments, defaultValues, children }: Readonly<CriteriaBasedFormProps>): import("react/jsx-runtime").JSX.Element;
@@ -1,66 +0,0 @@
1
- import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
- import { useFormContext, useWatch } from "react-hook-form";
3
- import { Box, Grid } from "@mui/material";
4
- import { useEffect } from "react";
5
- import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
6
- import { SelectInput } from "../../inputs/reactHookForm/selectInputs/SelectInput.js";
7
- import { InputWithPopupConfirmation } from "../../inputs/reactHookForm/selectInputs/InputWithPopupConfirmation.js";
8
- import { useSnackMessage } from "../../../hooks/useSnackMessage.js";
9
- import { unscrollableDialogStyles } from "../../dialogs/customMuiDialog/CustomMuiDialog.js";
10
- import "../../dialogs/descriptionModificationDialog/DescriptionModificationDialog.js";
11
- import "../../dialogs/elementSaveDialog/ElementSaveDialog.js";
12
- import "react-intl";
13
- import "@mui/icons-material";
14
- import "../../treeViewFinder/TreeViewFinder.js";
15
- import "../../../utils/conversionUtils.js";
16
- import "../../../utils/types/equipmentType.js";
17
- import "../../../utils/yupConfig.js";
18
- function CriteriaBasedForm({ equipments, defaultValues, children }) {
19
- const { getValues, setValue } = useFormContext();
20
- const { snackError } = useSnackMessage();
21
- const watchEquipmentType = useWatch({
22
- name: FieldConstants.EQUIPMENT_TYPE
23
- });
24
- useEffect(() => {
25
- if (watchEquipmentType && !equipments[watchEquipmentType]) {
26
- snackError({
27
- headerId: "obsoleteFilter"
28
- });
29
- }
30
- }, [snackError, equipments, watchEquipmentType]);
31
- const openConfirmationPopup = () => {
32
- return JSON.stringify(getValues(FieldConstants.CRITERIA_BASED)) !== JSON.stringify(defaultValues);
33
- };
34
- const handleResetOnConfirmation = () => {
35
- Object.keys(defaultValues).forEach(
36
- (field) => setValue(`${FieldConstants.CRITERIA_BASED}.${field}`, defaultValues[field])
37
- );
38
- };
39
- return /* @__PURE__ */ jsxs(Fragment, { children: [
40
- /* @__PURE__ */ jsx(Box, { sx: unscrollableDialogStyles.unscrollableHeader, children: /* @__PURE__ */ jsx(
41
- InputWithPopupConfirmation,
42
- {
43
- Input: SelectInput,
44
- name: FieldConstants.EQUIPMENT_TYPE,
45
- options: Object.values(equipments),
46
- label: "equipmentType",
47
- shouldOpenPopup: openConfirmationPopup,
48
- resetOnConfirmation: handleResetOnConfirmation,
49
- message: "changeTypeMessage",
50
- validateButtonLabel: "button.changeType",
51
- "data-testid": "EquipmentTypeSelector"
52
- }
53
- ) }),
54
- /* @__PURE__ */ jsx(Box, { sx: unscrollableDialogStyles.scrollableContent, children: /* @__PURE__ */ jsxs(Grid, { container: true, spacing: 2, children: [
55
- watchEquipmentType && equipments[watchEquipmentType] && equipments[watchEquipmentType].fields.map((equipment, index) => {
56
- const EquipmentForm = equipment.renderer;
57
- const uniqueKey = `${watchEquipmentType}-${index}`;
58
- return /* @__PURE__ */ jsx(Grid, { item: true, xs: 12, flexGrow: 1, children: /* @__PURE__ */ jsx(EquipmentForm, { ...equipment.props }) }, uniqueKey);
59
- }),
60
- children
61
- ] }) })
62
- ] });
63
- }
64
- export {
65
- CriteriaBasedForm
66
- };
@@ -1,60 +0,0 @@
1
- import { ObjectSchema } from 'yup';
2
- import { FieldConstants } from '../../../utils/constants/fieldConstants';
3
- import { default as yup } from '../../../utils/yupConfig';
4
- import { RangeInputData } from '../../inputs/reactHookForm/numbers/RangeInput';
5
- export type CriteriaBasedData = {
6
- [FieldConstants.COUNTRIES]?: string[];
7
- [FieldConstants.COUNTRIES_1]?: string[];
8
- [FieldConstants.COUNTRIES_2]?: string[];
9
- [FieldConstants.NOMINAL_VOLTAGE]?: RangeInputData | null;
10
- [FieldConstants.NOMINAL_VOLTAGE_1]?: RangeInputData | null;
11
- [FieldConstants.NOMINAL_VOLTAGE_2]?: RangeInputData | null;
12
- [FieldConstants.NOMINAL_VOLTAGE_3]?: RangeInputData | null;
13
- [key: string]: any;
14
- };
15
- export declare function getCriteriaBasedSchema(extraFields?: Record<string, yup.AnyObject | null>): {
16
- readonly criteriaBased: ObjectSchema<{
17
- nominalVoltage3: {
18
- type: string;
19
- value1: number | null;
20
- value2: number | null;
21
- };
22
- nominalVoltage2: {
23
- type: string;
24
- value1: number | null;
25
- value2: number | null;
26
- };
27
- nominalVoltage1: {
28
- type: string;
29
- value1: number | null;
30
- value2: number | null;
31
- };
32
- nominalVoltage: {
33
- type: string;
34
- value1: number | null;
35
- value2: number | null;
36
- };
37
- countries: string[] | undefined;
38
- countries1: string[] | undefined;
39
- countries2: string[] | undefined;
40
- }, yup.AnyObject, {
41
- nominalVoltage3: any;
42
- nominalVoltage2: any;
43
- nominalVoltage1: any;
44
- nominalVoltage: any;
45
- countries: "";
46
- countries1: "";
47
- countries2: "";
48
- }, "">;
49
- };
50
- export declare function getCriteriaBasedFormData(criteriaValues?: Record<string, any>, extraFields?: Record<string, yup.AnyObject | null>): {
51
- readonly criteriaBased: {
52
- readonly countries: any;
53
- readonly countries1: any;
54
- readonly countries2: any;
55
- readonly nominalVoltage: any;
56
- readonly nominalVoltage1: any;
57
- readonly nominalVoltage2: any;
58
- readonly nominalVoltage3: any;
59
- };
60
- };
@@ -1,36 +0,0 @@
1
- import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
2
- import "../../../utils/yupConfig.js";
3
- import { getRangeInputSchema, DEFAULT_RANGE_VALUE } from "../../inputs/reactHookForm/numbers/RangeInput.js";
4
- import * as yup from "yup";
5
- function getCriteriaBasedSchema(extraFields = {}) {
6
- return {
7
- [FieldConstants.CRITERIA_BASED]: yup.object().shape({
8
- [FieldConstants.COUNTRIES]: yup.array().of(yup.string().required()),
9
- [FieldConstants.COUNTRIES_1]: yup.array().of(yup.string().required()),
10
- [FieldConstants.COUNTRIES_2]: yup.array().of(yup.string().required()),
11
- ...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE),
12
- ...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE_1),
13
- ...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE_2),
14
- ...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE_3),
15
- ...extraFields
16
- })
17
- };
18
- }
19
- function getCriteriaBasedFormData(criteriaValues, extraFields = {}) {
20
- return {
21
- [FieldConstants.CRITERIA_BASED]: {
22
- [FieldConstants.COUNTRIES]: criteriaValues?.[FieldConstants.COUNTRIES] ?? [],
23
- [FieldConstants.COUNTRIES_1]: criteriaValues?.[FieldConstants.COUNTRIES_1] ?? [],
24
- [FieldConstants.COUNTRIES_2]: criteriaValues?.[FieldConstants.COUNTRIES_2] ?? [],
25
- [FieldConstants.NOMINAL_VOLTAGE]: criteriaValues?.[FieldConstants.NOMINAL_VOLTAGE] ?? DEFAULT_RANGE_VALUE,
26
- [FieldConstants.NOMINAL_VOLTAGE_1]: criteriaValues?.[FieldConstants.NOMINAL_VOLTAGE_1] ?? DEFAULT_RANGE_VALUE,
27
- [FieldConstants.NOMINAL_VOLTAGE_2]: criteriaValues?.[FieldConstants.NOMINAL_VOLTAGE_2] ?? DEFAULT_RANGE_VALUE,
28
- [FieldConstants.NOMINAL_VOLTAGE_3]: criteriaValues?.[FieldConstants.NOMINAL_VOLTAGE_3] ?? DEFAULT_RANGE_VALUE,
29
- ...extraFields
30
- }
31
- };
32
- }
33
- export {
34
- getCriteriaBasedFormData,
35
- getCriteriaBasedSchema
36
- };
@@ -1,8 +0,0 @@
1
- /**
2
- * Copyright (c) 2024, RTE (http://www.rte-france.com)
3
- * This Source Code Form is subject to the terms of the Mozilla Public
4
- * License, v. 2.0. If a copy of the MPL was not distributed with this
5
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
- */
7
- export * from './CriteriaBasedForm';
8
- export * from './criteriaBasedUtils';
@@ -1,7 +0,0 @@
1
- import { CriteriaBasedForm } from "./CriteriaBasedForm.js";
2
- import { getCriteriaBasedFormData, getCriteriaBasedSchema } from "./criteriaBasedUtils.js";
3
- export {
4
- CriteriaBasedForm,
5
- getCriteriaBasedFormData,
6
- getCriteriaBasedSchema
7
- };