From 3d0584a7f2340aace76b386fa3612ebe5f8ec46e Mon Sep 17 00:00:00 2001 From: Benjamin Eskola Date: Fri, 21 Aug 2026 15:01:12 +0100 Subject: [PATCH 1/3] Enable sidebar for enforcements --- app/components/sidebar_component.rb | 60 ++++++++++--------- app/views/layouts/application.html.erb | 2 +- .../bops_enforcements/tasks_controller.rb | 1 + .../check_report_details_spec.rb | 4 +- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/app/components/sidebar_component.rb b/app/components/sidebar_component.rb index 5bc1ef25ec..eb8f5a1329 100644 --- a/app/components/sidebar_component.rb +++ b/app/components/sidebar_component.rb @@ -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) @@ -46,30 +46,32 @@ 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"), - "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"), - "Assessment" - ]), - assessment_task.url, - class: "bops-sidebar__link" - ) - - elements << helpers.tag.hr(class: "govuk-!-margin-bottom-4") + if planning_application&.pre_application? + if section.section == "Assessment" + elements << helpers.govuk_link_to( + helpers.safe_join([ + helpers.render("shared/icons/envelope", class: "bops-sidebar__task-icon"), + "Consultation" + ]), + consultation_task.url, + class: "bops-sidebar__link" + ) + + elements << helpers.tag.hr(class: "govuk-!-margin-bottom-4") + + elsif section.section == "Consultation" + + elements << helpers.govuk_link_to( + helpers.safe_join([ + helpers.render("shared/icons/envelope", class: "bops-sidebar__task-icon"), + "Assessment" + ]), + assessment_task.url, + class: "bops-sidebar__link" + ) + + elements << helpers.tag.hr(class: "govuk-!-margin-bottom-4") + end end toggle_data = if top_level @@ -91,7 +93,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", @@ -125,6 +127,8 @@ 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 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e223f5d092..29e5010fae 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -64,7 +64,7 @@
<% if @show_sidebar %> - <%= render SidebarComponent.new(params:, task: @show_sidebar) %> + <%= render SidebarComponent.new(params:, case_record: @case_record, task: @show_sidebar) %> <% end %>
Date: Fri, 21 Aug 2026 15:25:33 +0100 Subject: [PATCH 2/3] Remove some duplication --- app/components/sidebar_component.rb | 32 ++++++++++------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/app/components/sidebar_component.rb b/app/components/sidebar_component.rb index eb8f5a1329..420c966f55 100644 --- a/app/components/sidebar_component.rb +++ b/app/components/sidebar_component.rb @@ -47,26 +47,20 @@ def render_section(section, top_level: true) elements = [] if planning_application&.pre_application? - if section.section == "Assessment" - elements << helpers.govuk_link_to( - helpers.safe_join([ - helpers.render("shared/icons/envelope", class: "bops-sidebar__task-icon"), - "Consultation" - ]), - consultation_task.url, - class: "bops-sidebar__link" - ) - - elements << helpers.tag.hr(class: "govuk-!-margin-bottom-4") - - elsif section.section == "Consultation" + if section.section == "Assessment" || section.section == "Consultation" + other_link = case section.section + when "Assessment" + "Consultation" + when "Consultation" + "Assessment" + end elements << helpers.govuk_link_to( helpers.safe_join([ helpers.render("shared/icons/envelope", class: "bops-sidebar__task-icon"), - "Assessment" + other_link ]), - assessment_task.url, + section_task(other_link).url, class: "bops-sidebar__link" ) @@ -148,11 +142,7 @@ def current_task?(task) 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 From 3cb17f0f4819e2e5ac76f102a5e844ba2c77491a Mon Sep 17 00:00:00 2001 From: Benjamin Eskola Date: Mon, 24 Aug 2026 17:34:18 +0100 Subject: [PATCH 3/3] Avoid using empty span just to fix alignment issue Instead of adding an empty span here, the spacing can be corrected by detecting whether there's another element present. This makes some of the logic simpler: just don't create an icon for hidden tasks. This also simplifies some code further by using the `class_names` helper. --- app/assets/stylesheets/sidebar.scss | 5 +++++ app/components/sidebar_component.rb | 20 +++++++------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/assets/stylesheets/sidebar.scss b/app/assets/stylesheets/sidebar.scss index c58f8c6a96..beb49994a3 100644 --- a/app/assets/stylesheets/sidebar.scss +++ b/app/assets/stylesheets/sidebar.scss @@ -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; } diff --git a/app/components/sidebar_component.rb b/app/components/sidebar_component.rb index 420c966f55..66104cfca3 100644 --- a/app/components/sidebar_component.rb +++ b/app/components/sidebar_component.rb @@ -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 @@ -127,14 +123,12 @@ def planning_application 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?