enhance for #402

This commit is contained in:
AllenFang
2018-08-01 20:26:00 +08:00
parent fadbcdaa24
commit 7919a4001d
2 changed files with 18 additions and 8 deletions
+9 -3
View File
@@ -1,5 +1,6 @@
/* eslint react/prop-types: 0 */
/* eslint react/require-default-props: 0 */
/* eslint no-lonely-if: 0 */
import React from 'react';
import PropTypes from 'prop-types';
@@ -62,8 +63,14 @@ export default (
currPage = page;
needNewState = true;
} else {
currPage = alignPage(nextProps.data, currPage, currSizePerPage, pageStartIndex);
needNewState = true;
// user should align the page when the page is not fit to the data size when remote enable
if (!isRemotePagination()) {
const newPage = alignPage(nextProps.data, currPage, currSizePerPage, pageStartIndex);
if (currPage !== newPage) {
currPage = newPage;
needNewState = true;
}
}
}
if (typeof sizePerPage !== 'undefined' && currSizePerPage !== sizePerPage) {
@@ -75,7 +82,6 @@ export default (
if (onPageChange) {
onPageChange(currPage, currSizePerPage);
}
this.currPage = currPage;
this.currSizePerPage = currSizePerPage;
}
@@ -138,6 +138,7 @@ describe('PaginationContext', () => {
instance = wrapper.instance();
wrapper.render();
nextProps = {
data,
pagination: {
options: {
page: 2,
@@ -167,6 +168,7 @@ describe('PaginationContext', () => {
instance = wrapper.instance();
wrapper.render();
nextProps = {
data,
pagination: {
options: {
page: 1,
@@ -178,7 +180,7 @@ describe('PaginationContext', () => {
});
it('shouldn\'t call options.onPageChange', () => {
expect(onPageChange).not.toHaveBeenCalled();
expect(onPageChange).toHaveBeenCalledTimes(0);
});
it('should have correct currPage', () => {
@@ -195,7 +197,7 @@ describe('PaginationContext', () => {
}));
instance = wrapper.instance();
wrapper.render();
nextProps = { pagination: defaultPagination };
nextProps = { data, pagination: defaultPagination };
instance.componentWillReceiveProps(nextProps);
});
@@ -216,6 +218,7 @@ describe('PaginationContext', () => {
instance = wrapper.instance();
wrapper.render();
nextProps = {
data,
pagination: {
options: {
sizePerPage: Const.SIZE_PER_PAGE_LIST[2],
@@ -245,6 +248,7 @@ describe('PaginationContext', () => {
instance = wrapper.instance();
wrapper.render();
nextProps = {
data,
pagination: {
options: {
sizePerPage: Const.SIZE_PER_PAGE_LIST[0],
@@ -255,8 +259,8 @@ describe('PaginationContext', () => {
instance.componentWillReceiveProps(nextProps);
});
it('shouldn\'t call options.onPageChange', () => {
expect(onPageChange).not.toHaveBeenCalled();
it('shouldn\'t call options.onPageChange', () => {
expect(onPageChange).toHaveBeenCalledTimes(0);
});
it('should have correct currSizePerPage', () => {
@@ -273,7 +277,7 @@ describe('PaginationContext', () => {
}));
instance = wrapper.instance();
wrapper.render();
nextProps = { pagination: defaultPagination };
nextProps = { data, pagination: defaultPagination };
instance.componentWillReceiveProps(nextProps);
});