@widergy/energy-ui 3.1.4 → 3.1.6
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
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [3.1.6](https://github.com/widergy/energy-ui/compare/v3.1.5...v3.1.6) (2024-02-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* uttable select all logic not working ([#408](https://github.com/widergy/energy-ui/issues/408)) ([a61e69b](https://github.com/widergy/energy-ui/commit/a61e69b26afa6f2097ada3dac007bc9c3f2fd6e4))
|
|
7
|
+
|
|
8
|
+
## [3.1.5](https://github.com/widergy/energy-ui/compare/v3.1.4...v3.1.5) (2024-01-31)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* change gmaps key env -> props ([#404](https://github.com/widergy/energy-ui/issues/404)) ([59953a3](https://github.com/widergy/energy-ui/commit/59953a3472c169d40faf750b92ae363854c1e0b6))
|
|
14
|
+
|
|
1
15
|
## [3.1.4](https://github.com/widergy/energy-ui/compare/v3.1.3...v3.1.4) (2024-01-23)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -34,6 +34,7 @@ const UTMapPropTypes = exports.UTMapPropTypes = {
|
|
|
34
34
|
field: _formTypes.fieldType,
|
|
35
35
|
meta: _formTypes.metaPropTypes,
|
|
36
36
|
input: _formTypes.inputPropTypes,
|
|
37
|
+
apiKey: _propTypes.string,
|
|
37
38
|
disabled: _propTypes.bool
|
|
38
39
|
};
|
|
39
40
|
const GoogleMapsPropTypes = exports.GoogleMapsPropTypes = {
|
|
@@ -6,18 +6,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _withScriptjs = _interopRequireDefault(require("react-google-maps/lib/withScriptjs"));
|
|
9
|
+
var _types = require("./types");
|
|
9
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
11
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
11
12
|
const WithGoogleMapScript = () => WrappedComponent => {
|
|
12
13
|
const Component = (0, _withScriptjs.default)(WrappedComponent);
|
|
13
|
-
const WithGoogleMap =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const WithGoogleMap = _ref => {
|
|
15
|
+
let {
|
|
16
|
+
apiKey,
|
|
17
|
+
...props
|
|
18
|
+
} = _ref;
|
|
19
|
+
return /*#__PURE__*/_react.default.createElement(Component, _extends({
|
|
20
|
+
googleMapURL: "https://maps.googleapis.com/maps/api/js?libraries=places,geometry&key=".concat(apiKey),
|
|
21
|
+
loadingElement: /*#__PURE__*/_react.default.createElement("div", {
|
|
22
|
+
style: {
|
|
23
|
+
height: "100%"
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}, props));
|
|
27
|
+
};
|
|
28
|
+
WithGoogleMap.propTypes = _types.UTMapPropTypes.propTypes;
|
|
21
29
|
return WithGoogleMap;
|
|
22
30
|
};
|
|
23
31
|
var _default = exports.default = WithGoogleMapScript;
|
|
@@ -23,7 +23,7 @@ var _ResponsiveCell = _interopRequireDefault(require("./components/ResponsiveCel
|
|
|
23
23
|
var _TableRow = _interopRequireDefault(require("./components/TableRow"));
|
|
24
24
|
var _theme = require("./theme");
|
|
25
25
|
var _constants = require("./constants");
|
|
26
|
-
var
|
|
26
|
+
var _utils2 = require("./utils");
|
|
27
27
|
var _types = require("./types");
|
|
28
28
|
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
29
29
|
var _hook = require("./hook");
|
|
@@ -79,8 +79,8 @@ const UTTable = _ref => {
|
|
|
79
79
|
totalRows,
|
|
80
80
|
totalRowsLabel
|
|
81
81
|
} = _ref;
|
|
82
|
-
const initialValidRowsPerPageOption = (0,
|
|
83
|
-
const initialValidPage = (0,
|
|
82
|
+
const initialValidRowsPerPageOption = (0, _utils2.getInitialValidRowsPerPage)(externalRowsPerPage, rowsPerPageOptions, data);
|
|
83
|
+
const initialValidPage = (0, _utils2.getInitialValidPage)(externalPage, initialValidRowsPerPageOption, data, integrationType);
|
|
84
84
|
const [order, setOrder] = (0, _react.useState)(initialOrder || {});
|
|
85
85
|
const [rows, setRows] = (0, _react.useState)([]);
|
|
86
86
|
const [selectedAll, setSelectedAll] = (0, _react.useState)(false);
|
|
@@ -102,24 +102,28 @@ const UTTable = _ref => {
|
|
|
102
102
|
(0, _react.useEffect)(() => {
|
|
103
103
|
if (!selectAllInCurrentPageOnly) setSelectedAll(!(0, _array.isEmpty)(data) && initialSelectedRows.length === data.length);
|
|
104
104
|
setSelectedRows(selectable ? initialSelectedRows : []);
|
|
105
|
-
setRows((0,
|
|
105
|
+
setRows((0, _utils2.orderRows)(data, order, data, columns));
|
|
106
106
|
if (externalRowsPerPage) setRowsPerPage(initialValidRowsPerPageOption);
|
|
107
107
|
const validPage = data.length / rowsPerPage > page || integrationType === _UTTable.INTEGRATION_TYPES.EXTERNAL;
|
|
108
108
|
if (!validPage) setPage(initialValidPage);
|
|
109
109
|
}, [data]);
|
|
110
|
-
const currentRows = (0, _react.useMemo)(() => disablePagination || integrationType === _UTTable.INTEGRATION_TYPES.EXTERNAL ? rows : (0,
|
|
110
|
+
const currentRows = (0, _react.useMemo)(() => disablePagination || integrationType === _UTTable.INTEGRATION_TYPES.EXTERNAL ? rows : (0, _utils2.getCurrentRows)(rows, page, rowsPerPage), [page, rowsPerPage, rows]);
|
|
111
111
|
const handleOrder = newOrder => {
|
|
112
112
|
setOrder(newOrder);
|
|
113
|
-
if (!disableAutoOrder && !(0, _array.isEmpty)(rows)) setRows((0,
|
|
113
|
+
if (!disableAutoOrder && !(0, _array.isEmpty)(rows)) setRows((0, _utils2.orderRows)(rows, newOrder, data, columns));
|
|
114
114
|
if (onOrderChange) onOrderChange(newOrder);
|
|
115
115
|
};
|
|
116
116
|
const handlePageChange = newPage => {
|
|
117
117
|
setPage(newPage);
|
|
118
118
|
if (onPageChange) onPageChange(newPage);
|
|
119
119
|
};
|
|
120
|
+
const allDisplayedRowsAreSelected = newSelectedRows => {
|
|
121
|
+
const displayedRows = (0, _utils.getSelectableRowIds)(rows, rowKey, disableRowSelection);
|
|
122
|
+
return displayedRows.every(value => newSelectedRows.includes(value));
|
|
123
|
+
};
|
|
120
124
|
const selectRow = row => {
|
|
121
125
|
if (!row[rowKey]) return null;
|
|
122
|
-
const pageRowsIds = (0,
|
|
126
|
+
const pageRowsIds = (0, _utils2.getSelectableRowIds)(currentRows, rowKey, disableRowSelection);
|
|
123
127
|
let newSelectedRows = [];
|
|
124
128
|
if (exclusiveSelection) {
|
|
125
129
|
newSelectedRows = [row[rowKey]];
|
|
@@ -127,7 +131,7 @@ const UTTable = _ref => {
|
|
|
127
131
|
const rowKeyIndex = selectedRows.indexOf(row[rowKey]);
|
|
128
132
|
if (rowKeyIndex === -1) newSelectedRows = [...selectedRows, row[rowKey]];else newSelectedRows = selectedRows.filter(el => el !== row[rowKey]);
|
|
129
133
|
const pageNewSelectedRows = newSelectedRows.filter(newSelectedRow => pageRowsIds.includes(newSelectedRow));
|
|
130
|
-
const allSelected = selectAllInCurrentPageOnly ? pageNewSelectedRows.length === pageRowsIds.length : newSelectedRows
|
|
134
|
+
const allSelected = selectAllInCurrentPageOnly ? pageNewSelectedRows.length === pageRowsIds.length : allDisplayedRowsAreSelected(newSelectedRows);
|
|
131
135
|
if (!allSelected && selectedAll) setSelectedAll(false);
|
|
132
136
|
if (allSelected && !selectedAll) setSelectedAll(true);
|
|
133
137
|
}
|
|
@@ -136,19 +140,19 @@ const UTTable = _ref => {
|
|
|
136
140
|
};
|
|
137
141
|
const selectAllRows = () => {
|
|
138
142
|
const newSelectedAll = !selectedAll;
|
|
139
|
-
const pageRowsIds = (0,
|
|
140
|
-
const newSelectedRows = selectAllInCurrentPageOnly ? newSelectedAll ? [...pageRowsIds, ...selectedRows.filter(row => !pageRowsIds.includes(row))] : selectedRows.filter(row => !pageRowsIds.includes(row)) : newSelectedAll ? (0,
|
|
143
|
+
const pageRowsIds = (0, _utils2.getSelectableRowIds)(currentRows, rowKey, disableRowSelection);
|
|
144
|
+
const newSelectedRows = selectAllInCurrentPageOnly ? newSelectedAll ? [...pageRowsIds, ...selectedRows.filter(row => !pageRowsIds.includes(row))] : selectedRows.filter(row => !pageRowsIds.includes(row)) : newSelectedAll ? (0, _utils2.getSelectableRowIds)(rows, rowKey, disableRowSelection) : [];
|
|
141
145
|
setSelectedRows(newSelectedRows);
|
|
142
146
|
setSelectedAll(newSelectedAll);
|
|
143
147
|
if (onSelectAllRows) onSelectAllRows(selectAllInCurrentPageOnly ? newSelectedRows : newSelectedAll);
|
|
144
148
|
};
|
|
145
149
|
(0, _react.useEffect)(() => {
|
|
146
150
|
if (selectAllInCurrentPageOnly) {
|
|
147
|
-
const pageRowsIds = (0,
|
|
151
|
+
const pageRowsIds = (0, _utils2.getSelectableRowIds)(currentRows, rowKey, disableRowSelection);
|
|
148
152
|
setSelectedAll(!(0, _array.isEmpty)(pageRowsIds) && pageRowsIds.every(row => selectedRows.includes(row)));
|
|
149
153
|
}
|
|
150
154
|
}, [page, rowsPerPage, rows, order, disableSelectAll]);
|
|
151
|
-
const columnsDefinition = (0, _react.useMemo)(() => (0,
|
|
155
|
+
const columnsDefinition = (0, _react.useMemo)(() => (0, _utils2.getColumnDefinition)(columns, isResponsive), [columns, isResponsive]);
|
|
152
156
|
const isFirstRow = (0, _react.useCallback)(index => !index, []);
|
|
153
157
|
const isLastRow = (0, _react.useCallback)(index => index === currentRows.length - 1, [currentRows]);
|
|
154
158
|
const onChangeRowPerPage = newRowsPerPage => {
|
|
@@ -157,7 +161,7 @@ const UTTable = _ref => {
|
|
|
157
161
|
if (onRowsPerPageChange) onRowsPerPageChange(newRowsPerPage || rowsPerPageOptions[0]);
|
|
158
162
|
};
|
|
159
163
|
const showPagination = !disablePagination && !loading && !(0, _array.isEmpty)(currentRows);
|
|
160
|
-
const rowStyles = (0, _react.useMemo)(() => (0,
|
|
164
|
+
const rowStyles = (0, _react.useMemo)(() => (0, _utils2.createRowStyles)(rowPadding, rowSpacing, headerPadding, isResponsive), [rowPadding, rowSpacing, headerPadding, isResponsive]);
|
|
161
165
|
const tableWidth = (0, _react.useMemo)(() => {
|
|
162
166
|
var _entry$target;
|
|
163
167
|
return (entry === null || entry === void 0 || (_entry$target = entry.target) === null || _entry$target === void 0 ? void 0 : _entry$target.clientWidth) || '100%';
|
|
@@ -174,7 +178,7 @@ const UTTable = _ref => {
|
|
|
174
178
|
var _event$target;
|
|
175
179
|
if (contentRef.current && stickyHeader) contentRef.current.scrollTo(event === null || event === void 0 || (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.scrollLeft, 0);
|
|
176
180
|
};
|
|
177
|
-
const columnSizes = (0, _react.useMemo)(() => (0,
|
|
181
|
+
const columnSizes = (0, _react.useMemo)(() => (0, _utils2.getColumnsSizes)({
|
|
178
182
|
columns,
|
|
179
183
|
fitColumnsWidth,
|
|
180
184
|
selectable
|