rez-table-listing-mui 1.3.20 → 1.3.21
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/package.json
CHANGED
|
@@ -16,22 +16,6 @@ interface FormDropdownProps {
|
|
|
16
16
|
onValueChange?: () => void;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
// Allowed date-based operators
|
|
20
|
-
const DATE_ALLOWED_OPERATORS = [
|
|
21
|
-
"equal",
|
|
22
|
-
"before",
|
|
23
|
-
"after",
|
|
24
|
-
"between",
|
|
25
|
-
"is",
|
|
26
|
-
"today",
|
|
27
|
-
"is_before",
|
|
28
|
-
"is_after",
|
|
29
|
-
"is_on_or_before",
|
|
30
|
-
"is_on_or_after",
|
|
31
|
-
"empty",
|
|
32
|
-
"not_empty",
|
|
33
|
-
];
|
|
34
|
-
|
|
35
19
|
const FormDropdown = ({
|
|
36
20
|
filter,
|
|
37
21
|
control,
|
|
@@ -70,21 +54,10 @@ const FormDropdown = ({
|
|
|
70
54
|
const newOperator = e.target.value;
|
|
71
55
|
const oldOperator = field.value;
|
|
72
56
|
|
|
57
|
+
// Update RHF field
|
|
73
58
|
field.onChange(e);
|
|
74
59
|
|
|
75
|
-
//
|
|
76
|
-
if (filter.filter_attribute_data_type === "date") {
|
|
77
|
-
const wasDateOp = DATE_ALLOWED_OPERATORS.includes(oldOperator);
|
|
78
|
-
const isDateOpNow =
|
|
79
|
-
DATE_ALLOWED_OPERATORS.includes(newOperator);
|
|
80
|
-
|
|
81
|
-
if (wasDateOp !== isDateOpNow) {
|
|
82
|
-
setValue(`${filter?.filter_attribute_name}.value`, "", {
|
|
83
|
-
shouldDirty: true,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
60
|
+
// Handle date/year specific operator-based value reset logic
|
|
88
61
|
if (
|
|
89
62
|
(filter?.filter_attribute_data_type === "date" ||
|
|
90
63
|
filter?.filter_attribute_data_type === "year") &&
|
|
@@ -112,7 +85,10 @@ const FormDropdown = ({
|
|
|
112
85
|
}
|
|
113
86
|
}
|
|
114
87
|
|
|
115
|
-
|
|
88
|
+
// ⭐ FIX: Ensure parent form re-evaluates AFTER RHF updates the operator
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
onValueChange?.();
|
|
91
|
+
}, 0);
|
|
116
92
|
}}
|
|
117
93
|
>
|
|
118
94
|
{dropdownList?.map((item, idx) => (
|
|
@@ -129,6 +105,137 @@ const FormDropdown = ({
|
|
|
129
105
|
|
|
130
106
|
export default FormDropdown;
|
|
131
107
|
|
|
108
|
+
// import { FormControl, MenuItem, Select, SxProps, Theme } from "@mui/material";
|
|
109
|
+
// import { Controller, UseFormSetValue } from "react-hook-form";
|
|
110
|
+
// import { FilterStateProps } from "../../../../../types/filter";
|
|
111
|
+
// import moment from "moment";
|
|
112
|
+
|
|
113
|
+
// interface FormDropdownProps {
|
|
114
|
+
// filter: FilterStateProps;
|
|
115
|
+
// control: any;
|
|
116
|
+
// setValue: UseFormSetValue<any>;
|
|
117
|
+
// dropdownList: {
|
|
118
|
+
// label?: string;
|
|
119
|
+
// value?: string;
|
|
120
|
+
// }[];
|
|
121
|
+
// isLoading?: boolean;
|
|
122
|
+
// sx?: SxProps<Theme>;
|
|
123
|
+
// onValueChange?: () => void;
|
|
124
|
+
// }
|
|
125
|
+
|
|
126
|
+
// // Allowed date-based operators
|
|
127
|
+
// const DATE_ALLOWED_OPERATORS = [
|
|
128
|
+
// "equal",
|
|
129
|
+
// "before",
|
|
130
|
+
// "after",
|
|
131
|
+
// "between",
|
|
132
|
+
// "is",
|
|
133
|
+
// "today",
|
|
134
|
+
// "is_before",
|
|
135
|
+
// "is_after",
|
|
136
|
+
// "is_on_or_before",
|
|
137
|
+
// "is_on_or_after",
|
|
138
|
+
// "empty",
|
|
139
|
+
// "not_empty",
|
|
140
|
+
// ];
|
|
141
|
+
|
|
142
|
+
// const FormDropdown = ({
|
|
143
|
+
// filter,
|
|
144
|
+
// control,
|
|
145
|
+
// setValue,
|
|
146
|
+
// dropdownList,
|
|
147
|
+
// isLoading = false,
|
|
148
|
+
// sx,
|
|
149
|
+
// onValueChange,
|
|
150
|
+
// }: FormDropdownProps) => {
|
|
151
|
+
// return (
|
|
152
|
+
// <Controller
|
|
153
|
+
// name={`${filter?.filter_attribute_name}.operator`}
|
|
154
|
+
// control={control}
|
|
155
|
+
// defaultValue={filter?.filter_operator || dropdownList?.[0]?.value || ""}
|
|
156
|
+
// render={({ field }) => (
|
|
157
|
+
// <FormControl sx={sx} size="small">
|
|
158
|
+
// <Select
|
|
159
|
+
// {...field}
|
|
160
|
+
// variant="standard"
|
|
161
|
+
// sx={{
|
|
162
|
+
// fontSize: "0.875rem",
|
|
163
|
+
// minWidth: 50,
|
|
164
|
+
// border: "none",
|
|
165
|
+
// boxShadow: "none",
|
|
166
|
+
// "& .MuiSelect-icon": {
|
|
167
|
+
// top: "45%",
|
|
168
|
+
// transform: "translateY(-50%)",
|
|
169
|
+
// "& .MuiOutlinedInput-input": {
|
|
170
|
+
// padding: "12px 20px",
|
|
171
|
+
// },
|
|
172
|
+
// },
|
|
173
|
+
// }}
|
|
174
|
+
// disabled={isLoading}
|
|
175
|
+
// disableUnderline
|
|
176
|
+
// onChange={(e) => {
|
|
177
|
+
// const newOperator = e.target.value;
|
|
178
|
+
// const oldOperator = field.value;
|
|
179
|
+
|
|
180
|
+
// field.onChange(e);
|
|
181
|
+
|
|
182
|
+
// // Reset value if operator switches date → non-date or non-date → date
|
|
183
|
+
// if (filter.filter_attribute_data_type === "date") {
|
|
184
|
+
// const wasDateOp = DATE_ALLOWED_OPERATORS.includes(oldOperator);
|
|
185
|
+
// const isDateOpNow =
|
|
186
|
+
// DATE_ALLOWED_OPERATORS.includes(newOperator);
|
|
187
|
+
|
|
188
|
+
// if (wasDateOp !== isDateOpNow) {
|
|
189
|
+
// setValue(`${filter?.filter_attribute_name}.value`, "", {
|
|
190
|
+
// shouldDirty: true,
|
|
191
|
+
// });
|
|
192
|
+
// }
|
|
193
|
+
// }
|
|
194
|
+
|
|
195
|
+
// if (
|
|
196
|
+
// (filter?.filter_attribute_data_type === "date" ||
|
|
197
|
+
// filter?.filter_attribute_data_type === "year") &&
|
|
198
|
+
// newOperator !== oldOperator
|
|
199
|
+
// ) {
|
|
200
|
+
// if (newOperator === "today") {
|
|
201
|
+
// setValue(
|
|
202
|
+
// `${filter?.filter_attribute_name}.value`,
|
|
203
|
+
// moment().format("YYYY-MM-DD"),
|
|
204
|
+
// {
|
|
205
|
+
// shouldDirty: true,
|
|
206
|
+
// }
|
|
207
|
+
// );
|
|
208
|
+
// } else if (newOperator === "between") {
|
|
209
|
+
// setValue(`${filter?.filter_attribute_name}.value`, ["", ""], {
|
|
210
|
+
// shouldDirty: true,
|
|
211
|
+
// });
|
|
212
|
+
// } else if (
|
|
213
|
+
// oldOperator === "between" ||
|
|
214
|
+
// oldOperator === "today"
|
|
215
|
+
// ) {
|
|
216
|
+
// setValue(`${filter?.filter_attribute_name}.value`, "", {
|
|
217
|
+
// shouldDirty: true,
|
|
218
|
+
// });
|
|
219
|
+
// }
|
|
220
|
+
// }
|
|
221
|
+
|
|
222
|
+
// onValueChange?.();
|
|
223
|
+
// }}
|
|
224
|
+
// >
|
|
225
|
+
// {dropdownList?.map((item, idx) => (
|
|
226
|
+
// <MenuItem key={idx} value={item.value}>
|
|
227
|
+
// {item.label}
|
|
228
|
+
// </MenuItem>
|
|
229
|
+
// ))}
|
|
230
|
+
// </Select>
|
|
231
|
+
// </FormControl>
|
|
232
|
+
// )}
|
|
233
|
+
// />
|
|
234
|
+
// );
|
|
235
|
+
// };
|
|
236
|
+
|
|
237
|
+
// export default FormDropdown;
|
|
238
|
+
|
|
132
239
|
// !! DON'T DELETE THIS OLD CODE !! //
|
|
133
240
|
|
|
134
241
|
// import { FormControl, MenuItem, Select, SxProps, Theme } from "@mui/material";
|