rez-table-listing-mui 1.0.46 → 1.0.48
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/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/components/filter/components/forms/components/Filter-criteria.tsx +11 -3
- package/src/components/filter/components/forms/index.tsx +1 -1
- package/src/components/table-settings/components/quick-tab.tsx +45 -2
- package/src/components/table-settings/index.tsx +5 -1
- package/src/libs/hooks/useElementWidth.tsx +28 -0
- package/src/libs/utils/apiColumn.ts +8 -7
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { CraftTableOptionsProps } from "../../../../../types/table-options";
|
|
18
18
|
import CustomSearch from "../../search";
|
|
19
19
|
import { filterStyles } from "../../../style";
|
|
20
|
+
import useElementWidth from "../../../../../libs/hooks/useElementWidth";
|
|
20
21
|
|
|
21
22
|
const FilterCriteria = ({
|
|
22
23
|
columnsData,
|
|
@@ -46,8 +47,11 @@ const FilterCriteria = ({
|
|
|
46
47
|
|
|
47
48
|
const [showFilterOptions, setShowFilterOption] = useState(false);
|
|
48
49
|
const { filters, setFilters } = tableStates;
|
|
50
|
+
|
|
49
51
|
const filterButtonRef = useRef<HTMLButtonElement>(null);
|
|
50
52
|
|
|
53
|
+
const filterButtonWidth = useElementWidth(filterButtonRef);
|
|
54
|
+
|
|
51
55
|
const handleAddFilter = (column: FilterColumnsListProps) => {
|
|
52
56
|
const dropdownOptions = columnsData.operation_list[column.data_type];
|
|
53
57
|
|
|
@@ -110,7 +114,7 @@ const FilterCriteria = ({
|
|
|
110
114
|
{showFilterOptions && (
|
|
111
115
|
<Paper
|
|
112
116
|
sx={{
|
|
113
|
-
width:
|
|
117
|
+
width: filterButtonWidth || 360, // Dynamic width based on button
|
|
114
118
|
p: 1,
|
|
115
119
|
mt: 2,
|
|
116
120
|
cursor: "pointer",
|
|
@@ -141,8 +145,12 @@ const FilterCriteria = ({
|
|
|
141
145
|
}}
|
|
142
146
|
>
|
|
143
147
|
{columnsData?.column_list
|
|
144
|
-
?.filter(
|
|
145
|
-
column
|
|
148
|
+
?.filter(
|
|
149
|
+
(column) =>
|
|
150
|
+
column.name.toLowerCase() !== "action" && // Exclude Action column in filter criteria options
|
|
151
|
+
column.name
|
|
152
|
+
.toLowerCase()
|
|
153
|
+
.includes(searchTerm.toLowerCase())
|
|
146
154
|
)
|
|
147
155
|
.map((column, index) => {
|
|
148
156
|
const isAlreadySelected = filters?.some(
|
|
@@ -107,7 +107,7 @@ const FilterForm = ({
|
|
|
107
107
|
|
|
108
108
|
useEffect(() => {
|
|
109
109
|
reset(defaultValues);
|
|
110
|
-
}, [selectedFilters
|
|
110
|
+
}, [selectedFilters]);
|
|
111
111
|
|
|
112
112
|
const debouncedUpdateFilters = useCallback(
|
|
113
113
|
customDebounce((updatedFilters: UpdatedFilterStateProps[]) => {
|
|
@@ -35,8 +35,14 @@ const QuickTab = ({
|
|
|
35
35
|
tabsApiData,
|
|
36
36
|
tabsApiDataLoading,
|
|
37
37
|
}: SettingsQuickTabProps) => {
|
|
38
|
-
const {
|
|
39
|
-
|
|
38
|
+
const {
|
|
39
|
+
quickTabStates,
|
|
40
|
+
setQuickTabStates,
|
|
41
|
+
settingsData,
|
|
42
|
+
setColumnTabState,
|
|
43
|
+
saveButtonError,
|
|
44
|
+
setSaveButtonError,
|
|
45
|
+
} = filterSettingStates;
|
|
40
46
|
|
|
41
47
|
const [searchTerm, setSearchTerm] = useState<string>("");
|
|
42
48
|
|
|
@@ -101,6 +107,43 @@ const QuickTab = ({
|
|
|
101
107
|
}));
|
|
102
108
|
}
|
|
103
109
|
}
|
|
110
|
+
|
|
111
|
+
// check for error
|
|
112
|
+
const hasInvalidValidShowList =
|
|
113
|
+
quickTabStates.show_list &&
|
|
114
|
+
(quickTabStates.show_list?.length === 0 ||
|
|
115
|
+
quickTabStates.show_list.length >= 5);
|
|
116
|
+
|
|
117
|
+
if (hasInvalidValidShowList) {
|
|
118
|
+
// Check if error is already in the state to avoid duplication
|
|
119
|
+
const errorMessage = {
|
|
120
|
+
type: "quick_tab_error",
|
|
121
|
+
message:
|
|
122
|
+
"Quick Tab : View as Tabs should have at least 1 and at most 5 tabs.",
|
|
123
|
+
};
|
|
124
|
+
const hasQuickTabError = saveButtonError?.messages?.some(
|
|
125
|
+
(message) => message.type === "quick_tab_error"
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
if (!hasQuickTabError) {
|
|
129
|
+
setSaveButtonError((prev) => ({
|
|
130
|
+
...prev,
|
|
131
|
+
hasError: true,
|
|
132
|
+
messages: [...(prev?.messages || []), errorMessage], // Only add if it doesn't exist
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
const otherMessages =
|
|
137
|
+
saveButtonError?.messages?.filter(
|
|
138
|
+
(message) => message.type !== "quick_tab_error"
|
|
139
|
+
) || [];
|
|
140
|
+
|
|
141
|
+
setSaveButtonError((prev) => ({
|
|
142
|
+
...prev,
|
|
143
|
+
hasError: otherMessages.length > 0,
|
|
144
|
+
messages: otherMessages,
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
104
147
|
}, [quickTabStates.show_list, quickTabStates.hide_list]);
|
|
105
148
|
|
|
106
149
|
// useEffect(() => {
|
|
@@ -37,6 +37,7 @@ export function QuickFilterSettings({
|
|
|
37
37
|
quickTabStates,
|
|
38
38
|
columnTabState,
|
|
39
39
|
sortingTabState,
|
|
40
|
+
saveButtonError,
|
|
40
41
|
} = filterSettingStates;
|
|
41
42
|
|
|
42
43
|
const hasAPIData = Boolean(Object.entries(columnsData).length);
|
|
@@ -148,7 +149,10 @@ export function QuickFilterSettings({
|
|
|
148
149
|
|
|
149
150
|
{!columnsDataLoading && hasAPIData && (
|
|
150
151
|
<DialogActions>
|
|
151
|
-
<CustomButton
|
|
152
|
+
<CustomButton
|
|
153
|
+
disabled={saveButtonError?.hasError}
|
|
154
|
+
onClick={handleSaveSetSettingsData}
|
|
155
|
+
>
|
|
152
156
|
Save Quick Filter
|
|
153
157
|
</CustomButton>
|
|
154
158
|
</DialogActions>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
// Custom hook to track the width of an element
|
|
4
|
+
const useElementWidth = (ref: React.RefObject<HTMLElement>) => {
|
|
5
|
+
const [width, setWidth] = useState<number>(0);
|
|
6
|
+
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
// If there's no element to observe, just return early
|
|
9
|
+
if (!ref.current) return;
|
|
10
|
+
|
|
11
|
+
// ResizeObserver callback function
|
|
12
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
13
|
+
if (ref.current) {
|
|
14
|
+
setWidth(ref.current.offsetWidth); // Update width state
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Start observing the element's size changes
|
|
19
|
+
resizeObserver.observe(ref.current);
|
|
20
|
+
|
|
21
|
+
// Clean up observer on component unmount
|
|
22
|
+
return () => resizeObserver.disconnect();
|
|
23
|
+
}, [ref]);
|
|
24
|
+
|
|
25
|
+
return width; // Return the current width
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default useElementWidth;
|
|
@@ -32,14 +32,15 @@ export const entityTableFilterMaster = async (entity_type: string) => {
|
|
|
32
32
|
`/meta/get-table-data?entity_type=${entity_type}&list_type=${entity_type}`
|
|
33
33
|
);
|
|
34
34
|
|
|
35
|
-
const filteredData = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
35
|
+
// const filteredData = {
|
|
36
|
+
// ...response.data.data,
|
|
37
|
+
// column_list: response.data.data.column_list.filter(
|
|
38
|
+
// (item: any) => item.attribute_key !== "action"
|
|
39
|
+
// ),
|
|
40
|
+
// };
|
|
41
41
|
// return response.data.data;
|
|
42
|
-
return filteredData; // FOR ACTION COLUMN REMOVE
|
|
42
|
+
// return filteredData; // FOR ACTION COLUMN REMOVE
|
|
43
|
+
return response.data.data;
|
|
43
44
|
} catch (error) {
|
|
44
45
|
console.error("Failed to fetch filter operation list meta:", error);
|
|
45
46
|
}
|