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

feat: implement pagination #321

Merged
merged 11 commits into from
Oct 27, 2018
Merged

Conversation

AlejandroYanes
Copy link
Collaborator

fixes #316

@codeclimate
Copy link

codeclimate bot commented Oct 21, 2018

Code Climate has analyzed commit f9e9eab and detected 4 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 4

View more on Code Climate.


return (
<div className={getContainerClassNames()} style={style}>
<ButtonIcon
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

onClick={() => onChange(activePage - 1)}
disabled={isFirstItemSelected} />
<PageButtons onChange={onChange} pages={pages} activePage={activePage} />
<ButtonIcon
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

);
}

PageButtons.propTypes = {
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

@@ -0,0 +1,8 @@
export default function getFirstItem(pages, activePage) {
if (activePage < 3) {
return activePage - (activePage - 1);

Choose a reason for hiding this comment

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

here you can return 1 since all posibilities are 1


const renderButtons = () => {
const firstItem = getFirstItem(pages, activePage);
return new Array(5).fill(0).map((item, index) => (

Choose a reason for hiding this comment

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

you don't need to use new, it's better to use Array(5) without new keyword

key={`page-button-${firstItem + index}`}
label={firstItem + index}
className={getButtonClassName(firstItem + index)}
onClick={() => onChange(firstItem + index)} />

Choose a reason for hiding this comment

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

onClick={(event) => onChange(event, firstItem + index)}

variant="border-filled"
className="rainbow-pagination_button rainbow-pagination_button-icon"
icon={<LeftArrow />}
onClick={() => onChange(activePage - 1)}

Choose a reason for hiding this comment

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

here pass the event too and the same above

Copy link
Collaborator

Choose a reason for hiding this comment

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

I will say that the we should use a hidden input inside then we change the value on the input in order to trigger the input change event

Copy link
Collaborator

@reiniergs reiniergs left a comment

Choose a reason for hiding this comment

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

use hidden input inside since this component implement inputable interface

@nexxtway nexxtway deleted a comment from reiniergs Oct 26, 2018

const getClassName = () => classnames(
'rainbow-pagination_navigation-button',
{ 'rainbow-pagination_navigation-button--disabled': disabled },

Choose a reason for hiding this comment

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

const getClassName = () => classnames('rainbow-pagination_navigation-button', {
    'rainbow-pagination_navigation-button--disabled': disabled,
});

const getButtonClassName = (firstItem, index, buttonsToRender) => (
classnames(
'rainbow-pagination_button',
{

Choose a reason for hiding this comment

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

same ^^:

classnames('rainbow-pagination_button', {
    'rainbow-pagination_button--first': index === 0,
    'rainbow-pagination_button--last': index === buttonsToRender - 1,
    'rainbow-pagination_button--active': activePage === firstItem + index,
};

and if this function does't depend on any prop then move outside the component above

return Array(buttonsToRender).fill(0).map((item, index) => {
const page = firstItem + index;
return (
<li key={`page-button-${page}`} className={getButtonClassName(firstItem, index, buttonsToRender)}>

Choose a reason for hiding this comment

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

put this in a const
const key = `page-button-${page}`;

return Array(buttonsToRender).fill(0).map((item, index) => {
const page = firstItem + index;
return (
<li key={`page-button-${page}`} className={getButtonClassName(firstItem, index, buttonsToRender)}>

Choose a reason for hiding this comment

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

since inside getButtonClassName you use firstItem + index then pass the constant page directly here

<a
onClick={event => onChange(event, page)}
aria-current={getAriaCurrent(page)}
aria-label={`Goto Page ${page}`}

Choose a reason for hiding this comment

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

same ^^ put in a variable

<GlobalHeader src="images/user/user3.jpg" />
<div className="rainbow-p-around_x-large rainbow-p-around_x-large">
<Pagination className="rainbow-m_auto" pages={7} activePage={activePage} onChange={this.handleOnChange} />
</div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to add the examples that are in the zeplin

}
}

.rainbow-pagination_button--first {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why you need add this classNames. You can use a pseudo-clase for example
the first element
.rainbow-pagination_button:nth-of-type(1)
the last element
.rainbow-pagination_button:nth-last-of-type(1)

width: 100%;

svg {
width: 7px !important;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why you use !important


@extend .center-items;

a {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why you put styles to the a element, this is a bad practice instead add a className to this element

height: 100%;
text-decoration: none;
font-weight: bold;
font-size: $font-size-text-large;
Copy link
Collaborator

Choose a reason for hiding this comment

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

font-size: $font-size-text-large it is the style of the font when is active, in the normal state it is font-size: $font-size-text-medium

className={getButtonClassName(page, activePage, index, buttonsToRender)}>
<a
onClick={event => onChange(event, page)}
aria-current={getAriaCurrent(page)}

Choose a reason for hiding this comment

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

here you forgot to pass activePage

@LeandroTorresSicilia LeandroTorresSicilia merged commit 8f75f7d into master Oct 27, 2018
@TahimiLeonBravo TahimiLeonBravo deleted the implement-pagination branch September 23, 2019 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: implement pagination component
4 participants