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

[added] Pagination component #786

Merged
merged 1 commit into from Jun 8, 2015
Merged

Conversation

roadmanfong
Copy link

I tried to make pagination component, and I'm not sure what should I put in unit test.

Closes #22

@roadmanfong roadmanfong mentioned this pull request Jun 4, 2015
@mtscout6
Copy link
Member

mtscout6 commented Jun 4, 2015

Thanks for putting this together.

Unit tests should ensure:

  • classNames are applied or not applied as appropriate for the various states
  • Mouse and keyboard usage (ReactTestUtils makes this feasible.)
    • ie. ensure that onSelect event is fired when you expect.
  • Html layout is as expected in the various states, this can be done in the same tests that test classNames (For example when you use the ellipsis prop the li for the ... button is added.)
  • Accessibility concerns are tested. Even if they are just static having tests to ensure they are there are good to ensure they are not accidentally removed.

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.

@mtscout6 mtscout6 added this to the 1.0.0 Release milestone Jun 4, 2015
className={pagenumber === this.props.activePage ? 'active' : null}
data-pagenumber={pagenumber}
onClick={this._onSelect}>
<a href='#' onClick={this.noClick}>{pagenumber}</a>
Copy link
Member

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,
Copy link
Member

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.

Copy link
Member

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)
]);

@mtscout6
Copy link
Member

mtscout6 commented Jun 4, 2015

Can you add a link in the side nav for Pagination, right under Pager

side-nav

@mtscout6
Copy link
Member

mtscout6 commented Jun 4, 2015

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');
Copy link
Member

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.

Copy link
Member

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.

@AlexKVal
Copy link
Member

AlexKVal commented Jun 5, 2015

[fixed] should be placed into comment's header only if you're fixing something in the existing codebase.

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 🍒
Let's it not stop you on your way ❇️
I was doing such kind of errors with all those commits by myself many times 😄

@roadmanfong
Copy link
Author

Oh I see, should I rebase the commit?

@AlexKVal
Copy link
Member

AlexKVal commented Jun 5, 2015

You can do git push -f as many times as you need 👍
Until you like the PR by yourself 😉

@AlexKVal
Copy link
Member

AlexKVal commented Jun 5, 2015

Anyway you will have to remove this [fixed] before this PR can be merged,
because this project uses automatic changelog generation from these [_tag_] tags in commit headers.
By this package https://github.com/mtscout6/mt-changelog

@roadmanfong
Copy link
Author

Ok I removed it.

A lot of things to learn.
Thank you for your patience. 😃

@AlexKVal
Copy link
Member

AlexKVal commented Jun 5, 2015

No worries.
It is thank you for contributing ! 🍒

A lot of things to learn.

Open Source - it means we all always will learn 🌈 😄

if(this.props.onSelect){
this.props.onSelect(event, selectedEvent);
}
},
Copy link
Member

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.

@roadmanfong
Copy link
Author

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>
Copy link
Member

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say options

@AlexKVal
Copy link
Member

AlexKVal commented Jun 6, 2015

Before git push run linter check by npm run lint.
There should be no any warnings. ❇️

Such these:

src/PaginationButton.js
  15:19  warning  'onSelect' is missing in props validation for PaginationButton  react/prop-types
  16:57  warning  'eventKey' is missing in props validation for PaginationButton  react/prop-types
  17:17  warning  'onSelect' is missing in props validation for PaginationButton  react/prop-types

@mtscout6
Copy link
Member

mtscout6 commented Jun 6, 2015

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.

@roadmanfong
Copy link
Author

Ok, I added test assert for the ellipse, and fixed some wording in the docs. Please have a look of last commit.

@roadmanfong
Copy link
Author

active and disabled now are props of PaginationButton.

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} />

@mtscout6
Copy link
Member

mtscout6 commented Jun 8, 2015

LGTM

Need one more approval from one of the @react-bootstrap/collaborators

@AlexKVal
Copy link
Member

AlexKVal commented Jun 8, 2015

Address this:

$ npm run lint
src/Pagination.js
  37:28  warning  hasHiddenPagesBefore is defined but never used  no-unused-vars

And this:
className={classNames(this.props.className, this.getBsClassSet())}> here

And we commit 👍

@AlexKVal
Copy link
Member

AlexKVal commented Jun 8, 2015

@roadmanfong nevemind 😃 , I'll make them myself.

You've done a great job 👍
Thank you 🍒

AlexKVal added a commit that referenced this pull request Jun 8, 2015
[added] Pagination component
@AlexKVal AlexKVal merged commit 1fce364 into react-bootstrap:master Jun 8, 2015
@mtscout6
Copy link
Member

mtscout6 commented Jun 8, 2015

@roadmanfong I agree, huge thanks for putting the effort into this!

@AlexKVal AlexKVal mentioned this pull request Jun 8, 2015
mtscout6 added a commit that referenced this pull request Jun 9, 2015
Using the `SafeAnchor` for better accessibility.

Per #786 commitcomment-11527424
Resolves #788
@roadmanfong
Copy link
Author

@AlexKVal @mtscout6 Thank you guys. It's a great experience to join this project.

@AlexKVal
Copy link
Member

AlexKVal commented Jun 9, 2015

@roadmanfong additional PRs are welcome 😉 🌈

@mtscout6
Copy link
Member

mtscout6 commented Jun 9, 2015

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}>

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

aryad14 pushed a commit to aryad14/react-bootstrap that referenced this pull request Oct 11, 2023
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants