rez-table-listing-mui 1.2.17 → 1.2.18
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/index.tsx +22 -0
- package/src/listing/libs/hooks/useEntityTableAPI.tsx +0 -50
- package/src/listing/libs/utils/apiColumn.ts +0 -1
- package/src/view/FIlterWrapper.tsx +90 -6
- package/src/view/ListingView.tsx +5 -3
package/package.json
CHANGED
|
@@ -244,6 +244,28 @@ export function TableFilter({
|
|
|
244
244
|
label: editMode ? "Replace Filter" : "Save",
|
|
245
245
|
onClick: (inputValue) => {
|
|
246
246
|
if (editMode) {
|
|
247
|
+
const selectedId = filterMaster?.saved_filters?.selectedId;
|
|
248
|
+
const selectedName =
|
|
249
|
+
inputValue || filterMaster?.saved_filters?.selectedName;
|
|
250
|
+
|
|
251
|
+
const newFilterMasterState = {
|
|
252
|
+
...filterMaster,
|
|
253
|
+
saved_filters: {
|
|
254
|
+
...filterMaster?.attributes,
|
|
255
|
+
selectedId,
|
|
256
|
+
selectedName,
|
|
257
|
+
},
|
|
258
|
+
} as FilterMasterStateProps;
|
|
259
|
+
|
|
260
|
+
setFilterMaster(newFilterMasterState);
|
|
261
|
+
|
|
262
|
+
const newState = {
|
|
263
|
+
filterMaster: newFilterMasterState,
|
|
264
|
+
filters: filters,
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
onChangeFunction && onChangeFunction(newState);
|
|
268
|
+
|
|
247
269
|
onUpdateFilter && onUpdateFilter(inputValue || "");
|
|
248
270
|
setSaveFilterModalOpen(false);
|
|
249
271
|
setEditMode(false);
|
|
@@ -150,32 +150,10 @@ export const useDeleteFilterAPI = (tableStates: CraftTableOptionsProps) => {
|
|
|
150
150
|
onSuccess: async () => {
|
|
151
151
|
queryClient.invalidateQueries({ queryKey: ["meta"] });
|
|
152
152
|
|
|
153
|
-
console.log("on success is running");
|
|
154
|
-
|
|
155
153
|
const { filters, filterToDelete, filterMaster, setFilterMaster } =
|
|
156
154
|
tableStates;
|
|
157
155
|
|
|
158
|
-
console.log(
|
|
159
|
-
filterToDelete?.value === filterMaster?.saved_filters?.selectedId,
|
|
160
|
-
filterToDelete,
|
|
161
|
-
filterMaster
|
|
162
|
-
);
|
|
163
|
-
|
|
164
156
|
if (filterToDelete?.value === filterMaster?.saved_filters?.selectedId) {
|
|
165
|
-
console.log("inside if condition");
|
|
166
|
-
// const newFilterMasterState: FilterMasterStateProps = {
|
|
167
|
-
// ...filterMaster,
|
|
168
|
-
// attributes: {
|
|
169
|
-
// selected: filterMaster?.attributes.selected || "",
|
|
170
|
-
// radio: filterMaster?.attributes.radio || [],
|
|
171
|
-
// },
|
|
172
|
-
// saved_filters: {
|
|
173
|
-
// selectedId: "",
|
|
174
|
-
// selectedName: "",
|
|
175
|
-
// },
|
|
176
|
-
// activeFilterTabIndex: -1,
|
|
177
|
-
// };
|
|
178
|
-
|
|
179
157
|
const newFilterMasterState = {
|
|
180
158
|
...filterMaster,
|
|
181
159
|
saved_filters: {
|
|
@@ -184,7 +162,6 @@ export const useDeleteFilterAPI = (tableStates: CraftTableOptionsProps) => {
|
|
|
184
162
|
},
|
|
185
163
|
activeFilterTabIndex: -1,
|
|
186
164
|
};
|
|
187
|
-
console.log(" 1");
|
|
188
165
|
|
|
189
166
|
setFilterMaster(newFilterMasterState as FilterMasterStateProps);
|
|
190
167
|
|
|
@@ -193,8 +170,6 @@ export const useDeleteFilterAPI = (tableStates: CraftTableOptionsProps) => {
|
|
|
193
170
|
filters: filters,
|
|
194
171
|
};
|
|
195
172
|
|
|
196
|
-
console.log("first");
|
|
197
|
-
|
|
198
173
|
const payload = {
|
|
199
174
|
entity_type: MAPPED_ENTITY_TYPE,
|
|
200
175
|
mapped_entity_type: ENTITY_TYPE,
|
|
@@ -202,8 +177,6 @@ export const useDeleteFilterAPI = (tableStates: CraftTableOptionsProps) => {
|
|
|
202
177
|
type: "filter",
|
|
203
178
|
};
|
|
204
179
|
|
|
205
|
-
console.log("payload - ", payload);
|
|
206
|
-
|
|
207
180
|
await saveLayoutAPI(payload);
|
|
208
181
|
}
|
|
209
182
|
},
|
|
@@ -269,29 +242,6 @@ export const useCommonDropdownAPI = (
|
|
|
269
242
|
|
|
270
243
|
//ALL VIEW SETTINGS API
|
|
271
244
|
|
|
272
|
-
// export const useSettingsDropDownAPI = () => {
|
|
273
|
-
// const queryClient = useQueryClient();
|
|
274
|
-
|
|
275
|
-
// const viewSettingsDropDownMutation = useMutation({
|
|
276
|
-
// mutationKey: ["viewsettingsDropdown"],
|
|
277
|
-
// mutationFn: ({
|
|
278
|
-
// entity_type,
|
|
279
|
-
// column,
|
|
280
|
-
// sort_by,
|
|
281
|
-
// }: {
|
|
282
|
-
// entity_type: string;
|
|
283
|
-
// column: string;
|
|
284
|
-
// sort_by: string;
|
|
285
|
-
// }) => {
|
|
286
|
-
// return viewSettingsDropDown(entity_type, column, sort_by);
|
|
287
|
-
// },
|
|
288
|
-
// // onSuccess: () => {
|
|
289
|
-
// // queryClient.invalidateQueries({ queryKey: ["meta"] });
|
|
290
|
-
// // },
|
|
291
|
-
// });
|
|
292
|
-
|
|
293
|
-
// return { viewSettingsDropDownMutation };
|
|
294
|
-
|
|
295
245
|
export const useSettingsDropDownAPI = ({
|
|
296
246
|
entity_type,
|
|
297
247
|
column,
|
|
@@ -124,7 +124,6 @@ export const updateSavedFilter = async (
|
|
|
124
124
|
};
|
|
125
125
|
|
|
126
126
|
// ALL View Settings API
|
|
127
|
-
|
|
128
127
|
export const saveSettingsData = async (payload: any) => {
|
|
129
128
|
try {
|
|
130
129
|
const response = await api.post(`/entity/create?entity_type=${MAPPED_ENTITY_TYPE}`, payload);
|
|
@@ -2,18 +2,102 @@ import { useEffect } from "react";
|
|
|
2
2
|
import { CraftTableFilter } from "..";
|
|
3
3
|
import { useGetNavigationLayoutAPI } from "../listing/libs/hooks/useGetNavigationLayoutAPI";
|
|
4
4
|
import { ENTITY_TYPE } from "../listing/libs/utils/common";
|
|
5
|
+
import {
|
|
6
|
+
useDeleteFilterAPI,
|
|
7
|
+
useSavedFilterAPI,
|
|
8
|
+
useUpdateFilterAPI,
|
|
9
|
+
} from "../listing/libs/hooks/useEntityTableAPI";
|
|
10
|
+
import { FilterMasterStateProps } from "../listing/types/filter";
|
|
5
11
|
|
|
6
12
|
const CraftTableFilterWrapper = ({
|
|
7
13
|
tableStates,
|
|
8
14
|
dropdownData,
|
|
9
|
-
onDeleteFilter,
|
|
10
|
-
onSaveFilter,
|
|
11
|
-
handleUpdateFilter,
|
|
12
15
|
onChangeFunction,
|
|
13
16
|
columnsData,
|
|
14
17
|
}: any) => {
|
|
15
18
|
const getNavigationLayoutQuery = useGetNavigationLayoutAPI(ENTITY_TYPE);
|
|
16
19
|
|
|
20
|
+
const { filters, filterMaster, setFilterMaster, filterToDelete } =
|
|
21
|
+
tableStates;
|
|
22
|
+
|
|
23
|
+
const { savedMutation } = useSavedFilterAPI(); //API CALL FOR SAVED FILTER
|
|
24
|
+
const { updateMutation } = useUpdateFilterAPI(); //API FOR UPDATE FILTER
|
|
25
|
+
const { deleteMutation } = useDeleteFilterAPI(tableStates); //API FOR DELETING FILTER
|
|
26
|
+
|
|
27
|
+
// API to handle saving a filter
|
|
28
|
+
const handleSaveFilter = (name: string) => {
|
|
29
|
+
const quickFilter = filters.map((f: any) => ({
|
|
30
|
+
filter_attribute: f.filter_attribute,
|
|
31
|
+
filter_operator: f.filter_operator,
|
|
32
|
+
filter_value: f.filter_value,
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
const payload = {
|
|
36
|
+
name,
|
|
37
|
+
is_default: false,
|
|
38
|
+
mapped_entity_type: ENTITY_TYPE, // For that entity type
|
|
39
|
+
status: "ACTIVE",
|
|
40
|
+
entity_type: "SFM", // FIXED entity type
|
|
41
|
+
filterDetails: quickFilter,
|
|
42
|
+
};
|
|
43
|
+
const entity_type = "SFM";
|
|
44
|
+
savedMutation.mutate(
|
|
45
|
+
{ entity_type, payload },
|
|
46
|
+
{
|
|
47
|
+
onSuccess: (response) => {
|
|
48
|
+
const newFilterId = response?.id;
|
|
49
|
+
if (newFilterId) {
|
|
50
|
+
setFilterMaster(
|
|
51
|
+
(prev: FilterMasterStateProps) =>
|
|
52
|
+
({
|
|
53
|
+
...prev,
|
|
54
|
+
saved_filters: {
|
|
55
|
+
...prev?.saved_filters,
|
|
56
|
+
selectedId: newFilterId.toString(),
|
|
57
|
+
selectedName: name,
|
|
58
|
+
},
|
|
59
|
+
activeFilterTabIndex: 1,
|
|
60
|
+
} as FilterMasterStateProps)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const handleUpdateFilter = () => {
|
|
69
|
+
const quickFilter = filters.map((f: any) => ({
|
|
70
|
+
filter_attribute: f.filter_attribute,
|
|
71
|
+
filter_operator: f.filter_operator,
|
|
72
|
+
filter_value: f.filter_value,
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
const payload = {
|
|
76
|
+
name: filterMaster?.saved_filters?.selectedName, // Name of the filter
|
|
77
|
+
is_default: false,
|
|
78
|
+
id: filterMaster?.saved_filters?.selectedId,
|
|
79
|
+
mapped_entity_type: ENTITY_TYPE,
|
|
80
|
+
status: "ACTIVE",
|
|
81
|
+
entity_type: "SFM",
|
|
82
|
+
filterDetails: quickFilter,
|
|
83
|
+
};
|
|
84
|
+
const entity_type = "SFM";
|
|
85
|
+
updateMutation.mutate({ entity_type, payload });
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const handleRemoveFilter = () => {
|
|
89
|
+
const payload = {
|
|
90
|
+
name: filterToDelete?.label,
|
|
91
|
+
id: filterToDelete?.value,
|
|
92
|
+
is_default: false,
|
|
93
|
+
mapped_entity_type: ENTITY_TYPE,
|
|
94
|
+
status: "INACTIVE",
|
|
95
|
+
entity_type: "SFM",
|
|
96
|
+
};
|
|
97
|
+
const entity_type = "SFM";
|
|
98
|
+
deleteMutation.mutate({ entity_type, payload });
|
|
99
|
+
};
|
|
100
|
+
|
|
17
101
|
useEffect(() => {
|
|
18
102
|
if (getNavigationLayoutQuery.isSuccess) {
|
|
19
103
|
const { setFilters, setFilterMaster } = tableStates;
|
|
@@ -33,11 +117,11 @@ const CraftTableFilterWrapper = ({
|
|
|
33
117
|
<CraftTableFilter
|
|
34
118
|
tableStates={tableStates}
|
|
35
119
|
onClose={() => tableStates.setShowTableFilter(false)}
|
|
36
|
-
onUpdateFilter={handleUpdateFilter}
|
|
37
120
|
columnsData={columnsData}
|
|
38
121
|
dropdownData={dropdownData || []}
|
|
39
|
-
|
|
40
|
-
|
|
122
|
+
onUpdateFilter={handleUpdateFilter}
|
|
123
|
+
onDeleteFilter={handleRemoveFilter}
|
|
124
|
+
onSaveFilter={handleSaveFilter}
|
|
41
125
|
onChangeFunction={onChangeFunction}
|
|
42
126
|
/>
|
|
43
127
|
);
|
package/src/view/ListingView.tsx
CHANGED
|
@@ -316,6 +316,8 @@ function ListingView() {
|
|
|
316
316
|
|
|
317
317
|
//API to update the filter
|
|
318
318
|
const handleUpdateFilter = () => {
|
|
319
|
+
console.log("handleUpdateFilter");
|
|
320
|
+
|
|
319
321
|
const quickFilter = filters.map((f) => ({
|
|
320
322
|
filter_attribute: f.filter_attribute,
|
|
321
323
|
filter_operator: f.filter_operator,
|
|
@@ -380,11 +382,11 @@ function ListingView() {
|
|
|
380
382
|
<CraftTableFilterWrapper
|
|
381
383
|
tableStates={tableStates}
|
|
382
384
|
onClose={() => tableStates.setShowTableFilter(false)}
|
|
383
|
-
onUpdateFilter={handleUpdateFilter}
|
|
384
385
|
columnsData={metaQuery.data || {}}
|
|
385
386
|
dropdownData={dropdownData || []}
|
|
386
|
-
|
|
387
|
-
|
|
387
|
+
// onUpdateFilter={handleUpdateFilter}
|
|
388
|
+
// onDeleteFilter={handleRemoveFilter}
|
|
389
|
+
// onSaveFilter={handleSaveFilter}
|
|
388
390
|
onChangeFunction={handleChangeFunction}
|
|
389
391
|
/>
|
|
390
392
|
),
|