@m4l/components 0.0.36 → 0.0.37
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 +0 -1
- 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 +318 -130
- package/dist/components/DynamicFilter/types.d.ts +4 -2
- package/dist/components/Icon/index.js +26 -4
- package/dist/components/NoItemSelected/index.js +0 -1
- 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/package.json +1 -1
- 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,4 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare const SKTWrapperFilterButton: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
3
|
-
export declare const InputFilter: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
4
3
|
export declare const WrapperFilterButton: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FilterFieldApply, Field } from '../../../types';
|
|
3
|
+
export declare const getDefaultBooleanFilter: (field: Field, fixed: boolean, getLabel: (key: string) => string) => FilterFieldApply;
|
|
4
|
+
export declare function BooleanFilter(): JSX.Element;
|
|
File without changes
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FilterFieldApply, Field } from '../../../types';
|
|
3
|
+
export declare const getDefaultDateTimeFilter: (field: Field, fixed: boolean, getLabel: (key: string) => string) => FilterFieldApply;
|
|
4
|
+
export declare function DateTimeFilter(): JSX.Element;
|
|
File without changes
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FilterFieldApply, Field } from '../../../types';
|
|
3
|
+
export declare const getDefaultNumberFilter: (field: Field, fixed: boolean, getLabel: (key: string) => string) => FilterFieldApply;
|
|
4
|
+
export declare function NumberFilter(): JSX.Element;
|
|
File without changes
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Field, FilterFieldApply } from '../../../types';
|
|
3
|
+
export declare const getDefaultStringFilter: (field: Field, fixed: boolean, getLabel: (key: string) => string) => FilterFieldApply;
|
|
4
|
+
export declare function StringFilter(): JSX.Element;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const WrapperStringFilter: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
3
|
+
export declare const WrapperAutoComplete: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { FilterFieldApply, Field
|
|
3
|
-
export declare const getDefaultFilterValues: (field: Field, fixed: boolean,
|
|
2
|
+
import type { FilterFieldApply, Field } from '../../types';
|
|
3
|
+
export declare const getDefaultFilterValues: (field: Field, fixed: boolean, getLabel: (key: string) => string) => FilterFieldApply;
|
|
4
4
|
export declare const PopupEditFilterComponent: (props: {
|
|
5
5
|
filter: FilterFieldApply;
|
|
6
6
|
}) => JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitialFilterFieldApply } from '
|
|
1
|
+
import { InitialFilterFieldApply } from '../../types';
|
|
2
2
|
export declare function isValidDate(d: any): any;
|
|
3
3
|
export declare const verifyStringFilter: (filter: InitialFilterFieldApply) => boolean;
|
|
4
4
|
export declare const verifyBooleanFilter: (filter: InitialFilterFieldApply) => boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
import { useModuleDictionary, useEnvironment, voidFunction, useHostTools, useFlagsPresent } from "@m4l/core";
|
|
5
5
|
import * as Yup from "yup";
|
|
@@ -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,
|
|
@@ -333,12 +458,12 @@ function DateTimeFilter() {
|
|
|
333
458
|
if (!isLoaded) {
|
|
334
459
|
setPoupEditValidationSchema({
|
|
335
460
|
valueOperator: Yup.object().nullable().required(getLabel(`operator_required`)),
|
|
336
|
-
valueOperand1: Yup.date().test("valueOperand1", getLabel(`
|
|
461
|
+
valueOperand1: Yup.date().test("valueOperand1", getLabel(`dynamic_filter.error_invalid_date1`), (value) => {
|
|
337
462
|
return Boolean(value);
|
|
338
463
|
}),
|
|
339
464
|
valueOperand2: Yup.date().when(["valueOperator.id"], {
|
|
340
465
|
is: "b",
|
|
341
|
-
then: Yup.date().test("DOB", getLabel(`
|
|
466
|
+
then: Yup.date().test("DOB", getLabel(`dynamic_filter.error_invalid_date2`), (value) => {
|
|
342
467
|
return Boolean(value);
|
|
343
468
|
})
|
|
344
469
|
})
|
|
@@ -359,7 +484,7 @@ function DateTimeFilter() {
|
|
|
359
484
|
}, [getLabel, filter, field]);
|
|
360
485
|
return /* @__PURE__ */ jsx(WrapperAllFieldsFilter, {
|
|
361
486
|
children: isLoaded && /* @__PURE__ */ jsxs(Fragment, {
|
|
362
|
-
children: [/* @__PURE__ */ jsx(WrapperAutoComplete, {
|
|
487
|
+
children: [/* @__PURE__ */ jsx(WrapperAutoComplete$1, {
|
|
363
488
|
children: /* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
364
489
|
name: "valueOperator",
|
|
365
490
|
autoComplete: "off",
|
|
@@ -371,7 +496,8 @@ function DateTimeFilter() {
|
|
|
371
496
|
}), /* @__PURE__ */ jsx(RHFDateTime, {
|
|
372
497
|
name: "valueOperand1",
|
|
373
498
|
autoComplete: "off",
|
|
374
|
-
label: ""
|
|
499
|
+
label: "",
|
|
500
|
+
focused: true
|
|
375
501
|
}), operator && operator.id === "b" && /* @__PURE__ */ jsx(RHFDateTime, {
|
|
376
502
|
name: "valueOperand2",
|
|
377
503
|
autoComplete: "off",
|
|
@@ -380,108 +506,166 @@ function DateTimeFilter() {
|
|
|
380
506
|
})
|
|
381
507
|
});
|
|
382
508
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
};
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
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;
|
|
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;
|
|
430
527
|
const defaultFilter = {
|
|
431
528
|
id: 0,
|
|
432
529
|
fieldName: field.name,
|
|
433
530
|
fixed,
|
|
434
531
|
isSetted: false,
|
|
435
|
-
operator: "
|
|
532
|
+
operator: "e",
|
|
436
533
|
labelOperator: "",
|
|
437
534
|
operand1: "",
|
|
535
|
+
operand2: "",
|
|
438
536
|
labelOperands: ""
|
|
439
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) => {
|
|
440
656
|
switch (field.type) {
|
|
441
657
|
case "string":
|
|
442
|
-
|
|
658
|
+
return getDefaultStringFilter(field, fixed, getLabel);
|
|
443
659
|
case "number":
|
|
660
|
+
return getDefaultNumberFilter(field, fixed, getLabel);
|
|
444
661
|
case "boolean":
|
|
445
|
-
|
|
446
|
-
if (dfop1 !== void 0 && typeof dfop1 === "boolean") {
|
|
447
|
-
defaultFilter.operand1 = dfop1;
|
|
448
|
-
} else {
|
|
449
|
-
defaultFilter.operand1 = true;
|
|
450
|
-
}
|
|
451
|
-
break;
|
|
662
|
+
return getDefaultBooleanFilter(field, fixed, getLabel);
|
|
452
663
|
case "time":
|
|
453
664
|
case "date":
|
|
454
665
|
case "datetime":
|
|
455
|
-
|
|
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;
|
|
666
|
+
return getDefaultDateTimeFilter(field, fixed, getLabel);
|
|
481
667
|
}
|
|
482
|
-
|
|
483
|
-
console.log("operator", defaultFilter);
|
|
484
|
-
return defaultFilter;
|
|
668
|
+
throw new Error("Type no defined");
|
|
485
669
|
};
|
|
486
670
|
const PopupEditFilterComponent = (props) => {
|
|
487
671
|
const {
|
|
@@ -493,6 +677,8 @@ const PopupEditFilterComponent = (props) => {
|
|
|
493
677
|
switch (field.type) {
|
|
494
678
|
case "string":
|
|
495
679
|
return /* @__PURE__ */ jsx(StringFilter, {});
|
|
680
|
+
case "number":
|
|
681
|
+
return /* @__PURE__ */ jsx(NumberFilter, {});
|
|
496
682
|
case "boolean":
|
|
497
683
|
return /* @__PURE__ */ jsx(BooleanFilter, {});
|
|
498
684
|
case "datetime":
|
|
@@ -551,7 +737,7 @@ const getRawFilter = (applyedFilter) => {
|
|
|
551
737
|
o2: af.operand2
|
|
552
738
|
}));
|
|
553
739
|
};
|
|
554
|
-
const getInitialFilters = (fields, filters, getFieldByName,
|
|
740
|
+
const getInitialFilters = (fields, filters, getFieldByName, getLabel) => {
|
|
555
741
|
const newFilters = [];
|
|
556
742
|
const fixedFields = [];
|
|
557
743
|
for (let index = 0; index < filters.length; index++) {
|
|
@@ -596,7 +782,7 @@ const getInitialFilters = (fields, filters, getFieldByName, getLabelOperator) =>
|
|
|
596
782
|
const field = fields[index];
|
|
597
783
|
if (field.fixed) {
|
|
598
784
|
if (!filters.find((f) => f.fieldName === field.name)) {
|
|
599
|
-
const newFilter = getDefaultFilterValues(field, true,
|
|
785
|
+
const newFilter = getDefaultFilterValues(field, true, getLabel);
|
|
600
786
|
newFilter.id = newFilters.length + 1;
|
|
601
787
|
newFilters.push(newFilter);
|
|
602
788
|
}
|
|
@@ -633,7 +819,7 @@ function BaseProvider(props) {
|
|
|
633
819
|
return {
|
|
634
820
|
...ALL_FIELDS,
|
|
635
821
|
label: getLabel("filter.all_fields"),
|
|
636
|
-
urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/
|
|
822
|
+
urlIcon: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/all_fields.svg`
|
|
637
823
|
};
|
|
638
824
|
}, [getLabel, host_static_assets, environment_assets]);
|
|
639
825
|
const [inEdition, setInEdition] = useState(false);
|
|
@@ -648,9 +834,9 @@ function BaseProvider(props) {
|
|
|
648
834
|
});
|
|
649
835
|
}, [fields, all_fields]);
|
|
650
836
|
const getLabelOperator = useCallback((operator) => {
|
|
651
|
-
return getLabel(`
|
|
837
|
+
return getLabel(`dynamic_filter.operator_${operator}`);
|
|
652
838
|
}, [getLabel]);
|
|
653
|
-
const [applyedFilters, setApplyedFilters] = useState(getInitialFilters(fields, initialFilters, getFieldByName,
|
|
839
|
+
const [applyedFilters, setApplyedFilters] = useState(getInitialFilters(fields, initialFilters, getFieldByName, getLabel));
|
|
654
840
|
const availableFields = useMemo(() => {
|
|
655
841
|
const newFields = [];
|
|
656
842
|
for (let index = 0; index < fields.length; index++) {
|
|
@@ -675,7 +861,7 @@ function BaseProvider(props) {
|
|
|
675
861
|
setIsDirty(false);
|
|
676
862
|
onChangeFilter(applyedFilters, getRawFilter(applyedFilters));
|
|
677
863
|
} else {
|
|
678
|
-
toast(getLabel("
|
|
864
|
+
toast(getLabel("dynamic_filter.error_filters_no_setted"), {
|
|
679
865
|
type: "error",
|
|
680
866
|
autoClose: 1e4
|
|
681
867
|
});
|
|
@@ -693,7 +879,6 @@ function BaseProvider(props) {
|
|
|
693
879
|
return;
|
|
694
880
|
}
|
|
695
881
|
if (!NoValid) {
|
|
696
|
-
console.log("Ingrese");
|
|
697
882
|
setIsDirty(false);
|
|
698
883
|
onChangeFilter(applyedFilters, getRawFilter(applyedFilters));
|
|
699
884
|
}
|
|
@@ -758,7 +943,7 @@ function BaseProvider(props) {
|
|
|
758
943
|
const showPopupForAddFilter = useCallback((anchorEl, field) => {
|
|
759
944
|
setPopupData({
|
|
760
945
|
popupAnchorEl: anchorEl,
|
|
761
|
-
filter: getDefaultFilterValues(field, false,
|
|
946
|
+
filter: getDefaultFilterValues(field, false, getLabel),
|
|
762
947
|
field
|
|
763
948
|
});
|
|
764
949
|
setInEdition(true);
|
|
@@ -1015,28 +1200,27 @@ const SKTWrapperFilterButton = styled("div")(({
|
|
|
1015
1200
|
justifyContent: "center",
|
|
1016
1201
|
alignItems: "center",
|
|
1017
1202
|
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)
|
|
1203
|
+
height: theme.spacing(3.75),
|
|
1204
|
+
background: alpha(theme.palette.primary.main, 0.3)
|
|
1028
1205
|
}));
|
|
1029
1206
|
const WrapperFilterButton = styled("div")(() => ({
|
|
1030
1207
|
"&.isDirty": {
|
|
1208
|
+
animationName: "dirtyEffect",
|
|
1209
|
+
animationDuration: "1s",
|
|
1210
|
+
animationFillMode: "both",
|
|
1211
|
+
animationIterationCount: "infinite",
|
|
1212
|
+
transition: "all .3s",
|
|
1031
1213
|
"@keyframes dirtyEffect": {
|
|
1032
|
-
|
|
1214
|
+
"20%": {
|
|
1033
1215
|
opacity: 1
|
|
1034
1216
|
},
|
|
1035
|
-
|
|
1036
|
-
opacity: 0
|
|
1217
|
+
"50%": {
|
|
1218
|
+
opacity: 0.5
|
|
1219
|
+
},
|
|
1220
|
+
"100%": {
|
|
1221
|
+
opacity: 1
|
|
1037
1222
|
}
|
|
1038
|
-
}
|
|
1039
|
-
animation: "dirtyEffect 2s infinite ease"
|
|
1223
|
+
}
|
|
1040
1224
|
},
|
|
1041
1225
|
"&.isDirtyError": {}
|
|
1042
1226
|
}));
|
|
@@ -1064,18 +1248,21 @@ function FilterButton() {
|
|
|
1064
1248
|
}
|
|
1065
1249
|
const color = useMemo(() => {
|
|
1066
1250
|
if (automatic) {
|
|
1067
|
-
return "
|
|
1251
|
+
return "active";
|
|
1068
1252
|
}
|
|
1069
1253
|
if (!isValid) {
|
|
1070
1254
|
return "error";
|
|
1071
1255
|
}
|
|
1072
|
-
return "
|
|
1256
|
+
return "selected";
|
|
1073
1257
|
}, [automatic, isValid]);
|
|
1258
|
+
console.log("Dynamic color value", color);
|
|
1259
|
+
console.log("Dynamic automatic value", automatic);
|
|
1074
1260
|
return /* @__PURE__ */ jsx(WrapperFilterButton, {
|
|
1261
|
+
id: "WrapperFilterButton",
|
|
1075
1262
|
className: isDirty && isValid ? "isDirty" : "",
|
|
1076
1263
|
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1077
|
-
color,
|
|
1078
|
-
dictionaryTooltip: "
|
|
1264
|
+
bgColor: color,
|
|
1265
|
+
dictionaryTooltip: "dynamic_filter.filter_tooltip",
|
|
1079
1266
|
onClick: () => fireOnChangeFilters(),
|
|
1080
1267
|
"aria-label": "settings",
|
|
1081
1268
|
src: `${host_static_assets}/${environment_assets}/frontend/components/dynamic_filter/assets/icons/${automatic ? "refresh" : "search"}.svg`
|
|
@@ -1186,6 +1373,7 @@ function InputFilter() {
|
|
|
1186
1373
|
if (!withAllField && availableFields.length == 0) {
|
|
1187
1374
|
return /* @__PURE__ */ jsx(Fragment, {});
|
|
1188
1375
|
}
|
|
1376
|
+
console.log("availableFields test", availableFields.length);
|
|
1189
1377
|
return /* @__PURE__ */ jsxs(WrapperInputFilter, {
|
|
1190
1378
|
id: "WrapperInputFilter",
|
|
1191
1379
|
children: [/* @__PURE__ */ jsx(StyledInputFilter, {
|
|
@@ -1195,7 +1383,7 @@ function InputFilter() {
|
|
|
1195
1383
|
onClick: onClickFilter,
|
|
1196
1384
|
onChange: onChangeFilter,
|
|
1197
1385
|
onKeyPress: handleKeyPressMenu
|
|
1198
|
-
}), /* @__PURE__ */ jsx(MenuPopover, {
|
|
1386
|
+
}), availableFields.length > 0 && /* @__PURE__ */ jsx(MenuPopover, {
|
|
1199
1387
|
id: "MenuPopover",
|
|
1200
1388
|
open: Boolean(openAnchorEl),
|
|
1201
1389
|
anchorEl: openAnchorEl,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Maybe } from '@m4l/core';
|
|
2
2
|
export declare type FieldType = 'number' | 'string' | 'boolean' | 'date' | 'datetime' | 'time' | 'select' | 'in';
|
|
3
3
|
export declare type OperandType = number | string | boolean | Date | [] | object;
|
|
4
|
-
export declare type Operator = '
|
|
4
|
+
export declare type Operator = 'b' | 'e' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'c' | 'nc';
|
|
5
5
|
export declare const OPERATORS: Array<Operator>;
|
|
6
6
|
export declare type StringOperator = 'c' | 'nc';
|
|
7
7
|
export declare const STRING_OPERATORS: Array<StringOperator>;
|
|
8
|
+
export declare type NumberOperator = 'b' | 'e' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
|
|
9
|
+
export declare const NUMBER_OPERATORS: Array<NumberOperator>;
|
|
8
10
|
export declare type BooleanOperator = 'e' | 'ne';
|
|
9
11
|
export declare const BOOLEAN_OPERATORS: Array<BooleanOperator>;
|
|
10
12
|
export declare type DateTimeOperator = 'b' | 'e' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
|
|
@@ -32,7 +34,7 @@ export interface BaseApplyFilter {
|
|
|
32
34
|
export interface ValuesFilter {
|
|
33
35
|
operator: Operator;
|
|
34
36
|
labelOperator: string;
|
|
35
|
-
labelOperands: string;
|
|
37
|
+
labelOperands: string | number;
|
|
36
38
|
operand1?: Maybe<OperandType>;
|
|
37
39
|
operand2?: Maybe<OperandType>;
|
|
38
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { styled } from "@mui/material";
|
|
1
|
+
import { styled, useTheme } from "@mui/material";
|
|
2
2
|
import { useState, useEffect } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
const MaskIcon = styled("div", {
|
|
@@ -8,7 +8,7 @@ const MaskIcon = styled("div", {
|
|
|
8
8
|
mask: `url(${props.src}) no-repeat`,
|
|
9
9
|
width: props.width === void 0 ? "20px" : props.width,
|
|
10
10
|
height: props.height === void 0 ? "20px" : props.height,
|
|
11
|
-
backgroundColor: props.bgColor
|
|
11
|
+
backgroundColor: props.bgColor
|
|
12
12
|
}));
|
|
13
13
|
const WrapperPlaceHolder = styled("div", {
|
|
14
14
|
shouldForwardProp: (props) => props !== "widht" && props !== "height"
|
|
@@ -20,13 +20,35 @@ const WrapperPlaceHolder = styled("div", {
|
|
|
20
20
|
height: props.height
|
|
21
21
|
}));
|
|
22
22
|
function Icon(props) {
|
|
23
|
-
const [resource, setResource] = useState(void 0);
|
|
24
23
|
const {
|
|
25
24
|
src,
|
|
26
25
|
width = "16px",
|
|
27
26
|
height = "16px",
|
|
28
27
|
bgColor = "active"
|
|
29
28
|
} = props;
|
|
29
|
+
const [resource, setResource] = useState(void 0);
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
const getBgColor = () => {
|
|
32
|
+
if (bgColor === "active") {
|
|
33
|
+
return theme.palette.action.active;
|
|
34
|
+
}
|
|
35
|
+
if (bgColor === "selected") {
|
|
36
|
+
return theme.palette.primary.main;
|
|
37
|
+
}
|
|
38
|
+
if (bgColor === "info") {
|
|
39
|
+
return theme.palette.info.main;
|
|
40
|
+
}
|
|
41
|
+
if (bgColor === "warning") {
|
|
42
|
+
return theme.palette.warning.main;
|
|
43
|
+
}
|
|
44
|
+
if (bgColor === "error") {
|
|
45
|
+
return theme.palette.error.main;
|
|
46
|
+
}
|
|
47
|
+
if (bgColor === "disabled") {
|
|
48
|
+
return theme.palette.action.disabled;
|
|
49
|
+
}
|
|
50
|
+
return bgColor;
|
|
51
|
+
};
|
|
30
52
|
useEffect(() => {
|
|
31
53
|
let mounted = true;
|
|
32
54
|
if (resource)
|
|
@@ -54,7 +76,7 @@ function Icon(props) {
|
|
|
54
76
|
src: resource,
|
|
55
77
|
width,
|
|
56
78
|
height,
|
|
57
|
-
bgColor
|
|
79
|
+
bgColor: getBgColor()
|
|
58
80
|
}) : /* @__PURE__ */ jsx("img", {
|
|
59
81
|
src: placeHolder,
|
|
60
82
|
alt: "icon_svg"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { IconButtonProps as MUIIconButtonProps } from '@mui/material';
|
|
3
3
|
import { IconButtonProps } from './types';
|
|
4
|
-
export declare function IconButton({ src, tooltip, size, dictionaryTooltip, ...other }: IconButtonProps & MUIIconButtonProps): JSX.Element;
|
|
4
|
+
export declare function IconButton({ src, tooltip, size, dictionaryTooltip, bgColor, ...other }: IconButtonProps & MUIIconButtonProps): JSX.Element;
|
|
5
5
|
export default IconButton;
|
|
@@ -64,6 +64,7 @@ function IconButton({
|
|
|
64
64
|
tooltip,
|
|
65
65
|
size = "small",
|
|
66
66
|
dictionaryTooltip,
|
|
67
|
+
bgColor = "active",
|
|
67
68
|
...other
|
|
68
69
|
}) {
|
|
69
70
|
const {
|
|
@@ -72,9 +73,10 @@ function IconButton({
|
|
|
72
73
|
const iconMemo = useMemo(() => {
|
|
73
74
|
console.log("IconButton", size, other, src);
|
|
74
75
|
return /* @__PURE__ */ jsx(Icon, {
|
|
75
|
-
src
|
|
76
|
+
src,
|
|
77
|
+
bgColor
|
|
76
78
|
});
|
|
77
|
-
}, [src]);
|
|
79
|
+
}, [src, bgColor]);
|
|
78
80
|
const finalTooltip = useMemo(() => {
|
|
79
81
|
if (dictionaryTooltip && getLabel) {
|
|
80
82
|
return getLabel(dictionaryTooltip);
|
package/package.json
CHANGED