@synerise/ds-table 0.53.1 → 0.54.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.54.0](https://github.com/synerise/synerise-design/compare/@synerise/ds-table@0.53.2...@synerise/ds-table@0.54.0) (2024-07-02)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **table:** infinite loader - trigger loading without scrolling ([4559290](https://github.com/synerise/synerise-design/commit/455929012ab463980f0dd5de7230636a0ee058b6))
12
+
13
+
14
+ ### Features
15
+
16
+ * **table:** add custom name for children column ([e5b2089](https://github.com/synerise/synerise-design/commit/e5b2089e011a28eccfdc56843c268fc861677a07))
17
+
18
+
19
+
20
+
21
+
22
+ ## [0.53.2](https://github.com/synerise/synerise-design/compare/@synerise/ds-table@0.53.1...@synerise/ds-table@0.53.2) (2024-06-27)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **button-group:** remove margin from button-group ([cfb42ac](https://github.com/synerise/synerise-design/commit/cfb42ac433aa99ef7ac4c133a74f7ed0e913b901))
28
+
29
+
30
+
31
+
32
+
6
33
  ## [0.53.1](https://github.com/synerise/synerise-design/compare/@synerise/ds-table@0.53.0...@synerise/ds-table@0.53.1) (2024-06-21)
7
34
 
8
35
  **Note:** Version bump only for package @synerise/ds-table
@@ -20,7 +20,8 @@ import { columnsToSortState, useSortState } from '../ColumnSortMenu/useSortState
20
20
  import { columnWithSortButtons } from '../ColumnSortMenu/columnWithSortButtons';
21
21
  import { useRowKey } from '../hooks/useRowKey';
22
22
  import { useRowStar } from '../hooks/useRowStar/useRowStar';
23
- import { RowSelectionColumn } from '../RowSelection'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ import { RowSelectionColumn } from '../RowSelection';
24
+ import { getChildrenColumnName } from '../utils/getChildrenColumnName'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
25
 
25
26
  function DefaultTable(props) {
26
27
  var _selection$selections;
@@ -41,6 +42,8 @@ function DefaultTable(props) {
41
42
  var _useRowStar = useRowStar((rowStar == null ? void 0 : rowStar.starredRowKeys) || []),
42
43
  getRowStarColumn = _useRowStar.getRowStarColumn;
43
44
 
45
+ var childrenColumnName = getChildrenColumnName(expandable == null ? void 0 : expandable.childrenColumnName);
46
+
44
47
  var _useRowKey = useRowKey(rowKey),
45
48
  getRowKey = _useRowKey.getRowKey;
46
49
 
@@ -111,8 +114,10 @@ function DefaultTable(props) {
111
114
  selectedRows = [].concat(selectedRows, [row]);
112
115
  }
113
116
 
114
- if (row.children !== undefined && Array.isArray(row.children)) {
115
- row.children.forEach(function (child) {
117
+ var rowChildren = row[childrenColumnName];
118
+
119
+ if (rowChildren !== undefined && Array.isArray(rowChildren)) {
120
+ rowChildren.forEach(function (child) {
116
121
  var childKey = getRowKey(child);
117
122
 
118
123
  if (childKey && selectedRowKeys.indexOf(childKey) >= 0) {
@@ -125,7 +130,7 @@ function DefaultTable(props) {
125
130
  }
126
131
 
127
132
  return [];
128
- }, [dataSource, getRowKey, selection]);
133
+ }, [dataSource, getRowKey, selection, childrenColumnName]);
129
134
  var renderRowSelection = React.useCallback(function (key, record) {
130
135
  var _ref5 = selection,
131
136
  selectedRowKeys = _ref5.selectedRowKeys,
@@ -140,9 +145,10 @@ function DefaultTable(props) {
140
145
  independentSelectionExpandedRows: independentSelectionExpandedRows,
141
146
  onChange: onChange,
142
147
  selectedRecords: selectedRecords,
143
- tableLocale: locale
148
+ tableLocale: locale,
149
+ childrenColumnName: childrenColumnName
144
150
  });
145
- }, [locale, rowKey, selectedRecords, selection]);
151
+ }, [locale, rowKey, selectedRecords, selection, childrenColumnName]);
146
152
  return (
147
153
  /*#__PURE__*/
148
154
  // @ts-ignore
@@ -5,7 +5,7 @@ import { IconContainer } from '@synerise/ds-icon';
5
5
  export var FilterButtonGroup = styled(ButtonGroup).withConfig({
6
6
  displayName: "FilterTriggerstyles__FilterButtonGroup",
7
7
  componentId: "sc-1h4wcrp-0"
8
- })([".ant-btn-group{width:auto;margin:0;}"]);
8
+ })([".ant-btn-group{width:auto;}"]);
9
9
  export var FilterButtonLabel = styled.span.withConfig({
10
10
  displayName: "FilterTriggerstyles__FilterButtonLabel",
11
11
  componentId: "sc-1h4wcrp-1"
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ type ErrorItemProps = {
3
+ onRetryClick?: () => void;
4
+ };
5
+ export declare const ErrorItem: ({ onRetryClick }: ErrorItemProps) => React.JSX.Element;
6
+ export {};
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import Alert from '@synerise/ds-alert';
3
+ import Button from '@synerise/ds-button';
4
+ import Icon, { RefreshM } from '@synerise/ds-icon';
5
+ import { TableLocaleContext } from '../utils/locale';
6
+ export var ErrorItem = function ErrorItem(_ref) {
7
+ var onRetryClick = _ref.onRetryClick;
8
+ return /*#__PURE__*/React.createElement(TableLocaleContext.Consumer, null, function (tableLocale) {
9
+ return /*#__PURE__*/React.createElement("div", {
10
+ style: {
11
+ display: 'flex'
12
+ }
13
+ }, /*#__PURE__*/React.createElement(Alert.InlineAlert, {
14
+ type: "alert",
15
+ message: tableLocale.infiniteScrollError
16
+ }), onRetryClick && /*#__PURE__*/React.createElement(Button, {
17
+ onClick: onRetryClick,
18
+ type: "ghost",
19
+ mode: "icon-label",
20
+ icon: /*#__PURE__*/React.createElement(Icon, {
21
+ component: /*#__PURE__*/React.createElement(RefreshM, null)
22
+ }),
23
+ style: {
24
+ marginLeft: 8
25
+ }
26
+ }, tableLocale.infiniteScrollRetry));
27
+ });
28
+ };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { LoaderItemProps } from './InfiniteLoaderItem.types';
3
- declare const InfiniteLoaderItem: ({ infiniteScroll, position }: LoaderItemProps) => React.ReactElement;
3
+ declare const InfiniteLoaderItem: ({ infiniteScroll, position }: LoaderItemProps) => React.JSX.Element;
4
4
  export default InfiniteLoaderItem;
@@ -1,67 +1,35 @@
1
- import * as React from 'react';
2
- import Alert from '@synerise/ds-alert';
3
- import Button from '@synerise/ds-button';
4
- import Icon, { RefreshM } from '@synerise/ds-icon';
5
- import { TableLocaleContext } from '../utils/locale';
6
- import { Loader } from './InfiniteLoaderItem.styles';
1
+ import React, { useEffect } from 'react';
7
2
  import { infiniteScrollPropsToState } from './utils';
3
+ import { ErrorItem } from './ErrorItem';
4
+ import { LoadingItem } from './LoadingItem';
5
+ import { NoMoreItem } from './NoMoreItem';
8
6
 
9
- var LoadingItem = function LoadingItem() {
10
- return /*#__PURE__*/React.createElement(TableLocaleContext.Consumer, null, function (tableLocale) {
11
- return /*#__PURE__*/React.createElement(Loader, {
12
- size: "M",
13
- label: tableLocale.infiniteScrollLoading
14
- });
15
- });
16
- };
17
-
18
- var NoMoreItem = function NoMoreItem() {
19
- return /*#__PURE__*/React.createElement(TableLocaleContext.Consumer, null, function (tableLocale) {
20
- return /*#__PURE__*/React.createElement(Alert.InlineAlert, {
21
- // @ts-ignore
22
- type: "info",
23
- message: tableLocale.infiniteScrollNoMoreData
24
- });
25
- });
26
- };
27
-
28
- var ErrorItem = function ErrorItem(_ref) {
29
- var onRetryClick = _ref.onRetryClick;
30
- return /*#__PURE__*/React.createElement(TableLocaleContext.Consumer, null, function (tableLocale) {
31
- return /*#__PURE__*/React.createElement("div", {
32
- style: {
33
- display: 'flex'
34
- }
35
- }, /*#__PURE__*/React.createElement(Alert.InlineAlert, {
36
- // @ts-ignore
37
- type: "alert",
38
- message: tableLocale.infiniteScrollError
39
- }), onRetryClick && /*#__PURE__*/React.createElement(Button, {
40
- onClick: onRetryClick,
41
- type: "ghost",
42
- mode: "icon-label",
43
- icon: /*#__PURE__*/React.createElement(Icon, {
44
- component: /*#__PURE__*/React.createElement(RefreshM, null)
45
- }),
46
- style: {
47
- marginLeft: 8
48
- }
49
- }, tableLocale.infiniteScrollRetry));
50
- });
51
- };
52
-
53
- var InfiniteLoaderItem = function InfiniteLoaderItem(_ref2) {
54
- var infiniteScroll = _ref2.infiniteScroll,
55
- position = _ref2.position;
7
+ var InfiniteLoaderItem = function InfiniteLoaderItem(_ref) {
8
+ var infiniteScroll = _ref.infiniteScroll,
9
+ position = _ref.position;
56
10
  var hasMore = infiniteScroll.hasMore,
57
11
  isLoading = infiniteScroll.isLoading,
12
+ onScrollEndReach = infiniteScroll.onScrollEndReach,
58
13
  hasError = infiniteScroll.hasError,
59
14
  onRetryButtonClick = infiniteScroll.onRetryButtonClick,
60
15
  render = infiniteScroll.render;
61
16
 
62
17
  var handleRetryClick = function handleRetryClick() {
63
18
  onRetryButtonClick && onRetryButtonClick(position);
64
- };
19
+ }; // @ts-expect-error TS7030: Not all code paths return a value
20
+ // eslint-disable-next-line consistent-return
21
+
22
+
23
+ useEffect(function () {
24
+ if (!isLoading && hasMore) {
25
+ if ((!position || position === 'BOTTOM') && typeof onScrollEndReach === 'function') {
26
+ var timeout = setTimeout(onScrollEndReach, 0);
27
+ return function () {
28
+ clearTimeout(timeout);
29
+ };
30
+ }
31
+ }
32
+ }, [hasMore, isLoading, onScrollEndReach, position]);
65
33
 
66
34
  if (typeof render === 'function') {
67
35
  return render(infiniteScrollPropsToState(infiniteScroll));
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const LoadingItem: () => React.JSX.Element;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { TableLocaleContext } from '../utils/locale';
3
+ import { Loader } from './InfiniteLoaderItem.styles';
4
+ export var LoadingItem = function LoadingItem() {
5
+ return /*#__PURE__*/React.createElement(TableLocaleContext.Consumer, null, function (tableLocale) {
6
+ return /*#__PURE__*/React.createElement(Loader, {
7
+ size: "M",
8
+ label: tableLocale.infiniteScrollLoading
9
+ });
10
+ });
11
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const NoMoreItem: () => React.JSX.Element;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import Alert from '@synerise/ds-alert';
3
+ import { TableLocaleContext } from '../utils/locale';
4
+ export var NoMoreItem = function NoMoreItem() {
5
+ return /*#__PURE__*/React.createElement(TableLocaleContext.Consumer, null, function (tableLocale) {
6
+ return /*#__PURE__*/React.createElement(Alert.InlineAlert, {
7
+ type: "info",
8
+ message: tableLocale.infiniteScrollNoMoreData
9
+ });
10
+ });
11
+ };
@@ -1,4 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { RowSelectionProps } from './RowSelectionColumn.types';
3
3
  import { RowType } from '../Table.types';
4
- export declare function RowSelectionColumn<T extends object & RowType<T>>({ rowKey, record, limit, independentSelectionExpandedRows, selectedRowKeys, selectedRecords, tableLocale, onChange, }: RowSelectionProps<T>): React.ReactElement | null;
4
+ export declare function RowSelectionColumn<T extends object & RowType<T>>({ rowKey, record, limit, independentSelectionExpandedRows, selectedRowKeys, selectedRecords, tableLocale, onChange, childrenColumnName, }: RowSelectionProps<T>): React.ReactElement | null;
@@ -11,55 +11,52 @@ export function RowSelectionColumn(_ref) {
11
11
  selectedRowKeys = _ref.selectedRowKeys,
12
12
  selectedRecords = _ref.selectedRecords,
13
13
  tableLocale = _ref.tableLocale,
14
- onChange = _ref.onChange;
14
+ onChange = _ref.onChange,
15
+ childrenColumnName = _ref.childrenColumnName;
15
16
 
16
17
  var _useRowKey = useRowKey(rowKey),
17
18
  getRowKey = _useRowKey.getRowKey;
18
19
 
19
20
  var recordKey = getRowKey(record);
21
+ var rowChildren = record[childrenColumnName];
20
22
  var checkedChildren = React.useMemo(function () {
21
- var _record$children;
22
-
23
- return ((_record$children = record.children) == null ? void 0 : _record$children.filter(function (child) {
23
+ return (rowChildren == null ? void 0 : rowChildren.filter(function (child) {
24
24
  var childKey = getRowKey(child);
25
25
  return childKey && selectedRowKeys.indexOf(childKey) >= 0;
26
26
  })) || [];
27
- }, [getRowKey, record.children, selectedRowKeys]);
27
+ }, [getRowKey, rowChildren, selectedRowKeys]);
28
28
  var allChildrenSelected = React.useMemo(function () {
29
- var _record$children2;
30
-
31
- return !!((_record$children2 = record.children) != null && _record$children2.every(function (child) {
29
+ return !!(rowChildren != null && rowChildren.every(function (child) {
32
30
  var childKey = getRowKey(child);
33
31
  return childKey && selectedRowKeys.indexOf(childKey) >= 0;
34
32
  }));
35
- }, [getRowKey, record.children, selectedRowKeys]);
33
+ }, [getRowKey, rowChildren, selectedRowKeys]);
36
34
  var isIndeterminate = React.useMemo(function () {
37
- if (Array.isArray(record.children) && !independentSelectionExpandedRows) {
38
- var _record$children3;
39
-
40
- return checkedChildren.length > 0 && checkedChildren.length < (((_record$children3 = record.children) == null ? void 0 : _record$children3.length) || 0);
35
+ if (Array.isArray(rowChildren) && !independentSelectionExpandedRows) {
36
+ return checkedChildren.length > 0 && checkedChildren.length < ((rowChildren == null ? void 0 : rowChildren.length) || 0);
41
37
  }
42
38
 
43
39
  return false;
44
- }, [checkedChildren.length, independentSelectionExpandedRows, record.children]);
40
+ }, [checkedChildren.length, independentSelectionExpandedRows, rowChildren]);
45
41
  var isChecked = React.useMemo(function () {
46
- if (Array.isArray(record.children) && !independentSelectionExpandedRows) {
42
+ if (Array.isArray(rowChildren) && !independentSelectionExpandedRows) {
47
43
  return isChecked || allChildrenSelected;
48
44
  }
49
45
 
50
46
  return recordKey !== undefined && selectedRowKeys && selectedRowKeys.indexOf(recordKey) >= 0;
51
- }, [allChildrenSelected, independentSelectionExpandedRows, record.children, recordKey, selectedRowKeys]);
47
+ }, [allChildrenSelected, independentSelectionExpandedRows, rowChildren, recordKey, selectedRowKeys]);
52
48
  var handleSelectionChange = React.useCallback(function (isCheckedNext, changedRecord) {
53
49
  var selectedRows = selectedRecords;
50
+ var changedRecordChildren = changedRecord[childrenColumnName];
54
51
 
55
52
  if (isCheckedNext) {
56
- if (Array.isArray(changedRecord.children) && !independentSelectionExpandedRows) {
57
- selectedRows = [].concat(selectedRows, changedRecord.children);
53
+ if (Array.isArray(changedRecordChildren) && !independentSelectionExpandedRows) {
54
+ selectedRows = [].concat(selectedRows, changedRecordChildren);
58
55
  } else {
59
56
  selectedRows = [].concat(selectedRows, [changedRecord]);
60
57
  }
61
- } else if (Array.isArray(changedRecord.children) && !independentSelectionExpandedRows) {
62
- var childrenKeys = changedRecord.children.map(function (child) {
58
+ } else if (Array.isArray(changedRecordChildren) && !independentSelectionExpandedRows) {
59
+ var childrenKeys = changedRecordChildren.map(function (child) {
63
60
  return getRowKey(child);
64
61
  });
65
62
  selectedRows = selectedRows.filter(function (child) {
@@ -81,7 +78,7 @@ export function RowSelectionColumn(_ref) {
81
78
 
82
79
  return acc;
83
80
  }, []), selectedRows);
84
- }, [getRowKey, independentSelectionExpandedRows, onChange, recordKey, selectedRecords]);
81
+ }, [getRowKey, independentSelectionExpandedRows, onChange, recordKey, selectedRecords, childrenColumnName]);
85
82
  return recordKey !== undefined ? /*#__PURE__*/React.createElement(Tooltip, {
86
83
  title: tableLocale == null ? void 0 : tableLocale.selectRowTooltip,
87
84
  mouseLeaveDelay: 0
@@ -10,4 +10,5 @@ export type RowSelectionProps<T> = {
10
10
  record: T;
11
11
  tableLocale: DSTableProps<T>['locale'];
12
12
  onChange: (selectedRowKeys: React.ReactText[], selectedRecords: T[]) => void;
13
+ childrenColumnName: string;
13
14
  };
package/dist/Table.js CHANGED
@@ -19,6 +19,7 @@ import TableHeader from './TableHeader/TableHeader';
19
19
  import DefaultTable from './DefaultTable/DefaultTable';
20
20
  import GroupTable from './GroupTable/GroupTable';
21
21
  import { useTableLocale, TableLocaleContext } from './utils/locale';
22
+ import { getChildrenColumnName } from './utils/getChildrenColumnName';
22
23
  export var SELECTION_ALL = 'SELECTION_ALL';
23
24
  export var SELECTION_INVERT = 'SELECTION_INVERT';
24
25
  var ITEM_RENDER_TYPE = {
@@ -50,7 +51,8 @@ function DSTable(props) {
50
51
  hideColumnNames = props.hideColumnNames,
51
52
  renderSelectionTitle = props.renderSelectionTitle,
52
53
  hideTitlePart = props.hideTitlePart,
53
- disableColumnNamesLineBreak = props.disableColumnNamesLineBreak;
54
+ disableColumnNamesLineBreak = props.disableColumnNamesLineBreak,
55
+ expandable = props.expandable;
54
56
  var tableLocale = useTableLocale(intl, locale);
55
57
 
56
58
  var _useDataFormat = useDataFormat(),
@@ -83,9 +85,10 @@ function DSTable(props) {
83
85
  rowKey: rowKey,
84
86
  locale: tableLocale,
85
87
  renderSelectionTitle: renderSelectionTitle,
86
- hideTitlePart: hideTitlePart
88
+ hideTitlePart: hideTitlePart,
89
+ childrenColumnName: getChildrenColumnName(expandable == null ? void 0 : expandable.childrenColumnName)
87
90
  });
88
- }, [selection, grouped, dataSource, dataSourceTotalCount, hideTitleBar, headerWithBorderTop, title, filters, itemsMenu, dataSourceFull, searchComponent, filterComponent, headerButton, rowKey, tableLocale, renderSelectionTitle, hideTitlePart]);
91
+ }, [selection, grouped, dataSource, dataSourceTotalCount, hideTitleBar, headerWithBorderTop, title, filters, itemsMenu, dataSourceFull, searchComponent, filterComponent, headerButton, rowKey, tableLocale, renderSelectionTitle, hideTitlePart, expandable == null ? void 0 : expandable.childrenColumnName]);
89
92
  var footerPagination = React.useMemo(function () {
90
93
  return _objectSpread({
91
94
  showTotal: function showTotal(total, range) {
@@ -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
  };
@@ -3,5 +3,5 @@ import { Props } from './TableSelection.types';
3
3
  declare function TableSelection<T extends {
4
4
  key: React.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>): React.ReactElement | null;
7
7
  export default TableSelection;
@@ -13,7 +13,8 @@ function TableSelection(_ref) {
13
13
  dataSourceFull = _ref.dataSourceFull,
14
14
  selection = _ref.selection,
15
15
  rowKey = _ref.rowKey,
16
- locale = _ref.locale;
16
+ locale = _ref.locale,
17
+ childrenColumnName = _ref.childrenColumnName;
17
18
 
18
19
  var _useRowKey = useRowKey(rowKey),
19
20
  getRowKey = _useRowKey.getRowKey;
@@ -24,17 +25,19 @@ function TableSelection(_ref) {
24
25
  if (selection) {
25
26
  var rows = [];
26
27
  allData.forEach(function (record) {
27
- if (Array.isArray(record.children)) {
28
- record.children.forEach(function (child) {
28
+ var rowChildren = record[childrenColumnName];
29
+
30
+ if (Array.isArray(rowChildren)) {
31
+ rowChildren.forEach(function (child) {
29
32
  var key = getRowKey(child);
30
33
 
31
- if (record.children && key && keys.includes(key)) {
34
+ if (rowChildren && key && keys.includes(key)) {
32
35
  rows = [].concat(rows, [record]);
33
36
  }
34
37
  });
35
38
  }
36
39
 
37
- if (!Array.isArray(record.children) || selection.independentSelectionExpandedRows) {
40
+ if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
38
41
  var key = getRowKey(record);
39
42
 
40
43
  if (key && keys.includes(key)) {
@@ -46,20 +49,22 @@ function TableSelection(_ref) {
46
49
  }
47
50
 
48
51
  return [];
49
- }, [allData, getRowKey, selection]);
52
+ }, [allData, getRowKey, selection, childrenColumnName]);
50
53
  var selectAll = React.useCallback(function () {
51
54
  if (dataSource && selection) {
52
55
  var selectedRowKeys = selection.selectedRowKeys;
53
56
  var keys = isShowingSubset ? [].concat(selectedRowKeys) : [];
54
57
  dataSource.forEach(function (record) {
55
- if (Array.isArray(record.children)) {
56
- keys = [].concat(keys, record.children.reduce(function (acc, child) {
58
+ var rowChildren = record[childrenColumnName];
59
+
60
+ if (Array.isArray(rowChildren)) {
61
+ keys = [].concat(keys, rowChildren.reduce(function (acc, child) {
57
62
  var key = getRowKey(child);
58
63
  return key ? [].concat(acc, [key]) : acc;
59
64
  }, []));
60
65
  }
61
66
 
62
- if (!Array.isArray(record.children) || selection.independentSelectionExpandedRows) {
67
+ if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
63
68
  var key = getRowKey(record);
64
69
  keys = key !== undefined ? [].concat(keys, [key]) : [].concat(keys);
65
70
  }
@@ -68,21 +73,23 @@ function TableSelection(_ref) {
68
73
  var rows = getRowsForKeys(uniqueKeys);
69
74
  selection.onChange(uniqueKeys, rows);
70
75
  }
71
- }, [dataSource, selection, isShowingSubset, getRowsForKeys, getRowKey]);
76
+ }, [dataSource, selection, isShowingSubset, getRowsForKeys, getRowKey, childrenColumnName]);
72
77
  var unselectAll = React.useCallback(function () {
73
78
  if (selection) {
74
79
  if (isShowingSubset) {
75
80
  var selectedRowKeys = selection.selectedRowKeys;
76
81
  var keysToUnselect = [];
77
82
  dataSource.forEach(function (record) {
78
- if (Array.isArray(record.children)) {
79
- keysToUnselect = [].concat(keysToUnselect, record.children.reduce(function (acc, child) {
83
+ var rowChildren = record[childrenColumnName];
84
+
85
+ if (Array.isArray(rowChildren)) {
86
+ keysToUnselect = [].concat(keysToUnselect, rowChildren.reduce(function (acc, child) {
80
87
  var key = getRowKey(child);
81
88
  return key ? [].concat(acc, [key]) : acc;
82
89
  }, []));
83
90
  }
84
91
 
85
- if (!Array.isArray(record.children) || selection.independentSelectionExpandedRows) {
92
+ if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
86
93
  var key = getRowKey(record);
87
94
  keysToUnselect = key !== undefined ? [].concat(keysToUnselect, [key]) : [].concat(keysToUnselect);
88
95
  }
@@ -96,7 +103,7 @@ function TableSelection(_ref) {
96
103
  selection.onChange([], []);
97
104
  }
98
105
  }
99
- }, [dataSource, getRowKey, getRowsForKeys, isShowingSubset, selection]);
106
+ }, [dataSource, getRowKey, getRowsForKeys, isShowingSubset, selection, childrenColumnName]);
100
107
  var getSelectableChildren = React.useCallback(function (children) {
101
108
  return children ? children.filter(function (child) {
102
109
  return getRowKey(child) !== undefined;
@@ -107,8 +114,9 @@ function TableSelection(_ref) {
107
114
  var selectedRowKeys = selection.selectedRowKeys;
108
115
  var keys = isShowingSubset ? [].concat(selectedRowKeys) : [];
109
116
  dataSource.forEach(function (record) {
110
- var hasChildren = Array.isArray(record.children);
111
- var selectableChildren = hasChildren ? getSelectableChildren(record.children) : false;
117
+ var rowChildren = record[childrenColumnName];
118
+ var hasChildren = Array.isArray(rowChildren);
119
+ var selectableChildren = hasChildren ? getSelectableChildren(rowChildren) : false;
112
120
 
113
121
  if (selectableChildren) {
114
122
  selectableChildren.forEach(function (child) {
@@ -135,7 +143,7 @@ function TableSelection(_ref) {
135
143
  var rows = getRowsForKeys(keys);
136
144
  selection.onChange(keys, rows);
137
145
  }
138
- }, [dataSource, selection, isShowingSubset, getRowsForKeys, getSelectableChildren, getRowKey]);
146
+ }, [dataSource, selection, isShowingSubset, getRowsForKeys, getSelectableChildren, getRowKey, childrenColumnName]);
139
147
  var isEmpty = React.useMemo(function () {
140
148
  return dataSource.length === 0;
141
149
  }, [dataSource]);
@@ -144,21 +152,25 @@ function TableSelection(_ref) {
144
152
  var selectedRowKeys = selection.selectedRowKeys,
145
153
  independentSelectionExpandedRows = selection.independentSelectionExpandedRows;
146
154
  var allRecordsCount = dataSource.reduce(function (count, record) {
155
+ var rowChildren = record[childrenColumnName];
156
+
147
157
  if (independentSelectionExpandedRows) {
148
- return Array.isArray(record.children) ? count + getSelectableChildren(record.children).length + 1 : count + 1;
158
+ return Array.isArray(rowChildren) ? count + getSelectableChildren(rowChildren).length + 1 : count + 1;
149
159
  }
150
160
 
151
- return Array.isArray(record.children) ? count + getSelectableChildren(record.children).length : count + 1;
161
+ return Array.isArray(rowChildren) ? count + getSelectableChildren(rowChildren).length : count + 1;
152
162
  }, 0);
153
163
  var selectedKeysInDataSourceCount = isShowingSubset ? dataSource.reduce(function (count, record) {
154
- if (Array.isArray(record.children)) {
155
- return record.children.reduce(function (childCount, child) {
164
+ var rowChildren = record[childrenColumnName];
165
+
166
+ if (Array.isArray(rowChildren)) {
167
+ return rowChildren.reduce(function (childCount, child) {
156
168
  var key = getRowKey(child);
157
169
  return selectedRowKeys.includes(key) ? childCount + 1 : childCount;
158
170
  }, 0);
159
171
  }
160
172
 
161
- if (!Array.isArray(record.children) || selection.independentSelectionExpandedRows) {
173
+ if (!Array.isArray(rowChildren) || selection.independentSelectionExpandedRows) {
162
174
  var key = getRowKey(record);
163
175
  return selectedRowKeys.includes(key) ? count + 1 : count;
164
176
  }
@@ -166,7 +178,7 @@ function TableSelection(_ref) {
166
178
  return count;
167
179
  }, 0) : selectedRowKeys.length;
168
180
  return allRecordsCount === selectedKeysInDataSourceCount;
169
- }, [isEmpty, selection, dataSource, isShowingSubset, getSelectableChildren, getRowKey]);
181
+ }, [isEmpty, selection, dataSource, isShowingSubset, getSelectableChildren, getRowKey, childrenColumnName]);
170
182
  var selectionTooltipTitle = !allSelected ? locale == null ? void 0 : locale.selectAllTooltip : locale == null ? void 0 : locale.unselectAll;
171
183
  return selection != null && selection.selectedRowKeys ? /*#__PURE__*/React.createElement(S.Selection, {
172
184
  "data-popup-container": true
@@ -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;
@@ -204,13 +206,14 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
204
206
  var selectedRows = [];
205
207
  allData.forEach(function (row) {
206
208
  var key = getRowKey(row);
209
+ var rowChildren = row[childrenColumnName];
207
210
 
208
211
  if (key && selectedRowKeys.indexOf(key) >= 0) {
209
212
  selectedRows = [].concat(selectedRows, [row]);
210
213
  }
211
214
 
212
- if (row.children !== undefined && Array.isArray(row.children)) {
213
- row.children.forEach(function (child) {
215
+ if (rowChildren !== undefined && Array.isArray(rowChildren)) {
216
+ rowChildren.forEach(function (child) {
214
217
  var childKey = getRowKey(child);
215
218
 
216
219
  if (childKey && selectedRowKeys.indexOf(childKey) >= 0) {
@@ -248,9 +251,10 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
248
251
  independentSelectionExpandedRows: independentSelectionExpandedRows,
249
252
  onChange: handleChange,
250
253
  selectedRecords: selectedRecords,
251
- tableLocale: locale
254
+ tableLocale: locale,
255
+ childrenColumnName: childrenColumnName
252
256
  });
253
- }, [isSticky, locale, rowKey, selectedRecords, selection]);
257
+ }, [isSticky, locale, rowKey, selectedRecords, selection, childrenColumnName]);
254
258
  var virtualColumns = useMemo(function () {
255
259
  return compact([!!selection && {
256
260
  width: 64,
@@ -349,9 +353,11 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
349
353
 
350
354
  listRef.current.scrollTo(top);
351
355
  }, []);
352
- var scrollToTop = useCallback(function () {
356
+
357
+ var scrollToTop = function scrollToTop() {
353
358
  scrollTo(0);
354
- }, [scrollTo]);
359
+ };
360
+
355
361
  var outerElement = useMemo(function () {
356
362
  return OuterListElement(containerRef, isSticky);
357
363
  }, [isSticky]);
@@ -417,16 +423,19 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
417
423
  var _infiniteScroll$nextP, _infiniteScroll$prevP5;
418
424
 
419
425
  var listHeight = data.length * cellHeight - scroll.y + infiniteLoaderOffset;
420
- var listMaxScroll = stickyScrollThreshold && infiniteScroll != null && infiniteScroll.maxScroll ? (infiniteScroll == null ? void 0 : infiniteScroll.maxScroll) - stickyScrollThreshold : listHeight;
426
+ var listMaxScroll = stickyScrollThreshold && infiniteScroll != null && infiniteScroll.maxScroll ? infiniteScroll.maxScroll - stickyScrollThreshold : listHeight;
421
427
 
422
428
  var handleListScroll = function handleListScroll(_ref5) {
423
429
  var scrollOffset = _ref5.scrollOffset,
424
430
  scrollDirection = _ref5.scrollDirection;
425
431
 
426
- if (loading || listMaxScroll <= 0) {
432
+ if (!infiniteScroll || loading || listMaxScroll <= 0) {
427
433
  return;
428
434
  }
429
435
 
436
+ var onScrollTopReach = infiniteScroll.onScrollTopReach,
437
+ isLoading = infiniteScroll.isLoading,
438
+ onScrollEndReach = infiniteScroll.onScrollEndReach;
430
439
  var roundedOffset = Math.ceil(scrollOffset);
431
440
  listScrollTopRef.current = roundedOffset;
432
441
 
@@ -438,12 +447,14 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
438
447
  setIsHeaderVisible(roundedOffset > 0);
439
448
  }
440
449
 
441
- if (scrollDirection === 'forward' && roundedOffset >= listMaxScroll - LOAD_DATA_OFFSET && typeof (infiniteScroll == null ? void 0 : infiniteScroll.onScrollEndReach) === 'function') {
442
- infiniteScroll.onScrollEndReach();
450
+ if (isLoading) {
451
+ return;
443
452
  }
444
453
 
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();
454
+ if (scrollDirection === 'forward' && roundedOffset >= listMaxScroll - LOAD_DATA_OFFSET && typeof onScrollEndReach === 'function') {
455
+ onScrollEndReach();
456
+ } else if (scrollDirection === 'backward' && (offsetScroll && roundedOffset <= offsetScroll + LOAD_DATA_OFFSET || roundedOffset < LOAD_DATA_OFFSET) && typeof onScrollTopReach === 'function') {
457
+ onScrollTopReach();
447
458
  }
448
459
  };
449
460
 
@@ -509,9 +520,10 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
509
520
  var _expandable$expandedR2;
510
521
 
511
522
  var key = getRowKey(currentRow);
523
+ var rowChildren = currentRow[childrenColumnName];
512
524
 
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) {
525
+ if (key !== undefined && expandable != null && (_expandable$expandedR2 = expandable.expandedRowKeys) != null && _expandable$expandedR2.includes(key) && Array.isArray(rowChildren) && rowChildren.length) {
526
+ return [].concat(result, [currentRow], rowChildren.map(function (child, index) {
515
527
  var _objectSpread2;
516
528
 
517
529
  return _objectSpread({}, child, (_objectSpread2 = {}, _objectSpread2[EXPANDED_ROW_PROPERTY] = true, _objectSpread2.index = index, _objectSpread2));
@@ -524,7 +536,7 @@ var VirtualTable = function VirtualTable(props, forwardedRef) {
524
536
  }
525
537
 
526
538
  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]);
539
+ }, [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
540
  var columnsSliceStartIndex = Number(!!selection) + Number(!!rowStar);
529
541
  var scrollValue = !dataSource || (dataSource == null ? void 0 : dataSource.length) === 0 ? undefined : scroll;
530
542
  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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-table",
3
- "version": "0.53.1",
3
+ "version": "0.54.0",
4
4
  "description": "Table UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -33,29 +33,29 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-alert": "^0.8.15",
36
+ "@synerise/ds-alert": "^0.8.17",
37
37
  "@synerise/ds-badge": "^0.7.1",
38
- "@synerise/ds-button": "^0.21.0",
39
- "@synerise/ds-button-group": "^0.7.2",
38
+ "@synerise/ds-button": "^0.21.1",
39
+ "@synerise/ds-button-group": "^0.7.3",
40
40
  "@synerise/ds-checkbox": "^0.12.1",
41
- "@synerise/ds-column-manager": "^0.11.59",
41
+ "@synerise/ds-column-manager": "^0.11.61",
42
42
  "@synerise/ds-data-format": "^0.5.0",
43
- "@synerise/ds-dropdown": "^0.18.1",
43
+ "@synerise/ds-dropdown": "^0.18.3",
44
44
  "@synerise/ds-flag": "^0.5.0",
45
- "@synerise/ds-icon": "^0.62.1",
46
- "@synerise/ds-input": "^0.22.0",
45
+ "@synerise/ds-icon": "^0.63.0",
46
+ "@synerise/ds-input": "^0.23.0",
47
47
  "@synerise/ds-loader": "^0.3.9",
48
- "@synerise/ds-menu": "^0.19.2",
49
- "@synerise/ds-modal": "^0.17.31",
50
- "@synerise/ds-pagination": "^0.7.52",
51
- "@synerise/ds-result": "^0.6.57",
52
- "@synerise/ds-scrollbar": "^0.11.1",
53
- "@synerise/ds-search": "^0.8.94",
54
- "@synerise/ds-select": "^0.16.3",
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.5",
55
55
  "@synerise/ds-skeleton": "^0.6.1",
56
- "@synerise/ds-status": "^0.6.9",
57
- "@synerise/ds-tags": "^0.9.1",
58
- "@synerise/ds-tooltip": "^0.14.30",
56
+ "@synerise/ds-status": "^0.6.11",
57
+ "@synerise/ds-tags": "^0.9.3",
58
+ "@synerise/ds-tooltip": "^0.14.31",
59
59
  "@synerise/ds-typography": "^0.15.0",
60
60
  "@synerise/ds-utils": "^0.27.0",
61
61
  "@types/react-window": "^1.8.5",
@@ -79,5 +79,5 @@
79
79
  "devDependencies": {
80
80
  "@testing-library/react": "10.0.1"
81
81
  },
82
- "gitHead": "ef835e848d4f02cca258130baa6c9f44dfa15dd0"
82
+ "gitHead": "0692552b018dc9c8042f18c773f88890c9ad3270"
83
83
  }