Browse Source

Refactor stock owner / managing agent list partials into one shared partial

pull/2274/head
Rachael Booth 2 years ago
parent
commit
f8c0448908
  1. 36
      app/views/organisation_relationships/_managing_agent_list.erb
  2. 12
      app/views/organisation_relationships/_related_org_list.erb
  3. 11
      app/views/organisation_relationships/managing_agents.html.erb
  4. 11
      app/views/organisation_relationships/stock_owners.html.erb

36
app/views/organisation_relationships/_managing_agent_list.erb

@ -1,36 +0,0 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= 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 %>
</section>

12
app/views/organisation_relationships/_stock_owner_list.erb → app/views/organisation_relationships/_related_org_list.erb

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> <section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %> <%= govuk_table do |table| %>
<%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <%= 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 %> <% end %>
<%= table.with_head do |head| %> <%= table.with_head do |head| %>
<%= head.with_row do |row| %> <%= head.with_row do |row| %>
@ -13,20 +13,20 @@
<% end %> <% end %>
<% end %> <% end %>
<%= table.with_body do |body| %> <%= table.with_body do |body| %>
<% @stock_owners.each do |stock_owner| %> <% related_orgs.each do |org| %>
<%= body.with_row do |row| %> <%= body.with_row do |row| %>
<% if current_user.support? %> <% 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 %> <% else %>
<% row.with_cell(text: stock_owner.name) %> <% row.with_cell(text: org.name) %>
<% end %> <% end %>
<% row.with_cell(text: "ORG#{stock_owner.id}") %> <% row.with_cell(text: "ORG#{org.id}") %>
<% if current_user.data_coordinator? || current_user.support? %> <% if current_user.data_coordinator? || current_user.support? %>
<% row.with_cell(html_attributes: { <% row.with_cell(html_attributes: {
scope: "row", scope: "row",
class: "govuk-!-text-align-right", class: "govuk-!-text-align-right",
}) do %> }) 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 %> <% end %>
<% end %> <% end %>

11
app/views/organisation_relationships/managing_agents.html.erb

@ -22,6 +22,15 @@
<% end %> <% end %>
<% if @total_count != 0 %> <% if @total_count != 0 %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a managing agent", value: @searched) %> <%= 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" } %> <%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "managing agents" } %>
<% end %> <% end %>

11
app/views/organisation_relationships/stock_owners.html.erb

@ -19,6 +19,15 @@
<% end %> <% end %>
<% if @total_count != 0 %> <% if @total_count != 0 %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a stock owner", value: @searched) %> <%= 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" } %> <%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "stock owners" } %>
<% end %> <% end %>

Loading…
Cancel
Save