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

ENH: add optional extra_classes in version-switcher #576

Merged
merged 6 commits into from
Feb 9, 2022

Conversation

tupui
Copy link
Contributor

@tupui tupui commented Jan 20, 2022

Closes #566

Allow to specify additional classes per version in switcher.json.

Right now it adds the classes for all the versions. So a user might want to combine this with "active" if it's purely for styling otherwise it could make a Christmas tree in the dropdown. I could move the logic into the version check, but I was not sure if there was other use cases this could be used for.

@tupui
Copy link
Contributor Author

tupui commented Jan 20, 2022

Failure in CI seems unrelated.

@drammock
Copy link
Collaborator

This is different from what I was expecting, which was that the extra classes get added to the parent node (the drop-down button, not the individual entries). It will require checking whether the version in entry is the "current" version being viewed. The idea was that, e.g., the drop-down button could be red on outdated docs and green on stable and yellow on dev. But in all cases the drop-down entries have the same set of classes.

@tupui
Copy link
Contributor Author

tupui commented Jan 24, 2022

This is different from what I was expecting, which was that the extra classes get added to the parent node (the drop-down button, not the individual entries). It will require checking whether the version in entry is the "current" version being viewed. The idea was that, e.g., the drop-down button could be red on outdated docs and green on stable and yellow on dev. But in all cases the drop-down entries have the same set of classes.

I thought about the same and the reason I did it like this for now is that I was not sure if there might be other things people would want to do with this feature. You could add different markers, or shades, hide some elements based on some other context, etc.

I can move the block to the active only section so that it only applies there.

@larsoner @jorisvandenbossche what do you think?

@jorisvandenbossche
Copy link
Member

I was also assuming this was about the dropdown "button", not entries. See also my comment at scipy/scipy#15380 (comment)

If we all initially thought about a class for the button, then I would propose to first tackle that. We can still later see if there is demand for classes in the dropdown entries, but I would personally wait until there are actual use cases.

@tupui tupui force-pushed the extra_class_switcher branch from 1bc50f3 to e98bd62 Compare January 24, 2022 21:19
@tupui
Copy link
Contributor Author

tupui commented Jan 24, 2022

I updated the PR to only apply the classes when an element is active.

// Add extra class to the entry
if ("extra_classes" in entry) {
$.each(entry.extra_classes, function(index, extra_class) {
node.classList.add(extra_class);
Copy link
Member

Choose a reason for hiding this comment

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

This is still adding the class to the entry link, I think? (although now only to the active version)

if I understand correctly, the current code will add the class in the html (as it is after being generated with the javascript, simplified a bit for explanation purposes) where I labeled it "HERE" (so in the first <a> node):

<div class="dropdown show" id="version_switcher">
  <button type="button" class="..." id="version_switcher_button" ...>
    0.8.0 <span class="caret"></span>
  </button>
  <div id="version_switcher_menu" class="dropdown-menu ..." ...>
    <a class="list-group-item ... HERE" href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.1/index.html">v0.8.0 (stable)</a>
    <a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.1/index.html">v0.7.1</a>
    <a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.0/index.html" >0.7.0</a >
    ...
  </div>
</div>

While my understanding is that we want to be able to color the dropdown button, so have it instead at this location:

<div class="dropdown show" id="version_switcher">
  <button type="button" class="... HERE" id="version_switcher_button" ...>
    0.8.0 <span class="caret"></span>
  </button>
  <div id="version_switcher_menu" class="dropdown-menu ..." ...>
    <a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.1/index.html">v0.8.0 (stable)</a>
    <a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.1/index.html">v0.7.1</a>
    <a class="list-group-item ..." href="https://pydata-sphinx-theme.readthedocs.io/en/v0.7.0/index.html" >0.7.0</a >
    ...
  </div>
</div>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah ok I see. I move the code to version_switcher_button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes are in. Can you have another look @jorisvandenbossche?

@tupui tupui force-pushed the extra_class_switcher branch 2 times, most recently from 8b5f2bb to f168b98 Compare January 25, 2022 11:24
@tupui tupui force-pushed the extra_class_switcher branch from f168b98 to c50de2d Compare January 25, 2022 11:27
@damianavila
Copy link
Collaborator

+1, but wondering if we should showcase this on our site...

The idea was that, e.g., the drop-down button could be red on outdated docs and green on stable and yellow on dev. But in all cases the drop-down entries have the same set of classes.

Related to #574

@tupui
Copy link
Contributor Author

tupui commented Jan 27, 2022

+1, but wondering if we should showcase this on our site...

The idea was that, e.g., the drop-down button could be red on outdated docs and green on stable and yellow on dev. But in all cases the drop-down entries have the same set of classes.

Related to #574

@damianavila do you prefer that I copy this phrasing over what I put now in the doc?

  • extra_classes: an optional list of classes to add to the switcher
    button for a given version (e.g., ["dev", "rc"]). These classes are only
    added when the version is active.

EDIT: ok understood what you meant 😅 The demo site should show this.

@jorisvandenbossche
Copy link
Member

wondering if we should showcase this on our site...

Ideally yes, but I think that will require #574 to first be merged

@tupui
Copy link
Contributor Author

tupui commented Jan 27, 2022

wondering if we should showcase this on our site...

Ideally yes, but I think that will require #574 to first be merged

@jorisvandenbossche If this PR goes in first, you can showcase the behaviour in #574

@tupui
Copy link
Contributor Author

tupui commented Feb 7, 2022

@drammock @jorisvandenbossche @damianavila can you please take another look?

Copy link
Collaborator

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

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

This looks good to me - just one quick comment in there in case people give a string, but this looks good to me when that is resolved

@@ -72,6 +72,12 @@
if (entry.version == "{{ theme_switcher.get('version_match') }}") {
node.classList.add("active");
$("#version_switcher_button").text(entry.name);
// Add extra class to the button for the selected entry
if ("extra_classes" in entry) {
$.each(entry.extra_classes, function(index, extra_class) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I would not add complexity here. But I can make the change if you want.

I think the suggestion is not correct as the type check should happen before iterating on the list of classes. (But I am really a novice on JS so I could be missing something as well)

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK sounds good, let me re-work this so it's a one-liner then

@@ -72,6 +72,12 @@
if (entry.version == "{{ theme_switcher.get('version_match') }}") {
node.classList.add("active");
$("#version_switcher_button").text(entry.name);
// Add extra class to the button for the selected entry
if ("extra_classes" in entry) {
$.each(entry.extra_classes, function(index, extra_class) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I would not add complexity here. But I can make the change if you want.

I think the suggestion is not correct as the type check should happen before iterating on the list of classes. (But I am really a novice on JS so I could be missing something as well)

Copy link
Collaborator

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

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

OK I added in a quick one-liner replacement to make it simpler.

I'm OK merging this in unless anybody else objects. But I'll note that I don't feel good about merging in a PR that we cannot test in our test suite, and that we cannot demo in our demo documentation. :-/

…ersion-switcher.html

Co-authored-by: Chris Holdgraf <choldgraf@gmail.com>
@tupui
Copy link
Contributor Author

tupui commented Feb 8, 2022

Thanks for reviewing @choldgraf.

OK I added in a quick one-liner replacement to make it simpler.

I'm OK merging this in unless anybody else objects. But I'll note that I don't feel good about merging in a PR that we cannot test in our test suite, and that we cannot demo in our demo documentation. :-/

I guess you (I am not sure I would know what to do but I can try 😅) can update your PR #584 when this goes in. Also when this is in, #574 can be updated to reflect the last 2 PRs.

@tupui
Copy link
Contributor Author

tupui commented Feb 9, 2022

I resolved the conflicts. Had a quick look at the test you added @choldgraf but I don't understand how to adjust it for this PR (if I can since you added a note about not testing the JS).

@choldgraf
Copy link
Collaborator

Let's just merge this in, and add tests in the future once we figure out the right infrastructure. Maybe @jorisvandenbossche would be willing to add in some "extra classes" in #574 to test this out, and we can make a patch PR if something isn't working as expected.

Copy link
Collaborator

@choldgraf choldgraf left a comment

Choose a reason for hiding this comment

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

Thanks @tupui for the improvement!

@choldgraf choldgraf merged commit c987276 into pydata:master Feb 9, 2022
@tupui
Copy link
Contributor Author

tupui commented Feb 9, 2022

Sounds good, thanks 😃 !! Can't wait for the next release to use this.

@tupui tupui deleted the extra_class_switcher branch February 9, 2022 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow adding extra, version-specific css classes to the version dropdown
5 participants