rez-table-listing-mui 1.3.61 → 2.0.0

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 (34) hide show
  1. package/dist/index.d.ts +4 -5
  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/index.scss +0 -144
  8. package/src/listing/components/login/index.tsx +4 -4
  9. package/src/listing/components/pagination/default/index.tsx +108 -138
  10. package/src/listing/components/pagination/default/pagination.styles.ts +113 -0
  11. package/src/listing/components/{table-body-dnd-cell.tsx → table-body/table-body-dnd-cell.tsx} +18 -25
  12. package/src/listing/components/table-body/table-body.styles.ts +64 -0
  13. package/src/listing/components/{table-body.tsx → table-body/table-body.tsx} +35 -32
  14. package/src/listing/components/table-head/table-head-dnd-cell.tsx +112 -0
  15. package/src/listing/components/table-head/table-head-pin.tsx +29 -0
  16. package/src/listing/components/{table-head-popover.tsx → table-head/table-head-popover.tsx} +4 -16
  17. package/src/listing/components/table-head/table-head-resizer.tsx +22 -0
  18. package/src/listing/components/table-head/table-head.styles.ts +115 -0
  19. package/src/listing/components/{table-head.tsx → table-head/table-head.tsx} +36 -69
  20. package/src/listing/components/table.tsx +2 -2
  21. package/src/listing/components/tabs/index.tsx +28 -42
  22. package/src/listing/components/tabs/tabs.styles.ts +49 -0
  23. package/src/listing/libs/hooks/useEntityTableAPI.tsx +8 -0
  24. package/src/listing/libs/hooks/useEntityTableHooks.ts +3 -3
  25. package/src/listing/libs/services/getLayoutAPI.tsx +1 -1
  26. package/src/listing/libs/utils/apiColumn.ts +17 -8
  27. package/src/listing/libs/utils/common.ts +45 -1
  28. package/src/listing/types/common.ts +1 -0
  29. package/src/listing/types/table.ts +2 -2
  30. package/src/view/ListingView.tsx +58 -91
  31. package/src/listing/components/table-head-dnd-cell.tsx +0 -150
  32. package/src/listing/components/table-head-pin.tsx +0 -22
  33. package/src/listing/components/tabs/index.scss +0 -42
  34. package/src/listing/components/tabs/styles.ts +0 -34
@@ -6,12 +6,17 @@ 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,
12
16
  useEntityTableAPI,
13
17
  useGetAttributes,
14
18
  useGetOperationList,
19
+ useGetTableTabs,
15
20
  useSaveSettingsDataAPI,
16
21
  useSettingsDropDownAPI,
17
22
  } from "../listing/libs/hooks/useEntityTableAPI";
@@ -39,7 +44,10 @@ function ListingView() {
39
44
  const [searchTerm, setSearchTerm] = useState("");
40
45
  // const [data, setData] = useState<Person[]>(() => makeData(200, 3, 2));
41
46
 
42
- const [selectedTab, setSelectedTab] = useState("All");
47
+ const [selectedTab, setSelectedTab] = useState({
48
+ tab_name: "All",
49
+ tab_value: "",
50
+ });
43
51
 
44
52
  const tableStates = useCraftTable();
45
53
  const filterSettingStates = useCraftTableFilterSettings();
@@ -50,8 +58,30 @@ function ListingView() {
50
58
  filterSettingStates;
51
59
 
52
60
  const { defaultColumns } = useDefaultColumns();
61
+ const { data: getSettingsAPIData } = useGetNavigationLayoutAPI(ENTITY_TYPE);
62
+ const tabsPaylod = {
63
+ entity_type: ENTITY_TYPE,
64
+ defaultTabsConfig: {
65
+ attribute: "status",
66
+ },
67
+ };
53
68
 
54
- const { metaQuery } = useFetchData(ENTITY_TYPE);
69
+ const { tableTabs } = useGetTableTabs(tabsPaylod);
70
+ const tabsData = tableTabs;
71
+
72
+ const { metaQuery } = useFetchData(ENTITY_TYPE, {
73
+ tabs: {
74
+ columnName:
75
+ getSettingsAPIData?.mapped_json?.quick_tab?.attribute || "status",
76
+ sortBy: getSettingsAPIData?.mapped_json?.quick_tab?.sorting || "ASC",
77
+ value:
78
+ selectedTab?.tab_name?.toLowerCase() === "all"
79
+ ? tabsData?.find((tab: any) => tab?.tab_name?.toLowerCase() === "all")
80
+ ?.tab_value
81
+ : selectedTab?.tab_value,
82
+ name: selectedTab?.tab_name,
83
+ },
84
+ });
55
85
 
56
86
  const { detailsQuery } = useDetailsQueryAPI(
57
87
  filterMaster?.saved_filters?.selectedId
@@ -66,9 +96,7 @@ function ListingView() {
66
96
  const isColumnDefault =
67
97
  filterSettingStates?.columnTabState?.isDefault || false;
68
98
  const activeTabIndex = filterSettingStates?.columnTabState?.tabs?.findIndex(
69
- (tab) =>
70
- tab?.tab_name?.value == selectedTab ||
71
- tab?.tab_name?.label?.toLowerCase() == selectedTab?.toLowerCase()
99
+ (tab) => tab?.tab_name?.value == selectedTab?.tab_name
72
100
  );
73
101
  const settingsColumnState = (filterSettingStates?.settingsData?.column ||
74
102
  {}) as ColumnTabConfigProps;
@@ -86,83 +114,12 @@ function ListingView() {
86
114
  });
87
115
 
88
116
  const queryClient = useQueryClient();
89
- const { data: getSettingsAPIData } = useGetNavigationLayoutAPI(ENTITY_TYPE);
90
117
 
91
118
  const fetchMeta = async () => {
92
- try {
93
- const { res: allColumns } = await entityTableMetaMaster(ENTITY_TYPE);
94
-
95
- const savedColumnSettings = filterSettingStates.settingsData?.column;
96
-
97
- const getOrderedColumns = (
98
- showList: { value: string }[],
99
- filteredColumns: any[]
100
- ) => {
101
- // Build ordered columns using showList and filteredColumns
102
- // const orderedColumns = showList
103
- // ?.map((showItem) => {
104
- // return filteredColumns.find(
105
- // (col) => col?.accessorKey === showItem?.value
106
- // );
107
- // })
108
- // ?.filter((col): col is ColumnDef<any> => col !== undefined); // Ensure non-undefined columns are returned
109
-
110
- // didnt know what above code was doing so rewrote it as below
111
- // const res = showList.map((item: any) => ({
112
- // id: item.value,
113
- // accessorKey: item.value,
114
- // header: item.label,
115
- // }));
116
-
117
- // return res;
118
- return allColumns;
119
- };
119
+ const res = formatTableHeaders(metaQuery?.data?.column_list || []);
120
+ console.log("res", res);
120
121
 
121
- setColumns(allColumns);
122
-
123
- // if (
124
- // savedColumnSettings &&
125
- // !savedColumnSettings.isDefault &&
126
- // savedColumnSettings.tabs
127
- // ) {
128
- // // Tab-wise view: find the active tab and use its show_list
129
- // const activeTabSettings = savedColumnSettings.tabs.find(
130
- // (tab) => tab.tab_name?.value == selectedTab.toLowerCase()
131
- // );
132
-
133
- // if (activeTabSettings?.show_list) {
134
- // const visibleColumns = new Set(
135
- // activeTabSettings.show_list.map((c) => c.value)
136
- // );
137
-
138
- // // First, filter columns based on visibleColumns
139
- // const filteredColumns = allColumns.filter((col: any) =>
140
- // visibleColumns.has(col?.accessorKey)
141
- // );
142
- // setColumns(
143
- // getOrderedColumns(activeTabSettings.show_list, filteredColumns)
144
- // );
145
- // } else {
146
- // // Fallback if no specific settings for the active tab are found
147
- // setColumns(allColumns);
148
- // }
149
- // } else if (savedColumnSettings && savedColumnSettings.show_list) {
150
- // // Default view: use the main show_list
151
- // const visibleColumns = new Set(
152
- // savedColumnSettings.show_list.map((c) => c.value)
153
- // );
154
- // const filtered = allColumns.filter((col: any) =>
155
- // visibleColumns.has(col?.accessorKey)
156
- // );
157
-
158
- // setColumns(getOrderedColumns(savedColumnSettings.show_list, filtered));
159
- // } else {
160
- // // No settings found, use all columns
161
- // setColumns(allColumns);
162
- // }
163
- } catch (error) {
164
- console.error("Failed to fetch metadata:", error);
165
- }
122
+ setColumns(res);
166
123
  };
167
124
 
168
125
  useEffect(() => {
@@ -204,10 +161,15 @@ function ListingView() {
204
161
  size: 20,
205
162
  entity_type: ENTITY_TYPE,
206
163
  tabs: {
207
- columnName: getSettingsAPIData?.quick_tab?.attribute || "lead_status",
164
+ columnName: getSettingsAPIData?.quick_tab?.attribute || "status",
208
165
  sortBy: getSettingsAPIData?.quick_tab?.sorting || "ASC",
209
166
  value:
210
- selectedTab.toLowerCase() === "all" ? "" : selectedTab.toLowerCase(),
167
+ selectedTab?.tab_name?.toLowerCase() === "all"
168
+ ? tabsData?.find((tab) => tab?.tab_name?.toLowerCase() === "all")
169
+ .tab_value
170
+ : selectedTab?.tab_value,
171
+
172
+ name: selectedTab?.tab_name,
211
173
  },
212
174
  quickFilter: tableStates.filters,
213
175
  sortby: [
@@ -223,7 +185,6 @@ function ListingView() {
223
185
  () => tableData?.entity_list || [],
224
186
  [tableData?.entity_list]
225
187
  );
226
- const tabsData = tableData?.entity_tabs;
227
188
 
228
189
  // Auto-switch tab if the selected tab is removed
229
190
  useEffect(() => {
@@ -231,7 +192,8 @@ function ListingView() {
231
192
  tabsData &&
232
193
  tabsData.length > 0 &&
233
194
  !tabsData.some(
234
- (tab) => tab.tab_name?.toLowerCase() === selectedTab.toLowerCase()
195
+ (tab) =>
196
+ tab.tab_name?.toLowerCase() === selectedTab?.tab_name?.toLowerCase()
235
197
  )
236
198
  ) {
237
199
  // Try to select 'ALL' if it exists
@@ -239,17 +201,17 @@ function ListingView() {
239
201
  (tab) => tab.tab_name?.toLowerCase() === "all"
240
202
  );
241
203
  if (allTab) {
242
- setSelectedTab(allTab.tab_name || "All");
204
+ setSelectedTab(allTab || "All");
243
205
  } else {
244
- setSelectedTab(tabsData[0].tab_name || "All");
206
+ setSelectedTab(tabsData[0] || "All");
245
207
  }
246
208
  }
247
209
  }, [tabsData, selectedTab]);
248
210
 
249
211
  const totalCount = useMemo(() => {
250
212
  return Number(
251
- tableData?.entity_tabs?.find((tab) => {
252
- const activeTab = selectedTab || "All";
213
+ tabsData?.find((tab) => {
214
+ const activeTab = selectedTab?.tab_name || "All";
253
215
  return (
254
216
  tab.tab_name?.toLocaleLowerCase() === activeTab.toLocaleLowerCase()
255
217
  );
@@ -384,8 +346,8 @@ function ListingView() {
384
346
  mapped_json: data,
385
347
  type: "filter",
386
348
  };
387
-
388
349
  await saveLayoutAPI(payload);
350
+ queryClient.invalidateQueries({ queryKey: ["tableTabs"] });
389
351
  };
390
352
 
391
353
  const handleSaveSettingsData = (settingsData: SettingsDataProps) => {
@@ -518,7 +480,6 @@ function ListingView() {
518
480
  leftSideComponent: (
519
481
  <>
520
482
  <TableTabs
521
- columns={columns}
522
483
  settingsOptions={{
523
484
  showIcon: true,
524
485
  onClick: () => setShowListViewSettings(!showListViewSettings),
@@ -557,9 +518,15 @@ function ListingView() {
557
518
  ),
558
519
  searchValue: searchTerm,
559
520
  onSearchChange: (val) => setSearchTerm(val),
560
- showFilterToggle: true,
521
+ showFilterToggle: false,
561
522
  onFilterButtonClick: () =>
562
523
  tableStates.setShowTableFilter(!tableStates.showTableFilter),
524
+ showColumnToggle: false,
525
+ showSearch: false,
526
+ showChangeLayoutToggle: false,
527
+ showSortingToggle: false,
528
+ // viewMoreToggle: true,
529
+ // showCompactTableToggle: false,
563
530
  }}
564
531
  />
565
532
  );
@@ -1,150 +0,0 @@
1
- import { flexRender } from "@tanstack/react-table";
2
- import { useSortable } from "@dnd-kit/sortable";
3
- import { CSSProperties, useState } from "react";
4
- import { CSS } from "@dnd-kit/utilities";
5
- import { DownArrow, DragHandleIcon, UpArrow } from "../../assets/svg";
6
- import {
7
- getColumnAlignment,
8
- getColumnPinningStyles,
9
- } from "../libs/utils/common";
10
- import { align } from "../types/common";
11
- import { TableHeaderProps } from "../types/table";
12
- import TableHeadPin from "./table-head-pin";
13
- import TableHeadPopover from "./table-head-popover";
14
-
15
- function DraggableTableHeader<T>({
16
- header,
17
- activeTab,
18
- featureOptions,
19
- tableStates,
20
- filterSettingStates,
21
- onSaveSettings,
22
- }: TableHeaderProps<T>) {
23
- const { enableColumnPinning } = featureOptions;
24
-
25
- // Popover
26
- const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
27
-
28
- const handleHover = (event: React.MouseEvent<HTMLElement>) => {
29
- setAnchorEl((prev) => (prev ? null : event.currentTarget));
30
- };
31
-
32
- const handleClose = () => {
33
- setAnchorEl(null);
34
- };
35
-
36
- const { isDragging, transform, attributes, listeners } = useSortable({
37
- id: header.column.id,
38
- });
39
-
40
- const isPinned = header.column.getIsPinned();
41
-
42
- const styles: CSSProperties = {
43
- opacity: isDragging ? 0.8 : 1,
44
- position: "relative",
45
- transform: CSS.Translate.toString(transform),
46
- transition: "width transform 0.2s ease-in-out",
47
- width: header.column.getSize(),
48
- minWidth: `${header.column.columnDef.minSize ?? 180}px`,
49
- maxWidth: `${header.column.columnDef.maxSize}px`,
50
- };
51
-
52
- let sortProps: {
53
- className: string;
54
- title?: string;
55
- style?: CSSProperties;
56
- } = {
57
- className: "ts__content",
58
- // style: {
59
- // justifyContent: getColumnAlignment(
60
- // (header?.column?.columnDef?.meta as align)?.align
61
- // ),
62
- // },
63
- };
64
-
65
- // if (header.column.getCanSort()) {
66
- // sortProps = {
67
- // ...sortProps,
68
- // title:
69
- // header.column.getNextSortingOrder() === "asc"
70
- // ? "Sort ascending"
71
- // : header.column.getNextSortingOrder() === "desc"
72
- // ? "Sort descending"
73
- // : "Clear sort",
74
- // };
75
- // }
76
-
77
- return (
78
- <th
79
- onMouseLeave={handleClose}
80
- key={header?.id}
81
- className="ts__head__th"
82
- colSpan={header.colSpan}
83
- onClick={handleHover}
84
- style={{
85
- width: `${header.column.getSize()}px `,
86
- minWidth: `${header.column.columnDef.minSize}px`,
87
- maxWidth: `${header.column.columnDef.maxSize}px`,
88
- ...styles,
89
- ...getColumnPinningStyles(header.column),
90
- zIndex: isPinned ? 3 : isDragging ? 1 : 0,
91
- }}
92
- >
93
- {header.isPlaceholder ? null : (
94
- <div {...sortProps}>
95
- <div
96
- className={`${
97
- header.column.getCanSort() ? "ts__content__sort" : ""
98
- }`.trim()}
99
- // onClick={header.column.getToggleSortingHandler()}
100
- >
101
- {flexRender(header.column.columnDef.header, header.getContext())}
102
-
103
- {{
104
- asc: <UpArrow />,
105
- desc: <DownArrow />,
106
- }[header.column.getIsSorted() as "asc" | "desc"] ?? null}
107
- </div>
108
-
109
- {enableColumnPinning && (
110
- <TableHeadPin
111
- header={header}
112
- featureOptions={featureOptions}
113
- tableStates={tableStates}
114
- filterSettingStates={filterSettingStates}
115
- />
116
- )}
117
-
118
- <div {...attributes} {...listeners} className="ts__dnd__button">
119
- <DragHandleIcon />
120
- </div>
121
- </div>
122
- )}
123
-
124
- {/* column resizing */}
125
- {header.column.getCanResize() ? (
126
- <div
127
- onDoubleClick={() => header.column.resetSize()}
128
- onMouseDown={header.getResizeHandler()}
129
- onTouchStart={header.getResizeHandler()}
130
- className={`column__resize ${
131
- header.column.getIsResizing() ? "is__resizing" : ""
132
- }`}
133
- />
134
- ) : null}
135
-
136
- {/* Popover */}
137
- <TableHeadPopover
138
- anchorEl={anchorEl}
139
- activeTab={activeTab}
140
- onClose={handleClose}
141
- header={header}
142
- tableStates={tableStates}
143
- filterSettingStates={filterSettingStates}
144
- onSaveSettings={onSaveSettings}
145
- />
146
- </th>
147
- );
148
- }
149
-
150
- export default DraggableTableHeader;
@@ -1,22 +0,0 @@
1
- import { IconPinOffOutline } from "../../assets/svg";
2
- import { TableHeaderProps } from "../types/table";
3
-
4
- function TableHeadPin<T>({ header }: TableHeaderProps<T>) {
5
- return header.column.getIsPinned() !== "left" ? (
6
- <div className="ts--head--button" onClick={() => header.column.pin("left")}>
7
- {/* <IconPinOutline /> */}
8
- </div>
9
- ) : (
10
- <div
11
- className="ts--head--button"
12
- onClick={(e) => {
13
- e.stopPropagation();
14
- header.column.pin(false);
15
- }}
16
- >
17
- <IconPinOffOutline />
18
- </div>
19
- );
20
- }
21
-
22
- export default TableHeadPin;
@@ -1,42 +0,0 @@
1
- .table-tabs {
2
- .tabs {
3
- display: flex;
4
- justify-content: flex-start;
5
- align-items: center;
6
- margin: 0rem;
7
- padding: 0rem;
8
-
9
- .tabs-settings {
10
- margin-left: 0.1rem;
11
- margin-right: 0.5rem;
12
- cursor: pointer;
13
- }
14
-
15
- .tab {
16
- display: flex;
17
- gap: 0.5rem;
18
- padding: 0.5rem 1rem;
19
- cursor: pointer;
20
- color: var(--grey-900);
21
- font-size: 0.875rem;
22
- font-family: "Satoshi";
23
- font-weight: 700;
24
-
25
- .tab__label {
26
- font-family: inherit;
27
- }
28
-
29
- &.active {
30
- background: var(--grey-500);
31
- border-top-left-radius: 0.5rem;
32
- border-top-right-radius: 0.5rem;
33
- backdrop-filter: blur(200px);
34
- }
35
- }
36
-
37
- .tabs-dropdown {
38
- margin-left: 1rem;
39
- cursor: pointer;
40
- }
41
- }
42
- }
@@ -1,34 +0,0 @@
1
- import { SxProps, Theme } from "@mui/material";
2
-
3
- interface TabStylesProps {
4
- tabs: SxProps<Theme>;
5
- tab: SxProps<Theme>;
6
- tabCount: SxProps<Theme>;
7
- }
8
-
9
- export const tableTabsStyles: TabStylesProps = {
10
- tabs: {
11
- minHeight: "38px",
12
- },
13
-
14
- tab: {
15
- color: "#888888",
16
- padding: "8px 12px",
17
- minHeight: "38px",
18
- textTransform: "none",
19
- minWidth: "unset",
20
- whiteSpace: "nowrap",
21
-
22
- "&.Mui-selected": {
23
- color: "#0e0c0b",
24
- fontWeight: 700,
25
- },
26
- },
27
-
28
- tabCount: {
29
- padding: "2px 3px",
30
- borderRadius: "6px",
31
- border: "1px solid #0E0C0BE6",
32
- color: "#0E0C0B",
33
- },
34
- };