diff --git a/app/components/sdg_management/goals/index_component.html.erb b/app/components/sdg_management/goals/index_component.html.erb index d08dd0ca9..68c9f9823 100644 --- a/app/components/sdg_management/goals/index_component.html.erb +++ b/app/components/sdg_management/goals/index_component.html.erb @@ -1,25 +1,23 @@ <%= header %> -<%# TODO: replace links with tabs %> -<%= link_to SDG::Goal.model_name.human(count: 2).titleize, sdg_management_goals_path %> -<%= link_to SDG::Target.model_name.human(count: 2).titleize, sdg_management_targets_path %> - - - - - - - - - - - - <% goals.each do |goal| %> - - - - +<%= render SDGManagement::SubnavigationComponent.new(current: :goals) do %> +
<%= attribute_name(:code) %><%= attribute_name(:title) %><%= attribute_name(:description) %>
<%= goal.code %><%= goal.title %><%= goal.description %>
+ + + + + - <% end %> - -
<%= attribute_name(:code) %><%= attribute_name(:title) %><%= attribute_name(:description) %>
+ + + + <% goals.each do |goal| %> + + <%= goal.code %> + <%= goal.title %> + <%= goal.description %> + + <% end %> + + +<% end %> diff --git a/app/components/sdg_management/subnavigation_component.html.erb b/app/components/sdg_management/subnavigation_component.html.erb new file mode 100644 index 000000000..761aa26d0 --- /dev/null +++ b/app/components/sdg_management/subnavigation_component.html.erb @@ -0,0 +1,13 @@ + + +
+
+ <%= content %> +
+
diff --git a/app/components/sdg_management/subnavigation_component.rb b/app/components/sdg_management/subnavigation_component.rb new file mode 100644 index 000000000..35d1a0fda --- /dev/null +++ b/app/components/sdg_management/subnavigation_component.rb @@ -0,0 +1,30 @@ +class SDGManagement::SubnavigationComponent < ApplicationComponent + attr_reader :current + + def initialize(current:) + @current = current + end + + private + + def sections + %i[goals targets] + end + + def link_to_section(section) + link_to "SDG::#{section.to_s.classify}".constantize.model_name.human(count: 2).titleize, + path_for(section), + class: active_style(section) + end + + def path_for(section) + { + controller: "sdg_management/#{section}", + action: :index + } + end + + def active_style(section) + "is-active" if section == current + end +end diff --git a/app/components/sdg_management/targets/index_component.html.erb b/app/components/sdg_management/targets/index_component.html.erb index 6608dfb64..161ffd352 100644 --- a/app/components/sdg_management/targets/index_component.html.erb +++ b/app/components/sdg_management/targets/index_component.html.erb @@ -1,35 +1,33 @@ <%= header %> -<%# TODO: replace links with tabs %> -<%= link_to SDG::Goal.model_name.human(count: 2).titleize, sdg_management_goals_path %> -<%= link_to SDG::Target.model_name.human(count: 2).titleize, sdg_management_targets_path %> - - - - - - - - - - - <% targets.group_by(&:goal).map do |goal, targets| %> - - +<%= render SDGManagement::SubnavigationComponent.new(current: :targets) do %> +
<%= attribute_name(:title) %>
- <%= goal.code %>. <%= goal.title %> -
+ + + + + - <% targets.each do |target| %> - - + <% targets.group_by(&:goal).map do |goal, targets| %> + + - + + <% targets.each do |target| %> + + + + + <% end %> <% end %> - <% end %> - -
<%= attribute_name(:title) %>
- <%= target.code %> +
+ <%= goal.code %>. <%= goal.title %> - <%= target.title %> -
+ <%= target.code %> + + <%= target.title %> +
+ + +<% end %> diff --git a/spec/components/sdg_management/subnavigation_component_spec.rb b/spec/components/sdg_management/subnavigation_component_spec.rb new file mode 100644 index 000000000..11975e549 --- /dev/null +++ b/spec/components/sdg_management/subnavigation_component_spec.rb @@ -0,0 +1,30 @@ +require "rails_helper" + +describe SDGManagement::SubnavigationComponent, type: :component do + let(:component) do + SDGManagement::SubnavigationComponent.new(current: :goals) do + "Tab content" + end + end + + it "does not run Foundation component" do + render_inline component + + expect(page).not_to have_css "[data-tabs]" + end + + it "renders tabs and links properly styled" do + render_inline component + + expect(page).to have_selector "a.is-active", text: "Goals" + expect(page).to have_selector "a:not(.is-active)", text: "Targets" + end + + it "renders given block within active panel" do + render_inline component + + within "#goals.tabs-panel.is-active" do + expect(page).to have_content("Tab content") + end + end +end