rez-table-listing-mui 1.2.4 → 1.2.6

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.2.4",
3
+ "version": "1.2.6",
4
4
  "type": "module",
5
5
  "description": "A rez table listing component built on TanStack Table",
6
6
  "main": "dist/index.js",
@@ -30,7 +30,7 @@ const AttributesFilter = ({
30
30
  const currentFilterValue = useMemo(() => {
31
31
  if (!selectedAttribute) return [];
32
32
 
33
- const matchingColumn = columnsData.column_list.find(
33
+ const matchingColumn = columnsData?.column_list?.find(
34
34
  (column) => column.datasource_list === selectedAttribute
35
35
  );
36
36
 
@@ -65,7 +65,7 @@ const AttributesFilter = ({
65
65
  const selectedAttr = filterMaster?.attributes.selected;
66
66
  if (!selectedAttr) return;
67
67
 
68
- const matchingColumn = columnsData.column_list.find(
68
+ const matchingColumn = columnsData?.column_list?.find(
69
69
  (column) => column.datasource_list === selectedAttr
70
70
  );
71
71
  if (!matchingColumn) return;
@@ -53,13 +53,13 @@ export function TableFilter({
53
53
  };
54
54
 
55
55
  useEffect(() => {
56
- if (!columnsData || !columnsData.column_list) {
56
+ if (!columnsData || !columnsData?.column_list) {
57
57
  setSelectedFilters([]);
58
58
  return;
59
59
  }
60
60
 
61
61
  const updated = filters?.map((filter) => {
62
- const matchingColumn = columnsData.column_list.find(
62
+ const matchingColumn = columnsData?.column_list.find(
63
63
  (column) => column.attribute_key === filter.filter_attribute
64
64
  );
65
65
  const matchingDropdownList =
@@ -123,7 +123,7 @@ function TableWrapper<T>({
123
123
  showChangeLayoutToggle: true,
124
124
  viewMoreToggle: true,
125
125
  showSearch: true,
126
- showSortingToggle: true,
126
+ showSortingToggle: false,
127
127
  showFilterToggle: true,
128
128
  tableStates,
129
129
 
@@ -1,16 +1,13 @@
1
1
  .pagination_container {
2
2
  --grey-300: #edeeef;
3
3
 
4
- // box-shadow: 0 -2px 2px rgba(0, 0, 0, 0.05);
5
4
  padding: 8px;
6
5
  display: flex;
7
6
  justify-content: flex-end;
8
7
  align-items: center;
9
- gap: 1.5rem;
8
+ gap: 1rem;
10
9
  font-size: 0.875rem;
11
- // border-top: 1px solid var(--grey-300);
12
10
  background-color: #fff;
13
- margin-bottom: 0.5rem;
14
11
 
15
12
  @media screen and (max-width: 991px) {
16
13
  justify-content: center;
@@ -61,21 +61,6 @@ const TableSearch = ({ value, onChange }: TableSearchProps): JSX.Element => {
61
61
  top: "10px",
62
62
  }}
63
63
  >
64
- {/* <Box
65
- className="search-icon ts--button"
66
- onClick={() => {
67
- setShowSearchInput((prev) => !prev);
68
- if (!showSearchInput) {
69
- // Focus input when showing
70
- setTimeout(() => {
71
- searchContainerRef.current?.querySelector("input")?.focus();
72
- }, 100);
73
- }
74
- }}
75
- >
76
- <SearchIcon />
77
- </Box> */}
78
-
79
64
  <TextField
80
65
  type="text"
81
66
  placeholder="Search"
@@ -137,136 +137,6 @@ const QuickTab = ({
137
137
  }
138
138
  }, [quickTabStates?.hide_list, quickTabStates?.show_list]);
139
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
142
-
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]);
239
-
240
- // useEffect(() => {
241
- // setQuickTabStates((prev) => ({
242
- // ...prev,
243
- // hide_list: tabsApiData, // All data goes to hide_list initially
244
- // show_list: [], // Empty the show_list when attribute/sorting changes
245
- // }));
246
- // }, [tabsApiData, quickTabStates.attribute, quickTabStates.sorting]);
247
-
248
- // if (!Object.entries(quickTabStates).length) {
249
- // // Logic for column
250
- // setColumnTabState((prev) => ({ ...prev, isDefault: true }));
251
- // // Logic for sorting
252
- // setSortingTabState((prev) => ({ ...prev, isDefault: true, tabs: [] }));
253
- // } else {
254
- // // Logic for sorting
255
- // if (!sortingTabState.tabs?.length) {
256
- // const emptySortBy: SortingConfigSortByProps[] = [
257
- // { column: "", order: "asc" },
258
- // ];
259
- // setSortingTabState((prev) => ({
260
- // ...prev,
261
- // tabs: quickTabStates?.show_list?.map((tab) => ({
262
- // tab_name: tab,
263
- // sortby: emptySortBy,
264
- // })),
265
- // }));
266
- // }
267
- // }
268
- // }, [quickTabStates]);
269
-
270
140
  const sortingOptions = [
271
141
  { label: "A-Z", value: "asc" },
272
142
  { label: "Z-A", value: "dsc" },
@@ -262,7 +262,7 @@ const Sorting = ({
262
262
  showList:
263
263
  columnTabState?.show_list ||
264
264
  // if columns isDefault and show_list is empty, show all columns
265
- columnsData?.column_list.map((column) => ({
265
+ columnsData?.column_list?.map((column) => ({
266
266
  label: column.name,
267
267
  value: column.attribute_key,
268
268
  })) ||
@@ -1,9 +1,9 @@
1
1
  import "./index.scss";
2
- import { formatClassName } from "../../libs/utils/common";
3
- import { CircularProgress, IconButton } from "@mui/material";
2
+ import { Box, CircularProgress, IconButton, Tab, Tabs } from "@mui/material";
4
3
  import { CraftTableOptionsProps } from "../../types/table-options";
5
4
  import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined";
6
5
  import { settingsOptionsProps } from "../../types/table";
6
+ import { tableTabsStyles } from "./styles";
7
7
 
8
8
  interface TabDataProps {
9
9
  tab_value: string | null;
@@ -28,50 +28,70 @@ export function TableTabs({
28
28
  tableStates,
29
29
  settingsOptions,
30
30
  }: TableTabsProps) {
31
+ if (loading) return <CircularProgress size={24} />;
32
+
31
33
  const handleTabClick = (tab: string) => {
32
34
  onClick(tab);
33
35
  tableStates.setPagination((prev) => ({ ...prev, pageIndex: 0 }));
34
36
  };
35
37
 
36
38
  // Normalize tab_value to uppercase for display + logic
37
- const normalizedTabs = tabsData.map((tab) => ({
38
- ...tab,
39
- tab_value: tab.tab_value?.toUpperCase() ?? "UNKNOWN",
40
- }));
39
+ const normalizedTabs = tabsData
40
+ ?.filter((tab) => tab.tab_value)
41
+ ?.map((tab) => ({
42
+ ...tab,
43
+ tab_value: tab.tab_value,
44
+ }));
41
45
 
42
46
  return (
43
- <div className="table-tabs">
44
- {loading ? (
45
- <div className="tabs-loader">
46
- <CircularProgress size={24} />
47
- </div>
48
- ) : (
49
- <div className="tabs">
50
- {settingsOptions?.showIcon && (
51
- <IconButton
52
- onClick={settingsOptions?.onClick}
53
- style={{ zIndex: 1000 }}
54
- >
55
- <SettingsOutlinedIcon />
56
- </IconButton>
57
- )}
58
-
59
- <ul className="tabs">
60
- {normalizedTabs.map(({ tab_value, tab_value_count }) => (
61
- <li
62
- key={tab_value}
63
- className={formatClassName(
64
- `tab ${activeTab === tab_value ? "active" : ""}`
65
- )}
66
- onClick={() => handleTabClick(tab_value)}
67
- >
68
- <span className="tab__label">{tab_value}</span>
69
- <span className="count">{tab_value_count}</span>
70
- </li>
71
- ))}
72
- </ul>
73
- </div>
47
+ <Box display="flex" alignItems="center" justifyContent="flex-start">
48
+ {/* Layout settings icon */}
49
+ {settingsOptions?.showIcon && (
50
+ <IconButton
51
+ onClick={settingsOptions?.onClick}
52
+ sx={{ zIndex: 1000, mx: 1 }}
53
+ >
54
+ <SettingsOutlinedIcon />
55
+ </IconButton>
74
56
  )}
75
- </div>
57
+
58
+ {/* Tabs */}
59
+ <Tabs
60
+ value={activeTab}
61
+ onChange={(_, newValue) => handleTabClick(newValue)}
62
+ variant="scrollable"
63
+ scrollButtons={false}
64
+ slotProps={{ indicator: { sx: { display: "none" } } }}
65
+ sx={tableTabsStyles.tabs}
66
+ >
67
+ {normalizedTabs.map(({ tab_value, tab_value_count }) => {
68
+ const isSelected = activeTab === tab_value;
69
+
70
+ return (
71
+ <Tab
72
+ key={tab_value}
73
+ value={tab_value}
74
+ label={
75
+ <Box display="flex" alignItems="center" gap={1}>
76
+ <Box>{tab_value}</Box>
77
+ <Box
78
+ sx={{
79
+ ...tableTabsStyles.tabCount,
80
+ ...(isSelected && {
81
+ backgroundColor: "#ced3da",
82
+ borderColor: "#ced3da",
83
+ }),
84
+ }}
85
+ >
86
+ {tab_value_count}
87
+ </Box>
88
+ </Box>
89
+ }
90
+ sx={tableTabsStyles.tab}
91
+ />
92
+ );
93
+ })}
94
+ </Tabs>
95
+ </Box>
76
96
  );
77
97
  }
@@ -0,0 +1,33 @@
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 6px",
30
+ borderRadius: "4px",
31
+ border: "1px solid #888",
32
+ },
33
+ };
@@ -3,17 +3,23 @@
3
3
  display: flex;
4
4
  justify-content: space-between;
5
5
  align-items: center;
6
- // min-height: 2.5rem;
7
6
  background-color: #fff;
8
7
 
8
+ .tabs-section {
9
+ flex: 1 1 auto; // allow tabs to grow and shrink
10
+ min-width: 0; // important to allow shrinking
11
+ overflow: hidden; // prevent overflow
12
+ }
13
+
9
14
  .right-section {
10
15
  display: flex;
11
16
  justify-content: center;
12
- // gap: 0.4rem; // All icons gap
17
+ flex-shrink: 0;
18
+
13
19
  .search-wrapper {
14
20
  display: flex;
15
21
  align-items: center;
16
- justify-content: flex-end; //
22
+ justify-content: flex-end;
17
23
  position: relative;
18
24
  margin-right: 0.1rem;
19
25
 
@@ -26,33 +32,6 @@
26
32
  // z-index: 2;
27
33
  margin-bottom: 1.2rem;
28
34
  }
29
-
30
- // .search-input {
31
- // width: 0;
32
- // opacity: 0;
33
- // margin-left: 8px;
34
- // padding: 6px 8px;
35
- // font-size: 0.875rem;
36
- // border: 1px solid #ccc;
37
- // border-radius: 4px;
38
- // background-color: #f5f5f5;
39
- // color: #000;
40
- // transition: width 0.3s ease, opacity 0.3s ease;
41
- // // position: absolute;
42
- // // right: 40px;
43
- // // top: 50%;
44
- // // transform: translateY(-50%);
45
-
46
- // &:focus {
47
- // outline: none;
48
- // border-color: #000;
49
- // }
50
- // }
51
-
52
- // .search-input.expanded {
53
- // width: 200px;
54
- // opacity: 1;
55
- // }
56
35
  }
57
36
 
58
37
  .ts--button {
@@ -70,15 +49,6 @@
70
49
  margin-top: 1rem;
71
50
  }
72
51
 
73
- // .add-new-button {
74
- // margin-right: 0.9rem;
75
- // margin-bottom: 0.5rem;
76
- // border-radius: 2px;
77
- // // padding: 4px 14px;
78
- // background-color: #505050;
79
- // cursor: pointer;
80
- // }
81
-
82
52
  .fullscreen-toggle {
83
53
  margin-right: 0.5rem;
84
54
  margin-top: 0.9rem;
@@ -107,13 +107,13 @@ function Topbar<T>({
107
107
  handler: () => setShowSearchInput(false),
108
108
  });
109
109
 
110
- // const handleFilterDrawer = () => {
111
- // setShowFilterInput((prev) => !prev);
112
- // };
113
-
114
110
  return (
115
111
  <div className="ts-topbar">
116
- <div className="tabs-section">{leftSideComponent}</div>
112
+ <div className="tabs-section">
113
+ <div style={{ overflowX: "auto", whiteSpace: "nowrap" }}>
114
+ {leftSideComponent}
115
+ </div>
116
+ </div>
117
117
 
118
118
  <div className="right-section">
119
119
  {rightSideComponent}
@@ -13,140 +13,7 @@ export function useCraftTableFilterSettings() {
13
13
  const [showListViewSettings, setShowListViewSettings] =
14
14
  useState<boolean>(false);
15
15
 
16
- const [settingsData, setSettingsData] = useState<SettingsDataProps>({
17
- // quick_tab: {
18
- // attribute: "status",
19
- // sorting: "asc",
20
- // hide_list: ["active", "inactive", "pending"],
21
- // show_list: [],
22
- // isAllSelected: true,
23
- // isCombineOther: false,
24
- // },
25
- // column: {
26
- // isDefault: true,
27
- // show_list: [
28
- // {
29
- // label: "Customer Name",
30
- // value: "customer_name",
31
- // },
32
- // {
33
- // label: "Customer ID",
34
- // value: "customer_id",
35
- // },
36
- // ],
37
- // hide_list: [
38
- // {
39
- // label: "Email",
40
- // value: "email",
41
- // },
42
- // {
43
- // label: "Phone",
44
- // value: "phone",
45
- // },
46
- // ],
47
- // tabs: [
48
- // {
49
- // tab_name: "Active",
50
- // show_list: [
51
- // {
52
- // label: "Customer Name",
53
- // value: "customer_name",
54
- // },
55
- // {
56
- // label: "Status",
57
- // value: "status",
58
- // },
59
- // ],
60
- // hide_list: [
61
- // {
62
- // label: "Email",
63
- // value: "email",
64
- // },
65
- // ],
66
- // },
67
- // {
68
- // tab_name: "Inactive",
69
- // show_list: [
70
- // {
71
- // label: "Customer ID",
72
- // value: "customer_id",
73
- // },
74
- // {
75
- // label: "Status",
76
- // value: "status",
77
- // },
78
- // ],
79
- // hide_list: [
80
- // {
81
- // label: "Phone",
82
- // value: "phone",
83
- // },
84
- // ],
85
- // },
86
- // {
87
- // tab_name: "Pending",
88
- // show_list: [
89
- // {
90
- // label: "Customer Name",
91
- // value: "customer_name",
92
- // },
93
- // {
94
- // label: "Customer ID",
95
- // value: "customer_id",
96
- // },
97
- // ],
98
- // hide_list: [
99
- // {
100
- // label: "Email",
101
- // value: "email",
102
- // },
103
- // {
104
- // label: "Phone",
105
- // value: "phone",
106
- // },
107
- // ],
108
- // },
109
- // ],
110
- // },
111
- // sorting: {
112
- // isDefault: true,
113
- // sortby: [
114
- // {
115
- // column: "customer_id",
116
- // order: "asc",
117
- // },
118
- // ],
119
- // tabs: [
120
- // {
121
- // tab_name: "active",
122
- // sortby: [
123
- // {
124
- // column: "customer_name",
125
- // order: "asc",
126
- // },
127
- // ],
128
- // },
129
- // {
130
- // tab_name: "inactive",
131
- // sortby: [
132
- // {
133
- // column: "customer_id",
134
- // order: "desc",
135
- // },
136
- // ],
137
- // },
138
- // {
139
- // tab_name: "pending",
140
- // sortby: [
141
- // {
142
- // column: "status",
143
- // order: "asc",
144
- // },
145
- // ],
146
- // },
147
- // ],
148
- // },
149
- });
16
+ const [settingsData, setSettingsData] = useState<SettingsDataProps>({});
150
17
 
151
18
  // Quick FIlter settings local states
152
19
 
@@ -77,14 +77,23 @@ export function customDebounce<T extends (...args: any[]) => any>(
77
77
  }
78
78
 
79
79
  //ENTITY TYPE
80
+ const ENVIRONMENT = "adm_dev";
80
81
  export const ENTITY_TYPE = "ROL";
81
82
 
83
+ const environments = {
84
+ adm_dev: "http://localhost:4010/api",
85
+ crm_dev: "http://localhost:4011/api",
86
+ uat: "http://13.200.182.92:4010/api",
87
+ };
88
+
89
+ const getBaseUrl = () => environments[ENVIRONMENT]
90
+
82
91
  // uat http://13.200.182.92:4010/api
83
92
  // local http://localhost:4010/api
84
93
 
85
94
  // API INTEGRATION
86
95
  export const api = axios.create({
87
- baseURL: "http://localhost:4010/api",
96
+ baseURL: getBaseUrl(),
88
97
  timeout: 10000,
89
98
  headers: {
90
99
  "Content-Type": "application/json",