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

Display contents lists under specific conditions #719

Merged
merged 14 commits into from
Feb 7, 2018

Conversation

emmabeynon
Copy link
Contributor

@emmabeynon emmabeynon commented Jan 23, 2018

For https://trello.com/c/2UIR4Sen/210-investigate-how-to-deal-with-short-content-lists

We have identified that there are occasions where it's not appropriate to display a contents list, for example when there is only one item on the list. Having spiked an approach for displaying a contents list dependent on certain conditions, this PR implements the approach. We've reached the below criteria for displaying a contents list in conjunction with Si Stephens-Manassiev in the content team:

  1. We won't show a contents list that has one item.
  2. We will show a contents list with 2 items if the first item's character count is over 415.
  3. We will show a contents list with 2 items if the first item contains a table with more than 13 rows.
  4. We will show a contents list with 2 items if the first item contains an image and character count is over 224.
  5. We will show a contents list with 2 items if the first item contains an image and a table with more than 6 rows.
  6. We will show a contents list with 3 items or more.

To Do

Component guide for this PR:
https://government-frontend-pr-719.herokuapp.com/component-guide

@tijmenb tijmenb temporarily deployed to government-frontend-pr-719 January 23, 2018 11:03 Inactive
end

def first_item_content
element = Nokogiri::HTML(body).css('p').first
Copy link
Contributor

Choose a reason for hiding this comment

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

Some questions about this part:

  • what happens if the content begins with something that's not a paragraph, eg a table or image?
  • is this relatively slow at the moment? how performant could we make it?

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 point about the paragraphs - I'll try and find some Detailed Guides examples with other content and work something out.
Steve's got a suggestion for optimising the Nokogiri stuff below 👇

@@ -3,6 +3,7 @@ module ContentsList
include ActionView::Helpers::UrlHelper
include TypographyHelper

WORD_COUNT_LIMIT = 100
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if total word count is a useful heuristic.

Copy link
Contributor

Choose a reason for hiding this comment

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

What @fofr said. Some formats will contain medical terminology with superlongtechnicalwords, some will contain more legalese. I think a char count might be a more honest metric.

@fofr
Copy link
Contributor

fofr commented Jan 23, 2018

Love this as a starting point.

Are there some example URLs showing the effect?

end

def first_item_content
element = Nokogiri::HTML(body).css('p').first
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can optimise this a bit by only parsing the body once with Nokogiri, building the contents list as the existing implementation does, but also populating the first n chapters so we can check their length.
This https://stackoverflow.com/questions/3484874/how-to-split-a-html-document-using-nokogiri does something similar by building a hash of chapters.


def long_first_item_body
"<div class='govspeak'><h2 id='response-in-the-uk'>Item 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean facilisis
Copy link
Contributor

Choose a reason for hiding this comment

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

The Faker gem is great for generating this sort of thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice one! Will keep that in mind for production tests 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

We can also use the govuk_schema gem to generate random examples to test this with

@emmabeynon
Copy link
Contributor Author

emmabeynon commented Jan 23, 2018

Are there some example URLs showing the effect?

We've got this as an example of the contents list not showing if there's only one item: https://government-frontend-pr-719.herokuapp.com/government/topical-events/ukraine-reform-conference/about
Unfortunately there aren't any live examples of Topical Event About Pages with two items - I've fudged some data locally to check it works - but I know that Detailed Guides has some, so I can extend this to the view for this format and will update the PR with an example 👍
And then I remembered that Detailed Guides hasn't been moved to universal layout yet 🤦‍♀️

<%= render "components/contents-list-with-body", {
contents: @content_item.contents
} do %>
<% if @content_item.show_content_list? %>
Copy link
Contributor

@steventux steventux Jan 23, 2018

Choose a reason for hiding this comment

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

This might be better implemented in the contents-list-with-body component as there's already a check for @content_item.contents.any? which prevents the list and the contents link from displaying in the absence of any contents.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah definitely - I've noted it's not an ideal implementation in the PR description, and would need to investigate other formats using this component before making changes to it in prod.

@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 January 23, 2018 16:42 Inactive
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 January 23, 2018 16:45 Inactive
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 January 24, 2018 09:41 Inactive
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 January 24, 2018 11:20 Inactive
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 January 24, 2018 11:38 Inactive
@emmabeynon
Copy link
Contributor Author

@fofr @steventux I've added a condition for showing a contents list when a table has a certain number of rows, and a condition for when an image is present (I imagine we could use the same idea for videos). Regarding images, I had a quick chat with Steve about this last night and we agreed that since it seems that images are always the same size, the simplest way to deal with them is to just show contents lists when they're present.

@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 January 24, 2018 14:38 Inactive
return unless table.present?

row_count = table.css('tr').count
row_count > 10
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 this PR is still quite experimental, so a reminder to use the relevant constant TABLE_ROW_LIMIT here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that'll be me messing around with row numbers and not replacing the constant 🤦‍♀️

@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 January 24, 2018 15:00 Inactive
row_count > 10
end

def find_table
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks very similar to the following method, wonder if the logic is similar enough for one method.

@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 January 24, 2018 15:17 Inactive
@boffbowsh boffbowsh had a problem deploying to government-frontend-pr-719 February 6, 2018 11:58 Failure
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 February 6, 2018 12:03 Inactive
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 February 6, 2018 12:11 Inactive
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 February 7, 2018 11:42 Inactive
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-719 February 7, 2018 11:59 Inactive
emmabeynon and others added 14 commits February 7, 2018 12:23
In order to generate lorem ipsum for longer pieces of content in tests.
We have found instances where displaying a contents list on a page isn't always
appropriate, such as when there is only one item in the list. We have decided
to not show the contents list if there are fewer than three items, with an
additional condition that we do show the contents list if the first item's
content is more than 100 characters.
We now show the contents list in cases where there are only two content items
if the first item contains a table with more than 13 rows.
We now show the contents list when there are 2 items on a contents lists and
the first item has both an image and content over 50 characters.
We now show the contents list when there are 2 items on a contents lists and
the first item has both an image and a table with more than 6 rows.
We update test coverage to reflect that contents lists are shown under certain
conditions.
We update test coverage to reflect that contents lists are shown under certain
conditions.
We update test coverage to reflect that contents lists are shown under certain
conditions.
We update test coverage to reflect that contents lists are shown under certain
conditions.
We update test coverage to reflect that contents lists are shown under certain
conditions.

We have found that Working Groups with policies don't always have a body, which
caused problems in the current code implementation when it came to checking
content length in the first item of a contents list. Therefore we now check if
a "first item" is present in the body before carrying out the content checks.
We update test coverage to reflect that contents lists are shown under certain
conditions.
We update test coverage to reflect that contents lists are shown under certain
conditions.
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.

6 participants