From bce1474527c6135e5f8c4604d7266e6d42dab863 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 27 Oct 2023 11:00:08 +0200 Subject: [PATCH] Only render position field on table when cards rendered are not headers --- app/components/admin/widget/cards/row_component.html.erb | 6 ++++++ app/components/admin/widget/cards/row_component.rb | 6 ++++++ app/components/admin/widget/cards/table_component.html.erb | 3 +++ app/components/admin/widget/cards/table_component.rb | 4 ++++ spec/system/admin/widgets/cards_spec.rb | 1 + spec/system/sdg_management/homepage_spec.rb | 1 + 6 files changed, 21 insertions(+) diff --git a/app/components/admin/widget/cards/row_component.html.erb b/app/components/admin/widget/cards/row_component.html.erb index 3f965e028..d8e0876e6 100644 --- a/app/components/admin/widget/cards/row_component.html.erb +++ b/app/components/admin/widget/cards/row_component.html.erb @@ -9,6 +9,12 @@ <%= card.link_url %> + <% unless header_section? %> + + <%= card.order %> + + <% end %> + <% if card.image.present? %> diff --git a/app/components/admin/widget/cards/row_component.rb b/app/components/admin/widget/cards/row_component.rb index 58343d41f..95ddc6c97 100644 --- a/app/components/admin/widget/cards/row_component.rb +++ b/app/components/admin/widget/cards/row_component.rb @@ -5,4 +5,10 @@ class Admin::Widget::Cards::RowComponent < ApplicationComponent @card = card @options = options end + + private + + def header_section? + card.header_or_sdg_header? + end end diff --git a/app/components/admin/widget/cards/table_component.html.erb b/app/components/admin/widget/cards/table_component.html.erb index f3397df53..519e60d20 100644 --- a/app/components/admin/widget/cards/table_component.html.erb +++ b/app/components/admin/widget/cards/table_component.html.erb @@ -5,6 +5,9 @@ <%= attribute_name(:title) %> <%= attribute_name(:description) %> <%= attribute_name(:link_text) %> / <%= attribute_name(:link_url) %> + <% unless header_section? %> + <%= attribute_name(:order) %> + <% end %> <%= t("admin.shared.image") %> <%= t("admin.shared.actions") %> diff --git a/app/components/admin/widget/cards/table_component.rb b/app/components/admin/widget/cards/table_component.rb index efdb279c7..d11cc63a0 100644 --- a/app/components/admin/widget/cards/table_component.rb +++ b/app/components/admin/widget/cards/table_component.rb @@ -12,4 +12,8 @@ class Admin::Widget::Cards::TableComponent < ApplicationComponent def attribute_name(attribute) ::Widget::Card.human_attribute_name(attribute) end + + def header_section? + cards.first.header_or_sdg_header? + end end diff --git a/spec/system/admin/widgets/cards_spec.rb b/spec/system/admin/widgets/cards_spec.rb index ad0559237..4f5043ae7 100644 --- a/spec/system/admin/widgets/cards_spec.rb +++ b/spec/system/admin/widgets/cards_spec.rb @@ -142,6 +142,7 @@ describe "Cards", :admin do within("#header") do expect(page).to have_css(".homepage-card", count: 1) + expect(page).not_to have_css "th", exact_text: "Position" expect(page).to have_content "Header label" expect(page).to have_content "Header text" expect(page).to have_content "Header description" diff --git a/spec/system/sdg_management/homepage_spec.rb b/spec/system/sdg_management/homepage_spec.rb index 2245b3cd0..42bd72567 100644 --- a/spec/system/sdg_management/homepage_spec.rb +++ b/spec/system/sdg_management/homepage_spec.rb @@ -70,6 +70,7 @@ describe "SDG homepage configuration" do within(".sdg-header") do expect(page).to have_content "My header" expect(page).not_to have_content "Create header" + expect(page).not_to have_css "th", exact_text: "Position" end end