From f8c0448908b7f940d44808ccdb9554a1b68edf04 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Thu, 29 Feb 2024 10:12:05 +0000 Subject: [PATCH] Refactor stock owner / managing agent list partials into one shared partial --- .../_managing_agent_list.erb | 36 ------------------- ...k_owner_list.erb => _related_org_list.erb} | 12 +++---- .../managing_agents.html.erb | 11 +++++- .../stock_owners.html.erb | 11 +++++- 4 files changed, 26 insertions(+), 44 deletions(-) delete mode 100644 app/views/organisation_relationships/_managing_agent_list.erb rename app/views/organisation_relationships/{_stock_owner_list.erb => _related_org_list.erb} (70%) diff --git a/app/views/organisation_relationships/_managing_agent_list.erb b/app/views/organisation_relationships/_managing_agent_list.erb deleted file mode 100644 index acf8e027e..000000000 --- a/app/views/organisation_relationships/_managing_agent_list.erb +++ /dev/null @@ -1,36 +0,0 @@ -
- <%= govuk_table do |table| %> - <%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> - <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "agents", filters_count: 0)) %> - <% end %> - <%= table.with_head do |head| %> - <%= head.with_row do |row| %> - <% row.with_cell(header: true, text: "Organisation name", html_attributes: { scope: "col", class: "govuk-!-width-one-half" }) %> - <% row.with_cell(header: true, text: "Organisation ID", html_attributes: { scope: "col", class: "govuk-!-width-one-half" }) %> - <% if current_user.data_coordinator? || current_user.support? %> - <% row.with_cell %> - <% end %> - <% end %> - <% end %> - <%= table.with_body do |body| %> - <% @managing_agents.each do |managing_agent| %> - <%= body.with_row do |row| %> - <% if current_user.support? %> - <% row.with_cell(text: simple_format(govuk_link_to(managing_agent.name, organisation_path(managing_agent)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> - <% else %> - <% row.with_cell(text: managing_agent.name) %> - <% end %> - <% row.with_cell(text: "ORG#{managing_agent.id}") %> - <% if current_user.data_coordinator? || current_user.support? %> - <% row.with_cell(html_attributes: { - scope: "row", - class: "govuk-!-text-align-right", - }) do %> - <%= govuk_link_to("Remove", managing_agents_remove_organisation_path(target_organisation_id: managing_agent.id)) %> - <% end %> - <% end %> - <% end %> - <% end %> - <% end %> - <% end %> -
diff --git a/app/views/organisation_relationships/_stock_owner_list.erb b/app/views/organisation_relationships/_related_org_list.erb similarity index 70% rename from app/views/organisation_relationships/_stock_owner_list.erb rename to app/views/organisation_relationships/_related_org_list.erb index 8b2802e08..e4c32f23f 100644 --- a/app/views/organisation_relationships/_stock_owner_list.erb +++ b/app/views/organisation_relationships/_related_org_list.erb @@ -1,7 +1,7 @@
<%= govuk_table do |table| %> <%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> - <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "stock owners", filters_count: 0)) %> + <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: search_item, filters_count: 0)) %> <% end %> <%= table.with_head do |head| %> <%= head.with_row do |row| %> @@ -13,20 +13,20 @@ <% end %> <% end %> <%= table.with_body do |body| %> - <% @stock_owners.each do |stock_owner| %> + <% related_orgs.each do |org| %> <%= body.with_row do |row| %> <% if current_user.support? %> - <% row.with_cell(text: simple_format(govuk_link_to(stock_owner.name, organisation_path(stock_owner)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> + <% row.with_cell(text: simple_format(govuk_link_to(org.name, organisation_path(org)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% else %> - <% row.with_cell(text: stock_owner.name) %> + <% row.with_cell(text: org.name) %> <% end %> - <% row.with_cell(text: "ORG#{stock_owner.id}") %> + <% row.with_cell(text: "ORG#{org.id}") %> <% if current_user.data_coordinator? || current_user.support? %> <% row.with_cell(html_attributes: { scope: "row", class: "govuk-!-text-align-right", }) do %> - <%= govuk_link_to("Remove", stock_owners_remove_organisation_path(target_organisation_id: stock_owner.id)) %> + <%= govuk_link_to("Remove", remove_path.call(org.id)) %> <% end %> <% end %> <% end %> diff --git a/app/views/organisation_relationships/managing_agents.html.erb b/app/views/organisation_relationships/managing_agents.html.erb index 09d326b8b..6c6cf4fe7 100644 --- a/app/views/organisation_relationships/managing_agents.html.erb +++ b/app/views/organisation_relationships/managing_agents.html.erb @@ -22,6 +22,15 @@ <% end %> <% if @total_count != 0 %> <%= render SearchComponent.new(current_user:, search_label: "Search for a managing agent", value: @searched) %> - <%= render partial: "organisation_relationships/managing_agent_list", locals: { index: @managing_agents, title: "Managing agents", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> + <%= render partial: "organisation_relationships/related_org_list", locals: { + related_orgs: @managing_agents, + title: "Managing agents", + pagy: @pagy, + searched: @searched, + item_label:, + search_item: "agents", + total_count: @total_count, + remove_path: ->(org_id) { managing_agents_remove_organisation_path(target_organisation_id: org_id) } + } %> <%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "managing agents" } %> <% end %> diff --git a/app/views/organisation_relationships/stock_owners.html.erb b/app/views/organisation_relationships/stock_owners.html.erb index 8149a261c..18d2e9b65 100644 --- a/app/views/organisation_relationships/stock_owners.html.erb +++ b/app/views/organisation_relationships/stock_owners.html.erb @@ -19,6 +19,15 @@ <% end %> <% if @total_count != 0 %> <%= render SearchComponent.new(current_user:, search_label: "Search for a stock owner", value: @searched) %> - <%= render partial: "organisation_relationships/stock_owner_list", locals: { index: @stock_owners, title: "Stock owners", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> + <%= render partial: "organisation_relationships/related_org_list", locals: { + related_orgs: @stock_owners, + title: "Stock owners", + pagy: @pagy, + searched: @searched, + item_label:, + search_item: "stock owners", + total_count: @total_count, + remove_path: ->(org_id) { stock_owners_remove_organisation_path(target_organisation_id: org_id) } + } %> <%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "stock owners" } %> <% end %>