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 link to show resource from collection table #727

Merged
merged 1 commit into from
Jan 9, 2017
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
8 changes: 8 additions & 0 deletions app/assets/stylesheets/administrate/components/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@
.table__action--destroy {
color: $light-red;
}

.table__link-plain {
color: inherit;

&:hover {
color: inherit;
}
}
6 changes: 5 additions & 1 deletion app/views/administrate/application/_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ to display a collection of resources in an HTML table.
>
<% collection_presenter.attributes_for(resource).each do |attribute| %>
<td class="cell-data cell-data--<%= attribute.html_class %>">
<%= render_field attribute %>
<a href="<%= polymorphic_path([namespace, resource]) -%>"
class="action-show table__link-plain"
>
<%= render_field attribute %>
</a>
</td>
<% end %>

Expand Down
9 changes: 9 additions & 0 deletions spec/features/index_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
expect(page).to have_content(customer.email)
end

it "links to the customer show page without javascript", js: false do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this means that now we'll be able to disable JavaScript by default and enable JS instead?

Copy link
Contributor Author

@odlp odlp Jan 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default driver is currently RackTest for most of the feature specs. The js: false is redundant but I put it there to be explicit.

11 / 56 feature specs enable javascript with the :js flag:

bundle exec rspec spec/features
# 56 examples, 0 failures

bundle exec rspec spec/features --tag js
# 11 examples, 0 failures

We could convert these to use the hyperlink, but it's quite handy to have the coverage & confidence the data-url / JS option still works.

What do you think @nickcharlton?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry... re-reading your comment. Do you mean invert the test names? So links to the customer show page is the vanilla version, then links to the customer show page with javascript or similar?

customer = create(:customer)

visit admin_customers_path
click_show_link_for(customer)

expect(page).to have_header(displayed(customer))
end

it "links to the edit page" do
customer = create(:customer)

Expand Down
10 changes: 10 additions & 0 deletions spec/support/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def click_row_for(model)
end
end

def click_show_link_for(model)
within(row_css_for(model)) do
all(show_link_elements).first.click
end
end

private

def row_css_for(model)
Expand All @@ -15,6 +21,10 @@ def clickable_table_elements
".cell-data--string, .cell-data--number"
end

def show_link_elements
".action-show"
end

def url_for(model)
"/" + [
:admin,
Expand Down