rez-table-listing-mui 1.0.49 → 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 (30) hide show
  1. package/dist/index.d.ts +5 -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 +78 -33
  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 +175 -66
  9. package/src/components/filter/components/forms/components/Dropdown.tsx +36 -3
  10. package/src/components/filter/components/forms/components/Filter-criteria.tsx +1 -1
  11. package/src/components/filter/components/forms/components/Multi-Select.tsx +62 -34
  12. package/src/components/filter/components/forms/index.tsx +20 -2
  13. package/src/components/filter/components/saved-filter.tsx +63 -9
  14. package/src/components/filter/index.tsx +3 -3
  15. package/src/components/filter/style.ts +1 -1
  16. package/src/components/index.scss +1 -1
  17. package/src/components/table-settings/common/info-alert.tsx +37 -0
  18. package/src/components/table-settings/common/listing-values.tsx +63 -48
  19. package/src/components/table-settings/components/column.tsx +210 -170
  20. package/src/components/table-settings/components/quick-tab.tsx +277 -153
  21. package/src/components/table-settings/components/sorting.tsx +135 -109
  22. package/src/components/table-settings/components/toggle-button-switch.tsx +2 -2
  23. package/src/components/table-settings/index.tsx +3 -5
  24. package/src/components/table-settings/style.ts +1 -0
  25. package/src/components/topbar/index.tsx +3 -1
  26. package/src/libs/hooks/useEntityTableAPI.tsx +1 -16
  27. package/src/libs/utils/apiColumn.ts +1 -11
  28. package/src/libs/utils/common.ts +4 -3
  29. package/src/types/filter-settings.ts +11 -0
  30. package/src/types/filter.ts +1 -2
@@ -9,11 +9,11 @@ import {
9
9
  Typography,
10
10
  } from "@mui/material";
11
11
  import {
12
+ ColumnTabConfigProps,
12
13
  SettingsSortingProps,
13
14
  SortingConfigProps,
14
15
  SortingConfigSortByProps,
15
16
  } from "../../../types/filter-settings";
16
- import CustomToggleSwitchButton from "./toggle-button-switch";
17
17
  import CustomTabs from "../tabs/horizontal";
18
18
  import {
19
19
  closestCenter,
@@ -29,69 +29,92 @@ import {
29
29
  verticalListSortingStrategy,
30
30
  } from "@dnd-kit/sortable";
31
31
  import { AddIcon, CloseIcon } from "../../../assets/svg";
32
- import { TOGGLE_BUTTON_TABS } from "../constants";
33
32
 
34
33
  const Sorting = ({
35
34
  filterSettingStates,
36
35
  columnsData,
37
36
  }: SettingsSortingProps) => {
38
- const {
39
- quickTabStates,
40
- sortingTabState,
41
- setSortingTabState,
42
- saveButtonError,
43
- setSaveButtonError,
44
- columnTabState,
45
- } = filterSettingStates;
37
+ const { quickTabStates, saveButtonError, settingsData, setSettingsData } =
38
+ filterSettingStates;
46
39
 
47
40
  const [activeTab, setActiveTab] = useState<string | undefined>(
48
41
  quickTabStates?.show_list?.[0]
49
42
  );
50
43
 
44
+ const columnTabState = settingsData?.column as ColumnTabConfigProps;
45
+ const sortingTabState = settingsData?.sorting as SortingConfigProps;
51
46
  const isSortingDefault = sortingTabState?.isDefault;
52
47
 
48
+ const isStateEmpty = useMemo(() => {
49
+ return !sortingTabState || Object.entries(sortingTabState).length === 0;
50
+ }, [sortingTabState]);
51
+
52
+ const isEmptyDefault = useMemo(() => {
53
+ return !isStateEmpty && !sortingTabState?.sortby?.length;
54
+ }, [isStateEmpty, sortingTabState]);
55
+
56
+ const ERROR_CODE = "sorting_error";
57
+
53
58
  useEffect(() => {
54
- // Render empty columns
55
59
  const emptySortBy: SortingConfigSortByProps[] = [
56
60
  { column: "", order: "asc" },
57
61
  ];
58
62
 
59
- const mappedQuickTabs =
60
- quickTabStates?.show_list?.map((tab) => ({
61
- tab_name: tab,
62
- sortby: emptySortBy,
63
- })) || [];
64
-
65
- if (!Object.entries(sortingTabState)?.length) {
66
- // Create a new default sorting state
67
- const newSortingState: SortingConfigProps = {
68
- isDefault: true,
69
- sortby: emptySortBy,
70
- tabs: mappedQuickTabs,
71
- };
63
+ if (isStateEmpty) {
64
+ setSettingsData((prev) => ({
65
+ ...prev,
66
+ sorting: {
67
+ isDefault: true,
68
+ sortby: emptySortBy,
69
+ },
70
+ }));
72
71
 
73
- setSaveButtonError((prev) => ({
72
+ console.log("sorting is empty");
73
+ } else if (isEmptyDefault) {
74
+ setSettingsData((prev) => ({
74
75
  ...prev,
75
- hasError: true,
76
- messages: [
77
- ...saveButtonError?.messages,
78
- { type: "sorting_error", message: "Please select a column" },
79
- ],
76
+ sorting: {
77
+ ...prev.sorting,
78
+ isDefault: true,
79
+ },
80
80
  }));
81
81
 
82
- setActiveTab(newSortingState?.tabs?.[0]?.tab_name);
83
- setSortingTabState(newSortingState);
82
+ if (!sortingTabState?.isDefault) {
83
+ setSettingsData((prev) => ({
84
+ ...prev,
85
+ sorting: {
86
+ ...prev.sorting,
87
+ sortby: emptySortBy,
88
+ },
89
+ }));
90
+ }
84
91
  }
92
+ }, [
93
+ isStateEmpty,
94
+ isEmptyDefault,
95
+ sortingTabState,
96
+ quickTabStates,
97
+ setSettingsData,
98
+ ]);
85
99
 
86
- // If show_list is not empty
87
- // if (quickTabStates?.show_list?.length) {
88
- // setSortingTabState((prev) => ({
89
- // ...prev,
90
- // tabs: mappedQuickTabs,
91
- // }));
92
- // setActiveTab(mappedQuickTabs?.[0]?.tab_name);
93
- // }
94
- }, [quickTabStates?.show_list]);
100
+ // sortingTabState.sortby is filtered based on columnTabState.show_list
101
+ useEffect(() => {
102
+ // filter sorting sortby based on column show list
103
+ if (columnTabState?.isDefault) {
104
+ setSettingsData((prev) => ({
105
+ ...prev,
106
+ sorting: {
107
+ ...prev.sorting,
108
+ // remove sortby items that are not in column show list
109
+ sortby: prev.sorting?.sortby?.filter((item) =>
110
+ columnTabState?.show_list?.some(
111
+ (columnItem) => columnItem.value === item.column
112
+ )
113
+ ),
114
+ },
115
+ }));
116
+ }
117
+ }, [columnTabState?.show_list]);
95
118
 
96
119
  const sensors = useSensors(useSensor(PointerSensor));
97
120
 
@@ -116,20 +139,22 @@ const Sorting = ({
116
139
  ? sortingTabState?.sortby
117
140
  : activeTab !== undefined
118
141
  ? sortingTabState?.tabs?.[activeTabIndex || 0]?.sortby
142
+ ? sortingTabState?.tabs?.[activeTabIndex || 0]?.sortby
143
+ : []
119
144
  : [];
120
145
  }, [sortingTabState, activeTab]);
121
146
 
122
147
  const updateSortList = (updated: SortingConfigSortByProps[]) => {
123
- setSortingTabState((prev) => {
124
- if (prev.isDefault) {
125
- return { ...prev, sortby: updated };
148
+ setSettingsData((prev) => {
149
+ if (prev?.sorting?.isDefault) {
150
+ return { ...prev, sorting: { ...prev?.sorting, sortby: updated } };
126
151
  } else {
127
- const tabs = [...(prev.tabs || [])];
152
+ const tabs = [...(prev?.sorting?.tabs || [])];
128
153
  tabs[activeTabIndex || 0] = {
129
154
  ...tabs[activeTabIndex || 0],
130
155
  sortby: updated,
131
156
  };
132
- return { ...prev, tabs };
157
+ return { ...prev, sorting: { ...prev?.sorting, tabs } };
133
158
  }
134
159
  });
135
160
  };
@@ -141,20 +166,6 @@ const Sorting = ({
141
166
  ) => {
142
167
  if (!tabSortedList) return;
143
168
 
144
- // Check if sorting_error exists
145
- // If it does, remove it
146
- if (key === "column") {
147
- const otherErrors = saveButtonError?.messages?.filter(
148
- (error) => error.type !== "sorting_error"
149
- );
150
-
151
- setSaveButtonError((prev) => ({
152
- ...prev,
153
- hasError: otherErrors.length > 0,
154
- messages: otherErrors,
155
- }));
156
- }
157
-
158
169
  const updated = [...tabSortedList];
159
170
  updated[index] = { ...updated[index], [key]: value };
160
171
  updateSortList(updated);
@@ -168,15 +179,6 @@ const Sorting = ({
168
179
  order: "asc",
169
180
  };
170
181
 
171
- setSaveButtonError((prev) => ({
172
- ...prev,
173
- hasError: true,
174
- messages: [
175
- ...saveButtonError?.messages,
176
- { type: "sorting_error", message: "Please select a column" },
177
- ],
178
- }));
179
-
180
182
  updateSortList([...tabSortedList, newItem]);
181
183
  };
182
184
 
@@ -185,23 +187,6 @@ const Sorting = ({
185
187
 
186
188
  const updated = tabSortedList.filter((item) => item.column !== columnKey);
187
189
  updateSortList(updated);
188
-
189
- // ! CHECK THIS LOGIC AND CHANGE AS NEEDED
190
- // check if any of the columns are empty
191
- const columnsHasEmptyValue =
192
- updated.some((item) => item.column === "") || updated.length === 0;
193
-
194
- if (columnsHasEmptyValue) {
195
- const filteredErrors = saveButtonError?.messages?.filter(
196
- (error) => error.type !== "sorting_error"
197
- );
198
-
199
- setSaveButtonError((prev) => ({
200
- ...prev,
201
- hasError: true,
202
- messages: filteredErrors,
203
- }));
204
- }
205
190
  };
206
191
 
207
192
  const handleModeChange = (
@@ -209,7 +194,13 @@ const Sorting = ({
209
194
  value: boolean
210
195
  ) => {
211
196
  if (value !== null) {
212
- setSortingTabState((prev) => ({ ...prev, isDefault: value }));
197
+ setSettingsData((prev) => ({
198
+ ...prev,
199
+ sorting: {
200
+ ...prev.sorting,
201
+ isDefault: value,
202
+ },
203
+ }));
213
204
  }
214
205
  };
215
206
 
@@ -230,20 +221,53 @@ const Sorting = ({
230
221
 
231
222
  const hasShowListQuickTabs =
232
223
  quickTabStates?.show_list?.length !== 0 || isSortingDefault ? true : false;
233
- const showAddSortButton =
234
- tabSortedList?.length !== columnsData?.column_list?.length;
235
224
 
225
+ /**
226
+ * ? What is happening here?
227
+ *
228
+ * If column show list is present then takes it's length
229
+ * else it takes columnsData.column_list length
230
+ *
231
+ * compare it with sortingTabState.sortby.length
232
+ *
233
+ * if both are equal then showAddSortButton is false
234
+ */
235
+ const showAddSortButton = useMemo(() => {
236
+ const stateLength =
237
+ columnTabState?.show_list?.length ??
238
+ columnsData?.column_list?.length ??
239
+ 0;
240
+ const sortLength = sortingTabState?.sortby?.length ?? 0;
241
+
242
+ return sortLength !== stateLength;
243
+ }, [columnTabState, columnsData, sortingTabState]);
244
+
245
+ /**
246
+ * ? What is happening here?
247
+ *
248
+ * Check if sorting_error exists in saveButtonError state
249
+ * Check if sortingTabState sortby column is empty
250
+ */
236
251
  const isAddSortDisabled = useMemo(() => {
237
- return saveButtonError?.messages?.some(
238
- (error) => error?.type === "sorting_error"
252
+ const hasEmptyColumn = sortingTabState?.sortby?.some(
253
+ (item) => item.column === ""
239
254
  );
240
- }, [saveButtonError]);
255
+
256
+ return hasEmptyColumn;
257
+ }, [saveButtonError, sortingTabState]);
241
258
 
242
259
  const getCurrentLists = () => {
243
260
  if (sortingTabState?.isDefault) {
244
261
  return {
245
- showList: columnTabState.show_list || [],
246
- hideList: columnTabState.hide_list || [],
262
+ showList:
263
+ columnTabState?.show_list ||
264
+ // if columns isDefault and show_list is empty, show all columns
265
+ columnsData?.column_list.map((column) => ({
266
+ label: column.name,
267
+ value: column.attribute_key,
268
+ })) ||
269
+ [],
270
+ hideList: columnTabState?.hide_list || [],
247
271
  };
248
272
  } else {
249
273
  const currentTab = columnTabState?.tabs?.[activeTabIndex || 0];
@@ -254,17 +278,17 @@ const Sorting = ({
254
278
  }
255
279
  };
256
280
 
257
- const { showList, hideList } = getCurrentLists();
281
+ const { showList } = getCurrentLists();
258
282
 
259
283
  return (
260
284
  <Box sx={{ display: "flex", flexDirection: "column", gap: "0.75rem" }}>
261
285
  <Typography>Select attribute(s) you want to sort by</Typography>
262
286
 
263
- <CustomToggleSwitchButton
287
+ {/* <CustomToggleSwitchButton
264
288
  buttons={TOGGLE_BUTTON_TABS}
265
289
  value={isSortingDefault}
266
290
  onChange={handleModeChange}
267
- />
291
+ /> */}
268
292
 
269
293
  {hasShowListQuickTabs ? (
270
294
  <>
@@ -304,17 +328,19 @@ const Sorting = ({
304
328
  size="small"
305
329
  fullWidth
306
330
  >
307
- {showList?.map((column, index) => (
308
- <MenuItem
309
- key={index}
310
- value={column.value}
311
- disabled={tabSortedList.some(
312
- (s) => s.column === column?.value
313
- )}
314
- >
315
- {column?.label}
316
- </MenuItem>
317
- ))}
331
+ {showList
332
+ ?.filter((column) => column.value != "action")
333
+ .map((column, index) => (
334
+ <MenuItem
335
+ key={index}
336
+ value={column.value}
337
+ disabled={tabSortedList.some(
338
+ (s) => s.column === column?.value
339
+ )}
340
+ >
341
+ {column?.label}
342
+ </MenuItem>
343
+ ))}
318
344
  </Select>
319
345
  <Select
320
346
  value={sort.order}
@@ -329,7 +355,7 @@ const Sorting = ({
329
355
  fullWidth
330
356
  >
331
357
  <MenuItem value="asc">Ascending</MenuItem>
332
- <MenuItem value="desc">Descending</MenuItem>
358
+ <MenuItem value="dsc">Descending</MenuItem>
333
359
  </Select>
334
360
  <IconButton
335
361
  size="small"
@@ -33,12 +33,12 @@ export default function CustomToggleSwitchButton({
33
33
  <ToggleButtonGroup exclusive size="small" color="primary" {...props}>
34
34
  {buttons.map((button) => (
35
35
  <ToggleButton
36
- key={button.label}
36
+ key={button?.label}
37
37
  value={button?.value}
38
38
  disabled={button?.isDisabled}
39
39
  sx={selectedTabStyle}
40
40
  >
41
- {button.label}
41
+ {button?.label}
42
42
  </ToggleButton>
43
43
  ))}
44
44
  </ToggleButtonGroup>
@@ -61,12 +61,10 @@ export function QuickFilterSettings({
61
61
  const copySortingTabState = sortingTabState?.isDefault
62
62
  ? {
63
63
  isDefault: true,
64
- sortby: sortingTabState?.sortby || [],
64
+ sortby:
65
+ sortingTabState?.sortby?.filter((item) => item.column !== "") || [],
65
66
  }
66
- : {
67
- isDefault: false,
68
- tabs: sortingTabState?.tabs || [],
69
- };
67
+ : null;
70
68
 
71
69
  const modifiedSettingsData = {
72
70
  quick_tab: quickTabStates,
@@ -50,6 +50,7 @@ export const listingValuesStyles: ListingValuesStyleProps = {
50
50
  borderRadius: "8px",
51
51
  minHeight: "10rem",
52
52
  backgroundColor: "#fdfdfc",
53
+ zIndex: 1,
53
54
  },
54
55
  heading: { fontWeight: 400, color: "#0E0C0BB2", fontSize: "16px" },
55
56
  button: { fontSize: "13px", textTransform: "none", color: "#0E0C0BB2" },
@@ -199,7 +199,9 @@ function Topbar<T>({
199
199
  title="Filter"
200
200
  onClick={onFilterButtonClick && onFilterButtonClick}
201
201
  >
202
- <FilterationIcon />
202
+ <FilterationIcon
203
+ color={tableStates.filters.length ? "#1C1B1F" : "#888"}
204
+ />
203
205
  </div>
204
206
  )}
205
207
 
@@ -86,7 +86,7 @@ export const useEntityTableAPI = ({
86
86
  attributeFilter = [],
87
87
  }: EntityTableAPIProps) => {
88
88
  const { data, isPending: isTableDataPending } = useQuery({
89
- queryKey: ["entityTable", page, size, tabs.value, quickFilter],
89
+ queryKey: ["entityTable", page, size, tabs, quickFilter],
90
90
  queryFn: () =>
91
91
  entityListingCall({
92
92
  page,
@@ -252,21 +252,6 @@ export const useSettingsDropDownAPI = ({
252
252
  return { settingsTabDropdownData, settingsTabDropdownPending };
253
253
  };
254
254
 
255
- // export const useSaveSettingsDataAPI = ({ payload }: any) => {
256
- // const { data: saveSettingsAPIData } = useQuery({
257
- // queryKey: ["saveSettingsData", payload],
258
- // queryFn: () =>
259
- // saveSettingsData({
260
- // entity_type: "LAP",
261
- // mapped_entity_type: "AYR",
262
- // layout_json: payload,
263
- // }),
264
- // enabled: !!payload && !!Object.entries(payload).length,
265
- // });
266
-
267
- // return { saveSettingsAPIData };
268
- // };
269
-
270
255
  export const useSaveSettingsDataAPI = (entity_type: string) => {
271
256
  const queryClient = useQueryClient();
272
257
  const saveSettingsDataMutation = useMutation({
@@ -113,7 +113,7 @@ export const updateSavedFilter = async (
113
113
  ) => {
114
114
  try {
115
115
  const response = await api.post(
116
- `/entity/update/17?entity_type=${entity_type}`,
116
+ `/entity/update/${payload?.id}?entity_type=${entity_type}`,
117
117
  payload
118
118
  );
119
119
  return response.data;
@@ -123,16 +123,6 @@ export const updateSavedFilter = async (
123
123
  }
124
124
  };
125
125
 
126
- // export const saveSettingsData = async (payload: any) => {
127
- // try {
128
- // const response = await api.post(`/layout/create`, payload);
129
- // return response.data;
130
- // } catch (error) {
131
- // console.error("Failed to save settings data:", error);
132
- // throw error;
133
- // }
134
- // };
135
-
136
126
  // ALL View Settings API
137
127
 
138
128
  export const saveSettingsData = async (payload: any) => {
@@ -76,12 +76,15 @@ export function customDebounce<T extends (...args: any[]) => any>(
76
76
  };
77
77
  }
78
78
 
79
+ //ENTITY TYPE
80
+ export const ENTITY_TYPE = "NTM";
81
+
79
82
  // uat http://13.200.182.92:4010/api
80
83
  // local http://localhost:4010/api
81
84
 
82
85
  // API INTEGRATION
83
86
  export const api = axios.create({
84
- baseURL: " http://localhost:4010/api",
87
+ baseURL: "http://localhost:4010/api",
85
88
  timeout: 10000,
86
89
  headers: {
87
90
  "Content-Type": "application/json",
@@ -100,5 +103,3 @@ api.interceptors.request.use(
100
103
  return Promise.reject(error);
101
104
  }
102
105
  );
103
-
104
- export const ENTITY_TYPE = "AYR";
@@ -65,6 +65,13 @@ export interface ColumnTabConfigProps {
65
65
  tabs?: ColumnTab[];
66
66
  }
67
67
 
68
+ export interface TabWiseConfigProps {
69
+ isDefault?: boolean;
70
+ show_list?: ColumnItem[];
71
+ hide_list?: ColumnItem[];
72
+ tabs?: ColumnTab[];
73
+ }
74
+
68
75
  export interface SettingsSortingProps {
69
76
  filterSettingStates: craftTableFilterSettingsOptionsProps;
70
77
  columnsData: FilterColumnsDataProps;
@@ -87,6 +94,10 @@ export interface SettingsQuickTabProps {
87
94
  }
88
95
 
89
96
  export interface SettingsDataProps {
97
+ isDefault?: boolean;
98
+ show_list?: ColumnItem[];
99
+ hide_list?: ColumnItem[];
100
+ tabs?: ColumnTab[];
90
101
  quick_tab?: QuickTabConfigProps;
91
102
  column?: ColumnTabConfigProps;
92
103
  sorting?: SortingConfigProps;
@@ -49,7 +49,6 @@ export interface FilterColumnsListProps {
49
49
  data_source_type: string | null;
50
50
  datasource_list: any | null;
51
51
  visible: string;
52
-
53
52
  }
54
53
 
55
54
  export interface FilterColumnsDataProps {
@@ -181,7 +180,7 @@ export interface FilterFormComponentProps {
181
180
  export interface FilterMasterStateProps {
182
181
  attributes: {
183
182
  selected: string;
184
- radio: string;
183
+ radio: string[];
185
184
  };
186
185
  saved_filters: {
187
186
  selectedId: string;