rez-table-listing-mui 1.0.48 → 1.0.50

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.
Files changed (36) hide show
  1. package/dist/index.d.ts +7 -1
  2. package/dist/index.js +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/package.json +1 -1
  5. package/src/App.tsx +81 -24
  6. package/src/assets/svg.tsx +5 -5
  7. package/src/components/filter/components/attributes-filter.tsx +78 -52
  8. package/src/components/filter/components/forms/components/Date.tsx +178 -109
  9. package/src/components/filter/components/forms/components/Dropdown.tsx +36 -3
  10. package/src/components/filter/components/forms/components/Filter-criteria.tsx +3 -3
  11. package/src/components/filter/components/forms/components/Multi-Select.tsx +62 -34
  12. package/src/components/filter/components/forms/index.tsx +29 -7
  13. package/src/components/filter/components/main-filter.tsx +3 -0
  14. package/src/components/filter/components/saved-edit-filter.tsx +6 -0
  15. package/src/components/filter/components/saved-filter.tsx +66 -9
  16. package/src/components/filter/components/search/index.tsx +18 -1
  17. package/src/components/filter/index.tsx +21 -6
  18. package/src/components/filter/style.ts +1 -1
  19. package/src/components/index.scss +1 -1
  20. package/src/components/table-settings/common/info-alert.tsx +37 -0
  21. package/src/components/table-settings/common/listing-values.tsx +102 -54
  22. package/src/components/table-settings/components/column.tsx +206 -173
  23. package/src/components/table-settings/components/quick-tab.tsx +281 -153
  24. package/src/components/table-settings/components/sorting.tsx +135 -120
  25. package/src/components/table-settings/components/toggle-button-switch.tsx +2 -2
  26. package/src/components/table-settings/index.tsx +3 -5
  27. package/src/components/table-settings/style.ts +1 -0
  28. package/src/components/topbar/index.tsx +3 -1
  29. package/src/libs/hooks/useCraftTable.tsx +5 -0
  30. package/src/libs/hooks/useElementWidth.tsx +2 -2
  31. package/src/libs/hooks/useEntityTableAPI.tsx +1 -16
  32. package/src/libs/utils/apiColumn.ts +1 -11
  33. package/src/libs/utils/common.ts +4 -3
  34. package/src/types/filter-settings.ts +11 -0
  35. package/src/types/filter.ts +1 -2
  36. package/src/types/table-options.ts +2 -0
@@ -23,11 +23,11 @@ import {
23
23
  DragEndEvent,
24
24
  } from "@dnd-kit/core";
25
25
  import {
26
- QuickTabSortingType,
26
+ QuickTabConfigProps,
27
27
  SettingsQuickTabProps,
28
28
  } from "../../../types/filter-settings";
29
29
  import { TabsStyles } from "../style";
30
- import { ColumnItem, TabData } from "./column";
30
+ import InfoAlert from "../common/info-alert";
31
31
 
32
32
  const QuickTab = ({
33
33
  filterSettingStates,
@@ -35,116 +35,207 @@ const QuickTab = ({
35
35
  tabsApiData,
36
36
  tabsApiDataLoading,
37
37
  }: SettingsQuickTabProps) => {
38
- const {
39
- quickTabStates,
40
- setQuickTabStates,
41
- settingsData,
42
- setColumnTabState,
43
- saveButtonError,
44
- setSaveButtonError,
45
- } = filterSettingStates;
38
+ const { settingsData, setSettingsData, saveButtonError, setSaveButtonError } =
39
+ filterSettingStates;
46
40
 
47
41
  const [searchTerm, setSearchTerm] = useState<string>("");
42
+ const [currentQuickAttribute, setCurrentQuickAttribute] = useState<string>(
43
+ settingsData?.quick_tab?.attribute || ""
44
+ );
45
+
46
+ const quickTabStates = settingsData?.quick_tab as QuickTabConfigProps;
48
47
 
48
+ // In case there is no quick tab state from API
49
49
  useEffect(() => {
50
- // if Tab changes i dont want to reset the show list and hide list in tab change the api musnt trigger for the show list and hide list
51
-
52
- if (!Object.entries(quickTabStates).length) {
53
- // if (quickTabStates && quickTabStates.show_list?.length) return;
54
- setQuickTabStates({
55
- attribute: columnsData?.column_list?.filter(
56
- (item) => item.datasource_list
57
- )[0]?.attribute_key,
58
- sorting: sortingOptions[0]?.value as QuickTabSortingType,
59
- hide_list: [],
60
- show_list: [],
61
- isAllSelected: true,
62
- isCombineOther: false,
63
- });
64
- }
50
+ const stateToArray =
51
+ (quickTabStates && Object.entries(quickTabStates)) || [];
52
+ const isEmptyState = stateToArray.length ? false : true;
65
53
 
66
- if (settingsData?.quick_tab?.attribute !== quickTabStates?.attribute) {
67
- setQuickTabStates((prev) => ({
54
+ if (isEmptyState) {
55
+ setSettingsData((prev) => ({
68
56
  ...prev,
69
- hide_list: tabsApiData, // All data goes to hide_list initially
70
- show_list: [], // Empty the show_list when attribute/sorting changes
57
+ quick_tab: {
58
+ ...prev?.quick_tab,
59
+ attribute: columnsData?.column_list?.filter(
60
+ (item) => item.datasource_list
61
+ )[0]?.attribute_key,
62
+ sorting: "asc",
63
+ },
71
64
  }));
72
- } else {
73
- setQuickTabStates((prev) => ({
65
+ }
66
+ }, [columnsData]);
67
+
68
+ // When user changes attribute
69
+ useEffect(() => {
70
+ if (currentQuickAttribute === settingsData?.quick_tab?.attribute) return;
71
+
72
+ if (tabsApiData?.length) {
73
+ setSettingsData((prev) => ({
74
74
  ...prev,
75
- hide_list: settingsData?.quick_tab?.hide_list,
76
- show_list: settingsData?.quick_tab?.show_list,
75
+ quick_tab: {
76
+ ...prev?.quick_tab,
77
+ hide_list: tabsApiData,
78
+ show_list: [],
79
+ },
77
80
  }));
81
+
82
+ setCurrentQuickAttribute(settingsData.quick_tab?.attribute || "");
78
83
  }
79
- }, [columnsData.column_list, tabsApiData]);
84
+ }, [tabsApiData]);
80
85
 
81
- // When quickTabState show_list or hide_list changes, update the columnTabState
86
+ // Validation when user changes show list or hide list
82
87
  useEffect(() => {
83
- if (Object.entries(settingsData?.column || {}).length) {
84
- const mappedColumns: ColumnItem[] =
85
- columnsData?.column_list?.map((column) => ({
86
- label: column?.name,
87
- value: column?.attribute_key,
88
- })) || [];
89
- //Later changed TabData to interface from filter settings types file
90
- const mappedTabs: TabData[] =
91
- quickTabStates?.show_list?.map((tab) => ({
92
- tab_name: tab,
93
- show_list: mappedColumns,
94
- hide_list: [],
95
- })) || [];
96
-
97
- if (settingsData?.column?.isDefault) {
98
- setColumnTabState((prev) => ({
99
- ...prev,
100
- show_list: mappedColumns,
101
- hide_list: [],
102
- }));
88
+ const showList = quickTabStates?.show_list || [];
89
+ const hideList = quickTabStates?.hide_list || [];
90
+
91
+ if (showList || hideList) {
92
+ // Check if showList is valid (between 1 and 5 items)
93
+ const isValidShowList = showList.length > 0 && showList.length <= 5;
94
+ const ERROR_CODE = "quick_tab_error";
95
+
96
+ if (!isValidShowList) {
97
+ const errorMessage = {
98
+ type: ERROR_CODE,
99
+ message:
100
+ showList.length === 0
101
+ ? "Quick Tab: Please select at least one item"
102
+ : "Quick Tab: Please select no more than 5 items",
103
+ };
104
+
105
+ // Check if the error is already present in the messages array
106
+ const hasQuickTabError = saveButtonError?.messages?.some(
107
+ (message) => message.type === ERROR_CODE
108
+ );
109
+
110
+ // Update the error state
111
+ setSaveButtonError((prev) => {
112
+ const otherMessages =
113
+ prev?.messages?.filter((message) => message.type !== ERROR_CODE) ||
114
+ [];
115
+
116
+ return {
117
+ ...prev,
118
+ hasError: true,
119
+ messages: hasQuickTabError
120
+ ? [...prev?.messages]
121
+ : [...otherMessages, errorMessage],
122
+ };
123
+ });
103
124
  } else {
104
- setColumnTabState((prev) => ({
125
+ const hasOtherMessages = saveButtonError?.messages?.some(
126
+ (message) => message.type !== ERROR_CODE
127
+ );
128
+ // Reset error state if the list is valid
129
+ setSaveButtonError((prev) => ({
105
130
  ...prev,
106
- tabs: mappedTabs,
131
+ hasError: hasOtherMessages,
132
+ messages:
133
+ prev?.messages?.filter((message) => message.type !== ERROR_CODE) ||
134
+ [],
107
135
  }));
108
136
  }
109
137
  }
138
+ }, [quickTabStates?.hide_list, quickTabStates?.show_list]);
110
139
 
111
- // check for error
112
- const hasInvalidValidShowList =
113
- quickTabStates.show_list &&
114
- (quickTabStates.show_list?.length === 0 ||
115
- quickTabStates.show_list.length >= 5);
116
-
117
- if (hasInvalidValidShowList) {
118
- // Check if error is already in the state to avoid duplication
119
- const errorMessage = {
120
- type: "quick_tab_error",
121
- message:
122
- "Quick Tab : View as Tabs should have at least 1 and at most 5 tabs.",
123
- };
124
- const hasQuickTabError = saveButtonError?.messages?.some(
125
- (message) => message.type === "quick_tab_error"
126
- );
127
-
128
- if (!hasQuickTabError) {
129
- setSaveButtonError((prev) => ({
130
- ...prev,
131
- hasError: true,
132
- messages: [...(prev?.messages || []), errorMessage], // Only add if it doesn't exist
133
- }));
134
- }
135
- } else {
136
- const otherMessages =
137
- saveButtonError?.messages?.filter(
138
- (message) => message.type !== "quick_tab_error"
139
- ) || [];
140
+ // useEffect(() => {
141
+ // // if Tab changes i dont want to reset the show list and hide list in tab change the api musnt trigger for the show list and hide list
140
142
 
141
- setSaveButtonError((prev) => ({
142
- ...prev,
143
- hasError: otherMessages.length > 0,
144
- messages: otherMessages,
145
- }));
146
- }
147
- }, [quickTabStates.show_list, quickTabStates.hide_list]);
143
+ // if (!Object.entries(quickTabStates).length) {
144
+ // // if (quickTabStates && quickTabStates.show_list?.length) return;
145
+ // setQuickTabStates({
146
+ // attribute: columnsData?.column_list?.filter(
147
+ // (item) => item.datasource_list
148
+ // )[0]?.attribute_key,
149
+ // sorting: sortingOptions[0]?.value as QuickTabSortingType,
150
+ // hide_list: [],
151
+ // show_list: [],
152
+ // isAllSelected: true,
153
+ // isCombineOther: false,
154
+ // });
155
+ // }
156
+
157
+ // if (settingsData?.quick_tab?.attribute !== quickTabStates?.attribute) {
158
+ // setQuickTabStates((prev) => ({
159
+ // ...prev,
160
+ // hide_list: tabsApiData, // All data goes to hide_list initially
161
+ // show_list: [], // Empty the show_list when attribute/sorting changes
162
+ // }));
163
+ // } else {
164
+ // setQuickTabStates((prev) => ({
165
+ // ...prev,
166
+ // hide_list: settingsData?.quick_tab?.hide_list,
167
+ // show_list: settingsData?.quick_tab?.show_list,
168
+ // }));
169
+ // }
170
+ // }, [columnsData.column_list, tabsApiData]);
171
+
172
+ // // When quickTabState show_list or hide_list changes, update the columnTabState
173
+ // useEffect(() => {
174
+ // if (Object.entries(settingsData?.column || {}).length) {
175
+ // const mappedColumns: ColumnItem[] =
176
+ // columnsData?.column_list?.map((column) => ({
177
+ // label: column?.name,
178
+ // value: column?.attribute_key,
179
+ // })) || [];
180
+ // //Later changed TabData to interface from filter settings types file
181
+ // const mappedTabs: TabData[] =
182
+ // quickTabStates?.show_list?.map((tab) => ({
183
+ // tab_name: tab,
184
+ // show_list: mappedColumns,
185
+ // hide_list: [],
186
+ // })) || [];
187
+
188
+ // if (settingsData?.column?.isDefault) {
189
+ // setColumnTabState((prev) => ({
190
+ // ...prev,
191
+ // show_list: mappedColumns,
192
+ // hide_list: [],
193
+ // }));
194
+ // } else {
195
+ // setColumnTabState((prev) => ({
196
+ // ...prev,
197
+ // tabs: mappedTabs,
198
+ // }));
199
+ // }
200
+ // }
201
+
202
+ // // check for error
203
+ // const hasInvalidValidShowList =
204
+ // quickTabStates.show_list &&
205
+ // (quickTabStates.show_list?.length === 0 ||
206
+ // quickTabStates.show_list.length >= 5);
207
+
208
+ // if (hasInvalidValidShowList) {
209
+ // // Check if error is already in the state to avoid duplication
210
+ // const errorMessage = {
211
+ // type: "quick_tab_error",
212
+ // message:
213
+ // "Quick Tab : View as Tabs should have at least 1 and at most 5 tabs.",
214
+ // };
215
+ // const hasQuickTabError = saveButtonError?.messages?.some(
216
+ // (message) => message.type === "quick_tab_error"
217
+ // );
218
+
219
+ // if (!hasQuickTabError) {
220
+ // setSaveButtonError((prev) => ({
221
+ // ...prev,
222
+ // hasError: true,
223
+ // messages: [...(prev?.messages || []), errorMessage], // Only add if it doesn't exist
224
+ // }));
225
+ // }
226
+ // } else {
227
+ // const otherMessages =
228
+ // saveButtonError?.messages?.filter(
229
+ // (message) => message.type !== "quick_tab_error"
230
+ // ) || [];
231
+
232
+ // setSaveButtonError((prev) => ({
233
+ // ...prev,
234
+ // hasError: otherMessages.length > 0,
235
+ // messages: otherMessages,
236
+ // }));
237
+ // }
238
+ // }, [quickTabStates.show_list, quickTabStates.hide_list]);
148
239
 
149
240
  // useEffect(() => {
150
241
  // setQuickTabStates((prev) => ({
@@ -185,11 +276,11 @@ const QuickTab = ({
185
276
  ];
186
277
 
187
278
  // Convert show_list/hide_list to FilterValue[] for rendering only
188
- const showListValues = (quickTabStates.show_list || [])?.map((id) => ({
279
+ const showListValues = (quickTabStates?.show_list || [])?.map((id) => ({
189
280
  id,
190
281
  label: id?.charAt(0)?.toUpperCase() + id?.slice(1),
191
282
  }));
192
- const hideListValues = (quickTabStates.hide_list || []).map((id) => ({
283
+ const hideListValues = (quickTabStates?.hide_list || []).map((id) => ({
193
284
  id,
194
285
  label: id?.charAt(0)?.toUpperCase() + id?.slice(1),
195
286
  }));
@@ -228,11 +319,15 @@ const QuickTab = ({
228
319
  newShowList.splice(newIndex, 0, removed);
229
320
  }
230
321
  }
231
- setQuickTabStates({
232
- ...quickTabStates,
233
- show_list: newShowList,
234
- hide_list: newHideList,
235
- });
322
+
323
+ setSettingsData((prev) => ({
324
+ ...prev,
325
+ quick_tab: {
326
+ ...prev.quick_tab,
327
+ show_list: newShowList,
328
+ hide_list: newHideList,
329
+ },
330
+ }));
236
331
  } else {
237
332
  // Move between lists
238
333
  let newShowList = [...(quickTabStates.show_list ?? [])];
@@ -254,11 +349,15 @@ const QuickTab = ({
254
349
  newHideList.push(String(active.id));
255
350
  }
256
351
  }
257
- setQuickTabStates({
258
- ...quickTabStates,
259
- show_list: newShowList,
260
- hide_list: newHideList,
261
- });
352
+
353
+ setSettingsData((prev) => ({
354
+ ...prev,
355
+ quick_tab: {
356
+ ...prev.quick_tab,
357
+ show_list: newShowList,
358
+ hide_list: newHideList,
359
+ },
360
+ }));
262
361
  }
263
362
  };
264
363
 
@@ -277,42 +376,52 @@ const QuickTab = ({
277
376
 
278
377
  const limitedHideList = currentHideList.slice(0, availableSlots);
279
378
 
280
- setQuickTabStates({
281
- ...quickTabStates,
282
- show_list: [...currentShowList, ...limitedHideList],
283
- hide_list: currentHideList.filter(
284
- (item) => !limitedHideList.includes(item)
285
- ),
286
- });
379
+ setSettingsData((prev) => ({
380
+ ...prev,
381
+ quick_tab: {
382
+ ...prev.quick_tab,
383
+ show_list: [...currentShowList, ...limitedHideList],
384
+ hide_list: currentHideList.filter(
385
+ (item) => !limitedHideList.includes(item)
386
+ ),
387
+ },
388
+ }));
287
389
  };
288
390
 
289
391
  const handleHideAll = () => {
290
- setQuickTabStates({
291
- ...quickTabStates,
292
- hide_list: [
293
- ...(quickTabStates.hide_list || []),
294
- ...(quickTabStates.show_list || []),
295
- ],
296
- show_list: [],
297
- });
392
+ setSettingsData((prev) => ({
393
+ ...prev,
394
+ quick_tab: {
395
+ ...prev.quick_tab,
396
+ hide_list: [
397
+ ...(prev?.quick_tab?.hide_list || []),
398
+ ...(prev?.quick_tab?.show_list || []),
399
+ ],
400
+ show_list: [],
401
+ },
402
+ }));
298
403
  };
299
404
 
300
405
  // Checkbox logic (local only)
301
406
  const handleShowAllTabChange = (e: React.ChangeEvent<HTMLInputElement>) => {
302
- // setShowAllTab(e.target.checked);
303
- setQuickTabStates({
304
- ...quickTabStates,
305
- isAllSelected: e.target.checked,
306
- });
407
+ setSettingsData((prev) => ({
408
+ ...prev,
409
+ quick_tab: {
410
+ ...prev.quick_tab,
411
+ isAllSelected: e.target.checked,
412
+ },
413
+ }));
307
414
  };
308
415
  const handleCombineOtherTabChange = (
309
416
  e: React.ChangeEvent<HTMLInputElement>
310
417
  ) => {
311
- // setCombineOtherTab(e.target.checked);
312
- setQuickTabStates({
313
- ...quickTabStates,
314
- isCombineOther: e.target.checked,
315
- });
418
+ setSettingsData((prev) => ({
419
+ ...prev,
420
+ quick_tab: {
421
+ ...prev.quick_tab,
422
+ isCombineOther: e.target.checked,
423
+ },
424
+ }));
316
425
  };
317
426
 
318
427
  const handleItemToggle = (itemId: string, fromContainerId: string) => {
@@ -336,13 +445,18 @@ const QuickTab = ({
336
445
  }
337
446
  }
338
447
 
339
- setQuickTabStates({
340
- ...quickTabStates,
341
- show_list: toShowList,
342
- hide_list: toHideList,
343
- });
448
+ setSettingsData((prev) => ({
449
+ ...prev,
450
+ quick_tab: {
451
+ ...prev.quick_tab,
452
+ show_list: toShowList,
453
+ hide_list: toHideList,
454
+ },
455
+ }));
344
456
  };
345
457
 
458
+ const enableDND = quickTabStates?.sorting === "custom" ? true : false;
459
+
346
460
  return (
347
461
  <Box
348
462
  sx={{
@@ -356,7 +470,7 @@ const QuickTab = ({
356
470
  *Quick filter settings will be reflected in horizontal tabs
357
471
  </Typography>
358
472
  <Box>
359
- <Grid container>
473
+ <Grid sx={{ position: "relative" }} container>
360
474
  <Grid size={12}>
361
475
  <Box>
362
476
  <Grid sx={TabsStyles.mainTabDropdown} size={6}>
@@ -364,9 +478,12 @@ const QuickTab = ({
364
478
  <Select
365
479
  value={quickTabStates?.attribute || ""}
366
480
  onChange={(e) =>
367
- setQuickTabStates((prevState) => ({
368
- ...prevState,
369
- attribute: e.target.value,
481
+ setSettingsData((prev) => ({
482
+ ...prev,
483
+ quick_tab: {
484
+ ...prev?.quick_tab,
485
+ attribute: e.target.value,
486
+ },
370
487
  }))
371
488
  }
372
489
  >
@@ -387,12 +504,15 @@ const QuickTab = ({
387
504
  size="small"
388
505
  >
389
506
  <Select
390
- value={quickTabStates.sorting || "asc"}
507
+ value={quickTabStates?.sorting || "asc"}
391
508
  onChange={(e) =>
392
- setQuickTabStates({
393
- ...quickTabStates,
394
- sorting: e.target.value,
395
- })
509
+ setSettingsData((prev) => ({
510
+ ...prev,
511
+ quick_tab: {
512
+ ...prev?.quick_tab,
513
+ sorting: e.target.value,
514
+ },
515
+ }))
396
516
  }
397
517
  >
398
518
  {sortingOptions.map((option) => (
@@ -405,13 +525,8 @@ const QuickTab = ({
405
525
  </Grid>
406
526
  </Box>
407
527
  </Grid>
408
- <Grid
409
- sx={{
410
- marginLeft: "33.2rem",
411
- }}
412
- size={12}
413
- >
414
- <Alert
528
+ <Grid>
529
+ {/* <Alert
415
530
  severity="info"
416
531
  sx={{
417
532
  fontSize: "12px",
@@ -419,14 +534,14 @@ const QuickTab = ({
419
534
  }}
420
535
  >
421
536
  Please select at least 1 and at most 5 values to display as tabs.
422
- </Alert>
537
+ </Alert> */}
423
538
  </Grid>
424
539
  <DndContext
425
540
  sensors={sensors}
426
541
  collisionDetection={closestCenter}
427
542
  onDragEnd={handleDragEnd}
428
543
  >
429
- <Grid container spacing={2} size={12}>
544
+ <Grid sx={{ mt: 2 }} container spacing={2} size={12}>
430
545
  <ListingValues
431
546
  buttonText="Show All"
432
547
  onClick={handleShowAll}
@@ -437,6 +552,7 @@ const QuickTab = ({
437
552
  containerId="list"
438
553
  tabsApiDataLoading={tabsApiDataLoading}
439
554
  onItemToggle={handleItemToggle}
555
+ enableDragAndDrop={enableDND}
440
556
  />
441
557
  <ListingValues
442
558
  buttonText="Hide All"
@@ -446,6 +562,18 @@ const QuickTab = ({
446
562
  containerId="tabs"
447
563
  // tabsApiDataLoading={tabsApiDataLoading}
448
564
  onItemToggle={handleItemToggle}
565
+ enableDragAndDrop={enableDND}
566
+ AlertComponenet={
567
+ <InfoAlert
568
+ message="Please select at least 1 and at most 5 values to display as
569
+ tabs."
570
+ width={"49%"}
571
+ position="absolute"
572
+ color="#088AB2"
573
+ top={10}
574
+ zIndex={1}
575
+ />
576
+ }
449
577
  />
450
578
  </Grid>
451
579
  </DndContext>