readthedocs.org
e4b9e123 - Addons: sorting algorithm for versions customizable on flyout (#11069)

Commit
1 year ago
Addons: sorting algorithm for versions customizable on flyout (#11069) * 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 https://github.com/readthedocs/addons/issues/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. https://github.com/readthedocs/readthedocs.org/pull/11069#discussion_r1515799263
Author
Parents
Loading