Skip to content

Flyout: sort by version number, not lexicographically #222

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

Closed
astrojuanlu opened this issue Dec 19, 2023 · 7 comments · Fixed by readthedocs/readthedocs.org#11069
Closed
Assignees
Labels
Improvement Minor improvement to code

Comments

@astrojuanlu
Copy link

Right now versions are sorted in alphabetical/lexicographical order, which produces some funny results

image

@humitos
Copy link
Member

humitos commented Dec 19, 2023

I made the decision of sorting the version alphabetically by default on purpose. This is mainly to have a pretty simple and well defined sorting algorithm that everybody can easily understand.

In the old flyout, we use a pretty custom sorting algorithm that almost nobody understands, has lot of edge cases, and it's not possible to change without breaking people's documentation. I'm trying to avoid this pattern in the new flyout implementation.

This is the code of the "custom sorting algorithm" ™️ :

My idea is to make the sorting algorithm configurable via readthedocs/ext-theme#211 by exposing different sorting options to users, making each of them as clear as possible to manage different use cases (e.g. alphabetically, CalVer, SemVer, etc).

I don't know when this is going to be available, but I remember having issues on the logic for SemVer when working on the notifications addon at #71 and that's why I ended up implementing a pretty basic "is latest or non-stable" logic for that addon. Hopefully, we can find a way to make SemVer as simple as it seems without unexpected behaviors.

That said, I'd appreciate any feedback anyone can provide here. I will take it into consideration when jumping into this work 👍🏼

@humitos humitos added the Improvement Minor improvement to code label Dec 19, 2023
@humitos humitos changed the title Sort by version number, not lexicographically Flyout: sort by version number, not lexicographically Dec 19, 2023
@humitos
Copy link
Member

humitos commented Jan 26, 2024

Interesting. While doing some research about how to implement this, I found that depending on the PEP440 pattern you choose, it may be possible to sort it lexicographically or not: https://github.com/mbarkhau/bumpver#pattern-examples

humitos added a commit to readthedocs/readthedocs.org that referenced this issue Jan 26, 2024
Allow users to choose one of the pre-defined algorithms:

- Lexicographically
- SemVer (Read the Docs)
- CalVer
- Custom pattern

The sorting algorithm is implemented in the backend. So, the list returned under
`addons.flyout.versions` will be sorted acordingly the algorithm the user chose.
There is no need to do anything extra in the front-end.

The algorithm follows the next general rule: _"all the versions that don't match the
pattern defined, are considered invalid and sorted lexicographically between
them and added to the end of the list"_. That means that valid versions will
appear always first in the list and sorted together with other _valid versions_.

There is one _key feature_ here and is that the user can define any pattern
supported by `bumpver`, which is the module we use behind the scenes to perform
the sorting. See https://github.com/mbarkhau/bumpver#pattern-examples

On the other hand, `SemVer (Read the Docs)` is implemented used the exact same
code we were using for the old flyout implementation. This is mainly to keep
backward compatibility, but its usage is not recommended since it's pretty hard
to explain to users and hide non-clear/weird behavior.

Closes readthedocs/addons#222
@humitos
Copy link
Member

humitos commented Jan 26, 2024

I opened a PR for this and I'd appreciate any feedback you may have about it: readthedocs/readthedocs.org#11069. It implements different sorting algorithms and let the user to choose between them or create their own if required.

@github-project-automation github-project-automation bot moved this to Planned in 📍Roadmap Jan 29, 2024
@humitos humitos moved this from Planned to In progress in 📍Roadmap Feb 1, 2024
@humitos humitos moved this from In progress to Needs review in 📍Roadmap Mar 4, 2024
@astrojuanlu
Copy link
Author

I didn't forget about this 🙏🏽

@humitos
Copy link
Member

humitos commented Mar 7, 2024

@astrojuanlu Thanks for the ping. Everything is on its place. The PR is waiting for a final review. Hopefully, it will be deployed next Tuesday.

humitos added a commit to readthedocs/readthedocs.org that referenced this issue Mar 12, 2024
* Addons: sorting algorithm for versions customizable on flyout

Allow users to choose one of the pre-defined algorithms:

- Lexicographically
- SemVer (Read the Docs)
- CalVer
- Custom pattern

The sorting algorithm is implemented in the backend. So, the list returned under
`addons.flyout.versions` will be sorted acordingly the algorithm the user chose.
There is no need to do anything extra in the front-end.

The algorithm follows the next general rule: _"all the versions that don't match the
pattern defined, are considered invalid and sorted lexicographically between
them and added to the end of the list"_. That means that valid versions will
appear always first in the list and sorted together with other _valid versions_.

There is one _key feature_ here and is that the user can define any pattern
supported by `bumpver`, which is the module we use behind the scenes to perform
the sorting. See https://github.com/mbarkhau/bumpver#pattern-examples

On the other hand, `SemVer (Read the Docs)` is implemented used the exact same
code we were using for the old flyout implementation. This is mainly to keep
backward compatibility, but its usage is not recommended since it's pretty hard
to explain to users and hide non-clear/weird behavior.

Closes readthedocs/addons#222

* Use alphabetically instead of lexicographically

* Link BumpVer pattern examples

* Migration help_text

* Add bumpver as requirements

* Addons: allow to put `stable` and `latest` first when sorting

* Mark the string as translatable

* Install `bumpver` in the requirements

* Migrations update

* Rename field to match sorting (latest, stable)

* Fix migrations

* Fix algorithms

* Add tests for sorting algorithms

* Minor fixes

* Add tests for `AddonsConfigForm`

* Test: reduce the number of queries in 1

* Use descending sorting for _valid versions_

It makes more sense to show `latest  stable  <newest>` than `<oldest>` first.
#11069 (comment)
@github-project-automation github-project-automation bot moved this from Needs review to Done in 📍Roadmap Mar 12, 2024
@humitos
Copy link
Member

humitos commented Mar 12, 2024

A feature to sort versions in the beta addons flyout was released today. To enable this feature, you will need to activate the new beta addons in your project first, and then edit the sorting from the project's setting using the new beta dashboard from https://beta.readthedocs.org/. Please, let me know any feedback you may have 🙏🏼

Screenshot_2024-03-12_16-36-16

@astrojuanlu
Copy link
Author

Before After
Screenshot 2024-03-17 at 15-44-57 Welcome to Kedro’s award-winning documentation! — kedro 0 19 3 documentation Screenshot 2024-03-17 at 15-45-09 Welcome to Kedro’s award-winning documentation! — kedro 0 19 3 documentation

Thank you ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Minor improvement to code
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants