@telus-uds/components-community.data-grid 1.1.0 → 1.2.1
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/CHANGELOG.md +23 -2
- package/lib/cjs/DataGrid.js +47 -15
- package/lib/cjs/utility.js +41 -12
- package/lib/esm/DataGrid.js +46 -16
- package/lib/esm/utility.js +38 -11
- package/package.json +3 -3
- package/src/DataGrid.jsx +55 -13
- package/src/utility.jsx +43 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
# Change Log - @telus-uds/components-community.data-grid
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 11 Mar 2025 21:13:58 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.2.1
|
|
8
|
+
|
|
9
|
+
Tue, 11 Mar 2025 21:13:58 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- Bump @telus-uds/components-web to v4.3.0
|
|
14
|
+
- Bump @telus-uds/components-base to v3.4.0
|
|
15
|
+
- Bump @telus-uds/browserslist-config to v1.0.5
|
|
16
|
+
|
|
17
|
+
## 1.2.0
|
|
18
|
+
|
|
19
|
+
Wed, 05 Mar 2025 00:06:37 GMT
|
|
20
|
+
|
|
21
|
+
### Minor changes
|
|
22
|
+
|
|
23
|
+
- `DatePicker`: Enhancement to make the row checkboxes controlled by the row's data (sam.obisesan@telus.com)
|
|
24
|
+
- Bump @telus-uds/components-web to v4.2.1
|
|
25
|
+
- Bump @telus-uds/components-base to v3.3.0
|
|
26
|
+
- Bump @telus-uds/browserslist-config to v1.0.5
|
|
27
|
+
|
|
7
28
|
## 1.1.0
|
|
8
29
|
|
|
9
|
-
Fri, 14 Feb 2025
|
|
30
|
+
Fri, 14 Feb 2025 19:03:35 GMT
|
|
10
31
|
|
|
11
32
|
### Minor changes
|
|
12
33
|
|
package/lib/cjs/DataGrid.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.StyledIconContainer = void 0;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _componentsBase = require("@telus-uds/components-base");
|
|
10
10
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
@@ -17,6 +17,8 @@ var _DataGridRow = _interopRequireDefault(require("./DataGridRow"));
|
|
|
17
17
|
var _DataGridCell = _interopRequireDefault(require("./DataGridCell"));
|
|
18
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
19
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
22
|
const StyledIconContainer = exports.StyledIconContainer = /*#__PURE__*/_styledComponents.default.div.withConfig({
|
|
21
23
|
displayName: "DataGrid__StyledIconContainer",
|
|
22
24
|
componentId: "[object Object]__sc-1ddcmt-0"
|
|
@@ -49,17 +51,31 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
49
51
|
const [data, setData] = _react.default.useState(groupedRows ? (0, _utility.resetRowData)([...groupedRows], true) : (0, _utility.resetRowData)([...rows]));
|
|
50
52
|
const [columnsData, setColumnsData] = _react.default.useState((0, _utility.resetColumnsData)(columns));
|
|
51
53
|
const [checkAllState, setCheckAllState] = _react.default.useState(false);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
+
const [disableHeaderCheckbox, setDisableHeaderCheckbox] = _react.default.useState(false);
|
|
55
|
+
const [hideHeaderCheckBoxByRows, setHideHeaderCheckBoxByRows] = _react.default.useState(false);
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
57
|
+
let _isAtLeastOneRowUnselected = null;
|
|
58
|
+
let _isAtLeastOneRowEnabled = null;
|
|
59
|
+
let _hideHeaderCheckBoxByRows = null;
|
|
54
60
|
if (groupedRows) {
|
|
55
|
-
|
|
56
|
-
return (0, _utility.isAtLeastOneRowUnselected)(
|
|
61
|
+
_isAtLeastOneRowUnselected = Object.keys(data).some(el => {
|
|
62
|
+
return (0, _utility.isAtLeastOneRowUnselected)(data[el].data);
|
|
63
|
+
});
|
|
64
|
+
_isAtLeastOneRowEnabled = Object.keys(data).some(el => {
|
|
65
|
+
return (0, _utility.isAtLeastOneRowEnabled)(data[el].data);
|
|
66
|
+
});
|
|
67
|
+
_hideHeaderCheckBoxByRows = Object.keys(data).some(el => {
|
|
68
|
+
return (0, _utility.hasEveryRowHiddenItsCheckbox)(data[el].data);
|
|
57
69
|
});
|
|
58
70
|
} else {
|
|
59
|
-
|
|
71
|
+
_isAtLeastOneRowUnselected = (0, _utility.isAtLeastOneRowUnselected)(data);
|
|
72
|
+
_isAtLeastOneRowEnabled = (0, _utility.isAtLeastOneRowEnabled)(data);
|
|
73
|
+
_hideHeaderCheckBoxByRows = (0, _utility.hasEveryRowHiddenItsCheckbox)(data);
|
|
60
74
|
}
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
setCheckAllState(_isAtLeastOneRowEnabled === false ? false : !_isAtLeastOneRowUnselected);
|
|
76
|
+
setDisableHeaderCheckbox(!_isAtLeastOneRowEnabled);
|
|
77
|
+
setHideHeaderCheckBoxByRows(_hideHeaderCheckBoxByRows);
|
|
78
|
+
}, [data, groupedRows]);
|
|
63
79
|
const shouldDisplayIconColumn = (allData, _showCheckbox) => {
|
|
64
80
|
let doesOneRowHaveExpandedContent = null;
|
|
65
81
|
if (groupedRows) {
|
|
@@ -87,8 +103,11 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
87
103
|
setData(_rows);
|
|
88
104
|
setCheckAllState(!checkAllState);
|
|
89
105
|
};
|
|
90
|
-
const toggleCheckbox = rowId => {
|
|
106
|
+
const toggleCheckbox = (rowId, row) => {
|
|
91
107
|
let _data = null;
|
|
108
|
+
if (typeof row.checkBoxProps?.onChange === 'function') {
|
|
109
|
+
row.checkBoxProps.onChange();
|
|
110
|
+
}
|
|
92
111
|
if (groupedRows) {
|
|
93
112
|
const [group, _] = rowId.split('-');
|
|
94
113
|
const id = parseInt(_, 10);
|
|
@@ -115,15 +134,18 @@ const DataGrid = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
115
134
|
}
|
|
116
135
|
setData(_row);
|
|
117
136
|
};
|
|
118
|
-
const HeaderCheckBoxDisplay = showCheckbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Checkbox, {
|
|
137
|
+
const HeaderCheckBoxDisplay = showCheckbox && !hideHeaderCheckBoxByRows && /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Checkbox, {
|
|
119
138
|
label: getCopy('all'),
|
|
120
|
-
checked:
|
|
139
|
+
checked: checkAllState,
|
|
140
|
+
inactive: disableHeaderCheckbox,
|
|
121
141
|
onChange: toggleSelectAll
|
|
122
142
|
});
|
|
123
|
-
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) =>
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
143
|
+
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) => {
|
|
144
|
+
return _showCheckbox && !row.hideCheckbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Checkbox, {
|
|
145
|
+
...row.checkBoxProps,
|
|
146
|
+
onChange: () => toggleCheckbox(rowId, row)
|
|
147
|
+
});
|
|
148
|
+
};
|
|
127
149
|
const buildDisplayCaret = (row, rowId) => row.hasExpandedRow && /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.IconButton, {
|
|
128
150
|
onPress: () => toggleRowExpansion(rowId),
|
|
129
151
|
icon: row.isExpandedRowOpen === true ? hideExpandedRowIcon : expandRowIcon,
|
|
@@ -341,6 +363,16 @@ DataGrid.propTypes = {
|
|
|
341
363
|
expandedRowChildComponent: _propTypes.default.shape({
|
|
342
364
|
component: _propTypes.default.node,
|
|
343
365
|
displayOnLoad: _propTypes.default.bool.isRequired
|
|
366
|
+
}),
|
|
367
|
+
/**
|
|
368
|
+
* Set this to true to hide checkbox for the specified row
|
|
369
|
+
*/
|
|
370
|
+
hideCheckbox: _propTypes.default.bool,
|
|
371
|
+
checkBoxProps: _propTypes.default.shape({
|
|
372
|
+
checked: _propTypes.default.bool,
|
|
373
|
+
name: _propTypes.default.string,
|
|
374
|
+
value: _propTypes.default.string.isRequired,
|
|
375
|
+
onChange: _propTypes.default.func
|
|
344
376
|
})
|
|
345
377
|
})),
|
|
346
378
|
/**
|
package/lib/cjs/utility.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.toggleRowCheckbox = exports.toggleExpandedRow = exports.toggleAllCheckBoxes = exports.resetRowData = exports.resetColumnsData = exports.isAtLeastOneRowUnselected = exports.SORT_DIRECTION = exports.ROW_TYPE = exports.DATA_TYPE = exports.CELL_TYPE = void 0;
|
|
6
|
+
exports.toggleRowCheckbox = exports.toggleExpandedRow = exports.toggleAllCheckBoxes = exports.resetRowData = exports.resetColumnsData = exports.isAtLeastOneRowUnselected = exports.isAtLeastOneRowEnabled = exports.hasEveryRowHiddenItsCheckbox = exports.SORT_DIRECTION = exports.ROW_TYPE = exports.DATA_TYPE = exports.CELL_TYPE = void 0;
|
|
7
7
|
const ROW_TYPE = exports.ROW_TYPE = {
|
|
8
8
|
HEADING: 'heading',
|
|
9
9
|
SUBHEADING: 'subHeading',
|
|
@@ -25,20 +25,38 @@ const DATA_TYPE = exports.DATA_TYPE = {
|
|
|
25
25
|
const mappedData = array => {
|
|
26
26
|
return array.map(element => {
|
|
27
27
|
const eachRow = {
|
|
28
|
-
...element
|
|
29
|
-
isSelected: false
|
|
28
|
+
...element
|
|
30
29
|
};
|
|
31
30
|
if (eachRow.expandedRowChildComponent) {
|
|
32
31
|
eachRow.hasExpandedRow = true;
|
|
33
32
|
eachRow.isExpandedRowOpen = element.expandedRowChildComponent.displayOnLoad;
|
|
34
33
|
}
|
|
34
|
+
if (!eachRow.hideCheckbox) {
|
|
35
|
+
eachRow.hideCheckbox = false;
|
|
36
|
+
}
|
|
37
|
+
if (!eachRow.checkBoxProps) {
|
|
38
|
+
eachRow.checkBoxProps = {
|
|
39
|
+
value: `row_${eachRow.id}`,
|
|
40
|
+
inactive: false,
|
|
41
|
+
checked: false,
|
|
42
|
+
onChange: () => {}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
35
45
|
return eachRow;
|
|
36
46
|
});
|
|
37
47
|
};
|
|
38
48
|
const isAtLeastOneRowUnselected = array => {
|
|
39
|
-
return array.some(each => each.
|
|
49
|
+
return array.some(each => each.checkBoxProps?.inactive === false && each.checkBoxProps?.checked === false);
|
|
40
50
|
};
|
|
41
51
|
exports.isAtLeastOneRowUnselected = isAtLeastOneRowUnselected;
|
|
52
|
+
const isAtLeastOneRowEnabled = array => {
|
|
53
|
+
return array.some(each => each.checkBoxProps?.inactive === false);
|
|
54
|
+
};
|
|
55
|
+
exports.isAtLeastOneRowEnabled = isAtLeastOneRowEnabled;
|
|
56
|
+
const hasEveryRowHiddenItsCheckbox = array => {
|
|
57
|
+
return array.every(each => each.hideCheckbox === true);
|
|
58
|
+
};
|
|
59
|
+
exports.hasEveryRowHiddenItsCheckbox = hasEveryRowHiddenItsCheckbox;
|
|
42
60
|
const resetColumnsData = data => {
|
|
43
61
|
return data.map(element => ({
|
|
44
62
|
...element,
|
|
@@ -64,18 +82,29 @@ const resetRowData = function (data) {
|
|
|
64
82
|
exports.resetRowData = resetRowData;
|
|
65
83
|
const toggleAllCheckBoxes = (array, headerCheckBoxState) => {
|
|
66
84
|
return array.map(element => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
85
|
+
let _el = null;
|
|
86
|
+
if (element.hideCheckbox === true || element.checkBoxProps && element.checkBoxProps.inactive) {
|
|
87
|
+
_el = {
|
|
88
|
+
...element
|
|
89
|
+
};
|
|
90
|
+
} else {
|
|
91
|
+
_el = {
|
|
92
|
+
...element
|
|
93
|
+
};
|
|
94
|
+
_el.checkBoxProps.checked = !headerCheckBoxState;
|
|
95
|
+
}
|
|
96
|
+
return _el;
|
|
71
97
|
});
|
|
72
98
|
};
|
|
73
99
|
exports.toggleAllCheckBoxes = toggleAllCheckBoxes;
|
|
74
100
|
const toggleRowCheckbox = (array, rowId) => {
|
|
75
|
-
return array.map(el =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
101
|
+
return array.map(el => {
|
|
102
|
+
const _el = {
|
|
103
|
+
...el
|
|
104
|
+
};
|
|
105
|
+
_el.checkBoxProps.checked = el.id === rowId ? !_el.checkBoxProps.checked : _el.checkBoxProps.checked;
|
|
106
|
+
return _el;
|
|
107
|
+
});
|
|
79
108
|
};
|
|
80
109
|
exports.toggleRowCheckbox = toggleRowCheckbox;
|
|
81
110
|
const toggleExpandedRow = (array, rowId) => {
|
package/lib/esm/DataGrid.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { Typography, Checkbox, useCopy, useThemeTokens, variantProp, IconButton } from '@telus-uds/components-base';
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
import dictionary from './dictionary';
|
|
6
|
-
import { resetColumnsData, resetRowData, DATA_TYPE, SORT_DIRECTION, isAtLeastOneRowUnselected, toggleAllCheckBoxes, toggleExpandedRow, toggleRowCheckbox, ROW_TYPE, CELL_TYPE } from './utility';
|
|
6
|
+
import { resetColumnsData, resetRowData, DATA_TYPE, SORT_DIRECTION, isAtLeastOneRowUnselected, isAtLeastOneRowEnabled, hasEveryRowHiddenItsCheckbox, toggleAllCheckBoxes, toggleExpandedRow, toggleRowCheckbox, ROW_TYPE, CELL_TYPE } from './utility';
|
|
7
7
|
import DataGridTable from './DataGridTable';
|
|
8
8
|
import DataGridHead from './DataGridHead';
|
|
9
9
|
import DataGridBody from './DataGridBody';
|
|
@@ -42,17 +42,31 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
42
42
|
const [data, setData] = React.useState(groupedRows ? resetRowData([...groupedRows], true) : resetRowData([...rows]));
|
|
43
43
|
const [columnsData, setColumnsData] = React.useState(resetColumnsData(columns));
|
|
44
44
|
const [checkAllState, setCheckAllState] = React.useState(false);
|
|
45
|
-
const
|
|
46
|
-
|
|
45
|
+
const [disableHeaderCheckbox, setDisableHeaderCheckbox] = React.useState(false);
|
|
46
|
+
const [hideHeaderCheckBoxByRows, setHideHeaderCheckBoxByRows] = React.useState(false);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
let _isAtLeastOneRowUnselected = null;
|
|
49
|
+
let _isAtLeastOneRowEnabled = null;
|
|
50
|
+
let _hideHeaderCheckBoxByRows = null;
|
|
47
51
|
if (groupedRows) {
|
|
48
|
-
|
|
49
|
-
return isAtLeastOneRowUnselected(
|
|
52
|
+
_isAtLeastOneRowUnselected = Object.keys(data).some(el => {
|
|
53
|
+
return isAtLeastOneRowUnselected(data[el].data);
|
|
54
|
+
});
|
|
55
|
+
_isAtLeastOneRowEnabled = Object.keys(data).some(el => {
|
|
56
|
+
return isAtLeastOneRowEnabled(data[el].data);
|
|
57
|
+
});
|
|
58
|
+
_hideHeaderCheckBoxByRows = Object.keys(data).some(el => {
|
|
59
|
+
return hasEveryRowHiddenItsCheckbox(data[el].data);
|
|
50
60
|
});
|
|
51
61
|
} else {
|
|
52
|
-
|
|
62
|
+
_isAtLeastOneRowUnselected = isAtLeastOneRowUnselected(data);
|
|
63
|
+
_isAtLeastOneRowEnabled = isAtLeastOneRowEnabled(data);
|
|
64
|
+
_hideHeaderCheckBoxByRows = hasEveryRowHiddenItsCheckbox(data);
|
|
53
65
|
}
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
setCheckAllState(_isAtLeastOneRowEnabled === false ? false : !_isAtLeastOneRowUnselected);
|
|
67
|
+
setDisableHeaderCheckbox(!_isAtLeastOneRowEnabled);
|
|
68
|
+
setHideHeaderCheckBoxByRows(_hideHeaderCheckBoxByRows);
|
|
69
|
+
}, [data, groupedRows]);
|
|
56
70
|
const shouldDisplayIconColumn = (allData, _showCheckbox) => {
|
|
57
71
|
let doesOneRowHaveExpandedContent = null;
|
|
58
72
|
if (groupedRows) {
|
|
@@ -80,8 +94,11 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
80
94
|
setData(_rows);
|
|
81
95
|
setCheckAllState(!checkAllState);
|
|
82
96
|
};
|
|
83
|
-
const toggleCheckbox = rowId => {
|
|
97
|
+
const toggleCheckbox = (rowId, row) => {
|
|
84
98
|
let _data = null;
|
|
99
|
+
if (typeof row.checkBoxProps?.onChange === 'function') {
|
|
100
|
+
row.checkBoxProps.onChange();
|
|
101
|
+
}
|
|
85
102
|
if (groupedRows) {
|
|
86
103
|
const [group, _] = rowId.split('-');
|
|
87
104
|
const id = parseInt(_, 10);
|
|
@@ -108,15 +125,18 @@ const DataGrid = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
108
125
|
}
|
|
109
126
|
setData(_row);
|
|
110
127
|
};
|
|
111
|
-
const HeaderCheckBoxDisplay = showCheckbox && /*#__PURE__*/_jsx(Checkbox, {
|
|
128
|
+
const HeaderCheckBoxDisplay = showCheckbox && !hideHeaderCheckBoxByRows && /*#__PURE__*/_jsx(Checkbox, {
|
|
112
129
|
label: getCopy('all'),
|
|
113
|
-
checked:
|
|
130
|
+
checked: checkAllState,
|
|
131
|
+
inactive: disableHeaderCheckbox,
|
|
114
132
|
onChange: toggleSelectAll
|
|
115
133
|
});
|
|
116
|
-
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) =>
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
134
|
+
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) => {
|
|
135
|
+
return _showCheckbox && !row.hideCheckbox && /*#__PURE__*/_jsx(Checkbox, {
|
|
136
|
+
...row.checkBoxProps,
|
|
137
|
+
onChange: () => toggleCheckbox(rowId, row)
|
|
138
|
+
});
|
|
139
|
+
};
|
|
120
140
|
const buildDisplayCaret = (row, rowId) => row.hasExpandedRow && /*#__PURE__*/_jsx(IconButton, {
|
|
121
141
|
onPress: () => toggleRowExpansion(rowId),
|
|
122
142
|
icon: row.isExpandedRowOpen === true ? hideExpandedRowIcon : expandRowIcon,
|
|
@@ -334,6 +354,16 @@ DataGrid.propTypes = {
|
|
|
334
354
|
expandedRowChildComponent: PropTypes.shape({
|
|
335
355
|
component: PropTypes.node,
|
|
336
356
|
displayOnLoad: PropTypes.bool.isRequired
|
|
357
|
+
}),
|
|
358
|
+
/**
|
|
359
|
+
* Set this to true to hide checkbox for the specified row
|
|
360
|
+
*/
|
|
361
|
+
hideCheckbox: PropTypes.bool,
|
|
362
|
+
checkBoxProps: PropTypes.shape({
|
|
363
|
+
checked: PropTypes.bool,
|
|
364
|
+
name: PropTypes.string,
|
|
365
|
+
value: PropTypes.string.isRequired,
|
|
366
|
+
onChange: PropTypes.func
|
|
337
367
|
})
|
|
338
368
|
})),
|
|
339
369
|
/**
|
package/lib/esm/utility.js
CHANGED
|
@@ -19,18 +19,34 @@ export const DATA_TYPE = {
|
|
|
19
19
|
const mappedData = array => {
|
|
20
20
|
return array.map(element => {
|
|
21
21
|
const eachRow = {
|
|
22
|
-
...element
|
|
23
|
-
isSelected: false
|
|
22
|
+
...element
|
|
24
23
|
};
|
|
25
24
|
if (eachRow.expandedRowChildComponent) {
|
|
26
25
|
eachRow.hasExpandedRow = true;
|
|
27
26
|
eachRow.isExpandedRowOpen = element.expandedRowChildComponent.displayOnLoad;
|
|
28
27
|
}
|
|
28
|
+
if (!eachRow.hideCheckbox) {
|
|
29
|
+
eachRow.hideCheckbox = false;
|
|
30
|
+
}
|
|
31
|
+
if (!eachRow.checkBoxProps) {
|
|
32
|
+
eachRow.checkBoxProps = {
|
|
33
|
+
value: `row_${eachRow.id}`,
|
|
34
|
+
inactive: false,
|
|
35
|
+
checked: false,
|
|
36
|
+
onChange: () => {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
29
39
|
return eachRow;
|
|
30
40
|
});
|
|
31
41
|
};
|
|
32
42
|
export const isAtLeastOneRowUnselected = array => {
|
|
33
|
-
return array.some(each => each.
|
|
43
|
+
return array.some(each => each.checkBoxProps?.inactive === false && each.checkBoxProps?.checked === false);
|
|
44
|
+
};
|
|
45
|
+
export const isAtLeastOneRowEnabled = array => {
|
|
46
|
+
return array.some(each => each.checkBoxProps?.inactive === false);
|
|
47
|
+
};
|
|
48
|
+
export const hasEveryRowHiddenItsCheckbox = array => {
|
|
49
|
+
return array.every(each => each.hideCheckbox === true);
|
|
34
50
|
};
|
|
35
51
|
export const resetColumnsData = data => {
|
|
36
52
|
return data.map(element => ({
|
|
@@ -55,17 +71,28 @@ export const resetRowData = function (data) {
|
|
|
55
71
|
};
|
|
56
72
|
export const toggleAllCheckBoxes = (array, headerCheckBoxState) => {
|
|
57
73
|
return array.map(element => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
let _el = null;
|
|
75
|
+
if (element.hideCheckbox === true || element.checkBoxProps && element.checkBoxProps.inactive) {
|
|
76
|
+
_el = {
|
|
77
|
+
...element
|
|
78
|
+
};
|
|
79
|
+
} else {
|
|
80
|
+
_el = {
|
|
81
|
+
...element
|
|
82
|
+
};
|
|
83
|
+
_el.checkBoxProps.checked = !headerCheckBoxState;
|
|
84
|
+
}
|
|
85
|
+
return _el;
|
|
62
86
|
});
|
|
63
87
|
};
|
|
64
88
|
export const toggleRowCheckbox = (array, rowId) => {
|
|
65
|
-
return array.map(el =>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
return array.map(el => {
|
|
90
|
+
const _el = {
|
|
91
|
+
...el
|
|
92
|
+
};
|
|
93
|
+
_el.checkBoxProps.checked = el.id === rowId ? !_el.checkBoxProps.checked : _el.checkBoxProps.checked;
|
|
94
|
+
return _el;
|
|
95
|
+
});
|
|
69
96
|
};
|
|
70
97
|
export const toggleExpandedRow = (array, rowId) => {
|
|
71
98
|
return array.map(el => ({
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
],
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"prop-types": "^15.7.2",
|
|
8
|
-
"@telus-uds/components-web": "^4.
|
|
9
|
-
"@telus-uds/components-base": "^3.
|
|
8
|
+
"@telus-uds/components-web": "^4.3.0",
|
|
9
|
+
"@telus-uds/components-base": "^3.4.0",
|
|
10
10
|
"@telus-uds/system-theme-tokens": "^4.2.0",
|
|
11
11
|
"styled-components": "6.1.13",
|
|
12
12
|
"smooth-scrollbar": "8.8.4",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"standard-engine": {
|
|
47
47
|
"skip": true
|
|
48
48
|
},
|
|
49
|
-
"version": "1.1
|
|
49
|
+
"version": "1.2.1"
|
|
50
50
|
}
|
package/src/DataGrid.jsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import {
|
|
4
4
|
Typography,
|
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
DATA_TYPE,
|
|
17
17
|
SORT_DIRECTION,
|
|
18
18
|
isAtLeastOneRowUnselected,
|
|
19
|
+
isAtLeastOneRowEnabled,
|
|
20
|
+
hasEveryRowHiddenItsCheckbox,
|
|
19
21
|
toggleAllCheckBoxes,
|
|
20
22
|
toggleExpandedRow,
|
|
21
23
|
toggleRowCheckbox,
|
|
@@ -61,18 +63,36 @@ const DataGrid = React.forwardRef(
|
|
|
61
63
|
)
|
|
62
64
|
const [columnsData, setColumnsData] = React.useState(resetColumnsData(columns))
|
|
63
65
|
const [checkAllState, setCheckAllState] = React.useState(false)
|
|
66
|
+
const [disableHeaderCheckbox, setDisableHeaderCheckbox] = React.useState(false)
|
|
67
|
+
const [hideHeaderCheckBoxByRows, setHideHeaderCheckBoxByRows] = React.useState(false)
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
let _isAtLeastOneRowUnselected = null
|
|
71
|
+
let _isAtLeastOneRowEnabled = null
|
|
72
|
+
let _hideHeaderCheckBoxByRows = null
|
|
64
73
|
|
|
65
|
-
const shouldCheckHeaderBox = (allData) => {
|
|
66
|
-
let isARowUnselectedInAllGroups = null
|
|
67
74
|
if (groupedRows) {
|
|
68
|
-
|
|
69
|
-
return isAtLeastOneRowUnselected(
|
|
75
|
+
_isAtLeastOneRowUnselected = Object.keys(data).some((el) => {
|
|
76
|
+
return isAtLeastOneRowUnselected(data[el].data)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
_isAtLeastOneRowEnabled = Object.keys(data).some((el) => {
|
|
80
|
+
return isAtLeastOneRowEnabled(data[el].data)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
_hideHeaderCheckBoxByRows = Object.keys(data).some((el) => {
|
|
84
|
+
return hasEveryRowHiddenItsCheckbox(data[el].data)
|
|
70
85
|
})
|
|
71
86
|
} else {
|
|
72
|
-
|
|
87
|
+
_isAtLeastOneRowUnselected = isAtLeastOneRowUnselected(data)
|
|
88
|
+
_isAtLeastOneRowEnabled = isAtLeastOneRowEnabled(data)
|
|
89
|
+
_hideHeaderCheckBoxByRows = hasEveryRowHiddenItsCheckbox(data)
|
|
73
90
|
}
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
|
|
92
|
+
setCheckAllState(_isAtLeastOneRowEnabled === false ? false : !_isAtLeastOneRowUnselected)
|
|
93
|
+
setDisableHeaderCheckbox(!_isAtLeastOneRowEnabled)
|
|
94
|
+
setHideHeaderCheckBoxByRows(_hideHeaderCheckBoxByRows)
|
|
95
|
+
}, [data, groupedRows])
|
|
76
96
|
|
|
77
97
|
const shouldDisplayIconColumn = (allData, _showCheckbox) => {
|
|
78
98
|
let doesOneRowHaveExpandedContent = null
|
|
@@ -102,8 +122,13 @@ const DataGrid = React.forwardRef(
|
|
|
102
122
|
setCheckAllState(!checkAllState)
|
|
103
123
|
}
|
|
104
124
|
|
|
105
|
-
const toggleCheckbox = (rowId) => {
|
|
125
|
+
const toggleCheckbox = (rowId, row) => {
|
|
106
126
|
let _data = null
|
|
127
|
+
|
|
128
|
+
if (typeof row.checkBoxProps?.onChange === 'function') {
|
|
129
|
+
row.checkBoxProps.onChange()
|
|
130
|
+
}
|
|
131
|
+
|
|
107
132
|
if (groupedRows) {
|
|
108
133
|
const [group, _] = rowId.split('-')
|
|
109
134
|
const id = parseInt(_, 10)
|
|
@@ -128,16 +153,23 @@ const DataGrid = React.forwardRef(
|
|
|
128
153
|
setData(_row)
|
|
129
154
|
}
|
|
130
155
|
|
|
131
|
-
const HeaderCheckBoxDisplay = showCheckbox && (
|
|
156
|
+
const HeaderCheckBoxDisplay = showCheckbox && !hideHeaderCheckBoxByRows && (
|
|
132
157
|
<Checkbox
|
|
133
158
|
label={getCopy('all')}
|
|
134
|
-
checked={
|
|
159
|
+
checked={checkAllState}
|
|
160
|
+
inactive={disableHeaderCheckbox}
|
|
135
161
|
onChange={toggleSelectAll}
|
|
136
162
|
/>
|
|
137
163
|
)
|
|
138
164
|
|
|
139
|
-
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) =>
|
|
140
|
-
|
|
165
|
+
const buildCheckBoxDisplay = (_showCheckbox, row, rowId) => {
|
|
166
|
+
return (
|
|
167
|
+
_showCheckbox &&
|
|
168
|
+
!row.hideCheckbox && (
|
|
169
|
+
<Checkbox {...row.checkBoxProps} onChange={() => toggleCheckbox(rowId, row)} />
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
}
|
|
141
173
|
|
|
142
174
|
const buildDisplayCaret = (row, rowId) =>
|
|
143
175
|
row.hasExpandedRow && (
|
|
@@ -439,6 +471,16 @@ DataGrid.propTypes = {
|
|
|
439
471
|
expandedRowChildComponent: PropTypes.shape({
|
|
440
472
|
component: PropTypes.node,
|
|
441
473
|
displayOnLoad: PropTypes.bool.isRequired
|
|
474
|
+
}),
|
|
475
|
+
/**
|
|
476
|
+
* Set this to true to hide checkbox for the specified row
|
|
477
|
+
*/
|
|
478
|
+
hideCheckbox: PropTypes.bool,
|
|
479
|
+
checkBoxProps: PropTypes.shape({
|
|
480
|
+
checked: PropTypes.bool,
|
|
481
|
+
name: PropTypes.string,
|
|
482
|
+
value: PropTypes.string.isRequired,
|
|
483
|
+
onChange: PropTypes.func
|
|
442
484
|
})
|
|
443
485
|
})
|
|
444
486
|
),
|
package/src/utility.jsx
CHANGED
|
@@ -22,17 +22,40 @@ export const DATA_TYPE = {
|
|
|
22
22
|
|
|
23
23
|
const mappedData = (array) => {
|
|
24
24
|
return array.map((element) => {
|
|
25
|
-
const eachRow = { ...element
|
|
25
|
+
const eachRow = { ...element }
|
|
26
26
|
if (eachRow.expandedRowChildComponent) {
|
|
27
27
|
eachRow.hasExpandedRow = true
|
|
28
28
|
eachRow.isExpandedRowOpen = element.expandedRowChildComponent.displayOnLoad
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
if (!eachRow.hideCheckbox) {
|
|
32
|
+
eachRow.hideCheckbox = false
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!eachRow.checkBoxProps) {
|
|
36
|
+
eachRow.checkBoxProps = {
|
|
37
|
+
value: `row_${eachRow.id}`,
|
|
38
|
+
inactive: false,
|
|
39
|
+
checked: false,
|
|
40
|
+
onChange: () => {}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
30
43
|
return eachRow
|
|
31
44
|
})
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
export const isAtLeastOneRowUnselected = (array) => {
|
|
35
|
-
return array.some(
|
|
48
|
+
return array.some(
|
|
49
|
+
(each) => each.checkBoxProps?.inactive === false && each.checkBoxProps?.checked === false
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const isAtLeastOneRowEnabled = (array) => {
|
|
54
|
+
return array.some((each) => each.checkBoxProps?.inactive === false)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const hasEveryRowHiddenItsCheckbox = (array) => {
|
|
58
|
+
return array.every((each) => each.hideCheckbox === true)
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
export const resetColumnsData = (data) => {
|
|
@@ -49,6 +72,7 @@ export const resetRowData = (data, isGrouped = false) => {
|
|
|
49
72
|
data.forEach((el) => {
|
|
50
73
|
result[el.key] = { ...el, data: mappedData(el.data) }
|
|
51
74
|
})
|
|
75
|
+
|
|
52
76
|
return result
|
|
53
77
|
}
|
|
54
78
|
|
|
@@ -57,15 +81,27 @@ export const resetRowData = (data, isGrouped = false) => {
|
|
|
57
81
|
|
|
58
82
|
export const toggleAllCheckBoxes = (array, headerCheckBoxState) => {
|
|
59
83
|
return array.map((element) => {
|
|
60
|
-
|
|
84
|
+
let _el = null
|
|
85
|
+
if (
|
|
86
|
+
element.hideCheckbox === true ||
|
|
87
|
+
(element.checkBoxProps && element.checkBoxProps.inactive)
|
|
88
|
+
) {
|
|
89
|
+
_el = { ...element }
|
|
90
|
+
} else {
|
|
91
|
+
_el = { ...element }
|
|
92
|
+
_el.checkBoxProps.checked = !headerCheckBoxState
|
|
93
|
+
}
|
|
94
|
+
return _el
|
|
61
95
|
})
|
|
62
96
|
}
|
|
63
97
|
|
|
64
98
|
export const toggleRowCheckbox = (array, rowId) => {
|
|
65
|
-
return array.map((el) =>
|
|
66
|
-
...el
|
|
67
|
-
|
|
68
|
-
|
|
99
|
+
return array.map((el) => {
|
|
100
|
+
const _el = { ...el }
|
|
101
|
+
_el.checkBoxProps.checked =
|
|
102
|
+
el.id === rowId ? !_el.checkBoxProps.checked : _el.checkBoxProps.checked
|
|
103
|
+
return _el
|
|
104
|
+
})
|
|
69
105
|
}
|
|
70
106
|
|
|
71
107
|
export const toggleExpandedRow = (array, rowId) => {
|