@widergy/energy-ui 2.12.1 → 2.12.3
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.
|
@@ -16,6 +16,7 @@ var _ActionIcons = _interopRequireDefault(require("../ActionIcons"));
|
|
|
16
16
|
var _PrimaryAction = _interopRequireDefault(require("../PrimaryAction"));
|
|
17
17
|
var _types = require("../../types");
|
|
18
18
|
var _constants2 = require("./constants");
|
|
19
|
+
var _utils = require("./utils");
|
|
19
20
|
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
20
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
22
|
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); }
|
|
@@ -54,7 +55,8 @@ const TableRow = _ref => {
|
|
|
54
55
|
secondaryActions = []
|
|
55
56
|
} = columnsDefinition;
|
|
56
57
|
const SelectionComponent = exclusiveSelection ? _Radio.default : _Checkbox.default;
|
|
57
|
-
const
|
|
58
|
+
const hasActionsRow = selectable || (0, _utils.hasVisibleActions)(secondaryActions, cellProps.rowData);
|
|
59
|
+
const selectableCellStyles = isResponsive ? "".concat(_stylesModule.default.secondaryActionsContainer, "\n ").concat(cellProps.classes.responsiveCell, "\n ").concat(hasActionsRow ? cellProps.classes.responsiveRowTopBorder : _stylesModule.default.hidden, "\n ") : "\n\t".concat(_stylesModule.default.fixedRowLeft, "\n\t").concat(fixedRowsLeftClassName, "\n\t").concat((removeFixedRowsDivisors || (0, _array.isEmpty)(fixedLeftColumns)) && _stylesModule.default.disableBorderRight, "\n\t").concat(!selectable && (0, _array.isEmpty)(fixedLeftColumns) && _stylesModule.default.cleanFixedColumns, "\n");
|
|
58
60
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_UTTouchableWithoutFeedback.default, {
|
|
59
61
|
onClick: handleRowClick,
|
|
60
62
|
className: "\n ".concat(_stylesModule.default.row, "\n ").concat((!handleRowClick || isResponsive) && _stylesModule.default.noClick, "\n ").concat(isResponsive && cellProps.classes.responsiveRow, "\n ").concat(className, "\n "),
|
|
@@ -102,7 +104,7 @@ const TableRow = _ref => {
|
|
|
102
104
|
rowData: cellProps.rowData,
|
|
103
105
|
classes: cellProps.classes
|
|
104
106
|
})))), !(0, _array.isEmpty)(secondaryColumns) && /*#__PURE__*/_react.default.createElement("div", {
|
|
105
|
-
className: "\n ".concat(_stylesModule.default.secondaryColumns, " \n ").concat(isResponsive && checkBoxSelected && cellProps.classes.selectedResponsiveCell, "\n ").concat(isResponsive && selectable && _stylesModule.default.hideTopBorder, "\n "),
|
|
107
|
+
className: "\n ".concat(_stylesModule.default.secondaryColumns, " \n ").concat(isResponsive && checkBoxSelected && cellProps.classes.selectedResponsiveCell, "\n ").concat(isResponsive && selectable && _stylesModule.default.hideTopBorder, "\n ").concat(isResponsive && hasActionsRow && _stylesModule.default.fixBorderRadius, "\n "),
|
|
106
108
|
style: {
|
|
107
109
|
width: isResponsive ? 'auto' : columnSizes.secondaryColumnsSize
|
|
108
110
|
}
|
|
@@ -133,7 +133,7 @@ $selection-element-size: 42px;
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
.hidden {
|
|
136
|
-
display: none;
|
|
136
|
+
display: none !important;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
.hideTopBorder {
|
|
@@ -146,3 +146,10 @@ $selection-element-size: 42px;
|
|
|
146
146
|
.disableSelectionTooltip {
|
|
147
147
|
text-align: center;
|
|
148
148
|
}
|
|
149
|
+
|
|
150
|
+
.fixBorderRadius {
|
|
151
|
+
& :first-child {
|
|
152
|
+
border-top-left-radius: 0 !important;
|
|
153
|
+
border-top-right-radius: 0 !important;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasVisibleActions = void 0;
|
|
7
|
+
var _array = require("@widergy/web-utils/lib/array");
|
|
8
|
+
const hasVisibleActions = (secondaryActions, rowData) => !(0, _array.isEmpty)(secondaryActions) && secondaryActions.some(secondaryAction => {
|
|
9
|
+
var _secondaryAction$acti;
|
|
10
|
+
return secondaryAction === null || secondaryAction === void 0 || (_secondaryAction$acti = secondaryAction.actions) === null || _secondaryAction$acti === void 0 ? void 0 : _secondaryAction$acti.some(action => {
|
|
11
|
+
var _action$isVisible;
|
|
12
|
+
return (_action$isVisible = action.isVisible) === null || _action$isVisible === void 0 ? void 0 : _action$isVisible.call(action, rowData);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
exports.hasVisibleActions = hasVisibleActions;
|
|
@@ -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 _utils = 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, _utils.getInitialValidRowsPerPage)(externalRowsPerPage, rowsPerPageOptions, data);
|
|
83
|
+
const initialValidPage = (0, _utils.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,15 +102,15 @@ 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, _utils.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, _utils.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, _utils.orderRows)(rows, newOrder, data, columns));
|
|
114
114
|
if (onOrderChange) onOrderChange(newOrder);
|
|
115
115
|
};
|
|
116
116
|
const handlePageChange = newPage => {
|
|
@@ -123,7 +123,7 @@ const UTTable = _ref => {
|
|
|
123
123
|
};
|
|
124
124
|
const selectRow = row => {
|
|
125
125
|
if (!row[rowKey]) return null;
|
|
126
|
-
const pageRowsIds = (0,
|
|
126
|
+
const pageRowsIds = (0, _utils.getSelectableRowIds)(currentRows, rowKey, disableRowSelection);
|
|
127
127
|
let newSelectedRows = [];
|
|
128
128
|
if (exclusiveSelection) {
|
|
129
129
|
newSelectedRows = [row[rowKey]];
|
|
@@ -140,19 +140,19 @@ const UTTable = _ref => {
|
|
|
140
140
|
};
|
|
141
141
|
const selectAllRows = () => {
|
|
142
142
|
const newSelectedAll = !selectedAll;
|
|
143
|
-
const pageRowsIds = (0,
|
|
144
|
-
const newSelectedRows = selectAllInCurrentPageOnly ? newSelectedAll ? [...pageRowsIds, ...selectedRows.filter(row => !pageRowsIds.includes(row))] : selectedRows.filter(row => !pageRowsIds.includes(row)) : newSelectedAll ? (0,
|
|
143
|
+
const pageRowsIds = (0, _utils.getSelectableRowIds)(currentRows, rowKey, disableRowSelection);
|
|
144
|
+
const newSelectedRows = selectAllInCurrentPageOnly ? newSelectedAll ? [...pageRowsIds, ...selectedRows.filter(row => !pageRowsIds.includes(row))] : selectedRows.filter(row => !pageRowsIds.includes(row)) : newSelectedAll ? (0, _utils.getSelectableRowIds)(rows, rowKey, disableRowSelection) : [];
|
|
145
145
|
setSelectedRows(newSelectedRows);
|
|
146
146
|
setSelectedAll(newSelectedAll);
|
|
147
147
|
if (onSelectAllRows) onSelectAllRows(selectAllInCurrentPageOnly ? newSelectedRows : newSelectedAll);
|
|
148
148
|
};
|
|
149
149
|
(0, _react.useEffect)(() => {
|
|
150
150
|
if (selectAllInCurrentPageOnly) {
|
|
151
|
-
const pageRowsIds = (0,
|
|
151
|
+
const pageRowsIds = (0, _utils.getSelectableRowIds)(currentRows, rowKey, disableRowSelection);
|
|
152
152
|
setSelectedAll(!(0, _array.isEmpty)(pageRowsIds) && pageRowsIds.every(row => selectedRows.includes(row)));
|
|
153
153
|
}
|
|
154
154
|
}, [page, rowsPerPage, rows, order, disableSelectAll]);
|
|
155
|
-
const columnsDefinition = (0, _react.useMemo)(() => (0,
|
|
155
|
+
const columnsDefinition = (0, _react.useMemo)(() => (0, _utils.getColumnDefinition)(columns, isResponsive), [columns, isResponsive]);
|
|
156
156
|
const isFirstRow = (0, _react.useCallback)(index => !index, []);
|
|
157
157
|
const isLastRow = (0, _react.useCallback)(index => index === currentRows.length - 1, [currentRows]);
|
|
158
158
|
const onChangeRowPerPage = newRowsPerPage => {
|
|
@@ -161,7 +161,7 @@ const UTTable = _ref => {
|
|
|
161
161
|
if (onRowsPerPageChange) onRowsPerPageChange(newRowsPerPage || rowsPerPageOptions[0]);
|
|
162
162
|
};
|
|
163
163
|
const showPagination = !disablePagination && !loading && !(0, _array.isEmpty)(currentRows);
|
|
164
|
-
const rowStyles = (0, _react.useMemo)(() => (0,
|
|
164
|
+
const rowStyles = (0, _react.useMemo)(() => (0, _utils.createRowStyles)(rowPadding, rowSpacing, headerPadding, isResponsive), [rowPadding, rowSpacing, headerPadding, isResponsive]);
|
|
165
165
|
const tableWidth = (0, _react.useMemo)(() => {
|
|
166
166
|
var _entry$target;
|
|
167
167
|
return (entry === null || entry === void 0 || (_entry$target = entry.target) === null || _entry$target === void 0 ? void 0 : _entry$target.clientWidth) || '100%';
|
|
@@ -178,7 +178,7 @@ const UTTable = _ref => {
|
|
|
178
178
|
var _event$target;
|
|
179
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);
|
|
180
180
|
};
|
|
181
|
-
const columnSizes = (0, _react.useMemo)(() => (0,
|
|
181
|
+
const columnSizes = (0, _react.useMemo)(() => (0, _utils.getColumnsSizes)({
|
|
182
182
|
columns,
|
|
183
183
|
fitColumnsWidth,
|
|
184
184
|
selectable
|