Problem/Motivation
Facets soft limits JS is breaking facets tree manipulations.
I built a custom module that interacts with the facet list to become collapsible if you have a hierarchical facet.
With the current implementation, the selector used in soft-limit.js breaks if some facet results are still hidden (which could make sense with a collapsible hierarchy).
Steps to reproduce
Consider the following hierarchical facet:
Tree:
- Val 1
- Val 2
-- Val 2.1
-- Val 2.2
--- Val 2.2.1
--- Val 2.2.2
- Val 3
- Val 4
-- Val 4.1
-- Val 4.1.2
- Val 5
- Val 6
- Val 7
With a soft limit of 5 items, Val 1, Val 2, Val 3, Val 4, Val 5 are visible by default. If you click on "view more", Val 6 and Val 7 are shown. If you click on "view less", the values 6 and 7 are hidden. This is consistent.
Now, if you add some JS logic to let the hierarchy be collapsible, the default output of the facet is:
- Val 1
- Val 2
- Val 3
- Val 4
- Val 5
- Val 6
- Val 7
The soft limit shows Val 1 to 5. If you click on "view more", you see Val 6 and Val 7 BUT if you click on "view less", Val 6 and Var 7 are not hidden due to the fact that Val 2.1, Val 2.2 and so on are still hidden.
This is due to the current selector used in the script.
Proposed resolution
Change the selector to apply to direct children li.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 3208580-facets-soft-limit-issue.patch | 1.1 KB | foxy-vikvik |
| #16 | 3208580-soft-limit-with-hierarchical.patch | 1.27 KB | foxy-vikvik |
Issue fork facets-3208580
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
pfrenssenRebased on 2.0.x. I made a backup of the original patch against an outdated version of 8.x-1.x available in a separate branch: 3208580-soft-limits-are-8.x-1.x.
Comment #5
pfrenssenComment #6
pfrenssenComment #7
pfrenssen@artusamak do you want to change the merge base from 8.x-1.x to 2.0.x in https://git.drupalcode.org/project/facets/-/merge_requests/17 ? Thanks!
Comment #8
artusamakDone @pfrenssen
Comment #11
dimilias commentedThis works fine for us. We are using the one which contains also the 0 limit addition. +1 RTBC.
Comment #12
stopopol commented+1
Comment #13
saidatomComment #15
smustgrave commentedWould be good to get this one in.
Comment #16
foxy-vikvik commentedFor the "drupal/facets": "^3.0@beta"
In this case, button will be hide ONLY one level items
Comment #17
foxy-vikvik commentedFor the "drupal/facets": "^3.0@beta"
This is working for all levels.
Comment #20
strykaizer