@m4l/components 0.0.37 → 0.0.40

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 (31) hide show
  1. package/dist/components/DataGrid/index.js +0 -1
  2. package/dist/components/DynamicFilter/components/fieldstypes/validations.d.ts +1 -0
  3. package/dist/components/DynamicFilter/index.js +146 -122
  4. package/dist/components/DynamicFilter/types.d.ts +10 -10
  5. package/dist/components/Icon/index.js +1 -0
  6. package/dist/components/Image/index.d.ts +1 -1
  7. package/dist/components/Image/index.js +4 -4
  8. package/dist/components/Image/types.d.ts +1 -1
  9. package/dist/components/ModalDialog/index.js +19 -16
  10. package/dist/components/NoItemSelected/index.d.ts +2 -1
  11. package/dist/components/NoItemSelected/index.js +41 -33
  12. package/dist/components/NoItemSelected/styles.d.ts +2 -2
  13. package/dist/components/NoItemSelected/types.d.ts +6 -1
  14. package/dist/components/ObjectLogs/index.js +11 -9
  15. package/dist/components/SplitLayout/index.js +3 -1
  16. package/dist/components/{DataGrid/formatters → formatters}/BooleanFormatter/index.d.ts +0 -0
  17. package/dist/components/formatters/BooleanFormatter/index.js +32 -0
  18. package/dist/components/{DataGrid/formatters → formatters}/BooleanFormatter/types.d.ts +2 -0
  19. package/dist/components/{DataGrid/formatters → formatters}/DateFormatter/index.d.ts +0 -0
  20. package/dist/components/formatters/DateFormatter/index.js +55 -0
  21. package/dist/components/{DataGrid/formatters → formatters}/DateFormatter/types.d.ts +4 -2
  22. package/dist/components/{DataGrid/formatters → formatters}/index.d.ts +0 -0
  23. package/dist/components/formatters/types.d.ts +2 -0
  24. package/dist/components/index.d.ts +1 -1
  25. package/dist/components/mui_extended/IconButton/index.js +3 -2
  26. package/dist/components/mui_extended/Pager/index.js +3 -0
  27. package/dist/index.js +4 -4
  28. package/dist/vendor.js +3 -4
  29. package/package.json +2 -2
  30. package/dist/components/DataGrid/formatters/BooleanFormatter/index.js +0 -26
  31. package/dist/components/DataGrid/formatters/DateFormatter/index.js +0 -33
@@ -11,7 +11,6 @@ import { P as Pager, g as getPagerComponentsDictionary, d as defaultPagerDiction
11
11
  import { I as IconButton } from "../mui_extended/IconButton/index.js";
12
12
  import { u as useModal } from "../../hooks/useModal/index.js";
13
13
  import { useResponsiveDesktop } from "@m4l/graphics";
14
- import "date-fns";
15
14
  import { g as getModalDialogComponentsDictionary, d as defaultModalDialogDictionary } from "../ModalDialog/index.js";
16
15
  const WrapperGrid$1 = styled("div")(() => ({
17
16
  display: "flex",
@@ -1,5 +1,6 @@
1
1
  import { InitialFilterFieldApply } from '../../types';
2
2
  export declare function isValidDate(d: any): any;
3
3
  export declare const verifyStringFilter: (filter: InitialFilterFieldApply) => boolean;
4
+ export declare const verifyNumberFilter: (filter: InitialFilterFieldApply) => boolean;
4
5
  export declare const verifyBooleanFilter: (filter: InitialFilterFieldApply) => boolean;
5
6
  export declare const verifyDateTime: (filter: InitialFilterFieldApply) => boolean;
@@ -1,6 +1,6 @@
1
1
  import { S as ScrollBar } from "../ScrollBar/index.js";
2
2
  import { styled, alpha } from "@mui/material/styles";
3
- import { useRef, useState, useMemo, useCallback, useEffect, createContext, useContext } from "react";
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";
@@ -61,7 +61,7 @@ const ALL_FIELDS = {
61
61
  urlIcon: "https://s3.amazonaws.com/static.made4labs/environments/d1/frontend/components/icon/assets/icons/default.svg",
62
62
  type: "string",
63
63
  multiple: true,
64
- fixed: false
64
+ presence: "optional"
65
65
  };
66
66
  const WrapperStringFilter$1 = styled("div")(({
67
67
  theme
@@ -82,20 +82,20 @@ const getDefaultStringFilter = (field, fixed, getLabel) => {
82
82
  const dfop1 = field.defaultOperand1;
83
83
  const defaultFilter = {
84
84
  id: 0,
85
- fieldName: field.name,
85
+ n: field.name,
86
86
  fixed,
87
87
  isSetted: false,
88
- operator: "c",
88
+ o: "c",
89
89
  labelOperator: "",
90
- operand1: "",
91
- operand2: "",
90
+ o1: "",
91
+ o2: "",
92
92
  labelOperands: ""
93
93
  };
94
94
  if (dfop1 !== void 0 && typeof dfop1 === "string") {
95
- defaultFilter.operand1 = dfop1;
95
+ defaultFilter.o1 = dfop1;
96
96
  }
97
- defaultFilter.labelOperands = defaultFilter.operand1 + "";
98
- defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.operator}`);
97
+ defaultFilter.labelOperands = defaultFilter.o1 + "";
98
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
99
99
  return defaultFilter;
100
100
  };
101
101
  function StringFilter() {
@@ -125,12 +125,12 @@ function StringFilter() {
125
125
  return void 0;
126
126
  const newFilter = {
127
127
  id: filter.id,
128
- fieldName: field.name,
128
+ n: field.name,
129
129
  fixed: filter.fixed,
130
130
  isSetted: true,
131
- operator: data.valueOperator.id,
131
+ o: data.valueOperator.id,
132
132
  labelOperator: data.valueOperator.label,
133
- operand1: data.valueOperand1,
133
+ o1: data.valueOperand1,
134
134
  labelOperands: data.valueOperand1
135
135
  };
136
136
  return newFilter;
@@ -144,7 +144,7 @@ function StringFilter() {
144
144
  }
145
145
  setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
146
146
  if (filter && field) {
147
- setValue("valueOperand1", filter.operand1, {
147
+ setValue("valueOperand1", filter.o1, {
148
148
  shouldTouch: false,
149
149
  shouldValidate: false
150
150
  });
@@ -194,20 +194,20 @@ const getDefaultBooleanFilter = (field, fixed, getLabel) => {
194
194
  const dfop1 = field.defaultOperand1;
195
195
  const defaultFilter = {
196
196
  id: 0,
197
- fieldName: field.name,
197
+ n: field.name,
198
198
  fixed,
199
199
  isSetted: true,
200
- operator: "e",
200
+ o: "e",
201
201
  labelOperator: "",
202
- operand1: true,
203
- operand2: "",
202
+ o1: true,
203
+ o2: "",
204
204
  labelOperands: ""
205
205
  };
206
- defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.operator}`);
206
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
207
207
  if (dfop1 !== void 0 && typeof dfop1 === "boolean") {
208
- defaultFilter.operand1 = dfop1;
208
+ defaultFilter.o1 = dfop1;
209
209
  }
210
- defaultFilter.labelOperands = getLabel(`dynamic_filter.operand_${defaultFilter.operand1}`);
210
+ defaultFilter.labelOperands = getLabel(`dynamic_filter.operand_${defaultFilter.o1}`);
211
211
  return defaultFilter;
212
212
  };
213
213
  function BooleanFilter() {
@@ -245,12 +245,12 @@ function BooleanFilter() {
245
245
  return void 0;
246
246
  const newFilter = {
247
247
  id: filter.id,
248
- fieldName: field.name,
248
+ n: field.name,
249
249
  fixed: filter.fixed,
250
250
  isSetted: true,
251
- operator: data.valueOperator.id,
251
+ o: data.valueOperator.id,
252
252
  labelOperator: data.valueOperator.label,
253
- operand1: data.valueOperand1.value,
253
+ o1: data.valueOperand1.value,
254
254
  labelOperands: data.valueOperand1.label
255
255
  };
256
256
  return newFilter;
@@ -258,15 +258,15 @@ function BooleanFilter() {
258
258
  useEffect(() => {
259
259
  if (!isLoaded) {
260
260
  setPoupEditValidationSchema({
261
- valueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
262
- 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`))
263
263
  });
264
264
  }
265
265
  setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
266
266
  if (filter && field) {
267
267
  setValue("valueOperand1", {
268
- value: filter.operand1,
269
- label: getLabel(`dynamic_filter.operand_${filter.operand1}`)
268
+ value: filter.o1,
269
+ label: getLabel(`dynamic_filter.operand_${filter.o1}`)
270
270
  }, {
271
271
  shouldTouch: false,
272
272
  shouldValidate: false
@@ -318,40 +318,55 @@ function isValidDate(d) {
318
318
  return d && d instanceof Date;
319
319
  }
320
320
  const verifyStringFilter = (filter) => {
321
- if (typeof filter.operator !== "string") {
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) {
322
337
  return false;
323
338
  }
324
- if (STRING_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
339
+ if (typeof filter.o1 !== "number") {
325
340
  return false;
326
341
  }
327
- if (typeof filter.operand1 !== "string") {
342
+ if (filter.o === "b" && typeof filter.o2 !== "number") {
328
343
  return false;
329
344
  }
330
345
  return true;
331
346
  };
332
347
  const verifyBooleanFilter = (filter) => {
333
- if (typeof filter.operator !== "string") {
348
+ if (typeof filter.o !== "string") {
334
349
  return false;
335
350
  }
336
- if (BOOLEAN_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
351
+ if (BOOLEAN_OPERATORS.findIndex((f) => f === filter.o) === -1) {
337
352
  return false;
338
353
  }
339
- if (typeof filter.operand1 !== "boolean") {
354
+ if (typeof filter.o1 !== "boolean") {
340
355
  return false;
341
356
  }
342
357
  return true;
343
358
  };
344
359
  const verifyDateTime = (filter) => {
345
- if (typeof filter.operator !== "string") {
360
+ if (typeof filter.o !== "string") {
346
361
  return false;
347
362
  }
348
- if (DATE_TIME_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
363
+ if (DATE_TIME_OPERATORS.findIndex((f) => f === filter.o) === -1) {
349
364
  return false;
350
365
  }
351
- if (typeof filter.operand1 !== "string") {
366
+ if (typeof filter.o1 !== "string") {
352
367
  return false;
353
368
  }
354
- if (filter.operator === "b" && typeof filter.operand2 !== "string") {
369
+ if (filter.o === "b" && typeof filter.o2 !== "string") {
355
370
  return false;
356
371
  }
357
372
  return true;
@@ -363,13 +378,13 @@ const getDefaultDateTimeFilter = (field, fixed, getLabel) => {
363
378
  let dfop2 = field.defaultOperand2;
364
379
  const defaultFilter = {
365
380
  id: 0,
366
- fieldName: field.name,
381
+ n: field.name,
367
382
  fixed,
368
383
  isSetted: true,
369
- operator: "b",
384
+ o: "b",
370
385
  labelOperator: "",
371
- operand1: dfop1,
372
- operand2: dfop2,
386
+ o1: dfop1,
387
+ o2: dfop2,
373
388
  labelOperands: ""
374
389
  };
375
390
  if (dfop1) {
@@ -392,10 +407,10 @@ const getDefaultDateTimeFilter = (field, fixed, getLabel) => {
392
407
  if (dfop2 === void 0) {
393
408
  defaultEndDate.setHours(23, 59, 59, 999);
394
409
  }
395
- defaultFilter.operand1 = defaultStartDate.toISOString();
396
- defaultFilter.operand2 = defaultEndDate.toISOString();
410
+ defaultFilter.o1 = defaultStartDate.toISOString();
411
+ defaultFilter.o2 = defaultEndDate.toISOString();
397
412
  defaultFilter.labelOperands = `${format(defaultStartDate, "yyyy-MM-dd HH:mm:ss")} - ${format(defaultEndDate, "yyyy-MM-dd HH:mm:ss")}`;
398
- defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.operator}`);
413
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
399
414
  return defaultFilter;
400
415
  };
401
416
  function DateTimeFilter() {
@@ -436,45 +451,45 @@ function DateTimeFilter() {
436
451
  return void 0;
437
452
  const newFilter = {
438
453
  id: filter.id,
439
- fieldName: field.name,
454
+ n: field.name,
440
455
  fixed: filter.fixed,
441
456
  isSetted: true,
442
- operator: data.valueOperator.id,
443
- operand1: data.valueOperand1.toISOString(),
457
+ o: data.valueOperator.id,
458
+ o1: data.valueOperand1.toISOString(),
444
459
  labelOperator: data.valueOperator.label,
445
460
  labelOperands: ""
446
461
  };
447
462
  if (data.valueOperator.id === "b") {
448
- newFilter.operand2 = data.valueOperand2.toISOString();
463
+ newFilter.o2 = data.valueOperand2.toISOString();
449
464
  newFilter.labelOperands = `${format(data.valueOperand1, datetime_format)} - ${format(data.valueOperand2, datetime_format)}`;
450
465
  } else {
451
- newFilter.operand2 = newFilter.operand2 ? newFilter.operand2 : newFilter.operand1;
466
+ newFilter.o2 = newFilter.o2 ? newFilter.o2 : newFilter.o1;
452
467
  newFilter.labelOperands = format(data.valueOperand1, datetime_format);
453
468
  }
454
469
  return newFilter;
455
470
  }, []);
456
471
  useEffect(() => {
457
- console.debug("useEffect Datetime", isLoaded, filter?.operand1, filter?.operand2);
472
+ console.debug("useEffect Datetime", isLoaded, filter?.o1, filter?.o2);
458
473
  if (!isLoaded) {
459
474
  setPoupEditValidationSchema({
460
475
  valueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
461
- valueOperand1: Yup.date().test("valueOperand1", getLabel(`dynamic_filter.error_invalid_date1`), (value) => {
476
+ valueOperand1: Yup.date().test("valueOperand1", getLabel(`dynamic_filter.error_invalid_date`), (value) => {
462
477
  return Boolean(value);
463
478
  }),
464
479
  valueOperand2: Yup.date().when(["valueOperator.id"], {
465
480
  is: "b",
466
- then: Yup.date().test("DOB", getLabel(`dynamic_filter.error_invalid_date2`), (value) => {
481
+ then: Yup.date().test("DOB", getLabel(`dynamic_filter.error_invalid_date`), (value) => {
467
482
  return Boolean(value);
468
483
  })
469
484
  })
470
485
  });
471
486
  }
472
487
  if (filter && field) {
473
- setValue("valueOperand1", new Date(filter.operand1), {
488
+ setValue("valueOperand1", new Date(filter.o1), {
474
489
  shouldTouch: false,
475
490
  shouldValidate: false
476
491
  });
477
- setValue("valueOperand2", new Date(filter.operand2), {
492
+ setValue("valueOperand2", new Date(filter.o2), {
478
493
  shouldTouch: false,
479
494
  shouldValidate: false
480
495
  });
@@ -526,23 +541,23 @@ const getDefaultNumberFilter = (field, fixed, getLabel) => {
526
541
  const dfop2 = field.defaultOperand2;
527
542
  const defaultFilter = {
528
543
  id: 0,
529
- fieldName: field.name,
544
+ n: field.name,
530
545
  fixed,
531
546
  isSetted: false,
532
- operator: "e",
547
+ o: "e",
533
548
  labelOperator: "",
534
- operand1: "",
535
- operand2: "",
549
+ o1: "",
550
+ o2: "",
536
551
  labelOperands: ""
537
552
  };
538
553
  if (dfop1 !== void 0 && typeof dfop1 === "number") {
539
- defaultFilter.operand1 = dfop1;
540
- defaultFilter.labelOperands = defaultFilter.operand1;
554
+ defaultFilter.o1 = dfop1;
555
+ defaultFilter.labelOperands = defaultFilter.o1;
541
556
  }
542
557
  if (dfop2 !== void 0 && typeof dfop2 === "number") {
543
- defaultFilter.operand2 = dfop2;
558
+ defaultFilter.o2 = dfop2;
544
559
  }
545
- defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.operator}`);
560
+ defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.o}`);
546
561
  return defaultFilter;
547
562
  };
548
563
  function NumberFilter() {
@@ -577,34 +592,34 @@ function NumberFilter() {
577
592
  return void 0;
578
593
  const newFilter = {
579
594
  id: filter.id,
580
- fieldName: field.name,
595
+ n: field.name,
581
596
  fixed: filter.fixed,
582
597
  isSetted: true,
583
- operator: data.valueOperator.id,
584
- operand1: Number(data.valueOperand1),
585
- operand2: data.valueOperand2,
598
+ o: data.valueOperator.id,
599
+ o1: Number(data.valueOperand1),
600
+ o2: data.valueOperand2,
586
601
  labelOperator: data.valueOperator.label,
587
602
  labelOperands: data.valueOperand1
588
603
  };
589
604
  if (data.valueOperator.id === "b") {
590
605
  newFilter.labelOperands = `${data.valueOperand1} - ${data.valueOperand2}`;
591
- newFilter.operand2 = Number(data.valueOperand2);
606
+ newFilter.o2 = Number(data.valueOperand2);
592
607
  } else {
593
- newFilter.operand2 = void 0;
608
+ newFilter.o2 = void 0;
594
609
  }
595
610
  return newFilter;
596
611
  }, []);
597
612
  useEffect(() => {
598
613
  if (!isLoaded) {
599
614
  setPoupEditValidationSchema({
600
- valueOperator: Yup.object().nullable().required(getLabel(`dynamic_filter.operator_required`)),
601
- valueOperand1: Yup.number().typeError(getLabel(`dynamic_filter.operand_mustbe_number`)),
615
+ valueOperator: Yup.object().nullable().required(getLabel(`dynamic_filter.error_operator_required`)),
616
+ valueOperand1: Yup.number().typeError(getLabel(`dynamic_filter.error_operand_mustbe_number`)),
602
617
  valueOperand2: Yup.string().when("valueOperator", {
603
618
  is: (o) => {
604
619
  console.log("valueOperand2", o);
605
620
  return o.id === "b";
606
621
  },
607
- then: Yup.string().test("DOB", getLabel(`dynamic_filter.operand_mustbe_number`), (value) => {
622
+ then: Yup.string().test("DOB", getLabel(`dynamic_filter.error_operand_mustbe_number`), (value) => {
608
623
  console.log("imprimir", value);
609
624
  if (value === "")
610
625
  return false;
@@ -615,11 +630,11 @@ function NumberFilter() {
615
630
  }
616
631
  setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
617
632
  if (filter && field) {
618
- setValue("valueOperand1", filter.operand1, {
633
+ setValue("valueOperand1", filter.o1, {
619
634
  shouldTouch: false,
620
635
  shouldValidate: false
621
636
  });
622
- setValue("valueOperand2", filter.operand2, {
637
+ setValue("valueOperand2", filter.o2, {
623
638
  shouldTouch: false,
624
639
  shouldValidate: false
625
640
  });
@@ -652,40 +667,35 @@ function NumberFilter() {
652
667
  })
653
668
  });
654
669
  }
655
- const getDefaultFilterValues = (field, fixed, getLabel) => {
656
- switch (field.type) {
657
- case "string":
658
- return getDefaultStringFilter(field, fixed, getLabel);
659
- case "number":
660
- return getDefaultNumberFilter(field, fixed, getLabel);
661
- case "boolean":
662
- return getDefaultBooleanFilter(field, fixed, getLabel);
663
- case "time":
664
- case "date":
665
- case "datetime":
666
- return getDefaultDateTimeFilter(field, fixed, getLabel);
670
+ const strategiesDefaultFilterValues = {
671
+ string: getDefaultStringFilter,
672
+ number: getDefaultNumberFilter,
673
+ boolean: getDefaultBooleanFilter,
674
+ datetime: getDefaultDateTimeFilter,
675
+ __default__: () => {
676
+ throw new Error("Type no defined");
667
677
  }
668
- throw new Error("Type no defined");
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
669
689
  };
670
690
  const PopupEditFilterComponent = (props) => {
671
691
  const {
672
692
  getFieldByName
673
693
  } = useBase();
674
- const field = getFieldByName(props.filter.fieldName);
694
+ const field = getFieldByName(props.filter.n);
675
695
  if (!field)
676
696
  return /* @__PURE__ */ jsx(Fragment, {});
677
- switch (field.type) {
678
- case "string":
679
- return /* @__PURE__ */ jsx(StringFilter, {});
680
- case "number":
681
- return /* @__PURE__ */ jsx(NumberFilter, {});
682
- case "boolean":
683
- return /* @__PURE__ */ jsx(BooleanFilter, {});
684
- case "datetime":
685
- return /* @__PURE__ */ jsx(DateTimeFilter, {});
686
- default:
687
- return /* @__PURE__ */ jsx(Fragment, {});
688
- }
697
+ const Component = strategiesEditFilterComponent[field.type] ?? strategiesEditFilterComponent.__default__;
698
+ return /* @__PURE__ */ jsx(Component, {});
689
699
  };
690
700
  const initialState = {
691
701
  fields: [],
@@ -729,12 +739,21 @@ const getMaxId = (applyedFilters) => {
729
739
  const getFilterById = (id, applyedFilters) => {
730
740
  return applyedFilters.findIndex((f) => f.id === id);
731
741
  };
732
- const getRawFilter = (applyedFilter) => {
742
+ const formatToInitialFilters = (applyedFilter) => {
733
743
  return applyedFilter.map((af) => ({
734
- n: af.fieldName,
735
- o: af.operator,
736
- o1: af.operand1,
737
- o2: af.operand2
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) => {
752
+ return applyedFilter.map((af) => ({
753
+ n: af.n,
754
+ o: af.o,
755
+ o1: af.o1,
756
+ o2: af.o2
738
757
  }));
739
758
  };
740
759
  const getInitialFilters = (fields, filters, getFieldByName, getLabel) => {
@@ -746,15 +765,19 @@ const getInitialFilters = (fields, filters, getFieldByName, getLabel) => {
746
765
  ...filters[index],
747
766
  id: 0,
748
767
  isSetted: true,
749
- fixed: false
768
+ fixed: false,
769
+ labelOperator: ""
750
770
  };
751
- const field = getFieldByName(filter.fieldName);
771
+ const field = getFieldByName(filter.n);
752
772
  if (!field)
753
773
  continue;
754
774
  switch (field.type) {
755
775
  case "string":
756
776
  add = verifyStringFilter(filter);
757
777
  break;
778
+ case "number":
779
+ add = verifyNumberFilter(filter);
780
+ break;
758
781
  case "boolean":
759
782
  add = verifyBooleanFilter(filter);
760
783
  break;
@@ -765,7 +788,7 @@ const getInitialFilters = (fields, filters, getFieldByName, getLabel) => {
765
788
  add = false;
766
789
  }
767
790
  if (add) {
768
- if (field.fixed) {
791
+ if (field.presence === "fixed") {
769
792
  if (fixedFields.findIndex((f) => f === field.name) === -1) {
770
793
  filter.fixed = true;
771
794
  fixedFields.push(field.name);
@@ -775,14 +798,15 @@ const getInitialFilters = (fields, filters, getFieldByName, getLabel) => {
775
798
  }
776
799
  filter.isSetted = true;
777
800
  filter.id = newFilters.length + 1;
801
+ filter.labelOperator = getLabel(`dynamic_filter.operator_${filter.o}`);
778
802
  newFilters.push(filter);
779
803
  }
780
804
  }
781
805
  for (let index = 0; index < fields.length; index++) {
782
806
  const field = fields[index];
783
- if (field.fixed) {
784
- if (!filters.find((f) => f.fieldName === field.name)) {
785
- const newFilter = getDefaultFilterValues(field, true, getLabel);
807
+ if (field.presence === "initialized" || field.presence === "fixed") {
808
+ if (!filters.find((f) => f.n === field.name)) {
809
+ const newFilter = getDefaultFilterValues(field, field.presence === "fixed", getLabel);
786
810
  newFilter.id = newFilters.length + 1;
787
811
  newFilters.push(newFilter);
788
812
  }
@@ -844,7 +868,7 @@ function BaseProvider(props) {
844
868
  const field = fields[index];
845
869
  add = true;
846
870
  if (field.multiple !== void 0 && field.multiple === false) {
847
- const fIndx = applyedFilters.findIndex((f) => f.fieldName === field.name);
871
+ const fIndx = applyedFilters.findIndex((f) => f.n === field.name);
848
872
  if (fIndx > -1) {
849
873
  add = false;
850
874
  }
@@ -859,7 +883,7 @@ function BaseProvider(props) {
859
883
  if (isValid) {
860
884
  if (!automatic)
861
885
  setIsDirty(false);
862
- onChangeFilter(applyedFilters, getRawFilter(applyedFilters));
886
+ onChangeFilter(formatToInitialFilters(applyedFilters), formatToRawFilter(applyedFilters));
863
887
  } else {
864
888
  toast(getLabel("dynamic_filter.error_filters_no_setted"), {
865
889
  type: "error",
@@ -880,7 +904,7 @@ function BaseProvider(props) {
880
904
  }
881
905
  if (!NoValid) {
882
906
  setIsDirty(false);
883
- onChangeFilter(applyedFilters, getRawFilter(applyedFilters));
907
+ onChangeFilter(formatToInitialFilters(applyedFilters), formatToRawFilter(applyedFilters));
884
908
  }
885
909
  }, [applyedFilters]);
886
910
  const addFilter = useCallback((newFilter) => {
@@ -889,7 +913,7 @@ function BaseProvider(props) {
889
913
  const newFilterFull = {
890
914
  ...newFilter,
891
915
  id: getMaxId(lastApplyedFilters) + 1,
892
- labelOperator: getLabelOperator(newFilter.operator)
916
+ labelOperator: getLabelOperator(newFilter.o)
893
917
  };
894
918
  newArray.push(newFilterFull);
895
919
  return newArray;
@@ -902,7 +926,7 @@ function BaseProvider(props) {
902
926
  if (findedFilter > -1) {
903
927
  newArray.splice(findedFilter, 1, {
904
928
  ...newFilter,
905
- labelOperator: getLabelOperator(newFilter.operator)
929
+ labelOperator: getLabelOperator(newFilter.o)
906
930
  });
907
931
  }
908
932
  return newArray;
@@ -952,7 +976,7 @@ function BaseProvider(props) {
952
976
  setPopupData({
953
977
  popupAnchorEl: anchorEl,
954
978
  filter: filterToEdit,
955
- field: getFieldByName(filterToEdit.fieldName)
979
+ field: getFieldByName(filterToEdit.n)
956
980
  });
957
981
  setInEdition(true);
958
982
  }, []);
@@ -1060,7 +1084,7 @@ const ContainerOperands = styled("span")(({
1060
1084
  }));
1061
1085
  function ApplyedFilter(props) {
1062
1086
  const {
1063
- fieldName,
1087
+ n: fieldName,
1064
1088
  id,
1065
1089
  isSetted,
1066
1090
  fixed,
@@ -1358,11 +1382,11 @@ function InputFilter() {
1358
1382
  }
1359
1383
  if (withAllField) {
1360
1384
  addFilter({
1361
- fieldName: ALL_FIELDS.name,
1385
+ n: ALL_FIELDS.name,
1362
1386
  isSetted: true,
1363
1387
  fixed: false,
1364
- operator: "c",
1365
- operand1: valueFilter,
1388
+ o: "c",
1389
+ o1: valueFilter,
1366
1390
  labelOperands: valueFilter
1367
1391
  });
1368
1392
  setValueFilter("");
@@ -1471,8 +1495,8 @@ const PopupEditFilter = () => {
1471
1495
  const valuesFilter = {
1472
1496
  ...filter,
1473
1497
  valueOperator: {
1474
- id: filter.operator,
1475
- label: getLabelOperator(filter.operator)
1498
+ id: filter.o,
1499
+ label: getLabelOperator(filter.o)
1476
1500
  }
1477
1501
  };
1478
1502
  return valuesFilter;
@@ -1,5 +1,5 @@
1
1
  import { Maybe } from '@m4l/core';
2
- export declare type FieldType = 'number' | 'string' | 'boolean' | 'date' | 'datetime' | 'time' | 'select' | 'in';
2
+ export declare type FieldType = 'number' | 'string' | 'boolean' | 'datetime';
3
3
  export declare type OperandType = number | string | boolean | Date | [] | object;
4
4
  export declare type Operator = 'b' | 'e' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'c' | 'nc';
5
5
  export declare const OPERATORS: Array<Operator>;
@@ -11,12 +11,13 @@ export declare type BooleanOperator = 'e' | 'ne';
11
11
  export declare const BOOLEAN_OPERATORS: Array<BooleanOperator>;
12
12
  export declare type DateTimeOperator = 'b' | 'e' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
13
13
  export declare const DATE_TIME_OPERATORS: Array<DateTimeOperator>;
14
+ export declare type FieldPresence = 'initialized' | 'fixed' | 'optional';
14
15
  export interface Field {
15
16
  name: string;
16
17
  label: string;
17
18
  type: FieldType;
18
19
  multiple?: boolean;
19
- fixed?: boolean;
20
+ presence?: FieldPresence;
20
21
  urlIcon: string;
21
22
  defaultOperand1?: Maybe<OperandType>;
22
23
  defaultOperand2?: Maybe<OperandType>;
@@ -27,16 +28,16 @@ export interface OptionOperator<T> {
27
28
  }
28
29
  export interface BaseApplyFilter {
29
30
  id: number;
30
- fieldName: string;
31
+ n: string;
31
32
  isSetted: boolean;
32
33
  fixed: boolean;
33
34
  }
34
35
  export interface ValuesFilter {
35
- operator: Operator;
36
+ o: Operator;
36
37
  labelOperator: string;
37
38
  labelOperands: string | number;
38
- operand1?: Maybe<OperandType>;
39
- operand2?: Maybe<OperandType>;
39
+ o1?: Maybe<OperandType>;
40
+ o2?: Maybe<OperandType>;
40
41
  }
41
42
  export interface FormValuesFilter<T> {
42
43
  valueOperator?: Maybe<OptionOperator<T>>;
@@ -49,9 +50,8 @@ export interface RawFilterFieldApply {
49
50
  o1: Maybe<OperandType>;
50
51
  o2: Maybe<OperandType>;
51
52
  }
52
- export interface FilterFieldApply extends BaseApplyFilter, ValuesFilter {
53
- }
54
- export declare type InitialFilterFieldApply = Omit<FilterFieldApply, 'id' | 'fixed' | 'isSetted'>;
53
+ export declare type FilterFieldApply = BaseApplyFilter & ValuesFilter;
54
+ export declare type InitialFilterFieldApply = Omit<FilterFieldApply, 'id' | 'fixed' | 'isSetted' | 'labelOperator'>;
55
55
  export declare type FilterToAddApply = Omit<FilterFieldApply, 'id' | 'labelOperator'>;
56
56
  export declare type FilterToEditApply = Omit<FilterFieldApply, 'labelOperator'>;
57
57
  export interface FilterFormFieldApply extends BaseApplyFilter, ValuesFilter, FormValuesFilter<Operator> {
@@ -63,5 +63,5 @@ export interface DynamicFilterProps {
63
63
  withAllField?: boolean;
64
64
  fields: Array<Field>;
65
65
  initialFilters?: Array<InitialFilterFieldApply>;
66
- onChangeFilter: (newFilters: Array<FilterFieldApply>, rawFilters: Array<RawFilterFieldApply>) => void;
66
+ onChangeFilter: (initialFilters: Array<InitialFilterFieldApply>, rawFilters: Array<RawFilterFieldApply>) => void;
67
67
  }