@m4l/components 0.1.52 → 0.1.53
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/components/CommonActions/components/ActionFormCancel/{index.bd0d16d6.js → index.8dedf1d5.js} +15 -15
- package/components/CommonActions/components/ActionIntro/{index.d567aebb.js → index.5d5294f2.js} +5 -0
- package/components/CommonActions/components/ActionIntro/test/contants.d.ts +1 -0
- package/components/CommonActions/components/Actions/{index.f0a3167b.js → index.93c9823a.js} +14 -14
- package/components/DataGrid/{index.85390177.js → index.1a6508e2.js} +20 -20
- package/components/DynamicFilter/DynamicFilter.d.ts +9 -0
- package/components/DynamicFilter/classes/index.d.ts +5 -0
- package/components/DynamicFilter/classes/types.d.ts +22 -0
- package/components/DynamicFilter/constants.d.ts +14 -0
- package/components/DynamicFilter/contexts/DynamicFilterContext/helpers.d.ts +24 -0
- package/components/DynamicFilter/contexts/DynamicFilterContext/index.d.ts +18 -0
- package/components/DynamicFilter/contexts/DynamicFilterContext/store.d.ts +213 -0
- package/components/DynamicFilter/contexts/DynamicFilterContext/types.d.ts +5 -0
- package/components/DynamicFilter/dictionary.d.ts +21 -0
- package/components/DynamicFilter/hooks/useDynamicFilter.d.ts +2 -0
- package/components/DynamicFilter/index.2189989e.js +1808 -0
- package/components/DynamicFilter/index.d.ts +4 -6
- package/components/DynamicFilter/subcomponents/ApplyedFilters/subcomponents/ApplyedFilter/index.d.ts +3 -0
- package/components/DynamicFilter/subcomponents/ClearFilters/index.d.ts +1 -1
- package/components/DynamicFilter/subcomponents/FilterButton/index.d.ts +10 -0
- package/components/DynamicFilter/subcomponents/InnerForHooks/index.d.ts +6 -0
- package/components/DynamicFilter/subcomponents/InputFilter/index.d.ts +7 -1
- package/components/DynamicFilter/subcomponents/PopoverFilter/index.d.ts +15 -0
- package/components/DynamicFilter/subcomponents/PopoverMenuFields/index.d.ts +12 -0
- package/components/DynamicFilter/subcomponents/PopoverMenuFields/types.d.ts +6 -0
- package/components/DynamicFilter/subcomponents/fieldstypes/BooleanFilter/helpers.d.ts +39 -0
- package/components/DynamicFilter/subcomponents/fieldstypes/BooleanFilter/index.d.ts +4 -2
- package/components/DynamicFilter/subcomponents/fieldstypes/DateTimeFilter/helpers.d.ts +42 -0
- package/components/DynamicFilter/subcomponents/fieldstypes/DateTimeFilter/index.d.ts +4 -3
- package/components/DynamicFilter/subcomponents/fieldstypes/NumberFilter/helpers.d.ts +36 -0
- package/components/DynamicFilter/subcomponents/fieldstypes/NumberFilter/index.d.ts +4 -2
- package/components/DynamicFilter/subcomponents/fieldstypes/StringFilter/helpers.d.ts +39 -0
- package/components/DynamicFilter/subcomponents/fieldstypes/StringFilter/index.d.ts +4 -2
- package/components/DynamicFilter/subcomponents/fieldstypes/factory.d.ts +72 -4
- package/components/DynamicFilter/subcomponents/fieldstypes/validations.d.ts +25 -6
- package/components/DynamicFilter/tests/contants.d.ts +6 -0
- package/components/DynamicFilter/tests/types.d.ts +2 -0
- package/components/DynamicFilter/tests/utils.d.ts +2 -0
- package/components/DynamicFilter/types.d.ts +173 -42
- package/components/ErrorLabel/{index.78553a1e.js → index.12994bff.js} +5 -5
- package/components/Icon/{index.f6e8d810.js → index.b29ff2d9.js} +1 -1
- package/components/LanguagePopover/{index.5047b444.js → index.628fe97f.js} +5 -5
- package/components/ModalDialog/{index.5a307e29.js → index.49c40899.js} +5 -5
- package/components/ObjectLogs/{index.1315af37.js → index.d7c0092a.js} +23 -23
- package/components/PaperForm/{index.0114aa9b.js → index.c04000a9.js} +1 -1
- package/components/Period/{index.85fe764a.js → index.4f6e419d.js} +15 -15
- package/components/Resizeable/{index.8a442a8b.js → index.04fa8de5.js} +1 -1
- package/components/ScrollBar/{index.39eeb2de.js → index.35ebe9a1.js} +8 -3
- package/components/areas/components/AreasAdmin/{index.dbab59f1.js → index.25e50e70.js} +6 -6
- package/components/areas/components/AreasContainer/{index.f3f921b9.js → index.432b9d4c.js} +3 -3
- package/components/areas/components/GridLayout/{index.9953146d.js → index.359e777e.js} +5 -5
- package/components/areas/components/Window/{index.e34225ae.js → index.2b9f12fe.js} +35 -36
- package/components/areas/components/WindowPopUp/{index.90eb0348.js → index.d5fa0d74.js} +36 -37
- package/components/areas/components/{index.6d863764.js → index.912056a0.js} +10 -10
- package/components/areas/contexts/AreaContext/{index.f25f7180.js → index.b1439daf.js} +1 -1
- package/components/areas/contexts/AreasContext/{index.7406c20f.js → index.fb21af84.js} +1 -1
- package/components/areas/contexts/{index.e80d8f0f.js → index.1e46147e.js} +1 -1
- package/components/areas/hooks/{index.0fd57f88.js → index.5feefc73.js} +1 -1
- package/components/areas/hooks/useArea/{index.7bdbbb79.js → index.6f45f930.js} +2 -2
- package/components/areas/index.3df8c6d4.js +21 -0
- package/components/formatters/BooleanFormatter/{index.b3fb8a75.js → index.a50933fb.js} +1 -1
- package/components/formatters/{index.90a19f9f.js → index.7d2ad9ca.js} +2 -1
- package/components/hook-form/RHFAutocomplete/{index.74add0d0.js → index.0ffa2185.js} +69 -59
- package/components/hook-form/RHFAutocomplete/test/contants.d.ts +1 -0
- package/components/hook-form/RHFAutocompleteAsync/{index.0aa3c224.js → index.2dfbe7aa.js} +1 -1
- package/components/hook-form/RHFCheckbox/{index.ca94a050.js → index.1fcf42c8.js} +1 -1
- package/components/hook-form/RHFDateTime/{index.7f1cbd85.js → index.6c129ce4.js} +14 -25
- package/components/hook-form/RHFPeriod/{index.5d2a2071.js → index.1f6aa4c6.js} +2 -2
- package/components/hook-form/RHFTextField/classes/index.d.ts +0 -1
- package/components/hook-form/RHFTextField/{index.bef7eced.js → index.a021a2b3.js} +21 -11
- package/components/hook-form/RHFTextField/tests/contants.d.ts +2 -0
- package/components/index.d.ts +1 -3
- package/components/modal/{WindowBase.b5e29758.js → WindowBase.66ef3c9a.js} +3 -3
- package/components/modal/{WindowConfirm.cbc7720c.js → WindowConfirm.b31ed329.js} +16 -16
- package/components/modal/index.6d5b19ef.js +29 -0
- package/components/mui_extended/Accordion/{index.1d513477.js → index.002bad72.js} +2 -2
- package/components/mui_extended/IconButton/{index.1318a283.js → index.460c0476.js} +1 -1
- package/components/mui_extended/MenuActions/{index.1261168c.js → index.aaafafc3.js} +1 -1
- package/components/mui_extended/Pager/{index.984aac44.js → index.458f9f0d.js} +1 -1
- package/components/mui_extended/{index.cb9d48d2.js → index.915e84dc.js} +5 -5
- package/contexts/ModalContext/{index.3d92d9f9.js → index.d1aaddbc.js} +1 -1
- package/contexts/RHFormContext/{index.828b60ad.js → index.3dc6e2f5.js} +1 -0
- package/hooks/useModal/{index.4454145e.js → index.f77ab08b.js} +1 -1
- package/index.js +196 -225
- package/package.json +2 -2
- package/{react-draggable.0eef011c.js → react-draggable.6471b07e.js} +1 -1
- package/{react-resizable.bb58c8fc.js → react-resizable.b620abed.js} +2 -2
- package/test/constants_no_mock.d.ts +1 -0
- package/utils/{index.e882b264.js → index.b6ae791a.js} +12 -3
- package/utils/index.d.ts +2 -0
- package/vendor.d5904857.js +145 -0
- package/components/DynamicFilter/contexts/BaseContext/index.d.ts +0 -5
- package/components/DynamicFilter/contexts/BaseContext/types.d.ts +0 -45
- package/components/DynamicFilter/hooks/useFilter.d.ts +0 -1
- package/components/DynamicFilter/index.cddd7472.js +0 -1756
- package/components/DynamicFilter/subcomponents/ApplyedFilters/components/ApplyedFilter/index.d.ts +0 -3
- package/components/DynamicFilter/subcomponents/PopupEditFilter/index.d.ts +0 -2
- package/components/DynamicFilter/utils/Clases/index.d.ts +0 -20
- package/components/DynamicFilter/utils/Clases/types.d.ts +0 -17
- package/components/areas/index.6f09d168.js +0 -21
- package/components/modal/index.f6de895f.js +0 -29
|
@@ -0,0 +1,1808 @@
|
|
|
1
|
+
import { shallow } from "zustand/shallow";
|
|
2
|
+
import { S as ScrollBar } from "../ScrollBar/index.35ebe9a1.js";
|
|
3
|
+
import { I as IconButton } from "../mui_extended/IconButton/index.460c0476.js";
|
|
4
|
+
import { useContext, useMemo, useEffect, createContext, useRef, createElement, useState, useCallback } from "react";
|
|
5
|
+
import { useModuleDictionary, useEnvironment, useModuleSkeleton, useFlagsPresent, CommonFlags } from "@m4l/core";
|
|
6
|
+
import { useResponsiveDesktop, useFirstRender, useFormatter } from "@m4l/graphics";
|
|
7
|
+
import clsx from "clsx";
|
|
8
|
+
import { T as TEST_PROP_ID } from "../../vendor.d5904857.js";
|
|
9
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
10
|
+
import { generateUtilityClasses, alpha, styled as styled$1, Skeleton, MenuItem } from "@mui/material";
|
|
11
|
+
import { L as LabelMemuItem } from "../mui_extended/MenuActions/index.aaafafc3.js";
|
|
12
|
+
import { P as Popover } from "../mui_extended/Popover/index.58c49cc0.js";
|
|
13
|
+
import { I as Icon } from "../Icon/index.b29ff2d9.js";
|
|
14
|
+
import { R as RHFormProvider } from "../../contexts/RHFormContext/index.3dc6e2f5.js";
|
|
15
|
+
import { g as getCommonActionsDictionary, A as Actions } from "../CommonActions/components/Actions/index.93c9823a.js";
|
|
16
|
+
import { A as ActionCancel } from "../CommonActions/components/ActionCancel/index.a81752ef.js";
|
|
17
|
+
import { A as ActionIntro } from "../CommonActions/components/ActionIntro/index.5d5294f2.js";
|
|
18
|
+
import { useFormContext, useWatch } from "react-hook-form";
|
|
19
|
+
import "@mui/material/Button";
|
|
20
|
+
import "../mui_extended/Button/index.8406ed5b.js";
|
|
21
|
+
import "../../contexts/ModalContext/index.d1aaddbc.js";
|
|
22
|
+
import "../../react-draggable.6471b07e.js";
|
|
23
|
+
import "../ModalDialog/index.49c40899.js";
|
|
24
|
+
import "../Resizeable/index.04fa8de5.js";
|
|
25
|
+
import "../modal/WindowConfirm.b31ed329.js";
|
|
26
|
+
import "../modal/WindowBase.66ef3c9a.js";
|
|
27
|
+
import "../areas/components/index.912056a0.js";
|
|
28
|
+
import "../areas/components/AreasAdmin/index.25e50e70.js";
|
|
29
|
+
import { useStore, createStore } from "zustand";
|
|
30
|
+
import "../areas/contexts/AreasContext/index.fb21af84.js";
|
|
31
|
+
import "../areas/components/AreasContainer/index.432b9d4c.js";
|
|
32
|
+
import "react-grid-layout/css/styles.css";
|
|
33
|
+
import "../../react-resizable.b620abed.js";
|
|
34
|
+
import "../areas/contexts/index.1e46147e.js";
|
|
35
|
+
import "../areas/contexts/DynamicMFParmsContext/index.c19cb8cc.js";
|
|
36
|
+
import "@mui/lab";
|
|
37
|
+
import "../mui_extended/Accordion/index.002bad72.js";
|
|
38
|
+
import "../mui_extended/Avatar/index.fe06afd7.js";
|
|
39
|
+
import "react-router-dom";
|
|
40
|
+
import "../Image/index.aa24e982.js";
|
|
41
|
+
import "../mui_extended/Pager/index.458f9f0d.js";
|
|
42
|
+
import "../mui_extended/Tab/index.e0653a0a.js";
|
|
43
|
+
import "../mui_extended/Typography/index.be3a279a.js";
|
|
44
|
+
import { unstable_composeClasses } from "@mui/base";
|
|
45
|
+
import { g as getComponentUtilityClass, i as isValidDate } from "../../utils/index.b6ae791a.js";
|
|
46
|
+
import { devtools } from "zustand/middleware";
|
|
47
|
+
import { immer } from "zustand/middleware/immer";
|
|
48
|
+
import { R as RHFAutocomplete } from "../hook-form/RHFAutocomplete/index.0ffa2185.js";
|
|
49
|
+
import "lodash/debounce";
|
|
50
|
+
import "../hook-form/RHFCheckbox/index.1fcf42c8.js";
|
|
51
|
+
import { styled, alpha as alpha$1 } from "@mui/material/styles";
|
|
52
|
+
import "../ErrorLabel/index.12994bff.js";
|
|
53
|
+
import "@mui/x-date-pickers";
|
|
54
|
+
import { R as RHFDateTime } from "../hook-form/RHFDateTime/index.6c129ce4.js";
|
|
55
|
+
import { R as RHFTextField } from "../hook-form/RHFTextField/index.a021a2b3.js";
|
|
56
|
+
import "../hook-form/RHFPeriod/index.1f6aa4c6.js";
|
|
57
|
+
import "../Period/index.4f6e419d.js";
|
|
58
|
+
import "lodash/isString";
|
|
59
|
+
import "react-dropzone";
|
|
60
|
+
import "../hook-form/RHFUpload/index.7fdff30f.js";
|
|
61
|
+
import * as Yup from "yup";
|
|
62
|
+
import "@hookform/resolvers/yup";
|
|
63
|
+
import { styled as styled$2 } from "@m4l/styles";
|
|
64
|
+
const COMPONENT_CLASS_NAME = "M4LDynamicFilter";
|
|
65
|
+
const ASSETS_URL = "/frontend/components/dynamic_filter/assets/icons/";
|
|
66
|
+
const ASSETS = {
|
|
67
|
+
refresh: "refresh.svg",
|
|
68
|
+
search: "search.svg"
|
|
69
|
+
};
|
|
70
|
+
const ALL_FIELDS = {
|
|
71
|
+
name: "all",
|
|
72
|
+
dictionaryId: "dynamic_filter.all_fields",
|
|
73
|
+
urlIcon: "",
|
|
74
|
+
type: "string",
|
|
75
|
+
multiple: true,
|
|
76
|
+
presence: "optional"
|
|
77
|
+
};
|
|
78
|
+
const STRING_OPERATORS = ["c", "nc"];
|
|
79
|
+
const NUMBER_OPERATORS = ["b", "e", "ne", "gt", "gte", "lt", "lte"];
|
|
80
|
+
const BOOLEAN_OPERATORS = ["e", "ne"];
|
|
81
|
+
const DATE_TIME_OPERATORS = [
|
|
82
|
+
"b",
|
|
83
|
+
"e",
|
|
84
|
+
"ne",
|
|
85
|
+
"gt",
|
|
86
|
+
"gte",
|
|
87
|
+
"lt",
|
|
88
|
+
"lte"
|
|
89
|
+
];
|
|
90
|
+
const dynamicFilterClasses = generateUtilityClasses(COMPONENT_CLASS_NAME, [
|
|
91
|
+
"root",
|
|
92
|
+
"containerFistRow",
|
|
93
|
+
"containerInputFilter",
|
|
94
|
+
"filterButton",
|
|
95
|
+
"wrapperApplyedFilters",
|
|
96
|
+
"containerApplyedFilters",
|
|
97
|
+
"applyedFilter",
|
|
98
|
+
"popUpMenuFields",
|
|
99
|
+
"popoverMenuFieldsItem",
|
|
100
|
+
"popoverFilterPaper",
|
|
101
|
+
"popoverFilterHeader",
|
|
102
|
+
"containerBooleanFilter",
|
|
103
|
+
"containerDateTimeFilter",
|
|
104
|
+
"containerNumberFilter",
|
|
105
|
+
"containerStringFilter",
|
|
106
|
+
"isMobile",
|
|
107
|
+
"inEdition",
|
|
108
|
+
"isDirty",
|
|
109
|
+
"isValid"
|
|
110
|
+
]);
|
|
111
|
+
const useUtilityClasses = (ownerState) => {
|
|
112
|
+
const slots = {
|
|
113
|
+
root: ["root", ownerState.inEdition && "inEdition", ownerState.isDirty && "isDirty", ownerState.isValid && "isValid", ownerState.isMobile && "isMobile"],
|
|
114
|
+
filterButton: ["filterButton", ownerState.isValid && "isValid", ownerState.isDirty && "isDirty"],
|
|
115
|
+
containerFistRow: ["containerFistRow"],
|
|
116
|
+
containerInputFilter: ["containerInputFilter"],
|
|
117
|
+
wrapperApplyedFilters: ["wrapperApplyedFilters"],
|
|
118
|
+
containerApplyedFilters: ["containerApplyedFilters"],
|
|
119
|
+
applyedFilter: ["applyedFilter"],
|
|
120
|
+
popUpMenuFields: ["popUpMenuFields"],
|
|
121
|
+
popoverMenuFieldsItem: ["popoverMenuFieldsItem"],
|
|
122
|
+
popoverFilterPaper: ["popoverFilterPaper"],
|
|
123
|
+
popoverFilterHeader: ["popoverFilterHeader"],
|
|
124
|
+
clearFilters: ["clearFilters"],
|
|
125
|
+
containerBooleanFilter: ["containerBooleanFilter"],
|
|
126
|
+
containerDateTimeFilter: ["containerDateTimeFilter"],
|
|
127
|
+
containerNumberFilter: ["containerNumberFilter"],
|
|
128
|
+
containerStringFilter: ["containerStringFilter"]
|
|
129
|
+
};
|
|
130
|
+
return unstable_composeClasses(slots, getComponentUtilityClass(COMPONENT_CLASS_NAME), {});
|
|
131
|
+
};
|
|
132
|
+
const ContainerBooleanFilter = styled("div")(({
|
|
133
|
+
theme
|
|
134
|
+
}) => ({
|
|
135
|
+
display: "flex",
|
|
136
|
+
flexDirection: "column",
|
|
137
|
+
justifyContent: "center",
|
|
138
|
+
alignItems: "center",
|
|
139
|
+
width: "100%",
|
|
140
|
+
minWidth: theme.spacing(3.75),
|
|
141
|
+
height: "100%",
|
|
142
|
+
padding: theme.spacing(3, 0),
|
|
143
|
+
gap: theme.spacing(3)
|
|
144
|
+
}));
|
|
145
|
+
function useDynamicFilter(selector, equalityFn) {
|
|
146
|
+
const store = useContext(DynamicFilterContext);
|
|
147
|
+
if (!store)
|
|
148
|
+
throw new Error("useDynamicFilterStore context must be use inside DynamicFilterContext");
|
|
149
|
+
return useStore(store, selector, equalityFn);
|
|
150
|
+
}
|
|
151
|
+
const DYNAMICFILTER_TEST_ID = "m4ldynamicfilter";
|
|
152
|
+
const PREFIX_TEST_ATTRIBUTE = "data-test";
|
|
153
|
+
const TEST_PROP_FIELDS = `${PREFIX_TEST_ATTRIBUTE}-${DYNAMICFILTER_TEST_ID}-fields`;
|
|
154
|
+
function getTestIdByClass(key, detailId) {
|
|
155
|
+
return `${DYNAMICFILTER_TEST_ID}-${key}` + (detailId ? "-" + detailId : "");
|
|
156
|
+
}
|
|
157
|
+
const DYNAMICFILTER_DICTIONARY_ID = "dynamic_filter";
|
|
158
|
+
function getDynamicFilterComponentsDictionary() {
|
|
159
|
+
return [DYNAMICFILTER_DICTIONARY_ID].concat(getCommonActionsDictionary());
|
|
160
|
+
}
|
|
161
|
+
const defaultDynamicFilterDictionary = {
|
|
162
|
+
dynamic_filter: {
|
|
163
|
+
filter_tooltip: "Search",
|
|
164
|
+
operator_b: "between",
|
|
165
|
+
operator_e: "=",
|
|
166
|
+
operator_ne: "!=",
|
|
167
|
+
operator_gt: ">",
|
|
168
|
+
operator_gte: ">=",
|
|
169
|
+
operator_lt: "<",
|
|
170
|
+
operator_lte: "<=",
|
|
171
|
+
operator_c: "contains",
|
|
172
|
+
operator_nc: "not contains",
|
|
173
|
+
all_fields: "all_fields",
|
|
174
|
+
operand_true: "true",
|
|
175
|
+
operand_false: "false",
|
|
176
|
+
error_operator_required: "Operator required",
|
|
177
|
+
error_operand_required: "Operand required",
|
|
178
|
+
error_invalid_date: "Invalid date",
|
|
179
|
+
error_operand_mustbe_number: "Invalid number",
|
|
180
|
+
error_filters_no_setted: "Filters not yet set"
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const LABEL_FILTER_BUTTON = "filter_tooltip";
|
|
184
|
+
const DICCTIONARY = {
|
|
185
|
+
input_placeholder: "input_placeholder",
|
|
186
|
+
operand_true: "true",
|
|
187
|
+
operand_false: "false",
|
|
188
|
+
filter_tooltip_refresh: "filter_tooltip_refresh",
|
|
189
|
+
filter_tooltip_dirty: "filter_tooltip_dirty",
|
|
190
|
+
filter_tooltip_invalid: "filter_tooltip_invalid",
|
|
191
|
+
operator_b: "operator_b",
|
|
192
|
+
operator_e: "operator_e",
|
|
193
|
+
operator_ne: "operator_ne",
|
|
194
|
+
operator_gt: "operator_gt",
|
|
195
|
+
operator_gte: "operator_gte",
|
|
196
|
+
operator_lt: "operator_lt",
|
|
197
|
+
operator_lte: "operator_lte",
|
|
198
|
+
operator_c: "operator_c",
|
|
199
|
+
operator_nc: "operator_nc"
|
|
200
|
+
};
|
|
201
|
+
const getDynamicFilterDictionary = (key) => {
|
|
202
|
+
return `${DYNAMICFILTER_DICTIONARY_ID}.${key}`;
|
|
203
|
+
};
|
|
204
|
+
function BooleanFilter() {
|
|
205
|
+
const classesContainerBooleanFilter = useDynamicFilter((state) => state.classes.containerBooleanFilter);
|
|
206
|
+
const {
|
|
207
|
+
getLabel
|
|
208
|
+
} = useModuleDictionary();
|
|
209
|
+
const operators = useMemo(() => BOOLEAN_OPERATORS.map((o) => ({
|
|
210
|
+
id: o,
|
|
211
|
+
label: getLabel(getDynamicFilterDictionary(`operator_${o}`))
|
|
212
|
+
})), [getLabel]);
|
|
213
|
+
const optionsYesNo = useMemo(() => [{
|
|
214
|
+
value: true,
|
|
215
|
+
label: getLabel(getDynamicFilterDictionary(`operand_true`))
|
|
216
|
+
}, {
|
|
217
|
+
value: false,
|
|
218
|
+
label: getLabel(getDynamicFilterDictionary(`operand_false`))
|
|
219
|
+
}], [getLabel]);
|
|
220
|
+
return /* @__PURE__ */ jsxs(ContainerBooleanFilter, {
|
|
221
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
222
|
+
[TEST_PROP_ID]: getTestIdByClass("containerBooleanFilter")
|
|
223
|
+
} : {},
|
|
224
|
+
className: classesContainerBooleanFilter,
|
|
225
|
+
children: [/* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
226
|
+
name: "formValueOperator",
|
|
227
|
+
autoComplete: "off",
|
|
228
|
+
options: operators,
|
|
229
|
+
getOptionLabel: (option) => option.label,
|
|
230
|
+
isOptionEqualToValue: (option, value) => option.id === value.id,
|
|
231
|
+
label: ""
|
|
232
|
+
}), /* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
233
|
+
name: "formValueOperand1",
|
|
234
|
+
autoComplete: "off",
|
|
235
|
+
options: optionsYesNo,
|
|
236
|
+
getOptionLabel: (option) => option.label,
|
|
237
|
+
isOptionEqualToValue: (option, value) => option.value === value.value,
|
|
238
|
+
label: ""
|
|
239
|
+
})]
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
const ContainerDateTimeFilter = styled("div")(({
|
|
243
|
+
theme
|
|
244
|
+
}) => ({
|
|
245
|
+
display: "flex",
|
|
246
|
+
flexDirection: "column",
|
|
247
|
+
justifyContent: "center",
|
|
248
|
+
alignItems: "center",
|
|
249
|
+
width: "100%",
|
|
250
|
+
minWidth: theme.spacing(3.75),
|
|
251
|
+
padding: theme.spacing(3, 0),
|
|
252
|
+
gap: theme.spacing(3)
|
|
253
|
+
}));
|
|
254
|
+
function DateTimeFilter() {
|
|
255
|
+
const classesContainerDateTimeFilter = useDynamicFilter((state) => state.classes.containerDateTimeFilter, shallow);
|
|
256
|
+
const {
|
|
257
|
+
getLabel
|
|
258
|
+
} = useModuleDictionary();
|
|
259
|
+
const {
|
|
260
|
+
control
|
|
261
|
+
} = useFormContext();
|
|
262
|
+
const operator = useWatch({
|
|
263
|
+
control,
|
|
264
|
+
name: "formValueOperator"
|
|
265
|
+
});
|
|
266
|
+
const operators = useMemo(() => DATE_TIME_OPERATORS.map((o) => ({
|
|
267
|
+
id: o,
|
|
268
|
+
label: getLabel(getDynamicFilterDictionary(`operator_${o}`))
|
|
269
|
+
})), [getLabel]);
|
|
270
|
+
return /* @__PURE__ */ jsxs(ContainerDateTimeFilter, {
|
|
271
|
+
className: classesContainerDateTimeFilter,
|
|
272
|
+
children: [/* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
273
|
+
name: "formValueOperator",
|
|
274
|
+
autoComplete: "off",
|
|
275
|
+
options: operators,
|
|
276
|
+
getOptionLabel: (option) => option.label,
|
|
277
|
+
isOptionEqualToValue: (option, value) => option.id === value.id,
|
|
278
|
+
label: ""
|
|
279
|
+
}), /* @__PURE__ */ jsx(RHFDateTime, {
|
|
280
|
+
name: "formValueOperand1",
|
|
281
|
+
autoComplete: "off",
|
|
282
|
+
label: ""
|
|
283
|
+
}), operator && operator.id === "b" && /* @__PURE__ */ jsx(RHFDateTime, {
|
|
284
|
+
name: "formValueOperand2",
|
|
285
|
+
autoComplete: "off",
|
|
286
|
+
label: ""
|
|
287
|
+
})]
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
const ContainerNumberFilter = styled("div")(({
|
|
291
|
+
theme
|
|
292
|
+
}) => ({
|
|
293
|
+
display: "flex",
|
|
294
|
+
flexDirection: "column",
|
|
295
|
+
justifyContent: "center",
|
|
296
|
+
alignItems: "center",
|
|
297
|
+
width: "100%",
|
|
298
|
+
minWidth: theme.spacing(3.75),
|
|
299
|
+
padding: theme.spacing(3, 0),
|
|
300
|
+
gap: theme.spacing(3)
|
|
301
|
+
}));
|
|
302
|
+
function NumberFilter() {
|
|
303
|
+
const classesContainerNumberFilter = useDynamicFilter((state) => state.classes.containerNumberFilter);
|
|
304
|
+
const {
|
|
305
|
+
getLabel
|
|
306
|
+
} = useModuleDictionary();
|
|
307
|
+
const {
|
|
308
|
+
control
|
|
309
|
+
} = useFormContext();
|
|
310
|
+
const operator = useWatch({
|
|
311
|
+
control,
|
|
312
|
+
name: "formValueOperator"
|
|
313
|
+
});
|
|
314
|
+
const operators = useMemo(() => NUMBER_OPERATORS.map((o) => ({
|
|
315
|
+
id: o,
|
|
316
|
+
label: getLabel(getDynamicFilterDictionary(`operator_${o}`))
|
|
317
|
+
})), [getLabel]);
|
|
318
|
+
return /* @__PURE__ */ jsxs(ContainerNumberFilter, {
|
|
319
|
+
className: classesContainerNumberFilter,
|
|
320
|
+
children: [/* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
321
|
+
name: "formValueOperator",
|
|
322
|
+
autoComplete: "off",
|
|
323
|
+
options: operators,
|
|
324
|
+
getOptionLabel: (option) => option.label,
|
|
325
|
+
isOptionEqualToValue: (option, value) => option.id === value.id,
|
|
326
|
+
label: ""
|
|
327
|
+
}), /* @__PURE__ */ jsx(RHFTextField, {
|
|
328
|
+
name: "formValueOperand1",
|
|
329
|
+
type: "number"
|
|
330
|
+
}), operator && operator.id === "b" && /* @__PURE__ */ jsx(RHFTextField, {
|
|
331
|
+
name: "formValueOperand2",
|
|
332
|
+
type: "number"
|
|
333
|
+
})]
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
const ContainerStringFilter = styled("div")(({
|
|
337
|
+
theme
|
|
338
|
+
}) => ({
|
|
339
|
+
display: "flex",
|
|
340
|
+
flexDirection: "column",
|
|
341
|
+
justifyContent: "center",
|
|
342
|
+
alignItems: "center",
|
|
343
|
+
width: "100%",
|
|
344
|
+
minWidth: theme.spacing(3.75),
|
|
345
|
+
padding: theme.spacing(3, 0),
|
|
346
|
+
gap: theme.spacing(3)
|
|
347
|
+
}));
|
|
348
|
+
function StringFilter() {
|
|
349
|
+
const classesContainerStringFilter = useDynamicFilter((state) => state.classes.containerStringFilter);
|
|
350
|
+
const {
|
|
351
|
+
getLabel
|
|
352
|
+
} = useModuleDictionary();
|
|
353
|
+
const operators = useMemo(() => STRING_OPERATORS.map((o) => ({
|
|
354
|
+
id: o,
|
|
355
|
+
label: getLabel(getDynamicFilterDictionary(`operator_${o}`))
|
|
356
|
+
})), [getLabel]);
|
|
357
|
+
return /* @__PURE__ */ jsxs(ContainerStringFilter, {
|
|
358
|
+
className: classesContainerStringFilter,
|
|
359
|
+
children: [/* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
360
|
+
name: "formValueOperator",
|
|
361
|
+
autoComplete: "off",
|
|
362
|
+
options: operators,
|
|
363
|
+
getOptionLabel: (option) => option.label,
|
|
364
|
+
isOptionEqualToValue: (option, value) => option.id === value.id,
|
|
365
|
+
label: ""
|
|
366
|
+
}), /* @__PURE__ */ jsx(RHFTextField, {
|
|
367
|
+
name: "formValueOperand1"
|
|
368
|
+
})]
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
const getDefaultBooleanFilter = (field, fixed) => {
|
|
372
|
+
const dfop1 = field.defaultOperand1;
|
|
373
|
+
const defaultFilter = {
|
|
374
|
+
id: 0,
|
|
375
|
+
fieldType: "boolean",
|
|
376
|
+
field,
|
|
377
|
+
fixed,
|
|
378
|
+
isSetted: true,
|
|
379
|
+
operator: "e",
|
|
380
|
+
operand1: true
|
|
381
|
+
};
|
|
382
|
+
if (dfop1 !== void 0 && typeof dfop1 === "boolean") {
|
|
383
|
+
defaultFilter.operand1 = dfop1;
|
|
384
|
+
}
|
|
385
|
+
return defaultFilter;
|
|
386
|
+
};
|
|
387
|
+
const getBooleanLabels = (filter, getLabel) => {
|
|
388
|
+
const labelOperands = filter.operand1 ? getLabel(getDynamicFilterDictionary("operand_true")) : getLabel(getDynamicFilterDictionary("operand_false"));
|
|
389
|
+
return {
|
|
390
|
+
labelField: getLabel(filter.field.dictionaryId),
|
|
391
|
+
labelOperator: getLabel(getDynamicFilterDictionary(`operator_${filter.operator}`)),
|
|
392
|
+
labelOperands
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
const getBooleanSchema = (getLabel) => Yup.object({
|
|
396
|
+
formValueOperator: Yup.object().nullable().required(getLabel(`error_operator_required`)),
|
|
397
|
+
formValueOperand1: Yup.object().nullable().required(getLabel(`error_operand_required`))
|
|
398
|
+
});
|
|
399
|
+
const getBooleanFormValue = (field, getLabel, filterValueBoolean) => {
|
|
400
|
+
const filterValue = filterValueBoolean ? filterValueBoolean : void 0;
|
|
401
|
+
const operator = filterValue ? filterValue.operator : field.defaultOperator ?? "e";
|
|
402
|
+
const formValueOperand1 = filterValue ? {
|
|
403
|
+
value: filterValue.operand1,
|
|
404
|
+
label: getLabel(getDynamicFilterDictionary(`operand_${filterValue.operand1}`))
|
|
405
|
+
} : null;
|
|
406
|
+
const ret = {
|
|
407
|
+
fieldType: "boolean",
|
|
408
|
+
formValueOperator: {
|
|
409
|
+
id: operator,
|
|
410
|
+
label: getLabel(getDynamicFilterDictionary(`operator_${operator}`))
|
|
411
|
+
},
|
|
412
|
+
formValueOperand1
|
|
413
|
+
};
|
|
414
|
+
return ret;
|
|
415
|
+
};
|
|
416
|
+
const getFilterFromBooleanFormValue = (formFilterValue) => {
|
|
417
|
+
const operator = formFilterValue.formValueOperator.id;
|
|
418
|
+
const opeand1 = formFilterValue.formValueOperand1?.value || false;
|
|
419
|
+
return {
|
|
420
|
+
fieldType: "boolean",
|
|
421
|
+
operator,
|
|
422
|
+
operand1: opeand1
|
|
423
|
+
};
|
|
424
|
+
};
|
|
425
|
+
const getDefaultStringFilter = (field, fixed) => {
|
|
426
|
+
const dfop1 = field.defaultOperand1;
|
|
427
|
+
const defaultFilter = {
|
|
428
|
+
id: 0,
|
|
429
|
+
fieldType: "string",
|
|
430
|
+
field,
|
|
431
|
+
fixed,
|
|
432
|
+
isSetted: false,
|
|
433
|
+
operator: "c",
|
|
434
|
+
operand1: ""
|
|
435
|
+
};
|
|
436
|
+
if (dfop1 !== void 0 && typeof dfop1 === "string") {
|
|
437
|
+
defaultFilter.operand1 = dfop1;
|
|
438
|
+
}
|
|
439
|
+
return defaultFilter;
|
|
440
|
+
};
|
|
441
|
+
const getStringLabels = (filter, getLabel) => {
|
|
442
|
+
const labelOperands = filter.operand1 !== void 0 ? filter.operand1 + "" : "";
|
|
443
|
+
return {
|
|
444
|
+
labelField: getLabel(filter.field.dictionaryId),
|
|
445
|
+
labelOperator: getLabel(getDynamicFilterDictionary(`operator_${filter.operator}`)),
|
|
446
|
+
labelOperands
|
|
447
|
+
};
|
|
448
|
+
};
|
|
449
|
+
const getStringSchema = (getLabel) => Yup.object({
|
|
450
|
+
formValueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
|
|
451
|
+
formValueOperand1: Yup.string().required(getLabel(`operand_required`))
|
|
452
|
+
});
|
|
453
|
+
const getStringFormValue = (field, getLabel, filterValue) => {
|
|
454
|
+
const filterValueString = filterValue;
|
|
455
|
+
const operator = filterValueString ? filterValueString.operator : field.defaultOperator ?? "c";
|
|
456
|
+
const formValueOperand1 = filterValueString ? filterValueString.operand1 : "";
|
|
457
|
+
return {
|
|
458
|
+
fieldType: "string",
|
|
459
|
+
formValueOperator: {
|
|
460
|
+
id: operator,
|
|
461
|
+
label: getLabel(getDynamicFilterDictionary(`operator_${operator}`))
|
|
462
|
+
},
|
|
463
|
+
formValueOperand1
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
const getFilterFromStringFormValue = (formFilterValue) => {
|
|
467
|
+
const operator = formFilterValue.formValueOperator.id;
|
|
468
|
+
const operand1 = formFilterValue.formValueOperand1;
|
|
469
|
+
return {
|
|
470
|
+
fieldType: "string",
|
|
471
|
+
operator,
|
|
472
|
+
operand1
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
const getDefaultDateTimeFilter = (field, fixed) => {
|
|
476
|
+
const defaultStartDate = new Date();
|
|
477
|
+
const defaultEndDate = new Date();
|
|
478
|
+
defaultStartDate.setHours(0, 0, 0, 0);
|
|
479
|
+
defaultEndDate.setHours(23, 59, 59, 999);
|
|
480
|
+
const dfop1 = field.defaultOperand1 && field.defaultOperand1 instanceof Date ? field.defaultOperand1 : defaultStartDate;
|
|
481
|
+
const dfop2 = field.defaultOperand2 && field.defaultOperand2 instanceof Date ? field.defaultOperand2 : defaultEndDate;
|
|
482
|
+
const defaultFilter = {
|
|
483
|
+
id: 0,
|
|
484
|
+
fieldType: "datetime",
|
|
485
|
+
field,
|
|
486
|
+
fixed,
|
|
487
|
+
isSetted: true,
|
|
488
|
+
operator: "b",
|
|
489
|
+
operand1: dfop1,
|
|
490
|
+
operand2: dfop2
|
|
491
|
+
};
|
|
492
|
+
return defaultFilter;
|
|
493
|
+
};
|
|
494
|
+
const getDateLabels = (filter, getLabel, formatters) => {
|
|
495
|
+
const { dateFormatter } = formatters;
|
|
496
|
+
let labelOperands;
|
|
497
|
+
if (filter.operator === "b") {
|
|
498
|
+
labelOperands = filter.operand1 && filter.operand2 ? `${dateFormatter.formatDate(
|
|
499
|
+
filter.operand1,
|
|
500
|
+
dateFormatter.datetimeFormat
|
|
501
|
+
)} - ${dateFormatter.formatDate(
|
|
502
|
+
filter.operand2,
|
|
503
|
+
dateFormatter.datetimeFormat
|
|
504
|
+
)}` : "";
|
|
505
|
+
} else {
|
|
506
|
+
labelOperands = filter.operand1 ? dateFormatter.formatDate(filter.operand1, dateFormatter.datetimeFormat) : "";
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
labelField: getLabel(filter.field.dictionaryId),
|
|
510
|
+
labelOperator: getLabel(getDynamicFilterDictionary(`operator_${filter.operator}`)),
|
|
511
|
+
labelOperands
|
|
512
|
+
};
|
|
513
|
+
};
|
|
514
|
+
const getDateTimeSchema = (getLabel) => Yup.object({
|
|
515
|
+
formValueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
|
|
516
|
+
formValueOperand1: Yup.date().required(getLabel(`dynamic_filter.error_invalid_date`)).typeError(getLabel(`dynamic_filter.error_invalid_date`)),
|
|
517
|
+
formValueOperand2: Yup.mixed().when(["formValueOperator.id"], {
|
|
518
|
+
is: "b",
|
|
519
|
+
then: Yup.date().typeError(getLabel(`dynamic_filter.error_invalid_date`)).min(
|
|
520
|
+
Yup.ref("formValueOperand1"),
|
|
521
|
+
getLabel(`dynamic_filter.error_less_than_start`)
|
|
522
|
+
)
|
|
523
|
+
})
|
|
524
|
+
});
|
|
525
|
+
const getDateTimeFormValue = (field, getLabel, filterValueDateTime) => {
|
|
526
|
+
const filterValue = filterValueDateTime;
|
|
527
|
+
const operator = filterValue ? filterValue.operator : field.defaultOperator ?? "b";
|
|
528
|
+
const defaultStartDate = new Date();
|
|
529
|
+
const defaultEndDate = new Date();
|
|
530
|
+
const dfop1 = field.defaultOperand1 && field.defaultOperand1 instanceof Date ? field.defaultOperand1 : defaultStartDate;
|
|
531
|
+
const dfop2 = field.defaultOperand2 && field.defaultOperand2 instanceof Date ? field.defaultOperand2 : defaultEndDate;
|
|
532
|
+
const formValueOperand1 = filterValue ? filterValue.operand1 : dfop1;
|
|
533
|
+
const formValueOperand2 = filterValue && filterValue.operator === "b" ? filterValue.operand2 : dfop2;
|
|
534
|
+
return {
|
|
535
|
+
fieldType: "datetime",
|
|
536
|
+
formValueOperator: {
|
|
537
|
+
id: operator,
|
|
538
|
+
label: getLabel(getDynamicFilterDictionary(`operator_${operator}`))
|
|
539
|
+
},
|
|
540
|
+
formValueOperand1,
|
|
541
|
+
formValueOperand2
|
|
542
|
+
};
|
|
543
|
+
};
|
|
544
|
+
const getFilterFromDateTimeFormValue = (formFilterValue) => {
|
|
545
|
+
const operator = formFilterValue.formValueOperator.id;
|
|
546
|
+
const operand1 = formFilterValue.formValueOperand1;
|
|
547
|
+
if (operator === "b") {
|
|
548
|
+
const operand2 = formFilterValue.formValueOperand2;
|
|
549
|
+
return {
|
|
550
|
+
fieldType: "datetime",
|
|
551
|
+
operator,
|
|
552
|
+
operand1,
|
|
553
|
+
operand2
|
|
554
|
+
};
|
|
555
|
+
} else {
|
|
556
|
+
return {
|
|
557
|
+
fieldType: "datetime",
|
|
558
|
+
operator,
|
|
559
|
+
operand1
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
const getDefaultNumberFilter = (fieldNumber, fixed) => {
|
|
564
|
+
const field = fieldNumber;
|
|
565
|
+
const dOperator = field.defaultOperator ?? "e";
|
|
566
|
+
const dfop1 = field.defaultOperand1 ?? null;
|
|
567
|
+
const dfop2 = field.defaultOperand2 ?? null;
|
|
568
|
+
const defaultFilter = {
|
|
569
|
+
id: 0,
|
|
570
|
+
fieldType: "number",
|
|
571
|
+
field,
|
|
572
|
+
fixed,
|
|
573
|
+
isSetted: false,
|
|
574
|
+
operator: dOperator,
|
|
575
|
+
operand1: dfop1,
|
|
576
|
+
operand2: dfop2
|
|
577
|
+
};
|
|
578
|
+
return defaultFilter;
|
|
579
|
+
};
|
|
580
|
+
const getNumberLabels = (filter, getLabel) => {
|
|
581
|
+
let labelOperands;
|
|
582
|
+
if (filter.operator === "b") {
|
|
583
|
+
labelOperands = filter.operand1 && filter.operand2 ? `${filter.operand1} - ${filter.operand2}` : "";
|
|
584
|
+
} else {
|
|
585
|
+
labelOperands = filter.operand1 !== void 0 ? filter.operand1 + "" : "";
|
|
586
|
+
}
|
|
587
|
+
return {
|
|
588
|
+
labelField: getLabel(filter.field.dictionaryId),
|
|
589
|
+
labelOperator: getLabel(getDynamicFilterDictionary(`operator_${filter.operator}`)),
|
|
590
|
+
labelOperands
|
|
591
|
+
};
|
|
592
|
+
};
|
|
593
|
+
const getNumberSchema = (getLabel) => Yup.object({
|
|
594
|
+
formValueOperator: Yup.object().nullable().required(getLabel(`dynamic_filter.error_operator_required`)),
|
|
595
|
+
formValueOperand1: Yup.number().typeError(
|
|
596
|
+
getLabel(`dynamic_filter.error_operand_mustbe_number`)
|
|
597
|
+
),
|
|
598
|
+
formValueOperand2: Yup.mixed().when(["formValueOperator.id"], {
|
|
599
|
+
is: "b",
|
|
600
|
+
then: Yup.number().typeError(getLabel(`dynamic_filter.error_operand_mustbe_number`)).min(
|
|
601
|
+
Yup.ref("formValueOperand1"),
|
|
602
|
+
getLabel(`dynamic_filter.error_less_than_start`)
|
|
603
|
+
)
|
|
604
|
+
})
|
|
605
|
+
});
|
|
606
|
+
const getNumberFormValue = (field, getLabel, filterValue) => {
|
|
607
|
+
const filterValueNumber = filterValue;
|
|
608
|
+
const operator = filterValueNumber ? filterValueNumber.operator : field.defaultOperator ?? "e";
|
|
609
|
+
const formValueOperand1 = filterValueNumber ? filterValueNumber.operand1 : null;
|
|
610
|
+
const formValueOperand2 = filterValueNumber && filterValueNumber?.operator === "b" ? filterValueNumber.operand2 : null;
|
|
611
|
+
return {
|
|
612
|
+
fieldType: "number",
|
|
613
|
+
formValueOperator: {
|
|
614
|
+
id: operator,
|
|
615
|
+
label: getLabel(getDynamicFilterDictionary(`operator_${operator}`))
|
|
616
|
+
},
|
|
617
|
+
formValueOperand1,
|
|
618
|
+
formValueOperand2
|
|
619
|
+
};
|
|
620
|
+
};
|
|
621
|
+
const getFilterFromNumberFormValue = (formFilterValue) => {
|
|
622
|
+
const operator = formFilterValue.formValueOperator.id;
|
|
623
|
+
const operand1 = formFilterValue.formValueOperand1 ? formFilterValue.formValueOperand1 : 0;
|
|
624
|
+
if (operator === "b") {
|
|
625
|
+
const operand2 = formFilterValue.formValueOperand2 ? formFilterValue.formValueOperand2 : 0;
|
|
626
|
+
return {
|
|
627
|
+
fieldType: "number",
|
|
628
|
+
operator,
|
|
629
|
+
operand1,
|
|
630
|
+
operand2
|
|
631
|
+
};
|
|
632
|
+
} else {
|
|
633
|
+
return {
|
|
634
|
+
fieldType: "number",
|
|
635
|
+
operator,
|
|
636
|
+
operand1
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
const strategiesEditFilterComponent = {
|
|
641
|
+
boolean: BooleanFilter,
|
|
642
|
+
datetime: DateTimeFilter,
|
|
643
|
+
number: NumberFilter,
|
|
644
|
+
string: StringFilter,
|
|
645
|
+
__default__: () => {
|
|
646
|
+
throw new Error("Type no defined");
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
const DataTypeComponent = (props) => {
|
|
650
|
+
const {
|
|
651
|
+
formFilter,
|
|
652
|
+
statusLoad
|
|
653
|
+
} = props;
|
|
654
|
+
const {
|
|
655
|
+
setFocus
|
|
656
|
+
} = useFormContext();
|
|
657
|
+
const Component = strategiesEditFilterComponent[formFilter.field.type] ?? strategiesEditFilterComponent.__default__;
|
|
658
|
+
useEffect(() => {
|
|
659
|
+
setTimeout(() => setFocus("formValueOperand1"), 100);
|
|
660
|
+
}, [statusLoad]);
|
|
661
|
+
return /* @__PURE__ */ jsx(Component, {});
|
|
662
|
+
};
|
|
663
|
+
const strategiesLabelsFilters = {
|
|
664
|
+
boolean: getBooleanLabels,
|
|
665
|
+
datetime: getDateLabels,
|
|
666
|
+
number: getNumberLabels,
|
|
667
|
+
string: getStringLabels,
|
|
668
|
+
__default__: () => {
|
|
669
|
+
throw new Error("Type no defined");
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
const getLabelsFilter = (filter, getLabel, formatters) => {
|
|
673
|
+
const transformer = strategiesLabelsFilters[filter.field.type] ?? strategiesLabelsFilters.__default__;
|
|
674
|
+
return transformer(filter, getLabel, formatters);
|
|
675
|
+
};
|
|
676
|
+
const strategiesDefaultFilterValues = {
|
|
677
|
+
boolean: getDefaultBooleanFilter,
|
|
678
|
+
datetime: getDefaultDateTimeFilter,
|
|
679
|
+
number: getDefaultNumberFilter,
|
|
680
|
+
string: getDefaultStringFilter,
|
|
681
|
+
__default__: () => {
|
|
682
|
+
throw new Error("Type no defined");
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
const getDefaultValues = (field, fixed) => {
|
|
686
|
+
const transformer = strategiesDefaultFilterValues[field.type] ?? strategiesDefaultFilterValues.__default__;
|
|
687
|
+
return transformer(field, fixed);
|
|
688
|
+
};
|
|
689
|
+
const strategiesSchhemaValidationsFilters = {
|
|
690
|
+
boolean: getBooleanSchema,
|
|
691
|
+
datetime: getDateTimeSchema,
|
|
692
|
+
number: getNumberSchema,
|
|
693
|
+
string: getStringSchema,
|
|
694
|
+
__default__: () => {
|
|
695
|
+
throw new Error("Type no defined");
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
const getSchemaValidations = (field, getLabel) => {
|
|
699
|
+
const transformer = strategiesSchhemaValidationsFilters[field.type] ?? strategiesSchhemaValidationsFilters.__default__;
|
|
700
|
+
return transformer(getLabel);
|
|
701
|
+
};
|
|
702
|
+
const strategiesFormValue = {
|
|
703
|
+
boolean: getBooleanFormValue,
|
|
704
|
+
datetime: getDateTimeFormValue,
|
|
705
|
+
number: getNumberFormValue,
|
|
706
|
+
string: getStringFormValue,
|
|
707
|
+
__default__: () => {
|
|
708
|
+
throw new Error("Type no defined");
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
const getFormValue = (field, getLabel, filter) => {
|
|
712
|
+
const transformer = strategiesFormValue[field.type] ?? strategiesFormValue.__default__;
|
|
713
|
+
return transformer(field, getLabel, filter);
|
|
714
|
+
};
|
|
715
|
+
const strategiesFilterFromFormValue = {
|
|
716
|
+
boolean: getFilterFromBooleanFormValue,
|
|
717
|
+
datetime: getFilterFromDateTimeFormValue,
|
|
718
|
+
number: getFilterFromNumberFormValue,
|
|
719
|
+
string: getFilterFromStringFormValue,
|
|
720
|
+
__default__: () => {
|
|
721
|
+
throw new Error("Type no defined");
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
const getFilterFromFormValue = (filter) => {
|
|
725
|
+
const transformer = strategiesFilterFromFormValue[filter.fieldType] ?? strategiesFilterFromFormValue.__default__;
|
|
726
|
+
return transformer(filter);
|
|
727
|
+
};
|
|
728
|
+
const verifyBooleanFilter = (filter) => {
|
|
729
|
+
if (typeof filter.operator !== "string") {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
if (BOOLEAN_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
if (typeof filter.operand1 !== "boolean") {
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
return true;
|
|
739
|
+
};
|
|
740
|
+
const verifyDateTime = (filter) => {
|
|
741
|
+
if (typeof filter.operator !== "string") {
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
if (DATE_TIME_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
if (typeof filter.operand1 !== "string") {
|
|
748
|
+
return false;
|
|
749
|
+
}
|
|
750
|
+
if (!isValidDate(new Date(filter.operand1))) {
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
if (filter.operator === "b") {
|
|
754
|
+
if (typeof filter.operand2 !== "string") {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
if (!isValidDate(new Date(filter.operand1))) {
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return true;
|
|
762
|
+
};
|
|
763
|
+
const verifyNumberFilter = (filter) => {
|
|
764
|
+
if (typeof filter.operator !== "number") {
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
if (NUMBER_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
|
|
768
|
+
return false;
|
|
769
|
+
}
|
|
770
|
+
if (typeof filter.operand1 !== "number") {
|
|
771
|
+
return false;
|
|
772
|
+
}
|
|
773
|
+
if (filter.operator === "b" && typeof filter.operand2 !== "number") {
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
return true;
|
|
777
|
+
};
|
|
778
|
+
const verifyStringFilter = (filter) => {
|
|
779
|
+
if (typeof filter.operator !== "string") {
|
|
780
|
+
return false;
|
|
781
|
+
}
|
|
782
|
+
if (STRING_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
if (typeof filter.operand1 !== "string") {
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
return true;
|
|
789
|
+
};
|
|
790
|
+
const formatToInitialFilters = (applyedFilters) => {
|
|
791
|
+
return applyedFilters.map((af) => {
|
|
792
|
+
const ret = {
|
|
793
|
+
name: af.field.name,
|
|
794
|
+
operator: af.operator,
|
|
795
|
+
operand1: af.operand1,
|
|
796
|
+
operand2: af.operator === "b" ? af.operand2 : void 0
|
|
797
|
+
};
|
|
798
|
+
if (af.fieldType === "datetime") {
|
|
799
|
+
ret.operand1 = af.operand1.toISOString();
|
|
800
|
+
ret.operand2 = af.operator === "b" ? af.operand2.toISOString() : void 0;
|
|
801
|
+
}
|
|
802
|
+
return ret;
|
|
803
|
+
});
|
|
804
|
+
};
|
|
805
|
+
const formatToRawFilter = (applyedFilters) => {
|
|
806
|
+
return applyedFilters.map((af) => ({
|
|
807
|
+
n: af.field.name,
|
|
808
|
+
o: af.operator,
|
|
809
|
+
o1: af.operand1,
|
|
810
|
+
o2: af.operator === "b" ? af.operand2 : void 0
|
|
811
|
+
}));
|
|
812
|
+
};
|
|
813
|
+
const getPurgedInitialFiltersApplyed = (fields, initialFilters, getFieldByName) => {
|
|
814
|
+
const newFilters = [];
|
|
815
|
+
const fixedFields = [];
|
|
816
|
+
for (let index = 0; index < initialFilters.length; index++) {
|
|
817
|
+
try {
|
|
818
|
+
let add;
|
|
819
|
+
const initialFilter = initialFilters[index];
|
|
820
|
+
const field = getFieldByName(initialFilter.name);
|
|
821
|
+
const filter = {
|
|
822
|
+
id: 0,
|
|
823
|
+
isSetted: true,
|
|
824
|
+
fixed: false,
|
|
825
|
+
field,
|
|
826
|
+
fieldType: field.type,
|
|
827
|
+
operator: initialFilters[index].operator,
|
|
828
|
+
operand1: initialFilters[index].operand1,
|
|
829
|
+
operand2: initialFilters[index].operand2
|
|
830
|
+
};
|
|
831
|
+
if (!field)
|
|
832
|
+
continue;
|
|
833
|
+
switch (field.type) {
|
|
834
|
+
case "string":
|
|
835
|
+
add = verifyStringFilter(initialFilter);
|
|
836
|
+
break;
|
|
837
|
+
case "number":
|
|
838
|
+
add = verifyNumberFilter(initialFilter);
|
|
839
|
+
break;
|
|
840
|
+
case "boolean":
|
|
841
|
+
add = verifyBooleanFilter(initialFilter);
|
|
842
|
+
break;
|
|
843
|
+
case "datetime":
|
|
844
|
+
add = verifyDateTime(initialFilter);
|
|
845
|
+
break;
|
|
846
|
+
default:
|
|
847
|
+
add = false;
|
|
848
|
+
}
|
|
849
|
+
if (add) {
|
|
850
|
+
if (filter.fieldType === "datetime") {
|
|
851
|
+
filter.operand1 = new Date(filter.operand1 + "");
|
|
852
|
+
filter.operand2 = new Date(filter.operand2 + "");
|
|
853
|
+
}
|
|
854
|
+
if (field.presence === "fixed") {
|
|
855
|
+
if (fixedFields.findIndex((f) => f === field.name) === -1) {
|
|
856
|
+
filter.fixed = true;
|
|
857
|
+
fixedFields.push(field.name);
|
|
858
|
+
} else {
|
|
859
|
+
filter.fixed = false;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
filter.isSetted = true;
|
|
863
|
+
filter.id = newFilters.length + 1;
|
|
864
|
+
newFilters.push(filter);
|
|
865
|
+
}
|
|
866
|
+
} catch (error) {
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
for (let index = 0; index < fields.length; index++) {
|
|
870
|
+
const field = fields[index];
|
|
871
|
+
if (field.presence === "initialized" || field.presence === "fixed") {
|
|
872
|
+
if (!initialFilters.find((f) => f.name === field.name)) {
|
|
873
|
+
const newFilter = getDefaultValues(field, field.presence === "fixed");
|
|
874
|
+
newFilter.id = newFilters.length + 1;
|
|
875
|
+
newFilters.push(newFilter);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return newFilters;
|
|
880
|
+
};
|
|
881
|
+
const updateAvailableFieldsNoBoilerPlate = (state) => {
|
|
882
|
+
const newFields = [];
|
|
883
|
+
for (let index = 0; index < state.fields.length; index++) {
|
|
884
|
+
let add;
|
|
885
|
+
const field = state.fields[index];
|
|
886
|
+
add = true;
|
|
887
|
+
if (field.multiple !== void 0 && field.multiple === false) {
|
|
888
|
+
const fIndx = state.applyedFilters.findIndex((f) => f.field.name === field.name);
|
|
889
|
+
if (fIndx > -1) {
|
|
890
|
+
add = false;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (add) {
|
|
894
|
+
newFields.push(field);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
state.availableFields = newFields;
|
|
898
|
+
};
|
|
899
|
+
const updateOwnerStateClasses = (state) => {
|
|
900
|
+
state.classes = useUtilityClasses(state.ownerState);
|
|
901
|
+
};
|
|
902
|
+
const createAreaStore = (initProps) => {
|
|
903
|
+
const startProps = {
|
|
904
|
+
applyedFilters: [],
|
|
905
|
+
availableFields: [],
|
|
906
|
+
fnAnchorEl: void 0,
|
|
907
|
+
popoverFilterData: void 0,
|
|
908
|
+
classes: useUtilityClasses(initProps.ownerState),
|
|
909
|
+
inputData: "",
|
|
910
|
+
...initProps
|
|
911
|
+
};
|
|
912
|
+
return createStore(
|
|
913
|
+
devtools(
|
|
914
|
+
immer((set, get) => ({
|
|
915
|
+
...startProps,
|
|
916
|
+
actions: {
|
|
917
|
+
init: (initialFiltersApplyed) => {
|
|
918
|
+
set((state) => {
|
|
919
|
+
state.applyedFilters = getPurgedInitialFiltersApplyed(
|
|
920
|
+
state.fields,
|
|
921
|
+
initialFiltersApplyed,
|
|
922
|
+
state.actions.getFieldByName
|
|
923
|
+
);
|
|
924
|
+
updateAvailableFieldsNoBoilerPlate(state);
|
|
925
|
+
});
|
|
926
|
+
},
|
|
927
|
+
getFieldByName: (name) => {
|
|
928
|
+
const field = (get().withAllField ? get().fields.concat(get().allField) : get().fields).find((f) => {
|
|
929
|
+
return f.name === name;
|
|
930
|
+
});
|
|
931
|
+
if (field) {
|
|
932
|
+
return field;
|
|
933
|
+
}
|
|
934
|
+
throw new Error("No exist field");
|
|
935
|
+
},
|
|
936
|
+
removeFilter: (id) => {
|
|
937
|
+
set((state) => {
|
|
938
|
+
const index_to_remove = state.applyedFilters.findIndex(
|
|
939
|
+
(f) => id === f.id && !f.fixed
|
|
940
|
+
);
|
|
941
|
+
if (index_to_remove > -1) {
|
|
942
|
+
state.applyedFilters.splice(index_to_remove, 1);
|
|
943
|
+
}
|
|
944
|
+
updateAvailableFieldsNoBoilerPlate(state);
|
|
945
|
+
});
|
|
946
|
+
},
|
|
947
|
+
showPopoverFilterForAdd: (anchorEl, field) => {
|
|
948
|
+
set((state) => {
|
|
949
|
+
state.fnAnchorEl = void 0;
|
|
950
|
+
state.inputData = "";
|
|
951
|
+
state.popoverFilterData = {
|
|
952
|
+
openFor: "add",
|
|
953
|
+
fnAnchorEl: () => anchorEl,
|
|
954
|
+
field
|
|
955
|
+
};
|
|
956
|
+
});
|
|
957
|
+
get().actions.setInEdition(true);
|
|
958
|
+
},
|
|
959
|
+
showPopoverFilterForEdit: (anchorEl, filterToEdit) => {
|
|
960
|
+
set((state) => {
|
|
961
|
+
state.popoverFilterData = {
|
|
962
|
+
openFor: "edit",
|
|
963
|
+
fnAnchorEl: () => anchorEl,
|
|
964
|
+
filter: filterToEdit
|
|
965
|
+
};
|
|
966
|
+
});
|
|
967
|
+
get().actions.setInEdition(true);
|
|
968
|
+
},
|
|
969
|
+
hidePopoverFilter: (stayInEditon) => {
|
|
970
|
+
set((state) => {
|
|
971
|
+
state.popoverFilterData = void 0;
|
|
972
|
+
});
|
|
973
|
+
get().actions.setInEdition(stayInEditon);
|
|
974
|
+
},
|
|
975
|
+
clearFilters: () => {
|
|
976
|
+
set((state) => {
|
|
977
|
+
state.applyedFilters = state.applyedFilters.filter((f) => f.fixed);
|
|
978
|
+
updateAvailableFieldsNoBoilerPlate(state);
|
|
979
|
+
});
|
|
980
|
+
},
|
|
981
|
+
fireOnChangeFilters: () => {
|
|
982
|
+
set((state) => {
|
|
983
|
+
if (state.ownerState.isValid) {
|
|
984
|
+
if (!state.automatic) {
|
|
985
|
+
state.ownerState.isDirty = false;
|
|
986
|
+
}
|
|
987
|
+
state.onChangeFilters(
|
|
988
|
+
formatToInitialFilters(state.applyedFilters),
|
|
989
|
+
formatToRawFilter(state.applyedFilters)
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
},
|
|
994
|
+
getNewId: () => {
|
|
995
|
+
return get().applyedFilters.reduce((prev, n) => {
|
|
996
|
+
return n.id > prev ? n.id : prev;
|
|
997
|
+
}, 0) + 1;
|
|
998
|
+
},
|
|
999
|
+
addFilter: (newFilter) => {
|
|
1000
|
+
set((state) => {
|
|
1001
|
+
state.applyedFilters.push(newFilter);
|
|
1002
|
+
});
|
|
1003
|
+
},
|
|
1004
|
+
updateFilter: (editFilter) => {
|
|
1005
|
+
set((state) => {
|
|
1006
|
+
const index = state.applyedFilters.findIndex(
|
|
1007
|
+
(ap) => ap.id === editFilter.id
|
|
1008
|
+
);
|
|
1009
|
+
if (index > -1) {
|
|
1010
|
+
state.applyedFilters[index] = editFilter;
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
},
|
|
1014
|
+
setInputData: (inputData) => {
|
|
1015
|
+
set((state) => {
|
|
1016
|
+
state.inputData = inputData;
|
|
1017
|
+
});
|
|
1018
|
+
},
|
|
1019
|
+
setInEdition: (newInEdition) => {
|
|
1020
|
+
set((state) => {
|
|
1021
|
+
state.ownerState.inEdition = newInEdition;
|
|
1022
|
+
updateOwnerStateClasses(state);
|
|
1023
|
+
});
|
|
1024
|
+
},
|
|
1025
|
+
setIsMobile: (newIsMobile) => {
|
|
1026
|
+
set((state) => {
|
|
1027
|
+
state.ownerState.isMobile = newIsMobile;
|
|
1028
|
+
updateOwnerStateClasses(state);
|
|
1029
|
+
});
|
|
1030
|
+
},
|
|
1031
|
+
openPopoverMenuFields: (anchorEl) => {
|
|
1032
|
+
set((state) => {
|
|
1033
|
+
state.fnAnchorEl = () => anchorEl;
|
|
1034
|
+
});
|
|
1035
|
+
},
|
|
1036
|
+
closePopoverMenuFields: (newInEdition) => {
|
|
1037
|
+
set((state) => {
|
|
1038
|
+
state.fnAnchorEl = void 0;
|
|
1039
|
+
state.ownerState.inEdition = newInEdition || false;
|
|
1040
|
+
updateOwnerStateClasses(state);
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
})),
|
|
1045
|
+
{ name: `Dynamic filter` }
|
|
1046
|
+
)
|
|
1047
|
+
);
|
|
1048
|
+
};
|
|
1049
|
+
const DynamicFilterContext = createContext(null);
|
|
1050
|
+
function DynamicFilterProvider(props) {
|
|
1051
|
+
const {
|
|
1052
|
+
automatic = true,
|
|
1053
|
+
withAllField = true,
|
|
1054
|
+
fields,
|
|
1055
|
+
initialApplyedFilters = [],
|
|
1056
|
+
onChangeFilters,
|
|
1057
|
+
children
|
|
1058
|
+
} = props;
|
|
1059
|
+
const {
|
|
1060
|
+
getLabel
|
|
1061
|
+
} = useModuleDictionary();
|
|
1062
|
+
const dynamicFilterStoreRef = useRef();
|
|
1063
|
+
const {
|
|
1064
|
+
host_static_assets,
|
|
1065
|
+
environment_assets
|
|
1066
|
+
} = useEnvironment();
|
|
1067
|
+
const isDesktop = useResponsiveDesktop();
|
|
1068
|
+
const isFirstRender = useFirstRender([isDesktop]);
|
|
1069
|
+
if (!dynamicFilterStoreRef.current) {
|
|
1070
|
+
dynamicFilterStoreRef.current = createAreaStore({
|
|
1071
|
+
allField: {
|
|
1072
|
+
...ALL_FIELDS,
|
|
1073
|
+
urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/all_fields.svg`
|
|
1074
|
+
},
|
|
1075
|
+
withAllField,
|
|
1076
|
+
fields,
|
|
1077
|
+
automatic,
|
|
1078
|
+
onChangeFilters,
|
|
1079
|
+
getLabel,
|
|
1080
|
+
ownerState: {
|
|
1081
|
+
isDirty: !automatic,
|
|
1082
|
+
inEdition: false,
|
|
1083
|
+
isValid: true,
|
|
1084
|
+
isMobile: !isDesktop
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
dynamicFilterStoreRef.current.getState().actions.init(initialApplyedFilters);
|
|
1088
|
+
}
|
|
1089
|
+
useEffect(() => {
|
|
1090
|
+
if (isFirstRender) {
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
dynamicFilterStoreRef.current?.getState().actions.setIsMobile(!isDesktop);
|
|
1094
|
+
}, [isDesktop]);
|
|
1095
|
+
return /* @__PURE__ */ jsx(DynamicFilterContext.Provider, {
|
|
1096
|
+
value: dynamicFilterStoreRef.current,
|
|
1097
|
+
children
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
const DynamicFilterRoot = styled("div", {})(({
|
|
1101
|
+
theme
|
|
1102
|
+
}) => ({
|
|
1103
|
+
display: "flex",
|
|
1104
|
+
alignItems: "center",
|
|
1105
|
+
justifyContent: "flex-start",
|
|
1106
|
+
height: "auto",
|
|
1107
|
+
width: "100%",
|
|
1108
|
+
padding: theme.spacing(0.5),
|
|
1109
|
+
borderRadius: theme.spacing(1),
|
|
1110
|
+
border: `1px solid ${theme.palette.divider}`,
|
|
1111
|
+
[`&.${dynamicFilterClasses.isMobile}`]: {
|
|
1112
|
+
flexDirection: "column",
|
|
1113
|
+
justifyContent: "space-between",
|
|
1114
|
+
minWidth: theme.spacing(25),
|
|
1115
|
+
gap: theme.spacing(0.75)
|
|
1116
|
+
},
|
|
1117
|
+
[`&.${dynamicFilterClasses.root}.${dynamicFilterClasses.inEdition}`]: {
|
|
1118
|
+
border: `1px solid ${theme.palette.primary.main}`
|
|
1119
|
+
},
|
|
1120
|
+
[`&.${dynamicFilterClasses.isMobile} .${dynamicFilterClasses.containerApplyedFilters}`]: {
|
|
1121
|
+
margin: "0px",
|
|
1122
|
+
padding: "0px",
|
|
1123
|
+
border: "0px"
|
|
1124
|
+
},
|
|
1125
|
+
[`&.${dynamicFilterClasses.filterButton}.${dynamicFilterClasses.isDirty}`]: {
|
|
1126
|
+
animationName: "dirtyEffect",
|
|
1127
|
+
animationDuration: "1s",
|
|
1128
|
+
animationFillMode: "both",
|
|
1129
|
+
animationIterationCount: "infinite",
|
|
1130
|
+
transition: "all .3s",
|
|
1131
|
+
"@keyframes dirtyEffect": {
|
|
1132
|
+
"20%": {
|
|
1133
|
+
opacity: 1
|
|
1134
|
+
},
|
|
1135
|
+
"50%": {
|
|
1136
|
+
opacity: 0.5
|
|
1137
|
+
},
|
|
1138
|
+
"100%": {
|
|
1139
|
+
opacity: 1
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
},
|
|
1143
|
+
[`&.${dynamicFilterClasses.filterButton} .${dynamicFilterClasses.applyedFilter}`]: {
|
|
1144
|
+
border: `1px solid ${theme.palette.error.main}`
|
|
1145
|
+
},
|
|
1146
|
+
...theme.components?.M4LDynamicFilter?.styleOverrides
|
|
1147
|
+
}));
|
|
1148
|
+
const ContainerFistRow = styled("div")(() => ({
|
|
1149
|
+
width: "100%",
|
|
1150
|
+
display: "flex",
|
|
1151
|
+
justifyContent: "space-between"
|
|
1152
|
+
}));
|
|
1153
|
+
const WrapperApplyedFilters = styled("div")(({
|
|
1154
|
+
theme
|
|
1155
|
+
}) => ({
|
|
1156
|
+
width: "100%",
|
|
1157
|
+
margin: theme.spacing(0, 1),
|
|
1158
|
+
paddingLeft: theme.spacing(1),
|
|
1159
|
+
borderLeft: `1px solid ${theme.palette.divider}`
|
|
1160
|
+
}));
|
|
1161
|
+
const ContainerApplyedFilters = styled("div")(({
|
|
1162
|
+
theme
|
|
1163
|
+
}) => ({
|
|
1164
|
+
width: "100%",
|
|
1165
|
+
display: "flex",
|
|
1166
|
+
justifyContent: "flex-start",
|
|
1167
|
+
alignItems: "center",
|
|
1168
|
+
height: "auto",
|
|
1169
|
+
gap: theme.spacing(1.5)
|
|
1170
|
+
}));
|
|
1171
|
+
const WrapperApplyedFilter = styled("div")(({
|
|
1172
|
+
theme
|
|
1173
|
+
}) => ({
|
|
1174
|
+
width: "auto",
|
|
1175
|
+
display: "flex",
|
|
1176
|
+
justifyContent: "center",
|
|
1177
|
+
alignItems: "center",
|
|
1178
|
+
height: "100%",
|
|
1179
|
+
minHeight: theme.spacing(3),
|
|
1180
|
+
paddingLeft: theme.spacing(1),
|
|
1181
|
+
backgroundColor: theme.palette.grid?.sectionHeader,
|
|
1182
|
+
border: "1px solid",
|
|
1183
|
+
borderColor: alpha(`${theme.palette.divider}`, 0.1),
|
|
1184
|
+
overflow: "visible",
|
|
1185
|
+
borderRadius: theme.spacing(1)
|
|
1186
|
+
}));
|
|
1187
|
+
const AplyedFilterStyled = styled("div")(({
|
|
1188
|
+
theme
|
|
1189
|
+
}) => ({
|
|
1190
|
+
...theme.typography.body2,
|
|
1191
|
+
display: "flex",
|
|
1192
|
+
justifyContent: "center",
|
|
1193
|
+
alignItems: "center",
|
|
1194
|
+
width: "auto",
|
|
1195
|
+
height: "100%",
|
|
1196
|
+
marginRight: theme.spacing(1),
|
|
1197
|
+
marginLeft: theme.spacing(1),
|
|
1198
|
+
whiteSpace: "nowrap"
|
|
1199
|
+
}));
|
|
1200
|
+
const ContainerField = styled("span")(({
|
|
1201
|
+
theme
|
|
1202
|
+
}) => ({
|
|
1203
|
+
...theme.typography.subtitle2
|
|
1204
|
+
}));
|
|
1205
|
+
const ContainerOperator = styled("span")(({
|
|
1206
|
+
theme
|
|
1207
|
+
}) => ({
|
|
1208
|
+
...theme.typography.body2,
|
|
1209
|
+
marginLeft: theme.spacing(1.5),
|
|
1210
|
+
fontStyle: "italic"
|
|
1211
|
+
}));
|
|
1212
|
+
const ContainerOperands = styled("span")(({
|
|
1213
|
+
theme
|
|
1214
|
+
}) => ({
|
|
1215
|
+
...theme.typography.body2,
|
|
1216
|
+
marginLeft: theme.spacing(1.5)
|
|
1217
|
+
}));
|
|
1218
|
+
function ApplyedFilter(props) {
|
|
1219
|
+
const {
|
|
1220
|
+
id,
|
|
1221
|
+
fixed,
|
|
1222
|
+
field,
|
|
1223
|
+
isSetted
|
|
1224
|
+
} = props;
|
|
1225
|
+
const classesApplyedFilter = useDynamicFilter((state) => state.classes.applyedFilter);
|
|
1226
|
+
const formatters = useFormatter();
|
|
1227
|
+
const {
|
|
1228
|
+
getLabel
|
|
1229
|
+
} = useModuleDictionary();
|
|
1230
|
+
const {
|
|
1231
|
+
host_static_assets,
|
|
1232
|
+
environment_assets
|
|
1233
|
+
} = useEnvironment();
|
|
1234
|
+
const {
|
|
1235
|
+
removeFilter,
|
|
1236
|
+
hidePopoverFilter: hidePopupEdit,
|
|
1237
|
+
showPopoverFilterForEdit: showPopupForEdit
|
|
1238
|
+
} = useDynamicFilter((state) => state.actions);
|
|
1239
|
+
const labels = useMemo(() => {
|
|
1240
|
+
return getLabelsFilter(props, getLabel, formatters);
|
|
1241
|
+
}, [props]);
|
|
1242
|
+
const urlIcon = useMemo(() => {
|
|
1243
|
+
return field.urlIcon;
|
|
1244
|
+
}, [field]);
|
|
1245
|
+
const onDelete = () => {
|
|
1246
|
+
hidePopupEdit(false);
|
|
1247
|
+
removeFilter(id);
|
|
1248
|
+
};
|
|
1249
|
+
const onClick = (event) => {
|
|
1250
|
+
hidePopupEdit(false);
|
|
1251
|
+
const currentTarget = event.currentTarget;
|
|
1252
|
+
setTimeout(() => showPopupForEdit(currentTarget, props), 10);
|
|
1253
|
+
};
|
|
1254
|
+
return /* @__PURE__ */ jsxs(WrapperApplyedFilter, {
|
|
1255
|
+
className: clsx(classesApplyedFilter, !isSetted ? "noSetted" : null),
|
|
1256
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
1257
|
+
[TEST_PROP_ID]: getTestIdByClass("applyedFilter", field.name)
|
|
1258
|
+
} : {},
|
|
1259
|
+
children: [urlIcon && /* @__PURE__ */ jsx(IconButton, {
|
|
1260
|
+
src: urlIcon,
|
|
1261
|
+
onClick
|
|
1262
|
+
}), /* @__PURE__ */ jsxs(AplyedFilterStyled, {
|
|
1263
|
+
onClick,
|
|
1264
|
+
children: [/* @__PURE__ */ jsx(ContainerField, {
|
|
1265
|
+
children: labels.labelField
|
|
1266
|
+
}), /* @__PURE__ */ jsx(ContainerOperator, {
|
|
1267
|
+
children: labels.labelOperator
|
|
1268
|
+
}), /* @__PURE__ */ jsx(ContainerOperands, {
|
|
1269
|
+
children: labels.labelOperands
|
|
1270
|
+
})]
|
|
1271
|
+
}), !fixed && /* @__PURE__ */ jsx(IconButton, {
|
|
1272
|
+
size: "small",
|
|
1273
|
+
src: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/clear.svg`,
|
|
1274
|
+
onClick: onDelete,
|
|
1275
|
+
dictionaryTooltip: "dynamic_filter.tooltip_clear_filter"
|
|
1276
|
+
})]
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
function ApplyedFilters() {
|
|
1280
|
+
const classesWrapperApplyedFilters = useDynamicFilter((state) => state.classes.wrapperApplyedFilters, shallow);
|
|
1281
|
+
const classesContainerApplyedFilters = useDynamicFilter((state) => state.classes.containerApplyedFilters, shallow);
|
|
1282
|
+
const applyedFilters = useDynamicFilter((state) => state.applyedFilters, shallow);
|
|
1283
|
+
const isSkeleton = useModuleSkeleton();
|
|
1284
|
+
if (isSkeleton) {
|
|
1285
|
+
return /* @__PURE__ */ jsx(WrapperApplyedFilters, {
|
|
1286
|
+
className: classesWrapperApplyedFilters
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
return /* @__PURE__ */ jsx(WrapperApplyedFilters, {
|
|
1290
|
+
className: classesWrapperApplyedFilters,
|
|
1291
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
1292
|
+
[TEST_PROP_ID]: getTestIdByClass("wrapperApplyedFilters")
|
|
1293
|
+
} : {},
|
|
1294
|
+
children: /* @__PURE__ */ jsx(ScrollBar, {
|
|
1295
|
+
children: /* @__PURE__ */ jsx(ContainerApplyedFilters, {
|
|
1296
|
+
className: classesContainerApplyedFilters,
|
|
1297
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
1298
|
+
[TEST_PROP_ID]: getTestIdByClass("containerApplyedFilters")
|
|
1299
|
+
} : {},
|
|
1300
|
+
children: [...applyedFilters].sort((a, b) => a.isSetted === b.isSetted ? 0 : a.isSetted ? -1 : 1).reverse().map((filter) => /* @__PURE__ */ jsx(ApplyedFilter, {
|
|
1301
|
+
...filter
|
|
1302
|
+
}, filter.id))
|
|
1303
|
+
})
|
|
1304
|
+
})
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
const SKTClearFilters = styled$1("div")(({
|
|
1308
|
+
theme
|
|
1309
|
+
}) => ({
|
|
1310
|
+
display: "flex",
|
|
1311
|
+
justifyContent: "center",
|
|
1312
|
+
alignItems: "center",
|
|
1313
|
+
minWidth: theme.spacing(3.75),
|
|
1314
|
+
height: theme.spacing(3.75)
|
|
1315
|
+
}));
|
|
1316
|
+
const WrapperClearFilters = styled$1("div")(({
|
|
1317
|
+
theme
|
|
1318
|
+
}) => ({
|
|
1319
|
+
paddingLeft: theme.spacing(0.5),
|
|
1320
|
+
borderLeft: `1px solid ${theme.palette.divider}`
|
|
1321
|
+
}));
|
|
1322
|
+
const ClearFilters = () => {
|
|
1323
|
+
const {
|
|
1324
|
+
host_static_assets,
|
|
1325
|
+
environment_assets
|
|
1326
|
+
} = useEnvironment();
|
|
1327
|
+
const isSkeleton = useModuleSkeleton();
|
|
1328
|
+
const {
|
|
1329
|
+
clearFilters,
|
|
1330
|
+
hidePopoverFilter: hidePopupEdit
|
|
1331
|
+
} = useDynamicFilter((state) => state.actions);
|
|
1332
|
+
const applyedFilters = useDynamicFilter((state) => state.applyedFilters, shallow);
|
|
1333
|
+
const clearFiltersClasses = useDynamicFilter((state) => state.classes.clearFilters, shallow);
|
|
1334
|
+
if (isSkeleton) {
|
|
1335
|
+
return /* @__PURE__ */ jsx(SKTClearFilters, {
|
|
1336
|
+
children: /* @__PURE__ */ jsx(Skeleton, {
|
|
1337
|
+
variant: "circular",
|
|
1338
|
+
width: "20px",
|
|
1339
|
+
height: "20px"
|
|
1340
|
+
})
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
const onClickClearFilters = () => {
|
|
1344
|
+
hidePopupEdit(false);
|
|
1345
|
+
clearFilters();
|
|
1346
|
+
};
|
|
1347
|
+
if (applyedFilters.findIndex((f) => f.fixed == false) > -1) {
|
|
1348
|
+
return /* @__PURE__ */ jsx(WrapperClearFilters, {
|
|
1349
|
+
className: clearFiltersClasses,
|
|
1350
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1351
|
+
src: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/clear.svg`,
|
|
1352
|
+
onClick: onClickClearFilters,
|
|
1353
|
+
dictionaryTooltip: "dynamic_filter.tooltip_clear_filters"
|
|
1354
|
+
})
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
return null;
|
|
1358
|
+
};
|
|
1359
|
+
const SKTWrapperFilterButton = styled("div")(({
|
|
1360
|
+
theme
|
|
1361
|
+
}) => ({
|
|
1362
|
+
display: "flex",
|
|
1363
|
+
justifyContent: "center",
|
|
1364
|
+
alignItems: "center",
|
|
1365
|
+
minWidth: theme.spacing(3.75),
|
|
1366
|
+
height: theme.spacing(3.75),
|
|
1367
|
+
background: alpha$1(theme.palette.primary.main, 0.3)
|
|
1368
|
+
}));
|
|
1369
|
+
styled("div")(() => ({
|
|
1370
|
+
display: "block"
|
|
1371
|
+
}));
|
|
1372
|
+
function FilterButton() {
|
|
1373
|
+
const automatic = useDynamicFilter((state) => state.automatic);
|
|
1374
|
+
const isValid = useDynamicFilter((state) => state.ownerState.isValid);
|
|
1375
|
+
const isDirty = useDynamicFilter((state) => state.ownerState.isDirty);
|
|
1376
|
+
const {
|
|
1377
|
+
fireOnChangeFilters
|
|
1378
|
+
} = useDynamicFilter((state) => state.actions);
|
|
1379
|
+
const classesFilterButton = useDynamicFilter((state) => state.classes.filterButton);
|
|
1380
|
+
const isSkeleton = useModuleSkeleton();
|
|
1381
|
+
const {
|
|
1382
|
+
host_static_assets,
|
|
1383
|
+
environment_assets
|
|
1384
|
+
} = useEnvironment();
|
|
1385
|
+
if (isSkeleton) {
|
|
1386
|
+
return /* @__PURE__ */ jsx(SKTWrapperFilterButton, {
|
|
1387
|
+
children: /* @__PURE__ */ jsx(Skeleton, {
|
|
1388
|
+
variant: "circular",
|
|
1389
|
+
width: 20,
|
|
1390
|
+
height: 20
|
|
1391
|
+
})
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
return /* @__PURE__ */ jsx(IconButton, {
|
|
1395
|
+
className: classesFilterButton,
|
|
1396
|
+
bgColor: "primary.main",
|
|
1397
|
+
dictionaryTooltip: getDynamicFilterDictionary(isValid ? isDirty ? DICCTIONARY.filter_tooltip_dirty : DICCTIONARY.filter_tooltip_refresh : DICCTIONARY.filter_tooltip_invalid),
|
|
1398
|
+
onClick: fireOnChangeFilters,
|
|
1399
|
+
"aria-label": "settings",
|
|
1400
|
+
src: `${host_static_assets}/${environment_assets}/${ASSETS_URL}/${automatic ? ASSETS.refresh : ASSETS.search}`
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
function PopoverMenuFields(props) {
|
|
1404
|
+
const {
|
|
1405
|
+
selectFieldIndex,
|
|
1406
|
+
fields
|
|
1407
|
+
} = props;
|
|
1408
|
+
const fnAnchorEl = useDynamicFilter((state) => state.fnAnchorEl, shallow);
|
|
1409
|
+
const classesPopUpMenuFields = useDynamicFilter((state) => state.classes.popUpMenuFields, shallow);
|
|
1410
|
+
const classespopoverMenuFieldsItem = useDynamicFilter((state) => state.classes.popoverMenuFieldsItem, shallow);
|
|
1411
|
+
const {
|
|
1412
|
+
showPopoverFilterForAdd,
|
|
1413
|
+
closePopoverMenuFields
|
|
1414
|
+
} = useDynamicFilter((state) => state.actions, shallow);
|
|
1415
|
+
const handleClosePopover = () => {
|
|
1416
|
+
closePopoverMenuFields(false);
|
|
1417
|
+
};
|
|
1418
|
+
const handleOpenPopUpClickItem = (_event, field) => {
|
|
1419
|
+
if (fnAnchorEl) {
|
|
1420
|
+
showPopoverFilterForAdd(fnAnchorEl(), field);
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
return /* @__PURE__ */ jsx(Popover, {
|
|
1424
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
1425
|
+
[TEST_PROP_ID]: getTestIdByClass("popUpMenuFields")
|
|
1426
|
+
} : {},
|
|
1427
|
+
disableRestoreFocus: true,
|
|
1428
|
+
className: classesPopUpMenuFields,
|
|
1429
|
+
open: Boolean(fnAnchorEl),
|
|
1430
|
+
anchorEl: fnAnchorEl && fnAnchorEl(),
|
|
1431
|
+
onClose: handleClosePopover,
|
|
1432
|
+
anchorOrigin: {
|
|
1433
|
+
vertical: "bottom",
|
|
1434
|
+
horizontal: "left"
|
|
1435
|
+
},
|
|
1436
|
+
transformOrigin: {
|
|
1437
|
+
vertical: "top",
|
|
1438
|
+
horizontal: "left"
|
|
1439
|
+
},
|
|
1440
|
+
disableAutoFocus: true,
|
|
1441
|
+
arrowType: "top-left",
|
|
1442
|
+
sx: {
|
|
1443
|
+
"& .MuiMenuItem-root": {
|
|
1444
|
+
px: 1,
|
|
1445
|
+
typography: "body2",
|
|
1446
|
+
borderRadius: 0.75
|
|
1447
|
+
},
|
|
1448
|
+
mt: "16px"
|
|
1449
|
+
},
|
|
1450
|
+
children: Boolean(fnAnchorEl) && fields.map((field, index) => /* @__PURE__ */ createElement(MenuItem, {
|
|
1451
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
1452
|
+
[TEST_PROP_ID]: getTestIdByClass("popoverMenuFieldsItem", field.name)
|
|
1453
|
+
} : {},
|
|
1454
|
+
className: classespopoverMenuFieldsItem,
|
|
1455
|
+
key: `menu_action_${index}`,
|
|
1456
|
+
dense: true,
|
|
1457
|
+
onClick: (event) => handleOpenPopUpClickItem(event, field),
|
|
1458
|
+
selected: index === selectFieldIndex
|
|
1459
|
+
}, /* @__PURE__ */ jsx(Icon, {
|
|
1460
|
+
src: field.urlIcon
|
|
1461
|
+
}), /* @__PURE__ */ jsx(LabelMemuItem, {
|
|
1462
|
+
children: field.dictionaryId
|
|
1463
|
+
})))
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
const WrapperInputFilter = styled("div")(({
|
|
1467
|
+
theme
|
|
1468
|
+
}) => ({
|
|
1469
|
+
display: "flex",
|
|
1470
|
+
justifyContent: "center",
|
|
1471
|
+
alignItems: "center",
|
|
1472
|
+
width: "100%",
|
|
1473
|
+
height: theme.spacing(3),
|
|
1474
|
+
borderLeft: `1px solid ${theme.palette.divider}`,
|
|
1475
|
+
paddingLeft: theme.spacing(1),
|
|
1476
|
+
marginLeft: theme.spacing(1),
|
|
1477
|
+
[theme.breakpoints.up("sm")]: {
|
|
1478
|
+
width: theme.spacing(25)
|
|
1479
|
+
},
|
|
1480
|
+
"& > input": {
|
|
1481
|
+
background: "transparent",
|
|
1482
|
+
display: "flex",
|
|
1483
|
+
justifyContent: "center",
|
|
1484
|
+
alignItems: "center",
|
|
1485
|
+
minWidth: theme.spacing(3.75),
|
|
1486
|
+
width: "100%",
|
|
1487
|
+
outline: "none",
|
|
1488
|
+
border: "none",
|
|
1489
|
+
[theme.breakpoints.up("sm")]: {
|
|
1490
|
+
width: "auto"
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
}));
|
|
1494
|
+
function InputFilter() {
|
|
1495
|
+
const anchorEl = useDynamicFilter((state) => state.fnAnchorEl, shallow);
|
|
1496
|
+
useDynamicFilter((state) => state.popoverFilterData, shallow);
|
|
1497
|
+
const withAllField = useDynamicFilter((state) => state.withAllField);
|
|
1498
|
+
const inputData = useDynamicFilter((state) => state.inputData);
|
|
1499
|
+
const availableFields = useDynamicFilter((state) => state.availableFields, shallow);
|
|
1500
|
+
const classesContainerInputFilter = useDynamicFilter((state) => state.classes.containerInputFilter, shallow);
|
|
1501
|
+
const {
|
|
1502
|
+
showPopoverFilterForAdd,
|
|
1503
|
+
addFilter,
|
|
1504
|
+
openPopoverMenuFields,
|
|
1505
|
+
closePopoverMenuFields,
|
|
1506
|
+
hidePopoverFilter,
|
|
1507
|
+
getFieldByName,
|
|
1508
|
+
getNewId,
|
|
1509
|
+
setInEdition,
|
|
1510
|
+
setInputData
|
|
1511
|
+
} = useDynamicFilter((state) => state.actions, shallow);
|
|
1512
|
+
const isSkeleton = useModuleSkeleton();
|
|
1513
|
+
const {
|
|
1514
|
+
getLabel
|
|
1515
|
+
} = useModuleDictionary();
|
|
1516
|
+
const [selectFieldIndex, setSelectFieldIndex] = useState(-1);
|
|
1517
|
+
const [finalFields, setFinalFields] = useState([]);
|
|
1518
|
+
useEffect(() => {
|
|
1519
|
+
if (!anchorEl) {
|
|
1520
|
+
setFinalFields([]);
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
setFinalFields(availableFields.filter((field) => field.dictionaryId.includes(inputData)));
|
|
1524
|
+
setSelectFieldIndex(-1);
|
|
1525
|
+
}, [anchorEl, inputData, availableFields]);
|
|
1526
|
+
const handleOpenPopUpClickItem = (field) => {
|
|
1527
|
+
closePopoverMenuFields();
|
|
1528
|
+
if (anchorEl)
|
|
1529
|
+
showPopoverFilterForAdd(anchorEl(), field);
|
|
1530
|
+
};
|
|
1531
|
+
const onFocusInputFilter = (event) => {
|
|
1532
|
+
openPopoverMenuFields(event.currentTarget);
|
|
1533
|
+
setInEdition(true);
|
|
1534
|
+
};
|
|
1535
|
+
const onChangeInputFilter = (event) => {
|
|
1536
|
+
setInputData(event.target.value);
|
|
1537
|
+
if (!anchorEl) {
|
|
1538
|
+
openPopoverMenuFields(event.currentTarget);
|
|
1539
|
+
}
|
|
1540
|
+
hidePopoverFilter(true);
|
|
1541
|
+
};
|
|
1542
|
+
const handleKeyDown = (event) => {
|
|
1543
|
+
if (event.key === "ArrowDown") {
|
|
1544
|
+
let newIndex = -1;
|
|
1545
|
+
if (finalFields.length > 0) {
|
|
1546
|
+
if (selectFieldIndex < finalFields.length - 1) {
|
|
1547
|
+
newIndex = selectFieldIndex + 1;
|
|
1548
|
+
} else {
|
|
1549
|
+
newIndex = finalFields.length - 1;
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
setSelectFieldIndex(newIndex);
|
|
1553
|
+
}
|
|
1554
|
+
if (event.key === "ArrowUp") {
|
|
1555
|
+
let newIndex = -1;
|
|
1556
|
+
if (finalFields.length > 0) {
|
|
1557
|
+
if (selectFieldIndex > -1) {
|
|
1558
|
+
newIndex = selectFieldIndex - 1;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
setSelectFieldIndex(newIndex);
|
|
1562
|
+
}
|
|
1563
|
+
if (event.key === "Escape") {
|
|
1564
|
+
closePopoverMenuFields();
|
|
1565
|
+
}
|
|
1566
|
+
if (event.key !== "Enter")
|
|
1567
|
+
return;
|
|
1568
|
+
if (selectFieldIndex === -1) {
|
|
1569
|
+
if (inputData.trim() === "") {
|
|
1570
|
+
closePopoverMenuFields();
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
if (withAllField) {
|
|
1574
|
+
addFilter({
|
|
1575
|
+
id: getNewId(),
|
|
1576
|
+
fieldType: "string",
|
|
1577
|
+
field: getFieldByName(ALL_FIELDS.name),
|
|
1578
|
+
isSetted: true,
|
|
1579
|
+
fixed: false,
|
|
1580
|
+
operator: "c",
|
|
1581
|
+
operand1: inputData
|
|
1582
|
+
});
|
|
1583
|
+
setInputData("");
|
|
1584
|
+
closePopoverMenuFields();
|
|
1585
|
+
}
|
|
1586
|
+
} else {
|
|
1587
|
+
handleOpenPopUpClickItem(finalFields[selectFieldIndex]);
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
if (isSkeleton) {
|
|
1591
|
+
return /* @__PURE__ */ jsx(WrapperInputFilter, {
|
|
1592
|
+
children: /* @__PURE__ */ jsx(Skeleton, {
|
|
1593
|
+
variant: "text",
|
|
1594
|
+
width: "100%",
|
|
1595
|
+
height: 24
|
|
1596
|
+
})
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
if (!withAllField && availableFields.length == 0) {
|
|
1600
|
+
return null;
|
|
1601
|
+
}
|
|
1602
|
+
return /* @__PURE__ */ jsxs(WrapperInputFilter, {
|
|
1603
|
+
className: classesContainerInputFilter,
|
|
1604
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
1605
|
+
[TEST_PROP_ID]: getTestIdByClass("containerInputFilter")
|
|
1606
|
+
} : {},
|
|
1607
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
1608
|
+
type: "text",
|
|
1609
|
+
value: inputData,
|
|
1610
|
+
placeholder: getLabel(getDynamicFilterDictionary("input_placeholder")),
|
|
1611
|
+
onFocus: onFocusInputFilter,
|
|
1612
|
+
onChange: onChangeInputFilter,
|
|
1613
|
+
onKeyDown: handleKeyDown
|
|
1614
|
+
}), /* @__PURE__ */ jsx(PopoverMenuFields, {
|
|
1615
|
+
selectFieldIndex,
|
|
1616
|
+
fields: finalFields
|
|
1617
|
+
})]
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
const TitleContainer = styled$2("div")(({
|
|
1621
|
+
theme
|
|
1622
|
+
}) => ({
|
|
1623
|
+
...theme.typography.subtitle2,
|
|
1624
|
+
width: "100%",
|
|
1625
|
+
display: "flex",
|
|
1626
|
+
justifyContent: "flex-start",
|
|
1627
|
+
alignItems: "center",
|
|
1628
|
+
padding: theme.spacing(2, 0),
|
|
1629
|
+
marginLeft: theme.spacing(1.5)
|
|
1630
|
+
}));
|
|
1631
|
+
const StyledHeaderFilter = styled$2("div")(({
|
|
1632
|
+
theme
|
|
1633
|
+
}) => ({
|
|
1634
|
+
width: "100%",
|
|
1635
|
+
display: "flex",
|
|
1636
|
+
justifyContent: "flex-start",
|
|
1637
|
+
alignItems: "center",
|
|
1638
|
+
borderBottom: `1px solid ${theme.palette.divider}`
|
|
1639
|
+
}));
|
|
1640
|
+
const PopoverFilter = () => {
|
|
1641
|
+
let popupValidationSchema;
|
|
1642
|
+
let field;
|
|
1643
|
+
let formFilter;
|
|
1644
|
+
let filterFormValue;
|
|
1645
|
+
let anchorEl;
|
|
1646
|
+
const popoverFilterData = useDynamicFilter((state) => state.popoverFilterData, shallow);
|
|
1647
|
+
const refPreviousPopoverFilterData = useRef(popoverFilterData);
|
|
1648
|
+
const classesPopoverFilterPapper = useDynamicFilter((state) => state.classes.popoverFilterPaper, shallow);
|
|
1649
|
+
const classesPopoverFilterHeader = useDynamicFilter((state) => state.classes.popoverFilterHeader, shallow);
|
|
1650
|
+
const {
|
|
1651
|
+
hidePopoverFilter,
|
|
1652
|
+
addFilter,
|
|
1653
|
+
updateFilter,
|
|
1654
|
+
getNewId
|
|
1655
|
+
} = useDynamicFilter((state) => state.actions);
|
|
1656
|
+
const {
|
|
1657
|
+
getLabel
|
|
1658
|
+
} = useModuleDictionary();
|
|
1659
|
+
const onClose = useCallback(() => {
|
|
1660
|
+
hidePopoverFilter(false);
|
|
1661
|
+
}, []);
|
|
1662
|
+
const handleKeyDownPopper = useCallback((event) => {
|
|
1663
|
+
if (event.key === "Escape") {
|
|
1664
|
+
onClose();
|
|
1665
|
+
}
|
|
1666
|
+
}, []);
|
|
1667
|
+
const statusLoad = useMemo(() => {
|
|
1668
|
+
let returnStatus;
|
|
1669
|
+
if (popoverFilterData && refPreviousPopoverFilterData.current === void 0) {
|
|
1670
|
+
returnStatus = "ready";
|
|
1671
|
+
} else if (!popoverFilterData) {
|
|
1672
|
+
returnStatus = "initial";
|
|
1673
|
+
} else {
|
|
1674
|
+
returnStatus = "reload_values_provider";
|
|
1675
|
+
}
|
|
1676
|
+
refPreviousPopoverFilterData.current = popoverFilterData;
|
|
1677
|
+
return returnStatus;
|
|
1678
|
+
}, [popoverFilterData]);
|
|
1679
|
+
if (!popoverFilterData) {
|
|
1680
|
+
return null;
|
|
1681
|
+
}
|
|
1682
|
+
if (popoverFilterData.openFor === "add") {
|
|
1683
|
+
popupValidationSchema = getSchemaValidations(popoverFilterData.field, getLabel);
|
|
1684
|
+
field = popoverFilterData.field;
|
|
1685
|
+
anchorEl = popoverFilterData.fnAnchorEl();
|
|
1686
|
+
filterFormValue = getFormValue(field, getLabel);
|
|
1687
|
+
formFilter = {
|
|
1688
|
+
field,
|
|
1689
|
+
id: getNewId(),
|
|
1690
|
+
isSetted: true,
|
|
1691
|
+
fixed: false,
|
|
1692
|
+
...filterFormValue
|
|
1693
|
+
};
|
|
1694
|
+
} else {
|
|
1695
|
+
field = popoverFilterData.filter.field;
|
|
1696
|
+
anchorEl = popoverFilterData.fnAnchorEl();
|
|
1697
|
+
popupValidationSchema = getSchemaValidations(popoverFilterData.filter.field, getLabel);
|
|
1698
|
+
filterFormValue = getFormValue(field, getLabel, popoverFilterData.filter);
|
|
1699
|
+
formFilter = {
|
|
1700
|
+
...popoverFilterData.filter,
|
|
1701
|
+
...filterFormValue
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
const onSubmit = async (data) => {
|
|
1705
|
+
const newFilter = {
|
|
1706
|
+
...formFilter,
|
|
1707
|
+
...getFilterFromFormValue({
|
|
1708
|
+
...filterFormValue,
|
|
1709
|
+
...data
|
|
1710
|
+
})
|
|
1711
|
+
};
|
|
1712
|
+
if (popoverFilterData?.openFor === "add") {
|
|
1713
|
+
addFilter(newFilter);
|
|
1714
|
+
} else {
|
|
1715
|
+
updateFilter(newFilter);
|
|
1716
|
+
}
|
|
1717
|
+
hidePopoverFilter(false);
|
|
1718
|
+
};
|
|
1719
|
+
const handleClosePopover = () => {
|
|
1720
|
+
hidePopoverFilter(false);
|
|
1721
|
+
};
|
|
1722
|
+
return /* @__PURE__ */ jsx(Popover, {
|
|
1723
|
+
open: true,
|
|
1724
|
+
anchorEl,
|
|
1725
|
+
disableRestoreFocus: true,
|
|
1726
|
+
onKeyDown: handleKeyDownPopper,
|
|
1727
|
+
onClose: handleClosePopover,
|
|
1728
|
+
anchorOrigin: {
|
|
1729
|
+
vertical: "bottom",
|
|
1730
|
+
horizontal: "left"
|
|
1731
|
+
},
|
|
1732
|
+
transformOrigin: {
|
|
1733
|
+
vertical: "top",
|
|
1734
|
+
horizontal: "left"
|
|
1735
|
+
},
|
|
1736
|
+
arrowType: "top-left",
|
|
1737
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
1738
|
+
[TEST_PROP_ID]: getTestIdByClass("popoverFilterPaper")
|
|
1739
|
+
} : {},
|
|
1740
|
+
PaperProps: {
|
|
1741
|
+
className: classesPopoverFilterPapper,
|
|
1742
|
+
sx: {
|
|
1743
|
+
mt: "12px"
|
|
1744
|
+
}
|
|
1745
|
+
},
|
|
1746
|
+
children: /* @__PURE__ */ jsxs(RHFormProvider, {
|
|
1747
|
+
onSubmit,
|
|
1748
|
+
values: filterFormValue,
|
|
1749
|
+
validationSchema: popupValidationSchema,
|
|
1750
|
+
statusLoad,
|
|
1751
|
+
children: [/* @__PURE__ */ jsxs(StyledHeaderFilter, {
|
|
1752
|
+
className: classesPopoverFilterHeader,
|
|
1753
|
+
children: [field.urlIcon && /* @__PURE__ */ jsx(Icon, {
|
|
1754
|
+
src: field.urlIcon
|
|
1755
|
+
}), /* @__PURE__ */ jsx(TitleContainer, {
|
|
1756
|
+
children: getLabel(field.dictionaryId)
|
|
1757
|
+
})]
|
|
1758
|
+
}), /* @__PURE__ */ jsx(DataTypeComponent, {
|
|
1759
|
+
formFilter,
|
|
1760
|
+
statusLoad
|
|
1761
|
+
}), /* @__PURE__ */ jsxs(Actions, {
|
|
1762
|
+
children: [/* @__PURE__ */ jsx(ActionCancel, {
|
|
1763
|
+
onClick: onClose
|
|
1764
|
+
}), /* @__PURE__ */ jsx(ActionIntro, {})]
|
|
1765
|
+
})]
|
|
1766
|
+
})
|
|
1767
|
+
});
|
|
1768
|
+
};
|
|
1769
|
+
const InnerForHooks = () => {
|
|
1770
|
+
const isMobile = useDynamicFilter((state) => state.ownerState.isMobile, shallow);
|
|
1771
|
+
const classesRoot = useDynamicFilter((state) => state.classes.root, shallow);
|
|
1772
|
+
const classesContainerFistRow = useDynamicFilter((state) => state.classes.containerFistRow, shallow);
|
|
1773
|
+
const fields = useDynamicFilter((state) => state.fields, shallow);
|
|
1774
|
+
return /* @__PURE__ */ jsx(DynamicFilterRoot, {
|
|
1775
|
+
"data-testid": "DynamicFilter",
|
|
1776
|
+
className: classesRoot,
|
|
1777
|
+
...process.env.NODE_ENV !== "production" ? {
|
|
1778
|
+
[TEST_PROP_FIELDS]: fields
|
|
1779
|
+
} : {},
|
|
1780
|
+
children: !isMobile ? /* @__PURE__ */ jsxs(Fragment, {
|
|
1781
|
+
children: [/* @__PURE__ */ jsx(FilterButton, {}), /* @__PURE__ */ jsx(InputFilter, {}), /* @__PURE__ */ jsx(ApplyedFilters, {}), /* @__PURE__ */ jsx(PopoverFilter, {}), /* @__PURE__ */ jsx(ClearFilters, {})]
|
|
1782
|
+
}) : /* @__PURE__ */ jsxs(Fragment, {
|
|
1783
|
+
children: [/* @__PURE__ */ jsxs(ContainerFistRow, {
|
|
1784
|
+
className: classesContainerFistRow,
|
|
1785
|
+
children: [/* @__PURE__ */ jsx(FilterButton, {}), /* @__PURE__ */ jsx(InputFilter, {}), /* @__PURE__ */ jsx(ClearFilters, {})]
|
|
1786
|
+
}), /* @__PURE__ */ jsx(ApplyedFilters, {}), /* @__PURE__ */ jsx(PopoverFilter, {})]
|
|
1787
|
+
})
|
|
1788
|
+
});
|
|
1789
|
+
};
|
|
1790
|
+
const DynamicFilter = (inProps) => {
|
|
1791
|
+
const render = useFlagsPresent([CommonFlags.FLAG_DICTIONARY_LOADED]);
|
|
1792
|
+
if (!render) {
|
|
1793
|
+
return null;
|
|
1794
|
+
}
|
|
1795
|
+
return /* @__PURE__ */ jsx(DynamicFilterProvider, {
|
|
1796
|
+
...inProps,
|
|
1797
|
+
children: /* @__PURE__ */ jsx(InnerForHooks, {})
|
|
1798
|
+
});
|
|
1799
|
+
};
|
|
1800
|
+
export {
|
|
1801
|
+
DynamicFilter as D,
|
|
1802
|
+
LABEL_FILTER_BUTTON as L,
|
|
1803
|
+
DYNAMICFILTER_DICTIONARY_ID as a,
|
|
1804
|
+
DICCTIONARY as b,
|
|
1805
|
+
getDynamicFilterDictionary as c,
|
|
1806
|
+
defaultDynamicFilterDictionary as d,
|
|
1807
|
+
getDynamicFilterComponentsDictionary as g
|
|
1808
|
+
};
|