Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-62 Feature/product taxon tabs extensibility #274

Merged
merged 98 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
4002e57
Lay groundwork for order tabs builder
tomdonarski Sep 24, 2023
9ee43d7
Lay groundwork for tab's root item
tomdonarski Sep 24, 2023
b90bcb6
Add test for adding to root already appended item
tomdonarski Sep 24, 2023
38fa683
Remove unnecessary tests
tomdonarski Sep 24, 2023
485ee96
Add test for tab class.
tomdonarski Sep 25, 2023
cbe0e80
Accommodate text variable in tab class
tomdonarski Sep 25, 2023
d0cade7
Facilitate tab url
tomdonarski Sep 25, 2023
941d186
Add partial_name to tabs attributes
tomdonarski Sep 25, 2023
65de37e
Add css classes to tab attributes
tomdonarski Sep 26, 2023
55abda6
Add methods for building particular tabs
tomdonarski Sep 26, 2023
8eca944
Add Proc handling for url attribute
tomdonarski Sep 26, 2023
3370768
Facilitate check for active css class.
tomdonarski Sep 26, 2023
a27ea5e
Include module providing availability_check
tomdonarski Sep 26, 2023
c47c921
Initialize cart tab
tomdonarski Sep 26, 2023
9e33d66
Build cart tab
tomdonarski Sep 26, 2023
38b2f1c
Fix initialization
tomdonarski Sep 26, 2023
9699a26
Fix - use existing attribute
tomdonarski Sep 26, 2023
413e034
Improve variable naming
tomdonarski Sep 27, 2023
2911f84
Fix test setup
tomdonarski Sep 27, 2023
0a8ffdd
Fix test description
tomdonarski Sep 27, 2023
743a569
Add test for checking if tab is active
tomdonarski Sep 27, 2023
9c988fb
Add method for checking access to class index
tomdonarski Sep 27, 2023
5eebf1c
Populate tab building steps
tomdonarski Sep 27, 2023
94b9950
Unify naming of currently selected partials
tomdonarski Sep 27, 2023
d6fd48c
Remove dependency on unnecessary attribute
tomdonarski Sep 27, 2023
c93c192
Cleanup test setup
tomdonarski Sep 27, 2023
e013c04
Facilitate .complete? check.
tomdonarski Sep 27, 2023
059f77a
Fix variable naming in root
tomdonarski Sep 27, 2023
a37a98b
Populate root with tabs.
tomdonarski Sep 27, 2023
d35cfff
Fix variable naming
tomdonarski Sep 27, 2023
4563657
Lint fixes
tomdonarski Sep 27, 2023
a700610
Lint fixes
tomdonarski Sep 28, 2023
4833d37
Build admin order_tabs upon initialization
tomdonarski Sep 28, 2023
2293024
Use order_tabs defined on boot
tomdonarski Sep 28, 2023
4ac6845
Fix - pass correct argument
tomdonarski Sep 28, 2023
08018a9
Rename text to name
tomdonarski Sep 28, 2023
e180d72
Incorporate translators
tomdonarski Sep 28, 2023
c6e0a7b
Use path instead of url
tomdonarski Sep 28, 2023
f1828e3
Fix appending css active class
tomdonarski Sep 29, 2023
6bb3ddf
Migrate user tabs from view to separate class
tomdonarski Sep 29, 2023
e65ea17
Migrate product tabs from view to separate class
tomdonarski Sep 29, 2023
5cc8bc3
Disable variables set up in the engine
tomdonarski Sep 29, 2023
57af58a
Move attributes to config.
tomdonarski Sep 29, 2023
a60a413
Adjust default tab builders to use config
tomdonarski Sep 29, 2023
e44c65d
Change back partial current attribute
tomdonarski Sep 29, 2023
5b001f1
Supply configs in builders with partial_name
tomdonarski Sep 29, 2023
f845daf
Fix active check to use partial_name.
tomdonarski Sep 29, 2023
235fb56
Enable variables set up in the engine
tomdonarski Sep 29, 2023
2e48d2e
Lint fix
tomdonarski Sep 29, 2023
7c8c182
Lint fixes
tomdonarski Sep 29, 2023
50f449e
Use global scope
tomdonarski Sep 29, 2023
9ad49dd
Refactor order_tabs_builder
tomdonarski Oct 2, 2023
109faee
Refactor product_tabs_builder.
tomdonarski Oct 2, 2023
3a6ad94
Disable class length cop
tomdonarski Oct 2, 2023
3fb2c43
Add missing data_hook attribute
tomdonarski Oct 3, 2023
759fce6
Use more descriptive namespace
tomdonarski Oct 3, 2023
4ca9106
Group tabs together in the app config
tomdonarski Oct 3, 2023
1569d11
Embed default translation mechanism in tab
tomdonarski Oct 3, 2023
5e923d8
Remove custom translations
tomdonarski Oct 4, 2023
31d41c3
Add missing .complete? checks
tomdonarski Oct 4, 2023
934e845
Introduce TabBuilder.
tomdonarski Oct 4, 2023
3b36fb9
Fix .complete? check
tomdonarski Oct 4, 2023
57e054f
Lint fix
tomdonarski Oct 4, 2023
e489e1a
Improve formatting
tomdonarski Oct 4, 2023
6c2f96c
Remove unnecessary test
tomdonarski Oct 4, 2023
6d34140
Cleanup tab test
tomdonarski Oct 4, 2023
94b4157
Refactor test to meet rubocop expectations
tomdonarski Oct 4, 2023
68026ae
Spell fix
tomdonarski Oct 5, 2023
b7903a3
Add missing tests
tomdonarski Oct 12, 2023
2075114
Adhere to naming convention in tests
tomdonarski Oct 17, 2023
63e847e
Cleanup - remove superfluous method
tomdonarski Oct 17, 2023
dbccb04
Rename an attribute
tomdonarski Oct 17, 2023
474be4c
Fix spec after renaming an attribute
tomdonarski Oct 17, 2023
927d42f
Create common abstraction for
tomdonarski Oct 17, 2023
c47e0ec
Add missing test
tomdonarski Oct 17, 2023
60db052
Remove superfluous methods
tomdonarski Oct 17, 2023
4902cff
Abstract away #child_with_key? method
tomdonarski Oct 17, 2023
c354d4a
Simplify setup
tomdonarski Oct 17, 2023
699e886
Abstract away #remove method
tomdonarski Oct 17, 2023
25f6970
Abstract away #item_for_key method
tomdonarski Oct 17, 2023
c6d901a
Abstract away #insert_before method
tomdonarski Oct 17, 2023
af2e2fa
Abstract away #insert_after method
tomdonarski Oct 17, 2023
8430877
Remove superfluous method
tomdonarski Oct 18, 2023
b1c9aeb
Equalize spec setup
tomdonarski Oct 18, 2023
57d6c65
Remove superfluous test
tomdonarski Oct 18, 2023
f19f5d9
Equalize root specs
tomdonarski Oct 18, 2023
b458feb
Introduce a shared abstraction for ability checks
tomdonarski Oct 18, 2023
40a4e5e
Lint fix
tomdonarski Oct 18, 2023
e198cb6
Abstract away common tests to shared examples
tomdonarski Oct 18, 2023
3af140a
Remove tab css data from configuration,
tomdonarski Oct 18, 2023
35a3b96
Fix spec.
tomdonarski Oct 18, 2023
0c66363
Move 'add' method to a separate module,
tomdonarski Oct 23, 2023
925e58d
Split shared examples
tomdonarski Oct 23, 2023
a7fdd65
Include item appendage module in Root and Section
tomdonarski Oct 23, 2023
763aad1
Contain all item manipulation behaviour
tomdonarski Oct 23, 2023
c55de0a
Add back deleted method
tomdonarski Oct 23, 2023
b2e42db
Add missing spec for 'add_to_section'
tomdonarski Oct 23, 2023
21e4db5
Lint fix
tomdonarski Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/helpers/spree/admin/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,18 @@ def page_header_back_button(url)
def main_menu
Rails.application.config.spree_backend.main_menu
end

def order_tabs
Rails.application.config.spree_backend.tabs[:order]
end

def user_tabs
Rails.application.config.spree_backend.tabs[:user]
end

def product_tabs
Rails.application.config.spree_backend.tabs[:product]
end
end
end
end
50 changes: 50 additions & 0 deletions app/models/spree/admin/item_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module Spree
module Admin
module ItemManager
def add(item)
raise KeyError, "Item with key #{item.key} already exists" if index_for_key(item.key)

@items << item
end

def child_with_key?(key)
index_for_key(key).present?
end

def remove(item_key)
item_index = index_for_key!(item_key)

@items.delete_at(item_index)
end

def item_for_key(key)
@items.find { |e| e.key == key }
end

def insert_before(item_key, item_to_add)
item_index = index_for_key!(item_key)

@items.insert(item_index, item_to_add)
end

def insert_after(item_key, item_to_add)
item_index = index_for_key!(item_key)

@items.insert(item_index + 1, item_to_add)
end

private

def index_for_key(key)
@items.index { |e| e.key == key }
end

def index_for_key!(key)
item_index = index_for_key(key)
raise KeyError, "Item not found for key #{key}" unless item_index

item_index
end
end
end
end
22 changes: 0 additions & 22 deletions app/models/spree/admin/main_menu/availability_builder_methods.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/spree/admin/main_menu/item_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Spree
module Admin
module MainMenu
class ItemBuilder
include AvailabilityBuilderMethods
include ::Spree::Admin::PermissionChecks

def initialize(key, url)
@key = key
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/admin/main_menu/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize
end

def add_to_section(section_key, item)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hasn't been used anywhere. Moreover, add_item is not defined anywhere. Even if it's a typo, and should be add_item the whole does what add method (defined in Section class) does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not used in our code, because it's a method for extension developers who need to add a custom item to the admin panel main menu. That's not a reason to delete it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have missed a test for this one, but let's just fix the implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added it back, and wrote a test for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks!

@items.find { |e| e.key == section_key }.add_item(item)
@items.find { |e| e.key == section_key }.add(item)
end
end
end
Expand Down
47 changes: 2 additions & 45 deletions app/models/spree/admin/main_menu/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Spree
module Admin
module MainMenu
class Section
include ::Spree::Admin::ItemManager

attr_reader :key, :label_translation_key, :icon_key, :items

def initialize(key, label_translation_key, icon_key, availability_check, items)
Expand All @@ -12,38 +14,6 @@ def initialize(key, label_translation_key, icon_key, availability_check, items)
@items = items
end

def add(item)
raise KeyError, "Item with key #{key} already exists" if index_for_key(item.key)

@items << item
end

def child_with_key?(key)
index_for_key(key).present?
end

def remove(item_key)
item_index = index_for_key!(item_key)

@items.delete_at(item_index)
end

def item_for_key(key)
@items.find { |e| e.key == key }
end

def insert_before(item_key, item_to_add)
item_index = index_for_key!(item_key)

@items.insert(item_index, item_to_add)
end

def insert_after(item_key, item_to_add)
item_index = index_for_key!(item_key)

@items.insert(item_index + 1, item_to_add)
end

def available?(current_ability, current_store)
return true unless @availability_check.present?

Expand All @@ -53,19 +23,6 @@ def available?(current_ability, current_store)
def children?
@items.any?
end

private

def index_for_key(key)
@items.index { |e| e.key == key }
end

def index_for_key!(key)
item_index = index_for_key(key)
raise KeyError, "Item not found for key #{key}" unless item_index

item_index
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/admin/main_menu/section_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Spree
module Admin
module MainMenu
class SectionBuilder
include AvailabilityBuilderMethods
include ::Spree::Admin::PermissionChecks

def initialize(key, icon_key)
@key = key
Expand Down
30 changes: 30 additions & 0 deletions app/models/spree/admin/permission_checks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Spree
module Admin
module PermissionChecks
def with_availability_check(availability_check)
@availability_check = availability_check
self
end

def with_manage_ability_check(*classes)
@availability_check = ->(ability, _current) { classes.any? { |c| ability.can?(:manage, c) } }
self
end

def with_admin_ability_check(*classes)
@availability_check = ->(ability, _current) { classes.any? { |c| ability.can?(:admin, c) } }
self
end

def with_index_ability_check(*classes)
@availability_check = ->(ability, _current) { classes.any? { |c| ability.can?(:index, c) } }
self
end

def with_update_ability_check
@availability_check = ->(ability, resource) { ability.can?(:update, resource) }
self
end
end
end
end
17 changes: 17 additions & 0 deletions app/models/spree/admin/tabs/conditional_checker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Spree
module Admin
module Tabs
module ConditionalChecker
def with_active_check
@active_check = ->(current_tab, text) { current_tab == text }
self
end

def with_completed_check
@completed_check = ->(resource) { resource.completed? }
self
end
end
end
end
end
12 changes: 12 additions & 0 deletions app/models/spree/admin/tabs/data_hook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Spree
module Admin
module Tabs
module DataHook
def with_data_hook(data_hook)
@data_hook = data_hook
self
end
end
end
end
end
Loading
Loading