Skip to content

Commit

Permalink
fix[Op#50737]: Make "Cancel" button routing more consistent
Browse files Browse the repository at this point in the history
1. In "General information" section, cancel redirects back to the index
   page
2. All other "Cancel" buttons stay on the same page, but hide the forms
  • Loading branch information
akabiru committed Nov 16, 2023
1 parent ad79c98 commit 317a3fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ def submit_button_options
end

def cancel_button_options
{ href: edit_admin_settings_storage_path(storage) }.tap do |options_hash|
if new_record?
options_hash[:href] = admin_settings_storages_path
options_hash[:target] = '_top'
end
end
{ href: edit_admin_settings_storage_path(storage) }
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ def submit_button_options
end

def cancel_button_options
{
href: cancel_button_path,
data: { turbo_stream: true }
}
{ href: cancel_button_path,
data: { turbo_stream: true } }.tap do |options_hash|
if storage.new_record?
options_hash[:data][:turbo_stream] = false
options_hash[:target] = '_top' # Break out of Turbo Frame, follow full page redirect
end
end
end

private
Expand All @@ -64,9 +67,7 @@ def default_form_url

def cancel_button_path
options.fetch(:cancel_button_path) do
if storage.new_record?
new_admin_settings_storage_path
elsif storage.persisted?
if storage.persisted?
edit_admin_settings_storage_path(storage)
else
admin_settings_storages_path
Expand Down

0 comments on commit 317a3fe

Please sign in to comment.