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

Pagination Front End - Part 1 #9937

Merged
merged 15 commits into from
Apr 5, 2022
Merged

Conversation

RetiredBlob
Copy link
Contributor

@RetiredBlob RetiredBlob commented Mar 10, 2022

Part of #9943

The 240 breakpoint design will be done in a separate PR, since this PR is already quite big


  • I have assigned myself to this PR and the corresponding issues
  • I have added the cross-team label to this PR if it requires visibility across World Service teams
  • I have assigned this PR to the Simorgh project
  • (BBC contributors only) This PR follows the repository use guidelines

Testing:

  • Automated (jest and/or cypress) tests added (for new features) or updated (for existing features)
  • If necessary, I have run the local E2E non-smoke tests relevant to my changes (CYPRESS_APP_ENV=local CYPRESS_SMOKE=false yarn test:e2e:interactive)
  • This PR requires manual testing

@RetiredBlob RetiredBlob changed the title Pagination bad Pagination Front End - Part 1 Mar 15, 2022
@RetiredBlob RetiredBlob marked this pull request as ready for review March 15, 2022 10:02
background: #696969;
`;
const UnavailableBlock = styled(Block)`
color: #bababa;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🐑

@ryanmccombe ryanmccombe added the ws-glasgow Work pertaining to the World Service Glasgow team label Mar 15, 2022
@rebeccamcginn
Copy link
Contributor

The ellipsis between 1 and 2 feels like a bug. I know it's most likely in the designs but... no number is missing!

image

@JonBeeb
Copy link
Contributor

JonBeeb commented Mar 24, 2022

Er, I would leave it as it is for now and keep the same logic is Webcore?

</EllipsisBlock>
),
};
/* eslint-enable react/prop-types */
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we have prop types. Can we remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an eslint-enable - it corresponds with the eslint-disable on line 97

Copy link
Contributor

@andrewscfc andrewscfc left a comment

Choose a reason for hiding this comment

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

Not quite finished reviewing this but just dropping what I've found so far, hope it helps!

src/app/lib/utilities/findNClosestIndicies/index.js Outdated Show resolved Hide resolved
activePage,
pageCount,
activePageOnEdge: activePage === 1 || activePage === pageCount,
};
Copy link
Contributor

@andrewscfc andrewscfc Mar 25, 2022

Choose a reason for hiding this comment

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

When I first looked at this file I was pretty unclear where state is initialised (here I eventually found). I'm unsure of the need for a global state variable in this case 🤔 Can we chain the functions so state is not mutated globally?

On this line for example we could reduce rather than map arrive at the final state value, see below for a sketch of what I might suggest

I feel it reads better and elimates the risk of errors being introduced later when working with global state.

Comment on lines 167 to 184
if (pageCount <= 1) return null;
state = {
activePage,
pageCount,
activePageOnEdge: activePage === 1 || activePage === pageCount,
};
state.result = Array(pageCount)
.fill()
.map((_, i) => createPage(i));

setRequiredVisibility();
setDynamicVisibility();
pruneInvisible();
insertEllipsis();
insertArrows();
addKeys();

return state.result;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (pageCount <= 1) return null;
state = {
activePage,
pageCount,
activePageOnEdge: activePage === 1 || activePage === pageCount,
};
state.result = Array(pageCount)
.fill()
.map((_, i) => createPage(i));
setRequiredVisibility();
setDynamicVisibility();
pruneInvisible();
insertEllipsis();
insertArrows();
addKeys();
return state.result;
if (pageCount <= 1) return null;
const intialState = {
activePage,
pageCount,
activePageOnEdge: activePage === 1 || activePage === pageCount,
};
//state is no longer global
const state = Array(pageCount)
.fill()
.reduce((currentState, i) => createPage(i, currentState), intialState);
return pipe(setRequiredVisibility, setDynamicVisibility, pruneInvisible, insertEllipsis, insertArrows, addKeys)(state).result;

Copy link
Contributor

Choose a reason for hiding this comment

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

btw, fully aware this code won't 'just work', just illustrating the general pattern

Comment on lines 160 to 163
state.result.forEach((result, i) => {
// eslint-disable-next-line no-param-reassign
result.key = i;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
state.result.forEach((result, i) => {
// eslint-disable-next-line no-param-reassign
result.key = i;
});
state.result = state.result.map((result, i) => {
return { ...result, key: i };
});

Think this will remove the need for the linting comment and make this more functional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 this is a bigger problem since moving state to being passed into each function

really don't think it's worth the added code complexity to try to make all of these helper functions pure

they're all private - the default export is pure

Copy link
Contributor

@andrewscfc andrewscfc left a comment

Choose a reason for hiding this comment

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

Think I've finished my review of this, let me know if you need any help or clarification. Happy to debate the points as well, I know some of my suggestions result in significant changes.


const ActiveBlock = styled(Block)`
color: ${C_WHITE};
background: #696969;
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's annoying but I think these colours should be added to psammead styles or we should reference existing colours? As we make chameleon changes it'll be very difficult to make global changes without doing this

Copy link
Contributor

Choose a reason for hiding this comment

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

I added this here RetiredBlob@50a2cde


const Pagination = ({ activePage, pageCount }) => {
const { service } = useContext(ServiceContext);
const clampedPageCount = clamp(1, 99, pageCount);
Copy link
Contributor

@andrewscfc andrewscfc Mar 25, 2022

Choose a reason for hiding this comment

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

You could consider maintaining the max page count in the BFF to keep this decision in one place in case we change it in the future?

Also there would be no need for the clamp logic as the BFF would only return up to 40 pages and 404 if any page higher (or lower) were requested

pageCount: 1,
};

export default Pagination;
Copy link
Contributor

Choose a reason for hiding this comment

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

This component needs some tests to show it can take varying page ranges and return suitable visual components. It's not about retesting buildBlocks as that has a lot of the complex view logic, but checking that the correct dom elements are rendered for different page ranges. It doesn't need to be as comprehensive as the buildBlocks test.

@JonBeeb
Copy link
Contributor

JonBeeb commented Mar 28, 2022

Updated UX /a11y captured in this ticket: #9984

@JonBeeb JonBeeb added this to the Pagination milestone Mar 28, 2022
text-decoration: none;
height: 100%;
width: 100%;
&:hover {

Choose a reason for hiding this comment

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

Missing focus?

if (!blocks) return null;

return (
<OL role="list">

Choose a reason for hiding this comment

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

Should 'OL' be in caps?

@ryanmccombe ryanmccombe merged commit 10db592 into bbc:latest Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ws-glasgow Work pertaining to the World Service Glasgow team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants