@spothero/ui 15.5.3 → 15.5.5

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.
@@ -271,7 +271,9 @@ var Table = /*#__PURE__*/function (_Component) {
271
271
  value: function componentDidUpdate(prevProps, prevState) {
272
272
  var _this$props3 = this.props,
273
273
  onPageChange = _this$props3.onPageChange,
274
- onSortChange = _this$props3.onSortChange;
274
+ onSortChange = _this$props3.onSortChange,
275
+ totalDataRowCount = _this$props3.totalDataRowCount,
276
+ pageSize = _this$props3.pageSize;
275
277
  var previousCurrentPage = prevState.currentPage,
276
278
  previousSortOrder = prevState.sortOrder,
277
279
  previousSortDataKey = prevState.sortDataKey;
@@ -281,6 +283,12 @@ var Table = /*#__PURE__*/function (_Component) {
281
283
  sortOrder = _this$state4.sortOrder,
282
284
  sortDataKey = _this$state4.sortDataKey;
283
285
 
286
+ if (totalDataRowCount !== prevProps.totalDataRowCount || pageSize !== prevProps.pageSize) {
287
+ this.setState({
288
+ totalPages: Math.ceil(totalDataRowCount / pageSize)
289
+ });
290
+ }
291
+
284
292
  if (previousCurrentPage !== currentPage && onPageChange) {
285
293
  onPageChange({
286
294
  totalPages: totalPages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spothero/ui",
3
- "version": "15.5.3",
3
+ "version": "15.5.5",
4
4
  "description": "SpotHero's React component UI library.",
5
5
  "main": "v2/index.js",
6
6
  "repository": "https://github.com/spothero/fe-monorepo",
@@ -163,4 +163,4 @@
163
163
  "react-redux": ">=7.0.0",
164
164
  "redux": ">=4.0.0"
165
165
  }
166
- }
166
+ }
@@ -147,7 +147,7 @@ export default class Table extends Component {
147
147
  }
148
148
 
149
149
  componentDidUpdate(prevProps, prevState) {
150
- const {onPageChange, onSortChange} = this.props;
150
+ const {onPageChange, onSortChange, totalDataRowCount, pageSize} = this.props;
151
151
  const {
152
152
  currentPage: previousCurrentPage,
153
153
  sortOrder: previousSortOrder,
@@ -155,6 +155,12 @@ export default class Table extends Component {
155
155
  } = prevState;
156
156
  const {totalPages, currentPage, sortOrder, sortDataKey} = this.state;
157
157
 
158
+ if (totalDataRowCount !== prevProps.totalDataRowCount || pageSize !== prevProps.pageSize) {
159
+ this.setState({
160
+ totalPages: Math.ceil(totalDataRowCount / pageSize)
161
+ })
162
+ }
163
+
158
164
  if (previousCurrentPage !== currentPage && onPageChange) {
159
165
  onPageChange({
160
166
  totalPages,
@@ -1,4 +1,4 @@
1
- import React, {useState} from 'react';
1
+ import React, {useEffect, useState} from 'react';
2
2
 
3
3
  import Table from '../Table';
4
4
  import TableSortType from '../TableSortType';
@@ -54,6 +54,41 @@ export const Pagination = () => {
54
54
  );
55
55
  };
56
56
 
57
+ export const AsyncPagination = () => {
58
+ const [currentPage, setCurrentPage] = useState(1);
59
+ const [data, setData] = useState(PAGE_1_DATA);
60
+ const [totalDataRowCount, setTotalDataRowCount] = useState(0);
61
+
62
+ const onPageChange = pages => {
63
+ if (window.onPageChange) {
64
+ window.onPageChange(pages);
65
+ }
66
+
67
+ setCurrentPage(pages.currentPage);
68
+ setData(pages.currentPage === 1 ? PAGE_1_DATA : PAGE_2_DATA);
69
+ };
70
+
71
+ useEffect(() => {
72
+ setTimeout(() => {
73
+ setTotalDataRowCount(TableData.length);
74
+ }, 500);
75
+ }, [])
76
+
77
+ return (
78
+ <Table
79
+ data={data}
80
+ headers={headers}
81
+ pageSize={PAGE_SIZE}
82
+ currentPage={currentPage}
83
+ className="AvengersTable"
84
+ onPageChange={onPageChange}
85
+ totalDataRowCount={totalDataRowCount}
86
+ />
87
+ );
88
+ };
89
+
90
+
91
+
57
92
  export const WithSortableHeaders = () => {
58
93
  const [{sortBy, sortOrder, sortDataKey}, setState] = useState({
59
94
  sortBy: ['-lastName'],