@megha-ui/react 1.3.25 → 1.3.27
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/components/grid/hooks/useBulkSelect.d.ts +2 -1
- package/dist/components/grid/hooks/useBulkSelect.js +32 -28
- package/dist/components/grid/index.js +2 -1
- package/dist/components/grid/types/grid.d.ts +1 -0
- package/dist/components/grid/utils/newGridHeader.js +3 -1
- package/dist/components/grid/utils/newGridRow.js +4 -0
- package/package.json +1 -1
|
@@ -3,8 +3,9 @@ interface UseBulkSelectProps {
|
|
|
3
3
|
data: DataRow[];
|
|
4
4
|
setSelectedRows?: any;
|
|
5
5
|
selectedRows?: Set<string>;
|
|
6
|
+
idKey: string;
|
|
6
7
|
}
|
|
7
|
-
export declare const useBulkSelect: ({ data, selectedRows, setSelectedRows }: UseBulkSelectProps) => {
|
|
8
|
+
export declare const useBulkSelect: ({ data, selectedRows, setSelectedRows, idKey, }: UseBulkSelectProps) => {
|
|
8
9
|
selectedRows: Set<string> | undefined;
|
|
9
10
|
toggleRowSelection: (id: string) => void;
|
|
10
11
|
toggleSelectAll: (visibleData: DataRow[], allSelected: boolean) => void;
|
|
@@ -1,44 +1,48 @@
|
|
|
1
1
|
import { useCallback, useMemo } from "react";
|
|
2
|
-
export const useBulkSelect = ({ data, selectedRows, setSelectedRows }) => {
|
|
2
|
+
export const useBulkSelect = ({ data, selectedRows, setSelectedRows, idKey, }) => {
|
|
3
3
|
const toggleRowSelection = useCallback((id) => {
|
|
4
|
-
setSelectedRows &&
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
newSelectedRows.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
setSelectedRows &&
|
|
5
|
+
setSelectedRows((prevSelectedRows) => {
|
|
6
|
+
const newSelectedRows = new Set(prevSelectedRows);
|
|
7
|
+
if (newSelectedRows.has(id)) {
|
|
8
|
+
newSelectedRows.delete(id);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
newSelectedRows.add(id);
|
|
12
|
+
}
|
|
13
|
+
return newSelectedRows;
|
|
14
|
+
});
|
|
14
15
|
}, []);
|
|
15
16
|
const toggleSelectAll = useCallback((visibleData, allSelected) => {
|
|
16
|
-
setSelectedRows &&
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
setSelectedRows &&
|
|
18
|
+
setSelectedRows((prevSelectedRows) => {
|
|
19
|
+
const newSelectedRows = new Set(prevSelectedRows);
|
|
20
|
+
if (allSelected) {
|
|
21
|
+
visibleData.forEach((item) => { var _a; return newSelectedRows.delete((_a = item === null || item === void 0 ? void 0 : item[idKey].value) === null || _a === void 0 ? void 0 : _a.toString()); });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
visibleData.forEach((item) => {
|
|
25
|
+
var _a;
|
|
26
|
+
newSelectedRows.add((_a = item === null || item === void 0 ? void 0 : item[idKey].value) === null || _a === void 0 ? void 0 : _a.toString());
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return newSelectedRows;
|
|
30
|
+
});
|
|
29
31
|
}, []);
|
|
30
32
|
const allRowsSelected = useMemo(() => {
|
|
31
33
|
return data.every((item) => {
|
|
32
34
|
var _a;
|
|
33
|
-
return (item === null || item === void 0 ? void 0 : item[
|
|
34
|
-
selectedRows &&
|
|
35
|
+
return (item === null || item === void 0 ? void 0 : item[idKey]) &&
|
|
36
|
+
selectedRows &&
|
|
37
|
+
selectedRows.has((_a = item === null || item === void 0 ? void 0 : item[idKey].value) === null || _a === void 0 ? void 0 : _a.toString());
|
|
35
38
|
});
|
|
36
39
|
}, [data, selectedRows]);
|
|
37
40
|
const someRowsSelected = useMemo(() => {
|
|
38
41
|
return data.some((item) => {
|
|
39
42
|
var _a;
|
|
40
|
-
return (item === null || item === void 0 ? void 0 : item[
|
|
41
|
-
selectedRows &&
|
|
43
|
+
return (item === null || item === void 0 ? void 0 : item[idKey]) &&
|
|
44
|
+
selectedRows &&
|
|
45
|
+
selectedRows.has((_a = item === null || item === void 0 ? void 0 : item[idKey].value) === null || _a === void 0 ? void 0 : _a.toString());
|
|
42
46
|
});
|
|
43
47
|
}, [selectedRows, allRowsSelected]);
|
|
44
48
|
return {
|
|
@@ -32,7 +32,7 @@ import NewGridHeader from "./utils/newGridHeader";
|
|
|
32
32
|
import NewGridRow from "./utils/newGridRow";
|
|
33
33
|
import NewSummariseDetails from "./utils/newSummariseDetails";
|
|
34
34
|
import NewGroupedGridDetails from "./utils/newGroupedGridDetails";
|
|
35
|
-
const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable = true, paginate, rowsPerPageOptions = [10, 20, 50, 100], defaultRowsPerPage = 100, defaultColumnsPerView = 200, widthMode = "custom", bulkSelect = false, cellBorder = false, rowHeight = "3rem", onRowClick, rowCount = false, rowBorder = true, showMenu = false, search = false, defaultSearchOperation = "contains", gridBorder = false, isLoading = false, rowTopBorder, rowBottomBorder, rowLeftBorder, rowRightBorder, headerBackground = "var(--row-header-bg)", headerTopBorder = "none", headerBottomBorder = "none", SettingIcon, ExportIcon, ignoredExportItems = ["action", "actions"], borderColor = "#dbdfe9", updateColumns, showHideAvailable = false, columnSearchOutside = false, multiSorting = false, exportAvailable = false, exportableFileName = "", groupBy, updateGroupBy, rowKey = "id", hlBorderColor = "black", selectedRow, selectedRowStyle = {
|
|
35
|
+
const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable = true, paginate, rowsPerPageOptions = [10, 20, 50, 100], defaultRowsPerPage = 100, defaultColumnsPerView = 200, widthMode = "custom", bulkSelect = false, bulkId = "id", cellBorder = false, rowHeight = "3rem", onRowClick, rowCount = false, rowBorder = true, showMenu = false, search = false, defaultSearchOperation = "contains", gridBorder = false, isLoading = false, rowTopBorder, rowBottomBorder, rowLeftBorder, rowRightBorder, headerBackground = "var(--row-header-bg)", headerTopBorder = "none", headerBottomBorder = "none", SettingIcon, ExportIcon, ignoredExportItems = ["action", "actions"], borderColor = "#dbdfe9", updateColumns, showHideAvailable = false, columnSearchOutside = false, multiSorting = false, exportAvailable = false, exportableFileName = "", groupBy, updateGroupBy, rowKey = "id", hlBorderColor = "black", selectedRow, selectedRowStyle = {
|
|
36
36
|
borderLeft: "0.5rem solid #d9d9d9",
|
|
37
37
|
}, defaultSort, noKeyEvents = true, customOperation, hasCustomOperation, globalSearch, headerDropdownIndex, draggable = false, resizable = false, updateGridData, widthUnits, checkboxWrapper, ignoreHugContent = false, isSummarise = false, isHideDups = false, isMultipleChips = false, fullScreenAvailable = true, defaultGroupOpen, alternateRowColor = true, activeCalculateColor = "#2377BA", calculatetextColor = "#fff", actionsKey = "actions", ignoreClickKeys = "", saveAsNewView = false, handleSaveAsView, saveAsViewIcon, filterData, chipColor = "#ccc", withAscii = false, propSummariseKeys, SummariseIcon, summarizeColor = "black", isExpandable = false, expandedRow, extraRow, selectedCheckBox, setSelectedCheckbox, ignoreRowSelect, setOpenedRows, openedRows, getLoadingState, globalSearchOpen = false, updateFixedFilterValues = (fixedFilterValues) => {
|
|
38
38
|
console.log("Update fixed filter values not implemented", fixedFilterValues);
|
|
@@ -550,6 +550,7 @@ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, sub
|
|
|
550
550
|
data: sortedData,
|
|
551
551
|
selectedRows: selectedCheckBox,
|
|
552
552
|
setSelectedRows: setSelectedCheckbox,
|
|
553
|
+
idKey: bulkId
|
|
553
554
|
});
|
|
554
555
|
const [hasVerticalScroll, setHasVerticalScroll] = useState(false);
|
|
555
556
|
const [rowOpened, setRowOpened] = useState([]);
|
|
@@ -248,7 +248,9 @@ const GridHeader = ({ columns, onSearch, searchQueries, sortable, search, resiza
|
|
|
248
248
|
};
|
|
249
249
|
return (_jsxs(_Fragment, { children: [bulkSelect && (_jsx("div", { style: Object.assign(Object.assign({}, cellStyle), { textTransform: "uppercase", padding: "0.5rem", textAlign: "left", whiteSpace: "nowrap", textOverflow: "ellipsis", position: "sticky", top: 0, zIndex: 1, backgroundColor: "var(--row-header-bg)" }), children: _jsx("div", { style: {
|
|
250
250
|
display: "flex",
|
|
251
|
-
alignItems: "center"
|
|
251
|
+
alignItems: "center",
|
|
252
|
+
width: "100%",
|
|
253
|
+
height: "100%",
|
|
252
254
|
}, children: _jsx(Checkbox, { selected: allRowsSelected, onChange: () => toggleSelectAll(), noLabel: true, wrapperClass: checkboxWrapper }) }) })), groupByKeys.map((_groupBy) => {
|
|
253
255
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58;
|
|
254
256
|
return (_jsx(_Fragment, { children: headerColumns.find((column) => column.key === _groupBy) && (_jsxs("div", { className: `${sortable &&
|
|
@@ -100,6 +100,8 @@ const GridRow = ({ item, rowStyle, cellStyle, rowHeight, bulkSelect, selectedRow
|
|
|
100
100
|
: "var(--row-bg-even)" }), children: _jsx("div", { style: {
|
|
101
101
|
display: "flex",
|
|
102
102
|
alignItems: "center",
|
|
103
|
+
width: "100%",
|
|
104
|
+
height: "100%",
|
|
103
105
|
}, children: _jsx(Checkbox, { noLabel: true, disabled: ignoreRowSelect &&
|
|
104
106
|
ignoreRowSelect.has((_e = item["id"].value) === null || _e === void 0 ? void 0 : _e.toString()), onChange: () => { var _a; return toggleRowSelection((_a = item["id"].value) === null || _a === void 0 ? void 0 : _a.toString()); }, selected: item["id"] && selectedRows.has(item["id"].value), wrapperClass: checkboxWrapper }) }) })), item[groupBy] && (_jsx("div", { style: {
|
|
105
107
|
wordBreak: widthMode === "auto" ? "break-all" : "unset",
|
|
@@ -152,6 +154,8 @@ const GridRow = ({ item, rowStyle, cellStyle, rowHeight, bulkSelect, selectedRow
|
|
|
152
154
|
: "var(--row-bg-even)" }), children: _jsx("div", { style: {
|
|
153
155
|
display: "flex",
|
|
154
156
|
alignItems: "center",
|
|
157
|
+
width: "100%",
|
|
158
|
+
height: "100%",
|
|
155
159
|
}, children: _jsx(Checkbox, { noLabel: true, disabled: ignoreRowSelect &&
|
|
156
160
|
ignoreRowSelect.has((_m = item["id"].value) === null || _m === void 0 ? void 0 : _m.toString()), onChange: () => { var _a; return toggleRowSelection((_a = item["id"].value) === null || _a === void 0 ? void 0 : _a.toString()); }, selected: item["id"] && selectedRows.has(item["id"].value), wrapperClass: checkboxWrapper }) }) })), columns.map((column, colIndex) => {
|
|
157
161
|
var _a, _b, _c, _d, _e, _f, _g;
|
package/package.json
CHANGED