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

Refactor how we calculate section and link counts #1103

Merged
merged 1 commit into from
Jul 28, 2017

Conversation

carvil
Copy link
Contributor

@carvil carvil commented Jul 27, 2017

This commit moves the logic of determining how many sections and links
are on a given page to a new module, which has more granular functions
to extract all the necessary bits from a page to make a decision.

This refactoring aims at making it clearer what the steps are. Ideally,
each rendering application would set these counts in a meta tag and this
code would only read from it, but it's a bit more complicated than that,
especially for JS-driven finders.

What do you think?

This commit moves the logic of determining how many sections and links
are on a given page to a new module, which has more granular functions
to extract all the necessary bits from a page to make a decision.

This refactoring aims at making it clearer what the steps are. Ideally,
each rendering application would set these counts in a meta tag and this
code would only read from it, but it's a bit more complicated than that,
especially for JS-driven finders.
@carvil carvil requested a review from whoojemaflip July 27, 2017 16:07

PageContent.getNumberOfLinks = function () {
switch(true) {
case isNavigationGridPage():
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason for this specific order that might not be obvious to the next person to touch 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.

Good question. Before, the order was important because of document collections. They are both navigation pages and content pages, so the return statement needed a specific order. But with this switch statement, we look for navigation pages first (and they are findable in a deterministic way now since alphagov/whitehall#3358), and default to a content page at the bottom. That means we don't rely on ordering anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@whoojemaflip whoojemaflip left a comment

Choose a reason for hiding this comment

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

a massive improvement!

@carvil carvil merged commit cb9e1c4 into master Jul 28, 2017
@carvil carvil deleted the refactor-how-we-calculate-links-and-sections branch July 28, 2017 11:28
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.

2 participants