Skip to content

Commit

Permalink
Merge pull request #900 from alphagov/secondary-to-step-by-steps
Browse files Browse the repository at this point in the history
Add the closed step by step for secondary content
  • Loading branch information
DilwoarH authored Jun 20, 2019
2 parents 3235e77 + 5b1dbf8 commit 4a608d0
Show file tree
Hide file tree
Showing 6 changed files with 860 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
useful summary for people upgrading their application, not a replication
of the commit log.

## Unreleased

* Adds support for secondary content items for step by step (PR #900)
* Adds missing tests for related to step navs (PR #900)
* Adds missing tests for also part of step navs component (PR #900)

## 17.3.0

* Set the expiry of consent cookie to 1 year (PR #940)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,41 @@ examples:
Expand the step by step in the querystring
Show a list of the other step by steps (including other step by steps that have been marked as "hidden") under an "Also part of" heading, if the content item is part of less than 5 step by step journeys
Changes to the rules when there is a secondary step by step linked:
1. Content item is part of one step by step
No change. Expand the step by step in the sidebar.
2. Content item is part of multiple step by steps and no secondary step by step
No change. Will show a list of primary step by steps under the "Part of" heading. Secondary step by steps will not be shown.
3. User is on a step by step journey (the query string is in the url)
No change. Active step by step will be expanded.
4. Content item is part of multiple primary step by steps and a single secondary step by step
No change. Show "Part of" step by steps list. Secondary step by step won't be shown.
5. Content item is part of multiple step by steps and multiple secondary step by steps
No change. Show "Part of" step by step list. Secondary step by step won't be shown.
6. Step by step is marked as "hidden" for the content page
No change. "Also part of" component will only show when an active step by step is shown.
7. Content item is part of one secondary step by step and no other step by steps are linked.
Show secondary step by step expanded.
8. Content item is part of multiple secondary step by steps and no other step by steps are linked.
Show secondary step by step list in "Part of" component.
data:
tracking_id: "this-is-the-content-id"
steps: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,47 @@ def related_to_step_navs
end
end

def secondary_step_by_steps
@secondary_step_by_steps ||= parsed_secondary_to_step_navs.map do |step_nav|
StepByStepModel.new(step_nav)
end
end

def show_sidebar?
show_header? && current_step_nav.steps.present?
end

def show_header?
step_navs.count == 1 || active_step_by_step?
step_navs.count == 1 || active_step_by_step? || show_secondary_step_by_step?
end

def show_related_links?
return true if active_step_by_step?

step_navs.any? && step_navs.count < 5
if active_step_by_step?
true
elsif step_navs.any? && step_navs.count < 5
true
elsif show_related_links_for_secondary_step_by_steps?
true
else
false
end
end

def show_also_part_of_step_nav?
active_step_by_step? && also_part_of_step_nav.any? && step_navs_combined_list.count < 5
end

def related_links
step_by_step_navs = active_step_by_step? ? [active_step_by_step] : step_navs
step_by_step_navs = if active_step_by_step?
[active_step_by_step]
elsif step_navs.any?
step_navs
elsif show_related_links_for_secondary_step_by_steps?
secondary_step_by_steps
else
[]
end

format_related_links(step_by_step_navs)
end

Expand Down Expand Up @@ -71,6 +92,10 @@ def header
end
end

def primary_step_by_steps?
step_navs_combined_list.any?
end

def active_step_by_step?
active_step_nav_content_id.present? && active_step_by_step.present?
end
Expand All @@ -81,14 +106,34 @@ def active_step_by_step
@active_step_navs.first
end

def secondary_step_by_step?
secondary_step_by_steps.any?
end

def secondary_step_by_step
secondary_step_by_steps.first
end

def show_secondary_step_by_step?
!primary_step_by_steps? && secondary_step_by_step? && secondary_step_by_steps.count === 1
end

def show_related_links_for_secondary_step_by_steps?
!primary_step_by_steps? && secondary_step_by_step? && secondary_step_by_steps.count < 5
end

private

attr_reader :content_item, :current_path

def current_step_nav
return active_step_by_step if active_step_by_step?

step_navs.first
if active_step_by_step?
active_step_by_step
elsif primary_step_by_steps?
step_navs.first
elsif show_secondary_step_by_step?
secondary_step_by_step
end
end

def active_step_nav_content_id
Expand All @@ -114,6 +159,10 @@ def parsed_related_to_step_navs
content_item.dig("links", "related_to_step_navs").to_a
end

def parsed_secondary_to_step_navs
content_item.dig("links", "secondary_to_step_navs").to_a
end

def configure_for_sidebar(step_nav_content)
step_nav_content[:steps].each_with_index do |step, step_index|
step[:contents].each do |content|
Expand Down
3 changes: 2 additions & 1 deletion spec/components/contextual_footer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ def component_name

it 'renders the footer' do
content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: 'speech') do |payload|
# If this item is a part of a step nav this component might not render
# If this item is a part of a step nav or secondary step nav this component might not render
payload["links"].delete("part_of_step_navs")
payload["links"].delete("secondary_to_step_navs")
payload
end

Expand Down
Loading

0 comments on commit 4a608d0

Please sign in to comment.