@codezee/sixtify-brahma 0.2.185 → 0.2.186
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 +1 -1
- package/packages/shared-components/dist/AgGrid/hooks/useAgGridSelection.d.ts.map +1 -1
- package/packages/shared-components/dist/AgGrid/hooks/useAgGridSelection.js +71 -43
- package/packages/shared-components/dist/utils/CheckboxInput.d.ts.map +1 -1
- package/packages/shared-components/dist/utils/CheckboxInput.js +12 -2
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAgGridSelection.d.ts","sourceRoot":"","sources":["../../../src/AgGrid/hooks/useAgGridSelection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,KAAK,sBAAsB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,IAAI;IACtD,OAAO,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,gBAAgB,EAAE,CAAC,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC;QAC5C,IAAI,EAAE,CAAC,EAAE,CAAC;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC,CAAC;IACH,cAAc,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,KAAK,OAAO,CAAC;CACpD,CAAC;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CAAC,CAAC,CAuUxD,CAAC"}
|
|
@@ -5,14 +5,23 @@ const react_1 = require("react");
|
|
|
5
5
|
const useAgGridSelection = ({ gridRef, currentPageItems, totalRecords, selectedEmployee, fetchAll, getExtraParams, isRowSelectable, }) => {
|
|
6
6
|
const [selectedIds, setSelectedIds] = (0, react_1.useState)([]);
|
|
7
7
|
const [allDataCache, setAllDataCache] = (0, react_1.useState)(null);
|
|
8
|
-
const [selectableCount, setSelectableCount] = (0, react_1.useState)(null);
|
|
9
8
|
const originalSelectableCountRef = (0, react_1.useRef)(null);
|
|
10
9
|
const lastQueryParamsRef = (0, react_1.useRef)(null);
|
|
10
|
+
const previousTotalRecordsRef = (0, react_1.useRef)(totalRecords);
|
|
11
11
|
(0, react_1.useEffect)(() => {
|
|
12
|
-
if (originalSelectableCountRef.current === null && totalRecords > 0)
|
|
12
|
+
if ((originalSelectableCountRef.current === null && totalRecords > 0) ||
|
|
13
|
+
(originalSelectableCountRef.current !== null &&
|
|
14
|
+
totalRecords > originalSelectableCountRef.current)) {
|
|
13
15
|
originalSelectableCountRef.current = totalRecords;
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
const totalRecordsChanged = previousTotalRecordsRef.current !== totalRecords;
|
|
18
|
+
if (totalRecordsChanged) {
|
|
19
|
+
if (allDataCache) {
|
|
20
|
+
setAllDataCache(null);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
previousTotalRecordsRef.current = totalRecords;
|
|
24
|
+
}, [totalRecords, allDataCache, selectedIds.length]);
|
|
16
25
|
const currentPageState = (0, react_1.useMemo)(() => {
|
|
17
26
|
if (!currentPageItems.length) {
|
|
18
27
|
return { selected: 0, checked: false, indeterminate: false };
|
|
@@ -73,28 +82,27 @@ const useAgGridSelection = ({ gridRef, currentPageItems, totalRecords, selectedE
|
|
|
73
82
|
startRow: 0,
|
|
74
83
|
endRow: totalRecords ?? 0,
|
|
75
84
|
...extraParams,
|
|
76
|
-
quickFilter: null,
|
|
77
85
|
});
|
|
78
86
|
const selectableList = isRowSelectable
|
|
79
87
|
? list.filter((item) => isRowSelectable({ data: item }))
|
|
80
88
|
: list;
|
|
81
89
|
const allIds = Array.from(new Set(selectableList.map(({ id }) => id)));
|
|
82
90
|
setAllDataCache(list);
|
|
91
|
+
const calculatedSelectableCount = isRowSelectable
|
|
92
|
+
? list.filter((item) => isRowSelectable({ data: item })).length
|
|
93
|
+
: list.length;
|
|
83
94
|
if (apiSelectableCount !== undefined) {
|
|
84
|
-
setSelectableCount(apiSelectableCount);
|
|
85
95
|
if (originalSelectableCountRef.current === null) {
|
|
86
96
|
originalSelectableCountRef.current = apiSelectableCount;
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
|
-
else {
|
|
90
|
-
|
|
91
|
-
? list.filter((item) => isRowSelectable({ data: item })).length
|
|
92
|
-
: list.length;
|
|
93
|
-
if (originalSelectableCountRef.current === null) {
|
|
94
|
-
originalSelectableCountRef.current = calculatedSelectableCount;
|
|
95
|
-
}
|
|
99
|
+
else if (originalSelectableCountRef.current === null) {
|
|
100
|
+
originalSelectableCountRef.current = calculatedSelectableCount;
|
|
96
101
|
}
|
|
97
|
-
setSelectedIds(
|
|
102
|
+
setSelectedIds((prev) => {
|
|
103
|
+
const merged = new Set([...prev, ...allIds]);
|
|
104
|
+
return Array.from(merged);
|
|
105
|
+
});
|
|
98
106
|
if (totalRecords === 0 && totalCount) {
|
|
99
107
|
gridRef.current?.api?.setRowCount(totalCount, false);
|
|
100
108
|
}
|
|
@@ -102,7 +110,6 @@ const useAgGridSelection = ({ gridRef, currentPageItems, totalRecords, selectedE
|
|
|
102
110
|
const clearSelection = (0, react_1.useCallback)(() => {
|
|
103
111
|
setSelectedIds([]);
|
|
104
112
|
setAllDataCache(null);
|
|
105
|
-
setSelectableCount(null);
|
|
106
113
|
if (gridRef.current) {
|
|
107
114
|
gridRef.current.api.deselectAll();
|
|
108
115
|
}
|
|
@@ -128,22 +135,11 @@ const useAgGridSelection = ({ gridRef, currentPageItems, totalRecords, selectedE
|
|
|
128
135
|
}, []);
|
|
129
136
|
const selectedRecords = selectedEmployee.length;
|
|
130
137
|
const getTotalRecordsCount = () => {
|
|
131
|
-
if (selectedRecords === 0) {
|
|
132
|
-
return totalRecords;
|
|
133
|
-
}
|
|
134
|
-
if (originalSelectableCountRef.current !== null) {
|
|
135
|
-
return originalSelectableCountRef.current;
|
|
136
|
-
}
|
|
137
|
-
if (selectableCount && selectableCount > totalRecords) {
|
|
138
|
-
return selectableCount;
|
|
139
|
-
}
|
|
140
138
|
if (allDataCache?.length) {
|
|
141
139
|
const calculatedSelectableCount = isRowSelectable
|
|
142
140
|
? allDataCache.filter((item) => isRowSelectable({ data: item })).length
|
|
143
141
|
: allDataCache.length;
|
|
144
|
-
|
|
145
|
-
return calculatedSelectableCount;
|
|
146
|
-
}
|
|
142
|
+
return calculatedSelectableCount;
|
|
147
143
|
}
|
|
148
144
|
return totalRecords;
|
|
149
145
|
};
|
|
@@ -152,6 +148,16 @@ const useAgGridSelection = ({ gridRef, currentPageItems, totalRecords, selectedE
|
|
|
152
148
|
if (!selectedRecords) {
|
|
153
149
|
return null;
|
|
154
150
|
}
|
|
151
|
+
const originalCount = originalSelectableCountRef.current;
|
|
152
|
+
const allOriginalRowsSelected = originalCount !== null && selectedRecords === originalCount;
|
|
153
|
+
if (allOriginalRowsSelected) {
|
|
154
|
+
return {
|
|
155
|
+
show: true,
|
|
156
|
+
text: `All ${originalCount} rows are selected.`,
|
|
157
|
+
buttonText: "Clear selection",
|
|
158
|
+
onButtonClick: clearSelection,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
155
161
|
if (displayRecordsCount === selectedRecords) {
|
|
156
162
|
return {
|
|
157
163
|
show: true,
|
|
@@ -167,34 +173,56 @@ const useAgGridSelection = ({ gridRef, currentPageItems, totalRecords, selectedE
|
|
|
167
173
|
onButtonClick: () => void selectAll(),
|
|
168
174
|
};
|
|
169
175
|
}, [selectedRecords, displayRecordsCount, clearSelection, selectAll]);
|
|
176
|
+
const isInputFieldActive = (0, react_1.useCallback)(() => {
|
|
177
|
+
const activeElement = document.activeElement;
|
|
178
|
+
return (activeElement?.tagName === "INPUT" ||
|
|
179
|
+
activeElement?.tagName === "TEXTAREA" ||
|
|
180
|
+
activeElement?.contentEditable === "true");
|
|
181
|
+
}, []);
|
|
182
|
+
const isHeaderCheckboxActive = (0, react_1.useCallback)(() => {
|
|
183
|
+
const activeElement = document.activeElement;
|
|
184
|
+
return (activeElement?.closest(".ag-header-cell") !== null ||
|
|
185
|
+
activeElement?.closest(".ag-selection-checkbox") !== null ||
|
|
186
|
+
activeElement?.getAttribute("role") === "columnheader");
|
|
187
|
+
}, []);
|
|
170
188
|
(0, react_1.useEffect)(() => {
|
|
171
189
|
const handleKeyDown = (event) => {
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (isInputField || !currentPageItems.length) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
190
|
+
if (isInputFieldActive() || !currentPageItems.length) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const key = event.key.toLowerCase();
|
|
194
|
+
if (key === "a" && (event.ctrlKey || event.metaKey)) {
|
|
180
195
|
event.preventDefault();
|
|
181
196
|
selectCurrentPage();
|
|
197
|
+
return;
|
|
182
198
|
}
|
|
183
|
-
if (
|
|
184
|
-
const activeElement = document.activeElement;
|
|
185
|
-
const isInputField = activeElement?.tagName === "INPUT" ||
|
|
186
|
-
activeElement?.tagName === "TEXTAREA" ||
|
|
187
|
-
activeElement?.contentEditable === "true";
|
|
188
|
-
if (isInputField || !currentPageItems.length) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
199
|
+
if (key === "a" && event.altKey) {
|
|
191
200
|
event.preventDefault();
|
|
192
201
|
deselectCurrentPage();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if ((event.code === "Space" || event.key === " ") &&
|
|
205
|
+
isHeaderCheckboxActive() &&
|
|
206
|
+
gridRef.current) {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
if (currentPageState.checked) {
|
|
209
|
+
deselectCurrentPage();
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
selectCurrentPage();
|
|
213
|
+
}
|
|
193
214
|
}
|
|
194
215
|
};
|
|
195
216
|
document.addEventListener("keydown", handleKeyDown, true);
|
|
196
217
|
return () => document.removeEventListener("keydown", handleKeyDown, true);
|
|
197
|
-
}, [
|
|
218
|
+
}, [
|
|
219
|
+
currentPageItems.length,
|
|
220
|
+
selectCurrentPage,
|
|
221
|
+
deselectCurrentPage,
|
|
222
|
+
currentPageState.checked,
|
|
223
|
+
isInputFieldActive,
|
|
224
|
+
isHeaderCheckboxActive,
|
|
225
|
+
]);
|
|
198
226
|
return {
|
|
199
227
|
selectedIds,
|
|
200
228
|
allDataCache,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxInput.d.ts","sourceRoot":"","sources":["../../src/utils/CheckboxInput.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,GAAI;;CAAW,
|
|
1
|
+
{"version":3,"file":"CheckboxInput.d.ts","sourceRoot":"","sources":["../../src/utils/CheckboxInput.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,GAAI;;CAAW,4CA0CxC,CAAC"}
|
|
@@ -10,7 +10,7 @@ const material_1 = require("@mui/material");
|
|
|
10
10
|
const CheckboxInput = ({ ...rest }) => {
|
|
11
11
|
const theme = (0, material_1.useTheme)();
|
|
12
12
|
const { butterflyBlue, iron } = theme.palette.app.color;
|
|
13
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Checkbox, {
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Checkbox, { checkedIcon: (0, jsx_runtime_1.jsx)(CheckBoxRounded_1.default, { fontSize: "small", htmlColor: butterflyBlue[900], sx: {
|
|
14
14
|
borderRadius: 100,
|
|
15
15
|
marginLeft: "-1px",
|
|
16
16
|
} }), icon: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
@@ -19,6 +19,16 @@ const CheckboxInput = ({ ...rest }) => {
|
|
|
19
19
|
border: "1px solid",
|
|
20
20
|
borderColor: iron[800],
|
|
21
21
|
borderRadius: "4px",
|
|
22
|
-
} }),
|
|
22
|
+
} }), sx: {
|
|
23
|
+
"&:hover": {
|
|
24
|
+
backgroundColor: "action.hover",
|
|
25
|
+
},
|
|
26
|
+
"&.Mui-checked:hover": {
|
|
27
|
+
backgroundColor: "action.hover",
|
|
28
|
+
},
|
|
29
|
+
"& .MuiTouchRipple-root": {
|
|
30
|
+
color: butterflyBlue[900],
|
|
31
|
+
},
|
|
32
|
+
}, ...rest }));
|
|
23
33
|
};
|
|
24
34
|
exports.CheckboxInput = CheckboxInput;
|