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
[added] Pagination component #786
Conversation
Thanks for putting this together. Unit tests should ensure:
You can look at the other tests in this library for inspiration there's a lot of good examples on how to test components there. |
className={pagenumber === this.props.activePage ? 'active' : null} | ||
data-pagenumber={pagenumber} | ||
onClick={this._onSelect}> | ||
<a href='#' onClick={this.noClick}>{pagenumber}</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The anchor fills the entire <li>
block. Can you just put the _onSelect
on the anchor and forego one on the li
? I don't see a need for noClick
if you did.
Also, we have a new SafeAnchor
that would work well here: https://github.com/react-bootstrap/react-bootstrap/blob/v0.24-rc/src/SafeAnchor.js. Though this PR would need to be re-opened against the v0.24.0-rc
branch as the SafeAnchor
is not slated to hit till v0.24.0
.
This also raises another question I have about supplying an href or href template for each page, I can see some value in being able to do so. This implementation is assuming a purely single page app approach.
|
||
propTypes: { | ||
activePage: React.PropTypes.number, | ||
items: React.PropTypes.number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for this to be an array of links?
Or possibly include a prop for hrefTemplate
were the page number can be inserted. Thus allowing this to work with non-SPA sites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking something like:
React.PropTypes.oneOfType([
React.PropTypes.number,
React.PropTypes.arrayOf(React.PropTypes.string)
]);
I created #788 to so we don't forget to do the SafeAnchor change for the v0.24 release in this component. |
); | ||
let pageButtons = ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'li'); | ||
assert.equal(pageButtons.length, 5); | ||
assert.equal(pageButtons[2].getDOMNode().getAttribute('class').match(/active/)[0], 'active'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React.findDOMNode
is more future proof than getDOMNode()
We still have a number of tests using it but if we can use the newer function that would help us out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this assertion is cleaner with React.findDOMNode(pageButtons[2]).className.should.match(/\bactive\b/)
The \b
in the regex is a word boundary marker so if we need to add more classes in the future this assertion would still pass.
In this case you are just correcting the code you are proposing, so you don't need it. I know it is all very confusing at the beginning 🍒 |
Oh I see, should I rebase the commit? |
You can do |
Anyway you will have to remove this |
Ok I removed it. A lot of things to learn. |
No worries.
Open Source - it means we all always will learn 🌈 😄 |
if(this.props.onSelect){ | ||
this.props.onSelect(event, selectedEvent); | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are not doing anything in here why not just pass this.props.onSelect
right on through to the PaginationButton without this intermediary? You are already doing the conditional check for presence within the PaginationButton
.
Is it good to squash all my commits now? |
<p>Provide pagination links for your site or app with the multi-page pagination component.</p> | ||
<ReactPlayground codeText={Samples.PaginationBasic} /> | ||
|
||
<p>More controller such as first, last, previous, next and ellipsis.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controller => controllers ? or handlers ? or buttons ?
@mtscout6 What would you suggest ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say options
Before Such these:
|
If you can just add that test assertion for the ellipse and the wording in the docs then go ahead and squash. The concern I brought up with items and anchor hrefs can follow up in a different PR if someone needs it. |
Ok, I added test assert for the ellipse, and fixed some wording in the docs. Please have a look of last commit. |
Rewrote this lines let hiddenPagesBefore = activePage - parseInt(maxButtons / 2);
startPage = hiddenPagesBefore > 1 ? hiddenPagesBefore : 1;
hasHiddenPagesAfter = startPage + maxButtons <= items; Also have some changes in wording of document <p>Provide pagination links for your site or app with the multi-page pagination component. Set <code>items</code> to the number of pages. <code>activePage</code> prop dictates which page is active</p>
<ReactPlayground codeText={Samples.PaginationBasic} />
<p>More options such as <code>first</code>, <code>last</code>, <code>previous</code>, <code>next</code> and <code>ellipsis</code>.</p>
<ReactPlayground codeText={Samples.PaginationAdvanced} /> |
LGTM Need one more approval from one of the @react-bootstrap/collaborators |
Address this:
And this: And we commit 👍 |
@roadmanfong nevemind 😃 , I'll make them myself. You've done a great job 👍 |
@roadmanfong I agree, huge thanks for putting the effort into this! |
@roadmanfong additional PRs are welcome 😉 🌈 |
Agreed, we are always on the lookout for collaborators. Anything on the 1.0.0 roadmap that you'd like to tackle is fair game. |
key='next' | ||
eventKey={this.props.activePage + 1} | ||
disabled={this.props.activePage === this.props.items} | ||
onSelect={this.props.onSelect}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, when button is disabled it is still possible to click on it and OnSelect is handled
#1102
Bumps [tar](https://github.com/npm/node-tar) from 6.1.0 to 6.1.5. - [Release notes](https://github.com/npm/node-tar/releases) - [Changelog](https://github.com/npm/node-tar/blob/main/CHANGELOG.md) - [Commits](isaacs/node-tar@v6.1.0...v6.1.5) --- updated-dependencies: - dependency-name: tar dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
I tried to make pagination component, and I'm not sure what should I put in unit test.
Closes #22