Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoHide to Pagination #8615

Merged
merged 1 commit into from Dec 29, 2017

Conversation

@camsong
Copy link
Contributor

@camsong camsong commented Dec 14, 2017

It's quite cumbersome to show pagination when there is only 1 page.

Code like this can help but you need to define a const pageSize and not elegant.

const pageSize = 20;

<Table pagination={data.length > pageSize && { pageSize }} />

This is a common requirement so better to have a prop specifically for it.

autoHidePagination default is false, so it will not break any current behavior.

May refer to #4173

@camsong camsong force-pushed the camsong:table-autoHidePagination branch 2 times, most recently Dec 14, 2017
@yesmeck
Copy link
Member

@yesmeck yesmeck commented Dec 14, 2017

Hmm, how about moving this prop to pagination <Table pagination={{ autoHide: true }} />?

@camsong
Copy link
Contributor Author

@camsong camsong commented Dec 14, 2017

@yesmeck sure, will do

components/table/__tests__/Table.pagination.test.js Outdated
@@ -37,6 +37,21 @@ describe('Table.pagination', () => {
expect(wrapper).toMatchSnapshot();
});

it.only('should have pager when change pagination from false to undefined', () => {

This comment has been minimized.

@yesmeck

yesmeck Dec 14, 2017
Member

Remove "only".

@yesmeck
Copy link
Member

@yesmeck yesmeck commented Dec 14, 2017

And, you should PR to master.

@codecov
Copy link

@codecov codecov bot commented Dec 14, 2017

Codecov Report

No coverage uploaded for pull request base (master@5cda605). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #8615   +/-   ##
========================================
  Coverage          ?     85%           
========================================
  Files             ?     227           
  Lines             ?    4676           
  Branches          ?    1369           
========================================
  Hits              ?    3975           
  Misses            ?     701           
  Partials          ?       0
Impacted Files Coverage Δ
components/pagination/Pagination.tsx 94.11% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5cda605...25a0210. Read the comment docs.

@camsong camsong changed the title Add autoHidePagination to Table Add autoHide to Pagination Dec 14, 2017
@camsong
Copy link
Contributor Author

@camsong camsong commented Dec 14, 2017

@yesmeck I'm still using 2.x, I will make a PR to master as well.

@yesmeck
Copy link
Member

@yesmeck yesmeck commented Dec 14, 2017

You still need to PR to master, If we need release 2.x, we will cherry pick this feature to 2.x-stable branch.

@camsong camsong changed the base branch from 2.x-stable to master Dec 14, 2017
@camsong camsong force-pushed the camsong:table-autoHidePagination branch 3 times, most recently Dec 14, 2017
components/pagination/Pagination.tsx Outdated
@@ -50,6 +51,10 @@ export default class Pagination extends React.Component<PaginationProps, {}> {
}

render() {
// When autoHide is true and there is only 1 page, hide the pager
if (this.props.autoHide === true && (this.props.total || 0) <= (this.props.pageSize || 10)) {

This comment has been minimized.

@yesmeck

yesmeck Dec 15, 2017
Member

The defaultPageSize comes from rc-pagination, I think rc-paginaion is a better place a add this feature?

This comment has been minimized.

@camsong

camsong Dec 15, 2017
Author Contributor

Sounds good, done

@afc163
Copy link
Member

@afc163 afc163 commented Dec 15, 2017

autoHide => hideOnSinglePage

@camsong camsong force-pushed the camsong:table-autoHidePagination branch to 92bd9de Dec 15, 2017
@camsong
Copy link
Contributor Author

@camsong camsong commented Dec 15, 2017

@yesmeck @afc163 Done, tests should pass after rc-pagination released.

@yutingzhao1991
Copy link
Contributor

@yutingzhao1991 yutingzhao1991 commented Dec 17, 2017

@camsong rc-pagination published, you need to upgrade it to ~1.13.0 in antd.

@camsong camsong force-pushed the camsong:table-autoHidePagination branch from 92bd9de Dec 18, 2017
@camsong
Copy link
Contributor Author

@camsong camsong commented Dec 18, 2017

@yutingzhao1991 Thanks so much.

It seems antd also need to be published to get TypeScript support 😏
Right now we are using 2.x version with TS, can you help to make a release?

@yesmeck
Copy link
Member

@yesmeck yesmeck commented Dec 18, 2017

接口先自己覆盖下吧typings/index.d.ts。分支之前说错了,需要 PR 到 feature-3.1

/// <reference types="react" />
import * as React from 'react';

declare module 'antd/lib/pagination/Pagination' {
  interface PaginationProps {
    hideOnSinglePage?: boolean;
  }
}
@camsong camsong changed the base branch from master to feature-3.1 Dec 18, 2017
@camsong camsong force-pushed the camsong:table-autoHidePagination branch 2 times, most recently Dec 18, 2017
@camsong
Copy link
Contributor Author

@camsong camsong commented Dec 18, 2017

@yesmeck target branch changed, your patch works for now.

@yesmeck
Copy link
Member

@yesmeck yesmeck commented Dec 18, 2017

Should update rc-pagination to 1.13.0.

@camsong camsong force-pushed the camsong:table-autoHidePagination branch to 25a0210 Dec 18, 2017
@yesmeck yesmeck mentioned this pull request Dec 29, 2017
@yutingzhao1991 yutingzhao1991 changed the base branch from feature-3.1 to master Dec 29, 2017
@yutingzhao1991 yutingzhao1991 merged commit 1af1534 into ant-design:master Dec 29, 2017
4 checks passed
4 checks passed
codecov/patch Coverage not affected when comparing c30ac8d...25a0210
Details
codecov/project 85% (+0.02%) compared to c30ac8d
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
security/snyk No new issues
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants