Skip to content

Commit

Permalink
Feature: Add back button to association pages
Browse files Browse the repository at this point in the history
  • Loading branch information
binarygit committed Aug 6, 2024
1 parent 0007cd4 commit 1d45a58
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/components/avo/views/resource_index_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ def can_render_scopes?
defined?(Avo::Advanced)
end

def back_path
if @reflection.present? && !helpers.turbo_frame_request?
helpers.resource_path(record: @parent_record, resource: @parent_resource)
end
end

private

def reflection_model_class
Expand Down
2 changes: 1 addition & 1 deletion lib/avo/concerns/has_controls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def render_edit_controls
end

def render_index_controls(item:)
[AttachButton.new(item: item), ActionsList.new(as_index_control: true), CreateButton.new(item: item)]
[BackButton.new, AttachButton.new(item: item), ActionsList.new(as_index_control: true), CreateButton.new(item: item)]
end

def render_row_controls(item:)
Expand Down
10 changes: 10 additions & 0 deletions spec/features/avo/breadcrumbs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,15 @@
expect(breadcrumbs).to have_link team.name.to_s
expect(breadcrumbs).to_not have_link "Users"
end

it "has a back button" do
url = "/admin/resources/teams/#{team.id}/team_members?view=show"
visit url

expect(page).to have_link "Go back"
click_link "Go back"
expect(current_path).to eq "/admin/resources/teams/#{team.id}"
expect(page).to have_link "Go back", count: 1
end
end
end

0 comments on commit 1d45a58

Please sign in to comment.