Merge pull request #10750 from jibees/10560-allow-hide-of-groups-tab-in-shop-navigation

White Label: allow hide of groups tab in shop navigation
This commit is contained in:
Filipe
2023-05-24 21:11:04 +01:00
committed by GitHub
8 changed files with 74 additions and 3 deletions

View File

@@ -24,7 +24,7 @@ module ShopHelper
{ name: 'about', title: t(:shopping_tabs_about), show: true },
{ name: 'producers', title: t(:shopping_tabs_producers), show: true },
{ name: 'contact', title: t(:shopping_tabs_contact), show: true },
{ name: 'groups', title: t(:shopping_tabs_groups), show: current_distributor.groups.any? },
{ name: 'groups', title: t(:shopping_tabs_groups), show: show_groups_tabs? },
].select{ |tab| tab[:show] }
end
@@ -52,4 +52,10 @@ module ShopHelper
true
end
private
def show_groups_tabs?
!current_distributor.hide_groups_tab? && current_distributor.groups.any?
end
end

View File

@@ -35,7 +35,8 @@ module PermittedAttributes
:show_customer_names_to_suppliers, :preferred_shopfront_product_sorting_method,
:preferred_invoice_order_by_supplier,
:preferred_product_low_stock_display,
:hide_ofn_navigation, :white_label_logo, :white_label_logo_link
:hide_ofn_navigation, :white_label_logo, :white_label_logo_link,
:hide_groups_tab
]
end
end

View File

@@ -29,3 +29,11 @@
= render ConfirmModalComponent.new(id: "remove_logo", confirm_reflexes: "click->WhiteLabel#remove_logo" ) do
.margin-bottom-30
= t('.remove_logo_confirm')
// Hide groups tab boolean attribute
.row
.three.columns.alpha
= f.label :hide_groups_tab, t('.hide_groups_tab')
.three.columns
= f.check_box :hide_groups_tab

View File

@@ -1185,6 +1185,7 @@ en:
remove_logo_confirm: "Are you sure you want to remove this logo?"
remove_logo_success: "Logo removed"
white_label_logo_link_label: "Link for the logo used in shopfront"
hide_groups_tab: "Hide groups tab in shopfront"
actions:
edit_profile: Settings
properties: Properties

View File

@@ -0,0 +1,5 @@
class AddHideGroupsTabToEnterprises < ActiveRecord::Migration[7.0]
def change
add_column :enterprises, :hide_groups_tab, :boolean, default: false
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_04_24_141213) do
ActiveRecord::Schema[7.0].define(version: 2023_04_25_135232) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
@@ -226,6 +226,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_04_24_141213) do
t.string "whatsapp_phone", limit: 255
t.boolean "hide_ofn_navigation", default: false, null: false
t.text "white_label_logo_link"
t.boolean "hide_groups_tab", default: false
t.index ["address_id"], name: "index_enterprises_on_address_id"
t.index ["is_primary_producer", "sells"], name: "index_enterprises_on_is_primary_producer_and_sells"
t.index ["name"], name: "index_enterprises_on_name", unique: true

View File

@@ -706,6 +706,25 @@ describe '
expect(distributor1.reload.white_label_logo_link).to eq("https://www.openfoodnetwork.org")
end
end
it "can check/uncheck the hide_groups_tab attribute" do
check "Hide groups tab in shopfront"
click_button 'Update'
expect(flash_message)
.to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.hide_groups_tab).to be true
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") do
click_link "White Label"
end
uncheck "Hide groups tab in shopfront"
click_button 'Update'
expect(flash_message)
.to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.hide_groups_tab).to be false
end
end
end
end

View File

@@ -157,6 +157,36 @@ describe 'White label setting' do
it_behaves_like "does not hide the OFN navigation"
end
context "manage hide_groups_tab preference when distributor belongs to a group" do
let(:group) { create(:enterprise_group) }
before do
distributor.groups << group
end
context "when the preference is set to true" do
before do
distributor.update_attribute(:hide_groups_tab, true)
end
it "hides the groups tab" do
visit main_app.enterprise_shop_path(distributor)
expect(page).to have_no_selector "a[href='#groups']"
end
end
context "when the preference is set to false" do
before do
distributor.update_attribute(:hide_groups_tab, false)
end
it "shows the groups tab" do
visit main_app.enterprise_shop_path(distributor)
expect(page).to have_selector "a[href='#groups']"
end
end
end
end
context "manage the white_label_logo preference" do