@gridsuite/commons-ui 0.54.0 → 0.56.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/assets/criteria-based-filter-edition-dialog.css +168 -0
- package/dist/chunks/criteria-based-filter-edition-dialog.DxqH-mLe.js +1673 -0
- package/dist/chunks/filter-properties.GRon8-ML.js +195 -0
- package/dist/components/DirectoryItemSelector/directory-item-selector.d.ts +7 -6
- package/dist/components/DirectoryItemSelector/directory-item-selector.js +34 -43
- package/dist/components/FlatParameters/FlatParameters.js +3 -0
- package/dist/components/ReportViewer/log-report.d.ts +2 -2
- package/dist/components/TreeViewFinder/TreeViewFinder.d.ts +32 -58
- package/dist/components/TreeViewFinder/TreeViewFinder.js +126 -82
- package/dist/components/dialogs/custom-mui-dialog.d.ts +21 -0
- package/dist/components/dialogs/custom-mui-dialog.js +87 -0
- package/dist/components/dialogs/description-modification-dialog.d.ts +11 -0
- package/dist/components/dialogs/description-modification-dialog.js +71 -0
- package/dist/components/dialogs/popup-confirmation-dialog.d.ts +11 -0
- package/dist/components/dialogs/popup-confirmation-dialog.js +38 -0
- package/dist/components/filter/constants/equipment-types.d.ts +72 -0
- package/dist/components/filter/constants/equipment-types.js +63 -0
- package/dist/components/filter/constants/expert-filter-constants.d.ts +546 -0
- package/dist/components/filter/constants/expert-filter-constants.js +663 -0
- package/dist/components/filter/constants/field-constants.d.ts +45 -0
- package/dist/components/filter/constants/field-constants.js +43 -0
- package/dist/components/filter/constants/filter-constants.d.ts +21 -0
- package/dist/components/filter/constants/filter-constants.js +10 -0
- package/dist/components/filter/criteria-based/criteria-based-filter-edition-dialog.d.ts +29 -0
- package/dist/components/filter/criteria-based/criteria-based-filter-edition-dialog.js +19 -0
- package/dist/components/filter/criteria-based/criteria-based-filter-form.d.ts +15 -0
- package/dist/components/filter/criteria-based/criteria-based-filter-form.js +33 -0
- package/dist/components/filter/criteria-based/criteria-based-filter-utils.d.ts +37 -0
- package/dist/components/filter/criteria-based/criteria-based-filter-utils.js +127 -0
- package/dist/components/filter/criteria-based/criteria-based-form.d.ts +7 -0
- package/dist/components/filter/criteria-based/criteria-based-form.js +50 -0
- package/dist/components/filter/criteria-based/filter-free-properties.d.ts +10 -0
- package/dist/components/filter/criteria-based/filter-free-properties.js +15 -0
- package/dist/components/filter/criteria-based/filter-properties.d.ts +21 -0
- package/dist/components/filter/criteria-based/filter-properties.js +19 -0
- package/dist/components/filter/criteria-based/filter-property.d.ts +19 -0
- package/dist/components/filter/criteria-based/filter-property.js +67 -0
- package/dist/components/filter/expert/expert-filter-edition-dialog.d.ts +28 -0
- package/dist/components/filter/expert/expert-filter-edition-dialog.js +20 -0
- package/dist/components/filter/expert/expert-filter-form.d.ts +21 -0
- package/dist/components/filter/expert/expert-filter-form.js +22 -0
- package/dist/components/filter/expert/expert-filter-utils.d.ts +19 -0
- package/dist/components/filter/expert/expert-filter-utils.js +302 -0
- package/dist/components/filter/expert/expert-filter.type.d.ts +113 -0
- package/dist/components/filter/expert/expert-filter.type.js +103 -0
- package/dist/components/filter/explicit-naming/explicit-naming-filter-edition-dialog.d.ts +22 -0
- package/dist/components/filter/explicit-naming/explicit-naming-filter-edition-dialog.js +19 -0
- package/dist/components/filter/explicit-naming/explicit-naming-filter-form.d.ts +22 -0
- package/dist/components/filter/explicit-naming/explicit-naming-filter-form.js +23 -0
- package/dist/components/filter/filter-context.d.ts +12 -0
- package/dist/components/filter/filter-context.js +10 -0
- package/dist/components/filter/filter-creation-dialog.d.ts +21 -0
- package/dist/components/filter/filter-creation-dialog.js +17 -0
- package/dist/components/filter/filter-form.d.ts +11 -0
- package/dist/components/filter/filter-form.js +14 -0
- package/dist/components/filter/utils/criteria-based-utils.d.ts +28 -0
- package/dist/components/filter/utils/criteria-based-utils.js +197 -0
- package/dist/components/filter/utils/filters-utils.d.ts +5 -0
- package/dist/components/filter/utils/filters-utils.js +99 -0
- package/dist/components/inputs/select-clearable.d.ts +14 -0
- package/dist/components/inputs/select-clearable.js +40 -0
- package/dist/components/react-hook-form/ExpandingTextField.d.ts +1 -1
- package/dist/components/react-hook-form/ExpandingTextField.js +0 -37
- package/dist/components/react-hook-form/ag-grid-table-rhf/bottom-right-buttons.d.ts +17 -0
- package/dist/components/react-hook-form/ag-grid-table-rhf/bottom-right-buttons.js +15 -0
- package/dist/components/react-hook-form/ag-grid-table-rhf/cell-editors/numericEditor.d.ts +23 -0
- package/dist/components/react-hook-form/ag-grid-table-rhf/cell-editors/numericEditor.js +70 -0
- package/dist/components/react-hook-form/ag-grid-table-rhf/csv-uploader/csv-uploader.d.ts +16 -0
- package/dist/components/react-hook-form/ag-grid-table-rhf/csv-uploader/csv-uploader.js +69 -0
- package/dist/components/react-hook-form/ag-grid-table-rhf/custom-ag-grid-table.d.ts +23 -0
- package/dist/components/react-hook-form/ag-grid-table-rhf/custom-ag-grid-table.js +15 -0
- package/dist/components/react-hook-form/autocomplete-input.d.ts +17 -29
- package/dist/components/react-hook-form/autocomplete-input.js +4 -15
- package/dist/components/react-hook-form/autocomplete-inputs/multiple-autocomplete-input.d.ts +2 -0
- package/dist/components/react-hook-form/autocomplete-inputs/multiple-autocomplete-input.js +46 -0
- package/dist/components/react-hook-form/directory-items-input.d.ts +2 -4
- package/dist/components/react-hook-form/directory-items-input.js +61 -12
- package/dist/components/react-hook-form/error-management/error-input.d.ts +13 -4
- package/dist/components/react-hook-form/error-management/error-input.js +7 -7
- package/dist/components/react-hook-form/error-management/field-error-alert.d.ts +6 -3
- package/dist/components/react-hook-form/error-management/field-error-alert.js +3 -1
- package/dist/components/react-hook-form/numbers/float-input.d.ts +5 -17
- package/dist/components/react-hook-form/numbers/float-input.js +3 -5
- package/dist/components/react-hook-form/numbers/integer-input.d.ts +15 -12
- package/dist/components/react-hook-form/numbers/utils.d.ts +8 -2
- package/dist/components/react-hook-form/provider/custom-form-provider.d.ts +1 -0
- package/dist/components/react-hook-form/provider/custom-form-provider.js +12 -3
- package/dist/components/react-hook-form/radio-input.d.ts +14 -17
- package/dist/components/react-hook-form/radio-input.js +7 -9
- package/dist/components/react-hook-form/range-input.d.ts +54 -0
- package/dist/components/react-hook-form/range-input.js +118 -0
- package/dist/components/react-hook-form/select-inputs/countries-input.d.ts +8 -0
- package/dist/components/react-hook-form/select-inputs/countries-input.js +36 -0
- package/dist/components/react-hook-form/select-inputs/input-with-popup-confirmation.d.ts +2 -0
- package/dist/components/react-hook-form/select-inputs/input-with-popup-confirmation.js +61 -0
- package/dist/components/react-hook-form/select-inputs/mui-select-input.d.ts +12 -0
- package/dist/components/react-hook-form/select-inputs/mui-select-input.js +25 -0
- package/dist/components/react-hook-form/select-inputs/select-input.d.ts +9 -0
- package/dist/components/react-hook-form/select-inputs/select-input.js +37 -0
- package/dist/components/react-hook-form/text-input.d.ts +23 -32
- package/dist/components/react-hook-form/text-input.js +6 -20
- package/dist/components/react-hook-form/unique-name-input.d.ts +21 -0
- package/dist/components/react-hook-form/unique-name-input.js +129 -0
- package/dist/components/react-hook-form/utils/cancel-button.d.ts +9 -8
- package/dist/components/react-hook-form/utils/field-label.d.ts +12 -5
- package/dist/components/react-hook-form/utils/field-label.js +5 -1
- package/dist/components/react-hook-form/utils/functions.d.ts +12 -4
- package/dist/components/react-hook-form/utils/functions.js +21 -1
- package/dist/components/react-hook-form/utils/submit-button.d.ts +9 -8
- package/dist/components/react-hook-form/utils/text-field-with-adornment.d.ts +11 -11
- package/dist/components/react-hook-form/utils/text-field-with-adornment.js +18 -23
- package/dist/components/react-query-builder-inputs/add-button.d.ts +8 -0
- package/dist/components/react-query-builder-inputs/add-button.js +17 -0
- package/dist/components/react-query-builder-inputs/combinator-selector.d.ts +5 -0
- package/dist/components/react-query-builder-inputs/combinator-selector.js +38 -0
- package/dist/components/react-query-builder-inputs/country-value-editor.d.ts +5 -0
- package/dist/components/react-query-builder-inputs/country-value-editor.js +46 -0
- package/dist/components/react-query-builder-inputs/custom-react-query-builder.d.ts +8 -0
- package/dist/components/react-query-builder-inputs/custom-react-query-builder.js +21 -0
- package/dist/components/react-query-builder-inputs/element-value-editor.d.ts +14 -0
- package/dist/components/react-query-builder-inputs/element-value-editor.js +69 -0
- package/dist/components/react-query-builder-inputs/property-value-editor.d.ts +9 -0
- package/dist/components/react-query-builder-inputs/property-value-editor.js +100 -0
- package/dist/components/react-query-builder-inputs/remove-button.d.ts +5 -0
- package/dist/components/react-query-builder-inputs/remove-button.js +9 -0
- package/dist/components/react-query-builder-inputs/text-value-editor.d.ts +5 -0
- package/dist/components/react-query-builder-inputs/text-value-editor.js +34 -0
- package/dist/components/react-query-builder-inputs/translated-value-editor.d.ts +5 -0
- package/dist/components/react-query-builder-inputs/translated-value-editor.js +58 -0
- package/dist/components/react-query-builder-inputs/use-convert-value.d.ts +9 -0
- package/dist/components/react-query-builder-inputs/use-convert-value.js +24 -0
- package/dist/components/react-query-builder-inputs/use-valid.d.ts +7 -0
- package/dist/components/react-query-builder-inputs/use-valid.js +13 -0
- package/dist/components/react-query-builder-inputs/value-editor.d.ts +5 -0
- package/dist/components/react-query-builder-inputs/value-editor.js +18 -0
- package/dist/components/react-query-builder-inputs/value-selector.d.ts +4 -0
- package/dist/components/react-query-builder-inputs/value-selector.js +14 -0
- package/dist/components/translations/treeview-finder-en.d.ts +1 -0
- package/dist/components/translations/treeview-finder-en.js +4 -3
- package/dist/components/translations/treeview-finder-fr.d.ts +1 -0
- package/dist/components/translations/treeview-finder-fr.js +4 -3
- package/dist/hooks/localized-countries-hook.d.ts +6 -0
- package/dist/hooks/localized-countries-hook.js +45 -0
- package/dist/hooks/predefined-properties-hook.d.ts +18 -0
- package/dist/hooks/predefined-properties-hook.js +43 -0
- package/dist/hooks/useDebounce.d.ts +7 -1
- package/dist/hooks/useSnackMessage.d.ts +23 -5
- package/dist/hooks/useSnackMessage.js +14 -12
- package/dist/index.d.ts +92 -143
- package/dist/index.js +168 -91
- package/dist/utils/FetchStatus.d.ts +12 -0
- package/dist/utils/FetchStatus.js +9 -0
- package/dist/utils/conversion-utils.d.ts +12 -0
- package/dist/utils/conversion-utils.js +22 -0
- package/dist/utils/equipment-types-for-predefined-properties-mapper.d.ts +3 -0
- package/dist/utils/equipment-types-for-predefined-properties-mapper.js +31 -0
- package/dist/utils/functions.d.ts +14 -0
- package/dist/utils/functions.js +16 -0
- package/dist/utils/types.d.ts +21 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/yup-config.d.ts +8 -0
- package/dist/utils/yup-config.js +16 -0
- package/package.json +27 -4
- package/dist/components/react-hook-form/select-input.d.ts +0 -17
- package/dist/components/react-hook-form/select-input.js +0 -30
|
@@ -0,0 +1,1673 @@
|
|
|
1
|
+
import '../assets/criteria-based-filter-edition-dialog.css';
|
|
2
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import React, { useState, useMemo, useEffect, useCallback, useContext } from "react";
|
|
4
|
+
import { FieldConstants } from "../components/filter/constants/field-constants.js";
|
|
5
|
+
import { backToFrontTweak, frontToBackTweak } from "../components/filter/criteria-based/criteria-based-filter-utils.js";
|
|
6
|
+
import CustomMuiDialog from "../components/dialogs/custom-mui-dialog.js";
|
|
7
|
+
import { useSnackMessage } from "../hooks/useSnackMessage.js";
|
|
8
|
+
import { useWatch, useFormContext, useFieldArray, useController, useForm } from "react-hook-form";
|
|
9
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
10
|
+
import CriteriaBasedFilterForm, { criteriaBasedFilterEmptyFormData, criteriaBasedFilterSchema } from "../components/filter/criteria-based/criteria-based-filter-form.js";
|
|
11
|
+
import "../utils/yup-config.js";
|
|
12
|
+
import { UniqueNameInput } from "../components/react-hook-form/unique-name-input.js";
|
|
13
|
+
import { AgGridReact } from "ag-grid-react";
|
|
14
|
+
import "ag-grid-community/styles/ag-grid.css";
|
|
15
|
+
import "ag-grid-community/styles/ag-theme-alpine.css";
|
|
16
|
+
import { DialogContentText, Grid as Grid$1, Tooltip, useTheme, Box as Box$1 } from "@mui/material";
|
|
17
|
+
import IconButton from "@mui/material/IconButton";
|
|
18
|
+
import { Upload, ArrowCircleUp, ArrowCircleDown } from "@mui/icons-material";
|
|
19
|
+
import AddIcon from "@mui/icons-material/ControlPoint";
|
|
20
|
+
import DeleteIcon from "@mui/icons-material/Delete";
|
|
21
|
+
import Dialog from "@mui/material/Dialog";
|
|
22
|
+
import DialogTitle from "@mui/material/DialogTitle";
|
|
23
|
+
import DialogContent from "@mui/material/DialogContent";
|
|
24
|
+
import DialogActions from "@mui/material/DialogActions";
|
|
25
|
+
import { useCSVReader } from "react-papaparse";
|
|
26
|
+
import Button from "@mui/material/Button";
|
|
27
|
+
import Grid from "@mui/material/Grid";
|
|
28
|
+
import { useIntl, FormattedMessage } from "react-intl";
|
|
29
|
+
import CsvDownloader from "react-csv-downloader";
|
|
30
|
+
import Alert from "@mui/material/Alert";
|
|
31
|
+
import "../components/TreeViewFinder/TreeViewFinder.js";
|
|
32
|
+
import "../components/TopBar/TopBar.js";
|
|
33
|
+
import "../components/TopBar/GridLogo.js";
|
|
34
|
+
import "../components/TopBar/AboutDialog.js";
|
|
35
|
+
import "../components/SnackbarProvider/SnackbarProvider.js";
|
|
36
|
+
import "react-router-dom";
|
|
37
|
+
import "../utils/AuthService.js";
|
|
38
|
+
import "../components/MuiVirtualizedTable/MuiVirtualizedTable.js";
|
|
39
|
+
import "../components/ReportViewer/report-item.js";
|
|
40
|
+
import { v4, validate } from "uuid";
|
|
41
|
+
import "../components/ReportViewer/log-table.js";
|
|
42
|
+
import "../components/ReportViewer/report-tree-view-context.js";
|
|
43
|
+
import "@mui/x-tree-view";
|
|
44
|
+
import "../components/OverflowableText/overflowable-text.js";
|
|
45
|
+
import "../components/ElementSearchDialog/element-search-dialog.js";
|
|
46
|
+
import "../components/ElementSearchDialog/tag-renderer.js";
|
|
47
|
+
import "../components/react-hook-form/utils/submit-button.js";
|
|
48
|
+
import CancelButton from "../components/react-hook-form/utils/cancel-button.js";
|
|
49
|
+
import "../components/react-hook-form/provider/custom-form-provider.js";
|
|
50
|
+
import "../components/dialogs/description-modification-dialog.js";
|
|
51
|
+
import * as yup from "yup";
|
|
52
|
+
import "../components/dialogs/popup-confirmation-dialog.js";
|
|
53
|
+
import { FILTER_EQUIPMENTS } from "../components/filter/utils/criteria-based-utils.js";
|
|
54
|
+
import "autosuggest-highlight/match";
|
|
55
|
+
import "autosuggest-highlight/parse";
|
|
56
|
+
import "clsx";
|
|
57
|
+
import "../components/CardErrorBoundary/card-error-boundary.js";
|
|
58
|
+
import "notistack";
|
|
59
|
+
import "../components/react-hook-form/slider-input.js";
|
|
60
|
+
import "../components/react-hook-form/numbers/integer-input.js";
|
|
61
|
+
import "../components/react-hook-form/booleans/checkbox-input.js";
|
|
62
|
+
import "../components/react-hook-form/booleans/switch-input.js";
|
|
63
|
+
import "@mui/icons-material/Folder";
|
|
64
|
+
import { FilterContext } from "../components/filter/filter-context.js";
|
|
65
|
+
import { saveExplicitNamingFilter, saveCriteriaBasedFilter, saveExpertFilter } from "../components/filter/utils/filters-utils.js";
|
|
66
|
+
import { formatQuery, QueryBuilder } from "react-querybuilder";
|
|
67
|
+
import { getNumberOfSiblings, recursiveRemove, countRules, getOperators, queryValidator, testQuery, importExpertRules } from "../components/filter/expert/expert-filter-utils.js";
|
|
68
|
+
import { COMBINATOR_OPTIONS, RULES, EXPERT_FILTER_EQUIPMENTS, OPERATOR_OPTIONS, fields } from "../components/filter/constants/expert-filter-constants.js";
|
|
69
|
+
import { FieldType, OperatorType, DataType } from "../components/filter/expert/expert-filter.type.js";
|
|
70
|
+
import { QueryBuilderDnD } from "@react-querybuilder/dnd";
|
|
71
|
+
import * as ReactDnD from "react-dnd";
|
|
72
|
+
import * as ReactDndHtml5Backend from "react-dnd-html5-backend";
|
|
73
|
+
import { MaterialValueEditor, QueryBuilderMaterial } from "@react-querybuilder/material";
|
|
74
|
+
import CombinatorSelector from "../components/react-query-builder-inputs/combinator-selector.js";
|
|
75
|
+
import AddButton from "../components/react-query-builder-inputs/add-button.js";
|
|
76
|
+
import CountryValueEditor from "../components/react-query-builder-inputs/country-value-editor.js";
|
|
77
|
+
import TranslatedValueEditor from "../components/react-query-builder-inputs/translated-value-editor.js";
|
|
78
|
+
import TextValueEditor from "../components/react-query-builder-inputs/text-value-editor.js";
|
|
79
|
+
import Box from "@mui/material/Box";
|
|
80
|
+
import { Generator, Load, VoltageLevel, Substation, noSelectionForCopy as noSelectionForCopy$1 } from "../components/filter/constants/equipment-types.js";
|
|
81
|
+
import { useCustomFormContext } from "../components/react-hook-form/provider/use-custom-form-context.js";
|
|
82
|
+
import DirectoryItemsInput from "../components/react-hook-form/directory-items-input.js";
|
|
83
|
+
import { DISTRIBUTION_KEY, FilterType } from "../components/filter/constants/filter-constants.js";
|
|
84
|
+
import { FetchStatus } from "../utils/FetchStatus.js";
|
|
85
|
+
import PropTypes from "prop-types";
|
|
86
|
+
import "./filter-properties.GRon8-ML.js";
|
|
87
|
+
import "../components/react-hook-form/range-input.js";
|
|
88
|
+
import "../components/react-hook-form/select-inputs/mui-select-input.js";
|
|
89
|
+
import "localized-countries";
|
|
90
|
+
import "localized-countries/data/fr";
|
|
91
|
+
import "localized-countries/data/en";
|
|
92
|
+
import "@mui/icons-material/Check";
|
|
93
|
+
import "@mui/material/CircularProgress";
|
|
94
|
+
import "@mui/material/TextField";
|
|
95
|
+
import { ElementType } from "../utils/ElementType.js";
|
|
96
|
+
import PropertyValueEditor from "../components/react-query-builder-inputs/property-value-editor.js";
|
|
97
|
+
import ValueSelector from "../components/react-query-builder-inputs/value-selector.js";
|
|
98
|
+
import ErrorInput from "../components/react-hook-form/error-management/error-input.js";
|
|
99
|
+
import FieldErrorAlert from "../components/react-hook-form/error-management/field-error-alert.js";
|
|
100
|
+
import InputWithPopupConfirmation from "../components/react-hook-form/select-inputs/input-with-popup-confirmation.js";
|
|
101
|
+
import SelectInput from "../components/react-hook-form/select-inputs/select-input.js";
|
|
102
|
+
import { styled } from "@mui/material/styles";
|
|
103
|
+
import { NumericEditor } from "../components/react-hook-form/ag-grid-table-rhf/cell-editors/numericEditor.js";
|
|
104
|
+
import { toFloatOrNullValue } from "../components/react-hook-form/utils/functions.js";
|
|
105
|
+
import RadioInput from "../components/react-hook-form/radio-input.js";
|
|
106
|
+
import ExpandingTextField from "../components/react-hook-form/ExpandingTextField.js";
|
|
107
|
+
const CsvUploader = ({
|
|
108
|
+
name,
|
|
109
|
+
onClose,
|
|
110
|
+
open,
|
|
111
|
+
title,
|
|
112
|
+
fileHeaders,
|
|
113
|
+
fileName,
|
|
114
|
+
csvData,
|
|
115
|
+
validateData = (_rows) => true,
|
|
116
|
+
getDataFromCsv,
|
|
117
|
+
useFieldArrayOutput
|
|
118
|
+
}) => {
|
|
119
|
+
const watchTableValues = useWatch({ name });
|
|
120
|
+
const { append, replace } = useFieldArrayOutput;
|
|
121
|
+
const [createError, setCreateError] = React.useState("");
|
|
122
|
+
const intl = useIntl();
|
|
123
|
+
const { CSVReader } = useCSVReader();
|
|
124
|
+
const [importedData, setImportedData] = useState([]);
|
|
125
|
+
const [isConfirmationPopupOpen, setOpenConfirmationPopup] = useState(false);
|
|
126
|
+
const data = useMemo(() => {
|
|
127
|
+
const data2 = [...[fileHeaders]];
|
|
128
|
+
if (Array.isArray(csvData)) {
|
|
129
|
+
csvData.forEach((row) => data2.push([row]));
|
|
130
|
+
}
|
|
131
|
+
return data2;
|
|
132
|
+
}, [csvData, fileHeaders]);
|
|
133
|
+
const handleClose = () => {
|
|
134
|
+
onClose();
|
|
135
|
+
setCreateError("");
|
|
136
|
+
};
|
|
137
|
+
const validateCsvFile = (rows) => {
|
|
138
|
+
if (rows.length === 0) {
|
|
139
|
+
setCreateError(intl.formatMessage({ id: "noDataInCsvFile" }));
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
for (let i = 0; i < fileHeaders.length; i++) {
|
|
143
|
+
if (fileHeaders[i] !== "" && rows[0][i] !== fileHeaders[i]) {
|
|
144
|
+
setCreateError(
|
|
145
|
+
intl.formatMessage({ id: "wrongCsvHeadersError" })
|
|
146
|
+
);
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return validateData(rows);
|
|
151
|
+
};
|
|
152
|
+
const getResultsFromImportedData = () => {
|
|
153
|
+
return importedData.filter((row) => {
|
|
154
|
+
if (row[0].startsWith("#")) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return row.some((column) => !!(column == null ? void 0 : column.trim()));
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
const handleFileSubmit = (keepTableValues) => {
|
|
161
|
+
if (importedData.length !== 0) {
|
|
162
|
+
const result = getResultsFromImportedData();
|
|
163
|
+
if (validateCsvFile(result)) {
|
|
164
|
+
result.splice(0, 1);
|
|
165
|
+
const dataFromCsv = getDataFromCsv(result);
|
|
166
|
+
if (keepTableValues) {
|
|
167
|
+
append(dataFromCsv);
|
|
168
|
+
} else {
|
|
169
|
+
replace(dataFromCsv);
|
|
170
|
+
}
|
|
171
|
+
handleClose();
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
setCreateError(intl.formatMessage({ id: "noDataInCsvFile" }));
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const handleOpenCSVConfirmationDataDialog = () => {
|
|
178
|
+
const isValuesInTable = Array.isArray(watchTableValues) && watchTableValues.some(
|
|
179
|
+
(val) => val && Object.keys(val).filter(
|
|
180
|
+
(key) => key !== FieldConstants.AG_GRID_ROW_UUID
|
|
181
|
+
).some(
|
|
182
|
+
(e) => val[e] !== void 0 && val[e] !== null && String(val[e]).trim().length > 0
|
|
183
|
+
)
|
|
184
|
+
);
|
|
185
|
+
if (isValuesInTable && getResultsFromImportedData().length > 0) {
|
|
186
|
+
setOpenConfirmationPopup(true);
|
|
187
|
+
} else {
|
|
188
|
+
setOpenConfirmationPopup(false);
|
|
189
|
+
handleFileSubmit(false);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const handleAddPopupConfirmation = () => {
|
|
193
|
+
handleFileSubmit(true);
|
|
194
|
+
setOpenConfirmationPopup(false);
|
|
195
|
+
};
|
|
196
|
+
const handleReplacePopupConfirmation = () => {
|
|
197
|
+
handleFileSubmit(false);
|
|
198
|
+
setOpenConfirmationPopup(false);
|
|
199
|
+
};
|
|
200
|
+
const handleCancelDialog = () => {
|
|
201
|
+
setOpenConfirmationPopup(false);
|
|
202
|
+
};
|
|
203
|
+
const renderConfirmationCsvData = () => {
|
|
204
|
+
return /* @__PURE__ */ jsxs(
|
|
205
|
+
Dialog,
|
|
206
|
+
{
|
|
207
|
+
open: isConfirmationPopupOpen,
|
|
208
|
+
"aria-labelledby": "dialog-confirmation-csv-data",
|
|
209
|
+
children: [
|
|
210
|
+
/* @__PURE__ */ jsx(DialogTitle, { id: "dialog-confirmation-csv-data", children: "Confirmation" }),
|
|
211
|
+
/* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(DialogContentText, { children: intl.formatMessage({ id: "keepCSVDataMessage" }) }) }),
|
|
212
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [
|
|
213
|
+
/* @__PURE__ */ jsx(CancelButton, { onClick: handleCancelDialog }),
|
|
214
|
+
/* @__PURE__ */ jsx(
|
|
215
|
+
Button,
|
|
216
|
+
{
|
|
217
|
+
onClick: () => handleReplacePopupConfirmation(),
|
|
218
|
+
variant: "outlined",
|
|
219
|
+
children: /* @__PURE__ */ jsx(FormattedMessage, { id: "replace" })
|
|
220
|
+
}
|
|
221
|
+
),
|
|
222
|
+
/* @__PURE__ */ jsx(
|
|
223
|
+
Button,
|
|
224
|
+
{
|
|
225
|
+
onClick: () => handleAddPopupConfirmation(),
|
|
226
|
+
variant: "outlined",
|
|
227
|
+
children: /* @__PURE__ */ jsx(FormattedMessage, { id: "add" })
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
] })
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
};
|
|
235
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
236
|
+
/* @__PURE__ */ jsxs(Dialog, { open, onClose: handleClose, fullWidth: true, children: [
|
|
237
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: title }),
|
|
238
|
+
/* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsxs("div", { children: [
|
|
239
|
+
/* @__PURE__ */ jsxs(Grid, { container: true, spacing: 2, children: [
|
|
240
|
+
/* @__PURE__ */ jsx(Grid, { container: true, item: true, children: /* @__PURE__ */ jsx(Grid, { item: true, xs: 6, children: /* @__PURE__ */ jsx(
|
|
241
|
+
CsvDownloader,
|
|
242
|
+
{
|
|
243
|
+
datas: data,
|
|
244
|
+
filename: fileName,
|
|
245
|
+
separator: ",",
|
|
246
|
+
children: /* @__PURE__ */ jsx(Button, { variant: "contained", children: /* @__PURE__ */ jsx(FormattedMessage, { id: "GenerateCSV" }) })
|
|
247
|
+
}
|
|
248
|
+
) }) }),
|
|
249
|
+
/* @__PURE__ */ jsx(Grid, { container: true, item: true, spacing: 3, children: /* @__PURE__ */ jsx(
|
|
250
|
+
CSVReader,
|
|
251
|
+
{
|
|
252
|
+
onUploadAccepted: (results) => {
|
|
253
|
+
setImportedData([...results.data]);
|
|
254
|
+
setCreateError("");
|
|
255
|
+
},
|
|
256
|
+
children: ({ getRootProps, acceptedFile }) => /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Grid, { item: true, children: [
|
|
257
|
+
/* @__PURE__ */ jsx(
|
|
258
|
+
Button,
|
|
259
|
+
{
|
|
260
|
+
...getRootProps(),
|
|
261
|
+
variant: "contained",
|
|
262
|
+
children: /* @__PURE__ */ jsx(FormattedMessage, { id: "UploadCSV" })
|
|
263
|
+
}
|
|
264
|
+
),
|
|
265
|
+
/* @__PURE__ */ jsx(
|
|
266
|
+
"span",
|
|
267
|
+
{
|
|
268
|
+
style: {
|
|
269
|
+
marginLeft: "10px",
|
|
270
|
+
fontWeight: "bold"
|
|
271
|
+
},
|
|
272
|
+
children: acceptedFile ? acceptedFile.name : intl.formatMessage({
|
|
273
|
+
id: "uploadMessage"
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
)
|
|
277
|
+
] }) })
|
|
278
|
+
}
|
|
279
|
+
) })
|
|
280
|
+
] }),
|
|
281
|
+
createError !== "" && /* @__PURE__ */ jsx(Alert, { severity: "error", children: createError })
|
|
282
|
+
] }) }),
|
|
283
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [
|
|
284
|
+
/* @__PURE__ */ jsx(CancelButton, { onClick: handleClose }),
|
|
285
|
+
/* @__PURE__ */ jsx(
|
|
286
|
+
Button,
|
|
287
|
+
{
|
|
288
|
+
variant: "outlined",
|
|
289
|
+
onClick: () => handleOpenCSVConfirmationDataDialog(),
|
|
290
|
+
disabled: createError !== "",
|
|
291
|
+
children: /* @__PURE__ */ jsx(FormattedMessage, { id: "validate" })
|
|
292
|
+
}
|
|
293
|
+
)
|
|
294
|
+
] })
|
|
295
|
+
] }),
|
|
296
|
+
renderConfirmationCsvData()
|
|
297
|
+
] });
|
|
298
|
+
};
|
|
299
|
+
const InnerColoredButton = styled(IconButton)(({ theme }) => {
|
|
300
|
+
return {
|
|
301
|
+
color: theme.palette.primary.main
|
|
302
|
+
};
|
|
303
|
+
});
|
|
304
|
+
const BottomRightButtons = ({
|
|
305
|
+
name,
|
|
306
|
+
disableUp,
|
|
307
|
+
disableDown,
|
|
308
|
+
disableDelete,
|
|
309
|
+
handleAddRow,
|
|
310
|
+
handleDeleteRows,
|
|
311
|
+
handleMoveRowUp,
|
|
312
|
+
handleMoveRowDown,
|
|
313
|
+
useFieldArrayOutput,
|
|
314
|
+
csvProps
|
|
315
|
+
}) => {
|
|
316
|
+
const [uploaderOpen, setUploaderOpen] = useState(false);
|
|
317
|
+
const intl = useIntl();
|
|
318
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
319
|
+
/* @__PURE__ */ jsxs(Grid$1, { container: true, paddingTop: 1, paddingLeft: 2, children: [
|
|
320
|
+
/* @__PURE__ */ jsx(Grid$1, { item: true, xs: 1, children: csvProps && /* @__PURE__ */ jsx(
|
|
321
|
+
InnerColoredButton,
|
|
322
|
+
{
|
|
323
|
+
onClick: () => setUploaderOpen(true),
|
|
324
|
+
children: /* @__PURE__ */ jsx(
|
|
325
|
+
Tooltip,
|
|
326
|
+
{
|
|
327
|
+
title: intl.formatMessage({
|
|
328
|
+
id: "ImportCSV"
|
|
329
|
+
}),
|
|
330
|
+
placement: "bottom",
|
|
331
|
+
children: /* @__PURE__ */ jsx(Upload, {})
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
) }),
|
|
336
|
+
/* @__PURE__ */ jsxs(
|
|
337
|
+
Grid$1,
|
|
338
|
+
{
|
|
339
|
+
item: true,
|
|
340
|
+
xs: 11,
|
|
341
|
+
sx: { display: "flex", justifyContent: "right" },
|
|
342
|
+
children: [
|
|
343
|
+
/* @__PURE__ */ jsx(
|
|
344
|
+
InnerColoredButton,
|
|
345
|
+
{
|
|
346
|
+
onClick: handleAddRow,
|
|
347
|
+
children: /* @__PURE__ */ jsx(AddIcon, {})
|
|
348
|
+
},
|
|
349
|
+
"addButton"
|
|
350
|
+
),
|
|
351
|
+
/* @__PURE__ */ jsx(
|
|
352
|
+
InnerColoredButton,
|
|
353
|
+
{
|
|
354
|
+
onClick: handleDeleteRows,
|
|
355
|
+
disabled: disableDelete,
|
|
356
|
+
children: /* @__PURE__ */ jsx(DeleteIcon, {})
|
|
357
|
+
},
|
|
358
|
+
"DeleteButton"
|
|
359
|
+
),
|
|
360
|
+
/* @__PURE__ */ jsx(
|
|
361
|
+
InnerColoredButton,
|
|
362
|
+
{
|
|
363
|
+
disabled: disableUp,
|
|
364
|
+
onClick: handleMoveRowUp,
|
|
365
|
+
children: /* @__PURE__ */ jsx(ArrowCircleUp, {})
|
|
366
|
+
},
|
|
367
|
+
"upButton"
|
|
368
|
+
),
|
|
369
|
+
/* @__PURE__ */ jsx(
|
|
370
|
+
InnerColoredButton,
|
|
371
|
+
{
|
|
372
|
+
disabled: disableDown,
|
|
373
|
+
onClick: handleMoveRowDown,
|
|
374
|
+
children: /* @__PURE__ */ jsx(ArrowCircleDown, {})
|
|
375
|
+
},
|
|
376
|
+
"downButton"
|
|
377
|
+
)
|
|
378
|
+
]
|
|
379
|
+
}
|
|
380
|
+
)
|
|
381
|
+
] }),
|
|
382
|
+
/* @__PURE__ */ jsx(Grid$1, { item: true, xs: 12, children: /* @__PURE__ */ jsx(ErrorInput, { name, InputField: FieldErrorAlert }) }),
|
|
383
|
+
/* @__PURE__ */ jsx(
|
|
384
|
+
CsvUploader,
|
|
385
|
+
{
|
|
386
|
+
open: uploaderOpen,
|
|
387
|
+
onClose: () => setUploaderOpen(false),
|
|
388
|
+
name,
|
|
389
|
+
useFieldArrayOutput,
|
|
390
|
+
...csvProps
|
|
391
|
+
}
|
|
392
|
+
)
|
|
393
|
+
] });
|
|
394
|
+
};
|
|
395
|
+
const ROW_DRAGGING_SELECTION_COLUMN_DEF = [
|
|
396
|
+
{
|
|
397
|
+
rowDrag: true,
|
|
398
|
+
headerCheckboxSelection: true,
|
|
399
|
+
checkboxSelection: true,
|
|
400
|
+
maxWidth: 50
|
|
401
|
+
}
|
|
402
|
+
];
|
|
403
|
+
const style = (customProps) => ({
|
|
404
|
+
grid: (theme) => ({
|
|
405
|
+
width: "auto",
|
|
406
|
+
height: "100%",
|
|
407
|
+
position: "relative",
|
|
408
|
+
// - AG Grid colors override -
|
|
409
|
+
// It shouldn't be exactly like this, but I couldn't make it works otherwise
|
|
410
|
+
// https://www.ag-grid.com/react-data-grid/global-style-customisation/
|
|
411
|
+
"--ag-alpine-active-color": theme.palette.primary.main + " !important",
|
|
412
|
+
"--ag-checkbox-indeterminate-color": theme.palette.primary.main + " !important",
|
|
413
|
+
"--ag-background-color": theme.agGridBackground.color + " !important",
|
|
414
|
+
"--ag-header-background-color": theme.agGridBackground.color + " !important",
|
|
415
|
+
"--ag-odd-row-background-color": theme.agGridBackground.color + " !important",
|
|
416
|
+
"--ag-modal-overlay-background-color": theme.agGridBackground.color + " !important",
|
|
417
|
+
"--ag-selected-row-background-color": "transparent !important",
|
|
418
|
+
"--ag-range-selection-border-color": "transparent !important",
|
|
419
|
+
//overrides the default computed max height for ag grid default selector editor to make it more usable
|
|
420
|
+
//can be removed if a custom selector editor is implemented
|
|
421
|
+
"& .ag-select-list": {
|
|
422
|
+
maxHeight: "300px !important"
|
|
423
|
+
},
|
|
424
|
+
"& .ag-root-wrapper-body": {
|
|
425
|
+
maxHeight: "500px"
|
|
426
|
+
},
|
|
427
|
+
"& .ag-cell": {
|
|
428
|
+
boxShadow: "none"
|
|
429
|
+
},
|
|
430
|
+
"& .ag-cell-edit-wrapper": {
|
|
431
|
+
height: "inherit"
|
|
432
|
+
},
|
|
433
|
+
"& .ag-row-hover": {
|
|
434
|
+
cursor: "text"
|
|
435
|
+
},
|
|
436
|
+
"& .ag-overlay-loading-center": {
|
|
437
|
+
border: "none",
|
|
438
|
+
boxShadow: "none"
|
|
439
|
+
},
|
|
440
|
+
"& .numeric-input": {
|
|
441
|
+
fontSize: "calc(var(--ag-font-size) + 1px)",
|
|
442
|
+
paddingLeft: "calc(var(--ag-cell-horizontal-padding) - 1px)",
|
|
443
|
+
width: "100%",
|
|
444
|
+
height: "100%",
|
|
445
|
+
border: "inherit",
|
|
446
|
+
outline: "inherit",
|
|
447
|
+
backgroundColor: theme.agGridBackground.color
|
|
448
|
+
},
|
|
449
|
+
"& .Mui-focused .MuiOutlinedInput-root": {
|
|
450
|
+
// borders moves row height
|
|
451
|
+
outline: "var(--ag-borders-input) var(--ag-input-focus-border-color)",
|
|
452
|
+
outlineOffset: "-1px",
|
|
453
|
+
backgroundColor: theme.agGridBackground.color
|
|
454
|
+
},
|
|
455
|
+
...customProps
|
|
456
|
+
})
|
|
457
|
+
});
|
|
458
|
+
const CustomAgGridTable = ({
|
|
459
|
+
name,
|
|
460
|
+
columnDefs,
|
|
461
|
+
makeDefaultRowData: makeDefaultRowData2,
|
|
462
|
+
csvProps,
|
|
463
|
+
cssProps,
|
|
464
|
+
defaultColDef,
|
|
465
|
+
pagination,
|
|
466
|
+
paginationPageSize,
|
|
467
|
+
suppressRowClickSelection,
|
|
468
|
+
alwaysShowVerticalScroll,
|
|
469
|
+
stopEditingWhenCellsLoseFocus,
|
|
470
|
+
...props
|
|
471
|
+
}) => {
|
|
472
|
+
var _a, _b;
|
|
473
|
+
const theme = useTheme();
|
|
474
|
+
const [gridApi, setGridApi] = useState(null);
|
|
475
|
+
const [selectedRows, setSelectedRows] = useState([]);
|
|
476
|
+
const [newRowAdded, setNewRowAdded] = useState(false);
|
|
477
|
+
const { control, getValues, watch } = useFormContext();
|
|
478
|
+
const useFieldArrayOutput = useFieldArray({
|
|
479
|
+
control,
|
|
480
|
+
name
|
|
481
|
+
});
|
|
482
|
+
const { append, remove, update, swap, move } = useFieldArrayOutput;
|
|
483
|
+
const rowData = watch(name);
|
|
484
|
+
const isFirstSelected = (rowData == null ? void 0 : rowData.length) && ((_a = gridApi == null ? void 0 : gridApi.api.getRowNode(rowData[0][FieldConstants.AG_GRID_ROW_UUID])) == null ? void 0 : _a.isSelected());
|
|
485
|
+
const isLastSelected = (rowData == null ? void 0 : rowData.length) && ((_b = gridApi == null ? void 0 : gridApi.api.getRowNode(
|
|
486
|
+
rowData[rowData.length - 1][FieldConstants.AG_GRID_ROW_UUID]
|
|
487
|
+
)) == null ? void 0 : _b.isSelected());
|
|
488
|
+
const noRowSelected = selectedRows.length === 0;
|
|
489
|
+
const handleMoveRowUp = () => {
|
|
490
|
+
selectedRows.map((row) => getIndex(row)).sort().forEach((idx) => {
|
|
491
|
+
swap(idx, idx - 1);
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
const handleMoveRowDown = () => {
|
|
495
|
+
selectedRows.map((row) => getIndex(row)).sort().reverse().forEach((idx) => {
|
|
496
|
+
swap(idx, idx + 1);
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
const handleDeleteRows = () => {
|
|
500
|
+
if (selectedRows.length === rowData.length) {
|
|
501
|
+
remove();
|
|
502
|
+
} else {
|
|
503
|
+
selectedRows.forEach((val) => {
|
|
504
|
+
const idx = getIndex(val);
|
|
505
|
+
remove(idx);
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
useEffect(() => {
|
|
510
|
+
if (gridApi) {
|
|
511
|
+
gridApi.api.refreshCells({
|
|
512
|
+
force: true
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}, [gridApi, rowData]);
|
|
516
|
+
const handleAddRow = () => {
|
|
517
|
+
append(makeDefaultRowData2());
|
|
518
|
+
setNewRowAdded(true);
|
|
519
|
+
};
|
|
520
|
+
const getIndex = (val) => {
|
|
521
|
+
return getValues(name).findIndex(
|
|
522
|
+
(row) => row[FieldConstants.AG_GRID_ROW_UUID] === val[FieldConstants.AG_GRID_ROW_UUID]
|
|
523
|
+
);
|
|
524
|
+
};
|
|
525
|
+
useEffect(() => {
|
|
526
|
+
if (gridApi) {
|
|
527
|
+
gridApi.api.sizeColumnsToFit();
|
|
528
|
+
}
|
|
529
|
+
}, [columnDefs, gridApi]);
|
|
530
|
+
const intl = useIntl();
|
|
531
|
+
const getLocaleText = useCallback(
|
|
532
|
+
(params) => {
|
|
533
|
+
const key = "agGrid." + params.key;
|
|
534
|
+
return intl.messages[key] || params.defaultValue;
|
|
535
|
+
},
|
|
536
|
+
[intl]
|
|
537
|
+
);
|
|
538
|
+
const onGridReady = (params) => {
|
|
539
|
+
setGridApi(params);
|
|
540
|
+
};
|
|
541
|
+
const onRowDataUpdated = () => {
|
|
542
|
+
setNewRowAdded(false);
|
|
543
|
+
if (gridApi == null ? void 0 : gridApi.api) {
|
|
544
|
+
const lastIndex = rowData.length - 1;
|
|
545
|
+
gridApi.api.paginationGoToLastPage();
|
|
546
|
+
gridApi.api.ensureIndexVisible(lastIndex, "bottom");
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
return /* @__PURE__ */ jsxs(Grid$1, { container: true, spacing: 2, children: [
|
|
550
|
+
/* @__PURE__ */ jsx(
|
|
551
|
+
Grid$1,
|
|
552
|
+
{
|
|
553
|
+
item: true,
|
|
554
|
+
xs: 12,
|
|
555
|
+
className: theme.aggrid,
|
|
556
|
+
sx: style(cssProps).grid,
|
|
557
|
+
children: /* @__PURE__ */ jsx(
|
|
558
|
+
AgGridReact,
|
|
559
|
+
{
|
|
560
|
+
rowData: gridApi && (rowData == null ? void 0 : rowData.length) ? rowData : null,
|
|
561
|
+
onGridReady,
|
|
562
|
+
getLocaleText,
|
|
563
|
+
cacheOverflowSize: 10,
|
|
564
|
+
rowSelection: "multiple",
|
|
565
|
+
domLayout: "autoHeight",
|
|
566
|
+
rowDragEntireRow: true,
|
|
567
|
+
rowDragManaged: true,
|
|
568
|
+
onRowDragEnd: (e) => move(getIndex(e.node.data), e.overIndex),
|
|
569
|
+
suppressBrowserResizeObserver: true,
|
|
570
|
+
columnDefs,
|
|
571
|
+
detailRowAutoHeight: true,
|
|
572
|
+
onSelectionChanged: (event) => {
|
|
573
|
+
setSelectedRows(gridApi.api.getSelectedRows());
|
|
574
|
+
},
|
|
575
|
+
onRowDataUpdated: newRowAdded ? onRowDataUpdated : void 0,
|
|
576
|
+
onCellEditingStopped: (event) => {
|
|
577
|
+
update(event.rowIndex, event.data);
|
|
578
|
+
},
|
|
579
|
+
getRowId: (row) => row.data[FieldConstants.AG_GRID_ROW_UUID],
|
|
580
|
+
pagination,
|
|
581
|
+
paginationPageSize,
|
|
582
|
+
suppressRowClickSelection,
|
|
583
|
+
alwaysShowVerticalScroll,
|
|
584
|
+
stopEditingWhenCellsLoseFocus,
|
|
585
|
+
...props
|
|
586
|
+
}
|
|
587
|
+
)
|
|
588
|
+
}
|
|
589
|
+
),
|
|
590
|
+
/* @__PURE__ */ jsx(
|
|
591
|
+
BottomRightButtons,
|
|
592
|
+
{
|
|
593
|
+
name,
|
|
594
|
+
handleAddRow,
|
|
595
|
+
handleDeleteRows,
|
|
596
|
+
handleMoveRowDown,
|
|
597
|
+
handleMoveRowUp,
|
|
598
|
+
disableUp: noRowSelected || isFirstSelected,
|
|
599
|
+
disableDown: noRowSelected || isLastSelected,
|
|
600
|
+
disableDelete: noRowSelected,
|
|
601
|
+
csvProps,
|
|
602
|
+
useFieldArrayOutput
|
|
603
|
+
}
|
|
604
|
+
)
|
|
605
|
+
] });
|
|
606
|
+
};
|
|
607
|
+
const FILTER_EQUIPMENTS_ATTRIBUTES = "filterEquipmentsAttributes";
|
|
608
|
+
const explicitNamingFilterSchema = {
|
|
609
|
+
[FILTER_EQUIPMENTS_ATTRIBUTES]: yup.array().of(
|
|
610
|
+
yup.object().shape({
|
|
611
|
+
[FieldConstants.EQUIPMENT_ID]: yup.string().nullable(),
|
|
612
|
+
[DISTRIBUTION_KEY]: yup.number().nullable()
|
|
613
|
+
})
|
|
614
|
+
).compact(
|
|
615
|
+
(row) => !row[DISTRIBUTION_KEY] && !row[FieldConstants.EQUIPMENT_ID]
|
|
616
|
+
).when([FieldConstants.FILTER_TYPE], {
|
|
617
|
+
is: FilterType.EXPLICIT_NAMING.id,
|
|
618
|
+
then: (schema) => schema.min(1, "emptyFilterError").when([FieldConstants.EQUIPMENT_TYPE], {
|
|
619
|
+
is: (equipmentType) => isGeneratorOrLoad(equipmentType),
|
|
620
|
+
then: (schema2) => schema2.test(
|
|
621
|
+
"noKeyWithoutId",
|
|
622
|
+
"distributionKeyWithMissingIdError",
|
|
623
|
+
(array) => {
|
|
624
|
+
return !array.some(
|
|
625
|
+
(row) => !row[FieldConstants.EQUIPMENT_ID]
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
).test(
|
|
629
|
+
"ifOneKeyThenKeyEverywhere",
|
|
630
|
+
"missingDistributionKeyError",
|
|
631
|
+
(array) => {
|
|
632
|
+
return !(array.some(
|
|
633
|
+
(row) => row[DISTRIBUTION_KEY]
|
|
634
|
+
) && array.some(
|
|
635
|
+
(row) => !row[DISTRIBUTION_KEY]
|
|
636
|
+
));
|
|
637
|
+
}
|
|
638
|
+
)
|
|
639
|
+
})
|
|
640
|
+
})
|
|
641
|
+
};
|
|
642
|
+
function isGeneratorOrLoad(equipmentType) {
|
|
643
|
+
return equipmentType === Generator.type || equipmentType === Load.type;
|
|
644
|
+
}
|
|
645
|
+
function makeDefaultRowData() {
|
|
646
|
+
return {
|
|
647
|
+
[FieldConstants.AG_GRID_ROW_UUID]: v4(),
|
|
648
|
+
[FieldConstants.EQUIPMENT_ID]: "",
|
|
649
|
+
[DISTRIBUTION_KEY]: null
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
function makeDefaultTableRows() {
|
|
653
|
+
return [makeDefaultRowData(), makeDefaultRowData(), makeDefaultRowData()];
|
|
654
|
+
}
|
|
655
|
+
function getExplicitNamingFilterEmptyFormData() {
|
|
656
|
+
return {
|
|
657
|
+
[FILTER_EQUIPMENTS_ATTRIBUTES]: makeDefaultTableRows()
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
const ExplicitNamingFilterForm = () => {
|
|
661
|
+
const intl = useIntl();
|
|
662
|
+
const { getValues, setValue } = useFormContext();
|
|
663
|
+
const watchEquipmentType = useWatch({
|
|
664
|
+
name: FieldConstants.EQUIPMENT_TYPE
|
|
665
|
+
});
|
|
666
|
+
const forGeneratorOrLoad = isGeneratorOrLoad(watchEquipmentType);
|
|
667
|
+
const columnDefs = useMemo(() => {
|
|
668
|
+
const columnDefs2 = [
|
|
669
|
+
...ROW_DRAGGING_SELECTION_COLUMN_DEF,
|
|
670
|
+
{
|
|
671
|
+
headerName: intl.formatMessage({
|
|
672
|
+
id: FieldConstants.EQUIPMENT_ID
|
|
673
|
+
}),
|
|
674
|
+
field: FieldConstants.EQUIPMENT_ID,
|
|
675
|
+
editable: true,
|
|
676
|
+
singleClickEdit: true,
|
|
677
|
+
valueParser: (params) => {
|
|
678
|
+
var _a;
|
|
679
|
+
return ((_a = params.newValue) == null ? void 0 : _a.trim()) ?? null;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
];
|
|
683
|
+
if (forGeneratorOrLoad) {
|
|
684
|
+
columnDefs2.push({
|
|
685
|
+
headerName: intl.formatMessage({ id: DISTRIBUTION_KEY }),
|
|
686
|
+
field: DISTRIBUTION_KEY,
|
|
687
|
+
editable: true,
|
|
688
|
+
singleClickEdit: true,
|
|
689
|
+
cellEditor: NumericEditor,
|
|
690
|
+
maxWidth: 200
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
return columnDefs2;
|
|
694
|
+
}, [intl, forGeneratorOrLoad]);
|
|
695
|
+
const defaultColDef = useMemo(
|
|
696
|
+
() => ({
|
|
697
|
+
suppressMovable: true
|
|
698
|
+
}),
|
|
699
|
+
[]
|
|
700
|
+
);
|
|
701
|
+
const csvFileHeaders = useMemo(() => {
|
|
702
|
+
const csvFileHeaders2 = [
|
|
703
|
+
intl.formatMessage({ id: FieldConstants.EQUIPMENT_ID })
|
|
704
|
+
];
|
|
705
|
+
if (forGeneratorOrLoad) {
|
|
706
|
+
csvFileHeaders2.push(intl.formatMessage({ id: DISTRIBUTION_KEY }));
|
|
707
|
+
}
|
|
708
|
+
return csvFileHeaders2;
|
|
709
|
+
}, [intl, forGeneratorOrLoad]);
|
|
710
|
+
const getDataFromCsvFile = useCallback((csvData) => {
|
|
711
|
+
if (csvData) {
|
|
712
|
+
return csvData.map((value) => {
|
|
713
|
+
var _a, _b;
|
|
714
|
+
return {
|
|
715
|
+
[FieldConstants.AG_GRID_ROW_UUID]: v4(),
|
|
716
|
+
[FieldConstants.EQUIPMENT_ID]: (_a = value[0]) == null ? void 0 : _a.trim(),
|
|
717
|
+
[DISTRIBUTION_KEY]: toFloatOrNullValue((_b = value[1]) == null ? void 0 : _b.trim())
|
|
718
|
+
};
|
|
719
|
+
});
|
|
720
|
+
} else {
|
|
721
|
+
return [];
|
|
722
|
+
}
|
|
723
|
+
}, []);
|
|
724
|
+
const openConfirmationPopup = () => {
|
|
725
|
+
return getValues(FILTER_EQUIPMENTS_ATTRIBUTES).some(
|
|
726
|
+
(row) => row[DISTRIBUTION_KEY] || row[FieldConstants.EQUIPMENT_ID]
|
|
727
|
+
);
|
|
728
|
+
};
|
|
729
|
+
const handleResetOnConfirmation = () => {
|
|
730
|
+
setValue(FILTER_EQUIPMENTS_ATTRIBUTES, makeDefaultTableRows());
|
|
731
|
+
};
|
|
732
|
+
return /* @__PURE__ */ jsxs(Grid, { container: true, item: true, spacing: 2, children: [
|
|
733
|
+
/* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsx(
|
|
734
|
+
InputWithPopupConfirmation,
|
|
735
|
+
{
|
|
736
|
+
Input: SelectInput,
|
|
737
|
+
name: FieldConstants.EQUIPMENT_TYPE,
|
|
738
|
+
options: Object.values(FILTER_EQUIPMENTS),
|
|
739
|
+
label: "equipmentType",
|
|
740
|
+
shouldOpenPopup: openConfirmationPopup,
|
|
741
|
+
resetOnConfirmation: handleResetOnConfirmation,
|
|
742
|
+
message: "changeTypeMessage",
|
|
743
|
+
validateButtonLabel: "button.changeType"
|
|
744
|
+
}
|
|
745
|
+
) }),
|
|
746
|
+
watchEquipmentType && /* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsx(
|
|
747
|
+
CustomAgGridTable,
|
|
748
|
+
{
|
|
749
|
+
name: FILTER_EQUIPMENTS_ATTRIBUTES,
|
|
750
|
+
columnDefs,
|
|
751
|
+
defaultColDef,
|
|
752
|
+
makeDefaultRowData,
|
|
753
|
+
pagination: true,
|
|
754
|
+
paginationPageSize: 100,
|
|
755
|
+
suppressRowClickSelection: true,
|
|
756
|
+
alwaysShowVerticalScroll: true,
|
|
757
|
+
stopEditingWhenCellsLoseFocus: true,
|
|
758
|
+
csvProps: {
|
|
759
|
+
fileName: intl.formatMessage({
|
|
760
|
+
id: "filterCsvFileName"
|
|
761
|
+
}),
|
|
762
|
+
fileHeaders: csvFileHeaders,
|
|
763
|
+
getDataFromCsv: getDataFromCsvFile
|
|
764
|
+
},
|
|
765
|
+
cssProps: {
|
|
766
|
+
"& .ag-root-wrapper-body": {
|
|
767
|
+
maxHeight: "430px"
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
) })
|
|
772
|
+
] });
|
|
773
|
+
};
|
|
774
|
+
const RemoveButton = (props) => {
|
|
775
|
+
const {
|
|
776
|
+
field: { value: query, onChange }
|
|
777
|
+
} = useController({ name: EXPERT_FILTER_QUERY });
|
|
778
|
+
function handleDelete(e) {
|
|
779
|
+
onChange(recursiveRemove(query, props.path));
|
|
780
|
+
}
|
|
781
|
+
const isLastRuleOrGroup = props.path.toString() === [0].toString() && getNumberOfSiblings(props.path, query) === 1;
|
|
782
|
+
return /* @__PURE__ */ jsx(
|
|
783
|
+
IconButton,
|
|
784
|
+
{
|
|
785
|
+
size: "small",
|
|
786
|
+
onClick: handleDelete,
|
|
787
|
+
className: props.className,
|
|
788
|
+
children: !isLastRuleOrGroup && /* @__PURE__ */ jsx(DeleteIcon, {})
|
|
789
|
+
}
|
|
790
|
+
);
|
|
791
|
+
};
|
|
792
|
+
const ElementValueEditor = (props) => {
|
|
793
|
+
const { setValue } = useCustomFormContext();
|
|
794
|
+
const { fetchElementsInfos } = useContext(FilterContext);
|
|
795
|
+
useEffect(() => {
|
|
796
|
+
if (props.defaultValue && Array.isArray(props.defaultValue) && props.defaultValue.length > 0 && props.defaultValue[0].length > 0 && validate(props.defaultValue[0])) {
|
|
797
|
+
fetchElementsInfos && fetchElementsInfos(props.defaultValue).then(
|
|
798
|
+
(childrenWithMetadata) => {
|
|
799
|
+
setValue(
|
|
800
|
+
props.name,
|
|
801
|
+
childrenWithMetadata.map((v) => {
|
|
802
|
+
return {
|
|
803
|
+
id: v.elementUuid,
|
|
804
|
+
name: v.elementName,
|
|
805
|
+
specificMetadata: v.specificMetadata
|
|
806
|
+
};
|
|
807
|
+
})
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
}, [
|
|
813
|
+
props.name,
|
|
814
|
+
props.defaultValue,
|
|
815
|
+
props.elementType,
|
|
816
|
+
setValue,
|
|
817
|
+
fetchElementsInfos
|
|
818
|
+
]);
|
|
819
|
+
return /* @__PURE__ */ jsx(
|
|
820
|
+
DirectoryItemsInput,
|
|
821
|
+
{
|
|
822
|
+
name: props.name,
|
|
823
|
+
elementType: props.elementType,
|
|
824
|
+
equipmentTypes: props.equipmentTypes,
|
|
825
|
+
titleId: props.titleId,
|
|
826
|
+
hideErrorMessage: props.hideErrorMessage,
|
|
827
|
+
label: "filter",
|
|
828
|
+
itemFilter: props.itemFilter,
|
|
829
|
+
onChange: props.onChange,
|
|
830
|
+
labelRequiredFromContext: false
|
|
831
|
+
}
|
|
832
|
+
);
|
|
833
|
+
};
|
|
834
|
+
const styles = {
|
|
835
|
+
noArrows: {
|
|
836
|
+
"& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button": {
|
|
837
|
+
display: "none"
|
|
838
|
+
},
|
|
839
|
+
"& input[type=number]": {
|
|
840
|
+
MozAppearance: "textfield"
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
const ValueEditor = (props) => {
|
|
845
|
+
const formContext = useFormContext();
|
|
846
|
+
const { getValues } = formContext;
|
|
847
|
+
const itemFilter = useCallback(
|
|
848
|
+
(value) => {
|
|
849
|
+
var _a, _b, _c;
|
|
850
|
+
if ((value == null ? void 0 : value.type) === ElementType.FILTER) {
|
|
851
|
+
return (
|
|
852
|
+
// we do not authorize to use an expert filter in the rules of
|
|
853
|
+
// another expert filter, to prevent potential cycle problems
|
|
854
|
+
((_a = value == null ? void 0 : value.specificMetadata) == null ? void 0 : _a.type) !== FilterType.EXPERT.id && (props.field === FieldType.ID && ((_b = value == null ? void 0 : value.specificMetadata) == null ? void 0 : _b.equipmentType) === getValues(FieldConstants.EQUIPMENT_TYPE) || (props.field === FieldType.VOLTAGE_LEVEL_ID || props.field === FieldType.VOLTAGE_LEVEL_ID_1 || props.field === FieldType.VOLTAGE_LEVEL_ID_2) && ((_c = value == null ? void 0 : value.specificMetadata) == null ? void 0 : _c.equipmentType) === VoltageLevel.type)
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
return true;
|
|
858
|
+
},
|
|
859
|
+
[props.field, getValues]
|
|
860
|
+
);
|
|
861
|
+
if (props.operator === OperatorType.EXISTS) {
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
if ([FieldType.COUNTRY, FieldType.COUNTRY_1, FieldType.COUNTRY_2].includes(
|
|
865
|
+
props.field
|
|
866
|
+
)) {
|
|
867
|
+
return /* @__PURE__ */ jsx(CountryValueEditor, { ...props });
|
|
868
|
+
}
|
|
869
|
+
if (props.field === FieldType.ENERGY_SOURCE || props.field === FieldType.SHUNT_COMPENSATOR_TYPE || props.field === FieldType.LOAD_TYPE || props.field === FieldType.RATIO_REGULATION_MODE || props.field === FieldType.PHASE_REGULATION_MODE) {
|
|
870
|
+
return /* @__PURE__ */ jsx(TranslatedValueEditor, { ...props });
|
|
871
|
+
}
|
|
872
|
+
if (props.operator === OperatorType.IS_PART_OF || props.operator === OperatorType.IS_NOT_PART_OF) {
|
|
873
|
+
let equipmentTypes;
|
|
874
|
+
if (props.field === FieldType.VOLTAGE_LEVEL_ID || props.field === FieldType.VOLTAGE_LEVEL_ID_1 || props.field === FieldType.VOLTAGE_LEVEL_ID_2) {
|
|
875
|
+
equipmentTypes = [VoltageLevel.type];
|
|
876
|
+
} else if (props.field === FieldType.ID) {
|
|
877
|
+
equipmentTypes = [getValues(FieldConstants.EQUIPMENT_TYPE)];
|
|
878
|
+
}
|
|
879
|
+
return /* @__PURE__ */ jsx(
|
|
880
|
+
ElementValueEditor,
|
|
881
|
+
{
|
|
882
|
+
name: DataType.FILTER_UUID + props.rule.id,
|
|
883
|
+
elementType: ElementType.FILTER,
|
|
884
|
+
equipmentTypes,
|
|
885
|
+
titleId: "selectFilterDialogTitle",
|
|
886
|
+
hideErrorMessage: true,
|
|
887
|
+
onChange: (e) => {
|
|
888
|
+
props.handleOnChange(e.map((v) => v.id));
|
|
889
|
+
},
|
|
890
|
+
itemFilter,
|
|
891
|
+
defaultValue: props.value
|
|
892
|
+
}
|
|
893
|
+
);
|
|
894
|
+
} else if (props.field === FieldType.ID || props.field === FieldType.NAME || props.field === FieldType.VOLTAGE_LEVEL_ID || props.field === FieldType.VOLTAGE_LEVEL_ID_1 || props.field === FieldType.VOLTAGE_LEVEL_ID_2) {
|
|
895
|
+
return /* @__PURE__ */ jsx(TextValueEditor, { ...props });
|
|
896
|
+
} else if (props.field === FieldType.PROPERTY || props.field === FieldType.SUBSTATION_PROPERTY || props.field === FieldType.SUBSTATION_PROPERTY_1 || props.field === FieldType.SUBSTATION_PROPERTY_2) {
|
|
897
|
+
let equipmentType;
|
|
898
|
+
if (props.field === FieldType.SUBSTATION_PROPERTY || props.field === FieldType.SUBSTATION_PROPERTY_1 || props.field === FieldType.SUBSTATION_PROPERTY_2) {
|
|
899
|
+
equipmentType = Substation.type;
|
|
900
|
+
} else {
|
|
901
|
+
equipmentType = getValues(FieldConstants.EQUIPMENT_TYPE);
|
|
902
|
+
}
|
|
903
|
+
return /* @__PURE__ */ jsx(
|
|
904
|
+
PropertyValueEditor,
|
|
905
|
+
{
|
|
906
|
+
equipmentType,
|
|
907
|
+
valueEditorProps: props
|
|
908
|
+
}
|
|
909
|
+
);
|
|
910
|
+
}
|
|
911
|
+
return /* @__PURE__ */ jsx(Box, { sx: props.inputType === "number" ? styles.noArrows : void 0, children: /* @__PURE__ */ jsx(
|
|
912
|
+
MaterialValueEditor,
|
|
913
|
+
{
|
|
914
|
+
...props,
|
|
915
|
+
title: void 0
|
|
916
|
+
}
|
|
917
|
+
) });
|
|
918
|
+
};
|
|
919
|
+
const CustomReactQueryBuilder = (props) => {
|
|
920
|
+
const {
|
|
921
|
+
getValues,
|
|
922
|
+
setValue,
|
|
923
|
+
watch,
|
|
924
|
+
formState: { isSubmitted }
|
|
925
|
+
// Set to true after the form is submitted. Will remain true until the reset method is invoked.
|
|
926
|
+
} = useFormContext();
|
|
927
|
+
const intl = useIntl();
|
|
928
|
+
const query = watch(props.name);
|
|
929
|
+
const handleQueryChange = useCallback(
|
|
930
|
+
(newQuery) => {
|
|
931
|
+
const oldQuery = getValues(props.name);
|
|
932
|
+
const hasQueryChanged = formatQuery(oldQuery, "json_without_ids") !== formatQuery(newQuery, "json_without_ids");
|
|
933
|
+
const hasAddedRules = countRules(newQuery) > countRules(oldQuery);
|
|
934
|
+
setValue(props.name, newQuery, {
|
|
935
|
+
shouldDirty: hasQueryChanged,
|
|
936
|
+
shouldValidate: isSubmitted && hasQueryChanged && !hasAddedRules
|
|
937
|
+
});
|
|
938
|
+
},
|
|
939
|
+
[getValues, setValue, isSubmitted, props.name]
|
|
940
|
+
);
|
|
941
|
+
const combinators = useMemo(() => {
|
|
942
|
+
return Object.values(COMBINATOR_OPTIONS).map((c) => ({
|
|
943
|
+
name: c.name,
|
|
944
|
+
label: intl.formatMessage({ id: c.label })
|
|
945
|
+
}));
|
|
946
|
+
}, [intl]);
|
|
947
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
948
|
+
/* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsx(QueryBuilderMaterial, { children: /* @__PURE__ */ jsx(
|
|
949
|
+
QueryBuilderDnD,
|
|
950
|
+
{
|
|
951
|
+
dnd: { ...ReactDnD, ...ReactDndHtml5Backend },
|
|
952
|
+
children: /* @__PURE__ */ jsx(
|
|
953
|
+
QueryBuilder,
|
|
954
|
+
{
|
|
955
|
+
fields: props.fields,
|
|
956
|
+
query,
|
|
957
|
+
addRuleToNewGroups: true,
|
|
958
|
+
combinators,
|
|
959
|
+
onQueryChange: handleQueryChange,
|
|
960
|
+
getOperators: (fieldName) => getOperators(fieldName, intl),
|
|
961
|
+
validator: queryValidator,
|
|
962
|
+
controlClassnames: {
|
|
963
|
+
queryBuilder: "queryBuilder-branches"
|
|
964
|
+
},
|
|
965
|
+
controlElements: {
|
|
966
|
+
addRuleAction: (props2) => /* @__PURE__ */ jsx(AddButton, { ...props2, label: "rule" }),
|
|
967
|
+
addGroupAction: (props2) => /* @__PURE__ */ jsx(AddButton, { ...props2, label: "subGroup" }),
|
|
968
|
+
combinatorSelector: CombinatorSelector,
|
|
969
|
+
removeRuleAction: RemoveButton,
|
|
970
|
+
removeGroupAction: RemoveButton,
|
|
971
|
+
valueEditor: ValueEditor,
|
|
972
|
+
operatorSelector: ValueSelector,
|
|
973
|
+
fieldSelector: ValueSelector,
|
|
974
|
+
valueSourceSelector: ValueSelector
|
|
975
|
+
},
|
|
976
|
+
listsAsArrays: true
|
|
977
|
+
}
|
|
978
|
+
)
|
|
979
|
+
}
|
|
980
|
+
) }) }),
|
|
981
|
+
/* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsx(ErrorInput, { name: props.name, InputField: FieldErrorAlert }) })
|
|
982
|
+
] });
|
|
983
|
+
};
|
|
984
|
+
yup.setLocale({
|
|
985
|
+
mixed: {
|
|
986
|
+
required: "YupRequired",
|
|
987
|
+
notType: ({ type }) => {
|
|
988
|
+
if (type === "number") {
|
|
989
|
+
return "YupNotTypeNumber";
|
|
990
|
+
} else {
|
|
991
|
+
return "YupNotTypeDefault";
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
const EXPERT_FILTER_QUERY = "rules";
|
|
997
|
+
const expertFilterSchema = {
|
|
998
|
+
[EXPERT_FILTER_QUERY]: yup.object().when([FieldConstants.FILTER_TYPE], {
|
|
999
|
+
is: FilterType.EXPERT.id,
|
|
1000
|
+
then: (schema) => schema.when([FieldConstants.EQUIPMENT_TYPE], {
|
|
1001
|
+
is: (equipmentType) => isSupportedEquipmentType(equipmentType),
|
|
1002
|
+
then: (schema2) => schema2.test(
|
|
1003
|
+
RULES.EMPTY_GROUP,
|
|
1004
|
+
RULES.EMPTY_GROUP,
|
|
1005
|
+
(query) => {
|
|
1006
|
+
return testQuery(
|
|
1007
|
+
RULES.EMPTY_GROUP,
|
|
1008
|
+
query
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
).test(
|
|
1012
|
+
RULES.EMPTY_RULE,
|
|
1013
|
+
RULES.EMPTY_RULE,
|
|
1014
|
+
(query) => {
|
|
1015
|
+
return testQuery(
|
|
1016
|
+
RULES.EMPTY_RULE,
|
|
1017
|
+
query
|
|
1018
|
+
);
|
|
1019
|
+
}
|
|
1020
|
+
).test(
|
|
1021
|
+
RULES.INCORRECT_RULE,
|
|
1022
|
+
RULES.INCORRECT_RULE,
|
|
1023
|
+
(query) => {
|
|
1024
|
+
return testQuery(
|
|
1025
|
+
RULES.INCORRECT_RULE,
|
|
1026
|
+
query
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
).test(
|
|
1030
|
+
RULES.BETWEEN_RULE,
|
|
1031
|
+
RULES.BETWEEN_RULE,
|
|
1032
|
+
(query) => {
|
|
1033
|
+
return testQuery(
|
|
1034
|
+
RULES.BETWEEN_RULE,
|
|
1035
|
+
query
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
)
|
|
1039
|
+
})
|
|
1040
|
+
})
|
|
1041
|
+
};
|
|
1042
|
+
function isSupportedEquipmentType(equipmentType) {
|
|
1043
|
+
return Object.values(EXPERT_FILTER_EQUIPMENTS).map((equipments) => equipments.id).includes(equipmentType);
|
|
1044
|
+
}
|
|
1045
|
+
const defaultQuery = {
|
|
1046
|
+
combinator: COMBINATOR_OPTIONS.AND.name,
|
|
1047
|
+
rules: [
|
|
1048
|
+
{
|
|
1049
|
+
id: v4(),
|
|
1050
|
+
field: FieldType.ID,
|
|
1051
|
+
operator: OPERATOR_OPTIONS.CONTAINS.name,
|
|
1052
|
+
value: ""
|
|
1053
|
+
}
|
|
1054
|
+
]
|
|
1055
|
+
};
|
|
1056
|
+
function getExpertFilterEmptyFormData() {
|
|
1057
|
+
return {
|
|
1058
|
+
[EXPERT_FILTER_QUERY]: defaultQuery
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
const ExpertFilterForm = () => {
|
|
1062
|
+
const intl = useIntl();
|
|
1063
|
+
const { getValues, setValue } = useFormContext();
|
|
1064
|
+
const openConfirmationPopup = useCallback(() => {
|
|
1065
|
+
return formatQuery(getValues(EXPERT_FILTER_QUERY), "json_without_ids") !== formatQuery(defaultQuery, "json_without_ids");
|
|
1066
|
+
}, [getValues]);
|
|
1067
|
+
const handleResetOnConfirmation = useCallback(() => {
|
|
1068
|
+
setValue(EXPERT_FILTER_QUERY, defaultQuery);
|
|
1069
|
+
}, [setValue]);
|
|
1070
|
+
const watchEquipmentType = useWatch({
|
|
1071
|
+
name: FieldConstants.EQUIPMENT_TYPE
|
|
1072
|
+
});
|
|
1073
|
+
const translatedFields = useMemo(() => {
|
|
1074
|
+
var _a;
|
|
1075
|
+
return (_a = fields[watchEquipmentType]) == null ? void 0 : _a.map((field) => {
|
|
1076
|
+
return {
|
|
1077
|
+
...field,
|
|
1078
|
+
label: intl.formatMessage({ id: field.label })
|
|
1079
|
+
};
|
|
1080
|
+
});
|
|
1081
|
+
}, [intl, watchEquipmentType]);
|
|
1082
|
+
return /* @__PURE__ */ jsxs(Grid, { container: true, item: true, spacing: 2, children: [
|
|
1083
|
+
/* @__PURE__ */ jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsx(
|
|
1084
|
+
InputWithPopupConfirmation,
|
|
1085
|
+
{
|
|
1086
|
+
Input: SelectInput,
|
|
1087
|
+
name: FieldConstants.EQUIPMENT_TYPE,
|
|
1088
|
+
options: Object.values(EXPERT_FILTER_EQUIPMENTS),
|
|
1089
|
+
label: "equipmentType",
|
|
1090
|
+
shouldOpenPopup: openConfirmationPopup,
|
|
1091
|
+
resetOnConfirmation: handleResetOnConfirmation,
|
|
1092
|
+
message: "changeTypeMessage",
|
|
1093
|
+
validateButtonLabel: "button.changeType"
|
|
1094
|
+
}
|
|
1095
|
+
) }),
|
|
1096
|
+
watchEquipmentType && isSupportedEquipmentType(watchEquipmentType) && /* @__PURE__ */ jsx(
|
|
1097
|
+
CustomReactQueryBuilder,
|
|
1098
|
+
{
|
|
1099
|
+
name: EXPERT_FILTER_QUERY,
|
|
1100
|
+
fields: translatedFields
|
|
1101
|
+
}
|
|
1102
|
+
)
|
|
1103
|
+
] });
|
|
1104
|
+
};
|
|
1105
|
+
const FilterForm = (props) => {
|
|
1106
|
+
const { setValue } = useFormContext();
|
|
1107
|
+
const filterType = useWatch({ name: FieldConstants.FILTER_TYPE });
|
|
1108
|
+
const handleChange = (_event, value) => {
|
|
1109
|
+
setValue(FieldConstants.FILTER_TYPE, value);
|
|
1110
|
+
};
|
|
1111
|
+
return /* @__PURE__ */ jsxs(Grid$1, { container: true, spacing: 2, children: [
|
|
1112
|
+
/* @__PURE__ */ jsx(Grid$1, { item: true, xs: 12, children: /* @__PURE__ */ jsx(
|
|
1113
|
+
UniqueNameInput,
|
|
1114
|
+
{
|
|
1115
|
+
name: FieldConstants.NAME,
|
|
1116
|
+
label: "nameProperty",
|
|
1117
|
+
elementType: ElementType.FILTER,
|
|
1118
|
+
autoFocus: props.creation,
|
|
1119
|
+
activeDirectory: props.activeDirectory,
|
|
1120
|
+
elementExists: props.elementExists
|
|
1121
|
+
}
|
|
1122
|
+
) }),
|
|
1123
|
+
props.creation && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1124
|
+
/* @__PURE__ */ jsx(Grid$1, { item: true, xs: 12, children: /* @__PURE__ */ jsx(Box$1, { children: /* @__PURE__ */ jsx(
|
|
1125
|
+
ExpandingTextField,
|
|
1126
|
+
{
|
|
1127
|
+
name: FieldConstants.DESCRIPTION,
|
|
1128
|
+
label: "descriptionProperty",
|
|
1129
|
+
minRows: 3,
|
|
1130
|
+
rows: 5
|
|
1131
|
+
}
|
|
1132
|
+
) }) }),
|
|
1133
|
+
/* @__PURE__ */ jsx(Grid$1, { item: true, children: /* @__PURE__ */ jsx(
|
|
1134
|
+
RadioInput,
|
|
1135
|
+
{
|
|
1136
|
+
name: FieldConstants.FILTER_TYPE,
|
|
1137
|
+
options: Object.values(FilterType),
|
|
1138
|
+
formProps: { onChange: handleChange }
|
|
1139
|
+
}
|
|
1140
|
+
) })
|
|
1141
|
+
] }),
|
|
1142
|
+
filterType === FilterType.CRITERIA_BASED.id && /* @__PURE__ */ jsx(CriteriaBasedFilterForm, {}),
|
|
1143
|
+
filterType === FilterType.EXPLICIT_NAMING.id && /* @__PURE__ */ jsx(ExplicitNamingFilterForm, {}),
|
|
1144
|
+
filterType === FilterType.EXPERT.id && /* @__PURE__ */ jsx(ExpertFilterForm, {})
|
|
1145
|
+
] });
|
|
1146
|
+
};
|
|
1147
|
+
const emptyFormData = {
|
|
1148
|
+
[FieldConstants.NAME]: "",
|
|
1149
|
+
[FieldConstants.DESCRIPTION]: "",
|
|
1150
|
+
[FieldConstants.FILTER_TYPE]: FilterType.CRITERIA_BASED.id,
|
|
1151
|
+
[FieldConstants.EQUIPMENT_TYPE]: null,
|
|
1152
|
+
...criteriaBasedFilterEmptyFormData,
|
|
1153
|
+
...getExplicitNamingFilterEmptyFormData(),
|
|
1154
|
+
...getExpertFilterEmptyFormData()
|
|
1155
|
+
};
|
|
1156
|
+
const formSchema$3 = yup.object().shape({
|
|
1157
|
+
[FieldConstants.NAME]: yup.string().trim().required("nameEmpty"),
|
|
1158
|
+
[FieldConstants.DESCRIPTION]: yup.string().max(500, "descriptionLimitError"),
|
|
1159
|
+
[FieldConstants.FILTER_TYPE]: yup.string().required(),
|
|
1160
|
+
[FieldConstants.EQUIPMENT_TYPE]: yup.string().required(),
|
|
1161
|
+
...criteriaBasedFilterSchema,
|
|
1162
|
+
...explicitNamingFilterSchema,
|
|
1163
|
+
...expertFilterSchema
|
|
1164
|
+
}).required();
|
|
1165
|
+
const FilterCreationDialog = ({
|
|
1166
|
+
open,
|
|
1167
|
+
onClose,
|
|
1168
|
+
activeDirectory,
|
|
1169
|
+
createFilter,
|
|
1170
|
+
saveFilter,
|
|
1171
|
+
fetchAppsAndUrls,
|
|
1172
|
+
elementExists,
|
|
1173
|
+
language,
|
|
1174
|
+
fetchDirectoryContent,
|
|
1175
|
+
fetchRootFolders,
|
|
1176
|
+
fetchElementsInfos
|
|
1177
|
+
}) => {
|
|
1178
|
+
var _a;
|
|
1179
|
+
const { snackError } = useSnackMessage();
|
|
1180
|
+
const formMethods = {
|
|
1181
|
+
...useForm({
|
|
1182
|
+
defaultValues: emptyFormData,
|
|
1183
|
+
resolver: yupResolver(formSchema$3)
|
|
1184
|
+
}),
|
|
1185
|
+
language
|
|
1186
|
+
};
|
|
1187
|
+
const {
|
|
1188
|
+
formState: { errors }
|
|
1189
|
+
} = formMethods;
|
|
1190
|
+
const nameError = errors[FieldConstants.NAME];
|
|
1191
|
+
const isValidating = (_a = errors.root) == null ? void 0 : _a.isValidating;
|
|
1192
|
+
const onSubmit = useCallback(
|
|
1193
|
+
(filterForm) => {
|
|
1194
|
+
if (filterForm[FieldConstants.FILTER_TYPE] === FilterType.EXPLICIT_NAMING.id) {
|
|
1195
|
+
saveExplicitNamingFilter(
|
|
1196
|
+
filterForm[FILTER_EQUIPMENTS_ATTRIBUTES],
|
|
1197
|
+
true,
|
|
1198
|
+
filterForm[FieldConstants.EQUIPMENT_TYPE],
|
|
1199
|
+
filterForm[FieldConstants.NAME],
|
|
1200
|
+
filterForm[FieldConstants.DESCRIPTION],
|
|
1201
|
+
null,
|
|
1202
|
+
(error) => {
|
|
1203
|
+
snackError({
|
|
1204
|
+
messageTxt: error
|
|
1205
|
+
});
|
|
1206
|
+
},
|
|
1207
|
+
onClose,
|
|
1208
|
+
createFilter,
|
|
1209
|
+
saveFilter,
|
|
1210
|
+
activeDirectory
|
|
1211
|
+
);
|
|
1212
|
+
} else if (filterForm[FieldConstants.FILTER_TYPE] === FilterType.CRITERIA_BASED.id) {
|
|
1213
|
+
saveCriteriaBasedFilter(
|
|
1214
|
+
filterForm,
|
|
1215
|
+
activeDirectory,
|
|
1216
|
+
onClose,
|
|
1217
|
+
(error) => {
|
|
1218
|
+
snackError({
|
|
1219
|
+
messageTxt: error
|
|
1220
|
+
});
|
|
1221
|
+
},
|
|
1222
|
+
createFilter
|
|
1223
|
+
);
|
|
1224
|
+
} else if (filterForm[FieldConstants.FILTER_TYPE] === FilterType.EXPERT.id) {
|
|
1225
|
+
saveExpertFilter(
|
|
1226
|
+
null,
|
|
1227
|
+
filterForm[EXPERT_FILTER_QUERY],
|
|
1228
|
+
filterForm[FieldConstants.EQUIPMENT_TYPE],
|
|
1229
|
+
filterForm[FieldConstants.NAME],
|
|
1230
|
+
filterForm[FieldConstants.DESCRIPTION],
|
|
1231
|
+
true,
|
|
1232
|
+
activeDirectory,
|
|
1233
|
+
onClose,
|
|
1234
|
+
(error) => {
|
|
1235
|
+
snackError({
|
|
1236
|
+
messageTxt: error
|
|
1237
|
+
});
|
|
1238
|
+
},
|
|
1239
|
+
createFilter,
|
|
1240
|
+
saveFilter
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
},
|
|
1244
|
+
[activeDirectory, snackError, onClose, createFilter, saveFilter]
|
|
1245
|
+
);
|
|
1246
|
+
return /* @__PURE__ */ jsx(
|
|
1247
|
+
CustomMuiDialog,
|
|
1248
|
+
{
|
|
1249
|
+
open,
|
|
1250
|
+
onClose,
|
|
1251
|
+
onSave: onSubmit,
|
|
1252
|
+
formSchema: formSchema$3,
|
|
1253
|
+
formMethods,
|
|
1254
|
+
titleId: "createNewFilter",
|
|
1255
|
+
removeOptional: true,
|
|
1256
|
+
disabledSave: !!nameError || !!isValidating,
|
|
1257
|
+
children: /* @__PURE__ */ jsx(
|
|
1258
|
+
FilterContext.Provider,
|
|
1259
|
+
{
|
|
1260
|
+
value: {
|
|
1261
|
+
fetchDirectoryContent,
|
|
1262
|
+
fetchRootFolders,
|
|
1263
|
+
fetchElementsInfos,
|
|
1264
|
+
fetchAppsAndUrls
|
|
1265
|
+
},
|
|
1266
|
+
children: /* @__PURE__ */ jsx(
|
|
1267
|
+
FilterForm,
|
|
1268
|
+
{
|
|
1269
|
+
creation: true,
|
|
1270
|
+
activeDirectory,
|
|
1271
|
+
elementExists
|
|
1272
|
+
}
|
|
1273
|
+
)
|
|
1274
|
+
}
|
|
1275
|
+
)
|
|
1276
|
+
}
|
|
1277
|
+
);
|
|
1278
|
+
};
|
|
1279
|
+
const formSchema$2 = yup.object().shape({
|
|
1280
|
+
[FieldConstants.NAME]: yup.string().trim().required("nameEmpty"),
|
|
1281
|
+
[FieldConstants.FILTER_TYPE]: yup.string().required(),
|
|
1282
|
+
[FieldConstants.EQUIPMENT_TYPE]: yup.string().required(),
|
|
1283
|
+
...expertFilterSchema
|
|
1284
|
+
}).required();
|
|
1285
|
+
const ExpertFilterEditionDialog = ({
|
|
1286
|
+
id,
|
|
1287
|
+
name,
|
|
1288
|
+
titleId,
|
|
1289
|
+
open,
|
|
1290
|
+
onClose,
|
|
1291
|
+
broadcastChannel,
|
|
1292
|
+
selectionForCopy,
|
|
1293
|
+
getFilterById,
|
|
1294
|
+
setSelectionForCopy,
|
|
1295
|
+
createFilter,
|
|
1296
|
+
saveFilter,
|
|
1297
|
+
activeDirectory,
|
|
1298
|
+
elementExists,
|
|
1299
|
+
language,
|
|
1300
|
+
fetchDirectoryContent,
|
|
1301
|
+
fetchRootFolders,
|
|
1302
|
+
fetchElementsInfos
|
|
1303
|
+
}) => {
|
|
1304
|
+
var _a;
|
|
1305
|
+
const { snackError } = useSnackMessage();
|
|
1306
|
+
const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE);
|
|
1307
|
+
const formMethods = {
|
|
1308
|
+
...useForm({
|
|
1309
|
+
resolver: yupResolver(formSchema$2)
|
|
1310
|
+
}),
|
|
1311
|
+
language
|
|
1312
|
+
};
|
|
1313
|
+
const {
|
|
1314
|
+
reset,
|
|
1315
|
+
formState: { errors }
|
|
1316
|
+
} = formMethods;
|
|
1317
|
+
const nameError = errors[FieldConstants.NAME];
|
|
1318
|
+
const isValidating = (_a = errors.root) == null ? void 0 : _a.isValidating;
|
|
1319
|
+
useEffect(() => {
|
|
1320
|
+
if (id && open) {
|
|
1321
|
+
setDataFetchStatus(FetchStatus.FETCHING);
|
|
1322
|
+
getFilterById(id).then((response) => {
|
|
1323
|
+
setDataFetchStatus(FetchStatus.FETCH_SUCCESS);
|
|
1324
|
+
reset({
|
|
1325
|
+
[FieldConstants.NAME]: name,
|
|
1326
|
+
[FieldConstants.FILTER_TYPE]: FilterType.EXPERT.id,
|
|
1327
|
+
[FieldConstants.EQUIPMENT_TYPE]: response[FieldConstants.EQUIPMENT_TYPE],
|
|
1328
|
+
[EXPERT_FILTER_QUERY]: importExpertRules(
|
|
1329
|
+
response[EXPERT_FILTER_QUERY]
|
|
1330
|
+
)
|
|
1331
|
+
});
|
|
1332
|
+
}).catch((error) => {
|
|
1333
|
+
setDataFetchStatus(FetchStatus.FETCH_ERROR);
|
|
1334
|
+
snackError({
|
|
1335
|
+
messageTxt: error.message,
|
|
1336
|
+
headerId: "cannotRetrieveFilter"
|
|
1337
|
+
});
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
}, [id, name, open, reset, snackError, getFilterById]);
|
|
1341
|
+
const onSubmit = useCallback(
|
|
1342
|
+
(filterForm) => {
|
|
1343
|
+
saveExpertFilter(
|
|
1344
|
+
id,
|
|
1345
|
+
filterForm[EXPERT_FILTER_QUERY],
|
|
1346
|
+
filterForm[FieldConstants.EQUIPMENT_TYPE],
|
|
1347
|
+
filterForm[FieldConstants.NAME],
|
|
1348
|
+
"",
|
|
1349
|
+
// The description can not be edited from this dialog
|
|
1350
|
+
false,
|
|
1351
|
+
null,
|
|
1352
|
+
onClose,
|
|
1353
|
+
(error) => {
|
|
1354
|
+
snackError({
|
|
1355
|
+
messageTxt: error
|
|
1356
|
+
});
|
|
1357
|
+
},
|
|
1358
|
+
createFilter,
|
|
1359
|
+
saveFilter
|
|
1360
|
+
);
|
|
1361
|
+
if (selectionForCopy.sourceItemUuid === id) {
|
|
1362
|
+
setSelectionForCopy(noSelectionForCopy$1);
|
|
1363
|
+
broadcastChannel.postMessage({
|
|
1364
|
+
noSelectionForCopy: noSelectionForCopy$1
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
},
|
|
1368
|
+
[
|
|
1369
|
+
broadcastChannel,
|
|
1370
|
+
id,
|
|
1371
|
+
onClose,
|
|
1372
|
+
selectionForCopy.sourceItemUuid,
|
|
1373
|
+
snackError,
|
|
1374
|
+
setSelectionForCopy,
|
|
1375
|
+
saveFilter,
|
|
1376
|
+
createFilter
|
|
1377
|
+
]
|
|
1378
|
+
);
|
|
1379
|
+
const isDataReady = dataFetchStatus === FetchStatus.FETCH_SUCCESS;
|
|
1380
|
+
return /* @__PURE__ */ jsx(
|
|
1381
|
+
CustomMuiDialog,
|
|
1382
|
+
{
|
|
1383
|
+
open,
|
|
1384
|
+
onClose,
|
|
1385
|
+
onSave: onSubmit,
|
|
1386
|
+
formSchema: formSchema$2,
|
|
1387
|
+
formMethods,
|
|
1388
|
+
titleId,
|
|
1389
|
+
removeOptional: true,
|
|
1390
|
+
disabledSave: !!nameError || !!isValidating,
|
|
1391
|
+
isDataFetching: dataFetchStatus === FetchStatus.FETCHING,
|
|
1392
|
+
children: /* @__PURE__ */ jsx(
|
|
1393
|
+
FilterContext.Provider,
|
|
1394
|
+
{
|
|
1395
|
+
value: {
|
|
1396
|
+
fetchDirectoryContent,
|
|
1397
|
+
fetchRootFolders,
|
|
1398
|
+
fetchElementsInfos
|
|
1399
|
+
},
|
|
1400
|
+
children: isDataReady && /* @__PURE__ */ jsx(
|
|
1401
|
+
FilterForm,
|
|
1402
|
+
{
|
|
1403
|
+
activeDirectory,
|
|
1404
|
+
elementExists
|
|
1405
|
+
}
|
|
1406
|
+
)
|
|
1407
|
+
}
|
|
1408
|
+
)
|
|
1409
|
+
}
|
|
1410
|
+
);
|
|
1411
|
+
};
|
|
1412
|
+
const formSchema$1 = yup.object().shape({
|
|
1413
|
+
[FieldConstants.NAME]: yup.string().trim().required("nameEmpty"),
|
|
1414
|
+
[FieldConstants.FILTER_TYPE]: yup.string().required(),
|
|
1415
|
+
[FieldConstants.EQUIPMENT_TYPE]: yup.string().required(),
|
|
1416
|
+
...explicitNamingFilterSchema
|
|
1417
|
+
}).required();
|
|
1418
|
+
const ExplicitNamingFilterEditionDialog = ({
|
|
1419
|
+
id,
|
|
1420
|
+
name,
|
|
1421
|
+
titleId,
|
|
1422
|
+
open,
|
|
1423
|
+
onClose,
|
|
1424
|
+
broadcastChannel,
|
|
1425
|
+
selectionForCopy,
|
|
1426
|
+
setSelectionForCopy,
|
|
1427
|
+
getFilterById,
|
|
1428
|
+
createFilter,
|
|
1429
|
+
saveFilter,
|
|
1430
|
+
activeDirectory,
|
|
1431
|
+
elementExists,
|
|
1432
|
+
language
|
|
1433
|
+
}) => {
|
|
1434
|
+
var _a;
|
|
1435
|
+
const { snackError } = useSnackMessage();
|
|
1436
|
+
const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE);
|
|
1437
|
+
const formMethods = {
|
|
1438
|
+
...useForm({
|
|
1439
|
+
resolver: yupResolver(formSchema$1)
|
|
1440
|
+
}),
|
|
1441
|
+
language
|
|
1442
|
+
};
|
|
1443
|
+
const {
|
|
1444
|
+
reset,
|
|
1445
|
+
formState: { errors }
|
|
1446
|
+
} = formMethods;
|
|
1447
|
+
const nameError = errors[FieldConstants.NAME];
|
|
1448
|
+
const isValidating = (_a = errors.root) == null ? void 0 : _a.isValidating;
|
|
1449
|
+
useEffect(() => {
|
|
1450
|
+
if (id && open) {
|
|
1451
|
+
setDataFetchStatus(FetchStatus.FETCHING);
|
|
1452
|
+
getFilterById(id).then((response) => {
|
|
1453
|
+
setDataFetchStatus(FetchStatus.FETCH_SUCCESS);
|
|
1454
|
+
reset({
|
|
1455
|
+
[FieldConstants.NAME]: name,
|
|
1456
|
+
[FieldConstants.FILTER_TYPE]: FilterType.EXPLICIT_NAMING.id,
|
|
1457
|
+
[FieldConstants.EQUIPMENT_TYPE]: response[FieldConstants.EQUIPMENT_TYPE],
|
|
1458
|
+
[FILTER_EQUIPMENTS_ATTRIBUTES]: response[FILTER_EQUIPMENTS_ATTRIBUTES].map((row) => ({
|
|
1459
|
+
[FieldConstants.AG_GRID_ROW_UUID]: v4(),
|
|
1460
|
+
...row
|
|
1461
|
+
}))
|
|
1462
|
+
});
|
|
1463
|
+
}).catch((error) => {
|
|
1464
|
+
setDataFetchStatus(FetchStatus.FETCH_ERROR);
|
|
1465
|
+
snackError({
|
|
1466
|
+
messageTxt: error.message,
|
|
1467
|
+
headerId: "cannotRetrieveFilter"
|
|
1468
|
+
});
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
}, [id, name, open, reset, snackError, getFilterById]);
|
|
1472
|
+
const onSubmit = useCallback(
|
|
1473
|
+
(filterForm) => {
|
|
1474
|
+
saveExplicitNamingFilter(
|
|
1475
|
+
filterForm[FILTER_EQUIPMENTS_ATTRIBUTES],
|
|
1476
|
+
false,
|
|
1477
|
+
filterForm[FieldConstants.EQUIPMENT_TYPE],
|
|
1478
|
+
filterForm[FieldConstants.NAME],
|
|
1479
|
+
"",
|
|
1480
|
+
// The description can not be edited from this dialog
|
|
1481
|
+
id,
|
|
1482
|
+
(error) => {
|
|
1483
|
+
snackError({
|
|
1484
|
+
messageTxt: error
|
|
1485
|
+
});
|
|
1486
|
+
},
|
|
1487
|
+
onClose,
|
|
1488
|
+
createFilter,
|
|
1489
|
+
saveFilter
|
|
1490
|
+
);
|
|
1491
|
+
if (selectionForCopy.sourceItemUuid === id) {
|
|
1492
|
+
setSelectionForCopy(noSelectionForCopy$1);
|
|
1493
|
+
broadcastChannel.postMessage({
|
|
1494
|
+
noSelectionForCopy: noSelectionForCopy$1
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
},
|
|
1498
|
+
[
|
|
1499
|
+
broadcastChannel,
|
|
1500
|
+
id,
|
|
1501
|
+
selectionForCopy,
|
|
1502
|
+
onClose,
|
|
1503
|
+
snackError,
|
|
1504
|
+
createFilter,
|
|
1505
|
+
saveFilter,
|
|
1506
|
+
setSelectionForCopy
|
|
1507
|
+
]
|
|
1508
|
+
);
|
|
1509
|
+
const isDataReady = dataFetchStatus === FetchStatus.FETCH_SUCCESS;
|
|
1510
|
+
return /* @__PURE__ */ jsx(
|
|
1511
|
+
CustomMuiDialog,
|
|
1512
|
+
{
|
|
1513
|
+
open,
|
|
1514
|
+
onClose,
|
|
1515
|
+
onSave: onSubmit,
|
|
1516
|
+
formSchema: formSchema$1,
|
|
1517
|
+
formMethods,
|
|
1518
|
+
titleId,
|
|
1519
|
+
removeOptional: true,
|
|
1520
|
+
disabledSave: !!nameError || !!isValidating,
|
|
1521
|
+
isDataFetching: dataFetchStatus === FetchStatus.FETCHING,
|
|
1522
|
+
children: isDataReady && /* @__PURE__ */ jsx(
|
|
1523
|
+
FilterForm,
|
|
1524
|
+
{
|
|
1525
|
+
activeDirectory,
|
|
1526
|
+
elementExists
|
|
1527
|
+
}
|
|
1528
|
+
)
|
|
1529
|
+
}
|
|
1530
|
+
);
|
|
1531
|
+
};
|
|
1532
|
+
ExplicitNamingFilterEditionDialog.prototype = {
|
|
1533
|
+
id: PropTypes.string,
|
|
1534
|
+
name: PropTypes.string,
|
|
1535
|
+
titleId: PropTypes.string.isRequired,
|
|
1536
|
+
open: PropTypes.bool,
|
|
1537
|
+
onClose: PropTypes.func.isRequired
|
|
1538
|
+
};
|
|
1539
|
+
const noSelectionForCopy = {
|
|
1540
|
+
sourceItemUuid: null,
|
|
1541
|
+
name: null,
|
|
1542
|
+
description: null,
|
|
1543
|
+
parentDirectoryUuid: null
|
|
1544
|
+
};
|
|
1545
|
+
const formSchema = yup.object().shape({
|
|
1546
|
+
[FieldConstants.NAME]: yup.string().trim().required("nameEmpty"),
|
|
1547
|
+
[FieldConstants.FILTER_TYPE]: yup.string().required(),
|
|
1548
|
+
[FieldConstants.EQUIPMENT_TYPE]: yup.string().required(),
|
|
1549
|
+
...criteriaBasedFilterSchema
|
|
1550
|
+
}).required();
|
|
1551
|
+
const CriteriaBasedFilterEditionDialog = ({
|
|
1552
|
+
id,
|
|
1553
|
+
name,
|
|
1554
|
+
titleId,
|
|
1555
|
+
open,
|
|
1556
|
+
onClose,
|
|
1557
|
+
broadcastChannel,
|
|
1558
|
+
getFilterById,
|
|
1559
|
+
saveFilter,
|
|
1560
|
+
selectionForCopy,
|
|
1561
|
+
setSelelectionForCopy,
|
|
1562
|
+
activeDirectory,
|
|
1563
|
+
elementExists,
|
|
1564
|
+
language
|
|
1565
|
+
}) => {
|
|
1566
|
+
var _a;
|
|
1567
|
+
const { snackError } = useSnackMessage();
|
|
1568
|
+
const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE);
|
|
1569
|
+
const formMethods = {
|
|
1570
|
+
...useForm({
|
|
1571
|
+
resolver: yupResolver(formSchema)
|
|
1572
|
+
}),
|
|
1573
|
+
language
|
|
1574
|
+
};
|
|
1575
|
+
const {
|
|
1576
|
+
reset,
|
|
1577
|
+
formState: { errors }
|
|
1578
|
+
} = formMethods;
|
|
1579
|
+
const nameError = errors[FieldConstants.NAME];
|
|
1580
|
+
const isValidating = (_a = errors.root) == null ? void 0 : _a.isValidating;
|
|
1581
|
+
useEffect(() => {
|
|
1582
|
+
if (id && open) {
|
|
1583
|
+
setDataFetchStatus(FetchStatus.FETCHING);
|
|
1584
|
+
getFilterById(id).then((response) => {
|
|
1585
|
+
setDataFetchStatus(FetchStatus.FETCH_SUCCESS);
|
|
1586
|
+
reset({
|
|
1587
|
+
[FieldConstants.NAME]: name,
|
|
1588
|
+
[FieldConstants.FILTER_TYPE]: FilterType.CRITERIA_BASED.id,
|
|
1589
|
+
...backToFrontTweak(response)
|
|
1590
|
+
});
|
|
1591
|
+
}).catch((error) => {
|
|
1592
|
+
setDataFetchStatus(FetchStatus.FETCH_ERROR);
|
|
1593
|
+
snackError({
|
|
1594
|
+
messageTxt: error.message,
|
|
1595
|
+
headerId: "cannotRetrieveFilter"
|
|
1596
|
+
});
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
}, [id, name, open, reset, snackError, getFilterById]);
|
|
1600
|
+
const onSubmit = useCallback(
|
|
1601
|
+
(filterForm) => {
|
|
1602
|
+
saveFilter(
|
|
1603
|
+
frontToBackTweak(id, filterForm),
|
|
1604
|
+
filterForm[FieldConstants.NAME]
|
|
1605
|
+
).then(() => {
|
|
1606
|
+
if (selectionForCopy.sourceItemUuid === id) {
|
|
1607
|
+
setSelelectionForCopy(noSelectionForCopy);
|
|
1608
|
+
broadcastChannel.postMessage({
|
|
1609
|
+
noSelectionForCopy
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1612
|
+
}).catch((error) => {
|
|
1613
|
+
snackError({
|
|
1614
|
+
messageTxt: error.message
|
|
1615
|
+
});
|
|
1616
|
+
});
|
|
1617
|
+
},
|
|
1618
|
+
[
|
|
1619
|
+
broadcastChannel,
|
|
1620
|
+
id,
|
|
1621
|
+
selectionForCopy.sourceItemUuid,
|
|
1622
|
+
snackError,
|
|
1623
|
+
saveFilter,
|
|
1624
|
+
setSelelectionForCopy
|
|
1625
|
+
]
|
|
1626
|
+
);
|
|
1627
|
+
const isDataReady = dataFetchStatus === FetchStatus.FETCH_SUCCESS;
|
|
1628
|
+
return /* @__PURE__ */ jsx(
|
|
1629
|
+
CustomMuiDialog,
|
|
1630
|
+
{
|
|
1631
|
+
open,
|
|
1632
|
+
onClose,
|
|
1633
|
+
onSave: onSubmit,
|
|
1634
|
+
formSchema,
|
|
1635
|
+
formMethods,
|
|
1636
|
+
titleId,
|
|
1637
|
+
removeOptional: true,
|
|
1638
|
+
disabledSave: !!nameError || !!isValidating,
|
|
1639
|
+
isDataFetching: dataFetchStatus === FetchStatus.FETCHING,
|
|
1640
|
+
children: isDataReady && /* @__PURE__ */ jsx(
|
|
1641
|
+
FilterForm,
|
|
1642
|
+
{
|
|
1643
|
+
activeDirectory,
|
|
1644
|
+
elementExists
|
|
1645
|
+
}
|
|
1646
|
+
)
|
|
1647
|
+
}
|
|
1648
|
+
);
|
|
1649
|
+
};
|
|
1650
|
+
export {
|
|
1651
|
+
BottomRightButtons as B,
|
|
1652
|
+
CustomAgGridTable as C,
|
|
1653
|
+
ExpertFilterEditionDialog as E,
|
|
1654
|
+
FilterCreationDialog as F,
|
|
1655
|
+
ROW_DRAGGING_SELECTION_COLUMN_DEF as R,
|
|
1656
|
+
ValueEditor as V,
|
|
1657
|
+
ExplicitNamingFilterEditionDialog as a,
|
|
1658
|
+
CriteriaBasedFilterEditionDialog as b,
|
|
1659
|
+
CsvUploader as c,
|
|
1660
|
+
FILTER_EQUIPMENTS_ATTRIBUTES as d,
|
|
1661
|
+
explicitNamingFilterSchema as e,
|
|
1662
|
+
ExplicitNamingFilterForm as f,
|
|
1663
|
+
getExplicitNamingFilterEmptyFormData as g,
|
|
1664
|
+
RemoveButton as h,
|
|
1665
|
+
ElementValueEditor as i,
|
|
1666
|
+
CustomReactQueryBuilder as j,
|
|
1667
|
+
EXPERT_FILTER_QUERY as k,
|
|
1668
|
+
expertFilterSchema as l,
|
|
1669
|
+
getExpertFilterEmptyFormData as m,
|
|
1670
|
+
ExpertFilterForm as n,
|
|
1671
|
+
FilterForm as o,
|
|
1672
|
+
noSelectionForCopy as p
|
|
1673
|
+
};
|