@m4l/components 0.1.27 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/assets/Logo/index.228dcb5a.js +42 -35
  2. package/commonjs.565e6834.js +5 -5
  3. package/components/CommonActions/components/ActionCancel/index.a57fcfae.js +17 -0
  4. package/components/CommonActions/components/ActionFormCancel/index.b8215cd2.js +64 -0
  5. package/components/CommonActions/components/ActionFormIntro/index.ca4d2674.js +28 -22
  6. package/components/CommonActions/components/ActionIntro/index.591a8195.js +18 -0
  7. package/components/CommonActions/components/Actions/index.2ce05d29.js +867 -0
  8. package/components/DataGrid/index.07162c02.js +1075 -0
  9. package/components/DynamicFilter/components/PopupEditFilter/styles.d.ts +1 -0
  10. package/components/DynamicFilter/components/fieldstypes/DateTimeFilter/index.d.ts +2 -2
  11. package/components/DynamicFilter/components/fieldstypes/factory.d.ts +2 -2
  12. package/components/DynamicFilter/index.31876c9f.js +1582 -0
  13. package/components/ErrorLabel/index.c8615f16.js +13 -12
  14. package/components/Icon/index.619c31c4.js +65 -53
  15. package/components/Image/index.93d5f37f.js +190 -0
  16. package/components/Loadable/index.f5518558.js +8 -8
  17. package/components/ModalDialog/index.3e5675c4.js +186 -0
  18. package/components/NoItemSelected/{index.9609a7f7.js → index.46d2f632.js} +52 -41
  19. package/components/ObjectLogs/index.35dbf836.js +299 -0
  20. package/components/Page/index.4237c241.js +22 -20
  21. package/components/PaperForm/index.ec9cb8c9.js +66 -59
  22. package/components/Period/index.111600f2.js +249 -0
  23. package/components/PropertyValue/index.dfcfe1ba.js +95 -65
  24. package/components/Resizeable/index.45995d2b.js +19 -19
  25. package/components/ScrollBar/index.39eeb2de.js +26 -21
  26. package/components/ScrollToTop/index.e06f98f6.js +8 -7
  27. package/components/SplitLayout/index.4032673d.js +35 -33
  28. package/components/animate/LoadingScreen/index.1d0c4307.js +33 -33
  29. package/components/animate/MotionContainer/index.8d9f9d80.js +25 -22
  30. package/components/animate/MotionLazyContainer/index.572dd012.js +10 -10
  31. package/components/animate/features.0fbf41e1.js +3 -3
  32. package/components/animate/variants/bounce.784aaaaa.js +16 -13
  33. package/components/animate/variants/container.11f82b76.js +8 -6
  34. package/components/animate/variants/fade.b561c0fc.js +32 -28
  35. package/components/animate/variants/transition.bd46b9ce.js +17 -12
  36. package/components/formatters/BooleanFormatter/index.ae70b54f.js +56 -0
  37. package/components/formatters/DateFormatter/index.ed73f8ae.js +67 -0
  38. package/components/formatters/index.9bd10770.js +120 -0
  39. package/components/hook-form/RHFAutocomplete/index.de93fe01.js +279 -0
  40. package/components/hook-form/RHFAutocomplete/styles.d.ts +0 -2
  41. package/components/hook-form/RHFAutocomplete/subcomponents/Skeleton/index.d.ts +3 -0
  42. package/components/hook-form/RHFAutocomplete/subcomponents/Skeleton/styles.d.ts +3 -0
  43. package/components/hook-form/RHFAutocomplete/subcomponents/Skeleton/types.d.ts +4 -0
  44. package/components/hook-form/RHFAutocompleteAsync/index.ca696cce.js +87 -0
  45. package/components/hook-form/RHFCheckbox/index.6dcec9e2.js +49 -39
  46. package/components/hook-form/RHFDateTime/index.e70d2de3.js +107 -0
  47. package/components/hook-form/RHFDateTime/types.d.ts +1 -0
  48. package/components/hook-form/RHFMultiCheckbox/index.2680b3b6.js +23 -23
  49. package/components/hook-form/RHFPeriod/index.fa8426ac.js +55 -0
  50. package/components/hook-form/RHFRadioGroup/index.b3335e13.js +29 -29
  51. package/components/hook-form/RHFSelect/index.b6ca8bb2.js +24 -24
  52. package/components/hook-form/RHFTextField/index.f9aaaa90.js +110 -93
  53. package/components/hook-form/RHFUpload/{index.ec4d5326.js → index.d5cc7c13.js} +151 -130
  54. package/components/mui_extended/Accordion/index.a02ac6ae.js +73 -69
  55. package/components/mui_extended/Avatar/index.fe06afd7.js +44 -34
  56. package/components/mui_extended/BoxIcon/index.e638ecc8.js +10 -10
  57. package/components/mui_extended/Breadcrumbs/index.5e37d903.js +49 -44
  58. package/components/mui_extended/Button/index.1d13f53b.js +178 -0
  59. package/components/mui_extended/CircularProgress/index.ad569afd.js +8 -6
  60. package/components/mui_extended/IconButton/index.a321e5cb.js +82 -67
  61. package/components/mui_extended/LinkWithRoute/index.16436ab8.js +25 -21
  62. package/components/mui_extended/Pager/index.72b43352.js +141 -0
  63. package/components/mui_extended/Popover/index.028756ac.js +278 -0
  64. package/components/mui_extended/Tab/index.e0653a0a.js +25 -21
  65. package/components/mui_extended/Typography/index.e5494696.js +25 -21
  66. package/contexts/ModalContext/index.cc3690d3.js +148 -0
  67. package/contexts/ModalContext/{components → subcomponents}/ContentConfirm/index.d.ts +0 -0
  68. package/contexts/ModalContext/{components → subcomponents}/ContentConfirm/styles.d.ts +0 -0
  69. package/contexts/ModalContext/{components → subcomponents}/ContentConfirm/types.d.ts +0 -0
  70. package/contexts/ModalContext/types.d.ts +1 -2
  71. package/contexts/RHFormContext/index.f8c00745.js +64 -0
  72. package/hooks/useFormAddEdit/index.d4845f1a.js +40 -22
  73. package/hooks/useModal/index.78ee58f3.js +11 -0
  74. package/index.js +154 -154
  75. package/package.json +2 -1
  76. package/react-data-grid.d46d625e.js +2206 -1663
  77. package/react-draggable.20e95c61.js +800 -553
  78. package/react-json-view.f56a7f8e.js +2344 -2340
  79. package/react-resizable.5277deaf.js +470 -298
  80. package/react-splitter-layout.7810ac1b.js +130 -128
  81. package/utils/index.214d9542.js +500 -354
  82. package/components/CommonActions/components/ActionCancel/index.431160ba.js +0 -17
  83. package/components/CommonActions/components/ActionFormCancel/index.6a0f34aa.js +0 -49
  84. package/components/CommonActions/components/ActionIntro/index.85557b90.js +0 -18
  85. package/components/CommonActions/components/Actions/index.edeb05c2.js +0 -742
  86. package/components/DataGrid/index.2ce9da7d.js +0 -894
  87. package/components/DynamicFilter/index.e1d4a948.js +0 -1157
  88. package/components/Image/index.c9da2d5a.js +0 -152
  89. package/components/ModalDialog/index.ad61757f.js +0 -168
  90. package/components/ObjectLogs/index.6ebaec71.js +0 -266
  91. package/components/Period/index.81de7941.js +0 -175
  92. package/components/contexts/RHFormContext/index.33dba822.js +0 -56
  93. package/components/formatters/BooleanFormatter/index.8da35c9c.js +0 -42
  94. package/components/formatters/DateFormatter/index.1b9baacc.js +0 -57
  95. package/components/formatters/index.c2a9b55d.js +0 -106
  96. package/components/hook-form/RHFAutocomplete/index.5eee9d7c.js +0 -174
  97. package/components/hook-form/RHFAutocompleteAsync/index.757b5080.js +0 -65
  98. package/components/hook-form/RHFDateTime/index.9231a7c7.js +0 -81
  99. package/components/hook-form/RHFPeriod/index.e08fb1ab.js +0 -51
  100. package/components/mui_extended/Button/index.51dae0bb.js +0 -144
  101. package/components/mui_extended/Pager/index.1dc45f5e.js +0 -126
  102. package/components/mui_extended/Popover/index.cb2ccc66.js +0 -252
  103. package/contexts/ModalContext/index.9ebc793c.js +0 -136
  104. package/hooks/useModal/index.34f5978e.js +0 -11
  105. package/node_modules.168cb897.js +0 -55
@@ -0,0 +1,1582 @@
1
+ import { S as ScrollBar } from "../ScrollBar/index.39eeb2de.js";
2
+ import { styled } from "@mui/material/styles";
3
+ import { useRef, useState, useMemo, useCallback, useEffect, createContext, useContext } from "react";
4
+ import { useModuleDictionary, voidFunction, useEnvironment, useHostTools, useFlagsPresent } from "@m4l/core";
5
+ import * as Yup from "yup";
6
+ import { useFormContext, useWatch } from "react-hook-form";
7
+ import { R as RHFAutocomplete } from "../hook-form/RHFAutocomplete/index.de93fe01.js";
8
+ import "lodash/debounce";
9
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
10
+ import "../hook-form/RHFCheckbox/index.6dcec9e2.js";
11
+ import { alpha, styled as styled$1, Skeleton, MenuItem, useTheme, Popper, ClickAwayListener } from "@mui/material";
12
+ import "@mui/x-date-pickers";
13
+ import { R as RHFDateTime } from "../hook-form/RHFDateTime/index.e70d2de3.js";
14
+ import { useFormatter, useResponsiveDesktop } from "@m4l/graphics";
15
+ import { R as RHFTextField } from "../hook-form/RHFTextField/index.f9aaaa90.js";
16
+ import { I as Icon } from "../Icon/index.619c31c4.js";
17
+ import "../hook-form/RHFPeriod/index.fa8426ac.js";
18
+ import "../ErrorLabel/index.c8615f16.js";
19
+ import "../Period/index.111600f2.js";
20
+ import { L as LabelMemuItem, b as Actions, g as getCommonActionsDictionary } from "../CommonActions/components/Actions/index.2ce05d29.js";
21
+ import "@mui/material/Button";
22
+ import "react-router-dom";
23
+ import "../../contexts/ModalContext/index.cc3690d3.js";
24
+ import "@mui/lab";
25
+ import "lodash/isString";
26
+ import "react-dropzone";
27
+ import "../Image/index.93d5f37f.js";
28
+ import "../hook-form/RHFUpload/index.d5cc7c13.js";
29
+ import { I as IconButton } from "../mui_extended/IconButton/index.a321e5cb.js";
30
+ import "simplebar/dist/simplebar.min.css";
31
+ import { F as FilterButton } from "../mui_extended/Button/index.1d13f53b.js";
32
+ import { P as Popover } from "../mui_extended/Popover/index.028756ac.js";
33
+ import { R as RHFormProvider } from "../../contexts/RHFormContext/index.f8c00745.js";
34
+ import { A as ActionCancel } from "../CommonActions/components/ActionCancel/index.a57fcfae.js";
35
+ import { A as ActionIntro } from "../CommonActions/components/ActionIntro/index.591a8195.js";
36
+ const WrapperApplyedFilters = styled("div")(({
37
+ theme
38
+ }) => ({
39
+ width: "100%",
40
+ margin: theme.spacing(0, 1),
41
+ paddingLeft: theme.spacing(1),
42
+ borderLeft: `1px solid ${theme.palette.divider}`
43
+ }));
44
+ const ContainerApplyedFilters = styled("div")(({
45
+ theme
46
+ }) => ({
47
+ width: "100%",
48
+ display: "flex",
49
+ justifyContent: "flex-start",
50
+ alignItems: "center",
51
+ height: "auto",
52
+ gap: theme.spacing(1.5)
53
+ }));
54
+ const STRING_OPERATORS = ["c", "nc"];
55
+ const NUMBER_OPERATORS = ["b", "e", "ne", "gt", "gte", "lt", "lte"];
56
+ const BOOLEAN_OPERATORS = ["e", "ne"];
57
+ const DATE_TIME_OPERATORS = [
58
+ "b",
59
+ "e",
60
+ "ne",
61
+ "gt",
62
+ "gte",
63
+ "lt",
64
+ "lte"
65
+ ];
66
+ const ALL_FIELDS = {
67
+ name: "all",
68
+ label: "dynamic_filter.all_fields",
69
+ urlIcon: "",
70
+ type: "string",
71
+ multiple: true,
72
+ presence: "optional"
73
+ };
74
+ const WrapperStringFilter$1 = styled("div")(({
75
+ theme
76
+ }) => ({
77
+ display: "flex",
78
+ flexDirection: "column",
79
+ justifyContent: "center",
80
+ alignItems: "center",
81
+ width: "100%",
82
+ minWidth: theme.spacing(3.75),
83
+ padding: theme.spacing(3, 0),
84
+ gap: theme.spacing(3)
85
+ }));
86
+ const WrapperAutoComplete$3 = styled("div")(() => ({
87
+ width: "100%"
88
+ }));
89
+ const getDefaultStringFilter = (field, fixed, getLabel) => {
90
+ const dfop1 = field.defaultOperand1;
91
+ const defaultFilter = {
92
+ id: 0,
93
+ n: field.name,
94
+ fixed,
95
+ isSetted: false,
96
+ o: "c",
97
+ labelOperator: "",
98
+ o1: "",
99
+ o2: "",
100
+ labelOperands: ""
101
+ };
102
+ if (dfop1 !== void 0 && typeof dfop1 === "string") {
103
+ defaultFilter.o1 = dfop1;
104
+ }
105
+ defaultFilter.labelOperands = defaultFilter.o1 + "";
106
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
107
+ return defaultFilter;
108
+ };
109
+ function StringFilter() {
110
+ const {
111
+ popupData: {
112
+ filter,
113
+ field
114
+ },
115
+ setPoupEditValidationSchema,
116
+ setFnTransformFormValuesIntoValues: setTransformFunctionFormValuesToValues,
117
+ getLabelOperator
118
+ } = useBase();
119
+ const {
120
+ getLabel
121
+ } = useModuleDictionary();
122
+ const inputRef = useRef(null);
123
+ const {
124
+ setValue
125
+ } = useFormContext();
126
+ const [isLoaded, setIsLoaded] = useState(false);
127
+ const options = useMemo(() => STRING_OPERATORS.map((o) => ({
128
+ id: o,
129
+ label: getLabelOperator(o)
130
+ })), [getLabelOperator]);
131
+ const transformFunctionFormValuesToValues = useCallback((data) => {
132
+ if (!filter || !field)
133
+ return void 0;
134
+ const newFilter = {
135
+ id: filter.id,
136
+ n: field.name,
137
+ fixed: filter.fixed,
138
+ isSetted: true,
139
+ o: data.valueOperator.id,
140
+ labelOperator: data.valueOperator.label,
141
+ o1: data.valueOperand1,
142
+ labelOperands: data.valueOperand1
143
+ };
144
+ return newFilter;
145
+ }, []);
146
+ useEffect(() => {
147
+ if (!isLoaded) {
148
+ setPoupEditValidationSchema({
149
+ valueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
150
+ valueOperand1: Yup.string().required(getLabel(`operand_required`))
151
+ });
152
+ }
153
+ setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
154
+ if (filter && field) {
155
+ setValue("valueOperand1", filter.o1, {
156
+ shouldTouch: false,
157
+ shouldValidate: false
158
+ });
159
+ }
160
+ setIsLoaded(true);
161
+ }, [getLabel, filter, field]);
162
+ useEffect(() => {
163
+ inputRef.current?.focus();
164
+ }, [isLoaded]);
165
+ return /* @__PURE__ */ jsx(WrapperStringFilter$1, {
166
+ children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
167
+ children: [/* @__PURE__ */ jsx(WrapperAutoComplete$3, {
168
+ children: /* @__PURE__ */ jsx(RHFAutocomplete, {
169
+ name: "valueOperator",
170
+ autoComplete: "off",
171
+ options,
172
+ getOptionLabel: (option) => option.label,
173
+ isOptionEqualToValue: (option, value) => option.id === value.id,
174
+ label: ""
175
+ })
176
+ }), /* @__PURE__ */ jsx(RHFTextField, {
177
+ name: "valueOperand1",
178
+ ref: inputRef,
179
+ focused: true
180
+ })]
181
+ })
182
+ });
183
+ }
184
+ const WrapperAllFieldsFilter$1 = styled("div")(({
185
+ theme
186
+ }) => ({
187
+ display: "flex",
188
+ flexDirection: "column",
189
+ justifyContent: "center",
190
+ alignItems: "center",
191
+ width: "100%",
192
+ minWidth: theme.spacing(3.75),
193
+ height: "100%",
194
+ padding: theme.spacing(3, 0),
195
+ gap: theme.spacing(3)
196
+ }));
197
+ const WrapperAutoComplete$2 = styled("div")(() => ({
198
+ width: "100%"
199
+ }));
200
+ const getDefaultBooleanFilter = (field, fixed, getLabel) => {
201
+ const dfop1 = field.defaultOperand1;
202
+ const defaultFilter = {
203
+ id: 0,
204
+ n: field.name,
205
+ fixed,
206
+ isSetted: true,
207
+ o: "e",
208
+ labelOperator: "",
209
+ o1: true,
210
+ o2: "",
211
+ labelOperands: ""
212
+ };
213
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
214
+ if (dfop1 !== void 0 && typeof dfop1 === "boolean") {
215
+ defaultFilter.o1 = dfop1;
216
+ }
217
+ defaultFilter.labelOperands = getLabel(`dynamic_filter.operand_${defaultFilter.o1}`);
218
+ return defaultFilter;
219
+ };
220
+ function BooleanFilter() {
221
+ const {
222
+ setPoupEditValidationSchema,
223
+ setFnTransformFormValuesIntoValues: setTransformFunctionFormValuesToValues,
224
+ getLabelOperator
225
+ } = useBase();
226
+ const {
227
+ getLabel
228
+ } = useModuleDictionary();
229
+ const {
230
+ popupData: {
231
+ filter,
232
+ field
233
+ }
234
+ } = useBase();
235
+ const {
236
+ setValue
237
+ } = useFormContext();
238
+ const [isLoaded, setIsLoaded] = useState(false);
239
+ const operators = useMemo(() => BOOLEAN_OPERATORS.map((o) => ({
240
+ id: o,
241
+ label: getLabelOperator(o)
242
+ })), [getLabelOperator]);
243
+ const optionsYesNo = useMemo(() => [{
244
+ value: true,
245
+ label: getLabel("dynamic_filter.operand_true")
246
+ }, {
247
+ value: false,
248
+ label: getLabel("dynamic_filter.operand_false")
249
+ }], [getLabel]);
250
+ const transformFunctionFormValuesToValues = useCallback((data) => {
251
+ if (!filter || !field)
252
+ return void 0;
253
+ const newFilter = {
254
+ id: filter.id,
255
+ n: field.name,
256
+ fixed: filter.fixed,
257
+ isSetted: true,
258
+ o: data.valueOperator.id,
259
+ labelOperator: data.valueOperator.label,
260
+ o1: data.valueOperand1.value,
261
+ labelOperands: data.valueOperand1.label
262
+ };
263
+ return newFilter;
264
+ }, []);
265
+ useEffect(() => {
266
+ if (!isLoaded) {
267
+ setPoupEditValidationSchema({
268
+ valueOperator: Yup.object().nullable().required(getLabel(`error_operator_required`)),
269
+ valueOperand1: Yup.object().nullable().required(getLabel(`error_operand_required`))
270
+ });
271
+ }
272
+ setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
273
+ if (filter && field) {
274
+ setValue("valueOperand1", {
275
+ value: filter.o1,
276
+ label: getLabel(`dynamic_filter.operand_${filter.o1}`)
277
+ }, {
278
+ shouldTouch: false,
279
+ shouldValidate: false
280
+ });
281
+ }
282
+ setIsLoaded(true);
283
+ }, [getLabel]);
284
+ return /* @__PURE__ */ jsx(WrapperAllFieldsFilter$1, {
285
+ id: "WrapperAllFieldsFilter",
286
+ children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
287
+ children: [/* @__PURE__ */ jsx(WrapperAutoComplete$2, {
288
+ children: /* @__PURE__ */ jsx(RHFAutocomplete, {
289
+ name: "valueOperator",
290
+ autoComplete: "off",
291
+ options: operators,
292
+ getOptionLabel: (option) => option.label,
293
+ isOptionEqualToValue: (option, value) => option.id === value.id,
294
+ label: ""
295
+ })
296
+ }), /* @__PURE__ */ jsx(WrapperAutoComplete$2, {
297
+ children: /* @__PURE__ */ jsx(RHFAutocomplete, {
298
+ name: "valueOperand1",
299
+ autoComplete: "off",
300
+ options: optionsYesNo,
301
+ getOptionLabel: (option) => option.label,
302
+ isOptionEqualToValue: (option, value) => option.value === value.value,
303
+ label: ""
304
+ })
305
+ })]
306
+ })
307
+ });
308
+ }
309
+ const WrapperAllFieldsFilter = styled("div")(({
310
+ theme
311
+ }) => ({
312
+ display: "flex",
313
+ flexDirection: "column",
314
+ justifyContent: "center",
315
+ alignItems: "center",
316
+ width: "100%",
317
+ minWidth: theme.spacing(3.75),
318
+ padding: theme.spacing(3, 0),
319
+ gap: theme.spacing(3)
320
+ }));
321
+ const WrapperAutoComplete$1 = styled("div")(() => ({
322
+ width: "100%"
323
+ }));
324
+ function isValidDate(d) {
325
+ return d && d instanceof Date;
326
+ }
327
+ const verifyStringFilter = (filter) => {
328
+ if (typeof filter.o !== "string") {
329
+ return false;
330
+ }
331
+ if (STRING_OPERATORS.findIndex((f) => f === filter.o) === -1) {
332
+ return false;
333
+ }
334
+ if (typeof filter.o1 !== "string") {
335
+ return false;
336
+ }
337
+ return true;
338
+ };
339
+ const verifyNumberFilter = (filter) => {
340
+ if (typeof filter.o !== "number") {
341
+ return false;
342
+ }
343
+ if (NUMBER_OPERATORS.findIndex((f) => f === filter.o) === -1) {
344
+ return false;
345
+ }
346
+ if (typeof filter.o1 !== "number") {
347
+ return false;
348
+ }
349
+ if (filter.o === "b" && typeof filter.o2 !== "number") {
350
+ return false;
351
+ }
352
+ return true;
353
+ };
354
+ const verifyBooleanFilter = (filter) => {
355
+ if (typeof filter.o !== "string") {
356
+ return false;
357
+ }
358
+ if (BOOLEAN_OPERATORS.findIndex((f) => f === filter.o) === -1) {
359
+ return false;
360
+ }
361
+ if (typeof filter.o1 !== "boolean") {
362
+ return false;
363
+ }
364
+ return true;
365
+ };
366
+ const verifyDateTime = (filter) => {
367
+ if (typeof filter.o !== "string") {
368
+ return false;
369
+ }
370
+ if (DATE_TIME_OPERATORS.findIndex((f) => f === filter.o) === -1) {
371
+ return false;
372
+ }
373
+ if (typeof filter.o1 !== "string") {
374
+ return false;
375
+ }
376
+ if (filter.o === "b" && typeof filter.o2 !== "string") {
377
+ return false;
378
+ }
379
+ return true;
380
+ };
381
+ const getDefaultDateTimeFilter = (field, fixed, getLabel, formatters) => {
382
+ const defaultStartDate = new Date();
383
+ const defaultEndDate = new Date();
384
+ const {
385
+ dateFormatter
386
+ } = formatters;
387
+ let dfop1 = field.defaultOperand1;
388
+ let dfop2 = field.defaultOperand2;
389
+ const defaultFilter = {
390
+ id: 0,
391
+ n: field.name,
392
+ fixed,
393
+ isSetted: true,
394
+ o: "b",
395
+ labelOperator: "",
396
+ o1: dfop1,
397
+ o2: dfop2,
398
+ labelOperands: ""
399
+ };
400
+ if (dfop1) {
401
+ if (isValidDate(dfop1)) {
402
+ defaultStartDate.setDate(dfop1.getDate());
403
+ } else {
404
+ dfop1 = void 0;
405
+ }
406
+ }
407
+ if (dfop1 === void 0) {
408
+ defaultStartDate.setHours(0, 0, 0, 0);
409
+ }
410
+ if (dfop2) {
411
+ if (isValidDate(dfop2)) {
412
+ defaultEndDate.setDate(dfop2.getDate());
413
+ } else {
414
+ dfop2 = void 0;
415
+ }
416
+ }
417
+ if (dfop2 === void 0) {
418
+ defaultEndDate.setHours(23, 59, 59, 999);
419
+ }
420
+ defaultFilter.o1 = defaultStartDate.toISOString();
421
+ defaultFilter.o2 = defaultEndDate.toISOString();
422
+ defaultFilter.labelOperands = `${dateFormatter.formatDate(defaultStartDate, formatters.dateFormatter.datetimeFormat)} - ${dateFormatter.formatDate(defaultEndDate, dateFormatter.datetimeFormat)}`;
423
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
424
+ return defaultFilter;
425
+ };
426
+ function DateTimeFilter() {
427
+ const {
428
+ setPoupEditValidationSchema,
429
+ setFnTransformFormValuesIntoValues: setTransformFunctionFormValuesToValues,
430
+ getLabelOperator
431
+ } = useBase();
432
+ const {
433
+ getLabel
434
+ } = useModuleDictionary();
435
+ const {
436
+ dateFormatter
437
+ } = useFormatter();
438
+ const {
439
+ popupData: {
440
+ filter,
441
+ field
442
+ }
443
+ } = useBase();
444
+ const {
445
+ control,
446
+ setValue
447
+ } = useFormContext();
448
+ const operator = useWatch({
449
+ control,
450
+ name: "valueOperator"
451
+ });
452
+ const [isLoaded, setIsLoaded] = useState(false);
453
+ const options = useMemo(() => DATE_TIME_OPERATORS.map((o) => ({
454
+ id: o,
455
+ label: getLabelOperator(o)
456
+ })), [getLabelOperator]);
457
+ const transformFunctionFormValuesToValues = useCallback((data) => {
458
+ if (!filter || !field)
459
+ return void 0;
460
+ const newFilter = {
461
+ id: filter.id,
462
+ n: field.name,
463
+ fixed: filter.fixed,
464
+ isSetted: true,
465
+ o: data.valueOperator.id,
466
+ o1: data.valueOperand1.toISOString(),
467
+ labelOperator: data.valueOperator.label,
468
+ labelOperands: ""
469
+ };
470
+ if (data.valueOperator.id === "b") {
471
+ newFilter.o2 = data.valueOperand2.toISOString();
472
+ newFilter.labelOperands = `${dateFormatter.formatDate(data.valueOperand1, dateFormatter.datetimeFormat)} - ${dateFormatter.formatDate(data.valueOperand2, dateFormatter.datetimeFormat)}`;
473
+ } else {
474
+ newFilter.o2 = newFilter.o2 ? newFilter.o2 : newFilter.o1;
475
+ newFilter.labelOperands = dateFormatter.formatDate(data.valueOperand1, dateFormatter.datetimeFormat);
476
+ }
477
+ return newFilter;
478
+ }, []);
479
+ useEffect(() => {
480
+ if (!isLoaded) {
481
+ setPoupEditValidationSchema({
482
+ valueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
483
+ valueOperand1: Yup.date().required(getLabel(`dynamic_filter.error_invalid_date`)).typeError(getLabel(`dynamic_filter.error_invalid_date`)),
484
+ valueOperand2: Yup.mixed().when(["valueOperator.id"], {
485
+ is: "b",
486
+ then: Yup.date().typeError(getLabel(`dynamic_filter.error_invalid_date`)).min(Yup.ref("valueOperand1"), getLabel(`dynamic_filter.error_less_than_start`))
487
+ })
488
+ });
489
+ }
490
+ if (filter && field) {
491
+ setValue("valueOperand1", new Date(filter.o1), {
492
+ shouldTouch: false,
493
+ shouldValidate: false
494
+ });
495
+ setValue("valueOperand2", new Date(filter.o2), {
496
+ shouldTouch: false,
497
+ shouldValidate: false
498
+ });
499
+ }
500
+ setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
501
+ setIsLoaded(true);
502
+ }, [getLabel, filter, field]);
503
+ return /* @__PURE__ */ jsx(WrapperAllFieldsFilter, {
504
+ children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
505
+ children: [/* @__PURE__ */ jsx(WrapperAutoComplete$1, {
506
+ children: /* @__PURE__ */ jsx(RHFAutocomplete, {
507
+ name: "valueOperator",
508
+ autoComplete: "off",
509
+ options,
510
+ getOptionLabel: (option) => option.label,
511
+ isOptionEqualToValue: (option, value) => option.id === value.id,
512
+ label: ""
513
+ })
514
+ }), /* @__PURE__ */ jsx(RHFDateTime, {
515
+ name: "valueOperand1",
516
+ autoComplete: "off",
517
+ label: "",
518
+ focused: true
519
+ }), operator && operator.id === "b" && /* @__PURE__ */ jsx(RHFDateTime, {
520
+ name: "valueOperand2",
521
+ autoComplete: "off",
522
+ label: ""
523
+ })]
524
+ })
525
+ });
526
+ }
527
+ const WrapperStringFilter = styled("div")(({
528
+ theme
529
+ }) => ({
530
+ display: "flex",
531
+ flexDirection: "column",
532
+ justifyContent: "center",
533
+ alignItems: "center",
534
+ width: "100%",
535
+ minWidth: theme.spacing(3.75),
536
+ padding: theme.spacing(3, 0),
537
+ gap: theme.spacing(3)
538
+ }));
539
+ const WrapperAutoComplete = styled("div")(() => ({
540
+ width: "100%"
541
+ }));
542
+ const getDefaultNumberFilter = (field, fixed, getLabel) => {
543
+ const dfop1 = field.defaultOperand1;
544
+ const dfop2 = field.defaultOperand2;
545
+ const defaultFilter = {
546
+ id: 0,
547
+ n: field.name,
548
+ fixed,
549
+ isSetted: false,
550
+ o: "e",
551
+ labelOperator: "",
552
+ o1: "",
553
+ o2: "",
554
+ labelOperands: ""
555
+ };
556
+ if (dfop1 !== void 0 && typeof dfop1 === "number") {
557
+ defaultFilter.o1 = dfop1;
558
+ defaultFilter.labelOperands = defaultFilter.o1;
559
+ }
560
+ if (dfop2 !== void 0 && typeof dfop2 === "number") {
561
+ defaultFilter.o2 = dfop2;
562
+ }
563
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
564
+ return defaultFilter;
565
+ };
566
+ function NumberFilter() {
567
+ const {
568
+ popupData: {
569
+ filter,
570
+ field
571
+ },
572
+ setPoupEditValidationSchema,
573
+ setFnTransformFormValuesIntoValues: setTransformFunctionFormValuesToValues,
574
+ getLabelOperator
575
+ } = useBase();
576
+ const {
577
+ getLabel
578
+ } = useModuleDictionary();
579
+ const inputRef = useRef(null);
580
+ const {
581
+ control,
582
+ setValue
583
+ } = useFormContext();
584
+ const [isLoaded, setIsLoaded] = useState(false);
585
+ const operator = useWatch({
586
+ control,
587
+ name: "valueOperator"
588
+ });
589
+ const options = useMemo(() => NUMBER_OPERATORS.map((o) => ({
590
+ id: o,
591
+ label: getLabelOperator(o)
592
+ })), [getLabelOperator]);
593
+ const transformFunctionFormValuesToValues = useCallback((data) => {
594
+ if (!filter || !field)
595
+ return void 0;
596
+ const newFilter = {
597
+ id: filter.id,
598
+ n: field.name,
599
+ fixed: filter.fixed,
600
+ isSetted: true,
601
+ o: data.valueOperator.id,
602
+ o1: Number(data.valueOperand1),
603
+ o2: data.valueOperand2,
604
+ labelOperator: data.valueOperator.label,
605
+ labelOperands: data.valueOperand1
606
+ };
607
+ if (data.valueOperator.id === "b") {
608
+ newFilter.labelOperands = `${data.valueOperand1} - ${data.valueOperand2}`;
609
+ newFilter.o2 = Number(data.valueOperand2);
610
+ } else {
611
+ newFilter.o2 = void 0;
612
+ }
613
+ return newFilter;
614
+ }, []);
615
+ useEffect(() => {
616
+ if (!isLoaded) {
617
+ setPoupEditValidationSchema({
618
+ valueOperator: Yup.object().nullable().required(getLabel(`dynamic_filter.error_operator_required`)),
619
+ valueOperand1: Yup.number().typeError(getLabel(`dynamic_filter.error_operand_mustbe_number`)),
620
+ valueOperand2: Yup.string().when("valueOperator", {
621
+ is: (o) => {
622
+ return o.id === "b";
623
+ },
624
+ then: Yup.string().test("DOB", getLabel(`dynamic_filter.error_operand_mustbe_number`), (value) => {
625
+ if (value === "")
626
+ return false;
627
+ return !isNaN(Number(value));
628
+ })
629
+ })
630
+ });
631
+ }
632
+ setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
633
+ if (filter && field) {
634
+ setValue("valueOperand1", filter.o1, {
635
+ shouldTouch: false,
636
+ shouldValidate: false
637
+ });
638
+ setValue("valueOperand2", filter.o2, {
639
+ shouldTouch: false,
640
+ shouldValidate: false
641
+ });
642
+ }
643
+ setIsLoaded(true);
644
+ }, [getLabel, filter, field]);
645
+ useEffect(() => {
646
+ inputRef.current?.focus();
647
+ }, [isLoaded]);
648
+ return /* @__PURE__ */ jsx(WrapperStringFilter, {
649
+ children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
650
+ children: [/* @__PURE__ */ jsx(WrapperAutoComplete, {
651
+ children: /* @__PURE__ */ jsx(RHFAutocomplete, {
652
+ name: "valueOperator",
653
+ autoComplete: "off",
654
+ options,
655
+ getOptionLabel: (option) => option.label,
656
+ isOptionEqualToValue: (option, value) => option.id === value.id,
657
+ label: ""
658
+ })
659
+ }), /* @__PURE__ */ jsx(RHFTextField, {
660
+ name: "valueOperand1",
661
+ ref: inputRef,
662
+ type: "number",
663
+ focused: true
664
+ }), operator && operator.id === "b" && /* @__PURE__ */ jsx(RHFTextField, {
665
+ name: "valueOperand2",
666
+ ref: inputRef,
667
+ type: "number"
668
+ })]
669
+ })
670
+ });
671
+ }
672
+ const strategiesDefaultFilterValues = {
673
+ string: getDefaultStringFilter,
674
+ number: getDefaultNumberFilter,
675
+ boolean: getDefaultBooleanFilter,
676
+ datetime: getDefaultDateTimeFilter,
677
+ __default__: () => {
678
+ throw new Error("Type no defined");
679
+ }
680
+ };
681
+ const getDefaultFilterValues = (field, fixed, getLabel, formatters) => {
682
+ const transformer = strategiesDefaultFilterValues[field.type] ?? strategiesDefaultFilterValues.__default__;
683
+ return transformer(field, fixed, getLabel, formatters);
684
+ };
685
+ const strategiesEditFilterComponent = {
686
+ string: StringFilter,
687
+ number: NumberFilter,
688
+ boolean: BooleanFilter,
689
+ datetime: DateTimeFilter,
690
+ __default__: /* @__PURE__ */ jsx(Fragment, {})
691
+ };
692
+ const PopupEditFilterComponent = (props) => {
693
+ const {
694
+ getFieldByName
695
+ } = useBase();
696
+ const field = getFieldByName(props.filter.n);
697
+ if (!field)
698
+ return /* @__PURE__ */ jsx(Fragment, {});
699
+ const Component = strategiesEditFilterComponent[field.type] ?? strategiesEditFilterComponent.__default__;
700
+ return /* @__PURE__ */ jsx(Component, {});
701
+ };
702
+ const initialState = {
703
+ fields: [],
704
+ withAllField: true,
705
+ isDirty: false,
706
+ isValid: true,
707
+ automatic: false,
708
+ availableFields: [],
709
+ getFieldByName: () => void 0,
710
+ getLabelOperator: () => "",
711
+ applyedFilters: [],
712
+ addFilter: voidFunction,
713
+ updateFilter: voidFunction,
714
+ removeFilter: voidFunction,
715
+ clearFilters: voidFunction,
716
+ fireOnChangeFilters: voidFunction,
717
+ openAnchorEl: null,
718
+ openMenuFields: voidFunction,
719
+ closeMenuFields: voidFunction,
720
+ popupData: {
721
+ popupAnchorEl: null,
722
+ filter: null,
723
+ field: null
724
+ },
725
+ popupValidationSchema: {},
726
+ setPoupEditValidationSchema: voidFunction,
727
+ showPopupForAddFilter: voidFunction,
728
+ showPopupForEditFilter: voidFunction,
729
+ hidePopupEdit: voidFunction,
730
+ setInEdition: voidFunction,
731
+ inEdition: false,
732
+ setFnTransformFormValuesIntoValues: voidFunction,
733
+ fnTransformFormValuesIntoRawValues: () => void 0
734
+ };
735
+ const BaseContext = createContext(initialState);
736
+ const getMaxId = (applyedFilters) => {
737
+ return applyedFilters.reduce((prev, n) => {
738
+ return n.id > prev ? n.id : prev;
739
+ }, 0);
740
+ };
741
+ const getFilterById = (id, applyedFilters) => {
742
+ return applyedFilters.findIndex((f) => f.id === id);
743
+ };
744
+ const formatToInitialFilters = (applyedFilter) => {
745
+ return applyedFilter.map((af) => ({
746
+ n: af.n,
747
+ o: af.o,
748
+ labelOperands: af.labelOperands,
749
+ o1: af.o1,
750
+ o2: af.o2
751
+ }));
752
+ };
753
+ const formatToRawFilter = (applyedFilter) => {
754
+ return applyedFilter.map((af) => ({
755
+ n: af.n,
756
+ o: af.o,
757
+ o1: af.o1,
758
+ o2: af.o2
759
+ }));
760
+ };
761
+ const getInitialFilters = (fields, filters, getFieldByName, getLabel, formatters) => {
762
+ const newFilters = [];
763
+ const fixedFields = [];
764
+ for (let index = 0; index < filters.length; index++) {
765
+ let add;
766
+ const filter = {
767
+ ...filters[index],
768
+ id: 0,
769
+ isSetted: true,
770
+ fixed: false,
771
+ labelOperator: ""
772
+ };
773
+ const field = getFieldByName(filter.n);
774
+ if (!field)
775
+ continue;
776
+ switch (field.type) {
777
+ case "string":
778
+ add = verifyStringFilter(filter);
779
+ break;
780
+ case "number":
781
+ add = verifyNumberFilter(filter);
782
+ break;
783
+ case "boolean":
784
+ add = verifyBooleanFilter(filter);
785
+ break;
786
+ case "datetime":
787
+ add = verifyDateTime(filter);
788
+ break;
789
+ default:
790
+ add = false;
791
+ }
792
+ if (add) {
793
+ if (field.presence === "fixed") {
794
+ if (fixedFields.findIndex((f) => f === field.name) === -1) {
795
+ filter.fixed = true;
796
+ fixedFields.push(field.name);
797
+ } else {
798
+ filter.fixed = false;
799
+ }
800
+ }
801
+ filter.isSetted = true;
802
+ filter.id = newFilters.length + 1;
803
+ filter.labelOperator = getLabel(`dynamic_filter.operator_${filter.o}`);
804
+ newFilters.push(filter);
805
+ }
806
+ }
807
+ for (let index = 0; index < fields.length; index++) {
808
+ const field = fields[index];
809
+ if (field.presence === "initialized" || field.presence === "fixed") {
810
+ if (!filters.find((f) => f.n === field.name)) {
811
+ const newFilter = getDefaultFilterValues(field, field.presence === "fixed", getLabel, formatters);
812
+ newFilter.id = newFilters.length + 1;
813
+ newFilters.push(newFilter);
814
+ }
815
+ }
816
+ }
817
+ return newFilters;
818
+ };
819
+ function BaseProvider(props) {
820
+ const {
821
+ isSkeleton = false,
822
+ fields,
823
+ initialFilters = [],
824
+ withAllField = true,
825
+ onChangeFilter,
826
+ automatic = true,
827
+ children
828
+ } = props;
829
+ const [openAnchorEl, setOpenAnchorEl] = useState(null);
830
+ const [popupData, setPopupData] = useState({
831
+ popupAnchorEl: null,
832
+ filter: null,
833
+ field: null
834
+ });
835
+ const {
836
+ getLabel
837
+ } = useModuleDictionary();
838
+ const [popupValidationSchema, setInternalPopupValidationSchema] = useState(Yup.object().shape({}));
839
+ const [fnTransformFormValuesIntoRawValues, setInternalfnTransormFormValuesIntoRawValues] = useState(() => void 0);
840
+ const {
841
+ host_static_assets,
842
+ environment_assets
843
+ } = useEnvironment();
844
+ const formatter = useFormatter();
845
+ const all_fields = useMemo(() => {
846
+ return {
847
+ ...ALL_FIELDS,
848
+ label: getLabel("dynamic_filter.all_fields"),
849
+ urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/all_fields.svg`
850
+ };
851
+ }, [getLabel, host_static_assets, environment_assets]);
852
+ const [inEdition, setInEdition] = useState(false);
853
+ const [isDirty, setIsDirty] = useState(!automatic);
854
+ const [isValid, setIsValid] = useState(false);
855
+ const {
856
+ toast
857
+ } = useHostTools();
858
+ const getFieldByName = useCallback((name) => {
859
+ return fields.concat(all_fields).find((f) => {
860
+ return f.name === name;
861
+ });
862
+ }, [fields, all_fields]);
863
+ const getLabelOperator = useCallback((operator) => {
864
+ return getLabel(`dynamic_filter.operator_${operator}`);
865
+ }, [getLabel]);
866
+ const [applyedFilters, setApplyedFilters] = useState(getInitialFilters(fields, initialFilters, getFieldByName, getLabel, formatter));
867
+ const availableFields = useMemo(() => {
868
+ const newFields = [];
869
+ for (let index = 0; index < fields.length; index++) {
870
+ let add;
871
+ const field = fields[index];
872
+ add = true;
873
+ if (field.multiple !== void 0 && field.multiple === false) {
874
+ const fIndx = applyedFilters.findIndex((f) => f.n === field.name);
875
+ if (fIndx > -1) {
876
+ add = false;
877
+ }
878
+ }
879
+ if (add) {
880
+ newFields.push(field);
881
+ }
882
+ }
883
+ return newFields;
884
+ }, [fields, applyedFilters]);
885
+ const fireOnChangeFilters = useCallback(() => {
886
+ if (isValid) {
887
+ if (!automatic)
888
+ setIsDirty(false);
889
+ onChangeFilter(formatToInitialFilters(applyedFilters), formatToRawFilter(applyedFilters));
890
+ } else {
891
+ toast(getLabel("dynamic_filter.error_filters_no_setted"), {
892
+ type: "error",
893
+ autoClose: 1e4
894
+ });
895
+ }
896
+ }, [isValid, applyedFilters, onChangeFilter]);
897
+ useEffect(() => {
898
+ const NoValid = applyedFilters.findIndex((f) => !f.isSetted) > -1;
899
+ if (NoValid) {
900
+ setIsValid(false);
901
+ } else {
902
+ setIsValid(true);
903
+ }
904
+ if (!automatic) {
905
+ setIsDirty(true);
906
+ return;
907
+ }
908
+ if (!NoValid) {
909
+ setIsDirty(false);
910
+ onChangeFilter(formatToInitialFilters(applyedFilters), formatToRawFilter(applyedFilters));
911
+ }
912
+ }, [applyedFilters]);
913
+ const addFilter = useCallback((newFilter) => {
914
+ setApplyedFilters((lastApplyedFilters) => {
915
+ const newArray = [...lastApplyedFilters];
916
+ const newFilterFull = {
917
+ ...newFilter,
918
+ id: getMaxId(lastApplyedFilters) + 1,
919
+ labelOperator: getLabelOperator(newFilter.o)
920
+ };
921
+ newArray.push(newFilterFull);
922
+ return newArray;
923
+ });
924
+ }, []);
925
+ const updateFilter = useCallback((newFilter) => {
926
+ setApplyedFilters((lastApplyedFilters) => {
927
+ const newArray = [...lastApplyedFilters];
928
+ const findedFilter = getFilterById(newFilter.id, newArray);
929
+ if (findedFilter > -1) {
930
+ newArray.splice(findedFilter, 1, {
931
+ ...newFilter,
932
+ labelOperator: getLabelOperator(newFilter.o)
933
+ });
934
+ }
935
+ return newArray;
936
+ });
937
+ }, []);
938
+ const clearFilters = useCallback(() => {
939
+ setApplyedFilters((lastFilters) => {
940
+ const newFilters = [];
941
+ for (let index = 0; index < lastFilters.length; index++) {
942
+ const filter = lastFilters[index];
943
+ if (filter.fixed) {
944
+ newFilters.push(filter);
945
+ }
946
+ }
947
+ return newFilters;
948
+ });
949
+ }, []);
950
+ const openMenuFields = useCallback((anchorEl) => {
951
+ setOpenAnchorEl(anchorEl);
952
+ setInEdition(true);
953
+ }, [applyedFilters]);
954
+ const closeMenuFields = useCallback(() => {
955
+ console.log("closeMenuFields");
956
+ setOpenAnchorEl(null);
957
+ setInEdition(false);
958
+ }, []);
959
+ const hidePopupEdit = useCallback((stayInEditon) => {
960
+ if (popupData.popupAnchorEl) {
961
+ setPopupData({
962
+ popupAnchorEl: null,
963
+ filter: null,
964
+ field: null
965
+ });
966
+ }
967
+ if (!stayInEditon && inEdition) {
968
+ setInEdition(false);
969
+ }
970
+ }, [popupData, inEdition]);
971
+ const showPopupForAddFilter = useCallback((anchorEl, field) => {
972
+ setPopupData({
973
+ popupAnchorEl: anchorEl,
974
+ filter: getDefaultFilterValues(field, false, getLabel, formatter),
975
+ field
976
+ });
977
+ setInEdition(true);
978
+ }, []);
979
+ const showPopupForEditFilter = useCallback((anchorEl, filterToEdit) => {
980
+ setPopupData({
981
+ popupAnchorEl: anchorEl,
982
+ filter: filterToEdit,
983
+ field: getFieldByName(filterToEdit.n)
984
+ });
985
+ setInEdition(true);
986
+ }, []);
987
+ const removeFilter = useCallback((id) => {
988
+ setApplyedFilters((lastApplyedFilters) => {
989
+ const newArray = [...lastApplyedFilters];
990
+ const index_to_remove = lastApplyedFilters.findIndex((filter) => id === filter.id);
991
+ if (index_to_remove > -1) {
992
+ if (!newArray[index_to_remove].fixed) {
993
+ newArray.splice(index_to_remove, 1);
994
+ }
995
+ }
996
+ return newArray;
997
+ });
998
+ }, []);
999
+ const setPoupEditValidationSchema = useCallback((validationSchema) => {
1000
+ setInternalPopupValidationSchema(Yup.object().shape({
1001
+ ...validationSchema
1002
+ }));
1003
+ }, []);
1004
+ const setFnTransformFormValuesIntoValues = useCallback((fn) => {
1005
+ setInternalfnTransormFormValuesIntoRawValues(() => fn);
1006
+ }, []);
1007
+ return /* @__PURE__ */ jsx(BaseContext.Provider, {
1008
+ value: {
1009
+ isSkeleton,
1010
+ inEdition,
1011
+ automatic,
1012
+ isDirty,
1013
+ isValid,
1014
+ withAllField,
1015
+ fields,
1016
+ availableFields,
1017
+ getFieldByName,
1018
+ getLabelOperator,
1019
+ applyedFilters,
1020
+ addFilter,
1021
+ updateFilter,
1022
+ removeFilter,
1023
+ clearFilters,
1024
+ fireOnChangeFilters,
1025
+ openAnchorEl,
1026
+ openMenuFields,
1027
+ closeMenuFields,
1028
+ popupData,
1029
+ popupValidationSchema,
1030
+ showPopupForAddFilter,
1031
+ showPopupForEditFilter,
1032
+ hidePopupEdit,
1033
+ setInEdition,
1034
+ setPoupEditValidationSchema,
1035
+ fnTransformFormValuesIntoRawValues,
1036
+ setFnTransformFormValuesIntoValues
1037
+ },
1038
+ children
1039
+ });
1040
+ }
1041
+ const useBase = () => useContext(BaseContext);
1042
+ const WrapperApplyedFilter = styled("div")(({
1043
+ theme
1044
+ }) => ({
1045
+ width: "auto",
1046
+ display: "flex",
1047
+ justifyContent: "center",
1048
+ alignItems: "center",
1049
+ height: "100%",
1050
+ minHeight: theme.spacing(3),
1051
+ paddingLeft: theme.spacing(1),
1052
+ backgroundColor: theme.palette.grid?.sectionHeader,
1053
+ border: "1px solid",
1054
+ borderColor: alpha(`${theme.palette.divider}`, 0.1),
1055
+ overflow: "visible",
1056
+ borderRadius: theme.spacing(1),
1057
+ "&.waf_no_setted": {
1058
+ border: `1px solid ${theme.palette.error.main}`
1059
+ }
1060
+ }));
1061
+ const AplyedFilterStyled = styled("div")(({
1062
+ theme
1063
+ }) => ({
1064
+ ...theme.typography.body2,
1065
+ display: "flex",
1066
+ justifyContent: "center",
1067
+ alignItems: "center",
1068
+ width: "auto",
1069
+ height: "100%",
1070
+ marginRight: theme.spacing(1),
1071
+ marginLeft: theme.spacing(1),
1072
+ whiteSpace: "nowrap"
1073
+ }));
1074
+ const ContainerField = styled("span")(({
1075
+ theme
1076
+ }) => ({
1077
+ ...theme.typography.subtitle2
1078
+ }));
1079
+ const ContainerOperator = styled("span")(({
1080
+ theme
1081
+ }) => ({
1082
+ ...theme.typography.body2,
1083
+ marginLeft: theme.spacing(1.5),
1084
+ fontStyle: "italic"
1085
+ }));
1086
+ const ContainerOperands = styled("span")(({
1087
+ theme
1088
+ }) => ({
1089
+ ...theme.typography.body2,
1090
+ marginLeft: theme.spacing(1.5)
1091
+ }));
1092
+ function ApplyedFilter(props) {
1093
+ const {
1094
+ n: fieldName,
1095
+ id,
1096
+ isSetted,
1097
+ fixed,
1098
+ labelOperator,
1099
+ labelOperands
1100
+ } = props;
1101
+ const {
1102
+ removeFilter,
1103
+ showPopupForEditFilter,
1104
+ hidePopupEdit,
1105
+ getFieldByName
1106
+ } = useBase();
1107
+ const {
1108
+ host_static_assets,
1109
+ environment_assets
1110
+ } = useEnvironment();
1111
+ const field = useMemo(() => {
1112
+ return getFieldByName(fieldName);
1113
+ }, [getFieldByName]);
1114
+ const urlIcon = useMemo(() => {
1115
+ if (!field)
1116
+ return;
1117
+ if (field && field.urlIcon !== "") {
1118
+ return field.urlIcon;
1119
+ }
1120
+ return "";
1121
+ }, [field]);
1122
+ const onDelete = () => {
1123
+ hidePopupEdit(false);
1124
+ removeFilter(id);
1125
+ };
1126
+ const onClick = (event) => {
1127
+ showPopupForEditFilter(event.currentTarget, props);
1128
+ };
1129
+ if (!field) {
1130
+ return /* @__PURE__ */ jsx(Fragment, {});
1131
+ }
1132
+ return /* @__PURE__ */ jsxs(WrapperApplyedFilter, {
1133
+ id: "WrapperApplyedFilter",
1134
+ className: !isSetted ? "waf_no_setted" : "",
1135
+ children: [urlIcon && /* @__PURE__ */ jsx(IconButton, {
1136
+ src: urlIcon,
1137
+ onClick
1138
+ }), /* @__PURE__ */ jsxs(AplyedFilterStyled, {
1139
+ onClick,
1140
+ children: [/* @__PURE__ */ jsx(ContainerField, {
1141
+ children: field.label
1142
+ }), /* @__PURE__ */ jsx(ContainerOperator, {
1143
+ children: labelOperator
1144
+ }), /* @__PURE__ */ jsx(ContainerOperands, {
1145
+ children: labelOperands
1146
+ })]
1147
+ }), !fixed && /* @__PURE__ */ jsx(IconButton, {
1148
+ size: "small",
1149
+ src: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/clear.svg`,
1150
+ onClick: onDelete,
1151
+ dictionaryTooltip: "dynamic_filter.tooltip_clear_filter"
1152
+ })]
1153
+ });
1154
+ }
1155
+ function ApplyedFilters() {
1156
+ const {
1157
+ applyedFilters,
1158
+ isSkeleton
1159
+ } = useBase();
1160
+ if (isSkeleton) {
1161
+ return /* @__PURE__ */ jsx(WrapperApplyedFilters, {
1162
+ id: "WrapperApplyedFilters"
1163
+ });
1164
+ }
1165
+ return /* @__PURE__ */ jsx(WrapperApplyedFilters, {
1166
+ className: "WrapperApplyedFilters",
1167
+ children: /* @__PURE__ */ jsx(ScrollBar, {
1168
+ children: /* @__PURE__ */ jsx(ContainerApplyedFilters, {
1169
+ id: "WrapperApplyedFilters",
1170
+ children: [...applyedFilters].sort((a, b) => a.isSetted === b.isSetted ? 0 : a.isSetted ? -1 : 1).reverse().map((filter) => /* @__PURE__ */ jsx(ApplyedFilter, {
1171
+ ...filter
1172
+ }, filter.id))
1173
+ })
1174
+ })
1175
+ });
1176
+ }
1177
+ const SKTClearFilters = styled$1("div")(({
1178
+ theme
1179
+ }) => ({
1180
+ display: "flex",
1181
+ justifyContent: "center",
1182
+ alignItems: "center",
1183
+ minWidth: theme.spacing(3.75),
1184
+ height: theme.spacing(3.75)
1185
+ }));
1186
+ const WrapperClearFilters = styled$1("div")(({
1187
+ theme
1188
+ }) => ({
1189
+ paddingLeft: theme.spacing(0.5),
1190
+ borderLeft: `1px solid ${theme.palette.divider}`
1191
+ }));
1192
+ const ClearFilters = () => {
1193
+ const {
1194
+ host_static_assets,
1195
+ environment_assets
1196
+ } = useEnvironment();
1197
+ const {
1198
+ clearFilters,
1199
+ isSkeleton,
1200
+ applyedFilters
1201
+ } = useBase();
1202
+ if (isSkeleton) {
1203
+ return /* @__PURE__ */ jsx(SKTClearFilters, {
1204
+ children: /* @__PURE__ */ jsx(Skeleton, {
1205
+ variant: "circular",
1206
+ width: "20px",
1207
+ height: "20px"
1208
+ })
1209
+ });
1210
+ }
1211
+ if (applyedFilters.findIndex((f) => f.fixed == false) > -1) {
1212
+ return /* @__PURE__ */ jsx(WrapperClearFilters, {
1213
+ children: /* @__PURE__ */ jsx(IconButton, {
1214
+ src: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/clear.svg`,
1215
+ onClick: clearFilters,
1216
+ dictionaryTooltip: "dynamic_filter.tooltip_clear_filters"
1217
+ })
1218
+ });
1219
+ }
1220
+ return /* @__PURE__ */ jsx(Fragment, {});
1221
+ };
1222
+ const WrapperInputFilter = styled("div")(({
1223
+ theme
1224
+ }) => ({
1225
+ display: "flex",
1226
+ justifyContent: "center",
1227
+ alignItems: "center",
1228
+ width: "100%",
1229
+ height: theme.spacing(3),
1230
+ borderLeft: `1px solid ${theme.palette.divider}`,
1231
+ paddingLeft: theme.spacing(1),
1232
+ marginLeft: theme.spacing(1),
1233
+ [theme.breakpoints.up("sm")]: {
1234
+ width: theme.spacing(25)
1235
+ }
1236
+ }));
1237
+ const StyledInputFilter = styled("input")(({
1238
+ theme
1239
+ }) => ({
1240
+ background: "transparent",
1241
+ display: "flex",
1242
+ justifyContent: "center",
1243
+ alignItems: "center",
1244
+ minWidth: theme.spacing(3.75),
1245
+ width: "100%",
1246
+ "&": {
1247
+ outline: "none",
1248
+ border: "none"
1249
+ },
1250
+ [theme.breakpoints.up("sm")]: {
1251
+ width: "auto"
1252
+ }
1253
+ }));
1254
+ function InputFilter() {
1255
+ const {
1256
+ isSkeleton,
1257
+ withAllField,
1258
+ availableFields,
1259
+ showPopupForAddFilter,
1260
+ addFilter,
1261
+ openAnchorEl,
1262
+ openMenuFields,
1263
+ closeMenuFields,
1264
+ hidePopupEdit
1265
+ } = useBase();
1266
+ const [valueFilter, setValueFilter] = useState("");
1267
+ const finalFields = useMemo(() => {
1268
+ if (!openAnchorEl) {
1269
+ return [];
1270
+ }
1271
+ return availableFields.filter((field) => field.label.includes(valueFilter));
1272
+ }, [valueFilter, openAnchorEl]);
1273
+ if (isSkeleton) {
1274
+ return /* @__PURE__ */ jsx(WrapperInputFilter, {
1275
+ id: "SKTWrapperInputFilter",
1276
+ children: /* @__PURE__ */ jsx(Skeleton, {
1277
+ variant: "text",
1278
+ width: "100%",
1279
+ height: 24
1280
+ })
1281
+ });
1282
+ }
1283
+ const handleClose = () => {
1284
+ closeMenuFields();
1285
+ };
1286
+ const handleClickItem = (field) => {
1287
+ closeMenuFields();
1288
+ showPopupForAddFilter(openAnchorEl, field);
1289
+ };
1290
+ const onClickFilter = (event) => {
1291
+ openMenuFields(event.currentTarget);
1292
+ };
1293
+ const onChangeFilter = (event) => {
1294
+ setValueFilter(event.target.value);
1295
+ if (!openAnchorEl) {
1296
+ openMenuFields(event.currentTarget);
1297
+ }
1298
+ hidePopupEdit(true);
1299
+ };
1300
+ const handleKeyPressMenu = (event) => {
1301
+ if (event.key !== "Enter")
1302
+ return;
1303
+ if (valueFilter.trim() === "") {
1304
+ closeMenuFields();
1305
+ return;
1306
+ }
1307
+ if (withAllField) {
1308
+ addFilter({
1309
+ n: ALL_FIELDS.name,
1310
+ isSetted: true,
1311
+ fixed: false,
1312
+ o: "c",
1313
+ o1: valueFilter,
1314
+ labelOperands: valueFilter
1315
+ });
1316
+ setValueFilter("");
1317
+ closeMenuFields();
1318
+ }
1319
+ };
1320
+ if (!withAllField && availableFields.length == 0) {
1321
+ return /* @__PURE__ */ jsx(Fragment, {});
1322
+ }
1323
+ return /* @__PURE__ */ jsxs(WrapperInputFilter, {
1324
+ id: "WrapperInputFilter",
1325
+ children: [/* @__PURE__ */ jsx(StyledInputFilter, {
1326
+ type: "text",
1327
+ value: valueFilter,
1328
+ placeholder: "filter",
1329
+ onClick: onClickFilter,
1330
+ onChange: onChangeFilter,
1331
+ onKeyPress: handleKeyPressMenu
1332
+ }), availableFields.length > 0 && /* @__PURE__ */ jsx(Popover, {
1333
+ id: "Popover",
1334
+ open: Boolean(openAnchorEl),
1335
+ anchorEl: openAnchorEl,
1336
+ onClose: handleClose,
1337
+ disableAutoFocus: true,
1338
+ arrowType: "right-top",
1339
+ sx: {
1340
+ "& .MuiMenuItem-root": {
1341
+ px: 1,
1342
+ typography: "body2",
1343
+ borderRadius: 0.75
1344
+ }
1345
+ },
1346
+ children: Boolean(openAnchorEl) && finalFields.map((field, index) => /* @__PURE__ */ jsxs(MenuItem, {
1347
+ dense: true,
1348
+ onClick: () => handleClickItem(field),
1349
+ children: [/* @__PURE__ */ jsx(Icon, {
1350
+ src: field.urlIcon
1351
+ }), /* @__PURE__ */ jsx(LabelMemuItem, {
1352
+ children: field.label
1353
+ })]
1354
+ }, `menu_action_${index}`))
1355
+ })]
1356
+ });
1357
+ }
1358
+ const WrapperPopupEditFilter = styled("div")(({
1359
+ theme
1360
+ }) => ({
1361
+ display: "flex",
1362
+ flexDirection: "column",
1363
+ justifyContent: "center",
1364
+ alignItems: "center",
1365
+ padding: theme.spacing(1.4, 3, 3, 3),
1366
+ backgroundColor: theme.palette.background.default,
1367
+ borderRadius: theme.spacing(1)
1368
+ }));
1369
+ styled("div")(({
1370
+ theme
1371
+ }) => ({
1372
+ display: "flex",
1373
+ justifyContent: "center",
1374
+ gap: theme.spacing(3),
1375
+ paddingTop: theme.spacing(3)
1376
+ }));
1377
+ const TitleContainer = styled("div")(({
1378
+ theme
1379
+ }) => ({
1380
+ ...theme.typography.subtitle2,
1381
+ width: "100%",
1382
+ display: "flex",
1383
+ justifyContent: "flex-start",
1384
+ alignItems: "center",
1385
+ padding: theme.spacing(2, 0),
1386
+ marginLeft: theme.spacing(1.5)
1387
+ }));
1388
+ const HeaderContainer = styled("div")(({
1389
+ theme
1390
+ }) => ({
1391
+ width: "100%",
1392
+ display: "flex",
1393
+ justifyContent: "flex-start",
1394
+ alignItems: "center",
1395
+ borderBottom: `1px solid ${theme.palette.divider}`
1396
+ }));
1397
+ const WrapperEditFilter = styled("div")(() => ({
1398
+ "& .m4l_FormProvider": {
1399
+ padding: "0px",
1400
+ margin: "0px"
1401
+ }
1402
+ }));
1403
+ const PopupEditFilter = () => {
1404
+ const {
1405
+ popupValidationSchema,
1406
+ popupData: {
1407
+ popupAnchorEl,
1408
+ filter,
1409
+ field
1410
+ },
1411
+ hidePopupEdit,
1412
+ addFilter,
1413
+ updateFilter,
1414
+ getLabelOperator,
1415
+ fnTransformFormValuesIntoRawValues
1416
+ } = useBase();
1417
+ const theme = useTheme();
1418
+ const {
1419
+ getLabel
1420
+ } = useModuleDictionary();
1421
+ const values = useMemo(() => {
1422
+ if (!filter || !field)
1423
+ return {};
1424
+ const valuesFilter = {
1425
+ ...filter,
1426
+ valueOperator: {
1427
+ id: filter.o,
1428
+ label: getLabelOperator(filter.o)
1429
+ }
1430
+ };
1431
+ return valuesFilter;
1432
+ }, [filter, field, getLabelOperator, getLabel]);
1433
+ const onSubmit = async (data) => {
1434
+ if (!filter || !field)
1435
+ return;
1436
+ const newFilter = fnTransformFormValuesIntoRawValues(data);
1437
+ if (!newFilter)
1438
+ return;
1439
+ if (filter.id === 0) {
1440
+ addFilter(newFilter);
1441
+ } else {
1442
+ updateFilter(newFilter);
1443
+ }
1444
+ hidePopupEdit(false);
1445
+ };
1446
+ const onClose = () => {
1447
+ hidePopupEdit(false);
1448
+ };
1449
+ return /* @__PURE__ */ jsx(Popper, {
1450
+ open: Boolean(popupAnchorEl),
1451
+ anchorEl: popupAnchorEl,
1452
+ sx: {
1453
+ boxShadow: theme.customShadows.dropdown,
1454
+ borderRadius: 1
1455
+ },
1456
+ children: /* @__PURE__ */ jsx(ClickAwayListener, {
1457
+ onClickAway: onClose,
1458
+ children: /* @__PURE__ */ jsx(WrapperEditFilter, {
1459
+ children: filter && /* @__PURE__ */ jsx(RHFormProvider, {
1460
+ onSubmit,
1461
+ values,
1462
+ validationSchema: popupValidationSchema,
1463
+ children: /* @__PURE__ */ jsxs(WrapperPopupEditFilter, {
1464
+ children: [/* @__PURE__ */ jsxs(HeaderContainer, {
1465
+ children: [field?.urlIcon && /* @__PURE__ */ jsx(Icon, {
1466
+ src: field.urlIcon
1467
+ }), /* @__PURE__ */ jsx(TitleContainer, {
1468
+ children: field?.label
1469
+ })]
1470
+ }), /* @__PURE__ */ jsx(PopupEditFilterComponent, {
1471
+ filter
1472
+ }), /* @__PURE__ */ jsxs(Actions, {
1473
+ children: [/* @__PURE__ */ jsx(ActionCancel, {
1474
+ onClick: onClose
1475
+ }), /* @__PURE__ */ jsx(ActionIntro, {})]
1476
+ })]
1477
+ })
1478
+ })
1479
+ })
1480
+ })
1481
+ });
1482
+ };
1483
+ const WrapperFilter = styled("div", {
1484
+ shouldForwardProp: (prop) => prop !== "inEdition"
1485
+ })(({
1486
+ theme,
1487
+ inEdition
1488
+ }) => ({
1489
+ display: "flex",
1490
+ alignItems: "center",
1491
+ justifyContent: "flex-start",
1492
+ height: "auto",
1493
+ width: "100%",
1494
+ padding: theme.spacing(0.5),
1495
+ borderRadius: theme.spacing(1),
1496
+ border: inEdition ? `1px solid ${theme.palette.primary.main}` : `1px solid ${theme.palette.divider}`
1497
+ }));
1498
+ const WrapperFilterMobile = styled("div", {
1499
+ shouldForwardProp: (prop) => prop !== "inEdition"
1500
+ })(({
1501
+ theme,
1502
+ inEdition
1503
+ }) => ({
1504
+ display: "flex",
1505
+ flexDirection: "column",
1506
+ alignItems: "center",
1507
+ justifyContent: "space-between",
1508
+ minWidth: theme.spacing(25),
1509
+ height: "auto",
1510
+ width: "100%",
1511
+ padding: theme.spacing(0.5),
1512
+ borderRadius: theme.spacing(1),
1513
+ border: inEdition ? `1px solid ${theme.palette.primary.main}` : `1px solid ${theme.palette.divider}`,
1514
+ gap: theme.spacing(0.75),
1515
+ "& .WrapperApplyedFilters": {
1516
+ margin: "0px",
1517
+ padding: "0px",
1518
+ border: "0px"
1519
+ }
1520
+ }));
1521
+ const ContainerFistRow = styled("div")(() => ({
1522
+ width: "100%",
1523
+ display: "flex",
1524
+ justifyContent: "space-between"
1525
+ }));
1526
+ const DynamicFilter = (props) => {
1527
+ const isDesktop = useResponsiveDesktop();
1528
+ const render = useFlagsPresent(["dictionary_loaded"]);
1529
+ if (!render) {
1530
+ return /* @__PURE__ */ jsx(Fragment, {});
1531
+ }
1532
+ return /* @__PURE__ */ jsx(BaseProvider, {
1533
+ ...props,
1534
+ children: /* @__PURE__ */ jsx(BaseContext.Consumer, {
1535
+ children: ({
1536
+ inEdition
1537
+ }) => isDesktop ? /* @__PURE__ */ jsxs(WrapperFilter, {
1538
+ id: "WrapperFilter",
1539
+ inEdition,
1540
+ children: [/* @__PURE__ */ jsx(FilterButton, {}), /* @__PURE__ */ jsx(InputFilter, {}), /* @__PURE__ */ jsx(ApplyedFilters, {}), /* @__PURE__ */ jsx(PopupEditFilter, {}), /* @__PURE__ */ jsx(ClearFilters, {})]
1541
+ }) : /* @__PURE__ */ jsxs(WrapperFilterMobile, {
1542
+ id: "WrapperFilterMobile",
1543
+ inEdition,
1544
+ children: [/* @__PURE__ */ jsxs(ContainerFistRow, {
1545
+ id: "ContainerFistRow",
1546
+ children: [/* @__PURE__ */ jsx(FilterButton, {}), /* @__PURE__ */ jsx(InputFilter, {}), /* @__PURE__ */ jsx(ClearFilters, {})]
1547
+ }), /* @__PURE__ */ jsx(ApplyedFilters, {}), /* @__PURE__ */ jsx(PopupEditFilter, {})]
1548
+ })
1549
+ })
1550
+ });
1551
+ };
1552
+ function getDynamicFilterComponentsDictionary() {
1553
+ return ["dynamic_filter"].concat(getCommonActionsDictionary());
1554
+ }
1555
+ const defaultDynamicFilterDictionary = {
1556
+ dynamic_filter: {
1557
+ filter_tooltip: "Search",
1558
+ operator_b: "between",
1559
+ operator_e: "=",
1560
+ operator_ne: "!=",
1561
+ operator_gt: ">",
1562
+ operator_gte: ">=",
1563
+ operator_lt: "<",
1564
+ operator_lte: "<=",
1565
+ operator_c: "contains",
1566
+ operator_nc: "not contains",
1567
+ all_fields: "all_fields",
1568
+ operand_true: "true",
1569
+ operand_false: "false",
1570
+ error_operator_required: "Operator required",
1571
+ error_operand_required: "Operand required",
1572
+ error_invalid_date: "Invalid date",
1573
+ error_operand_mustbe_number: "Invalid number",
1574
+ error_filters_no_setted: "Filters not yet set"
1575
+ }
1576
+ };
1577
+ export {
1578
+ DynamicFilter as D,
1579
+ defaultDynamicFilterDictionary as d,
1580
+ getDynamicFilterComponentsDictionary as g,
1581
+ useBase as u
1582
+ };