Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/assets/stylesheets/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ body:has(.bops-fullwidth-container) {
text-decoration: none;
}

.bops-sidebar__task a:first-child {
// Where there is no preceding task-icon
margin-left: 34px;
}

li + .bops-sidebar__heading {
margin-top: 30px;
}
78 changes: 33 additions & 45 deletions app/components/sidebar_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ class SidebarComponent < ViewComponent::Base
include Rails.application.routes.url_helpers
include Rails.application.routes.mounted_helpers

def initialize(params: {}, task: nil)
def initialize(params: {}, case_record: nil, task: nil)
@params = params
@case_record = case_record
@task = task
end

private

attr_reader :params
delegate :case_record, to: :planning_application
attr_reader :params, :case_record

def tasks
if @task.blank? || (TrueClass === @task)
Expand All @@ -27,16 +27,12 @@ def render_task(task, top_level: true)
render_section(task, top_level:)
else
is_active = current_task?(task)
link_options = is_active ? {"aria-current" => "page"} : {}
link_options = is_active ? {"aria-current": "page"} : {}
link = helpers.govuk_link_to(task.name, task.url, **link_options)
content = if task.status_hidden?
safe_join([invisible_status_placeholder, link], " ")
else
safe_join([status_indicator_for(task), link], " ")
end
li_classes = ["bops-sidebar__task"]
li_classes << "bops-sidebar__task--active" if is_active
helpers.tag.li(content, class: li_classes.join(" "))
content = safe_join([status_indicator_for(task), link], " ")
li_classes = class_names("bops-sidebar__task", {"bops-sidebar__task--active": is_active})

helpers.tag.li(content, class: li_classes)
end
end

Expand All @@ -46,30 +42,26 @@ def render_section(section, top_level: true)

elements = []

if planning_application.pre_application? && section.section == "Assessment"
elements << helpers.govuk_link_to(
helpers.safe_join([
helpers.render("shared/icons/envelope", class: "bops-sidebar__task-icon"),
if planning_application&.pre_application?
if section.section == "Assessment" || section.section == "Consultation"
other_link = case section.section
when "Assessment"
"Consultation"
]),
consultation_task.url,
class: "bops-sidebar__link"
)

elements << helpers.tag.hr(class: "govuk-!-margin-bottom-4")

elsif planning_application.pre_application? && section.section == "Consultation"

elements << helpers.govuk_link_to(
helpers.safe_join([
helpers.render("shared/icons/envelope", class: "bops-sidebar__task-icon"),
when "Consultation"
"Assessment"
]),
assessment_task.url,
class: "bops-sidebar__link"
)

elements << helpers.tag.hr(class: "govuk-!-margin-bottom-4")
end

elements << helpers.govuk_link_to(
helpers.safe_join([
helpers.render("shared/icons/envelope", class: "bops-sidebar__task-icon"),
other_link
]),
section_task(other_link).url,
class: "bops-sidebar__link"
)

elements << helpers.tag.hr(class: "govuk-!-margin-bottom-4")
end
end

toggle_data = if top_level
Expand All @@ -91,7 +83,7 @@ def render_section(section, top_level: true)
helpers.tag.li(class: "bops-sidebar__heading") { heading }
end

if planning_application.pre_application? && section.section == "Assessment"
if planning_application&.pre_application? && section.section == "Assessment"
elements << helpers.tag.div(
helpers.govuk_link_to(
"Preview report",
Expand Down Expand Up @@ -125,30 +117,26 @@ def planning_application_reference
end

def planning_application
return unless case_record&.caseable_type == "PlanningApplication"

@planning_application ||= local_authority.planning_applications.find_by!(reference: planning_application_reference)
end

def status_indicator_for(task)
return if task.status_hidden?

icon_markup = helpers.render("shared/icons/#{task.status}")
helpers.content_tag(:span, icon_markup, class: "bops-sidebar__task-icon", aria: {hidden: true})
end

def invisible_status_placeholder
helpers.content_tag(:span, "", class: "bops-sidebar__task-icon", aria: {hidden: true})
end

def current_task?(task)
current_slug = params[:slug]
return false if current_slug.blank?

task.full_slug == current_slug
end

def consultation_task
@planning_application.case_record.tasks.find_by(section: "Consultation")&.first_child
end

def assessment_task
@planning_application.case_record.tasks.find_by(section: "Assessment")&.first_child
def section_task(section)
@planning_application.case_record.tasks.find_by(section:)&.first_child
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<div class="<% if @show_sidebar %> bops-fullwidth-container <% else %> govuk-width-container app-width-container--wide <% end %>">
<% if @show_sidebar %>
<%= render SidebarComponent.new(params:, task: @show_sidebar) %>
<%= render SidebarComponent.new(params:, case_record: @case_record, task: @show_sidebar) %>
<% end %>

<main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class TasksController < ApplicationController
before_action :set_enforcement
before_action :build_form, only: %i[edit update]
before_action :ensure_case_is_not_closed, only: %i[show edit update]
before_action :show_sidebar, only: :show

def show
super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

context "when checking report" do
before do
click_link "Check report details"
within "main" do
click_link "Check report details"
end
end

it "shows the relevant report details" do
Expand Down