AO3-7143 Adding filter to user collection page#5788
Conversation
This reverts commit b3246cd.
|
#5487 original PR. Reopened the PR since merging upstream made it quite angry. Apologies for the added complexity. |
|
@sarken pinging you since you commented in the previous PR |
|
It seems that the spec controller failure is not expected behaviour after this PR? |
sarken
left a comment
There was a problem hiding this comment.
I checked on the failing spec, and it looks like it's failing because we lost alphabetical sorting on user collection pages. That's something we definitely want to keep; users weren't happy when we accidentally switched to created_at sorting.
| <% if @user && @user == current_user %> | ||
| <li><%= span_if_current ts("Collections"), user_collections_path(@user) %></li> | ||
| <li><%= link_to ts("Manage Collection Items"), user_collection_items_path(@user) %></li> | ||
| <div class="navigation actions module"> |
There was a problem hiding this comment.
We only put our subnavigation in div like this in rare instances where we have complex navigation with multiple separate sets of actions, like two lists, or a list and a form outside the list. The div on works/index.html.erb is there because we can have both a form and a list... but I think it's wrong, actually, because they shouldn't be there at the same time.
I'm pretty sure the reason you've added this is to make the navigation take up the full width of #main and push the filters into the right position on the page. Interestingly, the bookmarks index doesn't have this div, nor does it have that problem -- and after some investigating, I figured out why. Both bookmark and work index pages leave the empty ol.index on the page, while the collection index removes it with the unless @collections.blank? logic on line 52. Empty list elements aren't great for accessibility, so we don't want to replicate that here, either.
I think the solution we need here is to add a clear to form.filters. That should keep the filters in the right position without either the empty list or the div.
There was a problem hiding this comment.
It seems that stylesheet 17 is taking priority over stylesheet 18. Regardless of if the index has filtered or not. The width: 100% seems to be the cause of the issue in that case? It is defined to be 75% in sheet 18 within line 9 but the one in style sheet 17 is applied first. Adding !important to the one in sheet 18 seems to fix it? But I wasn't sure if such a solution was desired.
There was a problem hiding this comment.
Which page and device/browser, and which width: 100%? After actioning this comment, the only width: 100% I can find in 17 is .dashboard.works-index h4.landmark, .dashboard.works-index ol.pagination, and I'm not running into issues on either the user collection index or work index, but I've only checked in desktop Safari.
0c99f89 has the changes I'm testing with.
There was a problem hiding this comment.
Oh I see, I got confused and reintroduced the class in page 17.
| <li><%= link_to ts("Manage Collection Items"), user_collection_items_path(@user) %></li> | ||
| <div class="navigation actions module"> | ||
| <h3 class="landmark heading"><%= t(".navigation.landmark_heading") %></h3> | ||
| <ul class="navigation actions" role="navigation"> |
There was a problem hiding this comment.
You can remove the role="navigation" while you're here -- it's not valid on list elements.
| <h3 class="landmark heading"><%= ts("List of Collections") %></h3> | ||
| <ul class="collection picture index group"> | ||
| <h3 class="landmark heading"><%= t(".main_content.landmark_heading") %></h3> | ||
| <ul class="collection picture index group <%= "no-filter" unless @sort_and_filter %>"> |
There was a problem hiding this comment.
Instead of adding a class, let's take a look at what's causing the problem here. (But just a quick note for the future that we have some rules for adding classes.)
It looks like all collection index pages get the filtered class, regardless of whether they have filters, thanks to this:
otwarchive/app/helpers/application_helper.rb
Lines 60 to 62 in 7f6d5b1
otwarchive/app/helpers/application_helper.rb
Lines 19 to 25 in 7f6d5b1
Unfortunately, collections don't use @facets, so we can't just remove the collections logic from page_has_filters?. But we can tweak it to (controller.controller_name == "collections" && @sort_and_filter) or even just @sort_and_filter, since collections are the only place we use that variable, and I think it's reasonable to reserve it so it's only ever used to determine whether we display filters. #5721 also uses that variable for filtered challenge pages.
As a bonus, this approach should also fix the issue where /works/:id/collections pages
There was a problem hiding this comment.
I was trying to find the root cause but couldn't quite find it. Thanks!
It seems that the default sort column is defined to be created_at in |
|
We just want to change the sort column on the user collection pages, not everywhere, so I don't think that's the right place to do it. Does restoring |
|
No rush, just noting that I put the label back to Reviewed: Action Needed since there were still test failures. |
|
I found the issue for the cucumber test, waiting for response for the rubocop failure. |
| And the 2nd collection result should contain "Privates" | ||
| And the 2nd collection result should contain "Bookmarked Items: 1" | ||
|
|
||
| Scenario: Sort collections by Works and Bookmarks from user's collection |
There was a problem hiding this comment.
Since this issue adds the user collection page, we want to test that such a page only shows collections belonging to the user. You covered this in the other feature file, with "Filtering on a user collection page should only return collections by that user".
On the other hand, I think we can skip this scenario. It's the same as "Scenario: Sort collections by Works and Bookmarks". It also doesn't deal with multiple collection owners, just the same one that got renamed.
| When I go to recengine's collections page | ||
| And I fill in "Filter by title" with "Duplicate Name" | ||
| And I press "Sort and Filter" | ||
| Then I should see "1 Collection" |
There was a problem hiding this comment.
You can add checks for the titles that should show up, "1nd collection result should contain" and so on.
| Then I should see "2 Collections" | ||
| When I fill in "Filter by title" with "Not Mine!" | ||
| And I press "Sort and Filter" | ||
| Then I should not see "iminvisible" |
There was a problem hiding this comment.
This "should not see" step can be skipped since there's already a better "no collections found" check that covers the same thing.
| @sort_and_filter = true | ||
| @user = User.find_by!(login: params[:user_id]) | ||
| @search = CollectionSearchForm.new({ maintainer_id: @user.id, sort_column: "title.keyword" }.merge(page: params[:page])) | ||
| @search = CollectionSearchForm.new(collection_filter_params.merge({ maintainer_id: @user.id, default_sort_column: "title.keyword" }.merge(page: params[:page]))) |
There was a problem hiding this comment.
Can we use sort_column instead of a new parameter?
There was a problem hiding this comment.
sort_column would override whatever sorting the user tries to make. It cannot be used
| And the 2nd collection result should contain "Privates" | ||
| And the 2nd collection result should contain "Bookmarked Items: 1" | ||
|
|
||
| Scenario: Sort collections by Works and Bookmarks from user's collection |
There was a problem hiding this comment.
I've left a couple of comments on lines in this scenario, but it looks like it's basically a duplicate of the scenario above it; the main difference appears to be that we are explicitly setting the sort direction to descending.
I'd suggest converting the previous test to a scenario outline, adding steps to specify the sort direction, and using the examples the collection page and moderator's collection page. It should cover the same things while adding fewer lines of code.
There was a problem hiding this comment.
The sort direction is specified in this one because the collection page default to date_updated + descending, while the user collection is title.keyword + ascending
| And I press "Sort and Filter" | ||
| Then I should see "Your search failed because of a syntax error" | ||
|
|
||
| @collections |
There was a problem hiding this comment.
We don't usually put tags before individual scenarios unless the tag is pulling double duty as a hook (e.g., @javascript and @load-default-skin).
| Then I should see "Your search failed because of a syntax error" | ||
|
|
||
| @collections | ||
| Scenario: Filtering on a user collection page should only return collections by that user. |
There was a problem hiding this comment.
I think this scenario would be better in collection_browse.feature since it doesn't need the Background steps at the top of this file.
However, like redsummernight said, I think we can also just live without this.
There was a problem hiding this comment.
Should this scenario be removed then?
Switched to a scenario outline due to 2 tests being very similar, and moved a test from filters
|
|
||
| def default_sort_column | ||
| "created_at" | ||
| options[:default_sort_column] ||= "created_at" |
There was a problem hiding this comment.
To red's point about not adding a new parameter, would something like options[:maintainer_id] ? "title.keyword" : "created_at" work here instead of setting the parameter in the controller?
|
|
||
| def collection_filter_params | ||
| params.permit(:commit, collection_search: [ | ||
| params.permit(:commit, :user_id, collection_search: [ |
There was a problem hiding this comment.
Do you know when the user_id parameter is used? I didn't notice it in the URL and it seemed to work without this addition, but it was only a quick test while I was looking into red's suggestion.
Issue
https://otwarchive.atlassian.net/browse/AO3-7143
Purpose
This adds the ability to filter collections on user pages like on the generic collections page.
Credit
Danaël / Rever (they / he)