From a558df54e77bf6f3d122bb77491f617ed5bc69ab Mon Sep 17 00:00:00 2001 From: Rafal Cymerys Date: Tue, 14 Nov 2023 14:20:15 +0100 Subject: [PATCH] Add generic tabs partial --- app/views/spree/admin/shared/_order_tabs.html.erb | 12 +----------- app/views/spree/admin/shared/_product_tabs.html.erb | 12 +----------- app/views/spree/admin/shared/_tabs.html.erb | 11 +++++++++++ app/views/spree/admin/users/_tabs.html.erb | 12 +----------- 4 files changed, 14 insertions(+), 33 deletions(-) create mode 100644 app/views/spree/admin/shared/_tabs.html.erb diff --git a/app/views/spree/admin/shared/_order_tabs.html.erb b/app/views/spree/admin/shared/_order_tabs.html.erb index 264999fcef..e2b1f4caab 100644 --- a/app/views/spree/admin/shared/_order_tabs.html.erb +++ b/app/views/spree/admin/shared/_order_tabs.html.erb @@ -4,15 +4,5 @@ <% end %> <% content_for :page_tabs do %> - <% order_tabs.items.each do |tab| %> - <% next unless tab.available?(current_ability, @order) %> - <%= content_tag :li, class: 'nav-item', data: { hook: tab.data_hook } do %> - <%= link_to_with_icon( - tab.icon_key, - Spree.t(tab.label_translation_key), - tab.url(@order), - class: tab.active?(current) ? 'active nav-link' : 'nav-link' - ) %> - <% end %> - <% end %> + <%= render partial: 'spree/admin/shared/tabs', locals: { tabs: order_tabs, object: @order, current: current } %> <% end %> diff --git a/app/views/spree/admin/shared/_product_tabs.html.erb b/app/views/spree/admin/shared/_product_tabs.html.erb index cb872b7da1..f9c58c2c9f 100644 --- a/app/views/spree/admin/shared/_product_tabs.html.erb +++ b/app/views/spree/admin/shared/_product_tabs.html.erb @@ -4,15 +4,5 @@ <% end %> <% content_for :page_tabs do %> - <% product_tabs.items.each do |tab| %> - <% next unless tab.available?(current_ability, @product) %> - - <% end %> + <%= render partial: 'spree/admin/shared/tabs', locals: { tabs: product_tabs, object: @product, current: current } %> <% end %> diff --git a/app/views/spree/admin/shared/_tabs.html.erb b/app/views/spree/admin/shared/_tabs.html.erb new file mode 100644 index 0000000000..f0a3d03b00 --- /dev/null +++ b/app/views/spree/admin/shared/_tabs.html.erb @@ -0,0 +1,11 @@ +<% tabs.items.each do |tab| %> + <% next unless tab.available?(current_ability, object) %> + <%= content_tag :li, class: 'nav-item', data: { hook: tab.data_hook } do %> + <%= link_to_with_icon( + tab.icon_key, + Spree.t(tab.label_translation_key), + tab.url(object), + class: tab.active?(current) ? 'active nav-link' : 'nav-link' + ) %> + <% end %> +<% end %> diff --git a/app/views/spree/admin/users/_tabs.html.erb b/app/views/spree/admin/users/_tabs.html.erb index 7abba11d6a..0b4107fdc2 100644 --- a/app/views/spree/admin/users/_tabs.html.erb +++ b/app/views/spree/admin/users/_tabs.html.erb @@ -4,15 +4,5 @@ <% end %> <% content_for :page_tabs do %> - <% user_tabs.items.each do |tab| %> - <% next unless tab.available?(current_ability, @user) %> - - <% end %> + <%= render partial: 'spree/admin/shared/tabs', locals: { tabs: user_tabs, object: @user, current: current } %> <% end %>