rez-table-listing-mui 2.0.13 → 2.0.15

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.
@@ -1,511 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- import {
3
- Box,
4
- Select,
5
- MenuItem,
6
- FormControl,
7
- Typography,
8
- Checkbox,
9
- FormControlLabel,
10
- Grid,
11
- Alert,
12
- } from "@mui/material";
13
-
14
- import ListingValues from "../common/listing-values";
15
- import {
16
- DndContext,
17
- closestCenter,
18
- KeyboardSensor,
19
- MouseSensor,
20
- TouchSensor,
21
- useSensor,
22
- useSensors,
23
- DragEndEvent,
24
- } from "@dnd-kit/core";
25
- import {
26
- QuickTabConfigProps,
27
- SettingsQuickTabProps,
28
- } from "../../../types/filter-settings";
29
- import { TabsStyles } from "../style";
30
- import InfoAlert from "../common/info-alert";
31
- import { craftTableFilterSettingsOptionsProps } from "../../../types/table-options";
32
- import { LANE_SELECTS } from "../constants";
33
- import { Group } from "@mui/icons-material";
34
-
35
- const GroupBy = ({
36
- filterSettingStates,
37
- columnsData,
38
- tabsApiData,
39
- tabsApiDataLoading,
40
- }: {
41
- filterSettingStates: craftTableFilterSettingsOptionsProps;
42
- columnsData: any;
43
- tabsApiData?: { label: string; value: string }[];
44
- tabsApiDataLoading?: boolean;
45
- }) => {
46
- const { settingsData, setSettingsData, saveButtonError, setSaveButtonError } =
47
- filterSettingStates;
48
-
49
- const [searchTerm, setSearchTerm] = useState<string>("");
50
- const [currentQuickAttribute, setCurrentQuickAttribute] = useState<string>(
51
- settingsData?.quick_tab?.attribute || ""
52
- );
53
-
54
- const quickTabStates = settingsData?.quick_tab as any;
55
-
56
- // In case there is no quick tab state from API
57
- useEffect(() => {
58
- const stateToArray =
59
- (quickTabStates && Object.entries(quickTabStates)) || [];
60
- const isEmptyState = stateToArray.length ? false : true;
61
-
62
- if (isEmptyState) {
63
- setSettingsData((prev) => ({
64
- ...prev,
65
- quick_tab: {
66
- ...prev?.quick_tab,
67
- attribute: LANE_SELECTS[0].value,
68
- sorting: "asc",
69
- },
70
- }));
71
- }
72
- }, [columnsData]);
73
-
74
- // When user changes attribute
75
- useEffect(() => {
76
- if (currentQuickAttribute === settingsData?.quick_tab?.attribute) return;
77
-
78
- if (tabsApiData?.length) {
79
- setSettingsData((prev) => ({
80
- ...prev,
81
- quick_tab: {
82
- ...prev?.quick_tab,
83
- hide_list: tabsApiData,
84
- show_list: [],
85
- },
86
- }));
87
-
88
- setCurrentQuickAttribute(settingsData?.quick_tab?.attribute || "");
89
- }
90
- }, [tabsApiData]);
91
-
92
- // Validation when user changes show list or hide list
93
- useEffect(() => {
94
- const showList = quickTabStates?.show_list || [];
95
- const hideList = quickTabStates?.hide_list || [];
96
-
97
- if (showList || hideList) {
98
- // Check if showList is valid (between 1 and 5 items)
99
- const isValidShowList = showList.length > 0 && showList.length <= 5;
100
- const ERROR_CODE = "quick_tab_error";
101
-
102
- if (!isValidShowList) {
103
- const errorMessage = {
104
- type: ERROR_CODE,
105
- message:
106
- showList.length === 0
107
- ? "Quick Lane: Please select at least one item"
108
- : "Quick Lane: Please select no more than 5 items",
109
- };
110
-
111
- // Check if the error is already present in the messages array
112
- const hasQuickTabError = saveButtonError?.messages?.some(
113
- (message) => message.type === ERROR_CODE
114
- );
115
-
116
- // Update the error state
117
-
118
- // Later we can use this to show error message when we will make error logic more simple
119
- // setSaveButtonError((prev) => {
120
- // const otherMessages =
121
- // prev?.messages?.filter((message) => message.type !== ERROR_CODE) ||
122
- // [];
123
-
124
- // return {
125
- // ...prev,
126
- // hasError: true,
127
- // messages: hasQuickTabError
128
- // ? [...prev?.messages]
129
- // : [...otherMessages, errorMessage],
130
- // };
131
- // });
132
- } else {
133
- const hasOtherMessages = saveButtonError?.messages?.some(
134
- (message) => message.type !== ERROR_CODE
135
- );
136
- // Reset error state if the list is valid
137
- // setSaveButtonError((prev) => ({
138
- // ...prev,
139
- // hasError: hasOtherMessages,
140
- // messages:
141
- // prev?.messages?.filter((message) => message.type !== ERROR_CODE) ||
142
- // [],
143
- // }));
144
- }
145
- }
146
- }, [quickTabStates?.hide_list, quickTabStates?.show_list]);
147
-
148
- const sortingOptions = [
149
- { label: "A-Z", value: "asc" },
150
- { label: "Z-A", value: "dsc" },
151
- { label: "Count (Ascending)", value: "count_asc" },
152
- { label: "Count (Descending)", value: "count_dsc" },
153
- { label: "Custom", value: "custom" },
154
- ];
155
-
156
- // Convert show_list/hide_list to FilterValue[] for rendering only
157
- const showListValues = (quickTabStates?.show_list || [])?.map((id: any) => ({
158
- id,
159
- label: id?.charAt(0)?.toUpperCase() + id?.slice(1),
160
- }));
161
- const hideListValues = (quickTabStates?.hide_list || [])?.map((id: any) => ({
162
- id,
163
- label: id?.charAt(0)?.toUpperCase() + id?.slice(1),
164
- }));
165
-
166
- const sensors = useSensors(
167
- useSensor(MouseSensor),
168
- useSensor(TouchSensor),
169
- useSensor(KeyboardSensor)
170
- );
171
-
172
- // Drag and drop logic, update only local state
173
- const handleDragEnd = (event: DragEndEvent) => {
174
- const { active, over } = event;
175
- if (!over) {
176
- return;
177
- }
178
- const currentContainer = active.data.current?.containerId;
179
- const overContainer = over.data.current?.containerId;
180
- if (!currentContainer || !overContainer) return;
181
- if (currentContainer === overContainer) {
182
- // Reorder within the same list
183
- let newShowList = [...(quickTabStates.show_list ?? [])];
184
- let newHideList = [...(quickTabStates.hide_list ?? [])];
185
- if (currentContainer === "list") {
186
- const oldIndex = newHideList.indexOf(String(active.id));
187
- const newIndex = newHideList.indexOf(String(over.id));
188
- if (oldIndex !== -1 && newIndex !== -1) {
189
- const [removed] = newHideList.splice(oldIndex, 1);
190
- newHideList.splice(newIndex, 0, removed);
191
- }
192
- } else {
193
- const oldIndex = newShowList.indexOf(String(active.id));
194
- const newIndex = newShowList.indexOf(String(over.id));
195
- if (oldIndex !== -1 && newIndex !== -1) {
196
- const [removed] = newShowList.splice(oldIndex, 1);
197
- newShowList.splice(newIndex, 0, removed);
198
- }
199
- }
200
-
201
- setSettingsData((prev) => ({
202
- ...prev,
203
- quick_tab: {
204
- ...prev?.quick_tab,
205
- show_list: newShowList,
206
- hide_list: newHideList,
207
- },
208
- }));
209
- } else {
210
- // Move between lists
211
- let newShowList = [...(quickTabStates.show_list ?? [])];
212
- let newHideList = [...(quickTabStates.hide_list ?? [])];
213
- if (currentContainer === "list" && overContainer === "lanes") {
214
- if (newShowList.length >= 5) return; // prevent overflow
215
- // Move from hide to show
216
-
217
- const idx = newHideList.indexOf(String(active.id));
218
- if (idx !== -1) {
219
- newHideList.splice(idx, 1);
220
- newShowList.push(String(active.id));
221
- }
222
- } else if (currentContainer === "lanes" && overContainer === "list") {
223
- // Move from show to hide
224
- const idx = newShowList.indexOf(String(active.id));
225
- if (idx !== -1) {
226
- newShowList.splice(idx, 1);
227
- newHideList.push(String(active.id));
228
- }
229
- }
230
-
231
- setSettingsData((prev) => ({
232
- ...prev,
233
- quick_tab: {
234
- ...prev?.quick_tab,
235
- show_list: newShowList,
236
- hide_list: newHideList,
237
- },
238
- }));
239
- }
240
- };
241
-
242
- const filteredListValues = hideListValues.filter((value: any) =>
243
- value?.label?.toLowerCase().includes(searchTerm.toLowerCase())
244
- );
245
-
246
- // Show All/Hide All logic (local only)
247
- const handleShowAll = () => {
248
- const currentShowList = quickTabStates.show_list || [];
249
- const currentHideList = quickTabStates.hide_list || [];
250
-
251
- const availableSlots = 5 - currentShowList.length;
252
-
253
- if (availableSlots <= 0) return; // Already at limit
254
-
255
- const limitedHideList = currentHideList.slice(0, availableSlots);
256
-
257
- setSettingsData((prev) => ({
258
- ...prev,
259
- quick_tab: {
260
- ...prev?.quick_tab,
261
- show_list: [...currentShowList, ...limitedHideList],
262
- hide_list: currentHideList.filter(
263
- (item: string) => !limitedHideList.includes(item)
264
- ),
265
- },
266
- }));
267
- };
268
-
269
- const handleHideAll = () => {
270
- setSettingsData((prev) => ({
271
- ...prev,
272
- quick_tab: {
273
- ...prev?.quick_tab,
274
- hide_list: [
275
- ...(prev?.quick_tab?.hide_list || []),
276
- ...(prev?.quick_tab?.show_list || []),
277
- ],
278
- show_list: [],
279
- },
280
- }));
281
- };
282
-
283
- // Checkbox logic (local only)
284
- const handleShowSubLaneChange = (e: React.ChangeEvent<HTMLInputElement>) => {
285
- setSettingsData((prev) => ({
286
- ...prev,
287
- quick_tab: {
288
- ...prev?.quick_tab,
289
- showSubLane: e.target.checked,
290
- },
291
- }));
292
- };
293
-
294
- const handleShowColorColumnsChange = (
295
- e: React.ChangeEvent<HTMLInputElement>
296
- ) => {
297
- setSettingsData((prev) => ({
298
- ...prev,
299
- quick_tab: {
300
- ...prev?.quick_tab,
301
- showColorColumns: e.target.checked,
302
- },
303
- }));
304
- };
305
-
306
- const handleItemToggle = (itemId: string, fromContainerId: string) => {
307
- const toShowList = [...(quickTabStates.show_list ?? [])];
308
- const toHideList = [...(quickTabStates.hide_list ?? [])];
309
-
310
- if (fromContainerId === "list") {
311
- if (toShowList.length >= 5) return; // prevent overflow
312
- // Move from hide_list to show_list
313
- const index = toHideList.indexOf(itemId);
314
- if (index > -1) {
315
- toHideList.splice(index, 1);
316
- toShowList.push(itemId);
317
- }
318
- } else if (fromContainerId === "lanes") {
319
- // Move from show_list to hide_list
320
- const index = toShowList.indexOf(itemId);
321
- if (index > -1) {
322
- toShowList.splice(index, 1);
323
- toHideList.push(itemId);
324
- }
325
- }
326
-
327
- setSettingsData((prev) => ({
328
- ...prev,
329
- quick_tab: {
330
- ...prev?.quick_tab,
331
- show_list: toShowList,
332
- hide_list: toHideList,
333
- },
334
- }));
335
- };
336
-
337
- const enableDND = quickTabStates?.sorting === "custom" ? true : false;
338
-
339
- return (
340
- <Box
341
- sx={{
342
- display: "flex",
343
- flexDirection: "column",
344
- // gap: "0.5rem",
345
- height: "100%",
346
- }}
347
- >
348
- <Typography variant="caption" sx={TabsStyles.mainTabsHeader}>
349
- *Quick filter settings will be reflected in vertical lanes
350
- </Typography>
351
- <Box>
352
- <Grid sx={{ position: "relative" }} container>
353
- <Grid size={12}>
354
- <Box>
355
- <Grid sx={TabsStyles.mainTabDropdown} size={6}>
356
- <FormControl sx={TabsStyles.mainTabSelect} size="small">
357
- <Select
358
- value={quickTabStates?.attribute || ""}
359
- onChange={(e) =>
360
- setSettingsData((prev) => ({
361
- ...prev,
362
- quick_tab: {
363
- ...prev?.quick_tab,
364
- attribute: e.target.value,
365
- },
366
- }))
367
- }
368
- displayEmpty
369
- renderValue={(selected) => {
370
- if (!selected) {
371
- return <em>Select Attribute</em>;
372
- }
373
- return selected;
374
- }}
375
- >
376
- {LANE_SELECTS?.map((lane: any) => (
377
- <MenuItem key={lane?.key} value={lane?.value}>
378
- {lane?.value}
379
- </MenuItem>
380
- ))}
381
- </Select>
382
- </FormControl>
383
- <FormControl
384
- sx={TabsStyles.selectDropdownSeparator}
385
- size="small"
386
- >
387
- <Select
388
- value={quickTabStates?.sorting || "asc"}
389
- onChange={(e) =>
390
- setSettingsData((prev) => ({
391
- ...prev,
392
- quick_tab: {
393
- ...prev?.quick_tab,
394
- sorting: e.target.value,
395
- },
396
- }))
397
- }
398
- displayEmpty
399
- renderValue={(selected) => {
400
- if (!selected) {
401
- return <em>Sort by</em>;
402
- }
403
- const option = sortingOptions.find(
404
- (opt) => opt.value === selected
405
- );
406
- return option?.label || selected;
407
- }}
408
- >
409
- {sortingOptions?.map((option) => (
410
- <MenuItem key={option?.value} value={option?.value}>
411
- {option?.label}
412
- </MenuItem>
413
- ))}
414
- </Select>
415
- </FormControl>
416
- </Grid>
417
- </Box>
418
- </Grid>
419
- <Grid>
420
- {/* <Alert
421
- severity="info"
422
- sx={{
423
- fontSize: "12px",
424
- color: "#088AB2",
425
- }}
426
- >
427
- Please select at least 1 and at most 5 values to display as lanes.
428
- </Alert> */}
429
- </Grid>
430
- <DndContext
431
- sensors={sensors}
432
- collisionDetection={closestCenter}
433
- onDragEnd={handleDragEnd}
434
- >
435
- <Grid sx={{ mt: 2 }} container spacing={2} size={12}>
436
- <ListingValues
437
- buttonText="Show All"
438
- onClick={handleShowAll}
439
- headerText="List of Values"
440
- filteredValues={filteredListValues}
441
- searchTerm={searchTerm}
442
- setSearchTerm={setSearchTerm}
443
- containerId="list"
444
- tabsApiDataLoading={tabsApiDataLoading}
445
- onItemToggle={handleItemToggle}
446
- enableDragAndDrop={enableDND}
447
- />
448
- <ListingValues
449
- buttonText="Hide All"
450
- onClick={handleHideAll}
451
- headerText="View as Lanes"
452
- filteredValues={showListValues}
453
- containerId="lanes"
454
- // tabsApiDataLoading={tabsApiDataLoading}
455
- onItemToggle={handleItemToggle}
456
- enableDragAndDrop={enableDND}
457
- // AlertComponenet={
458
- // <InfoAlert
459
- // message="Please select at least 1 and at most 5 values to display as
460
- // lanes."
461
- // width={"49%"}
462
- // position="absolute"
463
- // color="#088AB2"
464
- // top={10}
465
- // zIndex={1}
466
- // />
467
- // }
468
- />
469
- </Grid>
470
- </DndContext>
471
- <Grid size={12}>
472
- <Box sx={TabsStyles.checkboxStyle}>
473
- <FormControlLabel
474
- control={
475
- <Checkbox
476
- checked={quickTabStates?.showSubLane || false}
477
- onChange={handleShowSubLaneChange}
478
- size="small"
479
- sx={{
480
- "&.Mui-checked": {
481
- color: "#7A5AF8",
482
- },
483
- }}
484
- />
485
- }
486
- label="Show Sublane"
487
- />
488
- <FormControlLabel
489
- control={
490
- <Checkbox
491
- checked={quickTabStates?.showColorColumns || false}
492
- onChange={handleShowColorColumnsChange}
493
- size="small"
494
- sx={{
495
- "&.Mui-checked": {
496
- color: "#7A5AF8",
497
- },
498
- }}
499
- />
500
- }
501
- label="Show Color columns"
502
- />
503
- </Box>
504
- </Grid>
505
- </Grid>
506
- </Box>
507
- </Box>
508
- );
509
- };
510
-
511
- export default GroupBy;