@atlaskit/dynamic-table 14.8.9 → 14.8.10

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 (90) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/components/body.js +5 -22
  3. package/dist/cjs/components/loading-container-advanced.js +17 -61
  4. package/dist/cjs/components/loading-container.js +5 -23
  5. package/dist/cjs/components/managed-pagination.js +7 -28
  6. package/dist/cjs/components/rankable/body.js +12 -41
  7. package/dist/cjs/components/rankable/table-cell.js +10 -34
  8. package/dist/cjs/components/rankable/table-head-cell.js +4 -25
  9. package/dist/cjs/components/rankable/table-row.js +11 -46
  10. package/dist/cjs/components/stateful.js +23 -54
  11. package/dist/cjs/components/stateless.js +31 -84
  12. package/dist/cjs/components/table-head-cell.js +8 -16
  13. package/dist/cjs/components/table-head.js +12 -42
  14. package/dist/cjs/components/table-row.js +13 -23
  15. package/dist/cjs/hoc/with-dimensions.js +6 -27
  16. package/dist/cjs/hoc/with-sorted-page-rows.js +27 -64
  17. package/dist/cjs/index.js +0 -3
  18. package/dist/cjs/internal/helpers.js +9 -30
  19. package/dist/cjs/styled/constants.js +3 -9
  20. package/dist/cjs/styled/dynamic-table.js +4 -20
  21. package/dist/cjs/styled/empty-body.js +3 -10
  22. package/dist/cjs/styled/loading-container-advanced.js +5 -15
  23. package/dist/cjs/styled/loading-container.js +5 -15
  24. package/dist/cjs/styled/rankable/row-placeholder.js +6 -9
  25. package/dist/cjs/styled/rankable/table-cell.js +6 -12
  26. package/dist/cjs/styled/rankable/table-row.js +4 -11
  27. package/dist/cjs/styled/table-cell.js +8 -15
  28. package/dist/cjs/styled/table-head.js +12 -31
  29. package/dist/cjs/styled/table-row.js +5 -11
  30. package/dist/cjs/theme.js +0 -5
  31. package/dist/cjs/version.json +1 -1
  32. package/dist/es2019/components/body.js +0 -3
  33. package/dist/es2019/components/loading-container-advanced.js +7 -40
  34. package/dist/es2019/components/loading-container.js +0 -2
  35. package/dist/es2019/components/managed-pagination.js +2 -5
  36. package/dist/es2019/components/rankable/body.js +0 -8
  37. package/dist/es2019/components/rankable/table-cell.js +0 -1
  38. package/dist/es2019/components/rankable/table-head-cell.js +0 -3
  39. package/dist/es2019/components/rankable/table-row.js +2 -7
  40. package/dist/es2019/components/stateful.js +0 -14
  41. package/dist/es2019/components/stateless.js +3 -34
  42. package/dist/es2019/components/table-head-cell.js +2 -4
  43. package/dist/es2019/components/table-head.js +2 -10
  44. package/dist/es2019/components/table-row.js +2 -3
  45. package/dist/es2019/hoc/with-dimensions.js +4 -11
  46. package/dist/es2019/hoc/with-sorted-page-rows.js +16 -33
  47. package/dist/es2019/internal/helpers.js +6 -11
  48. package/dist/es2019/styled/constants.js +3 -3
  49. package/dist/es2019/styled/dynamic-table.js +1 -5
  50. package/dist/es2019/styled/empty-body.js +1 -1
  51. package/dist/es2019/styled/loading-container-advanced.js +3 -5
  52. package/dist/es2019/styled/loading-container.js +1 -1
  53. package/dist/es2019/styled/rankable/row-placeholder.js +6 -5
  54. package/dist/es2019/styled/rankable/table-cell.js +5 -4
  55. package/dist/es2019/styled/rankable/table-row.js +2 -2
  56. package/dist/es2019/styled/table-cell.js +7 -5
  57. package/dist/es2019/styled/table-head.js +4 -5
  58. package/dist/es2019/styled/table-row.js +2 -2
  59. package/dist/es2019/types.js +1 -0
  60. package/dist/es2019/version.json +1 -1
  61. package/dist/esm/components/body.js +5 -15
  62. package/dist/esm/components/loading-container-advanced.js +17 -65
  63. package/dist/esm/components/loading-container.js +5 -16
  64. package/dist/esm/components/managed-pagination.js +7 -23
  65. package/dist/esm/components/rankable/body.js +12 -30
  66. package/dist/esm/components/rankable/table-cell.js +10 -21
  67. package/dist/esm/components/rankable/table-head-cell.js +4 -15
  68. package/dist/esm/components/rankable/table-row.js +11 -31
  69. package/dist/esm/components/stateful.js +23 -51
  70. package/dist/esm/components/stateless.js +31 -70
  71. package/dist/esm/components/table-head-cell.js +8 -11
  72. package/dist/esm/components/table-head.js +12 -33
  73. package/dist/esm/components/table-row.js +13 -18
  74. package/dist/esm/hoc/with-dimensions.js +6 -22
  75. package/dist/esm/hoc/with-sorted-page-rows.js +27 -54
  76. package/dist/esm/internal/helpers.js +9 -16
  77. package/dist/esm/styled/constants.js +3 -3
  78. package/dist/esm/styled/dynamic-table.js +4 -10
  79. package/dist/esm/styled/empty-body.js +3 -3
  80. package/dist/esm/styled/loading-container-advanced.js +5 -8
  81. package/dist/esm/styled/loading-container.js +5 -6
  82. package/dist/esm/styled/rankable/row-placeholder.js +6 -5
  83. package/dist/esm/styled/rankable/table-cell.js +7 -7
  84. package/dist/esm/styled/rankable/table-row.js +4 -5
  85. package/dist/esm/styled/table-cell.js +11 -10
  86. package/dist/esm/styled/table-head.js +12 -19
  87. package/dist/esm/styled/table-row.js +5 -6
  88. package/dist/esm/types.js +1 -0
  89. package/dist/esm/version.json +1 -1
  90. package/package.json +1 -1
@@ -9,16 +9,13 @@ import TableCell from './table-cell';
9
9
  export class RankableTableRow extends React.Component {
10
10
  constructor(...args) {
11
11
  super(...args);
12
-
13
12
  _defineProperty(this, "innerRef", innerRefFn => ref => {
14
13
  innerRefFn(ref);
15
-
16
14
  if (typeof this.props.innerRef === 'function') {
17
15
  this.props.innerRef(ref);
18
16
  }
19
17
  });
20
18
  }
21
-
22
19
  render() {
23
20
  const {
24
21
  row,
@@ -37,18 +34,17 @@ export class RankableTableRow extends React.Component {
37
34
  ...restRowProps
38
35
  } = row;
39
36
  const inlineStyles = inlineStylesIfRanking(isRanking, refWidth);
40
-
41
37
  if (typeof key !== 'string' && !isRankingDisabled) {
42
38
  throw new Error('dynamic-table: ranking is not possible because table row does not have a key. Add the key to the row or disable ranking.');
43
39
  }
44
-
45
40
  return /*#__PURE__*/React.createElement(Draggable, {
46
41
  draggableId: key || rowIndex.toString(),
47
42
  index: rowIndex,
48
43
  isDragDisabled: isRankingDisabled
49
44
  }, (provided, snapshot) => /*#__PURE__*/React.createElement(RankableTableBodyRow, _extends({}, restRowProps, provided.dragHandleProps, provided.draggableProps, {
50
45
  ref: this.innerRef(provided.innerRef),
51
- style: { ...provided.draggableProps.style,
46
+ style: {
47
+ ...provided.draggableProps.style,
52
48
  ...inlineStyles
53
49
  },
54
50
  isHighlighted: isHighlighted,
@@ -69,6 +65,5 @@ export class RankableTableRow extends React.Component {
69
65
  });
70
66
  })));
71
67
  }
72
-
73
68
  }
74
69
  export default withDimensions(RankableTableRow);
@@ -3,7 +3,6 @@ import React from 'react';
3
3
  import noop from '@atlaskit/ds-lib/noop';
4
4
  import { reorderRows } from '../internal/helpers';
5
5
  import DynamicTableStateless from './stateless';
6
-
7
6
  /**
8
7
  * __Dynamic Table__
9
8
  *
@@ -33,19 +32,16 @@ import DynamicTableStateless from './stateless';
33
32
  export default class DynamicTable extends React.Component {
34
33
  constructor(...args) {
35
34
  super(...args);
36
-
37
35
  _defineProperty(this, "state", {
38
36
  page: this.props.defaultPage,
39
37
  sortKey: this.props.defaultSortKey,
40
38
  sortOrder: this.props.defaultSortOrder,
41
39
  rows: this.props.rows
42
40
  });
43
-
44
41
  _defineProperty(this, "onSetPage", (page, analyticsEvent) => {
45
42
  const {
46
43
  onSetPage
47
44
  } = this.props;
48
-
49
45
  if (onSetPage) {
50
46
  onSetPage(page, analyticsEvent);
51
47
  this.setState({
@@ -53,7 +49,6 @@ export default class DynamicTable extends React.Component {
53
49
  });
54
50
  }
55
51
  });
56
-
57
52
  _defineProperty(this, "onSort", ({
58
53
  key,
59
54
  item,
@@ -62,7 +57,6 @@ export default class DynamicTable extends React.Component {
62
57
  const {
63
58
  onSort
64
59
  } = this.props;
65
-
66
60
  if (onSort) {
67
61
  onSort({
68
62
  key,
@@ -75,13 +69,11 @@ export default class DynamicTable extends React.Component {
75
69
  });
76
70
  }
77
71
  });
78
-
79
72
  _defineProperty(this, "onRankEndIfExists", params => {
80
73
  if (this.props.onRankEnd) {
81
74
  this.props.onRankEnd(params);
82
75
  }
83
76
  });
84
-
85
77
  _defineProperty(this, "onRankEnd", params => {
86
78
  const {
87
79
  destination
@@ -93,12 +85,10 @@ export default class DynamicTable extends React.Component {
93
85
  const {
94
86
  rowsPerPage
95
87
  } = this.props;
96
-
97
88
  if (!destination || !rows) {
98
89
  this.onRankEndIfExists(params);
99
90
  return;
100
91
  }
101
-
102
92
  const reordered = reorderRows(params, rows, page, rowsPerPage);
103
93
  this.setState({
104
94
  rows: reordered
@@ -106,7 +96,6 @@ export default class DynamicTable extends React.Component {
106
96
  this.onRankEndIfExists(params);
107
97
  });
108
98
  }
109
-
110
99
  UNSAFE_componentWillReceiveProps(newProps) {
111
100
  const sortKey = newProps.sortKey || this.state.sortKey;
112
101
  const sortOrder = newProps.sortOrder || this.state.sortOrder;
@@ -118,7 +107,6 @@ export default class DynamicTable extends React.Component {
118
107
  rows: newProps.rows
119
108
  });
120
109
  }
121
-
122
110
  render() {
123
111
  const {
124
112
  page,
@@ -168,9 +156,7 @@ export default class DynamicTable extends React.Component {
168
156
  label: label
169
157
  });
170
158
  }
171
-
172
159
  }
173
-
174
160
  _defineProperty(DynamicTable, "defaultProps", {
175
161
  defaultPage: 1,
176
162
  isLoading: false,
@@ -14,29 +14,23 @@ import ManagedPagination from './managed-pagination';
14
14
  import RankableTableBody from './rankable/body';
15
15
  import TableHead from './table-head';
16
16
  const packageName = "@atlaskit/dynamic-table";
17
- const packageVersion = "14.8.9";
18
-
17
+ const packageVersion = "14.8.10";
19
18
  function toggleSortOrder(currentSortOrder) {
20
19
  switch (currentSortOrder) {
21
20
  case DESC:
22
21
  return ASC;
23
-
24
22
  case ASC:
25
23
  return DESC;
26
-
27
24
  default:
28
25
  return currentSortOrder;
29
26
  }
30
27
  }
31
-
32
28
  class DynamicTable extends React.Component {
33
29
  constructor(...args) {
34
30
  super(...args);
35
-
36
31
  _defineProperty(this, "state", {
37
32
  isRanking: false
38
33
  });
39
-
40
34
  _defineProperty(this, "onSort", item => () => {
41
35
  const {
42
36
  sortKey,
@@ -47,11 +41,9 @@ class DynamicTable extends React.Component {
47
41
  const {
48
42
  key
49
43
  } = item;
50
-
51
44
  if (!key) {
52
45
  return;
53
46
  }
54
-
55
47
  if (onSort && isRankable && key === sortKey && sortOrder === DESC) {
56
48
  onSort({
57
49
  key: null,
@@ -60,9 +52,7 @@ class DynamicTable extends React.Component {
60
52
  });
61
53
  return;
62
54
  }
63
-
64
55
  const sortOrderFormatted = key !== sortKey ? ASC : toggleSortOrder(sortOrder);
65
-
66
56
  if (onSort) {
67
57
  onSort({
68
58
  key,
@@ -71,37 +61,30 @@ class DynamicTable extends React.Component {
71
61
  });
72
62
  }
73
63
  });
74
-
75
64
  _defineProperty(this, "onSetPage", (page, event) => {
76
65
  const {
77
66
  onSetPage
78
67
  } = this.props;
79
-
80
68
  if (onSetPage) {
81
69
  onSetPage(page, event);
82
70
  }
83
71
  });
84
-
85
72
  _defineProperty(this, "onRankStart", params => {
86
73
  this.setState({
87
74
  isRanking: true
88
75
  });
89
-
90
76
  if (this.props.onRankStart) {
91
77
  this.props.onRankStart(params);
92
78
  }
93
79
  });
94
-
95
80
  _defineProperty(this, "onRankEnd", params => {
96
81
  this.setState({
97
82
  isRanking: false
98
83
  });
99
-
100
84
  if (this.props.onRankEnd) {
101
85
  this.props.onRankEnd(params);
102
86
  }
103
87
  });
104
-
105
88
  _defineProperty(this, "getSpinnerSize", () => {
106
89
  const {
107
90
  page,
@@ -109,48 +92,39 @@ class DynamicTable extends React.Component {
109
92
  rowsPerPage,
110
93
  loadingSpinnerSize
111
94
  } = this.props;
112
-
113
95
  if (loadingSpinnerSize) {
114
96
  return loadingSpinnerSize;
115
97
  }
116
-
117
98
  return getPageRows(rows || [], page, rowsPerPage).length > 2 ? LARGE : SMALL;
118
99
  });
119
-
120
100
  _defineProperty(this, "renderEmptyBody", () => {
121
101
  const {
122
102
  emptyView,
123
103
  isLoading,
124
104
  testId
125
105
  } = this.props;
126
-
127
106
  if (isLoading) {
128
107
  return /*#__PURE__*/React.createElement(EmptyViewWithFixedHeight, {
129
108
  testId: testId
130
109
  });
131
110
  }
132
-
133
111
  return emptyView && /*#__PURE__*/React.createElement(EmptyViewContainer, {
134
112
  testId: testId
135
113
  }, emptyView);
136
114
  });
137
115
  }
138
-
139
116
  UNSAFE_componentWillMount() {
140
117
  validateSortKey(this.props.sortKey, this.props.head);
141
118
  assertIsSortable(this.props.head);
142
119
  }
143
-
144
120
  UNSAFE_componentWillReceiveProps(nextProps) {
145
121
  if (this.props.sortKey !== nextProps.sortKey || this.props.head !== nextProps.head) {
146
122
  validateSortKey(nextProps.sortKey, nextProps.head);
147
123
  }
148
-
149
124
  if (this.props.head !== nextProps.head) {
150
125
  assertIsSortable(nextProps.head);
151
126
  }
152
127
  }
153
-
154
128
  render() {
155
129
  const {
156
130
  caption,
@@ -172,11 +146,10 @@ class DynamicTable extends React.Component {
172
146
  label
173
147
  } = this.props;
174
148
  const rowsLength = rows && rows.length;
175
- let totalPages; // set a flag to denote the dynamic table might get only one page of data
149
+ let totalPages;
150
+ // set a flag to denote the dynamic table might get only one page of data
176
151
  // for paginated data
177
-
178
152
  let isTotalPagesControlledExternally = false;
179
-
180
153
  if (passedDownTotalRows && Number.isInteger(passedDownTotalRows) && rowsPerPage && rowsLength && rowsLength <= passedDownTotalRows) {
181
154
  /**
182
155
  * If total number of rows / records have been passed down as prop
@@ -189,7 +162,6 @@ class DynamicTable extends React.Component {
189
162
  } else {
190
163
  totalPages = rowsLength && rowsPerPage ? Math.ceil(rowsLength / rowsPerPage) : 0;
191
164
  }
192
-
193
165
  totalPages = totalPages < 1 ? 1 : totalPages;
194
166
  const getPageNumber = page > totalPages ? totalPages : page; // page! required, because typescript can't yet see defaultProps to know that this won't be undefined
195
167
 
@@ -251,9 +223,7 @@ class DynamicTable extends React.Component {
251
223
  testId: testId
252
224
  }, emptyBody));
253
225
  }
254
-
255
226
  }
256
-
257
227
  _defineProperty(DynamicTable, "defaultProps", {
258
228
  isLoading: false,
259
229
  isFixedSize: false,
@@ -271,7 +241,6 @@ _defineProperty(DynamicTable, "defaultProps", {
271
241
  label: 'Pagination'
272
242
  }
273
243
  });
274
-
275
244
  export { DynamicTable as DynamicTableWithoutAnalytics };
276
245
  const createAndFireEventOnAtlaskit = createAndFireEvent('atlaskit');
277
246
  export default withAnalyticsContext({
@@ -1,7 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
3
  import { HeadCell } from '../styled/table-head';
4
-
5
4
  const TableHeadCell = ({
6
5
  content,
7
6
  inlineStyles,
@@ -16,12 +15,11 @@ const TableHeadCell = ({
16
15
  "data-testid": testId && `${testId}--head--cell`,
17
16
  ref: typeof innerRef !== 'string' ? innerRef : null // string refs must be discarded as LegacyRefs are not compatible with FC forwardRefs
18
17
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
19
-
20
18
  }, rest, {
21
19
  tabIndex: isSortable ? 0 : undefined,
22
20
  isSortable: isSortable
23
21
  }), /*#__PURE__*/React.createElement("span", null, content));
24
- }; // eslint-disable-next-line @repo/internal/react/require-jsdoc
25
-
22
+ };
26
23
 
24
+ // eslint-disable-next-line @repo/internal/react/require-jsdoc
27
25
  export default TableHeadCell;
@@ -5,24 +5,19 @@ import { validateSortKey } from '../internal/helpers';
5
5
  import { Head } from '../styled/table-head';
6
6
  import RankableHeadCell from './rankable/table-head-cell';
7
7
  import HeadCell from './table-head-cell';
8
-
9
8
  class TableHead extends React.Component {
10
9
  constructor(...args) {
11
10
  super(...args);
12
-
13
11
  _defineProperty(this, "canSortOnEnterPressed", (e, isSortable) => isSortable && e.key === 'Enter');
14
12
  }
15
-
16
13
  UNSAFE_componentWillMount() {
17
14
  validateSortKey(this.props.sortKey, this.props.head);
18
15
  }
19
-
20
16
  UNSAFE_componentWillReceiveProps(nextProps) {
21
17
  if (this.props.sortKey !== nextProps.sortKey || this.props.head !== nextProps.head) {
22
18
  validateSortKey(nextProps.sortKey, nextProps.head);
23
19
  }
24
20
  }
25
-
26
21
  render() {
27
22
  const {
28
23
  head,
@@ -34,11 +29,9 @@ class TableHead extends React.Component {
34
29
  isRankable,
35
30
  testId
36
31
  } = this.props;
37
-
38
32
  if (!head) {
39
33
  return null;
40
34
  }
41
-
42
35
  const HeadCellComponent = isRankable ? RankableHeadCell : HeadCell;
43
36
  const {
44
37
  cells,
@@ -65,8 +58,7 @@ class TableHead extends React.Component {
65
58
  }, restCellProps));
66
59
  })));
67
60
  }
61
+ }
68
62
 
69
- } // eslint-disable-next-line @repo/internal/react/require-jsdoc
70
-
71
-
63
+ // eslint-disable-next-line @repo/internal/react/require-jsdoc
72
64
  export default TableHead;
@@ -2,7 +2,6 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
3
  import { TableBodyCell } from '../styled/table-cell';
4
4
  import { TableBodyRow } from '../styled/table-row';
5
-
6
5
  const Row = ({
7
6
  row,
8
7
  head,
@@ -41,7 +40,7 @@ const Row = ({
41
40
  width: width
42
41
  }), content);
43
42
  }));
44
- }; // eslint-disable-next-line @repo/internal/react/require-jsdoc
45
-
43
+ };
46
44
 
45
+ // eslint-disable-next-line @repo/internal/react/require-jsdoc
47
46
  export default Row;
@@ -6,23 +6,19 @@ export default function withDimensions(WrappedComponent) {
6
6
  return class WithDimensions extends React.Component {
7
7
  constructor(...args) {
8
8
  super(...args);
9
-
10
9
  _defineProperty(this, "state", {
11
10
  refWidth: 0,
12
11
  refHeight: 0
13
12
  });
14
-
15
13
  _defineProperty(this, "innerRef", ref => {
16
14
  if (ref && !this.props.isRanking) {
17
15
  this.ref = ref;
18
16
  }
19
17
  });
20
-
21
18
  _defineProperty(this, "updateDimensions", () => {
22
19
  if (!this.ref) {
23
20
  return;
24
21
  }
25
-
26
22
  const clientRect = this.ref.getBoundingClientRect();
27
23
  const {
28
24
  width
@@ -30,7 +26,6 @@ export default function withDimensions(WrappedComponent) {
30
26
  const {
31
27
  height
32
28
  } = clientRect;
33
-
34
29
  if (width !== this.state.refWidth || height !== this.state.refHeight) {
35
30
  this.setState({
36
31
  refWidth: width,
@@ -39,29 +34,27 @@ export default function withDimensions(WrappedComponent) {
39
34
  }
40
35
  });
41
36
  }
42
-
43
37
  UNSAFE_componentWillReceiveProps(nextProps) {
44
38
  const wasRanking = this.props.isRanking;
45
39
  const willRanking = nextProps.isRanking;
46
-
47
40
  if (willRanking && !wasRanking) {
48
41
  this.updateDimensions();
49
42
  }
50
43
  }
51
-
52
44
  render() {
53
45
  const {
54
46
  refWidth,
55
47
  refHeight
56
48
  } = this.state;
57
- return /*#__PURE__*/React.createElement(WrappedComponent //@ts-expect-error TODO Fix legit TypeScript 3.9.6 improved inference error
49
+ return /*#__PURE__*/React.createElement(WrappedComponent
50
+ //@ts-expect-error TODO Fix legit TypeScript 3.9.6 improved inference error
58
51
  , _extends({
59
- refWidth: refWidth //@ts-expect-error TODO Fix legit TypeScript 3.9.6 improved inference error
52
+ refWidth: refWidth
53
+ //@ts-expect-error TODO Fix legit TypeScript 3.9.6 improved inference error
60
54
  ,
61
55
  refHeight: refHeight,
62
56
  innerRef: this.innerRef
63
57
  }, this.props));
64
58
  }
65
-
66
59
  };
67
60
  }
@@ -3,97 +3,84 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import React from 'react';
4
4
  import { ASC } from '../internal/constants';
5
5
  import { getPageRows, validateSortKey } from '../internal/helpers';
6
-
7
6
  // sort all rows based on sort key and order
8
7
  const getSortedRows = (head, rows, sortKey, sortOrder) => {
9
8
  if (!sortKey || !head) {
10
9
  return rows;
11
10
  }
12
-
13
11
  if (!rows) {
14
12
  return [];
15
- } // return value which will be used for sorting
16
-
13
+ }
17
14
 
15
+ // return value which will be used for sorting
18
16
  const getSortingCellValue = cells => {
19
17
  for (let i = 0; i < cells.length; i++) {
20
18
  if (head.cells[i] && head.cells[i].key === sortKey) {
21
19
  return cells[i].key;
22
20
  }
23
21
  }
24
-
25
22
  return undefined;
26
- }; // Get copy of rows to avoid sorting prop in place
23
+ };
27
24
 
25
+ // Get copy of rows to avoid sorting prop in place
26
+ const sortableRows = Array.from(rows);
28
27
 
29
- const sortableRows = Array.from(rows); // Reorder rows in table based on sorting cell value
28
+ // Reorder rows in table based on sorting cell value
30
29
  // Algorithm will sort numerics or strings, but not both
31
-
32
30
  return sortableRows.sort((a, b) => {
33
31
  const valA = getSortingCellValue(a.cells);
34
- const valB = getSortingCellValue(b.cells); // modifier used for sorting type (ascending or descending)
32
+ const valB = getSortingCellValue(b.cells);
35
33
 
34
+ // modifier used for sorting type (ascending or descending)
36
35
  const modifier = sortOrder === ASC ? 1 : -1;
37
-
38
36
  if (valA === undefined || valB === undefined) {
39
37
  return modifier;
40
38
  }
41
-
42
39
  if (typeof valA !== typeof valB) {
43
40
  // numbers are always grouped higher in the sort
44
41
  if (typeof valA === 'number') {
45
42
  return -1;
46
43
  }
47
-
48
44
  if (typeof valB === 'number') {
49
45
  return 1;
50
- } // strings are grouped next
51
-
52
-
46
+ }
47
+ // strings are grouped next
53
48
  if (typeof valA === 'string') {
54
49
  return -1;
55
50
  }
56
-
57
51
  if (typeof valB === 'string') {
58
52
  return 1;
59
53
  }
60
- } // Sort strings using localeCompare
61
-
54
+ }
62
55
 
56
+ // Sort strings using localeCompare
63
57
  if (typeof valA === 'string' && typeof valB === 'string') {
64
58
  return modifier * valA.localeCompare(valB, undefined, {
65
59
  sensitivity: 'accent',
66
60
  numeric: true
67
61
  });
68
62
  }
69
-
70
63
  if (!valA && valA !== 0 || valA < valB) {
71
64
  return -modifier;
72
65
  }
73
-
74
66
  if (!valB && valB !== 0 || valA > valB) {
75
67
  return modifier;
76
68
  }
77
-
78
69
  if (valA === valB) {
79
70
  return 0;
80
71
  }
81
-
82
72
  return 1;
83
73
  });
84
74
  };
85
-
86
75
  // get one page of data in table, sorting all rows previously
87
76
  export default function withSortedPageRows(WrappedComponent) {
88
77
  return class WithSortedPageRows extends React.Component {
89
78
  constructor(...args) {
90
79
  super(...args);
91
-
92
80
  _defineProperty(this, "state", {
93
81
  pageRows: []
94
82
  });
95
83
  }
96
-
97
84
  static getDerivedStateFromProps(props, state) {
98
85
  const {
99
86
  rows,
@@ -107,7 +94,6 @@ export default function withSortedPageRows(WrappedComponent) {
107
94
  validateSortKey(sortKey, head);
108
95
  let sortedRows;
109
96
  let pageRows;
110
-
111
97
  if (isTotalPagesControlledExternally) {
112
98
  sortedRows = rows;
113
99
  pageRows = rows;
@@ -115,22 +101,19 @@ export default function withSortedPageRows(WrappedComponent) {
115
101
  sortedRows = getSortedRows(head, rows, sortKey, sortOrder) || [];
116
102
  pageRows = getPageRows(sortedRows, page, rowsPerPage);
117
103
  }
118
-
119
- return { ...state,
104
+ return {
105
+ ...state,
120
106
  pageRows
121
107
  };
122
108
  }
123
-
124
109
  componentDidMount() {
125
110
  this.props.onPageRowsUpdate && this.props.onPageRowsUpdate(this.state.pageRows);
126
111
  }
127
-
128
112
  componentDidUpdate(_prevProps, prevState) {
129
113
  if (this.props.onPageRowsUpdate && this.state.pageRows !== prevState.pageRows) {
130
114
  this.props.onPageRowsUpdate(this.state.pageRows);
131
115
  }
132
116
  }
133
-
134
117
  render() {
135
118
  const {
136
119
  rows,
@@ -142,12 +125,12 @@ export default function withSortedPageRows(WrappedComponent) {
142
125
  // @ts-ignore - Rest types may only be created from object types
143
126
  ...restProps
144
127
  } = this.props;
145
- return /*#__PURE__*/React.createElement(WrappedComponent //@ts-expect-error TODO Fix legit TypeScript 3.9.6 improved inference error
128
+ return /*#__PURE__*/React.createElement(WrappedComponent
129
+ //@ts-expect-error TODO Fix legit TypeScript 3.9.6 improved inference error
146
130
  , _extends({
147
131
  pageRows: this.state.pageRows,
148
132
  head: head
149
133
  }, restProps));
150
134
  }
151
-
152
135
  };
153
136
  }
@@ -2,14 +2,12 @@ export const getPageRows = (allRows, pageNumber, rowsPerPage) => {
2
2
  if (!pageNumber || !rowsPerPage || !allRows.length) {
3
3
  return [];
4
4
  }
5
-
6
5
  return allRows.slice((pageNumber - 1) * rowsPerPage, pageNumber * rowsPerPage);
7
6
  };
8
7
  export const assertIsSortable = head => {
9
8
  if (!head || !head.cells) {
10
9
  return;
11
10
  }
12
-
13
11
  head.cells.forEach(cell => {
14
12
  if (cell.isSortable && !cell.key) {
15
13
  try {
@@ -25,9 +23,7 @@ export const validateSortKey = (sortKey, head) => {
25
23
  if (!sortKey) {
26
24
  return;
27
25
  }
28
-
29
26
  const headHasKey = head && head.cells.map(cell => cell.key).includes(sortKey);
30
-
31
27
  if (!headHasKey) {
32
28
  try {
33
29
  throw Error(`Cell with ${sortKey} key not found in head.`);
@@ -36,40 +32,39 @@ export const validateSortKey = (sortKey, head) => {
36
32
  console.error(e);
37
33
  }
38
34
  }
39
- }; // creates inline styles if flag ranking is true
35
+ };
40
36
 
37
+ // creates inline styles if flag ranking is true
41
38
  export const inlineStylesIfRanking = (isRanking, width, height) => {
42
39
  if (!isRanking) {
43
40
  return {};
44
41
  }
45
-
46
42
  if (height) {
47
43
  return {
48
44
  width,
49
45
  height
50
46
  };
51
47
  }
52
-
53
48
  return {
54
49
  width
55
50
  };
56
- }; // computes index of dropped item after ranking
51
+ };
57
52
 
53
+ // computes index of dropped item after ranking
58
54
  export const computeIndex = (index, page, rowsPerPage) => {
59
55
  const itemOnPreviousPages = rowsPerPage && isFinite(rowsPerPage) ? (page - 1) * rowsPerPage : 0;
60
56
  return index + itemOnPreviousPages;
61
- }; // reorder rows in table after ranking
57
+ };
62
58
 
59
+ // reorder rows in table after ranking
63
60
  export const reorderRows = (rankEnd, rows, page = 1, rowsPerPage) => {
64
61
  const {
65
62
  destination,
66
63
  sourceIndex
67
64
  } = rankEnd;
68
-
69
65
  if (!destination) {
70
66
  return rows;
71
67
  }
72
-
73
68
  const fromIndex = computeIndex(sourceIndex, page, rowsPerPage);
74
69
  const toIndex = computeIndex(destination.index, page, rowsPerPage);
75
70
  const reordered = rows.slice();