Skip to content

Commit

Permalink
Add preview action to the backend when spree_frontend is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalcymerys committed Nov 1, 2023
1 parent 50afc02 commit ff6e635
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions config/initializers/admin_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Rails.application.config.after_initialize do
action = ::Spree::Admin::Actions::ActionBuilder.new('preview', ->(resource) { "/products/#{resource.slug}" }).
with_icon_key('view.svg').
with_label_translation_key('admin.utilities.preview').
with_id('adminPreviewProduct').
with_target(:blank).
with_data_attributes({ turbo: false })

Rails.application.config.spree_backend.actions[:product].add(action)

This comment has been minimized.

Copy link
@tomdonarski

tomdonarski Nov 2, 2023

Contributor

I've just tried it:

Rails.application.config.spree_backend.actions[:product]
=> #<Spree::Admin::Actions::Root:0x000000010a491dc0 @items=[]>

action = ::Spree::Admin::Actions::ActionBuilder.new('preview', ->(resource) { "/products/#{resource.slug}" })
=>
#<Spree::Admin::Actions::ActionBuilder:0x000000010d113358

Rails.application.config.spree_backend.actions[:product].add(action)
=>
/Users/tomaszdonarski/spree_backend/app/models/spree/admin/item_manager.rb:5:in `add': undefined method `key' for #<Spree::Admin::Actions::ActionBuilder:0x000000010d113358 @key="preview", @label_translation_key="preview", @url=#<Proc:0x000000010c810e40 (irb):2 (lambda)>, @icon_key=nil, @style="light", @availability_checks=[], @classes="", @method=nil, @id=nil, @target=nil, @data_attributes={}> (NoMethodError)

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

This comment has been minimized.

Copy link
@rafalcymerys

rafalcymerys Nov 2, 2023

Author Member

Yeah, I missed the .build when creating an action. This is a WIP, waiting for the upstream change to be merged

This comment has been minimized.

Copy link
@tomdonarski

tomdonarski Nov 2, 2023

Contributor

It seems, what's left is this - spree/spree_backend#282 (comment)

Rails.application.config.spree_backend.actions[:images].add(action)
Rails.application.config.spree_backend.actions[:variants].add(action)
Rails.application.config.spree_backend.actions[:prices].add(action)
Rails.application.config.spree_backend.actions[:stock].add(action)
Rails.application.config.spree_backend.actions[:product_properties].add(action)
end

0 comments on commit ff6e635

Please sign in to comment.