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

✨ Add target_window to actions #3419

Merged
merged 7 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/helpers/rails_admin/application_helper.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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