rez-table-listing-mui 1.0.40 → 1.0.41
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.d.ts +12 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/App.tsx +22 -15
- package/src/assets/svg.tsx +61 -1
- package/src/components/common/loader/loader.tsx +20 -0
- package/src/components/table-settings/common/draggable-listitem.tsx +7 -6
- package/src/components/table-settings/common/listing-values.tsx +23 -24
- package/src/components/table-settings/components/column.tsx +111 -49
- package/src/components/table-settings/components/quick-tab.tsx +143 -29
- package/src/components/table-settings/components/sorting.tsx +201 -457
- package/src/components/table-settings/components/toggle-button-switch.tsx +1 -0
- package/src/components/table-settings/index.tsx +40 -14
- package/src/components/table-settings/style.ts +1 -4
- package/src/components/table-settings/tabs/vertical/custom-tab-panel.tsx +4 -3
- package/src/libs/hooks/useCraftTableFilterSettings.tsx +25 -6
- package/src/libs/hooks/useEntityTableAPI.tsx +43 -10
- package/src/libs/utils/apiColumn.ts +24 -2
- package/src/main.tsx +12 -1
- package/src/types/filter-settings.ts +10 -0
- package/src/types/table-options.ts +3 -0
|
@@ -35,36 +35,73 @@ const Sorting = ({
|
|
|
35
35
|
filterSettingStates,
|
|
36
36
|
columnsData,
|
|
37
37
|
}: SettingsSortingProps) => {
|
|
38
|
-
const {
|
|
39
|
-
|
|
38
|
+
const {
|
|
39
|
+
quickTabStates,
|
|
40
|
+
sortingTabState,
|
|
41
|
+
setSortingTabState,
|
|
42
|
+
saveButtonError,
|
|
43
|
+
setSaveButtonError,
|
|
44
|
+
} = filterSettingStates;
|
|
40
45
|
|
|
41
46
|
const [activeTab, setActiveTab] = useState<string | undefined>(
|
|
42
47
|
quickTabStates?.show_list?.[0]
|
|
43
48
|
);
|
|
44
49
|
|
|
50
|
+
const isSortingDefault = sortingTabState?.isDefault;
|
|
51
|
+
|
|
45
52
|
useEffect(() => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
// Render empty columns
|
|
54
|
+
const emptySortBy: SortingConfigSortByProps[] = [
|
|
55
|
+
{ column: "", order: "asc" },
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const mappedQuickTabs =
|
|
59
|
+
quickTabStates?.show_list?.map((tab) => ({
|
|
60
|
+
tab_name: tab,
|
|
61
|
+
sortby: emptySortBy,
|
|
62
|
+
})) || [];
|
|
51
63
|
|
|
64
|
+
if (!Object.entries(sortingTabState)?.length) {
|
|
52
65
|
// Create a new default sorting state
|
|
53
66
|
const newSortingState: SortingConfigProps = {
|
|
54
67
|
isDefault: true,
|
|
55
68
|
sortby: emptySortBy,
|
|
56
|
-
tabs:
|
|
57
|
-
tab_name: tab,
|
|
58
|
-
sortby: emptySortBy,
|
|
59
|
-
})),
|
|
69
|
+
tabs: mappedQuickTabs,
|
|
60
70
|
};
|
|
61
71
|
|
|
72
|
+
setSaveButtonError((prev) => ({
|
|
73
|
+
...prev,
|
|
74
|
+
hasError: true,
|
|
75
|
+
messages: [
|
|
76
|
+
...saveButtonError?.messages,
|
|
77
|
+
{ type: "sorting_error", message: "Please select a column" },
|
|
78
|
+
],
|
|
79
|
+
}));
|
|
80
|
+
|
|
62
81
|
setActiveTab(newSortingState?.tabs?.[0]?.tab_name);
|
|
63
82
|
setSortingTabState(newSortingState);
|
|
64
83
|
}
|
|
65
|
-
}, []);
|
|
66
84
|
|
|
67
|
-
|
|
85
|
+
// If show_list is not empty
|
|
86
|
+
// if (quickTabStates?.show_list?.length) {
|
|
87
|
+
// setSortingTabState((prev) => ({
|
|
88
|
+
// ...prev,
|
|
89
|
+
// tabs: mappedQuickTabs,
|
|
90
|
+
// }));
|
|
91
|
+
// setActiveTab(mappedQuickTabs?.[0]?.tab_name);
|
|
92
|
+
// }
|
|
93
|
+
}, [quickTabStates?.show_list]);
|
|
94
|
+
|
|
95
|
+
// useEffect(() => {
|
|
96
|
+
// const hasEmptySortBy = false;
|
|
97
|
+
|
|
98
|
+
// if (isSortingDefault !== undefined && isSortingDefault) {
|
|
99
|
+
// console.log("first");
|
|
100
|
+
// } else {
|
|
101
|
+
// console.log("second");
|
|
102
|
+
// }
|
|
103
|
+
// }, [isSortingDefault]);
|
|
104
|
+
|
|
68
105
|
const sensors = useSensors(useSensor(PointerSensor));
|
|
69
106
|
|
|
70
107
|
const activeTabIndex = sortingTabState?.tabs?.findIndex(
|
|
@@ -84,7 +121,7 @@ const Sorting = ({
|
|
|
84
121
|
* * - Return an empty array
|
|
85
122
|
*/
|
|
86
123
|
const tabSortedList = useMemo(() => {
|
|
87
|
-
return
|
|
124
|
+
return isSortingDefault
|
|
88
125
|
? sortingTabState?.sortby
|
|
89
126
|
: activeTab !== undefined
|
|
90
127
|
? sortingTabState?.tabs?.[activeTabIndex || 0]?.sortby
|
|
@@ -113,6 +150,20 @@ const Sorting = ({
|
|
|
113
150
|
) => {
|
|
114
151
|
if (!tabSortedList) return;
|
|
115
152
|
|
|
153
|
+
// Check if sorting_error exists
|
|
154
|
+
// If it does, remove it
|
|
155
|
+
if (key === "column") {
|
|
156
|
+
const otherErrors = saveButtonError?.messages?.filter(
|
|
157
|
+
(error) => error.type !== "sorting_error"
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
setSaveButtonError((prev) => ({
|
|
161
|
+
...prev,
|
|
162
|
+
hasError: otherErrors.length > 0,
|
|
163
|
+
messages: otherErrors,
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
|
|
116
167
|
const updated = [...tabSortedList];
|
|
117
168
|
updated[index] = { ...updated[index], [key]: value };
|
|
118
169
|
updateSortList(updated);
|
|
@@ -122,9 +173,19 @@ const Sorting = ({
|
|
|
122
173
|
if (!tabSortedList) return;
|
|
123
174
|
|
|
124
175
|
const newItem: SortingConfigSortByProps = {
|
|
125
|
-
column:
|
|
176
|
+
column: "",
|
|
126
177
|
order: "asc",
|
|
127
178
|
};
|
|
179
|
+
|
|
180
|
+
setSaveButtonError((prev) => ({
|
|
181
|
+
...prev,
|
|
182
|
+
hasError: true,
|
|
183
|
+
messages: [
|
|
184
|
+
...saveButtonError?.messages,
|
|
185
|
+
{ type: "sorting_error", message: "Please select a column" },
|
|
186
|
+
],
|
|
187
|
+
}));
|
|
188
|
+
|
|
128
189
|
updateSortList([...tabSortedList, newItem]);
|
|
129
190
|
};
|
|
130
191
|
|
|
@@ -133,6 +194,23 @@ const Sorting = ({
|
|
|
133
194
|
|
|
134
195
|
const updated = tabSortedList.filter((item) => item.column !== columnKey);
|
|
135
196
|
updateSortList(updated);
|
|
197
|
+
|
|
198
|
+
// ! CHECK THIS LOGIC AND CHANGE AS NEEDED
|
|
199
|
+
// check if any of the columns are empty
|
|
200
|
+
const columnsHasEmptyValue =
|
|
201
|
+
updated.some((item) => item.column === "") || updated.length === 0;
|
|
202
|
+
|
|
203
|
+
if (columnsHasEmptyValue) {
|
|
204
|
+
const filteredErrors = saveButtonError?.messages?.filter(
|
|
205
|
+
(error) => error.type !== "sorting_error"
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
setSaveButtonError((prev) => ({
|
|
209
|
+
...prev,
|
|
210
|
+
hasError: true,
|
|
211
|
+
messages: filteredErrors,
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
136
214
|
};
|
|
137
215
|
|
|
138
216
|
const handleModeChange = (
|
|
@@ -159,461 +237,127 @@ const Sorting = ({
|
|
|
159
237
|
}
|
|
160
238
|
};
|
|
161
239
|
|
|
240
|
+
const hasShowListQuickTabs =
|
|
241
|
+
quickTabStates?.show_list?.length !== 0 || isSortingDefault ? true : false;
|
|
242
|
+
const showAddSortButton =
|
|
243
|
+
tabSortedList?.length !== columnsData?.column_list?.length;
|
|
244
|
+
|
|
245
|
+
const isAddSortDisabled = useMemo(() => {
|
|
246
|
+
return saveButtonError?.messages?.some(
|
|
247
|
+
(error) => error?.type === "sorting_error"
|
|
248
|
+
);
|
|
249
|
+
}, [saveButtonError]);
|
|
250
|
+
|
|
162
251
|
return (
|
|
163
252
|
<Box sx={{ display: "flex", flexDirection: "column", gap: "0.75rem" }}>
|
|
164
253
|
<Typography>Select attribute(s) you want to sort by</Typography>
|
|
165
254
|
|
|
166
255
|
<CustomToggleSwitchButton
|
|
167
256
|
buttons={TOGGLE_BUTTON_TABS}
|
|
168
|
-
value={
|
|
257
|
+
value={isSortingDefault}
|
|
169
258
|
onChange={handleModeChange}
|
|
170
259
|
/>
|
|
171
260
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
261
|
+
{hasShowListQuickTabs ? (
|
|
262
|
+
<>
|
|
263
|
+
<Box>
|
|
264
|
+
{!isSortingDefault && (
|
|
265
|
+
<CustomTabs
|
|
266
|
+
value={activeTab}
|
|
267
|
+
onChange={(_, tab) => setActiveTab(tab)}
|
|
268
|
+
>
|
|
269
|
+
{quickTabStates?.show_list?.map((tab) => (
|
|
270
|
+
<Tab key={tab} label={tab} value={tab} />
|
|
271
|
+
))}
|
|
272
|
+
</CustomTabs>
|
|
273
|
+
)}
|
|
274
|
+
|
|
275
|
+
<DndContext
|
|
276
|
+
sensors={sensors}
|
|
277
|
+
collisionDetection={closestCenter}
|
|
278
|
+
onDragEnd={handleDragEnd}
|
|
279
|
+
>
|
|
280
|
+
<SortableContext
|
|
281
|
+
items={tabSortedList?.map((s) => s.column) || []}
|
|
282
|
+
strategy={verticalListSortingStrategy}
|
|
283
|
+
>
|
|
284
|
+
{tabSortedList?.map((sort, index) => (
|
|
285
|
+
<SortableItem key={sort.column} id={sort.column}>
|
|
286
|
+
<Box display="flex" gap={1} alignItems="center" mb={1}>
|
|
287
|
+
<Select
|
|
288
|
+
value={sort.column}
|
|
289
|
+
onChange={(e) =>
|
|
290
|
+
handleDNDDropdownChange(
|
|
291
|
+
"column",
|
|
292
|
+
e.target.value,
|
|
293
|
+
index
|
|
294
|
+
)
|
|
295
|
+
}
|
|
296
|
+
size="small"
|
|
297
|
+
fullWidth
|
|
298
|
+
>
|
|
299
|
+
{columnsData?.column_list?.map((column) => (
|
|
300
|
+
<MenuItem
|
|
301
|
+
key={column?.attribute_key}
|
|
302
|
+
value={column?.attribute_key}
|
|
303
|
+
disabled={tabSortedList.some(
|
|
304
|
+
(s) => s.column === column?.attribute_key
|
|
305
|
+
)}
|
|
306
|
+
>
|
|
307
|
+
{column?.name}
|
|
308
|
+
</MenuItem>
|
|
309
|
+
))}
|
|
310
|
+
</Select>
|
|
311
|
+
<Select
|
|
312
|
+
value={sort.order}
|
|
313
|
+
onChange={(e) =>
|
|
314
|
+
handleDNDDropdownChange(
|
|
315
|
+
"order",
|
|
316
|
+
e.target.value,
|
|
317
|
+
index
|
|
318
|
+
)
|
|
319
|
+
}
|
|
320
|
+
size="small"
|
|
321
|
+
fullWidth
|
|
322
|
+
>
|
|
323
|
+
<MenuItem value="asc">Ascending</MenuItem>
|
|
324
|
+
<MenuItem value="desc">Descending</MenuItem>
|
|
325
|
+
</Select>
|
|
326
|
+
<IconButton
|
|
327
|
+
size="small"
|
|
328
|
+
onClick={() => handleRemove(sort.column)}
|
|
329
|
+
>
|
|
330
|
+
<CloseIcon />
|
|
331
|
+
</IconButton>
|
|
332
|
+
</Box>
|
|
333
|
+
</SortableItem>
|
|
334
|
+
))}
|
|
335
|
+
</SortableContext>
|
|
336
|
+
</DndContext>
|
|
337
|
+
|
|
338
|
+
{showAddSortButton && (
|
|
339
|
+
<Box>
|
|
340
|
+
<Button
|
|
341
|
+
onClick={handleAddSort}
|
|
342
|
+
startIcon={<AddIcon />}
|
|
343
|
+
variant="text"
|
|
344
|
+
sx={{
|
|
345
|
+
fontSize: 13,
|
|
346
|
+
color: "#7A5AF8",
|
|
347
|
+
}}
|
|
348
|
+
disabled={isAddSortDisabled}
|
|
204
349
|
>
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
key={column?.attribute_key}
|
|
208
|
-
value={column?.attribute_key}
|
|
209
|
-
>
|
|
210
|
-
{column?.name}
|
|
211
|
-
</MenuItem>
|
|
212
|
-
))}
|
|
213
|
-
</Select>
|
|
214
|
-
<Select
|
|
215
|
-
value={sort.order}
|
|
216
|
-
onChange={(e) =>
|
|
217
|
-
handleDNDDropdownChange("order", e.target.value, index)
|
|
218
|
-
}
|
|
219
|
-
size="small"
|
|
220
|
-
fullWidth
|
|
221
|
-
>
|
|
222
|
-
<MenuItem value="asc">Ascending</MenuItem>
|
|
223
|
-
<MenuItem value="desc">Descending</MenuItem>
|
|
224
|
-
</Select>
|
|
225
|
-
<IconButton
|
|
226
|
-
size="small"
|
|
227
|
-
onClick={() => handleRemove(sort.column)}
|
|
228
|
-
>
|
|
229
|
-
<CloseIcon />
|
|
230
|
-
</IconButton>
|
|
350
|
+
Add Sort
|
|
351
|
+
</Button>
|
|
231
352
|
</Box>
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
onClick={handleAddSort}
|
|
239
|
-
startIcon={<AddIcon />}
|
|
240
|
-
variant="text"
|
|
241
|
-
sx={{
|
|
242
|
-
fontSize: 13,
|
|
243
|
-
color: "#7A5AF8",
|
|
244
|
-
}}
|
|
245
|
-
>
|
|
246
|
-
Add Sort
|
|
247
|
-
</Button>
|
|
353
|
+
)}
|
|
354
|
+
</Box>
|
|
355
|
+
</>
|
|
356
|
+
) : (
|
|
357
|
+
<Typography>View as Tabs empty in Quick Tab</Typography>
|
|
358
|
+
)}
|
|
248
359
|
</Box>
|
|
249
|
-
|
|
250
|
-
// <Box sx={{ display: "flex", flexDirection: "column", gap: "0.75rem" }}>
|
|
251
|
-
// <Typography>Select attribute(s) you want to sort by</Typography>
|
|
252
|
-
|
|
253
|
-
// <CustomToggleSwitchButton value={isDefault} onChange={handleModeChange} />
|
|
254
|
-
|
|
255
|
-
// <Box>
|
|
256
|
-
// {!isDefault && (
|
|
257
|
-
// <Tabs
|
|
258
|
-
// value={tab}
|
|
259
|
-
// onChange={(_, v) => setTab(v as TabKey)}
|
|
260
|
-
// sx={{
|
|
261
|
-
// mb: 2,
|
|
262
|
-
// "& .MuiTab-root": {
|
|
263
|
-
// color: "#0E0C0BE5",
|
|
264
|
-
// textTransform: "none",
|
|
265
|
-
// fontWeight: 500,
|
|
266
|
-
// },
|
|
267
|
-
// "& .Mui-selected": {
|
|
268
|
-
// color: "#7A5AF8",
|
|
269
|
-
// },
|
|
270
|
-
// "& .MuiTabs-indicator": {
|
|
271
|
-
// backgroundColor: "#7A5AF8",
|
|
272
|
-
// height: 3,
|
|
273
|
-
// },
|
|
274
|
-
// }}
|
|
275
|
-
// >
|
|
276
|
-
// {tabs.map((t) => (
|
|
277
|
-
// <Tab key={t} label={t} value={t} />
|
|
278
|
-
// ))}
|
|
279
|
-
// </Tabs>
|
|
280
|
-
// )}
|
|
281
|
-
|
|
282
|
-
// <DndContext
|
|
283
|
-
// sensors={sensors}
|
|
284
|
-
// collisionDetection={closestCenter}
|
|
285
|
-
// onDragEnd={handleDragEnd}
|
|
286
|
-
// >
|
|
287
|
-
// <SortableContext
|
|
288
|
-
// items={currentSortList?.map((s) => s.id)}
|
|
289
|
-
// strategy={verticalListSortingStrategy}
|
|
290
|
-
// >
|
|
291
|
-
// {currentSortList?.map((sort) => (
|
|
292
|
-
// <SortableItem key={sort.id} id={sort.id}>
|
|
293
|
-
// <Box display="flex" gap={1} alignItems="center" mb={1}>
|
|
294
|
-
// <Select
|
|
295
|
-
// value={sort.field}
|
|
296
|
-
// onChange={(e) =>
|
|
297
|
-
// handleChange(sort.id, "field", e.target.value)
|
|
298
|
-
// }
|
|
299
|
-
// size="small"
|
|
300
|
-
// fullWidth
|
|
301
|
-
// >
|
|
302
|
-
// {attributes.map((attr) => (
|
|
303
|
-
// <MenuItem key={attr} value={attr}>
|
|
304
|
-
// {attr}
|
|
305
|
-
// </MenuItem>
|
|
306
|
-
// ))}
|
|
307
|
-
// </Select>
|
|
308
|
-
// <Select
|
|
309
|
-
// value={sort.direction}
|
|
310
|
-
// onChange={(e) =>
|
|
311
|
-
// handleChange(sort.id, "direction", e.target.value)
|
|
312
|
-
// }
|
|
313
|
-
// size="small"
|
|
314
|
-
// fullWidth
|
|
315
|
-
// >
|
|
316
|
-
// <MenuItem value="asc">Ascending</MenuItem>
|
|
317
|
-
// <MenuItem value="desc">Descending</MenuItem>
|
|
318
|
-
// </Select>
|
|
319
|
-
// <IconButton
|
|
320
|
-
// size="small"
|
|
321
|
-
// onClick={() => handleRemove(sort.id)}
|
|
322
|
-
// >
|
|
323
|
-
// <CloseIcon />
|
|
324
|
-
// </IconButton>
|
|
325
|
-
// </Box>
|
|
326
|
-
// </SortableItem>
|
|
327
|
-
// ))}
|
|
328
|
-
// </SortableContext>
|
|
329
|
-
// </DndContext>
|
|
330
|
-
|
|
331
|
-
// <Button
|
|
332
|
-
// onClick={handleAddSort}
|
|
333
|
-
// startIcon={<AddIcon />}
|
|
334
|
-
// sx={{
|
|
335
|
-
// fontSize: 13,
|
|
336
|
-
// color: "#7A5AF8",
|
|
337
|
-
// textTransform: "uppercase",
|
|
338
|
-
// }}
|
|
339
|
-
// >
|
|
340
|
-
// Add Sort
|
|
341
|
-
// </Button>
|
|
342
|
-
// </Box>
|
|
343
|
-
|
|
344
|
-
// <Box>
|
|
345
|
-
// <Button
|
|
346
|
-
// onClick={handleSave}
|
|
347
|
-
// sx={{
|
|
348
|
-
// backgroundColor: "#7A5AF8",
|
|
349
|
-
// color: "#fff",
|
|
350
|
-
// textTransform: "none",
|
|
351
|
-
// }}
|
|
352
|
-
// >
|
|
353
|
-
// Save Sorting
|
|
354
|
-
// </Button>
|
|
355
|
-
// </Box>
|
|
356
|
-
// </Box>
|
|
357
360
|
);
|
|
358
361
|
};
|
|
359
362
|
|
|
360
363
|
export default Sorting;
|
|
361
|
-
|
|
362
|
-
// import React, { useEffect, useState } from "react";
|
|
363
|
-
// import {
|
|
364
|
-
// Box,
|
|
365
|
-
// Tabs,
|
|
366
|
-
// Tab,
|
|
367
|
-
// Button,
|
|
368
|
-
// Select,
|
|
369
|
-
// MenuItem,
|
|
370
|
-
// IconButton,
|
|
371
|
-
// Typography,
|
|
372
|
-
// } from "@mui/material";
|
|
373
|
-
// import {
|
|
374
|
-
// DndContext,
|
|
375
|
-
// closestCenter,
|
|
376
|
-
// useSensors,
|
|
377
|
-
// useSensor,
|
|
378
|
-
// PointerSensor,
|
|
379
|
-
// } from "@dnd-kit/core";
|
|
380
|
-
// import {
|
|
381
|
-
// SortableContext,
|
|
382
|
-
// arrayMove,
|
|
383
|
-
// verticalListSortingStrategy,
|
|
384
|
-
// } from "@dnd-kit/sortable";
|
|
385
|
-
// import SortableItem from "../../sorting-modal.tsx/sorting-item";
|
|
386
|
-
// import { AddIcon, CloseIcon } from "../../../assets/svg";
|
|
387
|
-
// import CustomToggleSwitchButton from "./toggle-button-switch";
|
|
388
|
-
// import { SettingsSortingProps } from "../../../types/filter-settings";
|
|
389
|
-
|
|
390
|
-
// const tabs = ["Active", "Reject"];
|
|
391
|
-
// type TabKey = (typeof tabs)[number];
|
|
392
|
-
|
|
393
|
-
// interface SortItem {
|
|
394
|
-
// id: string;
|
|
395
|
-
// field: string;
|
|
396
|
-
// direction: "asc" | "desc";
|
|
397
|
-
// }
|
|
398
|
-
|
|
399
|
-
// interface sortingTabState {
|
|
400
|
-
// isDefault: boolean;
|
|
401
|
-
// default: SortItem[];
|
|
402
|
-
// tabs: Record<TabKey, SortItem[]>;
|
|
403
|
-
// }
|
|
404
|
-
|
|
405
|
-
// const Sorting = ({ columnsData }: SettingsSortingProps) => {
|
|
406
|
-
// const [tab, setTab] = useState<TabKey>("Active");
|
|
407
|
-
// const [sortingTabState, setSortingTabState] = useState<sortingTabState>({
|
|
408
|
-
// isDefault: true,
|
|
409
|
-
// default: [],
|
|
410
|
-
// tabs: {
|
|
411
|
-
// Active: [],
|
|
412
|
-
// Reject: [],
|
|
413
|
-
// },
|
|
414
|
-
// });
|
|
415
|
-
|
|
416
|
-
// const isDefault = sortingTabState?.isDefault;
|
|
417
|
-
|
|
418
|
-
// const attributes = ["Id", "Status", "Name", "Date"];
|
|
419
|
-
// const sensors = useSensors(useSensor(PointerSensor));
|
|
420
|
-
|
|
421
|
-
// const currentSortList = isDefault ? sortingTabState.default : sortingTabState.tabs[tab];
|
|
422
|
-
|
|
423
|
-
// const updateSortList = (updated: SortItem[]) => {
|
|
424
|
-
// setSortingTabState((prev) =>
|
|
425
|
-
// isDefault
|
|
426
|
-
// ? { ...prev, default: updated }
|
|
427
|
-
// : { ...prev, tabs: { ...prev.tabs, [tab]: updated } }
|
|
428
|
-
// );
|
|
429
|
-
// };
|
|
430
|
-
|
|
431
|
-
// const handleDragEnd = (event: any) => {
|
|
432
|
-
// const { active, over } = event;
|
|
433
|
-
// if (!over || active.id === over.id) return;
|
|
434
|
-
|
|
435
|
-
// const list = currentSortList;
|
|
436
|
-
// const oldIndex = list.findIndex((i) => i.id === active.id);
|
|
437
|
-
// const newIndex = list.findIndex((i) => i.id === over.id);
|
|
438
|
-
// const reordered = arrayMove(list, oldIndex, newIndex);
|
|
439
|
-
// updateSortList(reordered);
|
|
440
|
-
// };
|
|
441
|
-
|
|
442
|
-
// const handleChange = (id: string, key: keyof SortItem, value: any) => {
|
|
443
|
-
// const updated = currentSortList.map((item) =>
|
|
444
|
-
// item.id === id ? { ...item, [key]: value } : item
|
|
445
|
-
// );
|
|
446
|
-
// updateSortList(updated);
|
|
447
|
-
// };
|
|
448
|
-
|
|
449
|
-
// const handleAddSort = () => {
|
|
450
|
-
// const newItem: SortItem = {
|
|
451
|
-
// id: Date.now().toString(),
|
|
452
|
-
// field: attributes[0],
|
|
453
|
-
// direction: "asc",
|
|
454
|
-
// };
|
|
455
|
-
// updateSortList([...currentSortList, newItem]);
|
|
456
|
-
// };
|
|
457
|
-
|
|
458
|
-
// const handleRemove = (id: string) => {
|
|
459
|
-
// const updated = currentSortList.filter((item) => item.id !== id);
|
|
460
|
-
// updateSortList(updated);
|
|
461
|
-
// };
|
|
462
|
-
|
|
463
|
-
// const handleModeChange = (
|
|
464
|
-
// _: React.MouseEvent<HTMLElement>,
|
|
465
|
-
// value: boolean
|
|
466
|
-
// ) => {
|
|
467
|
-
// if (value !== null) {
|
|
468
|
-
// setSortingTabState((prev) => ({ ...prev, isDefault: value }));
|
|
469
|
-
// }
|
|
470
|
-
// };
|
|
471
|
-
|
|
472
|
-
// const handleSave = () => {
|
|
473
|
-
// const payload: any = {
|
|
474
|
-
// isDefault: sortingTabState.isDefault,
|
|
475
|
-
// };
|
|
476
|
-
|
|
477
|
-
// if (sortingTabState.isDefault) {
|
|
478
|
-
// payload.sortby = sortingTabState.default.map((s) => ({
|
|
479
|
-
// column: s.field.toLowerCase(),
|
|
480
|
-
// order: s.direction,
|
|
481
|
-
// }));
|
|
482
|
-
// } else {
|
|
483
|
-
// payload.tabs = Object.entries(sortingTabState.tabs).map(
|
|
484
|
-
// ([tabName, sortby]) => ({
|
|
485
|
-
// tab_name: tabName.toLowerCase(),
|
|
486
|
-
// sortby: sortby.map((s) => ({
|
|
487
|
-
// column: s.field.toLowerCase(),
|
|
488
|
-
// order: s.direction,
|
|
489
|
-
// })),
|
|
490
|
-
// })
|
|
491
|
-
// );
|
|
492
|
-
// }
|
|
493
|
-
// };
|
|
494
|
-
|
|
495
|
-
// return (
|
|
496
|
-
// <Box p={2}>
|
|
497
|
-
// <Typography
|
|
498
|
-
// variant="h6"
|
|
499
|
-
// mb={2}
|
|
500
|
-
// sx={{ color: "#0E0C0BE5", fontWeight: "500", fontSize: "16px" }}
|
|
501
|
-
// >
|
|
502
|
-
// Select attribute(s) you want to sort by
|
|
503
|
-
// </Typography>
|
|
504
|
-
|
|
505
|
-
// <Box
|
|
506
|
-
// display="flex"
|
|
507
|
-
// flexDirection="column"
|
|
508
|
-
// alignItems="flex-start"
|
|
509
|
-
// gap={1}
|
|
510
|
-
// mb={2}
|
|
511
|
-
// >
|
|
512
|
-
// <CustomToggleSwitchButton value={isDefault} onChange={handleModeChange} />
|
|
513
|
-
|
|
514
|
-
// <Button
|
|
515
|
-
// onClick={handleAddSort}
|
|
516
|
-
// startIcon={<AddIcon />}
|
|
517
|
-
// sx={{
|
|
518
|
-
// fontSize: 13,
|
|
519
|
-
// padding: 0,
|
|
520
|
-
// color: "#7A5AF8",
|
|
521
|
-
// textTransform: "uppercase",
|
|
522
|
-
// fontWeight: 500,
|
|
523
|
-
// minHeight: 0,
|
|
524
|
-
// minWidth: 0,
|
|
525
|
-
// }}
|
|
526
|
-
// >
|
|
527
|
-
// Add Sort
|
|
528
|
-
// </Button>
|
|
529
|
-
// </Box>
|
|
530
|
-
|
|
531
|
-
// {!isDefault && (
|
|
532
|
-
// <Tabs
|
|
533
|
-
// value={tab}
|
|
534
|
-
// onChange={(_, v) => setTab(v as TabKey)}
|
|
535
|
-
// sx={{
|
|
536
|
-
// mb: 2,
|
|
537
|
-
// "& .MuiTab-root": {
|
|
538
|
-
// color: "#0E0C0BE5",
|
|
539
|
-
// textTransform: "none",
|
|
540
|
-
// fontWeight: 500,
|
|
541
|
-
// },
|
|
542
|
-
// "& .Mui-selected": {
|
|
543
|
-
// color: "#7A5AF8",
|
|
544
|
-
// },
|
|
545
|
-
// "& .MuiTabs-indicator": {
|
|
546
|
-
// backgroundColor: "#7A5AF8",
|
|
547
|
-
// height: 3,
|
|
548
|
-
// },
|
|
549
|
-
// }}
|
|
550
|
-
// >
|
|
551
|
-
// {tabs.map((t) => (
|
|
552
|
-
// <Tab key={t} label={t} value={t} />
|
|
553
|
-
// ))}
|
|
554
|
-
// </Tabs>
|
|
555
|
-
// )}
|
|
556
|
-
|
|
557
|
-
// <DndContext
|
|
558
|
-
// sensors={sensors}
|
|
559
|
-
// collisionDetection={closestCenter}
|
|
560
|
-
// onDragEnd={handleDragEnd}
|
|
561
|
-
// >
|
|
562
|
-
// <SortableContext
|
|
563
|
-
// items={currentSortList.map((s) => s.id)}
|
|
564
|
-
// strategy={verticalListSortingStrategy}
|
|
565
|
-
// >
|
|
566
|
-
// {currentSortList.map((sort) => (
|
|
567
|
-
// <SortableItem key={sort.id} id={sort.id}>
|
|
568
|
-
// <Box display="flex" gap={1} alignItems="center" mb={1}>
|
|
569
|
-
// <Select
|
|
570
|
-
// value={sort.field}
|
|
571
|
-
// onChange={(e) =>
|
|
572
|
-
// handleChange(sort.id, "field", e.target.value)
|
|
573
|
-
// }
|
|
574
|
-
// size="small"
|
|
575
|
-
// sx={{ minWidth: 450 }}
|
|
576
|
-
// >
|
|
577
|
-
// {attributes.map((attr) => (
|
|
578
|
-
// <MenuItem key={attr} value={attr}>
|
|
579
|
-
// {attr}
|
|
580
|
-
// </MenuItem>
|
|
581
|
-
// ))}
|
|
582
|
-
// </Select>
|
|
583
|
-
// <Select
|
|
584
|
-
// value={sort.direction}
|
|
585
|
-
// onChange={(e) =>
|
|
586
|
-
// handleChange(sort.id, "direction", e.target.value)
|
|
587
|
-
// }
|
|
588
|
-
// size="small"
|
|
589
|
-
// sx={{ minWidth: 450 }}
|
|
590
|
-
// >
|
|
591
|
-
// <MenuItem value="asc">Ascending</MenuItem>
|
|
592
|
-
// <MenuItem value="desc">Descending</MenuItem>
|
|
593
|
-
// </Select>
|
|
594
|
-
// <IconButton size="small" onClick={() => handleRemove(sort.id)}>
|
|
595
|
-
// <CloseIcon />
|
|
596
|
-
// </IconButton>
|
|
597
|
-
// </Box>
|
|
598
|
-
// </SortableItem>
|
|
599
|
-
// ))}
|
|
600
|
-
// </SortableContext>
|
|
601
|
-
// </DndContext>
|
|
602
|
-
|
|
603
|
-
// <Box sx={{ mt: 20, marginLeft: "700px" }}>
|
|
604
|
-
// <Button
|
|
605
|
-
// onClick={handleSave}
|
|
606
|
-
// sx={{
|
|
607
|
-
// backgroundColor: "#7A5AF8",
|
|
608
|
-
// color: "#fff",
|
|
609
|
-
// textTransform: "none",
|
|
610
|
-
// }}
|
|
611
|
-
// >
|
|
612
|
-
// Save Sorting
|
|
613
|
-
// </Button>
|
|
614
|
-
// </Box>
|
|
615
|
-
// </Box>
|
|
616
|
-
// );
|
|
617
|
-
// };
|
|
618
|
-
|
|
619
|
-
// export default Sorting;
|