rez-table-listing-mui 1.3.62 → 1.3.64

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez-table-listing-mui",
3
- "version": "1.3.62",
3
+ "version": "1.3.64",
4
4
  "type": "module",
5
5
  "description": "A rez table listing component built on TanStack Table",
6
6
  "main": "dist/index.js",
@@ -42,7 +42,7 @@ const FilterCriteriaEntityList = ({
42
42
 
43
43
  // Case 2: default behavior (apply search filter)
44
44
  return allEntities.filter((entity) =>
45
- entity.label.toLowerCase().includes(searchTerm.toLowerCase())
45
+ entity.label?.toLowerCase().includes(searchTerm?.toLowerCase())
46
46
  );
47
47
  }, [isSingleEntity, filters, allEntities, searchTerm]);
48
48
 
@@ -190,11 +190,24 @@ const ColumnTab = ({
190
190
  }
191
191
  };
192
192
 
193
+ const constructHideList = (): ColumnItem[] => {
194
+ return (
195
+ columnTabAttributes
196
+ ?.map((column) => ({
197
+ label: column?.name,
198
+ value: column?.attribute_key,
199
+ }))
200
+ ?.filter(
201
+ (tab) =>
202
+ !settingsColumnState?.show_list?.find((i) => i.value === tab.value)
203
+ ) || []
204
+ );
205
+ };
193
206
  const getCurrentLists = () => {
194
207
  if (settingsColumnState?.isDefault) {
195
208
  return {
196
209
  showList: settingsColumnState.show_list || [],
197
- hideList: settingsColumnState.hide_list || [],
210
+ hideList: constructHideList() || [],
198
211
  };
199
212
  } else {
200
213
  const currentTab = settingsColumnState?.tabs?.[selectedTabIndex];
@@ -106,6 +106,8 @@ const QuickTab = ({
106
106
  show_list: [],
107
107
  },
108
108
  }));
109
+
110
+ setCurrentQuickAttribute("");
109
111
  }
110
112
  }, [tabsApiData]);
111
113
 
@@ -174,8 +176,14 @@ const QuickTab = ({
174
176
  ];
175
177
 
176
178
  // Convert show_list/hide_list to FilterValue[] for rendering only
179
+
180
+ const constructHideList = () => {
181
+ return tabsApiData?.filter(
182
+ (tab) => !showListValues?.find((i) => i.value === tab.value)
183
+ );
184
+ };
177
185
  const showListValues = quickTabStates?.show_list || [];
178
- const hideListValues = quickTabStates?.hide_list || [];
186
+ const hideListValues = constructHideList() || [];
179
187
 
180
188
  const sensors = useSensors(
181
189
  useSensor(MouseSensor),
@@ -25,6 +25,7 @@ import {
25
25
  getLayoutAttributes,
26
26
  getAttributes,
27
27
  getTableTabs,
28
+ newCommonGetDropdownDataAPI,
28
29
  } from "../utils/apiColumn";
29
30
  import {
30
31
  FilterDataMainFilterEntityListProps,
@@ -269,7 +270,11 @@ export const useCommonFilterDropdownAPI = (
269
270
  queries: dropdownConfigs.map((cfg) => {
270
271
  return {
271
272
  queryKey: ["commonDropdown", cfg?.dataSourceType],
272
- queryFn: () => commonGetDropdownDataAPI(cfg?.dataSourceType, null),
273
+ queryFn: () =>
274
+ newCommonGetDropdownDataAPI({
275
+ entity_type: "ROL",
276
+ attribute_key: cfg?.key,
277
+ }),
273
278
  enabled: !!cfg?.dataSourceType,
274
279
  };
275
280
  }),
@@ -364,10 +369,14 @@ export const useGetFilterEntityListAndCriteria = ({
364
369
  return { filterEntityList, filterEntityWiseCriteria };
365
370
  };
366
371
 
367
- export const useGetAttributes = (entity_type: string) => {
372
+ export const useGetAttributes = (
373
+ entity_type: string,
374
+ element_type?: string
375
+ ) => {
368
376
  const attributes = useQuery({
369
- queryKey: ["attributes", entity_type],
370
- queryFn: () => getAttributes(entity_type),
377
+ queryKey: ["attributes", entity_type, element_type],
378
+ queryFn: () => getAttributes(entity_type, element_type),
379
+ enabled: !!entity_type, // optional safety
371
380
  });
372
381
 
373
382
  return { attributes };
@@ -409,6 +418,47 @@ export const useGetTableTabs = (payload: any) => {
409
418
  });
410
419
  return { tableTabs, isLoading };
411
420
  };
421
+
422
+ export const useDropdownAPI = ({
423
+ entity_type,
424
+ attribute_key,
425
+ inactiveIds,
426
+ parentId,
427
+ data,
428
+ enabled = true,
429
+ }: {
430
+ entity_type: string;
431
+ attribute_key?: string;
432
+ inactiveIds?: string | null;
433
+ parentId?: number | string;
434
+ data?: any;
435
+ enabled?: boolean;
436
+ }) => {
437
+ const query = useQuery({
438
+ queryKey: [
439
+ "commonDropdown",
440
+ entity_type,
441
+ attribute_key,
442
+ inactiveIds,
443
+ parentId,
444
+ ],
445
+ queryFn: () =>
446
+ newCommonGetDropdownDataAPI({
447
+ entity_type,
448
+ attribute_key,
449
+ inactiveIds,
450
+ parentId,
451
+ data,
452
+ }),
453
+ enabled, // prevents auto call unless needed
454
+ staleTime: 5 * 60 * 1000, // cache for 5 mins
455
+ });
456
+
457
+ return {
458
+ ...query,
459
+ dropdownData: query.data || [],
460
+ };
461
+ };
412
462
  // export const useGetSettingsColumnAttributes = (entity_type: string) => {
413
463
  // // First query to get meta data
414
464
  // const settingsColumnAttributes = useQuery({
@@ -14,11 +14,11 @@ export const useDetailsQueryAPI = (value: string | undefined) => {
14
14
  return { detailsQuery };
15
15
  };
16
16
 
17
- export const useFetchData = (entity_type: string) => {
17
+ export const useFetchData = (entity_type: string, payload?: any) => {
18
18
  // First query to get meta data
19
19
  const metaQuery = useQuery({
20
- queryKey: ["meta", entity_type],
21
- queryFn: () => entityTableFilterMaster(entity_type),
20
+ queryKey: ["meta", entity_type, payload],
21
+ queryFn: () => entityTableFilterMaster(entity_type, payload),
22
22
  });
23
23
 
24
24
  return { metaQuery };
@@ -27,10 +27,14 @@ export const entityTableMetaMaster = async (entity_type: string) => {
27
27
  }
28
28
  };
29
29
 
30
- export const entityTableFilterMaster = async (entity_type: string) => {
30
+ export const entityTableFilterMaster = async (
31
+ entity_type: string,
32
+ payload?: any
33
+ ) => {
31
34
  try {
32
35
  const response = await api.post(
33
- `/meta/get-table-data?entity_type=${entity_type}&list_type=${entity_type}`
36
+ `/meta/get-table-data?entity_type=${entity_type}&list_type=${entity_type}`,
37
+ payload
34
38
  );
35
39
 
36
40
  // const filteredData = {
@@ -205,16 +209,57 @@ export const getLayoutAttributes = async ({
205
209
  return response.data;
206
210
  };
207
211
 
208
- export const getAttributes = async (entity_type: string) => {
209
- const response = await api.get(
210
- `meta/attribute-master/getAttributes?direct=false&entity_type=${entity_type}`
211
- );
212
- console.log("resss", response);
212
+ export const getAttributes = async (
213
+ entity_type: string,
214
+ element_type?: string
215
+ ) => {
216
+ const response = await api.get("/meta/attribute-master/getAttributes", {
217
+ params: {
218
+ // direct: false, // commented as per requirement
219
+ entity_type,
220
+ ...(element_type && { element_type }),
221
+ },
222
+ });
213
223
 
214
224
  return response.data;
215
225
  };
216
226
 
217
227
  export const getTableTabs = async (payload: any) => {
218
- const response = await api.post(`filter/get-tabs-data`, payload);
228
+ const response = await api.post(`filter/adm/tabs`, payload);
219
229
  return response.data;
220
230
  };
231
+
232
+ export const newCommonGetDropdownDataAPI = async ({
233
+ entity_type,
234
+ attribute_key,
235
+ // organization_id,
236
+ data,
237
+ inactiveIds,
238
+ parentId,
239
+ }: {
240
+ entity_type: string | undefined;
241
+ attribute_key?: string;
242
+ // organization_id?: string | null;
243
+ data?: any;
244
+ inactiveIds?: string | null;
245
+ parentId?: number | string;
246
+ }) => {
247
+ // Body can still accept optional custom data if needed
248
+ const requestBody = data || {};
249
+
250
+ // Build query params dynamically
251
+ const queryParams: string[] = [];
252
+
253
+ if (entity_type) queryParams.push(`entity_type=${entity_type}`);
254
+ if (attribute_key) queryParams.push(`attribute_key=${attribute_key}`);
255
+ if (!Number.isNaN(Number(inactiveIds)) && inactiveIds)
256
+ queryParams.push(`inactiveIds=${inactiveIds}`);
257
+ if (parentId !== undefined && parentId !== null)
258
+ queryParams.push(`parent=${parentId}`);
259
+
260
+ const queryString = queryParams.length > 0 ? `?${queryParams.join("&")}` : "";
261
+
262
+ return await api
263
+ .post(`entity/getAttributeDropdown${queryString}`, requestBody)
264
+ .then((response) => response.data);
265
+ };
@@ -111,3 +111,47 @@ api.interceptors.request.use(
111
111
  return Promise.reject(error);
112
112
  }
113
113
  );
114
+
115
+ export const formatTableHeaders = (columns: any) => {
116
+ const mapped = columns.map((col: any) => {
117
+ const meta =
118
+ col.attribute_key === "status" ||
119
+ col.attribute_key === "lead_status" ||
120
+ col.attribute_key === "flag" ||
121
+ col.attribute_key === "invitation_status"
122
+ ? { type: "custom", propName: "renderStatus", align: col.align }
123
+ : col.attribute_key === "profile_image" ||
124
+ col.attribute_key === "short_logo"
125
+ ? {
126
+ type: "custom",
127
+ propName: "profileImageFetch",
128
+ align: col.align,
129
+ }
130
+ : col.attribute_key === "start_date" || col.attribute_key === "end_date"
131
+ ? { type: "custom", propName: "dateFormater", align: col.align }
132
+ : col.attribute_key === "action"
133
+ ? { type: "custom", propName: "renderAction", align: col.align }
134
+ : col.attribute_key === "code"
135
+ ? {
136
+ type: "custom",
137
+ propName: "drillCellRenderer",
138
+ align: col.align,
139
+ }
140
+ : col.attribute_key === "primary_mobile"
141
+ ? {
142
+ type: "custom",
143
+ propName: "apiCallonClick",
144
+ align: col.align,
145
+ }
146
+ : undefined;
147
+
148
+ return {
149
+ header: col.name ?? "",
150
+ accessorKey: col.attribute_key ?? "",
151
+ size: col.size,
152
+ meta,
153
+ };
154
+ });
155
+
156
+ return mapped;
157
+ };
@@ -95,7 +95,7 @@ export interface CraftTableProps<T> {
95
95
  filterOptions?: FilterOptionsProps;
96
96
  settingsOptions?: settingsOptionsProps;
97
97
  craftTableFilterSettingsOptions?: craftTableFilterSettingsOptionsProps;
98
- activeTab?: string;
98
+ activeTab?: any;
99
99
  }
100
100
  export interface CraftTableComponentProps<T> {
101
101
  table: Table<T>;
@@ -6,9 +6,14 @@ import {
6
6
  useDetailsQueryAPI,
7
7
  useFetchData,
8
8
  } from "../listing/libs/hooks/useEntityTableHooks";
9
- import { ENTITY_TYPE, MAPPED_ENTITY_TYPE } from "../listing/libs/utils/common";
9
+ import {
10
+ ENTITY_TYPE,
11
+ formatTableHeaders,
12
+ MAPPED_ENTITY_TYPE,
13
+ } from "../listing/libs/utils/common";
10
14
  import {
11
15
  useCommonFilterDropdownAPI,
16
+ useDropdownAPI,
12
17
  useEntityTableAPI,
13
18
  useGetAttributes,
14
19
  useGetOperationList,
@@ -54,8 +59,30 @@ function ListingView() {
54
59
  filterSettingStates;
55
60
 
56
61
  const { defaultColumns } = useDefaultColumns();
62
+ const { data: getSettingsAPIData } = useGetNavigationLayoutAPI(ENTITY_TYPE);
63
+ const tabsPaylod = {
64
+ entity_type: ENTITY_TYPE,
65
+ defaultTabsConfig: {
66
+ attribute: "status",
67
+ },
68
+ };
57
69
 
58
- const { metaQuery } = useFetchData(ENTITY_TYPE);
70
+ const { tableTabs } = useGetTableTabs(tabsPaylod);
71
+ const tabsData = tableTabs;
72
+
73
+ const { metaQuery } = useFetchData(ENTITY_TYPE, {
74
+ tabs: {
75
+ columnName:
76
+ getSettingsAPIData?.mapped_json?.quick_tab?.attribute || "status",
77
+ sortBy: getSettingsAPIData?.mapped_json?.quick_tab?.sorting || "ASC",
78
+ value:
79
+ selectedTab?.tab_name?.toLowerCase() === "all"
80
+ ? tabsData?.find((tab: any) => tab?.tab_name?.toLowerCase() === "all")
81
+ ?.tab_value
82
+ : selectedTab?.tab_value,
83
+ name: selectedTab?.tab_name,
84
+ },
85
+ });
59
86
 
60
87
  const { detailsQuery } = useDetailsQueryAPI(
61
88
  filterMaster?.saved_filters?.selectedId
@@ -66,6 +93,10 @@ function ListingView() {
66
93
  const { operationList } = useGetOperationList();
67
94
 
68
95
  const { attributes } = useGetAttributes(ENTITY_TYPE);
96
+ const { attributes: quickTabAttributes } = useGetAttributes(
97
+ ENTITY_TYPE,
98
+ "select"
99
+ );
69
100
 
70
101
  const isColumnDefault =
71
102
  filterSettingStates?.columnTabState?.isDefault || false;
@@ -80,99 +111,20 @@ function ListingView() {
80
111
  // );
81
112
  // const { dropdownData } = useCommonDropdownAPI(filters);
82
113
  const { dropdownFilterData } = useCommonFilterDropdownAPI(filters);
83
- const { settingsTabDropdownData, settingsTabDropdownPending } =
84
- useSettingsDropDownAPI({
85
- entity_type: ENTITY_TYPE,
86
- column: filterSettingStates?.quickTabStates?.attribute,
87
- sort_by: filterSettingStates?.quickTabStates?.sorting,
88
- });
89
- const tabsPaylod = {
90
- entity_type: ENTITY_TYPE,
91
- defaultTabsConfig: {
92
- attribute: "status",
93
- },
94
- };
95
114
 
96
- const { tableTabs } = useGetTableTabs(tabsPaylod);
115
+ const {
116
+ data: settingsTabDropdownData,
117
+ isLoading: settingsTabDropdownPending,
118
+ } = useDropdownAPI({
119
+ entity_type: ENTITY_TYPE,
120
+ attribute_key: filterSettingStates?.quickTabStates?.attribute,
121
+ });
97
122
 
98
123
  const queryClient = useQueryClient();
99
- const { data: getSettingsAPIData } = useGetNavigationLayoutAPI(ENTITY_TYPE);
100
124
 
101
125
  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
- return allColumns;
129
- };
130
-
131
- setColumns(allColumns);
132
-
133
- // if (
134
- // savedColumnSettings &&
135
- // !savedColumnSettings.isDefault &&
136
- // savedColumnSettings.tabs
137
- // ) {
138
- // // Tab-wise view: find the active tab and use its show_list
139
- // const activeTabSettings = savedColumnSettings.tabs.find(
140
- // (tab) => tab.tab_name?.value == selectedTab.toLowerCase()
141
- // );
142
-
143
- // if (activeTabSettings?.show_list) {
144
- // const visibleColumns = new Set(
145
- // activeTabSettings.show_list.map((c) => c.value)
146
- // );
147
-
148
- // // First, filter columns based on visibleColumns
149
- // const filteredColumns = allColumns.filter((col: any) =>
150
- // visibleColumns.has(col?.accessorKey)
151
- // );
152
- // setColumns(
153
- // getOrderedColumns(activeTabSettings.show_list, filteredColumns)
154
- // );
155
- // } else {
156
- // // Fallback if no specific settings for the active tab are found
157
- // setColumns(allColumns);
158
- // }
159
- // } else if (savedColumnSettings && savedColumnSettings.show_list) {
160
- // // Default view: use the main show_list
161
- // const visibleColumns = new Set(
162
- // savedColumnSettings.show_list.map((c) => c.value)
163
- // );
164
- // const filtered = allColumns.filter((col: any) =>
165
- // visibleColumns.has(col?.accessorKey)
166
- // );
167
-
168
- // setColumns(getOrderedColumns(savedColumnSettings.show_list, filtered));
169
- // } else {
170
- // // No settings found, use all columns
171
- // setColumns(allColumns);
172
- // }
173
- } catch (error) {
174
- console.error("Failed to fetch metadata:", error);
175
- }
126
+ const res = formatTableHeaders(metaQuery?.data?.column_list || []);
127
+ setColumns(res);
176
128
  };
177
129
 
178
130
  useEffect(() => {
@@ -208,7 +160,6 @@ function ListingView() {
208
160
 
209
161
  //For server side sorting
210
162
  const enableServerSideSorting = true;
211
- const tabsData = tableTabs?.data;
212
163
 
213
164
  const { tableData, isTableDataPending } = useEntityTableAPI({
214
165
  page: 0,
@@ -400,8 +351,8 @@ function ListingView() {
400
351
  mapped_json: data,
401
352
  type: "filter",
402
353
  };
403
-
404
354
  await saveLayoutAPI(payload);
355
+ queryClient.invalidateQueries({ queryKey: ["tableTabs"] });
405
356
  };
406
357
 
407
358
  const handleSaveSettingsData = (settingsData: SettingsDataProps) => {
@@ -553,7 +504,7 @@ function ListingView() {
553
504
  onClose={() => setShowListViewSettings(false)}
554
505
  columnsData={metaQuery.data || {}}
555
506
  columnsDataLoading={metaQuery.isPending}
556
- quickTabAttributes={attributes?.data?.map((item) => ({
507
+ quickTabAttributes={quickTabAttributes?.data?.map((item) => ({
557
508
  label: item.name,
558
509
  value: item.attribute_key,
559
510
  }))}