rez-table-listing-mui 1.3.21 → 1.3.22
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/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/listing/components/filter/components/forms/components/Dropdown.tsx +19 -40
- package/src/listing/components/filter/components/forms/utils/filter-date-input-resolver.tsx +30 -55
package/package.json
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { FormControl, MenuItem, Select, SxProps, Theme } from "@mui/material";
|
|
2
2
|
import { Controller, UseFormSetValue } from "react-hook-form";
|
|
3
|
-
import { FilterStateProps } from "../../../../../types/filter";
|
|
4
3
|
import moment from "moment";
|
|
4
|
+
import { FilterStateProps } from "../../../../../types/filter";
|
|
5
5
|
|
|
6
6
|
interface FormDropdownProps {
|
|
7
7
|
filter: FilterStateProps;
|
|
8
8
|
control: any;
|
|
9
9
|
setValue: UseFormSetValue<any>;
|
|
10
|
-
dropdownList: {
|
|
11
|
-
label?: string;
|
|
12
|
-
value?: string;
|
|
13
|
-
}[];
|
|
10
|
+
dropdownList: { label?: string; value?: string }[];
|
|
14
11
|
isLoading?: boolean;
|
|
15
12
|
sx?: SxProps<Theme>;
|
|
16
13
|
onValueChange?: () => void;
|
|
@@ -27,72 +24,54 @@ const FormDropdown = ({
|
|
|
27
24
|
}: FormDropdownProps) => {
|
|
28
25
|
return (
|
|
29
26
|
<Controller
|
|
30
|
-
name={`${filter
|
|
27
|
+
name={`${filter.filter_attribute_name}.operator`}
|
|
31
28
|
control={control}
|
|
32
|
-
defaultValue={filter
|
|
29
|
+
defaultValue={filter.filter_operator || dropdownList?.[0]?.value || ""}
|
|
33
30
|
render={({ field }) => (
|
|
34
31
|
<FormControl sx={sx} size="small">
|
|
35
32
|
<Select
|
|
36
33
|
{...field}
|
|
37
34
|
variant="standard"
|
|
35
|
+
disableUnderline
|
|
36
|
+
disabled={isLoading}
|
|
38
37
|
sx={{
|
|
39
38
|
fontSize: "0.875rem",
|
|
40
39
|
minWidth: 50,
|
|
41
|
-
border: "none",
|
|
42
40
|
boxShadow: "none",
|
|
43
|
-
"& .MuiSelect-icon": {
|
|
44
|
-
top: "45%",
|
|
45
|
-
transform: "translateY(-50%)",
|
|
46
|
-
"& .MuiOutlinedInput-input": {
|
|
47
|
-
padding: "12px 20px",
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
41
|
}}
|
|
51
|
-
disabled={isLoading}
|
|
52
|
-
disableUnderline
|
|
53
42
|
onChange={(e) => {
|
|
54
43
|
const newOperator = e.target.value;
|
|
55
44
|
const oldOperator = field.value;
|
|
56
45
|
|
|
57
|
-
// Update RHF field
|
|
58
46
|
field.onChange(e);
|
|
59
47
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
) {
|
|
48
|
+
const fieldName = `${filter.filter_attribute_name}.value`;
|
|
49
|
+
const type = filter.filter_attribute_data_type;
|
|
50
|
+
|
|
51
|
+
// RESET RULES (Unified)
|
|
52
|
+
if (type === "date" || type === "year") {
|
|
66
53
|
if (newOperator === "today") {
|
|
67
|
-
setValue(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
{
|
|
71
|
-
shouldDirty: true,
|
|
72
|
-
}
|
|
73
|
-
);
|
|
54
|
+
setValue(fieldName, moment().format("YYYY-MM-DD"), {
|
|
55
|
+
shouldDirty: true,
|
|
56
|
+
});
|
|
74
57
|
} else if (newOperator === "between") {
|
|
75
|
-
setValue(
|
|
58
|
+
setValue(fieldName, ["", ""], {
|
|
76
59
|
shouldDirty: true,
|
|
77
60
|
});
|
|
78
61
|
} else if (
|
|
79
62
|
oldOperator === "between" ||
|
|
80
63
|
oldOperator === "today"
|
|
81
64
|
) {
|
|
82
|
-
setValue(
|
|
83
|
-
shouldDirty: true,
|
|
84
|
-
});
|
|
65
|
+
setValue(fieldName, "", { shouldDirty: true });
|
|
85
66
|
}
|
|
86
67
|
}
|
|
87
68
|
|
|
88
|
-
//
|
|
89
|
-
setTimeout(() =>
|
|
90
|
-
onValueChange?.();
|
|
91
|
-
}, 0);
|
|
69
|
+
// Delay to ensure RHF state updates
|
|
70
|
+
setTimeout(() => onValueChange?.(), 0);
|
|
92
71
|
}}
|
|
93
72
|
>
|
|
94
73
|
{dropdownList?.map((item, idx) => (
|
|
95
|
-
<MenuItem
|
|
74
|
+
<MenuItem value={item.value} key={idx}>
|
|
96
75
|
{item.label}
|
|
97
76
|
</MenuItem>
|
|
98
77
|
))}
|
|
@@ -4,33 +4,14 @@ import FormTextfield from "../components/Textfield";
|
|
|
4
4
|
import FormDatePicker from "../components/Date";
|
|
5
5
|
import FormMultiSelect from "../components/Multi-Select";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
| "is_after"
|
|
16
|
-
| "is_on_or_before"
|
|
17
|
-
| "is_on_or_after"
|
|
18
|
-
| "empty"
|
|
19
|
-
| "not_empty";
|
|
20
|
-
|
|
21
|
-
export const DATE_ALLOWED_OPERATORS: DateOperator[] = [
|
|
22
|
-
"equal",
|
|
23
|
-
"before",
|
|
24
|
-
"after",
|
|
25
|
-
"between",
|
|
26
|
-
"is",
|
|
27
|
-
"today",
|
|
28
|
-
"is_before",
|
|
29
|
-
"is_after",
|
|
30
|
-
"is_on_or_before",
|
|
31
|
-
"is_on_or_after",
|
|
32
|
-
"empty",
|
|
33
|
-
"not_empty",
|
|
7
|
+
// Operators that SHOULD use TextField when applied on date fields
|
|
8
|
+
export const NON_DATE_OPERATORS = [
|
|
9
|
+
"is_day_before",
|
|
10
|
+
"is_day_after",
|
|
11
|
+
"is_month_before",
|
|
12
|
+
"is_month_after",
|
|
13
|
+
"is_before_bussiness_days",
|
|
14
|
+
"is_after_bussiness_days",
|
|
34
15
|
];
|
|
35
16
|
|
|
36
17
|
export const resolveFilterInput = ({
|
|
@@ -46,20 +27,10 @@ export const resolveFilterInput = ({
|
|
|
46
27
|
dropdownData: any;
|
|
47
28
|
updateFiltersFromForm: () => void;
|
|
48
29
|
}) => {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const showDatePicker =
|
|
52
|
-
isDateType && operator && DATE_ALLOWED_OPERATORS.includes(operator as any);
|
|
30
|
+
const dataType = filter?.filter_attribute_data_type;
|
|
53
31
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
(!operator || !DATE_ALLOWED_OPERATORS.includes(operator as any));
|
|
57
|
-
|
|
58
|
-
// TEXT / NUMBER -> Always TextField
|
|
59
|
-
if (
|
|
60
|
-
filter?.filter_attribute_data_type === "text" ||
|
|
61
|
-
filter?.filter_attribute_data_type === "number"
|
|
62
|
-
) {
|
|
32
|
+
// TEXT / NUMBER → always textfield
|
|
33
|
+
if (dataType === "text" || dataType === "number") {
|
|
63
34
|
return (
|
|
64
35
|
<FormTextfield
|
|
65
36
|
filter={filter}
|
|
@@ -69,8 +40,8 @@ export const resolveFilterInput = ({
|
|
|
69
40
|
);
|
|
70
41
|
}
|
|
71
42
|
|
|
72
|
-
// YEAR
|
|
73
|
-
if (
|
|
43
|
+
// YEAR → DatePicker (Year mode)
|
|
44
|
+
if (dataType === "year") {
|
|
74
45
|
return (
|
|
75
46
|
<FormDatePicker
|
|
76
47
|
filter={filter}
|
|
@@ -81,20 +52,24 @@ export const resolveFilterInput = ({
|
|
|
81
52
|
);
|
|
82
53
|
}
|
|
83
54
|
|
|
84
|
-
// DATE LOGIC
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
55
|
+
// DATE FIELD LOGIC
|
|
56
|
+
if (dataType === "date") {
|
|
57
|
+
const isNonDateOperator = operator && NON_DATE_OPERATORS.includes(operator);
|
|
58
|
+
|
|
59
|
+
if (isNonDateOperator) {
|
|
60
|
+
// Non-date operator → show TEXT FIELD
|
|
61
|
+
return (
|
|
62
|
+
<FormTextfield
|
|
63
|
+
filter={filter}
|
|
64
|
+
control={control}
|
|
65
|
+
onValueChange={updateFiltersFromForm}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
94
69
|
|
|
95
|
-
|
|
70
|
+
// Default for all other operators → Date Picker
|
|
96
71
|
return (
|
|
97
|
-
<
|
|
72
|
+
<FormDatePicker
|
|
98
73
|
filter={filter}
|
|
99
74
|
control={control}
|
|
100
75
|
onValueChange={updateFiltersFromForm}
|
|
@@ -102,7 +77,7 @@ export const resolveFilterInput = ({
|
|
|
102
77
|
);
|
|
103
78
|
}
|
|
104
79
|
|
|
105
|
-
//
|
|
80
|
+
// SELECT / MULTISELECT / RADIO / CHECKBOX
|
|
106
81
|
if (
|
|
107
82
|
filter?.filter_attribute_data_type !== undefined &&
|
|
108
83
|
["select", "multiselect", "radio", "checkbox"].includes(
|