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

Fixed #27471 -- Made admin's filter choices collapsable. #15424

Merged

Conversation

mgaligniana
Copy link
Member

@mgaligniana mgaligniana commented Feb 14, 2022

This is the 2nd approach to solve ticket 27471 following the knyghty and pauloxnet suggest using details/summary elements

You can run test doing: ./runtests.py admin_changelist.tests.SeleniumTests.test_collapse_filters --selenium=chrome,firefox

Copy link
Member

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

Thanks for this @mgaligniana.

I think I much prefer the <details> approach over rebuilding that by hand, so let's focus effort here for the now. (We can always revert to the original approach if it doesn't work out, but it should...)

Two initial queries:

  • Can we style the disclosure element at all? The ▼/▶. Maybe that's fine, but are there options?
  • Can you think about @kezabelle's point from Fixed #27471 -- Make admin's list_filter choices collapsable #15331 about persistence? Otherwise I collapse the irrelevant filters, click a remaining relevant one, which triggers a reload, and then all the filters are back how they started. Session Storage should be fine. I guess a (sparse) per-changelist, per-filter reference to control the open state, applied on load, and stored on a change. … 🤔

I don't think I'd worry about auto-collapsing (< 10) here.

@matthiask
Copy link
Contributor

Here's a snippet which works well to remove the default styles:

summary {
  list-style: none;

  &::-webkit-details-marker {
    display: none;
  }
}

Now you can add custom styles via details[open] > summary and details > summary (or something like that)

@mgaligniana
Copy link
Member Author

mgaligniana commented Feb 20, 2022

Thanks @matthiask and @carltongibson

  • I re-styled the disclosure element following your comments and this answer at Stack Overflow

  • I added the persistence logic and updated the test!

Thank you again!

@mgaligniana mgaligniana force-pushed the ticket_27471_using_details_html_element branch from 2d829d7 to a8e1b43 Compare February 20, 2022 19:31
@mgaligniana mgaligniana force-pushed the ticket_27471_using_details_html_element branch 2 times, most recently from dfe301e to b13259d Compare March 6, 2022 23:12
@mgaligniana mgaligniana force-pushed the ticket_27471_using_details_html_element branch from b13259d to a64d6e4 Compare March 21, 2022 09:14
@@ -11,6 +11,7 @@
<link rel="stylesheet" href="{% static "admin/css/nav_sidebar.css" %}">
<script src="{% static 'admin/js/nav_sidebar.js' %}" defer></script>
{% endif %}
<script src="{% static 'admin/js/filters.js' %}" defer></script>
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if this is the correct to place the file and if the name is accurate 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I moved it to the templates/admin/change_list.html.

@mgaligniana mgaligniana force-pushed the ticket_27471_using_details_html_element branch from a64d6e4 to 19d841d Compare April 16, 2022 01:49
}

#changelist-filter details > summary::before {
content: '▶️';
Copy link
Member Author

@mgaligniana mgaligniana Apr 16, 2022

Choose a reason for hiding this comment

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

With [Linux|Chrome] I see the ▶️ like this:

image

Should I re-define or load another font?

Copy link
Member

Choose a reason for hiding this comment

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

Can we use arrows instead of emojis? ↓ → 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I'm not an UX expert, but they look nice and the same in all browsers:

  • Firefox:
    image
  • Chrome:
    image

Maybe bolded and with --link-hover-color to make it clear that they are clickable:

#changelist-filter details > summary::before {
    content: '→';
    font-weight: bold;
    color: var(--link-hover-color);
}

#changelist-filter details[open] > summary::before {
    content: '↓';
    font-weight: bold;
    color: var(--link-hover-color);
}

image

Copy link
Member Author

Choose a reason for hiding this comment

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

I really like it @felixxm! Styles updated.

@felixxm felixxm changed the title Fixed #27471 -- Make admin's list_filter choices collapsable Fixed #27471 -- Made admin's filter choices collapsable. Apr 25, 2022
@felixxm felixxm force-pushed the ticket_27471_using_details_html_element branch 2 times, most recently from 77160ca to fd8f894 Compare April 25, 2022 08:10
Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

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

@mgaligniana Thanks 👍 I pushed small edits and updated screenshots in docs.

@@ -11,6 +11,7 @@
<link rel="stylesheet" href="{% static "admin/css/nav_sidebar.css" %}">
<script src="{% static 'admin/js/nav_sidebar.js' %}" defer></script>
{% endif %}
<script src="{% static 'admin/js/filters.js' %}" defer></script>
Copy link
Member

Choose a reason for hiding this comment

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

I moved it to the templates/admin/change_list.html.

@mgaligniana
Copy link
Member Author

@felixxm I know this is not the appropriate place to ask a question unrelated to the pull request but I just read the Django contributing Git guideline and it says:

Note that user.name should be your real name, not your GitHub nick.

I noticed mine is my GitHub username. Does it affect in any way? Should we document the reason?

@felixxm felixxm force-pushed the ticket_27471_using_details_html_element branch from fd8f894 to b42488b Compare April 25, 2022 15:59
@felixxm
Copy link
Member

felixxm commented Apr 25, 2022

I noticed mine is my GitHub username. Does it affect in any way? Should we document the reason?

Don't worry it's not a blocker. I updated the author's description.

@felixxm felixxm force-pushed the ticket_27471_using_details_html_element branch from b42488b to 27aa703 Compare April 26, 2022 06:45
@carltongibson carltongibson removed their request for review April 26, 2022 09:20
@felixxm felixxm merged commit 27aa703 into django:main Apr 26, 2022
@felixxm felixxm temporarily deployed to schedules April 27, 2022 03:20 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants