@synerise/ds-table 0.53.2 → 0.55.0

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +9 -0
  3. package/dist/Cell/Star/StarCell.d.ts +1 -1
  4. package/dist/DefaultTable/DefaultTable.d.ts +2 -2
  5. package/dist/DefaultTable/DefaultTable.js +55 -50
  6. package/dist/InfiniteScroll/ErrorItem.d.ts +6 -0
  7. package/dist/InfiniteScroll/ErrorItem.js +28 -0
  8. package/dist/InfiniteScroll/InfiniteLoaderItem.d.ts +2 -2
  9. package/dist/InfiniteScroll/InfiniteLoaderItem.js +22 -54
  10. package/dist/InfiniteScroll/LoadingItem.d.ts +2 -0
  11. package/dist/InfiniteScroll/LoadingItem.js +11 -0
  12. package/dist/InfiniteScroll/NoMoreItem.d.ts +2 -0
  13. package/dist/InfiniteScroll/NoMoreItem.js +11 -0
  14. package/dist/RowSelection/RowSelectionColumn.d.ts +2 -2
  15. package/dist/RowSelection/RowSelectionColumn.js +41 -33
  16. package/dist/RowSelection/RowSelectionColumn.types.d.ts +4 -2
  17. package/dist/Table.js +6 -3
  18. package/dist/Table.types.d.ts +4 -0
  19. package/dist/TableHeader/TableHeader.js +7 -4
  20. package/dist/TableHeader/TableHeader.types.d.ts +1 -0
  21. package/dist/TableHeader/TableSelection.d.ts +3 -3
  22. package/dist/TableHeader/TableSelection.js +69 -47
  23. package/dist/TableHeader/TableSelection.types.d.ts +1 -0
  24. package/dist/VirtualTable/VirtualTable.js +45 -32
  25. package/dist/utils/getChildrenColumnName.d.ts +1 -0
  26. package/dist/utils/getChildrenColumnName.js +4 -0
  27. package/dist/utils/getRecordSelectionStatus.d.ts +8 -0
  28. package/dist/utils/getRecordSelectionStatus.js +10 -0
  29. package/dist/utils/index.d.ts +4 -0
  30. package/dist/utils/index.js +5 -1
  31. package/dist/utils/isRecordSelectable.d.ts +5 -0
  32. package/dist/utils/isRecordSelectable.js +12 -0
  33. package/package.json +29 -31
@@ -27,7 +27,8 @@ var TableHeader = function TableHeader(_ref) {
27
27
  headerButton = _ref.headerButton,
28
28
  locale = _ref.locale,
29
29
  renderSelectionTitle = _ref.renderSelectionTitle,
30
- hideTitlePart = _ref.hideTitlePart;
30
+ hideTitlePart = _ref.hideTitlePart,
31
+ childrenColumnName = _ref.childrenColumnName;
31
32
 
32
33
  var _useDataFormat = useDataFormat(),
33
34
  formatValue = _useDataFormat.formatValue;
@@ -59,7 +60,8 @@ var TableHeader = function TableHeader(_ref) {
59
60
  dataSource: dataSource,
60
61
  dataSourceFull: dataSourceFull,
61
62
  selection: selection,
62
- locale: locale
63
+ locale: locale,
64
+ childrenColumnName: childrenColumnName
63
65
  }), renderSelectionTitle ? renderSelectionTitle(selection, filters) : /*#__PURE__*/React.createElement(S.TitleContainer, null, /*#__PURE__*/React.createElement(S.TitlePart, null, /*#__PURE__*/React.createElement("strong", null, formatValue(selectedRows)), " ", /*#__PURE__*/React.createElement("span", null, locale.selected))), itemsMenu) : /*#__PURE__*/React.createElement(S.Left, {
64
66
  "data-testid": "ds-table-title"
65
67
  }, selection && /*#__PURE__*/React.createElement(TableSelection, {
@@ -67,7 +69,8 @@ var TableHeader = function TableHeader(_ref) {
67
69
  dataSource: dataSource,
68
70
  dataSourceFull: dataSourceFull,
69
71
  selection: selection,
70
- locale: locale
72
+ locale: locale,
73
+ childrenColumnName: childrenColumnName
71
74
  }), /*#__PURE__*/React.createElement(S.TitleContainer, null, title && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(S.TitlePartEllipsis, null, isTitleTruncated ? /*#__PURE__*/React.createElement(Tooltip, {
72
75
  type: "largeSimple",
73
76
  description: title,
@@ -78,7 +81,7 @@ var TableHeader = function TableHeader(_ref) {
78
81
  }, title)) : /*#__PURE__*/React.createElement("strong", {
79
82
  ref: titleRef
80
83
  }, title)), !hideTitlePart && /*#__PURE__*/React.createElement(S.TitleSeparator, null)), !hideTitlePart && /*#__PURE__*/React.createElement(S.TitlePart, null, /*#__PURE__*/React.createElement("strong", null, formatValue(dataSourceTotalCount)), " ", /*#__PURE__*/React.createElement("span", null, locale.pagination.items))));
81
- }, [selection, dataSource, itemsMenu, locale, selectedRows, rowKey, dataSourceFull, renderSelectionTitle, filters, formatValue, title, isTitleTruncated, hideTitlePart, dataSourceTotalCount]);
84
+ }, [selection, dataSource, itemsMenu, locale, selectedRows, rowKey, dataSourceFull, renderSelectionTitle, filters, formatValue, title, isTitleTruncated, hideTitlePart, dataSourceTotalCount, childrenColumnName]);
82
85
  return /*#__PURE__*/React.createElement(S.Header, {
83
86
  withBorderTop: withBorderTop
84
87
  }, renderLeftSide, /*#__PURE__*/React.createElement(S.Right, null, headerButton, filters == null ? void 0 : filters.map(function (filter) {
@@ -19,4 +19,5 @@ export type Props<T extends {
19
19
  renderSelectionTitle?: (selection?: RowSelection<T>, filters?: Filter[]) => ReactNode;
20
20
  hideTitlePart?: boolean;
21
21
  dataSourceTotalCount?: number;
22
+ childrenColumnName: string;
22
23
  };
@@ -1,7 +1,7 @@
1
- import * as React from 'react';
1
+ import type { ReactElement, ReactText } from 'react';
2
2
  import { Props } from './TableSelection.types';
3
3
  declare function TableSelection<T extends {
4
- key: React.ReactText;
4
+ key: ReactText;
5
5
  children?: T[];
6
- }>({ dataSource, dataSourceFull, selection, rowKey, locale, }: Props<T>): React.ReactElement | null;
6
+ }>({ dataSource, dataSourceFull, selection, rowKey, locale, childrenColumnName, }: Props<T>): ReactElement | null;
7
7
  export default TableSelection;
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React, { useCallback, useMemo } from 'react';
2
2
  import Dropdown from '@synerise/ds-dropdown';
3
3
  import Menu from '@synerise/ds-menu';
4
4
  import Button from '@synerise/ds-button';
@@ -6,35 +6,39 @@ import Tooltip from '@synerise/ds-tooltip';
6
6
  import Icon, { OptionVerticalM } from '@synerise/ds-icon';
7
7
  import * as S from '../Table.styles';
8
8
  import { SELECTION_ALL, SELECTION_INVERT } from '../Table';
9
- import { useRowKey } from '../hooks/useRowKey'; // @ts-ignore
9
+ import { useRowKey } from '../hooks/useRowKey';
10
+ import { isRecordSelectable } from '../utils'; // @ts-ignore
10
11
 
11
12
  function TableSelection(_ref) {
12
13
  var dataSource = _ref.dataSource,
13
14
  dataSourceFull = _ref.dataSourceFull,
14
15
  selection = _ref.selection,
15
16
  rowKey = _ref.rowKey,
16
- locale = _ref.locale;
17
+ locale = _ref.locale,
18
+ childrenColumnName = _ref.childrenColumnName;
17
19
 
18
20
  var _useRowKey = useRowKey(rowKey),
19
21
  getRowKey = _useRowKey.getRowKey;
20
22
 
21
23
  var allData = dataSourceFull || dataSource;
22
24
  var isShowingSubset = dataSourceFull && dataSourceFull.length !== dataSource.length;
23
- var getRowsForKeys = React.useCallback(function (keys) {
25
+ var getRowsForKeys = useCallback(function (keys) {
24
26
  if (selection) {
25
27
  var rows = [];
26
28
  allData.forEach(function (record) {
27
- if (Array.isArray(record.children)) {
28
- record.children.forEach(function (child) {
29
+ var rowChildren = record[childrenColumnName];
30
+
31
+ if (Array.isArray(rowChildren)) {
32
+ rowChildren.forEach(function (child) {
29
33
  var key = getRowKey(child);
30
34
 
31
- if (record.children && key && keys.includes(key)) {
35
+ if (rowChildren && key && keys.includes(key)) {
32
36
  rows = [].concat(rows, [record]);
33
37
  }
34
38
  });
35
39
  }
36
40
 
37
- if (!Array.isArray(record.children) || selection.independentSelectionExpandedRows) {
41
+ if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
38
42
  var key = getRowKey(record);
39
43
 
40
44
  if (key && keys.includes(key)) {
@@ -46,43 +50,48 @@ function TableSelection(_ref) {
46
50
  }
47
51
 
48
52
  return [];
49
- }, [allData, getRowKey, selection]);
50
- var selectAll = React.useCallback(function () {
53
+ }, [allData, getRowKey, selection, childrenColumnName]);
54
+ var selectAll = useCallback(function () {
51
55
  if (dataSource && selection) {
52
- var selectedRowKeys = selection.selectedRowKeys;
56
+ var selectedRowKeys = selection.selectedRowKeys,
57
+ checkRowSelectionStatus = selection.checkRowSelectionStatus;
53
58
  var keys = isShowingSubset ? [].concat(selectedRowKeys) : [];
54
59
  dataSource.forEach(function (record) {
55
- if (Array.isArray(record.children)) {
56
- keys = [].concat(keys, record.children.reduce(function (acc, child) {
60
+ var rowChildren = record[childrenColumnName];
61
+
62
+ if (Array.isArray(rowChildren)) {
63
+ keys = [].concat(keys, rowChildren.reduce(function (acc, child) {
57
64
  var key = getRowKey(child);
58
- return key ? [].concat(acc, [key]) : acc;
65
+ return key && isRecordSelectable(child, checkRowSelectionStatus) ? [].concat(acc, [key]) : acc;
59
66
  }, []));
60
67
  }
61
68
 
62
- if (!Array.isArray(record.children) || selection.independentSelectionExpandedRows) {
69
+ if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
63
70
  var key = getRowKey(record);
64
- keys = key !== undefined ? [].concat(keys, [key]) : [].concat(keys);
71
+ keys = key !== undefined && isRecordSelectable(record, checkRowSelectionStatus) ? [].concat(keys, [key]) : [].concat(keys);
65
72
  }
66
73
  });
67
74
  var uniqueKeys = Array.from(new Set(keys));
68
75
  var rows = getRowsForKeys(uniqueKeys);
69
76
  selection.onChange(uniqueKeys, rows);
70
77
  }
71
- }, [dataSource, selection, isShowingSubset, getRowsForKeys, getRowKey]);
72
- var unselectAll = React.useCallback(function () {
78
+ }, [childrenColumnName, dataSource, selection, isShowingSubset, getRowsForKeys, getRowKey]);
79
+ var unselectAll = useCallback(function () {
73
80
  if (selection) {
74
81
  if (isShowingSubset) {
75
82
  var selectedRowKeys = selection.selectedRowKeys;
76
83
  var keysToUnselect = [];
77
84
  dataSource.forEach(function (record) {
78
- if (Array.isArray(record.children)) {
79
- keysToUnselect = [].concat(keysToUnselect, record.children.reduce(function (acc, child) {
85
+ var rowChildren = record[childrenColumnName];
86
+
87
+ if (Array.isArray(rowChildren)) {
88
+ keysToUnselect = [].concat(keysToUnselect, rowChildren.reduce(function (acc, child) {
80
89
  var key = getRowKey(child);
81
90
  return key ? [].concat(acc, [key]) : acc;
82
91
  }, []));
83
92
  }
84
93
 
85
- if (!Array.isArray(record.children) || selection.independentSelectionExpandedRows) {
94
+ if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
86
95
  var key = getRowKey(record);
87
96
  keysToUnselect = key !== undefined ? [].concat(keysToUnselect, [key]) : [].concat(keysToUnselect);
88
97
  }
@@ -96,19 +105,23 @@ function TableSelection(_ref) {
96
105
  selection.onChange([], []);
97
106
  }
98
107
  }
99
- }, [dataSource, getRowKey, getRowsForKeys, isShowingSubset, selection]);
100
- var getSelectableChildren = React.useCallback(function (children) {
108
+ }, [dataSource, getRowKey, getRowsForKeys, isShowingSubset, selection, childrenColumnName]);
109
+ var getSelectableChildren = useCallback(function (children) {
110
+ var selectionStatusValidator = selection && 'checkRowSelectionStatus' in selection ? selection.checkRowSelectionStatus : undefined;
101
111
  return children ? children.filter(function (child) {
102
- return getRowKey(child) !== undefined;
112
+ return isRecordSelectable(child, selectionStatusValidator) && getRowKey(child) !== undefined;
103
113
  }) : [];
104
- }, [getRowKey]);
105
- var selectInvert = React.useCallback(function () {
114
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
115
+ [getRowKey, selection == null ? void 0 : selection.checkRowSelectionStatus]);
116
+ var selectInvert = useCallback(function () {
106
117
  if (dataSource && selection) {
107
- var selectedRowKeys = selection.selectedRowKeys;
118
+ var selectedRowKeys = selection.selectedRowKeys,
119
+ checkRowSelectionStatus = selection.checkRowSelectionStatus;
108
120
  var keys = isShowingSubset ? [].concat(selectedRowKeys) : [];
109
121
  dataSource.forEach(function (record) {
110
- var hasChildren = Array.isArray(record.children);
111
- var selectableChildren = hasChildren ? getSelectableChildren(record.children) : false;
122
+ var rowChildren = record[childrenColumnName];
123
+ var hasChildren = Array.isArray(rowChildren);
124
+ var selectableChildren = hasChildren ? getSelectableChildren(rowChildren) : false;
112
125
 
113
126
  if (selectableChildren) {
114
127
  selectableChildren.forEach(function (child) {
@@ -127,7 +140,7 @@ function TableSelection(_ref) {
127
140
 
128
141
  if (selectedRowKeys.includes(key)) {
129
142
  if (isShowingSubset) keys.splice(keys.indexOf(key), 1);
130
- } else {
143
+ } else if (isRecordSelectable(record, checkRowSelectionStatus)) {
131
144
  keys = [].concat(keys, [key]);
132
145
  }
133
146
  }
@@ -135,47 +148,56 @@ function TableSelection(_ref) {
135
148
  var rows = getRowsForKeys(keys);
136
149
  selection.onChange(keys, rows);
137
150
  }
138
- }, [dataSource, selection, isShowingSubset, getRowsForKeys, getSelectableChildren, getRowKey]);
139
- var isEmpty = React.useMemo(function () {
151
+ }, [childrenColumnName, dataSource, selection, isShowingSubset, getRowsForKeys, getSelectableChildren, getRowKey]);
152
+ var isEmpty = useMemo(function () {
140
153
  return dataSource.length === 0;
141
154
  }, [dataSource]);
142
- var allSelected = React.useMemo(function () {
143
- if (isEmpty || !selection) return false;
144
- var selectedRowKeys = selection.selectedRowKeys,
145
- independentSelectionExpandedRows = selection.independentSelectionExpandedRows;
146
- var allRecordsCount = dataSource.reduce(function (count, record) {
155
+ var allSelectableRecordsCount = useMemo(function () {
156
+ if (isEmpty || !selection) return 0;
157
+ var independentSelectionExpandedRows = selection.independentSelectionExpandedRows,
158
+ checkRowSelectionStatus = selection.checkRowSelectionStatus;
159
+ return dataSource.reduce(function (count, record) {
160
+ var isSelectable = +isRecordSelectable(record, checkRowSelectionStatus);
161
+ var rowChildren = record[childrenColumnName];
162
+
147
163
  if (independentSelectionExpandedRows) {
148
- return Array.isArray(record.children) ? count + getSelectableChildren(record.children).length + 1 : count + 1;
164
+ return Array.isArray(rowChildren) ? count + getSelectableChildren(rowChildren).length + isSelectable : count + isSelectable;
149
165
  }
150
166
 
151
- return Array.isArray(record.children) ? count + getSelectableChildren(record.children).length : count + 1;
167
+ return Array.isArray(rowChildren) ? count + getSelectableChildren(rowChildren).length : count + isSelectable;
152
168
  }, 0);
169
+ }, [childrenColumnName, dataSource, getSelectableChildren, isEmpty, selection]);
170
+ var allSelected = useMemo(function () {
171
+ if (isEmpty || !selection) return false;
172
+ var selectedRowKeys = selection.selectedRowKeys;
153
173
  var selectedKeysInDataSourceCount = isShowingSubset ? dataSource.reduce(function (count, record) {
154
- if (Array.isArray(record.children)) {
155
- return record.children.reduce(function (childCount, child) {
174
+ var rowChildren = record[childrenColumnName];
175
+
176
+ if (Array.isArray(rowChildren)) {
177
+ return rowChildren.reduce(function (childCount, child) {
156
178
  var key = getRowKey(child);
157
179
  return selectedRowKeys.includes(key) ? childCount + 1 : childCount;
158
180
  }, 0);
159
181
  }
160
182
 
161
- if (!Array.isArray(record.children) || selection.independentSelectionExpandedRows) {
183
+ if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
162
184
  var key = getRowKey(record);
163
185
  return selectedRowKeys.includes(key) ? count + 1 : count;
164
186
  }
165
187
 
166
188
  return count;
167
189
  }, 0) : selectedRowKeys.length;
168
- return allRecordsCount === selectedKeysInDataSourceCount;
169
- }, [isEmpty, selection, dataSource, isShowingSubset, getSelectableChildren, getRowKey]);
190
+ return allSelectableRecordsCount === selectedKeysInDataSourceCount;
191
+ }, [isEmpty, selection, isShowingSubset, dataSource, allSelectableRecordsCount, childrenColumnName, getRowKey]);
170
192
  var selectionTooltipTitle = !allSelected ? locale == null ? void 0 : locale.selectAllTooltip : locale == null ? void 0 : locale.unselectAll;
171
193
  return selection != null && selection.selectedRowKeys ? /*#__PURE__*/React.createElement(S.Selection, {
172
194
  "data-popup-container": true
173
195
  }, /*#__PURE__*/React.createElement(Tooltip, {
174
196
  title: selectionTooltipTitle
175
197
  }, /*#__PURE__*/React.createElement(Button.Checkbox, {
176
- disabled: isEmpty,
198
+ disabled: isEmpty || allSelectableRecordsCount === 0,
177
199
  "data-testid": "ds-table-batch-selection-button",
178
- checked: allSelected,
200
+ checked: allSelected && allSelectableRecordsCount > 0,
179
201
  onChange: function onChange(isChecked) {
180
202
  if (isChecked) {
181
203
  selectAll();
@@ -185,7 +207,7 @@ function TableSelection(_ref) {
185
207
  },
186
208
  indeterminate: (selection == null ? void 0 : selection.selectedRowKeys.length) > 0 && !allSelected
187
209
  })), (selection == null ? void 0 : selection.selections) && /*#__PURE__*/React.createElement(Dropdown, {
188
- disabled: isEmpty,
210
+ disabled: isEmpty || allSelectableRecordsCount === 0,
189
211
  trigger: ['click'],
190
212
  overlay: /*#__PURE__*/React.createElement(S.SelectionMenu, null, selection == null ? void 0 : selection.selections.filter(Boolean).map(function (selectionMenuElement) {
191
213
  switch (selectionMenuElement) {
@@ -8,4 +8,5 @@ export interface Props<T extends {
8
8
  dataSourceFull?: T[];
9
9
  locale?: Locale;
10
10
  rowKey?: Function | string;
11
+ childrenColumnName: string;
11
12
  }
@@ -26,6 +26,7 @@ import { useRowKey } from '../hooks/useRowKey';
26
26
  import { useRowStar } from '../hooks/useRowStar';
27
27
  import { RowSelectionColumn } from '../RowSelection';
28
28
  import { EXPANDED_ROW_PROPERTY, HEADER_ROW_HEIGHT, LOAD_DATA_OFFSET } from './constants';
29
+ import { getChildrenColumnName } from '../utils/getChildrenColumnName';
29
30
  var relativeInlineStyle = {
30
31
  position: 'relative'
31
32
  };
@@ -74,6 +75,7 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
74
75
  firstItem = _useState2[0],
75
76
  setFirstItem = _useState2[1];
76
77
 
78
+ var childrenColumnName = getChildrenColumnName(expandable == null ? void 0 : expandable.childrenColumnName);
77
79
  var hasInfiniteScroll = Boolean(infiniteScroll);
78
80
  var isSticky = Boolean(sticky);
79
81
  var stickyScrollThreshold = sticky && sticky.scrollThreshold;
@@ -195,22 +197,21 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
195
197
  });
196
198
 
197
199
  var rowStarColumn = getRowStarColumn(propsForRowStar);
198
- var selectedRecords = getSelectedRecords();
199
-
200
- function getSelectedRecords() {
200
+ var selectedRecords = useMemo(function () {
201
201
  if (selection) {
202
202
  var _ref2 = selection,
203
203
  selectedRowKeys = _ref2.selectedRowKeys;
204
204
  var selectedRows = [];
205
205
  allData.forEach(function (row) {
206
206
  var key = getRowKey(row);
207
+ var rowChildren = row[childrenColumnName];
207
208
 
208
209
  if (key && selectedRowKeys.indexOf(key) >= 0) {
209
210
  selectedRows = [].concat(selectedRows, [row]);
210
211
  }
211
212
 
212
- if (row.children !== undefined && Array.isArray(row.children)) {
213
- row.children.forEach(function (child) {
213
+ if (rowChildren !== undefined && Array.isArray(rowChildren)) {
214
+ rowChildren.forEach(function (child) {
214
215
  var childKey = getRowKey(child);
215
216
 
216
217
  if (childKey && selectedRowKeys.indexOf(childKey) >= 0) {
@@ -223,14 +224,14 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
223
224
  }
224
225
 
225
226
  return [];
226
- }
227
-
227
+ }, [allData, childrenColumnName, getRowKey, selection]);
228
228
  var renderRowSelection = useCallback(function (key, record) {
229
229
  var _ref3 = selection,
230
230
  selectedRowKeys = _ref3.selectedRowKeys,
231
231
  limit = _ref3.limit,
232
232
  independentSelectionExpandedRows = _ref3.independentSelectionExpandedRows,
233
- onChange = _ref3.onChange;
233
+ onChange = _ref3.onChange,
234
+ checkRowSelectionStatus = _ref3.checkRowSelectionStatus;
234
235
 
235
236
  var handleChange = function handleChange(keys, records) {
236
237
  if (isSticky && listScrollTopRef.current) {
@@ -248,9 +249,11 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
248
249
  independentSelectionExpandedRows: independentSelectionExpandedRows,
249
250
  onChange: handleChange,
250
251
  selectedRecords: selectedRecords,
251
- tableLocale: locale
252
+ tableLocale: locale,
253
+ checkRowSelectionStatus: checkRowSelectionStatus,
254
+ childrenColumnName: childrenColumnName
252
255
  });
253
- }, [isSticky, locale, rowKey, selectedRecords, selection]);
256
+ }, [isSticky, locale, rowKey, selectedRecords, selection, childrenColumnName]);
254
257
  var virtualColumns = useMemo(function () {
255
258
  return compact([!!selection && {
256
259
  width: 64,
@@ -331,17 +334,19 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
331
334
 
332
335
  return infiniteLoaderItemHeight;
333
336
  }, [isSticky, infiniteScroll == null || (_infiniteScroll$prevP4 = infiniteScroll.prevPage) == null ? void 0 : _infiniteScroll$prevP4.hasMore]);
334
- var listInnerElementType = forwardRef(function (_ref4, innerElementRef) {
335
- var style = _ref4.style,
336
- rest = _objectWithoutPropertiesLoose(_ref4, _excluded);
337
-
338
- return /*#__PURE__*/React.createElement(S.InnerListElement, _extends({
339
- ref: innerElementRef,
340
- style: _objectSpread({}, style, {
341
- height: Number(style == null ? void 0 : style.height) + infiniteLoaderOffset + "px"
342
- })
343
- }, rest));
344
- });
337
+ var listInnerElementType = useMemo(function () {
338
+ return forwardRef(function (_ref4, innerElementRef) {
339
+ var style = _ref4.style,
340
+ rest = _objectWithoutPropertiesLoose(_ref4, _excluded);
341
+
342
+ return /*#__PURE__*/React.createElement(S.InnerListElement, _extends({
343
+ ref: innerElementRef,
344
+ style: _objectSpread({}, style, {
345
+ height: Number(style == null ? void 0 : style.height) + infiniteLoaderOffset + "px"
346
+ })
347
+ }, rest));
348
+ });
349
+ }, [infiniteLoaderOffset]);
345
350
  var scrollTo = useCallback(function (top) {
346
351
  if (!listRef.current) {
347
352
  return;
@@ -349,9 +354,11 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
349
354
 
350
355
  listRef.current.scrollTo(top);
351
356
  }, []);
352
- var scrollToTop = useCallback(function () {
357
+
358
+ var scrollToTop = function scrollToTop() {
353
359
  scrollTo(0);
354
- }, [scrollTo]);
360
+ };
361
+
355
362
  var outerElement = useMemo(function () {
356
363
  return OuterListElement(containerRef, isSticky);
357
364
  }, [isSticky]);
@@ -417,16 +424,19 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
417
424
  var _infiniteScroll$nextP, _infiniteScroll$prevP5;
418
425
 
419
426
  var listHeight = data.length * cellHeight - scroll.y + infiniteLoaderOffset;
420
- var listMaxScroll = stickyScrollThreshold && infiniteScroll != null && infiniteScroll.maxScroll ? (infiniteScroll == null ? void 0 : infiniteScroll.maxScroll) - stickyScrollThreshold : listHeight;
427
+ var listMaxScroll = stickyScrollThreshold && infiniteScroll != null && infiniteScroll.maxScroll ? infiniteScroll.maxScroll - stickyScrollThreshold : listHeight;
421
428
 
422
429
  var handleListScroll = function handleListScroll(_ref5) {
423
430
  var scrollOffset = _ref5.scrollOffset,
424
431
  scrollDirection = _ref5.scrollDirection;
425
432
 
426
- if (loading || listMaxScroll <= 0) {
433
+ if (!infiniteScroll || loading || listMaxScroll <= 0) {
427
434
  return;
428
435
  }
429
436
 
437
+ var onScrollTopReach = infiniteScroll.onScrollTopReach,
438
+ isLoading = infiniteScroll.isLoading,
439
+ onScrollEndReach = infiniteScroll.onScrollEndReach;
430
440
  var roundedOffset = Math.ceil(scrollOffset);
431
441
  listScrollTopRef.current = roundedOffset;
432
442
 
@@ -438,12 +448,14 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
438
448
  setIsHeaderVisible(roundedOffset > 0);
439
449
  }
440
450
 
441
- if (scrollDirection === 'forward' && roundedOffset >= listMaxScroll - LOAD_DATA_OFFSET && typeof (infiniteScroll == null ? void 0 : infiniteScroll.onScrollEndReach) === 'function') {
442
- infiniteScroll.onScrollEndReach();
451
+ if (isLoading) {
452
+ return;
443
453
  }
444
454
 
445
- if (scrollDirection === 'backward' && (offsetScroll && roundedOffset <= offsetScroll + LOAD_DATA_OFFSET || roundedOffset < LOAD_DATA_OFFSET) && typeof (infiniteScroll == null ? void 0 : infiniteScroll.onScrollTopReach) === 'function') {
446
- infiniteScroll.onScrollTopReach();
455
+ if (scrollDirection === 'forward' && roundedOffset >= listMaxScroll - LOAD_DATA_OFFSET && typeof onScrollEndReach === 'function') {
456
+ onScrollEndReach();
457
+ } else if (scrollDirection === 'backward' && (offsetScroll && roundedOffset <= offsetScroll + LOAD_DATA_OFFSET || roundedOffset < LOAD_DATA_OFFSET) && typeof onScrollTopReach === 'function') {
458
+ onScrollTopReach();
447
459
  }
448
460
  };
449
461
 
@@ -509,9 +521,10 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
509
521
  var _expandable$expandedR2;
510
522
 
511
523
  var key = getRowKey(currentRow);
524
+ var rowChildren = currentRow[childrenColumnName];
512
525
 
513
- if (key !== undefined && expandable != null && (_expandable$expandedR2 = expandable.expandedRowKeys) != null && _expandable$expandedR2.includes(key) && Array.isArray(currentRow.children) && currentRow.children.length) {
514
- return [].concat(result, [currentRow], currentRow.children.map(function (child, index) {
526
+ if (key !== undefined && expandable != null && (_expandable$expandedR2 = expandable.expandedRowKeys) != null && _expandable$expandedR2.includes(key) && Array.isArray(rowChildren) && rowChildren.length) {
527
+ return [].concat(result, [currentRow], rowChildren.map(function (child, index) {
515
528
  var _objectSpread2;
516
529
 
517
530
  return _objectSpread({}, child, (_objectSpread2 = {}, _objectSpread2[EXPANDED_ROW_PROPERTY] = true, _objectSpread2.index = index, _objectSpread2));
@@ -524,7 +537,7 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
524
537
  }
525
538
 
526
539
  return renderVirtualList(rawData);
527
- }, [connectObject, expandable == null ? void 0 : expandable.expandedRowKeys, cellHeight, scroll.y, isSticky, stickyScrollThreshold, infiniteScroll, createItemData, tableWidth, scrollWidth, onItemsRendered, outerElement, listInnerElementType, loading, offsetScroll, getRowKey, infiniteLoaderOffset]);
540
+ }, [connectObject, expandable == null ? void 0 : expandable.expandedRowKeys, cellHeight, scroll.y, isSticky, stickyScrollThreshold, infiniteScroll, createItemData, tableWidth, scrollWidth, onItemsRendered, outerElement, listInnerElementType, loading, offsetScroll, getRowKey, infiniteLoaderOffset, childrenColumnName]);
528
541
  var columnsSliceStartIndex = Number(!!selection) + Number(!!rowStar);
529
542
  var scrollValue = !dataSource || (dataSource == null ? void 0 : dataSource.length) === 0 ? undefined : scroll;
530
543
  var classNames = React.useMemo(function () {
@@ -0,0 +1 @@
1
+ export declare const getChildrenColumnName: (childrenColumnName?: string) => string;
@@ -0,0 +1,4 @@
1
+ var DEFAULT_CHILDREN_COLUMN_NAME = 'children';
2
+ export var getChildrenColumnName = function getChildrenColumnName(childrenColumnName) {
3
+ return childrenColumnName || DEFAULT_CHILDREN_COLUMN_NAME;
4
+ };
@@ -0,0 +1,8 @@
1
+ import { RowSelection } from '../Table.types';
2
+ export declare const getRecordSelectionStatus: <T>(checkRowSelectionStatus: ((record: T) => {
3
+ disabled?: boolean | undefined;
4
+ unavailable?: boolean | undefined;
5
+ }) | undefined, record: T) => {
6
+ unavailable: boolean | undefined;
7
+ disabled: boolean | undefined;
8
+ };
@@ -0,0 +1,10 @@
1
+ export var getRecordSelectionStatus = function getRecordSelectionStatus(checkRowSelectionStatus, record) {
2
+ var _ref = checkRowSelectionStatus && checkRowSelectionStatus(record) || {},
3
+ unavailable = _ref.unavailable,
4
+ disabled = _ref.disabled;
5
+
6
+ return {
7
+ unavailable: unavailable,
8
+ disabled: disabled
9
+ };
10
+ };
@@ -1,4 +1,8 @@
1
1
  export * from './getValueFromPath';
2
2
  export * from './locale';
3
+ export * from './locale';
3
4
  export * from './calculatePixels';
5
+ export * from './getRecordSelectionStatus';
4
6
  export * from './calculateColumnWidths';
7
+ export * from './getChildrenColumnName';
8
+ export * from './isRecordSelectable';
@@ -1,4 +1,8 @@
1
1
  export * from './getValueFromPath';
2
2
  export * from './locale';
3
+ export * from './locale';
3
4
  export * from './calculatePixels';
4
- export * from './calculateColumnWidths';
5
+ export * from './getRecordSelectionStatus';
6
+ export * from './calculateColumnWidths';
7
+ export * from './getChildrenColumnName';
8
+ export * from './isRecordSelectable';
@@ -0,0 +1,5 @@
1
+ import type { RowSelection } from '../Table.types';
2
+ export declare const isRecordSelectable: <T>(record: T, checkRowSelectionStatus?: ((record: T) => {
3
+ disabled?: boolean | undefined;
4
+ unavailable?: boolean | undefined;
5
+ }) | undefined) => boolean;
@@ -0,0 +1,12 @@
1
+ import { getRecordSelectionStatus } from './getRecordSelectionStatus';
2
+ export var isRecordSelectable = function isRecordSelectable(record, checkRowSelectionStatus) {
3
+ if (!checkRowSelectionStatus) {
4
+ return true;
5
+ }
6
+
7
+ var _getRecordSelectionSt = getRecordSelectionStatus(checkRowSelectionStatus, record),
8
+ unavailable = _getRecordSelectionSt.unavailable,
9
+ disabled = _getRecordSelectionSt.disabled;
10
+
11
+ return !(unavailable || disabled);
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-table",
3
- "version": "0.53.2",
3
+ "version": "0.55.0",
4
4
  "description": "Table UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -33,31 +33,31 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-alert": "^0.8.16",
37
- "@synerise/ds-badge": "^0.7.1",
38
- "@synerise/ds-button": "^0.21.1",
39
- "@synerise/ds-button-group": "^0.7.3",
40
- "@synerise/ds-checkbox": "^0.12.1",
41
- "@synerise/ds-column-manager": "^0.11.60",
42
- "@synerise/ds-data-format": "^0.5.0",
43
- "@synerise/ds-dropdown": "^0.18.2",
44
- "@synerise/ds-flag": "^0.5.0",
45
- "@synerise/ds-icon": "^0.63.0",
46
- "@synerise/ds-input": "^0.22.1",
47
- "@synerise/ds-loader": "^0.3.9",
48
- "@synerise/ds-menu": "^0.19.3",
49
- "@synerise/ds-modal": "^0.17.32",
50
- "@synerise/ds-pagination": "^0.7.53",
51
- "@synerise/ds-result": "^0.6.58",
52
- "@synerise/ds-scrollbar": "^0.11.2",
53
- "@synerise/ds-search": "^0.8.95",
54
- "@synerise/ds-select": "^0.16.4",
55
- "@synerise/ds-skeleton": "^0.6.1",
56
- "@synerise/ds-status": "^0.6.10",
57
- "@synerise/ds-tags": "^0.9.2",
58
- "@synerise/ds-tooltip": "^0.14.31",
59
- "@synerise/ds-typography": "^0.15.0",
60
- "@synerise/ds-utils": "^0.27.0",
36
+ "@synerise/ds-alert": "^0.8.18",
37
+ "@synerise/ds-badge": "^0.8.0",
38
+ "@synerise/ds-button": "^0.21.2",
39
+ "@synerise/ds-button-group": "^0.7.4",
40
+ "@synerise/ds-checkbox": "^0.12.2",
41
+ "@synerise/ds-column-manager": "^0.11.62",
42
+ "@synerise/ds-data-format": "^0.5.1",
43
+ "@synerise/ds-dropdown": "^0.18.4",
44
+ "@synerise/ds-flag": "^0.5.1",
45
+ "@synerise/ds-icon": "^0.64.0",
46
+ "@synerise/ds-input": "^0.23.1",
47
+ "@synerise/ds-loader": "^0.3.10",
48
+ "@synerise/ds-menu": "^0.19.4",
49
+ "@synerise/ds-modal": "^0.17.33",
50
+ "@synerise/ds-pagination": "^0.7.54",
51
+ "@synerise/ds-result": "^0.6.59",
52
+ "@synerise/ds-scrollbar": "^0.11.3",
53
+ "@synerise/ds-search": "^0.9.0",
54
+ "@synerise/ds-select": "^0.16.6",
55
+ "@synerise/ds-skeleton": "^0.6.2",
56
+ "@synerise/ds-status": "^0.6.12",
57
+ "@synerise/ds-tags": "^0.9.4",
58
+ "@synerise/ds-tooltip": "^0.14.32",
59
+ "@synerise/ds-typography": "^0.15.1",
60
+ "@synerise/ds-utils": "^0.28.0",
61
61
  "@types/react-window": "^1.8.5",
62
62
  "classnames": "2.3.2",
63
63
  "copy-to-clipboard": "^3.3.1",
@@ -73,11 +73,9 @@
73
73
  "peerDependencies": {
74
74
  "@synerise/ds-core": "*",
75
75
  "antd": "4.7.0",
76
- "react": ">=16.9.0 < 17.0.0",
76
+ "react": ">=16.9.0 <= 17.0.2",
77
+ "react-dom": "^16.14.0",
77
78
  "styled-components": "5.0.1"
78
79
  },
79
- "devDependencies": {
80
- "@testing-library/react": "10.0.1"
81
- },
82
- "gitHead": "587eb113074985ae21e4f0c25ec33c3e3e2e072b"
80
+ "gitHead": "6e5e5202d6c6f1c2caf6bfef799009813b437b3d"
83
81
  }