rez-table-listing-mui 1.3.44 → 1.3.45

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 (41) hide show
  1. package/dist/index.d.ts +70 -9
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +1 -1
  5. package/dist/index.mjs.map +1 -1
  6. package/package.json +1 -1
  7. package/src/listing/components/common/saved-filter-modal/index.tsx +517 -0
  8. package/src/listing/components/filter/components/attributes-filter.tsx +2 -2
  9. package/src/listing/components/filter/components/forms/components/Dropdown.tsx +2 -2
  10. package/src/listing/components/filter/components/forms/components/Filter-criteria.tsx +9 -7
  11. package/src/listing/components/filter/components/forms/components/Textfield.tsx +2 -4
  12. package/src/listing/components/filter/components/forms/components/filter-criteria-list.tsx +1 -0
  13. package/src/listing/components/filter/components/forms/index.tsx +23 -14
  14. package/src/listing/components/filter/components/forms/utils/filter-date-input-resolver.tsx +3 -3
  15. package/src/listing/components/filter/components/main-filter.tsx +6 -6
  16. package/src/listing/components/filter/components/saved-edit-filter.tsx +5 -3
  17. package/src/listing/components/filter/components/saved-filter.tsx +300 -124
  18. package/src/listing/components/filter/components/search/index.tsx +1 -0
  19. package/src/listing/components/filter/components/single-filter-rendering.tsx +3 -3
  20. package/src/listing/components/filter/index.tsx +130 -5
  21. package/src/listing/components/index-table.tsx +9 -0
  22. package/src/listing/components/login/index.tsx +3 -6
  23. package/src/listing/components/table-dnd.tsx +6 -0
  24. package/src/listing/components/table-head-dnd-cell.tsx +7 -0
  25. package/src/listing/components/table-head-popover.tsx +24 -3
  26. package/src/listing/components/table-head.tsx +10 -0
  27. package/src/listing/components/table-settings/components/column.tsx +85 -26
  28. package/src/listing/components/table-settings/components/quick-tab.tsx +395 -77
  29. package/src/listing/components/table-settings/components/sorting.tsx +60 -20
  30. package/src/listing/components/table-settings/index.tsx +12 -2
  31. package/src/listing/components/table.tsx +6 -0
  32. package/src/listing/libs/hooks/useEntityTableAPI.tsx +20 -5
  33. package/src/listing/libs/utils/apiColumn.ts +8 -3
  34. package/src/listing/libs/utils/common.ts +2 -1
  35. package/src/listing/libs/utils/hydrate-saved-filters.ts +2 -2
  36. package/src/listing/types/common.ts +1 -0
  37. package/src/listing/types/filter-settings.ts +8 -2
  38. package/src/listing/types/filter.ts +51 -3
  39. package/src/listing/types/table.ts +9 -0
  40. package/src/view/FIlterWrapper.tsx +15 -0
  41. package/src/view/ListingView.tsx +179 -63
@@ -10,14 +10,20 @@ import { ENTITY_TYPE, MAPPED_ENTITY_TYPE } from "../listing/libs/utils/common";
10
10
  import {
11
11
  useCommonFilterDropdownAPI,
12
12
  useEntityTableAPI,
13
+ useGetFilterEntityListAndCriteria,
13
14
  useGetLayoutAttributes,
14
15
  useGetOperationList,
16
+ useGetSettingsColumnAttributes,
17
+ useGetSettingsDataAPI,
15
18
  useSaveSettingsDataAPI,
16
19
  useSettingsDropDownAPI,
17
20
  } from "../listing/libs/hooks/useEntityTableAPI";
18
21
  import { entityTableMetaMaster } from "../listing/libs/utils/apiColumn";
19
22
  import { ColumnDef } from "@tanstack/react-table";
20
- import { SettingsDataProps } from "../listing/types/filter-settings";
23
+ import {
24
+ ColumnTabConfigProps,
25
+ SettingsDataProps,
26
+ } from "../listing/types/filter-settings";
21
27
  import TableWrapper from "../listing/components/index-table";
22
28
  import { TableTabs } from "../listing/components/tabs";
23
29
  import { QuickFilterSettings } from "../listing/components/table-settings";
@@ -27,6 +33,7 @@ import { hydrateSavedFilters } from "../listing/libs/utils/hydrate-saved-filters
27
33
  import { useGetNavigationLayoutAPI } from "../listing/libs/hooks/useGetNavigationLayoutAPI";
28
34
  import { useQueryClient } from "@tanstack/react-query";
29
35
  import { Box, CircularProgress, Typography } from "@mui/material";
36
+ import { ColumnItem } from "../listing/components/table-settings/components/column";
30
37
 
31
38
  function ListingView() {
32
39
  // const [mockLoading, setMockLoading] = useState<boolean>(true);
@@ -54,16 +61,27 @@ function ListingView() {
54
61
  : metaQuery?.data?.default_filter?.value
55
62
  );
56
63
  const { saveSettingsDataMutation } = useSaveSettingsDataAPI(ENTITY_TYPE);
64
+ const { settingsColumnAttributes } =
65
+ useGetSettingsColumnAttributes(ENTITY_TYPE);
57
66
  const { operationList } = useGetOperationList();
58
67
 
59
68
  const { layoutAttributes: quickTabAttributes } = useGetLayoutAttributes({
60
69
  entity_type: ENTITY_TYPE,
61
- element_type: "select",
70
+ data_type: "select",
62
71
  });
63
72
 
64
73
  const { layoutAttributes: sortingTabAttributes } = useGetLayoutAttributes({
65
74
  entity_type: ENTITY_TYPE,
66
75
  });
76
+ const isColumnDefault =
77
+ filterSettingStates?.columnTabState?.isDefault || false;
78
+ const activeTabIndex = filterSettingStates?.columnTabState?.tabs?.findIndex(
79
+ (tab) =>
80
+ tab?.tab_name?.value == selectedTab ||
81
+ tab?.tab_name?.label?.toLowerCase() == selectedTab?.toLowerCase()
82
+ );
83
+ const settingsColumnState = (filterSettingStates?.settingsData?.column ||
84
+ {}) as ColumnTabConfigProps;
67
85
 
68
86
  // const { dropdownData } = useCommonDropdownAPI(
69
87
  // dropdownColumnList || metaQuery.data.column_list
@@ -80,77 +98,84 @@ function ListingView() {
80
98
  const queryClient = useQueryClient();
81
99
  const { data: getSettingsAPIData } = useGetNavigationLayoutAPI(ENTITY_TYPE);
82
100
 
83
- useEffect(() => {
84
- // setTimeout(() => {
85
- // setMockLoading(false);
86
- // }, 1000);
87
-
88
- const fetchMeta = async () => {
89
- try {
90
- const { res: allColumns } = await entityTableMetaMaster(ENTITY_TYPE);
91
-
92
- const savedColumnSettings = filterSettingStates.settingsData?.column;
93
-
94
- const getOrderedColumns = (
95
- showList: { value: string }[],
96
- filteredColumns: any[]
97
- ) => {
98
- // Build ordered columns using showList and filteredColumns
99
- return showList
100
- ?.map((showItem) => {
101
- return filteredColumns.find(
102
- (col) => col?.accessorKey === showItem?.value
103
- );
104
- })
105
- ?.filter((col): col is ColumnDef<any> => col !== undefined); // Ensure non-undefined columns are returned
106
- };
107
-
108
- if (
109
- savedColumnSettings &&
110
- !savedColumnSettings.isDefault &&
111
- savedColumnSettings.tabs
112
- ) {
113
- // Tab-wise view: find the active tab and use its show_list
114
- const activeTabSettings = savedColumnSettings.tabs.find(
115
- (tab) => tab.tab_name.toLowerCase() === selectedTab.toLowerCase()
116
- );
101
+ const fetchMeta = async () => {
102
+ try {
103
+ const { res: allColumns } = await entityTableMetaMaster(ENTITY_TYPE);
104
+
105
+ const savedColumnSettings = filterSettingStates.settingsData?.column;
106
+
107
+ const getOrderedColumns = (
108
+ showList: { value: string }[],
109
+ filteredColumns: any[]
110
+ ) => {
111
+ // Build ordered columns using showList and filteredColumns
112
+ // const orderedColumns = showList
113
+ // ?.map((showItem) => {
114
+ // return filteredColumns.find(
115
+ // (col) => col?.accessorKey === showItem?.value
116
+ // );
117
+ // })
118
+ // ?.filter((col): col is ColumnDef<any> => col !== undefined); // Ensure non-undefined columns are returned
119
+
120
+ // didnt know what above code was doing so rewrote it as below
121
+ const res = showList.map((item: any) => ({
122
+ id: item.value,
123
+ accessorKey: item.value,
124
+ header: item.label,
125
+ }));
126
+
127
+ return res;
128
+ };
129
+
130
+ if (
131
+ savedColumnSettings &&
132
+ !savedColumnSettings.isDefault &&
133
+ savedColumnSettings.tabs
134
+ ) {
135
+ // Tab-wise view: find the active tab and use its show_list
136
+ const activeTabSettings = savedColumnSettings.tabs.find(
137
+ (tab) => tab.tab_name?.value == selectedTab.toLowerCase()
138
+ );
117
139
 
118
- if (activeTabSettings?.show_list) {
119
- const visibleColumns = new Set(
120
- activeTabSettings.show_list.map((c) => c.value)
121
- );
122
-
123
- // First, filter columns based on visibleColumns
124
- const filteredColumns = allColumns.filter((col: any) =>
125
- visibleColumns.has(col?.accessorKey)
126
- );
127
- setColumns(
128
- getOrderedColumns(activeTabSettings.show_list, filteredColumns)
129
- );
130
- } else {
131
- // Fallback if no specific settings for the active tab are found
132
- setColumns(allColumns);
133
- }
134
- } else if (savedColumnSettings && savedColumnSettings.show_list) {
135
- // Default view: use the main show_list
140
+ if (activeTabSettings?.show_list) {
136
141
  const visibleColumns = new Set(
137
- savedColumnSettings.show_list.map((c) => c.value)
142
+ activeTabSettings.show_list.map((c) => c.value)
138
143
  );
139
- const filtered = allColumns.filter((col: any) =>
144
+
145
+ // First, filter columns based on visibleColumns
146
+ const filteredColumns = allColumns.filter((col: any) =>
140
147
  visibleColumns.has(col?.accessorKey)
141
148
  );
142
-
143
149
  setColumns(
144
- getOrderedColumns(savedColumnSettings.show_list, filtered)
150
+ getOrderedColumns(activeTabSettings.show_list, filteredColumns)
145
151
  );
146
152
  } else {
147
- // No settings found, use all columns
153
+ // Fallback if no specific settings for the active tab are found
148
154
  setColumns(allColumns);
149
155
  }
150
- } catch (error) {
151
- console.error("Failed to fetch metadata:", error);
156
+ } else if (savedColumnSettings && savedColumnSettings.show_list) {
157
+ // Default view: use the main show_list
158
+ const visibleColumns = new Set(
159
+ savedColumnSettings.show_list.map((c) => c.value)
160
+ );
161
+ const filtered = allColumns.filter((col: any) =>
162
+ visibleColumns.has(col?.accessorKey)
163
+ );
164
+
165
+ setColumns(getOrderedColumns(savedColumnSettings.show_list, filtered));
166
+ } else {
167
+ // No settings found, use all columns
168
+ setColumns(allColumns);
152
169
  }
153
- };
170
+ } catch (error) {
171
+ console.error("Failed to fetch metadata:", error);
172
+ }
173
+ };
174
+
175
+ useEffect(() => {
176
+ // setTimeout(() => {
177
+ // setMockLoading(false);
178
+ // }, 1000);
154
179
 
155
180
  fetchMeta();
156
181
  }, [selectedTab]);
@@ -239,6 +264,91 @@ function ListingView() {
239
264
  );
240
265
  }, [tableData, selectedTab]);
241
266
 
267
+ const moveColumn = (
268
+ columnId: string,
269
+ showList: ColumnItem[],
270
+ hideList: ColumnItem[]
271
+ ) => {
272
+ const itemToMove = showList.find((c) => c.value === columnId);
273
+
274
+ return {
275
+ newShow: showList.filter((c) => c.value !== columnId),
276
+ newHide: itemToMove
277
+ ? [...hideList.filter((c) => c.value !== columnId), itemToMove]
278
+ : hideList,
279
+ };
280
+ };
281
+
282
+ const handleSaveSettings = (columnId: string) => {
283
+ let settingsData = filterSettingStates.settingsData;
284
+
285
+ const columnData = settingsData.column;
286
+ const defaultMode = isColumnDefault;
287
+
288
+ if (defaultMode) {
289
+ // Move for default mode
290
+ const { newShow, newHide } = moveColumn(
291
+ columnId,
292
+ columnData.show_list as ColumnItem[],
293
+ columnData.hide_list as ColumnItem[]
294
+ );
295
+
296
+ settingsData = {
297
+ ...settingsData,
298
+ column: {
299
+ ...columnData,
300
+ show_list: newShow,
301
+ hide_list: newHide,
302
+ },
303
+ };
304
+ } else {
305
+ // Move inside specific TAB
306
+ const updatedTabs = [...settingsColumnState?.tabs];
307
+ const tab = updatedTabs[activeTabIndex];
308
+
309
+ const { newShow, newHide } = moveColumn(
310
+ columnId,
311
+ tab.show_list,
312
+ tab.hide_list
313
+ );
314
+
315
+ updatedTabs[activeTabIndex] = {
316
+ ...tab,
317
+ show_list: newShow,
318
+ hide_list: newHide,
319
+ };
320
+
321
+ settingsData = {
322
+ ...settingsData,
323
+ column: {
324
+ ...columnData,
325
+ tabs: updatedTabs,
326
+ },
327
+ };
328
+ }
329
+
330
+ setSettingsData(settingsData);
331
+
332
+ saveSettingsDataMutation.mutate(
333
+ {
334
+ payload: {
335
+ entity_type: MAPPED_ENTITY_TYPE,
336
+ mapped_entity_type: ENTITY_TYPE,
337
+ mapped_json: settingsData,
338
+ type: "layout",
339
+ },
340
+ },
341
+ {
342
+ onSuccess: () => {
343
+ queryClient.invalidateQueries({
344
+ queryKey: ["GET_NAVIGATION_LAYOUT", ENTITY_TYPE],
345
+ });
346
+ fetchMeta();
347
+ },
348
+ }
349
+ );
350
+ };
351
+
242
352
  const handleRenderStatus = ({ value }: any) => {
243
353
  const statusValue = value?.toUpperCase();
244
354
  return (
@@ -279,7 +389,7 @@ function ListingView() {
279
389
  entity_type: MAPPED_ENTITY_TYPE,
280
390
  mapped_entity_type: ENTITY_TYPE,
281
391
  mapped_json: data,
282
- type: "layout",
392
+ type: "filter",
283
393
  };
284
394
 
285
395
  await saveLayoutAPI(payload);
@@ -325,8 +435,11 @@ function ListingView() {
325
435
  ) : (
326
436
  <TableWrapper
327
437
  data={filteredData}
438
+ activeTab={selectedTab}
328
439
  columns={columns && columns.length > 0 ? columns : defaultColumns}
329
440
  tableStates={tableStates}
441
+ filterSettingStates={filterSettingStates}
442
+ onSaveSettings={handleSaveSettings}
330
443
  featureOptions={{
331
444
  striped: true,
332
445
  compactTable: false,
@@ -429,11 +542,14 @@ function ListingView() {
429
542
  columnsDataLoading={metaQuery.isPending}
430
543
  quickTabAttributes={quickTabAttributes?.data}
431
544
  quickTabAttributesLoading={quickTabAttributes?.isLoading}
545
+ columnTabAttributes={settingsColumnAttributes?.data}
546
+ columnAttributesLoading={settingsColumnAttributes?.isLoading}
432
547
  sortingTabAttributes={sortingTabAttributes?.data}
433
548
  sortingTabAttributesLoading={sortingTabAttributes?.isLoading}
434
549
  tabsApiData={settingsTabDropdownData || []}
435
550
  tabsApiDataLoading={settingsTabDropdownPending}
436
551
  onSaveSettingsData={handleSaveSettingsData}
552
+ activeTab={selectedTab}
437
553
  />
438
554
  </>
439
555
  ),