From cc1744ebe686c406f64d2ab349e4926ff53edb05 Mon Sep 17 00:00:00 2001 From: Stephen Hulme Date: Fri, 27 Sep 2024 15:10:35 +0100 Subject: [PATCH 1/3] fix: filter for any relatives that might not have a purpose Not just when there is a single relative without a purpose --- app/views/labware/_relatives_list.html.erb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/views/labware/_relatives_list.html.erb b/app/views/labware/_relatives_list.html.erb index dadcd9544..429b80b8a 100644 --- a/app/views/labware/_relatives_list.html.erb +++ b/app/views/labware/_relatives_list.html.erb @@ -1,14 +1,18 @@ <%# locals: (presenter:) %> +<% + found_parents = presenter.labware.parents&.filter{ |parent| parent.purpose.present? } + found_children = presenter.labware.children&.filter{ |child| child.purpose.present? } +%>
Parents - <%= content_tag :span, presenter.labware.parents.size, class: "badge badge-pill badge-secondary" if presenter.labware.parents&.any? %> + <%= content_tag :span, found_parents.size, class: "badge badge-pill badge-secondary" %>
- <% if presenter.labware.parents&.any? { |parent| parent.purpose.present? } %> - <%= render partial: 'labware/parent_labware_item', collection: presenter.labware.parents, as: :labware %> + <% if found_parents %> + <%= render partial: 'labware/parent_labware_item', collection: found_parents, as: :labware %> <% else %>
No parents found
<% end %> @@ -16,12 +20,12 @@
Children - <%= content_tag :span, presenter.labware.children.size, class: "badge badge-pill badge-secondary" if presenter.labware.children&.any? %> + <%= content_tag :span, found_children.size, class: "badge badge-pill badge-secondary" %>
- <% if presenter.labware.children&.any? { |child| child.purpose.present? } %> - <%= render partial: 'labware/child_labware_item', collection: presenter.labware.children, as: :labware, locals: { presenter: presenter, open_in_new_window: true } %> + <% if found_children %> + <%= render partial: 'labware/child_labware_item', collection: found_children, as: :labware, locals: { presenter: presenter, open_in_new_window: true } %> <% else %>
No children found
<% end %> From 028725b650e6a3a76af2e11e7af7574c67a97bdf Mon Sep 17 00:00:00 2001 From: Stephen Hulme Date: Fri, 27 Sep 2024 15:29:27 +0100 Subject: [PATCH 2/3] fix: rename found_* -> valid_* --- app/views/labware/_relatives_list.html.erb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/labware/_relatives_list.html.erb b/app/views/labware/_relatives_list.html.erb index 429b80b8a..7f035cb7f 100644 --- a/app/views/labware/_relatives_list.html.erb +++ b/app/views/labware/_relatives_list.html.erb @@ -1,18 +1,18 @@ <%# locals: (presenter:) %> <% - found_parents = presenter.labware.parents&.filter{ |parent| parent.purpose.present? } - found_children = presenter.labware.children&.filter{ |child| child.purpose.present? } + valid_parents = presenter.labware.parents&.filter{ |parent| parent.purpose.present? } + valid_children = presenter.labware.children&.filter{ |child| child.purpose.present? } %>
Parents - <%= content_tag :span, found_parents.size, class: "badge badge-pill badge-secondary" %> + <%= content_tag :span, valid_parents.size, class: "badge badge-pill badge-secondary" %>
- <% if found_parents %> - <%= render partial: 'labware/parent_labware_item', collection: found_parents, as: :labware %> + <% if valid_parents %> + <%= render partial: 'labware/parent_labware_item', collection: valid_parents, as: :labware %> <% else %>
No parents found
<% end %> @@ -20,12 +20,12 @@
Children - <%= content_tag :span, found_children.size, class: "badge badge-pill badge-secondary" %> + <%= content_tag :span, valid_children.size, class: "badge badge-pill badge-secondary" %>
- <% if found_children %> - <%= render partial: 'labware/child_labware_item', collection: found_children, as: :labware, locals: { presenter: presenter, open_in_new_window: true } %> + <% if valid_children %> + <%= render partial: 'labware/child_labware_item', collection: valid_children, as: :labware, locals: { presenter: presenter, open_in_new_window: true } %> <% else %>
No children found
<% end %> From a1a3f9b538704ebd195143e293ad06c14c736532 Mon Sep 17 00:00:00 2001 From: Stephen Hulme Date: Fri, 27 Sep 2024 15:33:31 +0100 Subject: [PATCH 3/3] fix: default valid_relatives to an empty array if the filter returns nil --- app/views/labware/_relatives_list.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/labware/_relatives_list.html.erb b/app/views/labware/_relatives_list.html.erb index 7f035cb7f..6d07d5040 100644 --- a/app/views/labware/_relatives_list.html.erb +++ b/app/views/labware/_relatives_list.html.erb @@ -1,7 +1,7 @@ <%# locals: (presenter:) %> <% - valid_parents = presenter.labware.parents&.filter{ |parent| parent.purpose.present? } - valid_children = presenter.labware.children&.filter{ |child| child.purpose.present? } + valid_parents = presenter.labware.parents&.filter{ |parent| parent.purpose.present? } || [] + valid_children = presenter.labware.children&.filter{ |child| child.purpose.present? } || [] %>