diff --git a/app/views/labware/_relatives_list.html.erb b/app/views/labware/_relatives_list.html.erb index dadcd9544..6d07d5040 100644 --- a/app/views/labware/_relatives_list.html.erb +++ b/app/views/labware/_relatives_list.html.erb @@ -1,14 +1,18 @@ <%# locals: (presenter:) %> +<% + valid_parents = presenter.labware.parents&.filter{ |parent| parent.purpose.present? } || [] + valid_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, valid_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 valid_parents %> + <%= render partial: 'labware/parent_labware_item', collection: valid_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, valid_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 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 %>