rez-table-listing-mui 2.0.14 → 2.0.15

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": "2.0.14",
3
+ "version": "2.0.15",
4
4
  "type": "module",
5
5
  "description": "A rez table listing component built on TanStack Table",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,9 @@
1
1
  import { useQueries, useQuery } from "@tanstack/react-query";
2
2
  import { getKanbanData } from "../services/service";
3
- import { commonFetchDropdownDataAPI } from "../../listing/libs/utils/apiColumn";
3
+ import {
4
+ commonFetchDropdownDataAPI,
5
+ newCommonGetDropdownDataAPI,
6
+ } from "../../listing/libs/utils/apiColumn";
4
7
 
5
8
  export const kanbanDropdownResults = (
6
9
  entity_type: string,
@@ -21,6 +24,20 @@ export const kanbanDropdownResults = (
21
24
  });
22
25
  };
23
26
 
27
+ export const useGetAttributeDropdown = (
28
+ entity_type: string,
29
+ attribute_key: string
30
+ ) =>
31
+ useQuery({
32
+ queryKey: ["commonDropdown", entity_type, attribute_key],
33
+ queryFn: () =>
34
+ newCommonGetDropdownDataAPI({
35
+ entity_type,
36
+ attribute_key,
37
+ }),
38
+ enabled: Boolean(entity_type && attribute_key),
39
+ });
40
+
24
41
  export const useGetKanbanData = (entity_type: string) => {
25
42
  const {
26
43
  data: metaData,
@@ -23,7 +23,6 @@ import {
23
23
  } from "@dnd-kit/core";
24
24
  import { TabsStyles } from "../style";
25
25
  import { craftTableFilterSettingsOptionsProps } from "../../../types/table-options";
26
- import { LANE_SELECTS } from "../constants";
27
26
 
28
27
  const Lane = ({
29
28
  filterSettingStates,
@@ -31,55 +30,92 @@ const Lane = ({
31
30
  tabsApiData,
32
31
  tabsApiDataLoading,
33
32
  selectAttributeData,
33
+ laneHideListData,
34
34
  }: {
35
35
  filterSettingStates: craftTableFilterSettingsOptionsProps;
36
36
  columnsData: any;
37
37
  tabsApiData?: { label: string; value: string }[];
38
38
  tabsApiDataLoading?: boolean;
39
39
  selectAttributeData?: { label: string; value: string }[];
40
+ laneHideListData?: { label: string; value: string }[];
40
41
  }) => {
41
- const { settingsData, setSettingsData } = filterSettingStates;
42
+ const { kanbanSettingsData, setKanbanSettingsData } = filterSettingStates;
42
43
 
43
44
  const [searchTerm, setSearchTerm] = useState<string>("");
44
- const [currentQuickAttribute, setCurrentQuickAttribute] = useState<string>(
45
- settingsData?.quick_tab?.attribute || ""
45
+ const [currentLaneAttribute, setCurrentLaneAttribute] = useState<string>(
46
+ kanbanSettingsData?.lane?.attribute || ""
46
47
  );
47
48
 
48
- const quickTabStates = settingsData?.quick_tab as any;
49
+ console.log("selectAttributeData", selectAttributeData);
49
50
 
50
51
  useEffect(() => {
51
52
  const stateToArray =
52
- (quickTabStates && Object.entries(quickTabStates)) || [];
53
+ (kanbanSettingsData?.lane && Object.entries(kanbanSettingsData?.lane)) ||
54
+ [];
53
55
  const isEmptyState = stateToArray.length ? false : true;
54
56
 
55
57
  if (isEmptyState) {
56
- setSettingsData((prev) => ({
58
+ setKanbanSettingsData((prev) => ({
57
59
  ...prev,
58
- quick_tab: {
59
- ...prev?.quick_tab,
60
- attribute: LANE_SELECTS[0].value,
61
- sorting: "asc",
60
+ lane: {
61
+ ...prev?.lane,
62
+ attribute:
63
+ selectAttributeData
64
+ ?.filter(
65
+ (i) => i?.value !== kanbanSettingsData?.swim_lane?.attribute
66
+ )
67
+ ?.find((i) => i?.value == "stage_group")?.value || "",
62
68
  },
63
69
  }));
70
+ } else {
71
+ if (
72
+ kanbanSettingsData?.swim_lane?.attribute ==
73
+ kanbanSettingsData?.lane?.attribute
74
+ ) {
75
+ setKanbanSettingsData((prev) => ({
76
+ ...prev,
77
+ swim_lane: {
78
+ ...prev?.swim_lane,
79
+ attribute:
80
+ selectAttributeData
81
+ ?.filter(
82
+ (i) => i?.value !== kanbanSettingsData?.swim_lane?.attribute
83
+ )
84
+ ?.find((i) => i?.value == "stage_group")?.value || "",
85
+ // sorting: "asc",
86
+ },
87
+ }));
88
+ }
64
89
  }
65
- }, [columnsData]);
90
+ }, [selectAttributeData]);
66
91
 
67
92
  useEffect(() => {
68
- if (currentQuickAttribute === settingsData?.quick_tab?.attribute) return;
93
+ if (currentLaneAttribute === kanbanSettingsData?.lane?.attribute) return;
69
94
 
70
- if (tabsApiData?.length) {
71
- setSettingsData((prev) => ({
95
+ if (laneHideListData?.length) {
96
+ setKanbanSettingsData((prev) => ({
72
97
  ...prev,
73
- quick_tab: {
74
- ...prev?.quick_tab,
75
- hide_list: tabsApiData,
98
+ lane: {
99
+ ...prev?.lane,
100
+ hide_list: laneHideListData,
76
101
  show_list: [],
77
102
  },
78
103
  }));
79
104
 
80
- setCurrentQuickAttribute(settingsData?.quick_tab?.attribute || "");
105
+ setCurrentLaneAttribute(kanbanSettingsData?.lane?.attribute || "");
106
+ } else {
107
+ setKanbanSettingsData((prev) => ({
108
+ ...prev,
109
+ lane: {
110
+ ...prev?.lane,
111
+ hide_list: [],
112
+ show_list: [],
113
+ },
114
+ }));
115
+
116
+ setCurrentLaneAttribute("");
81
117
  }
82
- }, [tabsApiData]);
118
+ }, [laneHideListData]);
83
119
 
84
120
  const sortingOptions = [
85
121
  { label: "A-Z", value: "asc" },
@@ -89,19 +125,53 @@ const Lane = ({
89
125
  { label: "Custom", value: "custom" },
90
126
  ];
91
127
 
92
- const showListValues = (quickTabStates?.show_list || [])?.map((id: any) => ({
93
- id,
94
- label: id?.charAt(0)?.toUpperCase() + id?.slice(1),
95
- }));
96
- const hideListValues = (quickTabStates?.hide_list || [])?.map((id: any) => ({
97
- id,
98
- label: id?.charAt(0)?.toUpperCase() + id?.slice(1),
99
- }));
128
+ const isWorkflowAttribute =
129
+ kanbanSettingsData?.lane?.attribute === "stage_group" ||
130
+ kanbanSettingsData?.lane?.attribute === "stage";
131
+
132
+ const isSourceAttribute =
133
+ kanbanSettingsData?.lane?.attribute === "lead_source";
134
+
135
+ useEffect(() => {
136
+ if (isSourceAttribute) {
137
+ setKanbanSettingsData((prev) => ({
138
+ ...prev,
139
+ lane: {
140
+ ...prev.lane,
141
+ sorting: prev.lane?.sorting || "asc",
142
+ },
143
+ }));
144
+ }
145
+ }, [kanbanSettingsData?.lane?.attribute]);
146
+
147
+ const displaySortingValue = isWorkflowAttribute
148
+ ? "workflow_sequence"
149
+ : kanbanSettingsData?.lane?.sorting;
150
+
151
+ const enableDND =
152
+ isSourceAttribute && kanbanSettingsData?.lane?.sorting === "custom";
153
+
154
+ const normalizeTabItem = (item: any) => ({
155
+ label: item.label,
156
+ value: item?.value,
157
+ });
158
+ const constructHideList = () => {
159
+ const normalizedTabs = laneHideListData?.map(normalizeTabItem) || [];
160
+ return normalizedTabs?.filter(
161
+ (tab) => !showListValues?.some((i) => i?.value === tab?.value)
162
+ );
163
+ };
164
+
165
+ const showListValues = kanbanSettingsData?.lane?.show_list || [];
166
+ const hideListValues = constructHideList() || [];
100
167
 
101
168
  const filteredListValues = hideListValues.filter((value: any) =>
102
169
  value?.label?.toLowerCase().includes(searchTerm.toLowerCase())
103
170
  );
104
171
 
172
+ /* ===========================================================
173
+ DND CONFIG
174
+ =========================================================== */
105
175
  const sensors = useSensors(
106
176
  useSensor(MouseSensor),
107
177
  useSensor(TouchSensor),
@@ -109,45 +179,59 @@ const Lane = ({
109
179
  );
110
180
 
111
181
  const handleDragEnd = (event: DragEndEvent) => {
182
+ if (!enableDND) return; // protect reorder when drag is disabled
183
+
112
184
  const { active, over } = event;
113
185
  if (!over) return;
114
186
 
115
187
  const currentContainer = active.data.current?.containerId;
116
188
  const overContainer = over.data.current?.containerId;
189
+
117
190
  if (!currentContainer || !overContainer) return;
118
191
 
119
- let newShowList = [...(quickTabStates.show_list ?? [])];
120
- let newHideList = [...(quickTabStates.hide_list ?? [])];
192
+ let newShowList = [...(kanbanSettingsData?.lane?.show_list ?? [])];
193
+ let newHideList = [...(kanbanSettingsData?.lane?.hide_list ?? [])];
121
194
 
122
195
  if (currentContainer === overContainer) {
123
- const list = currentContainer === "list" ? newHideList : newShowList;
124
- const oldIndex = list.indexOf(String(active.id));
125
- const newIndex = list.indexOf(String(over.id));
196
+ if (currentContainer === "list") {
197
+ const oldIndex = newHideList.findIndex((i) => i.value === active.id);
198
+ const newIndex = newHideList.findIndex((i) => i.value === over.id);
126
199
 
127
- if (oldIndex !== -1 && newIndex !== -1) {
128
- const [removed] = list.splice(oldIndex, 1);
129
- list.splice(newIndex, 0, removed);
200
+ if (oldIndex !== -1 && newIndex !== -1) {
201
+ const [removed] = newHideList.splice(oldIndex, 1);
202
+ newHideList.splice(newIndex, 0, removed);
203
+ }
204
+ } else {
205
+ const oldIndex = newShowList.findIndex((i) => i.value === active.id);
206
+ const newIndex = newShowList.findIndex((i) => i.value === over.id);
207
+
208
+ if (oldIndex !== -1 && newIndex !== -1) {
209
+ const [removed] = newShowList.splice(oldIndex, 1);
210
+ newShowList.splice(newIndex, 0, removed);
211
+ }
130
212
  }
131
- } else {
132
- if (currentContainer === "list" && overContainer === "lanes") {
133
- const idx = newHideList.indexOf(String(active.id));
213
+ }
214
+
215
+ if (currentContainer !== overContainer) {
216
+ if (currentContainer === "list" && overContainer === "tabs") {
217
+ const idx = newHideList.findIndex((i) => i.value === String(active.id));
134
218
  if (idx !== -1) {
135
- newHideList.splice(idx, 1);
136
- newShowList.push(String(active.id));
219
+ const item = newHideList.splice(idx, 1)[0];
220
+ newShowList.push(item);
137
221
  }
138
- } else if (currentContainer === "lanes" && overContainer === "list") {
139
- const idx = newShowList.indexOf(String(active.id));
222
+ } else if (currentContainer === "tabs" && overContainer === "list") {
223
+ const idx = newShowList.findIndex((i) => i.value === String(active.id));
140
224
  if (idx !== -1) {
141
- newShowList.splice(idx, 1);
142
- newHideList.push(String(active.id));
225
+ const item = newShowList.splice(idx, 1)[0];
226
+ newHideList.push(item);
143
227
  }
144
228
  }
145
229
  }
146
230
 
147
- setSettingsData((prev) => ({
231
+ setKanbanSettingsData((prev) => ({
148
232
  ...prev,
149
- quick_tab: {
150
- ...prev?.quick_tab,
233
+ lane: {
234
+ ...prev.lane,
151
235
  show_list: newShowList,
152
236
  hide_list: newHideList,
153
237
  },
@@ -155,13 +239,13 @@ const Lane = ({
155
239
  };
156
240
 
157
241
  const handleShowAll = () => {
158
- setSettingsData((prev) => ({
242
+ setKanbanSettingsData((prev) => ({
159
243
  ...prev,
160
- quick_tab: {
161
- ...prev?.quick_tab,
244
+ lane: {
245
+ ...prev?.lane,
162
246
  show_list: [
163
- ...(prev?.quick_tab?.show_list || []),
164
- ...(prev?.quick_tab?.hide_list || []),
247
+ ...(prev?.lane?.show_list || []),
248
+ ...(prev?.lane?.hide_list || []),
165
249
  ],
166
250
  hide_list: [],
167
251
  },
@@ -169,51 +253,56 @@ const Lane = ({
169
253
  };
170
254
 
171
255
  const handleHideAll = () => {
172
- setSettingsData((prev) => ({
256
+ setKanbanSettingsData((prev) => ({
173
257
  ...prev,
174
- quick_tab: {
175
- ...prev?.quick_tab,
258
+ lane: {
259
+ ...prev?.lane,
176
260
  hide_list: [
177
- ...(prev?.quick_tab?.hide_list || []),
178
- ...(prev?.quick_tab?.show_list || []),
261
+ ...(prev?.lane?.hide_list || []),
262
+ ...(prev?.lane?.show_list || []),
179
263
  ],
180
264
  show_list: [],
181
265
  },
182
266
  }));
183
267
  };
184
268
 
185
- /* ---------- ITEM TOGGLE (UNCHANGED) ---------- */
186
- const handleItemToggle = (itemId: string, fromContainerId: string) => {
187
- const toShowList = [...(quickTabStates.show_list ?? [])];
188
- const toHideList = [...(quickTabStates.hide_list ?? [])];
189
-
190
- if (fromContainerId === "list") {
191
- const index = toHideList.indexOf(itemId);
192
- if (index > -1) {
193
- toHideList.splice(index, 1);
194
- toShowList.push(itemId);
195
- }
196
- } else {
197
- const index = toShowList.indexOf(itemId);
198
- if (index > -1) {
199
- toShowList.splice(index, 1);
200
- toHideList.push(itemId);
269
+ const handleItemToggle = (
270
+ item: { label: string; value: string },
271
+ fromContainerId: string
272
+ ) => {
273
+ setKanbanSettingsData((prev) => {
274
+ const toShowList = [...(kanbanSettingsData?.lane?.show_list ?? [])];
275
+ const toHideList = [...(kanbanSettingsData?.lane?.hide_list ?? [])];
276
+
277
+ if (fromContainerId === "list") {
278
+ const index = toHideList.findIndex((i) => i.value == item.value);
279
+ if (index > -1) {
280
+ toHideList.splice(index, 1);
281
+ toShowList.push(item);
282
+ }
283
+ } else if (fromContainerId === "tabs") {
284
+ const index = toShowList.findIndex((i) => i.value == item.value);
285
+ if (index > -1) {
286
+ toShowList.splice(index, 1);
287
+ toHideList.push(item);
288
+ }
201
289
  }
202
- }
203
-
204
- setSettingsData((prev) => ({
205
- ...prev,
206
- quick_tab: {
207
- ...prev?.quick_tab,
208
- show_list: toShowList,
209
- hide_list: toHideList,
210
- },
211
- }));
290
+ return {
291
+ ...prev,
292
+ lane: {
293
+ ...prev?.lane,
294
+ show_list: toShowList,
295
+ hide_list: toHideList,
296
+ },
297
+ };
298
+ });
212
299
  };
213
300
 
214
- const enableDND = quickTabStates?.sorting === "custom";
301
+ console.log("kanban", kanbanSettingsData);
215
302
 
216
- /* ================== RENDER ================== */
303
+ /* ===========================================================
304
+ RENDER
305
+ =========================================================== */
217
306
  return (
218
307
  <Box sx={{ display: "flex", flexDirection: "column", height: "100%" }}>
219
308
  <Typography variant="caption" sx={TabsStyles.mainTabsHeader}>
@@ -226,49 +315,70 @@ const Lane = ({
226
315
  <Grid sx={TabsStyles.mainTabDropdown} size={6}>
227
316
  <FormControl sx={TabsStyles.mainTabSelect} size="small">
228
317
  <Select
229
- value={quickTabStates?.attribute || ""}
318
+ value={kanbanSettingsData?.lane?.attribute || ""}
230
319
  onChange={(e) =>
231
- setSettingsData((prev) => ({
320
+ setKanbanSettingsData((prev) => ({
232
321
  ...prev,
233
- quick_tab: {
234
- ...prev?.quick_tab,
322
+ lane: {
323
+ ...prev?.lane,
235
324
  attribute: e.target.value,
236
325
  },
237
326
  }))
238
327
  }
239
328
  >
240
- {selectAttributeData?.map((lane: any) => (
241
- <MenuItem key={lane?.key} value={lane?.value}>
242
- {lane?.value}
243
- </MenuItem>
244
- ))}
329
+ {selectAttributeData
330
+ ?.filter(
331
+ (i) => i?.value !== kanbanSettingsData?.swim_lane?.attribute
332
+ )
333
+ ?.map((lane: any) => (
334
+ <MenuItem key={lane?.key} value={lane?.value}>
335
+ {lane?.label}
336
+ </MenuItem>
337
+ ))}
245
338
  </Select>
246
339
  </FormControl>
247
340
 
248
341
  <FormControl sx={TabsStyles.selectDropdownSeparator} size="small">
249
342
  <Select
250
- value={quickTabStates?.sorting || "asc"}
251
- onChange={(e) =>
252
- setSettingsData((prev) => ({
253
- ...prev,
254
- quick_tab: {
255
- ...prev?.quick_tab,
256
- sorting: e.target.value,
257
- },
258
- }))
259
- }
343
+ value={displaySortingValue || ""}
344
+ disabled={isWorkflowAttribute}
345
+ onChange={(e) => {
346
+ if (!isWorkflowAttribute) {
347
+ const value = e.target.value as
348
+ | "asc"
349
+ | "dsc"
350
+ | "count_asc"
351
+ | "count_dsc"
352
+ | "custom";
353
+
354
+ setKanbanSettingsData((prev) => ({
355
+ ...prev,
356
+ lane: {
357
+ ...prev?.lane,
358
+ sorting: value,
359
+ },
360
+ }));
361
+ }
362
+ }}
260
363
  >
261
- {sortingOptions.map((option) => (
262
- <MenuItem key={option.value} value={option.value}>
263
- {option.label}
364
+ {isWorkflowAttribute && (
365
+ <MenuItem value="workflow_sequence">
366
+ Workflow Sequence
264
367
  </MenuItem>
265
- ))}
368
+ )}
369
+
370
+ {!isWorkflowAttribute &&
371
+ sortingOptions.map((option) => (
372
+ <MenuItem key={option.value} value={option.value}>
373
+ {option.label}
374
+ </MenuItem>
375
+ ))}
266
376
  </Select>
267
377
  </FormControl>
268
378
  </Grid>
269
379
  </Grid>
270
380
 
271
- {/* Lists */}
381
+ {/* LISTING + DRAG */}
272
382
  <DndContext
273
383
  sensors={sensors}
274
384
  collisionDetection={closestCenter}
@@ -293,26 +403,27 @@ const Lane = ({
293
403
  onClick={handleHideAll}
294
404
  headerText="View as Lanes"
295
405
  filteredValues={showListValues}
296
- containerId="lanes"
406
+ containerId="tabs"
297
407
  onItemToggle={handleItemToggle}
298
408
  enableDragAndDrop={enableDND}
299
409
  />
300
410
  </Grid>
301
411
  </DndContext>
302
412
 
303
- {quickTabStates?.attribute === "Stage Group" && (
413
+ {/* SUBLANE CHECKBOX */}
414
+ {kanbanSettingsData?.lane?.attribute === "stage_group" && (
304
415
  <Grid size={12}>
305
416
  <Box sx={TabsStyles.checkboxStyle}>
306
417
  <FormControlLabel
307
418
  control={
308
419
  <Checkbox
309
- checked={quickTabStates?.showSubLane || false}
420
+ checked={kanbanSettingsData?.lane?.isSubLane || false}
310
421
  onChange={(e) =>
311
- setSettingsData((prev) => ({
422
+ setKanbanSettingsData((prev) => ({
312
423
  ...prev,
313
- quick_tab: {
314
- ...prev?.quick_tab,
315
- showSubLane: e.target.checked,
424
+ lane: {
425
+ ...prev?.lane,
426
+ isSubLane: e.target.checked,
316
427
  },
317
428
  }))
318
429
  }
@@ -325,12 +436,13 @@ const Lane = ({
325
436
  </Grid>
326
437
  )}
327
438
 
328
- {quickTabStates?.attribute === "Stage Group" &&
329
- quickTabStates?.showSubLane && (
439
+ {/* SUBLANE STAGE SELECT */}
440
+ {kanbanSettingsData?.lane?.attribute === "stage_group" &&
441
+ kanbanSettingsData?.lane?.isSubLane && (
330
442
  <Grid size={12}>
331
443
  <Grid sx={TabsStyles.mainTabDropdown} size={6}>
332
444
  <FormControl sx={TabsStyles.mainTabSelect} size="small">
333
- <Select value="Stage" disabled>
445
+ <Select value="Stage">
334
446
  <MenuItem value="Stage">Stage</MenuItem>
335
447
  </Select>
336
448
  </FormControl>