Skip to content

Commit

Permalink
✨ Add target_window to actions (#3419)
Browse files Browse the repository at this point in the history
* ✨ Add target_window to actions

* 🔧 Remove default value of target_window

* ✅ Add test for target_window

* Apply suggestions from code review

Co-authored-by: Mitsuhiro Shibuya <mit.shibuya@gmail.com>

* 💄 Change target_window to link_target

* 🚨 Fix lint issue

Co-authored-by: Mitsuhiro Shibuya <mit.shibuya@gmail.com>
  • Loading branch information
RocKhalil and mshibuya committed Nov 29, 2021
1 parent fa0db21 commit 2ee1111
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/helpers/rails_admin/application_helper.rb
Expand Up @@ -163,7 +163,7 @@ def menu_for(parent, abstract_model = nil, object = nil, only_icon = false)
else
'javascript:void(0)'
end
content_tag(:a, label, {href: href}.merge(action.pjax? ? {class: ['pjax']} : {}))
content_tag(:a, label, {href: href, target: action.link_target}.merge(action.pjax? ? {class: ['pjax']} : {}))
else
content_tag(:span, label)
end
Expand Down
7 changes: 6 additions & 1 deletion lib/rails_admin/config/actions/base.rb
Expand Up @@ -75,7 +75,12 @@ class Base

# Render via pjax?
register_instance_option :pjax? do
true
link_target.blank?
end

# Target window [_self, _blank]
register_instance_option :link_target do
nil
end

# This block is evaluated in the context of the controller when action is called
Expand Down
18 changes: 18 additions & 0 deletions spec/helpers/rails_admin/application_helper_spec.rb
Expand Up @@ -223,6 +223,24 @@
expect(helper.menu_for(:root)).not_to match(/Dashboard/)
expect(helper.menu_for(:root)).to match(/Look this/)
end

it 'should render allow an action to have link_target as config' do
RailsAdmin.config do |config|
config.actions do
dashboard
index
show do
link_target :_blank
end
end
end

@action = RailsAdmin::Config::Actions.find :show
@abstract_model = RailsAdmin::AbstractModel.new(Team)
@object = FactoryBot.create(:team, name: 'the avengers')

expect(helper.menu_for(:member, @abstract_model, @object)).to match(/_blank/)
end
end

describe '#main_navigation' do
Expand Down

0 comments on commit 2ee1111

Please sign in to comment.