@m4l/components 0.0.36 → 0.0.39

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 (47) hide show
  1. package/dist/components/CompanyLogo/index.js +0 -1
  2. package/dist/components/DataGrid/index.js +0 -1
  3. package/dist/components/DynamicFilter/components/FilterButton/styles.d.ts +0 -1
  4. package/dist/components/DynamicFilter/components/fieldstypes/BooleanFilter/index.d.ts +4 -0
  5. package/dist/components/DynamicFilter/components/{PopupEditFilter/components → fieldstypes}/BooleanFilter/styles.d.ts +0 -0
  6. package/dist/components/DynamicFilter/components/fieldstypes/DateTimeFilter/index.d.ts +4 -0
  7. package/dist/components/DynamicFilter/components/{PopupEditFilter/components → fieldstypes}/DateTimeFilter/styles.d.ts +0 -0
  8. package/dist/components/DynamicFilter/components/fieldstypes/NumberFilter/index.d.ts +4 -0
  9. package/dist/components/DynamicFilter/components/{PopupEditFilter/components/StringFilter → fieldstypes/NumberFilter}/styles.d.ts +0 -0
  10. package/dist/components/DynamicFilter/components/fieldstypes/StringFilter/index.d.ts +4 -0
  11. package/dist/components/DynamicFilter/components/fieldstypes/StringFilter/styles.d.ts +3 -0
  12. package/dist/components/DynamicFilter/components/{PopupEditFilter/components → fieldstypes}/factory.d.ts +2 -2
  13. package/dist/components/DynamicFilter/components/{PopupEditFilter/components → fieldstypes}/validations.d.ts +2 -1
  14. package/dist/components/DynamicFilter/index.js +400 -188
  15. package/dist/components/DynamicFilter/types.d.ts +12 -11
  16. package/dist/components/Icon/index.js +27 -4
  17. package/dist/components/Image/index.d.ts +1 -1
  18. package/dist/components/Image/index.js +4 -4
  19. package/dist/components/Image/types.d.ts +1 -1
  20. package/dist/components/ModalDialog/index.js +19 -16
  21. package/dist/components/NoItemSelected/index.d.ts +2 -1
  22. package/dist/components/NoItemSelected/index.js +41 -34
  23. package/dist/components/NoItemSelected/styles.d.ts +2 -2
  24. package/dist/components/NoItemSelected/types.d.ts +6 -1
  25. package/dist/components/ObjectLogs/index.js +9 -7
  26. package/dist/components/SplitLayout/index.js +3 -1
  27. package/dist/components/{DataGrid/formatters → formatters}/BooleanFormatter/index.d.ts +0 -0
  28. package/dist/components/formatters/BooleanFormatter/index.js +32 -0
  29. package/dist/components/{DataGrid/formatters → formatters}/BooleanFormatter/types.d.ts +2 -0
  30. package/dist/components/{DataGrid/formatters → formatters}/DateFormatter/index.d.ts +0 -0
  31. package/dist/components/formatters/DateFormatter/index.js +55 -0
  32. package/dist/components/{DataGrid/formatters → formatters}/DateFormatter/types.d.ts +4 -2
  33. package/dist/components/{DataGrid/formatters → formatters}/index.d.ts +0 -0
  34. package/dist/components/formatters/types.d.ts +2 -0
  35. package/dist/components/index.d.ts +1 -1
  36. package/dist/components/mui_extended/IconButton/index.d.ts +1 -1
  37. package/dist/components/mui_extended/IconButton/index.js +5 -2
  38. package/dist/components/mui_extended/IconButton/types.d.ts +2 -1
  39. package/dist/components/mui_extended/Pager/index.js +3 -0
  40. package/dist/index.js +4 -4
  41. package/dist/vendor.js +3 -4
  42. package/package.json +2 -2
  43. package/dist/components/DataGrid/formatters/BooleanFormatter/index.js +0 -26
  44. package/dist/components/DataGrid/formatters/DateFormatter/index.js +0 -33
  45. package/dist/components/DynamicFilter/components/PopupEditFilter/components/BooleanFilter/index.d.ts +0 -2
  46. package/dist/components/DynamicFilter/components/PopupEditFilter/components/DateTimeFilter/index.d.ts +0 -2
  47. package/dist/components/DynamicFilter/components/PopupEditFilter/components/StringFilter/index.d.ts +0 -2
@@ -1,6 +1,6 @@
1
1
  import { S as ScrollBar } from "../ScrollBar/index.js";
2
- import { styled } from "@mui/material/styles";
3
- import { useRef, useState, useMemo, useCallback, useEffect, createContext, useContext } from "react";
2
+ import { styled, alpha } from "@mui/material/styles";
3
+ import require$$0, { useRef, useState, useMemo, useCallback, useEffect, createContext, useContext } from "react";
4
4
  import { useModuleDictionary, useEnvironment, voidFunction, useHostTools, useFlagsPresent } from "@m4l/core";
5
5
  import * as Yup from "yup";
6
6
  import { useFormContext, useWatch } from "react-hook-form";
@@ -44,6 +44,7 @@ const ContainerApplyedFilters = styled("div")(({
44
44
  gap: theme.spacing(1.5)
45
45
  }));
46
46
  const STRING_OPERATORS = ["c", "nc"];
47
+ const NUMBER_OPERATORS = ["b", "e", "ne", "gt", "gte", "lt", "lte"];
47
48
  const BOOLEAN_OPERATORS = ["e", "ne"];
48
49
  const DATE_TIME_OPERATORS = [
49
50
  "b",
@@ -56,13 +57,13 @@ const DATE_TIME_OPERATORS = [
56
57
  ];
57
58
  const ALL_FIELDS = {
58
59
  name: "all",
59
- label: "filter.all_fields",
60
+ label: "dynamic_filter.all_fields",
60
61
  urlIcon: "https://s3.amazonaws.com/static.made4labs/environments/d1/frontend/components/icon/assets/icons/default.svg",
61
62
  type: "string",
62
63
  multiple: true,
63
64
  fixed: false
64
65
  };
65
- const WrapperStringFilter = styled("div")(({
66
+ const WrapperStringFilter$1 = styled("div")(({
66
67
  theme
67
68
  }) => ({
68
69
  display: "flex",
@@ -74,9 +75,29 @@ const WrapperStringFilter = styled("div")(({
74
75
  padding: theme.spacing(3, 0),
75
76
  gap: theme.spacing(3)
76
77
  }));
77
- const WrapperAutoComplete$2 = styled("div")(() => ({
78
+ const WrapperAutoComplete$3 = styled("div")(() => ({
78
79
  width: "100%"
79
80
  }));
81
+ const getDefaultStringFilter = (field, fixed, getLabel) => {
82
+ const dfop1 = field.defaultOperand1;
83
+ const defaultFilter = {
84
+ id: 0,
85
+ n: field.name,
86
+ fixed,
87
+ isSetted: false,
88
+ o: "c",
89
+ labelOperator: "",
90
+ o1: "",
91
+ o2: "",
92
+ labelOperands: ""
93
+ };
94
+ if (dfop1 !== void 0 && typeof dfop1 === "string") {
95
+ defaultFilter.o1 = dfop1;
96
+ }
97
+ defaultFilter.labelOperands = defaultFilter.o1 + "";
98
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
99
+ return defaultFilter;
100
+ };
80
101
  function StringFilter() {
81
102
  const {
82
103
  popupData: {
@@ -104,12 +125,12 @@ function StringFilter() {
104
125
  return void 0;
105
126
  const newFilter = {
106
127
  id: filter.id,
107
- fieldName: field.name,
128
+ n: field.name,
108
129
  fixed: filter.fixed,
109
130
  isSetted: true,
110
- operator: data.valueOperator.id,
131
+ o: data.valueOperator.id,
111
132
  labelOperator: data.valueOperator.label,
112
- operand1: data.valueOperand1,
133
+ o1: data.valueOperand1,
113
134
  labelOperands: data.valueOperand1
114
135
  };
115
136
  return newFilter;
@@ -123,7 +144,7 @@ function StringFilter() {
123
144
  }
124
145
  setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
125
146
  if (filter && field) {
126
- setValue("valueOperand1", filter.operand1, {
147
+ setValue("valueOperand1", filter.o1, {
127
148
  shouldTouch: false,
128
149
  shouldValidate: false
129
150
  });
@@ -134,9 +155,9 @@ function StringFilter() {
134
155
  console.debug("InputRef", inputRef);
135
156
  inputRef.current?.focus();
136
157
  }, [isLoaded]);
137
- return /* @__PURE__ */ jsx(WrapperStringFilter, {
158
+ return /* @__PURE__ */ jsx(WrapperStringFilter$1, {
138
159
  children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
139
- children: [/* @__PURE__ */ jsx(WrapperAutoComplete$2, {
160
+ children: [/* @__PURE__ */ jsx(WrapperAutoComplete$3, {
140
161
  children: /* @__PURE__ */ jsx(RHFAutocomplete, {
141
162
  name: "valueOperator",
142
163
  autoComplete: "off",
@@ -166,9 +187,29 @@ const WrapperAllFieldsFilter$1 = styled("div")(({
166
187
  padding: theme.spacing(3, 0),
167
188
  gap: theme.spacing(3)
168
189
  }));
169
- const WrapperAutoComplete$1 = styled("div")(() => ({
190
+ const WrapperAutoComplete$2 = styled("div")(() => ({
170
191
  width: "100%"
171
192
  }));
193
+ const getDefaultBooleanFilter = (field, fixed, getLabel) => {
194
+ const dfop1 = field.defaultOperand1;
195
+ const defaultFilter = {
196
+ id: 0,
197
+ n: field.name,
198
+ fixed,
199
+ isSetted: true,
200
+ o: "e",
201
+ labelOperator: "",
202
+ o1: true,
203
+ o2: "",
204
+ labelOperands: ""
205
+ };
206
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
207
+ if (dfop1 !== void 0 && typeof dfop1 === "boolean") {
208
+ defaultFilter.o1 = dfop1;
209
+ }
210
+ defaultFilter.labelOperands = getLabel(`dynamic_filter.operand_${defaultFilter.o1}`);
211
+ return defaultFilter;
212
+ };
172
213
  function BooleanFilter() {
173
214
  const {
174
215
  setPoupEditValidationSchema,
@@ -194,22 +235,22 @@ function BooleanFilter() {
194
235
  })), [getLabelOperator]);
195
236
  const optionsYesNo = useMemo(() => [{
196
237
  value: true,
197
- label: getLabel("filter.operand_true")
238
+ label: getLabel("dynamic_filter.operand_true")
198
239
  }, {
199
240
  value: false,
200
- label: getLabel("filter.operand_false")
241
+ label: getLabel("dynamic_filter.operand_false")
201
242
  }], [getLabel]);
202
243
  const transformFunctionFormValuesToValues = useCallback((data) => {
203
244
  if (!filter || !field)
204
245
  return void 0;
205
246
  const newFilter = {
206
247
  id: filter.id,
207
- fieldName: field.name,
248
+ n: field.name,
208
249
  fixed: filter.fixed,
209
250
  isSetted: true,
210
- operator: data.valueOperator.id,
251
+ o: data.valueOperator.id,
211
252
  labelOperator: data.valueOperator.label,
212
- operand1: data.valueOperand1.value,
253
+ o1: data.valueOperand1.value,
213
254
  labelOperands: data.valueOperand1.label
214
255
  };
215
256
  return newFilter;
@@ -217,15 +258,15 @@ function BooleanFilter() {
217
258
  useEffect(() => {
218
259
  if (!isLoaded) {
219
260
  setPoupEditValidationSchema({
220
- valueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
221
- valueOperand1: Yup.object().nullable().required(getLabel(`operand_required`))
261
+ valueOperator: Yup.object().nullable().required(getLabel(`error_operator_required`)),
262
+ valueOperand1: Yup.object().nullable().required(getLabel(`error_operand_required`))
222
263
  });
223
264
  }
224
265
  setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
225
266
  if (filter && field) {
226
267
  setValue("valueOperand1", {
227
- value: filter.operand1,
228
- label: getLabel(`filter.operand_${filter.operand1}`)
268
+ value: filter.o1,
269
+ label: getLabel(`dynamic_filter.operand_${filter.o1}`)
229
270
  }, {
230
271
  shouldTouch: false,
231
272
  shouldValidate: false
@@ -236,7 +277,7 @@ function BooleanFilter() {
236
277
  return /* @__PURE__ */ jsx(WrapperAllFieldsFilter$1, {
237
278
  id: "WrapperAllFieldsFilter",
238
279
  children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
239
- children: [/* @__PURE__ */ jsx(WrapperAutoComplete$1, {
280
+ children: [/* @__PURE__ */ jsx(WrapperAutoComplete$2, {
240
281
  children: /* @__PURE__ */ jsx(RHFAutocomplete, {
241
282
  name: "valueOperator",
242
283
  autoComplete: "off",
@@ -245,7 +286,7 @@ function BooleanFilter() {
245
286
  isOptionEqualToValue: (option, value) => option.id === value.id,
246
287
  label: ""
247
288
  })
248
- }), /* @__PURE__ */ jsx(WrapperAutoComplete$1, {
289
+ }), /* @__PURE__ */ jsx(WrapperAutoComplete$2, {
249
290
  children: /* @__PURE__ */ jsx(RHFAutocomplete, {
250
291
  name: "valueOperand1",
251
292
  autoComplete: "off",
@@ -270,9 +311,108 @@ const WrapperAllFieldsFilter = styled("div")(({
270
311
  padding: theme.spacing(3, 0),
271
312
  gap: theme.spacing(3)
272
313
  }));
273
- const WrapperAutoComplete = styled("div")(() => ({
314
+ const WrapperAutoComplete$1 = styled("div")(() => ({
274
315
  width: "100%"
275
316
  }));
317
+ function isValidDate(d) {
318
+ return d && d instanceof Date;
319
+ }
320
+ const verifyStringFilter = (filter) => {
321
+ if (typeof filter.o !== "string") {
322
+ return false;
323
+ }
324
+ if (STRING_OPERATORS.findIndex((f) => f === filter.o) === -1) {
325
+ return false;
326
+ }
327
+ if (typeof filter.o1 !== "string") {
328
+ return false;
329
+ }
330
+ return true;
331
+ };
332
+ const verifyNumberFilter = (filter) => {
333
+ if (typeof filter.o !== "number") {
334
+ return false;
335
+ }
336
+ if (NUMBER_OPERATORS.findIndex((f) => f === filter.o) === -1) {
337
+ return false;
338
+ }
339
+ if (typeof filter.o1 !== "number") {
340
+ return false;
341
+ }
342
+ if (filter.o === "b" && typeof filter.o2 !== "number") {
343
+ return false;
344
+ }
345
+ return true;
346
+ };
347
+ const verifyBooleanFilter = (filter) => {
348
+ if (typeof filter.o !== "string") {
349
+ return false;
350
+ }
351
+ if (BOOLEAN_OPERATORS.findIndex((f) => f === filter.o) === -1) {
352
+ return false;
353
+ }
354
+ if (typeof filter.o1 !== "boolean") {
355
+ return false;
356
+ }
357
+ return true;
358
+ };
359
+ const verifyDateTime = (filter) => {
360
+ if (typeof filter.o !== "string") {
361
+ return false;
362
+ }
363
+ if (DATE_TIME_OPERATORS.findIndex((f) => f === filter.o) === -1) {
364
+ return false;
365
+ }
366
+ if (typeof filter.o1 !== "string") {
367
+ return false;
368
+ }
369
+ if (filter.o === "b" && typeof filter.o2 !== "string") {
370
+ return false;
371
+ }
372
+ return true;
373
+ };
374
+ const getDefaultDateTimeFilter = (field, fixed, getLabel) => {
375
+ const defaultStartDate = new Date();
376
+ const defaultEndDate = new Date();
377
+ let dfop1 = field.defaultOperand1;
378
+ let dfop2 = field.defaultOperand2;
379
+ const defaultFilter = {
380
+ id: 0,
381
+ n: field.name,
382
+ fixed,
383
+ isSetted: true,
384
+ o: "b",
385
+ labelOperator: "",
386
+ o1: dfop1,
387
+ o2: dfop2,
388
+ labelOperands: ""
389
+ };
390
+ if (dfop1) {
391
+ if (isValidDate(dfop1)) {
392
+ defaultStartDate.setDate(dfop1.getDate());
393
+ } else {
394
+ dfop1 = void 0;
395
+ }
396
+ }
397
+ if (dfop1 === void 0) {
398
+ defaultStartDate.setHours(0, 0, 0, 0);
399
+ }
400
+ if (dfop2) {
401
+ if (isValidDate(dfop2)) {
402
+ defaultEndDate.setDate(dfop2.getDate());
403
+ } else {
404
+ dfop2 = void 0;
405
+ }
406
+ }
407
+ if (dfop2 === void 0) {
408
+ defaultEndDate.setHours(23, 59, 59, 999);
409
+ }
410
+ defaultFilter.o1 = defaultStartDate.toISOString();
411
+ defaultFilter.o2 = defaultEndDate.toISOString();
412
+ defaultFilter.labelOperands = `${format(defaultStartDate, "yyyy-MM-dd HH:mm:ss")} - ${format(defaultEndDate, "yyyy-MM-dd HH:mm:ss")}`;
413
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
414
+ return defaultFilter;
415
+ };
276
416
  function DateTimeFilter() {
277
417
  const {
278
418
  setPoupEditValidationSchema,
@@ -311,45 +451,45 @@ function DateTimeFilter() {
311
451
  return void 0;
312
452
  const newFilter = {
313
453
  id: filter.id,
314
- fieldName: field.name,
454
+ n: field.name,
315
455
  fixed: filter.fixed,
316
456
  isSetted: true,
317
- operator: data.valueOperator.id,
318
- operand1: data.valueOperand1.toISOString(),
457
+ o: data.valueOperator.id,
458
+ o1: data.valueOperand1.toISOString(),
319
459
  labelOperator: data.valueOperator.label,
320
460
  labelOperands: ""
321
461
  };
322
462
  if (data.valueOperator.id === "b") {
323
- newFilter.operand2 = data.valueOperand2.toISOString();
463
+ newFilter.o2 = data.valueOperand2.toISOString();
324
464
  newFilter.labelOperands = `${format(data.valueOperand1, datetime_format)} - ${format(data.valueOperand2, datetime_format)}`;
325
465
  } else {
326
- newFilter.operand2 = newFilter.operand2 ? newFilter.operand2 : newFilter.operand1;
466
+ newFilter.o2 = newFilter.o2 ? newFilter.o2 : newFilter.o1;
327
467
  newFilter.labelOperands = format(data.valueOperand1, datetime_format);
328
468
  }
329
469
  return newFilter;
330
470
  }, []);
331
471
  useEffect(() => {
332
- console.debug("useEffect Datetime", isLoaded, filter?.operand1, filter?.operand2);
472
+ console.debug("useEffect Datetime", isLoaded, filter?.o1, filter?.o2);
333
473
  if (!isLoaded) {
334
474
  setPoupEditValidationSchema({
335
475
  valueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
336
- valueOperand1: Yup.date().test("valueOperand1", getLabel(`filter.error_invalid_date1`), (value) => {
476
+ valueOperand1: Yup.date().test("valueOperand1", getLabel(`dynamic_filter.error_invalid_date`), (value) => {
337
477
  return Boolean(value);
338
478
  }),
339
479
  valueOperand2: Yup.date().when(["valueOperator.id"], {
340
480
  is: "b",
341
- then: Yup.date().test("DOB", getLabel(`filter.error_invalid_date2`), (value) => {
481
+ then: Yup.date().test("DOB", getLabel(`dynamic_filter.error_invalid_date`), (value) => {
342
482
  return Boolean(value);
343
483
  })
344
484
  })
345
485
  });
346
486
  }
347
487
  if (filter && field) {
348
- setValue("valueOperand1", new Date(filter.operand1), {
488
+ setValue("valueOperand1", new Date(filter.o1), {
349
489
  shouldTouch: false,
350
490
  shouldValidate: false
351
491
  });
352
- setValue("valueOperand2", new Date(filter.operand2), {
492
+ setValue("valueOperand2", new Date(filter.o2), {
353
493
  shouldTouch: false,
354
494
  shouldValidate: false
355
495
  });
@@ -359,7 +499,7 @@ function DateTimeFilter() {
359
499
  }, [getLabel, filter, field]);
360
500
  return /* @__PURE__ */ jsx(WrapperAllFieldsFilter, {
361
501
  children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
362
- children: [/* @__PURE__ */ jsx(WrapperAutoComplete, {
502
+ children: [/* @__PURE__ */ jsx(WrapperAutoComplete$1, {
363
503
  children: /* @__PURE__ */ jsx(RHFAutocomplete, {
364
504
  name: "valueOperator",
365
505
  autoComplete: "off",
@@ -371,7 +511,8 @@ function DateTimeFilter() {
371
511
  }), /* @__PURE__ */ jsx(RHFDateTime, {
372
512
  name: "valueOperand1",
373
513
  autoComplete: "off",
374
- label: ""
514
+ label: "",
515
+ focused: true
375
516
  }), operator && operator.id === "b" && /* @__PURE__ */ jsx(RHFDateTime, {
376
517
  name: "valueOperand2",
377
518
  autoComplete: "off",
@@ -380,126 +521,181 @@ function DateTimeFilter() {
380
521
  })
381
522
  });
382
523
  }
383
- function isValidDate(d) {
384
- return d && d instanceof Date;
385
- }
386
- const verifyStringFilter = (filter) => {
387
- if (typeof filter.operator !== "string") {
388
- return false;
389
- }
390
- if (STRING_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
391
- return false;
392
- }
393
- if (typeof filter.operand1 !== "string") {
394
- return false;
395
- }
396
- return true;
397
- };
398
- const verifyBooleanFilter = (filter) => {
399
- if (typeof filter.operator !== "string") {
400
- return false;
401
- }
402
- if (BOOLEAN_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
403
- return false;
404
- }
405
- if (typeof filter.operand1 !== "boolean") {
406
- return false;
407
- }
408
- return true;
409
- };
410
- const verifyDateTime = (filter) => {
411
- if (typeof filter.operator !== "string") {
412
- return false;
413
- }
414
- if (DATE_TIME_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
415
- return false;
416
- }
417
- if (typeof filter.operand1 !== "string") {
418
- return false;
419
- }
420
- if (filter.operator === "b" && typeof filter.operand2 !== "string") {
421
- return false;
422
- }
423
- return true;
424
- };
425
- const getDefaultFilterValues = (field, fixed, getLabelOperator) => {
426
- const defaultStartDate = new Date();
427
- const defaultEndDate = new Date();
428
- let dfop1 = field.defaultOperand1;
429
- let dfop2 = field.defaultOperand2;
524
+ const WrapperStringFilter = styled("div")(({
525
+ theme
526
+ }) => ({
527
+ display: "flex",
528
+ flexDirection: "column",
529
+ justifyContent: "center",
530
+ alignItems: "center",
531
+ width: "100%",
532
+ minWidth: theme.spacing(3.75),
533
+ padding: theme.spacing(3, 0),
534
+ gap: theme.spacing(3)
535
+ }));
536
+ const WrapperAutoComplete = styled("div")(() => ({
537
+ width: "100%"
538
+ }));
539
+ const getDefaultNumberFilter = (field, fixed, getLabel) => {
540
+ const dfop1 = field.defaultOperand1;
541
+ const dfop2 = field.defaultOperand2;
430
542
  const defaultFilter = {
431
543
  id: 0,
432
- fieldName: field.name,
544
+ n: field.name,
433
545
  fixed,
434
546
  isSetted: false,
435
- operator: "c",
547
+ o: "e",
436
548
  labelOperator: "",
437
- operand1: "",
549
+ o1: "",
550
+ o2: "",
438
551
  labelOperands: ""
439
552
  };
440
- switch (field.type) {
441
- case "string":
442
- break;
443
- case "number":
444
- case "boolean":
445
- defaultFilter.operator = "e";
446
- if (dfop1 !== void 0 && typeof dfop1 === "boolean") {
447
- defaultFilter.operand1 = dfop1;
448
- } else {
449
- defaultFilter.operand1 = true;
450
- }
451
- break;
452
- case "time":
453
- case "date":
454
- case "datetime":
455
- if (dfop1) {
456
- if (isValidDate(dfop1)) {
457
- defaultStartDate.setDate(dfop1.getDate());
458
- } else {
459
- dfop1 = void 0;
460
- }
461
- }
462
- if (dfop1 === void 0) {
463
- defaultStartDate.setHours(0, 0, 0, 0);
464
- }
465
- if (dfop2) {
466
- if (isValidDate(dfop2)) {
467
- defaultEndDate.setDate(dfop2.getDate());
468
- } else {
469
- dfop2 = void 0;
470
- }
471
- }
472
- if (dfop2 === void 0) {
473
- defaultEndDate.setHours(23, 59, 59, 999);
474
- }
475
- defaultFilter.operator = "b";
476
- defaultFilter.operand1 = defaultStartDate.toISOString();
477
- defaultFilter.operand2 = defaultEndDate.toISOString();
478
- defaultFilter.labelOperands = `${format(defaultStartDate, "yyyy-MM-dd HH:mm:ss")} - ${format(defaultEndDate, "yyyy-MM-dd HH:mm:ss")}`;
479
- defaultFilter.isSetted = true;
480
- break;
553
+ if (dfop1 !== void 0 && typeof dfop1 === "number") {
554
+ defaultFilter.o1 = dfop1;
555
+ defaultFilter.labelOperands = defaultFilter.o1;
481
556
  }
482
- defaultFilter.labelOperator = getLabelOperator(defaultFilter.operator);
483
- console.log("operator", defaultFilter);
557
+ if (dfop2 !== void 0 && typeof dfop2 === "number") {
558
+ defaultFilter.o2 = dfop2;
559
+ }
560
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
484
561
  return defaultFilter;
485
562
  };
563
+ function NumberFilter() {
564
+ const {
565
+ popupData: {
566
+ filter,
567
+ field
568
+ },
569
+ setPoupEditValidationSchema,
570
+ setFnTransformFormValuesIntoValues: setTransformFunctionFormValuesToValues,
571
+ getLabelOperator
572
+ } = useBase();
573
+ const {
574
+ getLabel
575
+ } = useModuleDictionary();
576
+ const inputRef = useRef(null);
577
+ const {
578
+ control,
579
+ setValue
580
+ } = useFormContext();
581
+ const [isLoaded, setIsLoaded] = useState(false);
582
+ const operator = useWatch({
583
+ control,
584
+ name: "valueOperator"
585
+ });
586
+ const options = useMemo(() => NUMBER_OPERATORS.map((o) => ({
587
+ id: o,
588
+ label: getLabelOperator(o)
589
+ })), [getLabelOperator]);
590
+ const transformFunctionFormValuesToValues = useCallback((data) => {
591
+ if (!filter || !field)
592
+ return void 0;
593
+ const newFilter = {
594
+ id: filter.id,
595
+ n: field.name,
596
+ fixed: filter.fixed,
597
+ isSetted: true,
598
+ o: data.valueOperator.id,
599
+ o1: Number(data.valueOperand1),
600
+ o2: data.valueOperand2,
601
+ labelOperator: data.valueOperator.label,
602
+ labelOperands: data.valueOperand1
603
+ };
604
+ if (data.valueOperator.id === "b") {
605
+ newFilter.labelOperands = `${data.valueOperand1} - ${data.valueOperand2}`;
606
+ newFilter.o2 = Number(data.valueOperand2);
607
+ } else {
608
+ newFilter.o2 = void 0;
609
+ }
610
+ return newFilter;
611
+ }, []);
612
+ useEffect(() => {
613
+ if (!isLoaded) {
614
+ setPoupEditValidationSchema({
615
+ valueOperator: Yup.object().nullable().required(getLabel(`dynamic_filter.error_operator_required`)),
616
+ valueOperand1: Yup.number().typeError(getLabel(`dynamic_filter.error_operand_mustbe_number`)),
617
+ valueOperand2: Yup.string().when("valueOperator", {
618
+ is: (o) => {
619
+ console.log("valueOperand2", o);
620
+ return o.id === "b";
621
+ },
622
+ then: Yup.string().test("DOB", getLabel(`dynamic_filter.error_operand_mustbe_number`), (value) => {
623
+ console.log("imprimir", value);
624
+ if (value === "")
625
+ return false;
626
+ return !isNaN(Number(value));
627
+ })
628
+ })
629
+ });
630
+ }
631
+ setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
632
+ if (filter && field) {
633
+ setValue("valueOperand1", filter.o1, {
634
+ shouldTouch: false,
635
+ shouldValidate: false
636
+ });
637
+ setValue("valueOperand2", filter.o2, {
638
+ shouldTouch: false,
639
+ shouldValidate: false
640
+ });
641
+ }
642
+ setIsLoaded(true);
643
+ }, [getLabel, filter, field]);
644
+ useEffect(() => {
645
+ console.debug("InputRef", inputRef);
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
+ focused: true
663
+ }), operator && operator.id === "b" && /* @__PURE__ */ jsx(RHFTextField, {
664
+ name: "valueOperand2",
665
+ ref: inputRef
666
+ })]
667
+ })
668
+ });
669
+ }
670
+ const strategiesDefaultFilterValues = {
671
+ string: getDefaultStringFilter,
672
+ number: getDefaultNumberFilter,
673
+ boolean: getDefaultBooleanFilter,
674
+ datetime: getDefaultDateTimeFilter,
675
+ __default__: () => {
676
+ throw new Error("Type no defined");
677
+ }
678
+ };
679
+ const getDefaultFilterValues = (field, fixed, getLabel) => {
680
+ const transformer = strategiesDefaultFilterValues[field.type] ?? strategiesDefaultFilterValues.__default__;
681
+ return transformer(field, fixed, getLabel);
682
+ };
683
+ const strategiesEditFilterComponent = {
684
+ string: StringFilter,
685
+ number: NumberFilter,
686
+ boolean: BooleanFilter,
687
+ datetime: DateTimeFilter,
688
+ __default__: require$$0.Fragment
689
+ };
486
690
  const PopupEditFilterComponent = (props) => {
487
691
  const {
488
692
  getFieldByName
489
693
  } = useBase();
490
- const field = getFieldByName(props.filter.fieldName);
694
+ const field = getFieldByName(props.filter.n);
491
695
  if (!field)
492
696
  return /* @__PURE__ */ jsx(Fragment, {});
493
- switch (field.type) {
494
- case "string":
495
- return /* @__PURE__ */ jsx(StringFilter, {});
496
- case "boolean":
497
- return /* @__PURE__ */ jsx(BooleanFilter, {});
498
- case "datetime":
499
- return /* @__PURE__ */ jsx(DateTimeFilter, {});
500
- default:
501
- return /* @__PURE__ */ jsx(Fragment, {});
502
- }
697
+ const Component = strategiesEditFilterComponent[field.type] ?? strategiesEditFilterComponent.__default__;
698
+ return /* @__PURE__ */ jsx(Component, {});
503
699
  };
504
700
  const initialState = {
505
701
  fields: [],
@@ -543,15 +739,24 @@ const getMaxId = (applyedFilters) => {
543
739
  const getFilterById = (id, applyedFilters) => {
544
740
  return applyedFilters.findIndex((f) => f.id === id);
545
741
  };
546
- const getRawFilter = (applyedFilter) => {
742
+ const formatToInitialFilters = (applyedFilter) => {
743
+ return applyedFilter.map((af) => ({
744
+ n: af.n,
745
+ o: af.o,
746
+ labelOperands: af.labelOperands,
747
+ o1: af.o1,
748
+ o2: af.o2
749
+ }));
750
+ };
751
+ const formatToRawFilter = (applyedFilter) => {
547
752
  return applyedFilter.map((af) => ({
548
- n: af.fieldName,
549
- o: af.operator,
550
- o1: af.operand1,
551
- o2: af.operand2
753
+ n: af.n,
754
+ o: af.o,
755
+ o1: af.o1,
756
+ o2: af.o2
552
757
  }));
553
758
  };
554
- const getInitialFilters = (fields, filters, getFieldByName, getLabelOperator) => {
759
+ const getInitialFilters = (fields, filters, getFieldByName, getLabel) => {
555
760
  const newFilters = [];
556
761
  const fixedFields = [];
557
762
  for (let index = 0; index < filters.length; index++) {
@@ -560,15 +765,19 @@ const getInitialFilters = (fields, filters, getFieldByName, getLabelOperator) =>
560
765
  ...filters[index],
561
766
  id: 0,
562
767
  isSetted: true,
563
- fixed: false
768
+ fixed: false,
769
+ labelOperator: ""
564
770
  };
565
- const field = getFieldByName(filter.fieldName);
771
+ const field = getFieldByName(filter.n);
566
772
  if (!field)
567
773
  continue;
568
774
  switch (field.type) {
569
775
  case "string":
570
776
  add = verifyStringFilter(filter);
571
777
  break;
778
+ case "number":
779
+ add = verifyNumberFilter(filter);
780
+ break;
572
781
  case "boolean":
573
782
  add = verifyBooleanFilter(filter);
574
783
  break;
@@ -589,14 +798,15 @@ const getInitialFilters = (fields, filters, getFieldByName, getLabelOperator) =>
589
798
  }
590
799
  filter.isSetted = true;
591
800
  filter.id = newFilters.length + 1;
801
+ filter.labelOperator = getLabel(`dynamic_filter.operator_${filter.o}`);
592
802
  newFilters.push(filter);
593
803
  }
594
804
  }
595
805
  for (let index = 0; index < fields.length; index++) {
596
806
  const field = fields[index];
597
807
  if (field.fixed) {
598
- if (!filters.find((f) => f.fieldName === field.name)) {
599
- const newFilter = getDefaultFilterValues(field, true, getLabelOperator);
808
+ if (!filters.find((f) => f.n === field.name)) {
809
+ const newFilter = getDefaultFilterValues(field, true, getLabel);
600
810
  newFilter.id = newFilters.length + 1;
601
811
  newFilters.push(newFilter);
602
812
  }
@@ -633,7 +843,7 @@ function BaseProvider(props) {
633
843
  return {
634
844
  ...ALL_FIELDS,
635
845
  label: getLabel("filter.all_fields"),
636
- urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/filter/assets/icons/all_fields.svg`
846
+ urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/all_fields.svg`
637
847
  };
638
848
  }, [getLabel, host_static_assets, environment_assets]);
639
849
  const [inEdition, setInEdition] = useState(false);
@@ -648,9 +858,9 @@ function BaseProvider(props) {
648
858
  });
649
859
  }, [fields, all_fields]);
650
860
  const getLabelOperator = useCallback((operator) => {
651
- return getLabel(`filter.operator_${operator}`);
861
+ return getLabel(`dynamic_filter.operator_${operator}`);
652
862
  }, [getLabel]);
653
- const [applyedFilters, setApplyedFilters] = useState(getInitialFilters(fields, initialFilters, getFieldByName, getLabelOperator));
863
+ const [applyedFilters, setApplyedFilters] = useState(getInitialFilters(fields, initialFilters, getFieldByName, getLabel));
654
864
  const availableFields = useMemo(() => {
655
865
  const newFields = [];
656
866
  for (let index = 0; index < fields.length; index++) {
@@ -658,7 +868,7 @@ function BaseProvider(props) {
658
868
  const field = fields[index];
659
869
  add = true;
660
870
  if (field.multiple !== void 0 && field.multiple === false) {
661
- const fIndx = applyedFilters.findIndex((f) => f.fieldName === field.name);
871
+ const fIndx = applyedFilters.findIndex((f) => f.n === field.name);
662
872
  if (fIndx > -1) {
663
873
  add = false;
664
874
  }
@@ -673,9 +883,9 @@ function BaseProvider(props) {
673
883
  if (isValid) {
674
884
  if (!automatic)
675
885
  setIsDirty(false);
676
- onChangeFilter(applyedFilters, getRawFilter(applyedFilters));
886
+ onChangeFilter(formatToInitialFilters(applyedFilters), formatToRawFilter(applyedFilters));
677
887
  } else {
678
- toast(getLabel("filter.error_filters_no_setted"), {
888
+ toast(getLabel("dynamic_filter.error_filters_no_setted"), {
679
889
  type: "error",
680
890
  autoClose: 1e4
681
891
  });
@@ -693,9 +903,8 @@ function BaseProvider(props) {
693
903
  return;
694
904
  }
695
905
  if (!NoValid) {
696
- console.log("Ingrese");
697
906
  setIsDirty(false);
698
- onChangeFilter(applyedFilters, getRawFilter(applyedFilters));
907
+ onChangeFilter(formatToInitialFilters(applyedFilters), formatToRawFilter(applyedFilters));
699
908
  }
700
909
  }, [applyedFilters]);
701
910
  const addFilter = useCallback((newFilter) => {
@@ -704,7 +913,7 @@ function BaseProvider(props) {
704
913
  const newFilterFull = {
705
914
  ...newFilter,
706
915
  id: getMaxId(lastApplyedFilters) + 1,
707
- labelOperator: getLabelOperator(newFilter.operator)
916
+ labelOperator: getLabelOperator(newFilter.o)
708
917
  };
709
918
  newArray.push(newFilterFull);
710
919
  return newArray;
@@ -717,7 +926,7 @@ function BaseProvider(props) {
717
926
  if (findedFilter > -1) {
718
927
  newArray.splice(findedFilter, 1, {
719
928
  ...newFilter,
720
- labelOperator: getLabelOperator(newFilter.operator)
929
+ labelOperator: getLabelOperator(newFilter.o)
721
930
  });
722
931
  }
723
932
  return newArray;
@@ -758,7 +967,7 @@ function BaseProvider(props) {
758
967
  const showPopupForAddFilter = useCallback((anchorEl, field) => {
759
968
  setPopupData({
760
969
  popupAnchorEl: anchorEl,
761
- filter: getDefaultFilterValues(field, false, getLabelOperator),
970
+ filter: getDefaultFilterValues(field, false, getLabel),
762
971
  field
763
972
  });
764
973
  setInEdition(true);
@@ -767,7 +976,7 @@ function BaseProvider(props) {
767
976
  setPopupData({
768
977
  popupAnchorEl: anchorEl,
769
978
  filter: filterToEdit,
770
- field: getFieldByName(filterToEdit.fieldName)
979
+ field: getFieldByName(filterToEdit.n)
771
980
  });
772
981
  setInEdition(true);
773
982
  }, []);
@@ -875,7 +1084,7 @@ const ContainerOperands = styled("span")(({
875
1084
  }));
876
1085
  function ApplyedFilter(props) {
877
1086
  const {
878
- fieldName,
1087
+ n: fieldName,
879
1088
  id,
880
1089
  isSetted,
881
1090
  fixed,
@@ -1015,28 +1224,27 @@ const SKTWrapperFilterButton = styled("div")(({
1015
1224
  justifyContent: "center",
1016
1225
  alignItems: "center",
1017
1226
  minWidth: theme.spacing(3.75),
1018
- height: theme.spacing(3.75)
1019
- }));
1020
- styled("div")(({
1021
- theme
1022
- }) => ({
1023
- display: "flex",
1024
- justifyContent: "center",
1025
- alignItems: "center",
1026
- minWidth: theme.spacing(3.75),
1027
- height: theme.spacing(3.75)
1227
+ height: theme.spacing(3.75),
1228
+ background: alpha(theme.palette.primary.main, 0.3)
1028
1229
  }));
1029
1230
  const WrapperFilterButton = styled("div")(() => ({
1030
1231
  "&.isDirty": {
1232
+ animationName: "dirtyEffect",
1233
+ animationDuration: "1s",
1234
+ animationFillMode: "both",
1235
+ animationIterationCount: "infinite",
1236
+ transition: "all .3s",
1031
1237
  "@keyframes dirtyEffect": {
1032
- from: {
1238
+ "20%": {
1033
1239
  opacity: 1
1034
1240
  },
1035
- to: {
1036
- opacity: 0
1241
+ "50%": {
1242
+ opacity: 0.5
1243
+ },
1244
+ "100%": {
1245
+ opacity: 1
1037
1246
  }
1038
- },
1039
- animation: "dirtyEffect 2s infinite ease"
1247
+ }
1040
1248
  },
1041
1249
  "&.isDirtyError": {}
1042
1250
  }));
@@ -1064,18 +1272,21 @@ function FilterButton() {
1064
1272
  }
1065
1273
  const color = useMemo(() => {
1066
1274
  if (automatic) {
1067
- return "default";
1275
+ return "active";
1068
1276
  }
1069
1277
  if (!isValid) {
1070
1278
  return "error";
1071
1279
  }
1072
- return "primary";
1280
+ return "selected";
1073
1281
  }, [automatic, isValid]);
1282
+ console.log("Dynamic color value", color);
1283
+ console.log("Dynamic automatic value", automatic);
1074
1284
  return /* @__PURE__ */ jsx(WrapperFilterButton, {
1285
+ id: "WrapperFilterButton",
1075
1286
  className: isDirty && isValid ? "isDirty" : "",
1076
1287
  children: /* @__PURE__ */ jsx(IconButton, {
1077
- color,
1078
- dictionaryTooltip: "filter.filter_tooltip",
1288
+ bgColor: color,
1289
+ dictionaryTooltip: "dynamic_filter.filter_tooltip",
1079
1290
  onClick: () => fireOnChangeFilters(),
1080
1291
  "aria-label": "settings",
1081
1292
  src: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/${automatic ? "refresh" : "search"}.svg`
@@ -1171,11 +1382,11 @@ function InputFilter() {
1171
1382
  }
1172
1383
  if (withAllField) {
1173
1384
  addFilter({
1174
- fieldName: ALL_FIELDS.name,
1385
+ n: ALL_FIELDS.name,
1175
1386
  isSetted: true,
1176
1387
  fixed: false,
1177
- operator: "c",
1178
- operand1: valueFilter,
1388
+ o: "c",
1389
+ o1: valueFilter,
1179
1390
  labelOperands: valueFilter
1180
1391
  });
1181
1392
  setValueFilter("");
@@ -1186,6 +1397,7 @@ function InputFilter() {
1186
1397
  if (!withAllField && availableFields.length == 0) {
1187
1398
  return /* @__PURE__ */ jsx(Fragment, {});
1188
1399
  }
1400
+ console.log("availableFields test", availableFields.length);
1189
1401
  return /* @__PURE__ */ jsxs(WrapperInputFilter, {
1190
1402
  id: "WrapperInputFilter",
1191
1403
  children: [/* @__PURE__ */ jsx(StyledInputFilter, {
@@ -1195,7 +1407,7 @@ function InputFilter() {
1195
1407
  onClick: onClickFilter,
1196
1408
  onChange: onChangeFilter,
1197
1409
  onKeyPress: handleKeyPressMenu
1198
- }), /* @__PURE__ */ jsx(MenuPopover, {
1410
+ }), availableFields.length > 0 && /* @__PURE__ */ jsx(MenuPopover, {
1199
1411
  id: "MenuPopover",
1200
1412
  open: Boolean(openAnchorEl),
1201
1413
  anchorEl: openAnchorEl,
@@ -1283,8 +1495,8 @@ const PopupEditFilter = () => {
1283
1495
  const valuesFilter = {
1284
1496
  ...filter,
1285
1497
  valueOperator: {
1286
- id: filter.operator,
1287
- label: getLabelOperator(filter.operator)
1498
+ id: filter.o,
1499
+ label: getLabelOperator(filter.o)
1288
1500
  }
1289
1501
  };
1290
1502
  return valuesFilter;