rez-table-listing-mui 1.3.9 → 1.3.11

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.9",
3
+ "version": "1.3.11",
4
4
  "type": "module",
5
5
  "description": "A rez table listing component built on TanStack Table",
6
6
  "main": "dist/index.js",
@@ -39,22 +39,20 @@ const SavedFilter = ({
39
39
  return () => {
40
40
  const editModeFromTabOptions =
41
41
  filterComponentOptions?.tabOptions?.savedFilter?.editMode;
42
-
43
- setFilterMaster(
44
- (prev) =>
45
- ({
46
- ...prev,
47
- saved_filters: {
48
- ...prev?.attributes,
49
- selectedId: "",
50
- selectedName: "",
51
- selectedCode: "",
52
- },
53
- } as FilterMasterStateProps)
54
- );
55
-
56
42
  if (!editModeFromTabOptions) {
57
43
  setEditMode && setEditMode(false);
44
+ setFilterMaster(
45
+ (prev) =>
46
+ ({
47
+ ...prev,
48
+ saved_filters: {
49
+ ...prev?.attributes,
50
+ selectedId: "",
51
+ selectedName: "",
52
+ selectedCode: "",
53
+ },
54
+ } as FilterMasterStateProps)
55
+ );
58
56
  }
59
57
  };
60
58
  }, []);
@@ -5,7 +5,6 @@ import {
5
5
  FilterComponentOptions,
6
6
  FilterDrawerProps,
7
7
  FilterMasterStateProps,
8
- TabType,
9
8
  } from "../../types/filter";
10
9
  import ConfirmModal, { InputField } from "../common/confirm-modal";
11
10
  import CustomTabPanel from "./components/tabs/custom-tab-panel";
@@ -89,10 +88,10 @@ export function TableFilter({
89
88
  }, [editModeFromTabOptions]);
90
89
 
91
90
  // Map tabs to type
92
- const tabMapping: TabType[] = [];
93
- if (showMainFilter) tabMapping.push("main");
94
- if (showSavedFilter) tabMapping.push("saved");
95
- if (showAttributesFilter) tabMapping.push("attributes");
91
+ const tabMapping: TabItem[] = [];
92
+ if (showMainFilter) tabMapping.push({ label: "Filter" });
93
+ if (showSavedFilter) tabMapping.push({ label: "Saved Filter" });
94
+ if (showAttributesFilter) tabMapping.push({ label: "Attributes" });
96
95
 
97
96
  const clearAttributeRadio = () => {
98
97
  const newFilterMaster = {
@@ -114,23 +113,16 @@ export function TableFilter({
114
113
  type: "text",
115
114
  };
116
115
 
117
- //FOR TABS
118
- const tabItems: TabItem[] = [
119
- { label: "Filter" },
120
- { label: "Saved Filter" },
121
- { label: "Attributes" },
122
- ];
123
-
124
116
  const handleTabChange = (_: React.SyntheticEvent, newValue: number) => {
125
- const tabType = tabMapping[newValue];
117
+ const tabType = tabMapping[newValue]?.label;
126
118
 
127
- if (tabType === "attributes" && tabMapping[tabValue] === "main") {
119
+ if (tabType === "Attributes" && tabMapping[tabValue]?.label === "Filter") {
128
120
  clearAttributeRadio();
129
121
  }
130
122
 
131
123
  setTabValue(newValue);
132
124
 
133
- if (tabType === "main") {
125
+ if (tabType === "Filter") {
134
126
  setEditMode(false);
135
127
 
136
128
  setFilterMaster(
@@ -145,17 +137,17 @@ export function TableFilter({
145
137
 
146
138
  setFilters([]);
147
139
 
148
- if (tabType === "saved") setEditMode(false);
140
+ if (tabType?.label === "Saved Filter") setEditMode(false);
149
141
 
150
142
  const patches: Partial<FilterMasterStateProps> = {};
151
143
 
152
- if (tabType === "saved") {
144
+ if (tabType?.label === "Saved Filter") {
153
145
  patches.saved_filters = {
154
146
  selectedId: "",
155
147
  selectedName: "",
156
148
  selectedCode: "",
157
149
  };
158
- } else if (tabType === "attributes") {
150
+ } else if (tabType?.label === "Attributes") {
159
151
  patches.attributes = { radio: [], selected: "" };
160
152
  }
161
153
 
@@ -214,7 +206,7 @@ export function TableFilter({
214
206
  <CustomTabs
215
207
  value={tabValue}
216
208
  onChange={handleTabChange}
217
- tabItems={tabItems}
209
+ tabItems={tabMapping}
218
210
  activeFilterIndex={filterMaster?.activeFilterTabIndex ?? 0}
219
211
  handleCrossClick={handleTabCrossClick}
220
212
  />
@@ -233,7 +225,7 @@ export function TableFilter({
233
225
  {showMainFilter && (
234
226
  <CustomTabPanel
235
227
  value={tabValue}
236
- index={tabMapping.indexOf("main")}
228
+ index={tabMapping.findIndex((tab) => tab.label === "Filter")}
237
229
  sx={{ p: "1.5rem 0.75rem" }}
238
230
  >
239
231
  <MainFilter
@@ -247,7 +239,7 @@ export function TableFilter({
247
239
  {showSavedFilter && (
248
240
  <CustomTabPanel
249
241
  value={tabValue}
250
- index={tabMapping.indexOf("saved")}
242
+ index={tabMapping.findIndex((tab) => tab.label === "Saved Filter")}
251
243
  sx={{ p: "1.5rem 0.75rem" }}
252
244
  >
253
245
  <SavedFilter
@@ -262,7 +254,7 @@ export function TableFilter({
262
254
  {showAttributesFilter && (
263
255
  <CustomTabPanel
264
256
  value={tabValue}
265
- index={tabMapping.indexOf("attributes")}
257
+ index={tabMapping.findIndex((tab) => tab.label === "Attributes")}
266
258
  sx={{ p: "1.5rem 0.75rem" }}
267
259
  >
268
260
  <AttributesFilter
@@ -21,6 +21,7 @@ import {
21
21
  saveSettingsData,
22
22
  updateSavedFilter,
23
23
  viewSettingsDropDown,
24
+ getOperationList,
24
25
  } from "../utils/apiColumn";
25
26
  import {
26
27
  FilterDataMainFilterEntityListProps,
@@ -355,3 +356,13 @@ export const useGetFilterEntityListAndCriteria = ({
355
356
 
356
357
  return { filterEntityList, filterEntityWiseCriteria };
357
358
  };
359
+
360
+ export const useGetOperationList = () => {
361
+ // First query to get meta data
362
+ const operationList = useQuery({
363
+ queryKey: ["operationList"],
364
+ queryFn: () => getOperationList(),
365
+ });
366
+
367
+ return { operationList };
368
+ };
@@ -185,3 +185,8 @@ export const getFilterCriteriaByEntity = async (
185
185
 
186
186
  return response.data;
187
187
  };
188
+
189
+ export const getOperationList = async () => {
190
+ const response = await api.post(`/meta/operation-list`);
191
+ return response.data;
192
+ };
@@ -0,0 +1,26 @@
1
+ import { FilterStateProps, OperationList } from "../../types/filter";
2
+
3
+ export const hydrateSavedFilters = async (
4
+ savedFilters: FilterStateProps[],
5
+ operationList: OperationList
6
+ ) => {
7
+ return savedFilters.map((filter) => {
8
+ // const attribute = tableStates..find(
9
+ // (attr) => attr.attribute_key === filter.filter_attribute
10
+ // );
11
+ if (typeof filter.filter_attribute_data_type === "undefined") {
12
+ return {
13
+ ...filter,
14
+ dropdown_list: [],
15
+ };
16
+ }
17
+
18
+ const matchingDropdownList =
19
+ operationList[filter.filter_attribute_data_type] || [];
20
+
21
+ return {
22
+ ...filter,
23
+ dropdown_list: matchingDropdownList,
24
+ };
25
+ });
26
+ };
@@ -101,7 +101,7 @@ type RecordFilterComponentProps = {
101
101
  delete: ModalConfig;
102
102
  };
103
103
 
104
- export type TabType = "main" | "saved" | "attributes";
104
+ type TabType = "main" | "saved" | "attributes";
105
105
 
106
106
  interface FilterComponentTabOptions {
107
107
  mainFilter?: FilterComponentOptionsMainFilterOptions;
@@ -194,6 +194,20 @@ export interface FilterStateProps {
194
194
  datasource_list?: string | null;
195
195
  }
196
196
 
197
+ export interface OperationOption {
198
+ label: string;
199
+ value: string;
200
+ }
201
+
202
+ export interface OperationList {
203
+ text: OperationOption[];
204
+ number: OperationOption[];
205
+ date: OperationOption[];
206
+ select: OperationOption[];
207
+ multiselect: OperationOption[];
208
+ year: OperationOption[];
209
+ }
210
+
197
211
  export interface createSavedFilterPayload {
198
212
  name: string;
199
213
  organization_id?: number;
@@ -10,6 +10,7 @@ import { ENTITY_TYPE, MAPPED_ENTITY_TYPE } from "../listing/libs/utils/common";
10
10
  import {
11
11
  useCommonFilterDropdownAPI,
12
12
  useEntityTableAPI,
13
+ useGetOperationList,
13
14
  useGetSettingsDataAPI,
14
15
  useSaveSettingsDataAPI,
15
16
  useSettingsDropDownAPI,
@@ -22,6 +23,7 @@ import { TableTabs } from "../listing/components/tabs";
22
23
  import { QuickFilterSettings } from "../listing/components/table-settings";
23
24
  import CraftTableFilterWrapper from "./FIlterWrapper";
24
25
  import { saveLayoutAPI } from "../listing/libs/services/saveLayoutAPI";
26
+ import { hydrateSavedFilters } from "../listing/libs/utils/hydrate-saved-filters";
25
27
 
26
28
  function ListingView() {
27
29
  // const [mockLoading, setMockLoading] = useState<boolean>(true);
@@ -49,6 +51,7 @@ function ListingView() {
49
51
  : metaQuery?.data?.default_filter?.value
50
52
  );
51
53
  const { saveSettingsDataMutation } = useSaveSettingsDataAPI(ENTITY_TYPE);
54
+ const { operationList } = useGetOperationList();
52
55
 
53
56
  // const { dropdownData } = useCommonDropdownAPI(
54
57
  // dropdownColumnList || metaQuery.data.column_list
@@ -139,8 +142,23 @@ function ListingView() {
139
142
  fetchMeta();
140
143
  }, [selectedTab]);
141
144
 
145
+ // useEffect(() => {
146
+ // setFilters(detailsQuery.data ?? []);
147
+ // }, [detailsQuery.data]);
148
+
142
149
  useEffect(() => {
143
- setFilters(detailsQuery.data ?? []);
150
+ const setFilterDropdown = async () => {
151
+ if (Array.isArray(detailsQuery.data)) {
152
+ const hydrated = await hydrateSavedFilters(
153
+ detailsQuery.data,
154
+ operationList.data
155
+ );
156
+ setFilters(hydrated);
157
+ } else {
158
+ setFilters([]);
159
+ }
160
+ };
161
+ setFilterDropdown();
144
162
  }, [detailsQuery.data]);
145
163
 
146
164
  useEffect(() => {
@@ -307,7 +325,7 @@ function ListingView() {
307
325
  onChangeFunction={handleChangeFunction}
308
326
  filterComponentOptions={{
309
327
  showMainHeader: false,
310
- showTabs: false,
328
+ showTabs: true,
311
329
  isRuleEngine: true,
312
330
  tabOptions: {
313
331
  mainFilter: {