@gridsuite/commons-ui 0.75.0 → 0.76.2

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 (35) hide show
  1. package/dist/components/{filter → contingencyList}/criteriaBased/CriteriaBasedForm.d.ts +1 -1
  2. package/dist/components/{filter/criteriaBased/criteriaBasedFilterUtils.d.ts → contingencyList/criteriaBased/criteriaBasedUtils.d.ts} +0 -39
  3. package/dist/components/contingencyList/criteriaBased/criteriaBasedUtils.js +36 -0
  4. package/dist/components/{filter → contingencyList}/criteriaBased/index.d.ts +1 -6
  5. package/dist/components/contingencyList/criteriaBased/index.js +7 -0
  6. package/dist/components/elementSearch/elementSearchInput/ElementSearchInput.js +11 -2
  7. package/dist/components/filter/FilterCreationDialog.js +1 -10
  8. package/dist/components/filter/FilterForm.js +0 -2
  9. package/dist/components/filter/constants/FilterConstants.d.ts +0 -4
  10. package/dist/components/filter/constants/FilterConstants.js +0 -1
  11. package/dist/components/filter/index.d.ts +1 -1
  12. package/dist/components/filter/index.js +3 -24
  13. package/dist/components/filter/utils/filterApi.d.ts +0 -1
  14. package/dist/components/filter/utils/filterApi.js +0 -10
  15. package/dist/components/filter/utils/index.js +1 -2
  16. package/dist/components/index.js +3 -24
  17. package/dist/index.js +3 -24
  18. package/dist/translations/en/filterEn.d.ts +0 -1
  19. package/dist/translations/en/filterEn.js +1 -2
  20. package/dist/translations/fr/filterFr.d.ts +0 -1
  21. package/dist/translations/fr/filterFr.js +1 -2
  22. package/package.json +1 -1
  23. package/dist/components/filter/criteriaBased/CriteriaBasedFilterEditionDialog.d.ts +0 -19
  24. package/dist/components/filter/criteriaBased/CriteriaBasedFilterEditionDialog.js +0 -103
  25. package/dist/components/filter/criteriaBased/CriteriaBasedFilterForm.d.ts +0 -49
  26. package/dist/components/filter/criteriaBased/CriteriaBasedFilterForm.js +0 -33
  27. package/dist/components/filter/criteriaBased/FilterFreeProperties.d.ts +0 -12
  28. package/dist/components/filter/criteriaBased/FilterFreeProperties.js +0 -68
  29. package/dist/components/filter/criteriaBased/FilterProperties.d.ts +0 -15
  30. package/dist/components/filter/criteriaBased/FilterProperties.js +0 -121
  31. package/dist/components/filter/criteriaBased/FilterProperty.d.ts +0 -18
  32. package/dist/components/filter/criteriaBased/FilterProperty.js +0 -65
  33. package/dist/components/filter/criteriaBased/criteriaBasedFilterUtils.js +0 -158
  34. package/dist/components/filter/criteriaBased/index.js +0 -27
  35. /package/dist/components/{filter → contingencyList}/criteriaBased/CriteriaBasedForm.js +0 -0
@@ -1,103 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { yupResolver } from "@hookform/resolvers/yup";
3
- import { useState, useEffect, useCallback } from "react";
4
- import { useForm } from "react-hook-form";
5
- import { useSnackMessage } from "../../../hooks/useSnackMessage.js";
6
- import { saveFilter } from "../../../services/explore.js";
7
- import { FetchStatus } from "../../../utils/constants/fetchStatus.js";
8
- import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
9
- import "../../../utils/yupConfig.js";
10
- import { CustomMuiDialog } from "../../dialogs/customMuiDialog/CustomMuiDialog.js";
11
- import { FilterForm } from "../FilterForm.js";
12
- import { FilterType, NO_ITEM_SELECTION_FOR_COPY } from "../constants/FilterConstants.js";
13
- import { criteriaBasedFilterSchema } from "./CriteriaBasedFilterForm.js";
14
- import { backToFrontTweak, frontToBackTweak } from "./criteriaBasedFilterUtils.js";
15
- import * as yup from "yup";
16
- const formSchema = yup.object().shape({
17
- [FieldConstants.NAME]: yup.string().trim().required("nameEmpty"),
18
- [FieldConstants.FILTER_TYPE]: yup.string().required(),
19
- [FieldConstants.EQUIPMENT_TYPE]: yup.string().required(),
20
- ...criteriaBasedFilterSchema
21
- }).required();
22
- function CriteriaBasedFilterEditionDialog({
23
- id,
24
- name,
25
- titleId,
26
- open,
27
- onClose,
28
- broadcastChannel,
29
- getFilterById,
30
- itemSelectionForCopy,
31
- setItemSelectionForCopy,
32
- activeDirectory,
33
- elementExists,
34
- language
35
- }) {
36
- var _a;
37
- const { snackError } = useSnackMessage();
38
- const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE);
39
- const formMethods = useForm({
40
- resolver: yupResolver(formSchema)
41
- });
42
- const {
43
- reset,
44
- formState: { errors }
45
- } = formMethods;
46
- const nameError = errors[FieldConstants.NAME];
47
- const isValidating = (_a = errors.root) == null ? void 0 : _a.isValidating;
48
- useEffect(() => {
49
- if (id && open) {
50
- setDataFetchStatus(FetchStatus.FETCHING);
51
- getFilterById(id).then((response) => {
52
- setDataFetchStatus(FetchStatus.FETCH_SUCCESS);
53
- reset({
54
- [FieldConstants.NAME]: name,
55
- [FieldConstants.FILTER_TYPE]: FilterType.CRITERIA_BASED.id,
56
- ...backToFrontTweak(response)
57
- });
58
- }).catch((error) => {
59
- setDataFetchStatus(FetchStatus.FETCH_ERROR);
60
- snackError({
61
- messageTxt: error.message,
62
- headerId: "cannotRetrieveFilter"
63
- });
64
- });
65
- }
66
- }, [id, name, open, reset, snackError, getFilterById]);
67
- const onSubmit = useCallback(
68
- (filterForm) => {
69
- saveFilter(frontToBackTweak(id, filterForm), filterForm[FieldConstants.NAME]).then(() => {
70
- if (itemSelectionForCopy.sourceItemUuid === id) {
71
- setItemSelectionForCopy(NO_ITEM_SELECTION_FOR_COPY);
72
- broadcastChannel.postMessage({ NO_SELECTION_FOR_COPY: NO_ITEM_SELECTION_FOR_COPY });
73
- }
74
- }).catch((error) => {
75
- snackError({
76
- messageTxt: error.message
77
- });
78
- });
79
- },
80
- [broadcastChannel, id, itemSelectionForCopy.sourceItemUuid, snackError, setItemSelectionForCopy]
81
- );
82
- const isDataReady = dataFetchStatus === FetchStatus.FETCH_SUCCESS;
83
- return /* @__PURE__ */ jsx(
84
- CustomMuiDialog,
85
- {
86
- open,
87
- onClose,
88
- onSave: onSubmit,
89
- formSchema,
90
- formMethods,
91
- titleId,
92
- removeOptional: true,
93
- disabledSave: !!nameError || !!isValidating,
94
- isDataFetching: dataFetchStatus === FetchStatus.FETCHING,
95
- language,
96
- unscrollableFullHeight: true,
97
- children: isDataReady && /* @__PURE__ */ jsx(FilterForm, { activeDirectory, elementExists })
98
- }
99
- );
100
- }
101
- export {
102
- CriteriaBasedFilterEditionDialog
103
- };
@@ -1,49 +0,0 @@
1
- import { default as yup } from '../../../utils/yupConfig';
2
-
3
- export declare const criteriaBasedFilterSchema: {
4
- readonly criteriaBased: yup.ObjectSchema<{
5
- nominalVoltage3: {
6
- value1: number | null;
7
- value2: number | null;
8
- type: string;
9
- };
10
- nominalVoltage2: {
11
- value1: number | null;
12
- value2: number | null;
13
- type: string;
14
- };
15
- nominalVoltage1: {
16
- value1: number | null;
17
- value2: number | null;
18
- type: string;
19
- };
20
- nominalVoltage: {
21
- value1: number | null;
22
- value2: number | null;
23
- type: string;
24
- };
25
- countries: string[] | undefined;
26
- countries1: string[] | undefined;
27
- countries2: string[] | undefined;
28
- }, yup.AnyObject, {
29
- nominalVoltage3: any;
30
- nominalVoltage2: any;
31
- nominalVoltage1: any;
32
- nominalVoltage: any;
33
- countries: "";
34
- countries1: "";
35
- countries2: "";
36
- }, "">;
37
- };
38
- export declare const criteriaBasedFilterEmptyFormData: {
39
- readonly criteriaBased: {
40
- readonly countries: any;
41
- readonly countries1: any;
42
- readonly countries2: any;
43
- readonly nominalVoltage: any;
44
- readonly nominalVoltage1: any;
45
- readonly nominalVoltage2: any;
46
- readonly nominalVoltage3: any;
47
- };
48
- };
49
- export declare function CriteriaBasedFilterForm(): import("react/jsx-runtime").JSX.Element;
@@ -1,33 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { filterPropertiesYupSchema, FilterProperties } from "./FilterProperties.js";
3
- import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
4
- import "../../../utils/yupConfig.js";
5
- import { CriteriaBasedForm } from "./CriteriaBasedForm.js";
6
- import { getCriteriaBasedSchema, getCriteriaBasedFormData } from "./criteriaBasedFilterUtils.js";
7
- import { FILTER_EQUIPMENTS } from "../utils/filterFormUtils.js";
8
- import { FreePropertiesTypes } from "./FilterFreeProperties.js";
9
- import * as yup from "yup";
10
- const criteriaBasedFilterSchema = getCriteriaBasedSchema({
11
- [FieldConstants.ENERGY_SOURCE]: yup.string().nullable(),
12
- ...filterPropertiesYupSchema
13
- });
14
- const criteriaBasedFilterEmptyFormData = getCriteriaBasedFormData(void 0, {
15
- [FieldConstants.ENERGY_SOURCE]: null,
16
- [FreePropertiesTypes.SUBSTATION_FILTER_PROPERTIES]: [],
17
- [FreePropertiesTypes.FREE_FILTER_PROPERTIES]: []
18
- });
19
- function CriteriaBasedFilterForm() {
20
- return /* @__PURE__ */ jsx(
21
- CriteriaBasedForm,
22
- {
23
- equipments: FILTER_EQUIPMENTS,
24
- defaultValues: criteriaBasedFilterEmptyFormData[FieldConstants.CRITERIA_BASED],
25
- children: /* @__PURE__ */ jsx(FilterProperties, {})
26
- }
27
- );
28
- }
29
- export {
30
- CriteriaBasedFilterForm,
31
- criteriaBasedFilterEmptyFormData,
32
- criteriaBasedFilterSchema
33
- };
@@ -1,12 +0,0 @@
1
- import { PredefinedProperties } from '../../../utils/types/types';
2
-
3
- export declare enum FreePropertiesTypes {
4
- SUBSTATION_FILTER_PROPERTIES = "substationFreeProperties",
5
- FREE_FILTER_PROPERTIES = "freeProperties"
6
- }
7
- interface FilterFreePropertiesProps {
8
- freePropertiesType: FreePropertiesTypes;
9
- predefined: PredefinedProperties;
10
- }
11
- export declare function FilterFreeProperties({ freePropertiesType, predefined }: FilterFreePropertiesProps): import("react/jsx-runtime").JSX.Element;
12
- export {};
@@ -1,68 +0,0 @@
1
- import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
- import { Grid, ListItem, Button } from "@mui/material";
3
- import { useWatch, useFieldArray } from "react-hook-form";
4
- import { FormattedMessage } from "react-intl";
5
- import AddIcon from "@mui/icons-material/Add";
6
- import { useMemo } from "react";
7
- import { ErrorInput } from "../../inputs/reactHookForm/errorManagement/ErrorInput.js";
8
- import { FieldErrorAlert } from "../../inputs/reactHookForm/errorManagement/FieldErrorAlert.js";
9
- import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
10
- import { FilterProperty, PROPERTY_NAME, PROPERTY_VALUES_1, PROPERTY_VALUES_2, PROPERTY_VALUES } from "./FilterProperty.js";
11
- import { Line, Hvdc } from "../../../utils/types/equipmentTypes.js";
12
- var FreePropertiesTypes = /* @__PURE__ */ ((FreePropertiesTypes2) => {
13
- FreePropertiesTypes2["SUBSTATION_FILTER_PROPERTIES"] = "substationFreeProperties";
14
- FreePropertiesTypes2["FREE_FILTER_PROPERTIES"] = "freeProperties";
15
- return FreePropertiesTypes2;
16
- })(FreePropertiesTypes || {});
17
- function FilterFreeProperties({ freePropertiesType, predefined }) {
18
- const watchEquipmentType = useWatch({
19
- name: FieldConstants.EQUIPMENT_TYPE
20
- });
21
- const isForLineOrHvdcLineSubstation = (watchEquipmentType === Line.type || watchEquipmentType === Hvdc.type) && freePropertiesType === "substationFreeProperties";
22
- const fieldName = `${FieldConstants.CRITERIA_BASED}.${freePropertiesType}`;
23
- const {
24
- fields: filterProperties,
25
- // don't use it to access form data ! check doc,
26
- append,
27
- remove
28
- } = useFieldArray({
29
- name: fieldName
30
- });
31
- function addNewProp() {
32
- if (isForLineOrHvdcLineSubstation) {
33
- append({
34
- [PROPERTY_NAME]: null,
35
- [PROPERTY_VALUES_1]: [],
36
- [PROPERTY_VALUES_2]: []
37
- });
38
- } else {
39
- append({ [PROPERTY_NAME]: null, [PROPERTY_VALUES]: [] });
40
- }
41
- }
42
- const valuesFields = isForLineOrHvdcLineSubstation ? [
43
- { name: PROPERTY_VALUES_1, label: "PropertyValues1" },
44
- { name: PROPERTY_VALUES_2, label: "PropertyValues2" }
45
- ] : [{ name: PROPERTY_VALUES, label: "PropertyValues" }];
46
- const title = useMemo(() => {
47
- return freePropertiesType === "freeProperties" ? "FreeProps" : "SubstationFreeProps";
48
- }, [freePropertiesType]);
49
- return /* @__PURE__ */ jsxs(Fragment, { children: [
50
- /* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsx(FormattedMessage, { id: title, children: (formattedTitle) => /* @__PURE__ */ jsx("h4", { children: formattedTitle }) }) }),
51
- filterProperties.map((prop, index) => /* @__PURE__ */ jsx(ListItem, { children: /* @__PURE__ */ jsx(
52
- FilterProperty,
53
- {
54
- index,
55
- valuesFields,
56
- predefined,
57
- handleDelete: remove,
58
- propertyType: freePropertiesType
59
- }
60
- ) }, prop.id)),
61
- /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Button, { startIcon: /* @__PURE__ */ jsx(AddIcon, {}), onClick: () => addNewProp(), children: /* @__PURE__ */ jsx(FormattedMessage, { id: "AddFreePropCrit" }) }) }),
62
- /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(ErrorInput, { name: fieldName, InputField: FieldErrorAlert }) })
63
- ] });
64
- }
65
- export {
66
- FilterFreeProperties,
67
- FreePropertiesTypes
68
- };
@@ -1,15 +0,0 @@
1
- import { default as yup } from '../../../utils/yupConfig';
2
-
3
- export declare const filterPropertiesYupSchema: {
4
- substationFreeProperties: yup.ArraySchema<{
5
- prop_values?: (string | undefined)[] | undefined;
6
- prop_values1?: (string | undefined)[] | undefined;
7
- prop_values2?: (string | undefined)[] | undefined;
8
- name_property: string;
9
- }[] | undefined, yup.AnyObject, "", "">;
10
- freeProperties: yup.ArraySchema<{
11
- prop_values?: (string | undefined)[] | undefined;
12
- name_property: string;
13
- }[] | undefined, yup.AnyObject, "", "">;
14
- };
15
- export declare function FilterProperties(): any;
@@ -1,121 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import Grid from "@mui/material/Grid";
3
- import { useMemo, useEffect } from "react";
4
- import { useWatch } from "react-hook-form";
5
- import { FormattedMessage } from "react-intl";
6
- import { Line, Hvdc, Substation, Load, Generator, TwoWindingTransfo, Battery, ShuntCompensator, VoltageLevel } from "../../../utils/types/equipmentTypes.js";
7
- import { areArrayElementsUnique } from "../../../utils/functions.js";
8
- import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
9
- import "../../../utils/yupConfig.js";
10
- import { FreePropertiesTypes, FilterFreeProperties } from "./FilterFreeProperties.js";
11
- import { PROPERTY_NAME, PROPERTY_VALUES, PROPERTY_VALUES_1, PROPERTY_VALUES_2 } from "./FilterProperty.js";
12
- import { usePredefinedProperties } from "../../../hooks/usePredefinedProperties.js";
13
- import { FilterType } from "../constants/FilterConstants.js";
14
- import "@mui/icons-material";
15
- import { EquipmentType } from "../../../utils/types/equipmentType.js";
16
- import * as yup from "yup";
17
- function propertyValuesTest(values, context, doublePropertyValues) {
18
- const rootLevelForm = context.from[context.from.length - 1];
19
- const filterType = rootLevelForm.value[FieldConstants.FILTER_TYPE];
20
- if (filterType !== FilterType.CRITERIA_BASED.id) {
21
- return true;
22
- }
23
- const equipmentType = rootLevelForm.value[FieldConstants.EQUIPMENT_TYPE];
24
- const isForLineOrHvdcLine = equipmentType === Line.type || equipmentType === Hvdc.type;
25
- if (doublePropertyValues) {
26
- return isForLineOrHvdcLine ? (values == null ? void 0 : values.length) > 0 : true;
27
- }
28
- return isForLineOrHvdcLine || (values == null ? void 0 : values.length) > 0;
29
- }
30
- const filterPropertiesYupSchema = {
31
- [FreePropertiesTypes.SUBSTATION_FILTER_PROPERTIES]: yup.array().of(
32
- yup.object().shape({
33
- [PROPERTY_NAME]: yup.string().required(),
34
- [PROPERTY_VALUES]: yup.array().of(yup.string()).test(
35
- "can not be empty if not line",
36
- "YupRequired",
37
- (values, context) => propertyValuesTest(values, context, false)
38
- ),
39
- [PROPERTY_VALUES_1]: yup.array().of(yup.string()).test(
40
- "can not be empty if line",
41
- "YupRequired",
42
- (values, context) => propertyValuesTest(values, context, true)
43
- ),
44
- [PROPERTY_VALUES_2]: yup.array().of(yup.string()).test(
45
- "can not be empty if line",
46
- "YupRequired",
47
- (values, context) => propertyValuesTest(values, context, true)
48
- )
49
- })
50
- ).test("distinct names", "filterPropertiesNameUniquenessError", (properties, context) => {
51
- const rootLevelForm = context.from[context.from.length - 1];
52
- const filterType = rootLevelForm.value[FieldConstants.FILTER_TYPE];
53
- if (filterType !== FilterType.CRITERIA_BASED.id) {
54
- return true;
55
- }
56
- const names = properties.filter((prop) => !!prop[PROPERTY_NAME]).map((prop) => prop[PROPERTY_NAME]);
57
- return areArrayElementsUnique(names);
58
- }),
59
- [FreePropertiesTypes.FREE_FILTER_PROPERTIES]: yup.array().of(
60
- yup.object().shape({
61
- [PROPERTY_NAME]: yup.string().required(),
62
- [PROPERTY_VALUES]: yup.array().of(yup.string()).test(
63
- "can not be empty if not line",
64
- "YupRequired",
65
- (values, context) => propertyValuesTest(values, context, false)
66
- )
67
- })
68
- ).test("distinct names", "filterPropertiesNameUniquenessError", (properties, context) => {
69
- const rootLevelForm = context.from[context.from.length - 1];
70
- const filterType = rootLevelForm.value[FieldConstants.FILTER_TYPE];
71
- if (filterType !== FilterType.CRITERIA_BASED.id) {
72
- return true;
73
- }
74
- const names = properties.filter((prop) => !!prop[PROPERTY_NAME]).map((prop) => prop[PROPERTY_NAME]);
75
- return areArrayElementsUnique(names);
76
- })
77
- };
78
- function FilterProperties() {
79
- const watchEquipmentType = useWatch({
80
- name: FieldConstants.EQUIPMENT_TYPE
81
- });
82
- const [equipmentPredefinedProps, setEquipmentType] = usePredefinedProperties(watchEquipmentType);
83
- const [substationPredefinedProps, setSubstationType] = usePredefinedProperties(null);
84
- const displayEquipmentProperties = useMemo(() => {
85
- return watchEquipmentType === Substation.type || watchEquipmentType === Load.type || watchEquipmentType === Generator.type || watchEquipmentType === Line.type || watchEquipmentType === TwoWindingTransfo.type || watchEquipmentType === Battery.type || watchEquipmentType === ShuntCompensator.type || watchEquipmentType === VoltageLevel.type;
86
- }, [watchEquipmentType]);
87
- const displaySubstationProperties = useMemo(() => {
88
- return watchEquipmentType !== Substation.type && watchEquipmentType !== null;
89
- }, [watchEquipmentType]);
90
- useEffect(() => {
91
- if (displayEquipmentProperties) {
92
- setEquipmentType(watchEquipmentType);
93
- }
94
- }, [displayEquipmentProperties, watchEquipmentType, setEquipmentType]);
95
- useEffect(() => {
96
- if (displaySubstationProperties) {
97
- setSubstationType(EquipmentType.SUBSTATION);
98
- }
99
- }, [displaySubstationProperties, setSubstationType]);
100
- return watchEquipmentType && /* @__PURE__ */ jsx(Grid, { item: true, container: true, spacing: 1, children: /* @__PURE__ */ jsxs(Grid, { item: true, xs: 12, children: [
101
- /* @__PURE__ */ jsx(FormattedMessage, { id: "FreePropsCrit", children: (txt) => /* @__PURE__ */ jsx("h3", { children: txt }) }),
102
- displayEquipmentProperties && /* @__PURE__ */ jsx(
103
- FilterFreeProperties,
104
- {
105
- freePropertiesType: FreePropertiesTypes.FREE_FILTER_PROPERTIES,
106
- predefined: equipmentPredefinedProps
107
- }
108
- ),
109
- displaySubstationProperties && /* @__PURE__ */ jsx(
110
- FilterFreeProperties,
111
- {
112
- freePropertiesType: FreePropertiesTypes.SUBSTATION_FILTER_PROPERTIES,
113
- predefined: substationPredefinedProps
114
- }
115
- )
116
- ] }) });
117
- }
118
- export {
119
- FilterProperties,
120
- filterPropertiesYupSchema
121
- };
@@ -1,18 +0,0 @@
1
- import { PredefinedProperties } from '../../../utils/types/types';
2
-
3
- export declare const PROPERTY_NAME = "name_property";
4
- export declare const PROPERTY_VALUES = "prop_values";
5
- export declare const PROPERTY_VALUES_1 = "prop_values1";
6
- export declare const PROPERTY_VALUES_2 = "prop_values2";
7
- interface FilterPropertyProps {
8
- index: number;
9
- valuesFields: Array<{
10
- name: string;
11
- label: string;
12
- }>;
13
- handleDelete: (index: number) => void;
14
- predefined: PredefinedProperties;
15
- propertyType: string;
16
- }
17
- export declare function FilterProperty(props: FilterPropertyProps): import("react/jsx-runtime").JSX.Element;
18
- export {};
@@ -1,65 +0,0 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { useMemo, useCallback } from "react";
3
- import DeleteIcon from "@mui/icons-material/Delete";
4
- import IconButton from "@mui/material/IconButton";
5
- import Grid from "@mui/material/Grid";
6
- import { useFormContext, useWatch } from "react-hook-form";
7
- import { AutocompleteInput } from "../../inputs/reactHookForm/autocompleteInputs/AutocompleteInput.js";
8
- import { MultipleAutocompleteInput } from "../../inputs/reactHookForm/autocompleteInputs/MultipleAutocompleteInput.js";
9
- import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
10
- const PROPERTY_NAME = "name_property";
11
- const PROPERTY_VALUES = "prop_values";
12
- const PROPERTY_VALUES_1 = "prop_values1";
13
- const PROPERTY_VALUES_2 = "prop_values2";
14
- function FilterProperty(props) {
15
- const { propertyType, index, predefined, valuesFields, handleDelete } = props;
16
- const { setValue } = useFormContext();
17
- const watchName = useWatch({
18
- name: `${FieldConstants.CRITERIA_BASED}.${propertyType}[${index}].${PROPERTY_NAME}`
19
- });
20
- const predefinedNames = useMemo(() => {
21
- return Object.keys(predefined ?? []).sort();
22
- }, [predefined]);
23
- const predefinedValues = useMemo(() => {
24
- const predefinedForName = predefined == null ? void 0 : predefined[watchName];
25
- if (!predefinedForName) {
26
- return [];
27
- }
28
- return [...new Set(predefinedForName)].sort();
29
- }, [watchName, predefined]);
30
- const onNameChange = useCallback(() => {
31
- valuesFields.forEach(
32
- (valuesField) => setValue(`${FieldConstants.CRITERIA_BASED}.${propertyType}[${index}].${valuesField.name}`, [])
33
- );
34
- }, [setValue, index, valuesFields, propertyType]);
35
- return /* @__PURE__ */ jsxs(Grid, { container: true, item: true, spacing: 1, columns: 21, children: [
36
- /* @__PURE__ */ jsx(Grid, { item: true, xs: 6, children: /* @__PURE__ */ jsx(
37
- AutocompleteInput,
38
- {
39
- name: `${FieldConstants.CRITERIA_BASED}.${propertyType}[${index}].${PROPERTY_NAME}`,
40
- label: "PropertyName",
41
- options: predefinedNames,
42
- freeSolo: true,
43
- autoSelect: true,
44
- forcePopupIcon: true,
45
- onChangeCallback: onNameChange
46
- }
47
- ) }),
48
- valuesFields.map((valuesField) => /* @__PURE__ */ jsx(Grid, { item: true, xs: true, children: /* @__PURE__ */ jsx(
49
- MultipleAutocompleteInput,
50
- {
51
- name: `${FieldConstants.CRITERIA_BASED}.${propertyType}[${index}].${valuesField.name}`,
52
- label: valuesField.label,
53
- options: predefinedValues
54
- }
55
- ) }, valuesField.name)),
56
- /* @__PURE__ */ jsx(Grid, { item: true, xs: 1, alignSelf: "center", children: /* @__PURE__ */ jsx(IconButton, { onClick: () => handleDelete(index), children: /* @__PURE__ */ jsx(DeleteIcon, {}) }) })
57
- ] });
58
- }
59
- export {
60
- FilterProperty,
61
- PROPERTY_NAME,
62
- PROPERTY_VALUES,
63
- PROPERTY_VALUES_1,
64
- PROPERTY_VALUES_2
65
- };
@@ -1,158 +0,0 @@
1
- import { FieldConstants } from "../../../utils/constants/fieldConstants.js";
2
- import { PROPERTY_VALUES, PROPERTY_VALUES_1, PROPERTY_VALUES_2, PROPERTY_NAME } from "./FilterProperty.js";
3
- import { FilterType } from "../constants/FilterConstants.js";
4
- import "../../../utils/yupConfig.js";
5
- import { getRangeInputSchema, DEFAULT_RANGE_VALUE } from "../../inputs/reactHookForm/numbers/RangeInput.js";
6
- import { FreePropertiesTypes } from "./FilterFreeProperties.js";
7
- import * as yup from "yup";
8
- function getCriteriaBasedSchema(extraFields = {}) {
9
- return {
10
- [FieldConstants.CRITERIA_BASED]: yup.object().shape({
11
- [FieldConstants.COUNTRIES]: yup.array().of(yup.string().required()),
12
- [FieldConstants.COUNTRIES_1]: yup.array().of(yup.string().required()),
13
- [FieldConstants.COUNTRIES_2]: yup.array().of(yup.string().required()),
14
- ...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE),
15
- ...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE_1),
16
- ...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE_2),
17
- ...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE_3),
18
- ...extraFields
19
- })
20
- };
21
- }
22
- function getCriteriaBasedFormData(criteriaValues, extraFields = {}) {
23
- return {
24
- [FieldConstants.CRITERIA_BASED]: {
25
- [FieldConstants.COUNTRIES]: (criteriaValues == null ? void 0 : criteriaValues[FieldConstants.COUNTRIES]) ?? [],
26
- [FieldConstants.COUNTRIES_1]: (criteriaValues == null ? void 0 : criteriaValues[FieldConstants.COUNTRIES_1]) ?? [],
27
- [FieldConstants.COUNTRIES_2]: (criteriaValues == null ? void 0 : criteriaValues[FieldConstants.COUNTRIES_2]) ?? [],
28
- [FieldConstants.NOMINAL_VOLTAGE]: (criteriaValues == null ? void 0 : criteriaValues[FieldConstants.NOMINAL_VOLTAGE]) ?? DEFAULT_RANGE_VALUE,
29
- [FieldConstants.NOMINAL_VOLTAGE_1]: (criteriaValues == null ? void 0 : criteriaValues[FieldConstants.NOMINAL_VOLTAGE_1]) ?? DEFAULT_RANGE_VALUE,
30
- [FieldConstants.NOMINAL_VOLTAGE_2]: (criteriaValues == null ? void 0 : criteriaValues[FieldConstants.NOMINAL_VOLTAGE_2]) ?? DEFAULT_RANGE_VALUE,
31
- [FieldConstants.NOMINAL_VOLTAGE_3]: (criteriaValues == null ? void 0 : criteriaValues[FieldConstants.NOMINAL_VOLTAGE_3]) ?? DEFAULT_RANGE_VALUE,
32
- ...extraFields
33
- }
34
- };
35
- }
36
- function backToFrontTweak(response) {
37
- const subProps = response.equipmentFilterForm.substationFreeProperties;
38
- const freeProps = response.equipmentFilterForm.freeProperties;
39
- const props1 = response.equipmentFilterForm.freeProperties1;
40
- const props2 = response.equipmentFilterForm.freeProperties2;
41
- const allKeys = /* @__PURE__ */ new Set();
42
- if (subProps) {
43
- Object.keys(subProps).forEach((k) => allKeys.add(k));
44
- }
45
- if (props1) {
46
- Object.keys(props1).forEach((k) => allKeys.add(k));
47
- }
48
- if (props2) {
49
- Object.keys(props2).forEach((k) => allKeys.add(k));
50
- }
51
- const filterSubstationProperties = [];
52
- const filterFreeProperties = [];
53
- allKeys.forEach((k) => {
54
- const prop = { [PROPERTY_NAME]: k };
55
- const values = subProps == null ? void 0 : subProps[k];
56
- if (values) {
57
- prop[PROPERTY_VALUES] = values;
58
- }
59
- const values1 = props1 == null ? void 0 : props1[k];
60
- if (values1) {
61
- prop[PROPERTY_VALUES_1] = values1;
62
- }
63
- const values2 = props2 == null ? void 0 : props2[k];
64
- if (values2) {
65
- prop[PROPERTY_VALUES_2] = values2;
66
- }
67
- filterSubstationProperties.push(prop);
68
- });
69
- allKeys.clear();
70
- if (freeProps) {
71
- Object.keys(freeProps).forEach((k) => allKeys.add(k));
72
- }
73
- allKeys.forEach((k) => {
74
- const prop = { [PROPERTY_NAME]: k };
75
- const values = freeProps == null ? void 0 : freeProps[k];
76
- if (values) {
77
- prop[PROPERTY_VALUES] = values;
78
- }
79
- filterFreeProperties.push(prop);
80
- });
81
- return {
82
- [FieldConstants.EQUIPMENT_TYPE]: response[FieldConstants.EQUIPMENT_TYPE],
83
- ...getCriteriaBasedFormData(response.equipmentFilterForm, {
84
- [FieldConstants.ENERGY_SOURCE]: response.equipmentFilterForm[FieldConstants.ENERGY_SOURCE],
85
- [FreePropertiesTypes.SUBSTATION_FILTER_PROPERTIES]: filterSubstationProperties,
86
- [FreePropertiesTypes.FREE_FILTER_PROPERTIES]: filterFreeProperties
87
- })
88
- };
89
- }
90
- function isNominalVoltageEmpty(nominalVoltage) {
91
- return nominalVoltage[FieldConstants.VALUE_1] === null && nominalVoltage[FieldConstants.VALUE_2] === null;
92
- }
93
- function cleanNominalVoltages(formValues) {
94
- const cleanedFormValues = { ...formValues };
95
- if (isNominalVoltageEmpty(cleanedFormValues[FieldConstants.NOMINAL_VOLTAGE])) {
96
- cleanedFormValues[FieldConstants.NOMINAL_VOLTAGE] = null;
97
- }
98
- if (isNominalVoltageEmpty(cleanedFormValues[FieldConstants.NOMINAL_VOLTAGE_1])) {
99
- cleanedFormValues[FieldConstants.NOMINAL_VOLTAGE_1] = null;
100
- }
101
- if (isNominalVoltageEmpty(cleanedFormValues[FieldConstants.NOMINAL_VOLTAGE_2])) {
102
- cleanedFormValues[FieldConstants.NOMINAL_VOLTAGE_2] = null;
103
- }
104
- if (isNominalVoltageEmpty(cleanedFormValues[FieldConstants.NOMINAL_VOLTAGE_3])) {
105
- cleanedFormValues[FieldConstants.NOMINAL_VOLTAGE_3] = null;
106
- }
107
- return cleanedFormValues;
108
- }
109
- function frontToBackTweak(id, filter) {
110
- const filterSubstationProperties = filter[FieldConstants.CRITERIA_BASED][FreePropertiesTypes.SUBSTATION_FILTER_PROPERTIES];
111
- const eff = {
112
- [FieldConstants.EQUIPMENT_TYPE]: filter[FieldConstants.EQUIPMENT_TYPE],
113
- ...cleanNominalVoltages(filter[FieldConstants.CRITERIA_BASED])
114
- };
115
- delete eff[FreePropertiesTypes.SUBSTATION_FILTER_PROPERTIES];
116
- const props = {};
117
- const props1 = {};
118
- const props2 = {};
119
- filterSubstationProperties.forEach((prop) => {
120
- const values = prop[PROPERTY_VALUES];
121
- const values1 = prop[PROPERTY_VALUES_1];
122
- const values2 = prop[PROPERTY_VALUES_2];
123
- if (values) {
124
- props[prop[PROPERTY_NAME]] = values;
125
- }
126
- if (values1) {
127
- props1[prop[PROPERTY_NAME]] = values1;
128
- }
129
- if (values2) {
130
- props2[prop[PROPERTY_NAME]] = values2;
131
- }
132
- });
133
- eff.substationFreeProperties = props;
134
- eff.freeProperties1 = props1;
135
- eff.freeProperties2 = props2;
136
- const filterFreeProperties = filter[FieldConstants.CRITERIA_BASED][FreePropertiesTypes.FREE_FILTER_PROPERTIES];
137
- delete eff[FreePropertiesTypes.FREE_FILTER_PROPERTIES];
138
- const freeProps = {};
139
- filterFreeProperties.forEach((prop) => {
140
- const values = prop[PROPERTY_VALUES];
141
- if (values) {
142
- freeProps[prop[PROPERTY_NAME]] = values;
143
- }
144
- });
145
- eff.freeProperties = freeProps;
146
- return {
147
- id,
148
- type: FilterType.CRITERIA_BASED.id,
149
- // in the back end we store everything in a field called equipmentFilterForm
150
- equipmentFilterForm: eff
151
- };
152
- }
153
- export {
154
- backToFrontTweak,
155
- frontToBackTweak,
156
- getCriteriaBasedFormData,
157
- getCriteriaBasedSchema
158
- };
@@ -1,27 +0,0 @@
1
- import { CriteriaBasedFilterEditionDialog } from "./CriteriaBasedFilterEditionDialog.js";
2
- import { CriteriaBasedFilterForm, criteriaBasedFilterEmptyFormData, criteriaBasedFilterSchema } from "./CriteriaBasedFilterForm.js";
3
- import { CriteriaBasedForm } from "./CriteriaBasedForm.js";
4
- import { FilterFreeProperties, FreePropertiesTypes } from "./FilterFreeProperties.js";
5
- import { FilterProperties, filterPropertiesYupSchema } from "./FilterProperties.js";
6
- import { FilterProperty, PROPERTY_NAME, PROPERTY_VALUES, PROPERTY_VALUES_1, PROPERTY_VALUES_2 } from "./FilterProperty.js";
7
- import { backToFrontTweak, frontToBackTweak, getCriteriaBasedFormData, getCriteriaBasedSchema } from "./criteriaBasedFilterUtils.js";
8
- export {
9
- CriteriaBasedFilterEditionDialog,
10
- CriteriaBasedFilterForm,
11
- CriteriaBasedForm,
12
- FilterFreeProperties,
13
- FilterProperties,
14
- FilterProperty,
15
- FreePropertiesTypes,
16
- PROPERTY_NAME,
17
- PROPERTY_VALUES,
18
- PROPERTY_VALUES_1,
19
- PROPERTY_VALUES_2,
20
- backToFrontTweak,
21
- criteriaBasedFilterEmptyFormData,
22
- criteriaBasedFilterSchema,
23
- filterPropertiesYupSchema,
24
- frontToBackTweak,
25
- getCriteriaBasedFormData,
26
- getCriteriaBasedSchema
27
- };