@m4l/components 0.0.35 → 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CompanyLogo/index.js +2 -3
- package/dist/components/DataGrid/index.js +21 -22
- package/dist/components/DynamicFilter/components/FilterButton/styles.d.ts +0 -1
- package/dist/components/DynamicFilter/components/fieldstypes/BooleanFilter/index.d.ts +4 -0
- package/dist/components/DynamicFilter/components/{PopupEditFilter/components → fieldstypes}/BooleanFilter/styles.d.ts +0 -0
- package/dist/components/DynamicFilter/components/fieldstypes/DateTimeFilter/index.d.ts +4 -0
- package/dist/components/DynamicFilter/components/{PopupEditFilter/components → fieldstypes}/DateTimeFilter/styles.d.ts +0 -0
- package/dist/components/DynamicFilter/components/fieldstypes/NumberFilter/index.d.ts +4 -0
- package/dist/components/DynamicFilter/components/{PopupEditFilter/components/StringFilter → fieldstypes/NumberFilter}/styles.d.ts +0 -0
- package/dist/components/DynamicFilter/components/fieldstypes/StringFilter/index.d.ts +4 -0
- package/dist/components/DynamicFilter/components/fieldstypes/StringFilter/styles.d.ts +3 -0
- package/dist/components/DynamicFilter/components/{PopupEditFilter/components → fieldstypes}/factory.d.ts +2 -2
- package/dist/components/DynamicFilter/components/{PopupEditFilter/components → fieldstypes}/validations.d.ts +1 -1
- package/dist/components/DynamicFilter/index.js +338 -140
- package/dist/components/DynamicFilter/types.d.ts +4 -2
- package/dist/components/Icon/index.js +29 -6
- package/dist/components/ModalDialog/index.js +6 -6
- package/dist/components/NoItemSelected/index.js +2 -3
- package/dist/components/ObjectLogs/index.js +17 -7
- package/dist/components/{DataGrid/formatters → formatters}/BooleanFormatter/index.d.ts +0 -0
- package/dist/components/formatters/BooleanFormatter/index.js +32 -0
- package/dist/components/{DataGrid/formatters → formatters}/BooleanFormatter/types.d.ts +2 -0
- package/dist/components/{DataGrid/formatters → formatters}/DateFormatter/index.d.ts +0 -0
- package/dist/components/formatters/DateFormatter/index.js +55 -0
- package/dist/components/{DataGrid/formatters → formatters}/DateFormatter/types.d.ts +4 -2
- package/dist/components/{DataGrid/formatters → formatters}/index.d.ts +0 -0
- package/dist/components/formatters/types.d.ts +2 -0
- package/dist/components/hook-form/RHFDateTime.js +9 -2
- package/dist/components/hook-form/RHFUpload.js +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/mui_extended/Accordion/index.js +2 -2
- package/dist/components/mui_extended/IconButton/index.d.ts +1 -1
- package/dist/components/mui_extended/IconButton/index.js +4 -2
- package/dist/components/mui_extended/IconButton/types.d.ts +2 -1
- package/dist/components/mui_extended/MenuActions/index.js +3 -3
- package/dist/components/mui_extended/Pager/index.js +5 -5
- package/dist/contexts/ModalContext/index.js +4 -4
- package/dist/index.js +3 -3
- package/dist/vendor.js +3 -3
- package/package.json +2 -5
- package/dist/components/DataGrid/formatters/BooleanFormatter/index.js +0 -26
- package/dist/components/DataGrid/formatters/DateFormatter/index.js +0 -33
- package/dist/components/DynamicFilter/components/PopupEditFilter/components/BooleanFilter/index.d.ts +0 -2
- package/dist/components/DynamicFilter/components/PopupEditFilter/components/DateTimeFilter/index.d.ts +0 -2
- package/dist/components/DynamicFilter/components/PopupEditFilter/components/StringFilter/index.d.ts +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S as ScrollBar } from "../ScrollBar/index.js";
|
|
2
|
-
import { styled } from "@mui/material/styles";
|
|
2
|
+
import { styled, alpha } from "@mui/material/styles";
|
|
3
3
|
import { useRef, useState, useMemo, useCallback, useEffect, createContext, useContext } from "react";
|
|
4
|
-
import { useModuleDictionary, voidFunction, useHostTools,
|
|
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";
|
|
7
7
|
import { F as FormProvider } from "../hook-form/FormProvider/index.js";
|
|
@@ -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: "
|
|
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$
|
|
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
|
+
fieldName: field.name,
|
|
86
|
+
fixed,
|
|
87
|
+
isSetted: false,
|
|
88
|
+
operator: "c",
|
|
89
|
+
labelOperator: "",
|
|
90
|
+
operand1: "",
|
|
91
|
+
operand2: "",
|
|
92
|
+
labelOperands: ""
|
|
93
|
+
};
|
|
94
|
+
if (dfop1 !== void 0 && typeof dfop1 === "string") {
|
|
95
|
+
defaultFilter.operand1 = dfop1;
|
|
96
|
+
}
|
|
97
|
+
defaultFilter.labelOperands = defaultFilter.operand1 + "";
|
|
98
|
+
defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.operator}`);
|
|
99
|
+
return defaultFilter;
|
|
100
|
+
};
|
|
80
101
|
function StringFilter() {
|
|
81
102
|
const {
|
|
82
103
|
popupData: {
|
|
@@ -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$
|
|
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$
|
|
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
|
+
fieldName: field.name,
|
|
198
|
+
fixed,
|
|
199
|
+
isSetted: true,
|
|
200
|
+
operator: "e",
|
|
201
|
+
labelOperator: "",
|
|
202
|
+
operand1: true,
|
|
203
|
+
operand2: "",
|
|
204
|
+
labelOperands: ""
|
|
205
|
+
};
|
|
206
|
+
defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.operator}`);
|
|
207
|
+
if (dfop1 !== void 0 && typeof dfop1 === "boolean") {
|
|
208
|
+
defaultFilter.operand1 = dfop1;
|
|
209
|
+
}
|
|
210
|
+
defaultFilter.labelOperands = getLabel(`dynamic_filter.operand_${defaultFilter.operand1}`);
|
|
211
|
+
return defaultFilter;
|
|
212
|
+
};
|
|
172
213
|
function BooleanFilter() {
|
|
173
214
|
const {
|
|
174
215
|
setPoupEditValidationSchema,
|
|
@@ -194,10 +235,10 @@ function BooleanFilter() {
|
|
|
194
235
|
})), [getLabelOperator]);
|
|
195
236
|
const optionsYesNo = useMemo(() => [{
|
|
196
237
|
value: true,
|
|
197
|
-
label: getLabel("
|
|
238
|
+
label: getLabel("dynamic_filter.operand_true")
|
|
198
239
|
}, {
|
|
199
240
|
value: false,
|
|
200
|
-
label: getLabel("
|
|
241
|
+
label: getLabel("dynamic_filter.operand_false")
|
|
201
242
|
}], [getLabel]);
|
|
202
243
|
const transformFunctionFormValuesToValues = useCallback((data) => {
|
|
203
244
|
if (!filter || !field)
|
|
@@ -225,7 +266,7 @@ function BooleanFilter() {
|
|
|
225
266
|
if (filter && field) {
|
|
226
267
|
setValue("valueOperand1", {
|
|
227
268
|
value: filter.operand1,
|
|
228
|
-
label: getLabel(`
|
|
269
|
+
label: getLabel(`dynamic_filter.operand_${filter.operand1}`)
|
|
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$
|
|
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$
|
|
289
|
+
}), /* @__PURE__ */ jsx(WrapperAutoComplete$2, {
|
|
249
290
|
children: /* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
250
291
|
name: "valueOperand1",
|
|
251
292
|
autoComplete: "off",
|
|
@@ -270,9 +311,93 @@ 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.operator !== "string") {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
if (STRING_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
if (typeof filter.operand1 !== "string") {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
};
|
|
332
|
+
const verifyBooleanFilter = (filter) => {
|
|
333
|
+
if (typeof filter.operator !== "string") {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
if (BOOLEAN_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
if (typeof filter.operand1 !== "boolean") {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
return true;
|
|
343
|
+
};
|
|
344
|
+
const verifyDateTime = (filter) => {
|
|
345
|
+
if (typeof filter.operator !== "string") {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
if (DATE_TIME_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
if (typeof filter.operand1 !== "string") {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
if (filter.operator === "b" && typeof filter.operand2 !== "string") {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
return true;
|
|
358
|
+
};
|
|
359
|
+
const getDefaultDateTimeFilter = (field, fixed, getLabel) => {
|
|
360
|
+
const defaultStartDate = new Date();
|
|
361
|
+
const defaultEndDate = new Date();
|
|
362
|
+
let dfop1 = field.defaultOperand1;
|
|
363
|
+
let dfop2 = field.defaultOperand2;
|
|
364
|
+
const defaultFilter = {
|
|
365
|
+
id: 0,
|
|
366
|
+
fieldName: field.name,
|
|
367
|
+
fixed,
|
|
368
|
+
isSetted: true,
|
|
369
|
+
operator: "b",
|
|
370
|
+
labelOperator: "",
|
|
371
|
+
operand1: dfop1,
|
|
372
|
+
operand2: dfop2,
|
|
373
|
+
labelOperands: ""
|
|
374
|
+
};
|
|
375
|
+
if (dfop1) {
|
|
376
|
+
if (isValidDate(dfop1)) {
|
|
377
|
+
defaultStartDate.setDate(dfop1.getDate());
|
|
378
|
+
} else {
|
|
379
|
+
dfop1 = void 0;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (dfop1 === void 0) {
|
|
383
|
+
defaultStartDate.setHours(0, 0, 0, 0);
|
|
384
|
+
}
|
|
385
|
+
if (dfop2) {
|
|
386
|
+
if (isValidDate(dfop2)) {
|
|
387
|
+
defaultEndDate.setDate(dfop2.getDate());
|
|
388
|
+
} else {
|
|
389
|
+
dfop2 = void 0;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (dfop2 === void 0) {
|
|
393
|
+
defaultEndDate.setHours(23, 59, 59, 999);
|
|
394
|
+
}
|
|
395
|
+
defaultFilter.operand1 = defaultStartDate.toISOString();
|
|
396
|
+
defaultFilter.operand2 = defaultEndDate.toISOString();
|
|
397
|
+
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}`);
|
|
399
|
+
return defaultFilter;
|
|
400
|
+
};
|
|
276
401
|
function DateTimeFilter() {
|
|
277
402
|
const {
|
|
278
403
|
setPoupEditValidationSchema,
|
|
@@ -282,6 +407,11 @@ function DateTimeFilter() {
|
|
|
282
407
|
const {
|
|
283
408
|
getLabel
|
|
284
409
|
} = useModuleDictionary();
|
|
410
|
+
const {
|
|
411
|
+
dfnsFormat: {
|
|
412
|
+
datetime_format
|
|
413
|
+
}
|
|
414
|
+
} = useEnvironment();
|
|
285
415
|
const {
|
|
286
416
|
popupData: {
|
|
287
417
|
filter,
|
|
@@ -316,10 +446,10 @@ function DateTimeFilter() {
|
|
|
316
446
|
};
|
|
317
447
|
if (data.valueOperator.id === "b") {
|
|
318
448
|
newFilter.operand2 = data.valueOperand2.toISOString();
|
|
319
|
-
newFilter.labelOperands = `${format(data.valueOperand1,
|
|
449
|
+
newFilter.labelOperands = `${format(data.valueOperand1, datetime_format)} - ${format(data.valueOperand2, datetime_format)}`;
|
|
320
450
|
} else {
|
|
321
451
|
newFilter.operand2 = newFilter.operand2 ? newFilter.operand2 : newFilter.operand1;
|
|
322
|
-
newFilter.labelOperands = format(data.valueOperand1,
|
|
452
|
+
newFilter.labelOperands = format(data.valueOperand1, datetime_format);
|
|
323
453
|
}
|
|
324
454
|
return newFilter;
|
|
325
455
|
}, []);
|
|
@@ -328,12 +458,12 @@ function DateTimeFilter() {
|
|
|
328
458
|
if (!isLoaded) {
|
|
329
459
|
setPoupEditValidationSchema({
|
|
330
460
|
valueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
|
|
331
|
-
valueOperand1: Yup.date().test("valueOperand1", getLabel(`
|
|
461
|
+
valueOperand1: Yup.date().test("valueOperand1", getLabel(`dynamic_filter.error_invalid_date1`), (value) => {
|
|
332
462
|
return Boolean(value);
|
|
333
463
|
}),
|
|
334
464
|
valueOperand2: Yup.date().when(["valueOperator.id"], {
|
|
335
465
|
is: "b",
|
|
336
|
-
then: Yup.date().test("DOB", getLabel(`
|
|
466
|
+
then: Yup.date().test("DOB", getLabel(`dynamic_filter.error_invalid_date2`), (value) => {
|
|
337
467
|
return Boolean(value);
|
|
338
468
|
})
|
|
339
469
|
})
|
|
@@ -354,7 +484,7 @@ function DateTimeFilter() {
|
|
|
354
484
|
}, [getLabel, filter, field]);
|
|
355
485
|
return /* @__PURE__ */ jsx(WrapperAllFieldsFilter, {
|
|
356
486
|
children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
|
|
357
|
-
children: [/* @__PURE__ */ jsx(WrapperAutoComplete, {
|
|
487
|
+
children: [/* @__PURE__ */ jsx(WrapperAutoComplete$1, {
|
|
358
488
|
children: /* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
359
489
|
name: "valueOperator",
|
|
360
490
|
autoComplete: "off",
|
|
@@ -366,7 +496,8 @@ function DateTimeFilter() {
|
|
|
366
496
|
}), /* @__PURE__ */ jsx(RHFDateTime, {
|
|
367
497
|
name: "valueOperand1",
|
|
368
498
|
autoComplete: "off",
|
|
369
|
-
label: ""
|
|
499
|
+
label: "",
|
|
500
|
+
focused: true
|
|
370
501
|
}), operator && operator.id === "b" && /* @__PURE__ */ jsx(RHFDateTime, {
|
|
371
502
|
name: "valueOperand2",
|
|
372
503
|
autoComplete: "off",
|
|
@@ -375,108 +506,166 @@ function DateTimeFilter() {
|
|
|
375
506
|
})
|
|
376
507
|
});
|
|
377
508
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
};
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
if (BOOLEAN_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
|
|
398
|
-
return false;
|
|
399
|
-
}
|
|
400
|
-
if (typeof filter.operand1 !== "boolean") {
|
|
401
|
-
return false;
|
|
402
|
-
}
|
|
403
|
-
return true;
|
|
404
|
-
};
|
|
405
|
-
const verifyDateTime = (filter) => {
|
|
406
|
-
if (typeof filter.operator !== "string") {
|
|
407
|
-
return false;
|
|
408
|
-
}
|
|
409
|
-
if (DATE_TIME_OPERATORS.findIndex((f) => f === filter.operator) === -1) {
|
|
410
|
-
return false;
|
|
411
|
-
}
|
|
412
|
-
if (typeof filter.operand1 !== "string") {
|
|
413
|
-
return false;
|
|
414
|
-
}
|
|
415
|
-
if (filter.operator === "b" && typeof filter.operand2 !== "string") {
|
|
416
|
-
return false;
|
|
417
|
-
}
|
|
418
|
-
return true;
|
|
419
|
-
};
|
|
420
|
-
const getDefaultFilterValues = (field, fixed, getLabelOperator) => {
|
|
421
|
-
const defaultStartDate = new Date();
|
|
422
|
-
const defaultEndDate = new Date();
|
|
423
|
-
let dfop1 = field.defaultOperand1;
|
|
424
|
-
let dfop2 = field.defaultOperand2;
|
|
509
|
+
const WrapperStringFilter = styled("div")(({
|
|
510
|
+
theme
|
|
511
|
+
}) => ({
|
|
512
|
+
display: "flex",
|
|
513
|
+
flexDirection: "column",
|
|
514
|
+
justifyContent: "center",
|
|
515
|
+
alignItems: "center",
|
|
516
|
+
width: "100%",
|
|
517
|
+
minWidth: theme.spacing(3.75),
|
|
518
|
+
padding: theme.spacing(3, 0),
|
|
519
|
+
gap: theme.spacing(3)
|
|
520
|
+
}));
|
|
521
|
+
const WrapperAutoComplete = styled("div")(() => ({
|
|
522
|
+
width: "100%"
|
|
523
|
+
}));
|
|
524
|
+
const getDefaultNumberFilter = (field, fixed, getLabel) => {
|
|
525
|
+
const dfop1 = field.defaultOperand1;
|
|
526
|
+
const dfop2 = field.defaultOperand2;
|
|
425
527
|
const defaultFilter = {
|
|
426
528
|
id: 0,
|
|
427
529
|
fieldName: field.name,
|
|
428
530
|
fixed,
|
|
429
531
|
isSetted: false,
|
|
430
|
-
operator: "
|
|
532
|
+
operator: "e",
|
|
431
533
|
labelOperator: "",
|
|
432
534
|
operand1: "",
|
|
535
|
+
operand2: "",
|
|
433
536
|
labelOperands: ""
|
|
434
537
|
};
|
|
538
|
+
if (dfop1 !== void 0 && typeof dfop1 === "number") {
|
|
539
|
+
defaultFilter.operand1 = dfop1;
|
|
540
|
+
defaultFilter.labelOperands = defaultFilter.operand1;
|
|
541
|
+
}
|
|
542
|
+
if (dfop2 !== void 0 && typeof dfop2 === "number") {
|
|
543
|
+
defaultFilter.operand2 = dfop2;
|
|
544
|
+
}
|
|
545
|
+
defaultFilter.labelOperator = getLabel(`dynamic_filter.operator_${defaultFilter.operator}`);
|
|
546
|
+
return defaultFilter;
|
|
547
|
+
};
|
|
548
|
+
function NumberFilter() {
|
|
549
|
+
const {
|
|
550
|
+
popupData: {
|
|
551
|
+
filter,
|
|
552
|
+
field
|
|
553
|
+
},
|
|
554
|
+
setPoupEditValidationSchema,
|
|
555
|
+
setFnTransformFormValuesIntoValues: setTransformFunctionFormValuesToValues,
|
|
556
|
+
getLabelOperator
|
|
557
|
+
} = useBase();
|
|
558
|
+
const {
|
|
559
|
+
getLabel
|
|
560
|
+
} = useModuleDictionary();
|
|
561
|
+
const inputRef = useRef(null);
|
|
562
|
+
const {
|
|
563
|
+
control,
|
|
564
|
+
setValue
|
|
565
|
+
} = useFormContext();
|
|
566
|
+
const [isLoaded, setIsLoaded] = useState(false);
|
|
567
|
+
const operator = useWatch({
|
|
568
|
+
control,
|
|
569
|
+
name: "valueOperator"
|
|
570
|
+
});
|
|
571
|
+
const options = useMemo(() => NUMBER_OPERATORS.map((o) => ({
|
|
572
|
+
id: o,
|
|
573
|
+
label: getLabelOperator(o)
|
|
574
|
+
})), [getLabelOperator]);
|
|
575
|
+
const transformFunctionFormValuesToValues = useCallback((data) => {
|
|
576
|
+
if (!filter || !field)
|
|
577
|
+
return void 0;
|
|
578
|
+
const newFilter = {
|
|
579
|
+
id: filter.id,
|
|
580
|
+
fieldName: field.name,
|
|
581
|
+
fixed: filter.fixed,
|
|
582
|
+
isSetted: true,
|
|
583
|
+
operator: data.valueOperator.id,
|
|
584
|
+
operand1: Number(data.valueOperand1),
|
|
585
|
+
operand2: data.valueOperand2,
|
|
586
|
+
labelOperator: data.valueOperator.label,
|
|
587
|
+
labelOperands: data.valueOperand1
|
|
588
|
+
};
|
|
589
|
+
if (data.valueOperator.id === "b") {
|
|
590
|
+
newFilter.labelOperands = `${data.valueOperand1} - ${data.valueOperand2}`;
|
|
591
|
+
newFilter.operand2 = Number(data.valueOperand2);
|
|
592
|
+
} else {
|
|
593
|
+
newFilter.operand2 = void 0;
|
|
594
|
+
}
|
|
595
|
+
return newFilter;
|
|
596
|
+
}, []);
|
|
597
|
+
useEffect(() => {
|
|
598
|
+
if (!isLoaded) {
|
|
599
|
+
setPoupEditValidationSchema({
|
|
600
|
+
valueOperator: Yup.object().nullable().required(getLabel(`dynamic_filter.operator_required`)),
|
|
601
|
+
valueOperand1: Yup.number().typeError(getLabel(`dynamic_filter.operand_mustbe_number`)),
|
|
602
|
+
valueOperand2: Yup.string().when("valueOperator", {
|
|
603
|
+
is: (o) => {
|
|
604
|
+
console.log("valueOperand2", o);
|
|
605
|
+
return o.id === "b";
|
|
606
|
+
},
|
|
607
|
+
then: Yup.string().test("DOB", getLabel(`dynamic_filter.operand_mustbe_number`), (value) => {
|
|
608
|
+
console.log("imprimir", value);
|
|
609
|
+
if (value === "")
|
|
610
|
+
return false;
|
|
611
|
+
return !isNaN(Number(value));
|
|
612
|
+
})
|
|
613
|
+
})
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
setTransformFunctionFormValuesToValues(transformFunctionFormValuesToValues);
|
|
617
|
+
if (filter && field) {
|
|
618
|
+
setValue("valueOperand1", filter.operand1, {
|
|
619
|
+
shouldTouch: false,
|
|
620
|
+
shouldValidate: false
|
|
621
|
+
});
|
|
622
|
+
setValue("valueOperand2", filter.operand2, {
|
|
623
|
+
shouldTouch: false,
|
|
624
|
+
shouldValidate: false
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
setIsLoaded(true);
|
|
628
|
+
}, [getLabel, filter, field]);
|
|
629
|
+
useEffect(() => {
|
|
630
|
+
console.debug("InputRef", inputRef);
|
|
631
|
+
inputRef.current?.focus();
|
|
632
|
+
}, [isLoaded]);
|
|
633
|
+
return /* @__PURE__ */ jsx(WrapperStringFilter, {
|
|
634
|
+
children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
|
|
635
|
+
children: [/* @__PURE__ */ jsx(WrapperAutoComplete, {
|
|
636
|
+
children: /* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
637
|
+
name: "valueOperator",
|
|
638
|
+
autoComplete: "off",
|
|
639
|
+
options,
|
|
640
|
+
getOptionLabel: (option) => option.label,
|
|
641
|
+
isOptionEqualToValue: (option, value) => option.id === value.id,
|
|
642
|
+
label: ""
|
|
643
|
+
})
|
|
644
|
+
}), /* @__PURE__ */ jsx(RHFTextField, {
|
|
645
|
+
name: "valueOperand1",
|
|
646
|
+
ref: inputRef,
|
|
647
|
+
focused: true
|
|
648
|
+
}), operator && operator.id === "b" && /* @__PURE__ */ jsx(RHFTextField, {
|
|
649
|
+
name: "valueOperand2",
|
|
650
|
+
ref: inputRef
|
|
651
|
+
})]
|
|
652
|
+
})
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
const getDefaultFilterValues = (field, fixed, getLabel) => {
|
|
435
656
|
switch (field.type) {
|
|
436
657
|
case "string":
|
|
437
|
-
|
|
658
|
+
return getDefaultStringFilter(field, fixed, getLabel);
|
|
438
659
|
case "number":
|
|
660
|
+
return getDefaultNumberFilter(field, fixed, getLabel);
|
|
439
661
|
case "boolean":
|
|
440
|
-
|
|
441
|
-
if (dfop1 !== void 0 && typeof dfop1 === "boolean") {
|
|
442
|
-
defaultFilter.operand1 = dfop1;
|
|
443
|
-
} else {
|
|
444
|
-
defaultFilter.operand1 = true;
|
|
445
|
-
}
|
|
446
|
-
break;
|
|
662
|
+
return getDefaultBooleanFilter(field, fixed, getLabel);
|
|
447
663
|
case "time":
|
|
448
664
|
case "date":
|
|
449
665
|
case "datetime":
|
|
450
|
-
|
|
451
|
-
if (isValidDate(dfop1)) {
|
|
452
|
-
defaultStartDate.setDate(dfop1.getDate());
|
|
453
|
-
} else {
|
|
454
|
-
dfop1 = void 0;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
if (dfop1 === void 0) {
|
|
458
|
-
defaultStartDate.setHours(0, 0, 0, 0);
|
|
459
|
-
}
|
|
460
|
-
if (dfop2) {
|
|
461
|
-
if (isValidDate(dfop2)) {
|
|
462
|
-
defaultEndDate.setDate(dfop2.getDate());
|
|
463
|
-
} else {
|
|
464
|
-
dfop2 = void 0;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
if (dfop2 === void 0) {
|
|
468
|
-
defaultEndDate.setHours(23, 59, 59, 999);
|
|
469
|
-
}
|
|
470
|
-
defaultFilter.operator = "b";
|
|
471
|
-
defaultFilter.operand1 = defaultStartDate.toISOString();
|
|
472
|
-
defaultFilter.operand2 = defaultEndDate.toISOString();
|
|
473
|
-
defaultFilter.labelOperands = `${format(defaultStartDate, "yyyy-MM-dd HH:mm:ss")} - ${format(defaultEndDate, "yyyy-MM-dd HH:mm:ss")}`;
|
|
474
|
-
defaultFilter.isSetted = true;
|
|
475
|
-
break;
|
|
666
|
+
return getDefaultDateTimeFilter(field, fixed, getLabel);
|
|
476
667
|
}
|
|
477
|
-
|
|
478
|
-
console.log("operator", defaultFilter);
|
|
479
|
-
return defaultFilter;
|
|
668
|
+
throw new Error("Type no defined");
|
|
480
669
|
};
|
|
481
670
|
const PopupEditFilterComponent = (props) => {
|
|
482
671
|
const {
|
|
@@ -488,6 +677,8 @@ const PopupEditFilterComponent = (props) => {
|
|
|
488
677
|
switch (field.type) {
|
|
489
678
|
case "string":
|
|
490
679
|
return /* @__PURE__ */ jsx(StringFilter, {});
|
|
680
|
+
case "number":
|
|
681
|
+
return /* @__PURE__ */ jsx(NumberFilter, {});
|
|
491
682
|
case "boolean":
|
|
492
683
|
return /* @__PURE__ */ jsx(BooleanFilter, {});
|
|
493
684
|
case "datetime":
|
|
@@ -546,7 +737,7 @@ const getRawFilter = (applyedFilter) => {
|
|
|
546
737
|
o2: af.operand2
|
|
547
738
|
}));
|
|
548
739
|
};
|
|
549
|
-
const getInitialFilters = (fields, filters, getFieldByName,
|
|
740
|
+
const getInitialFilters = (fields, filters, getFieldByName, getLabel) => {
|
|
550
741
|
const newFilters = [];
|
|
551
742
|
const fixedFields = [];
|
|
552
743
|
for (let index = 0; index < filters.length; index++) {
|
|
@@ -591,7 +782,7 @@ const getInitialFilters = (fields, filters, getFieldByName, getLabelOperator) =>
|
|
|
591
782
|
const field = fields[index];
|
|
592
783
|
if (field.fixed) {
|
|
593
784
|
if (!filters.find((f) => f.fieldName === field.name)) {
|
|
594
|
-
const newFilter = getDefaultFilterValues(field, true,
|
|
785
|
+
const newFilter = getDefaultFilterValues(field, true, getLabel);
|
|
595
786
|
newFilter.id = newFilters.length + 1;
|
|
596
787
|
newFilters.push(newFilter);
|
|
597
788
|
}
|
|
@@ -620,12 +811,17 @@ function BaseProvider(props) {
|
|
|
620
811
|
} = useModuleDictionary();
|
|
621
812
|
const [popupValidationSchema, setInternalPopupValidationSchema] = useState(Yup.object().shape({}));
|
|
622
813
|
const [fnTransformFormValuesIntoRawValues, setInternalfnTransormFormValuesIntoRawValues] = useState(() => void 0);
|
|
814
|
+
const {
|
|
815
|
+
host_static_assets,
|
|
816
|
+
environment_assets
|
|
817
|
+
} = useEnvironment();
|
|
623
818
|
const all_fields = useMemo(() => {
|
|
624
819
|
return {
|
|
625
820
|
...ALL_FIELDS,
|
|
626
|
-
label: getLabel("filter.all_fields")
|
|
821
|
+
label: getLabel("filter.all_fields"),
|
|
822
|
+
urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/all_fields.svg`
|
|
627
823
|
};
|
|
628
|
-
}, [getLabel]);
|
|
824
|
+
}, [getLabel, host_static_assets, environment_assets]);
|
|
629
825
|
const [inEdition, setInEdition] = useState(false);
|
|
630
826
|
const [isDirty, setIsDirty] = useState(!automatic);
|
|
631
827
|
const [isValid, setIsValid] = useState(false);
|
|
@@ -638,9 +834,9 @@ function BaseProvider(props) {
|
|
|
638
834
|
});
|
|
639
835
|
}, [fields, all_fields]);
|
|
640
836
|
const getLabelOperator = useCallback((operator) => {
|
|
641
|
-
return getLabel(`
|
|
837
|
+
return getLabel(`dynamic_filter.operator_${operator}`);
|
|
642
838
|
}, [getLabel]);
|
|
643
|
-
const [applyedFilters, setApplyedFilters] = useState(getInitialFilters(fields, initialFilters, getFieldByName,
|
|
839
|
+
const [applyedFilters, setApplyedFilters] = useState(getInitialFilters(fields, initialFilters, getFieldByName, getLabel));
|
|
644
840
|
const availableFields = useMemo(() => {
|
|
645
841
|
const newFields = [];
|
|
646
842
|
for (let index = 0; index < fields.length; index++) {
|
|
@@ -665,7 +861,7 @@ function BaseProvider(props) {
|
|
|
665
861
|
setIsDirty(false);
|
|
666
862
|
onChangeFilter(applyedFilters, getRawFilter(applyedFilters));
|
|
667
863
|
} else {
|
|
668
|
-
toast(getLabel("
|
|
864
|
+
toast(getLabel("dynamic_filter.error_filters_no_setted"), {
|
|
669
865
|
type: "error",
|
|
670
866
|
autoClose: 1e4
|
|
671
867
|
});
|
|
@@ -683,7 +879,6 @@ function BaseProvider(props) {
|
|
|
683
879
|
return;
|
|
684
880
|
}
|
|
685
881
|
if (!NoValid) {
|
|
686
|
-
console.log("Ingrese");
|
|
687
882
|
setIsDirty(false);
|
|
688
883
|
onChangeFilter(applyedFilters, getRawFilter(applyedFilters));
|
|
689
884
|
}
|
|
@@ -748,7 +943,7 @@ function BaseProvider(props) {
|
|
|
748
943
|
const showPopupForAddFilter = useCallback((anchorEl, field) => {
|
|
749
944
|
setPopupData({
|
|
750
945
|
popupAnchorEl: anchorEl,
|
|
751
|
-
filter: getDefaultFilterValues(field, false,
|
|
946
|
+
filter: getDefaultFilterValues(field, false, getLabel),
|
|
752
947
|
field
|
|
753
948
|
});
|
|
754
949
|
setInEdition(true);
|
|
@@ -882,7 +1077,7 @@ function ApplyedFilter(props) {
|
|
|
882
1077
|
} = useBase();
|
|
883
1078
|
const {
|
|
884
1079
|
host_static_assets,
|
|
885
|
-
|
|
1080
|
+
environment_assets
|
|
886
1081
|
} = useEnvironment();
|
|
887
1082
|
console.log("fieldName by ApplyedFilter 1", getFieldByName(fieldName));
|
|
888
1083
|
const field = useMemo(() => {
|
|
@@ -924,7 +1119,7 @@ function ApplyedFilter(props) {
|
|
|
924
1119
|
children: labelOperands
|
|
925
1120
|
})]
|
|
926
1121
|
}), !fixed && /* @__PURE__ */ jsx(IconButton, {
|
|
927
|
-
src: `${host_static_assets}/${
|
|
1122
|
+
src: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/close.svg`,
|
|
928
1123
|
onClick: onDelete
|
|
929
1124
|
})]
|
|
930
1125
|
});
|
|
@@ -971,7 +1166,7 @@ const WrapperClearFilters = styled$1("div")(({
|
|
|
971
1166
|
const ClearFilters = () => {
|
|
972
1167
|
const {
|
|
973
1168
|
host_static_assets,
|
|
974
|
-
|
|
1169
|
+
environment_assets
|
|
975
1170
|
} = useEnvironment();
|
|
976
1171
|
const {
|
|
977
1172
|
clearFilters,
|
|
@@ -991,7 +1186,7 @@ const ClearFilters = () => {
|
|
|
991
1186
|
if (applyedFilters.findIndex((f) => f.fixed == false) > -1) {
|
|
992
1187
|
return /* @__PURE__ */ jsx(WrapperClearFilters, {
|
|
993
1188
|
children: /* @__PURE__ */ jsx(IconButton, {
|
|
994
|
-
src: `${host_static_assets}/${
|
|
1189
|
+
src: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/clear.svg`,
|
|
995
1190
|
onClick: clearFilters
|
|
996
1191
|
})
|
|
997
1192
|
});
|
|
@@ -1005,28 +1200,27 @@ const SKTWrapperFilterButton = styled("div")(({
|
|
|
1005
1200
|
justifyContent: "center",
|
|
1006
1201
|
alignItems: "center",
|
|
1007
1202
|
minWidth: theme.spacing(3.75),
|
|
1008
|
-
height: theme.spacing(3.75)
|
|
1009
|
-
|
|
1010
|
-
styled("div")(({
|
|
1011
|
-
theme
|
|
1012
|
-
}) => ({
|
|
1013
|
-
display: "flex",
|
|
1014
|
-
justifyContent: "center",
|
|
1015
|
-
alignItems: "center",
|
|
1016
|
-
minWidth: theme.spacing(3.75),
|
|
1017
|
-
height: theme.spacing(3.75)
|
|
1203
|
+
height: theme.spacing(3.75),
|
|
1204
|
+
background: alpha(theme.palette.primary.main, 0.3)
|
|
1018
1205
|
}));
|
|
1019
1206
|
const WrapperFilterButton = styled("div")(() => ({
|
|
1020
1207
|
"&.isDirty": {
|
|
1208
|
+
animationName: "dirtyEffect",
|
|
1209
|
+
animationDuration: "1s",
|
|
1210
|
+
animationFillMode: "both",
|
|
1211
|
+
animationIterationCount: "infinite",
|
|
1212
|
+
transition: "all .3s",
|
|
1021
1213
|
"@keyframes dirtyEffect": {
|
|
1022
|
-
|
|
1214
|
+
"20%": {
|
|
1023
1215
|
opacity: 1
|
|
1024
1216
|
},
|
|
1025
|
-
|
|
1026
|
-
opacity: 0
|
|
1217
|
+
"50%": {
|
|
1218
|
+
opacity: 0.5
|
|
1219
|
+
},
|
|
1220
|
+
"100%": {
|
|
1221
|
+
opacity: 1
|
|
1027
1222
|
}
|
|
1028
|
-
}
|
|
1029
|
-
animation: "dirtyEffect 2s infinite ease"
|
|
1223
|
+
}
|
|
1030
1224
|
},
|
|
1031
1225
|
"&.isDirtyError": {}
|
|
1032
1226
|
}));
|
|
@@ -1040,7 +1234,7 @@ function FilterButton() {
|
|
|
1040
1234
|
} = useBase();
|
|
1041
1235
|
const {
|
|
1042
1236
|
host_static_assets,
|
|
1043
|
-
|
|
1237
|
+
environment_assets
|
|
1044
1238
|
} = useEnvironment();
|
|
1045
1239
|
console.log("Render isDirty", isDirty, automatic);
|
|
1046
1240
|
if (isSkeleton) {
|
|
@@ -1054,21 +1248,24 @@ function FilterButton() {
|
|
|
1054
1248
|
}
|
|
1055
1249
|
const color = useMemo(() => {
|
|
1056
1250
|
if (automatic) {
|
|
1057
|
-
return "
|
|
1251
|
+
return "active";
|
|
1058
1252
|
}
|
|
1059
1253
|
if (!isValid) {
|
|
1060
1254
|
return "error";
|
|
1061
1255
|
}
|
|
1062
|
-
return "
|
|
1256
|
+
return "selected";
|
|
1063
1257
|
}, [automatic, isValid]);
|
|
1258
|
+
console.log("Dynamic color value", color);
|
|
1259
|
+
console.log("Dynamic automatic value", automatic);
|
|
1064
1260
|
return /* @__PURE__ */ jsx(WrapperFilterButton, {
|
|
1261
|
+
id: "WrapperFilterButton",
|
|
1065
1262
|
className: isDirty && isValid ? "isDirty" : "",
|
|
1066
1263
|
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1067
|
-
color,
|
|
1068
|
-
dictionaryTooltip: "
|
|
1264
|
+
bgColor: color,
|
|
1265
|
+
dictionaryTooltip: "dynamic_filter.filter_tooltip",
|
|
1069
1266
|
onClick: () => fireOnChangeFilters(),
|
|
1070
1267
|
"aria-label": "settings",
|
|
1071
|
-
src: `${host_static_assets}/${
|
|
1268
|
+
src: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/${automatic ? "refresh" : "search"}.svg`
|
|
1072
1269
|
})
|
|
1073
1270
|
});
|
|
1074
1271
|
}
|
|
@@ -1176,6 +1373,7 @@ function InputFilter() {
|
|
|
1176
1373
|
if (!withAllField && availableFields.length == 0) {
|
|
1177
1374
|
return /* @__PURE__ */ jsx(Fragment, {});
|
|
1178
1375
|
}
|
|
1376
|
+
console.log("availableFields test", availableFields.length);
|
|
1179
1377
|
return /* @__PURE__ */ jsxs(WrapperInputFilter, {
|
|
1180
1378
|
id: "WrapperInputFilter",
|
|
1181
1379
|
children: [/* @__PURE__ */ jsx(StyledInputFilter, {
|
|
@@ -1185,7 +1383,7 @@ function InputFilter() {
|
|
|
1185
1383
|
onClick: onClickFilter,
|
|
1186
1384
|
onChange: onChangeFilter,
|
|
1187
1385
|
onKeyPress: handleKeyPressMenu
|
|
1188
|
-
}), /* @__PURE__ */ jsx(MenuPopover, {
|
|
1386
|
+
}), availableFields.length > 0 && /* @__PURE__ */ jsx(MenuPopover, {
|
|
1189
1387
|
id: "MenuPopover",
|
|
1190
1388
|
open: Boolean(openAnchorEl),
|
|
1191
1389
|
anchorEl: openAnchorEl,
|