Feature: filter presets
Motivation
I really like the filters functionality and use it extensively. However, in most cases you have to type some text in the filter fields and that text is often repeated. There are values that I use more frequently than others (e.g. month-1 or month-11 to month-1 for time, or some specific tag or posting filter for the advanced filter). It would be nice to be able to use them without having to type anything.
Current workarounds
Creating and storing links in a sidebar, bookmarks, dashboards or elsewhere. But it doesn't allow to mix and combine filters together. Also having to keep complicated Advanced filter strings somewhere in the notes.
Proposed implementation
Define filter presets in Fava config, similar to sidebar links. If any presets are defined, display them in a strip that extends the header. There are two types of presets: for time and advanced filters. Time is pretty self-explanatory. Advanced filters "toggle" on click so it's possible to combine them together separated by a space for AND logic. Uses simple substring match to avoid exposing lexer from Python (that overcomplicates things). Actual value of the filter and its label are separate, especially relevant for Advanced filter that may look rather complicated (that's one of the reasons for this feature)
Screenshot
Notes
Currently doesn't include documentation or tests, will add if the feature is generally approved.
Hi, thanks for the PR!
I see the ability to toggle filters more quickly as a useful feature but I don't think we should add a new configuration mechanism for this. To enable this via the existing sidebar links configuration (or bookmarks or whatever), I'd instead suggest creating a new URL route similar to jump that applies these filter transformations.
Or even better, additionally, to enable (some parts of this feature) without having any specific configuration, how about storing recent filters and adding them to the dropdowns? For the time filter examples in your screenshot I'd expect that to work quite well.
Hi, thanks for the reply!
To enable this via the existing sidebar links configuration (or bookmarks or whatever), I'd instead suggest creating a new URL route similar to jump that applies these filter transformations.
What you imagine these urls to look like? Do I understand correctly that it would be something that just toggles specific value (e.g. tag) in the filter, if clicked, but via routing? Also if you have code pointers for reference at hand, that'd be useful. I'll also need to learn a bit more about Svelte routing.
storing recent filters
Do you mean browser's local storage?
I've actually considered adding these to the dropdowns initially but:
- It adds one additional click to access functinality
- Needs some design so that current suggestions, recents, etc don't get all mixed up and there's some visual separation
- While for the time filter it's possible, for the given examples for the advanced filter it's more complicated. That's where aliases are more useful as sometimes filter values (especially when filtering by postings) may get long and complicated. For example, the current filter value field gets not so helpful relatively quickly as it's short, so I need to copy the text elsewhere to read.
As for sidebar links as an implementation, one reason I didn't go with this is that I already use those extensively. I have about dozen of presets for various pages, some with default time or advanced filter applied. Having more just makes the list less comprehensible (or asks for an ability to group links in the sidebar, for example). Also these "filter presets" are meant to be applied on top of already chosen path and to be combined together in various configurations.
In any case, happy to keep in running in the fork on a side as it works well for me. But was wondering if there's anything code- or idea- wise that would be useful for the mainstream.
What you imagine these urls to look like? Do I understand correctly that it would be something that just toggles specific value (e.g. tag) in the filter, if clicked, but via routing? Also if you have code pointers for reference at hand, that'd be useful. I'll also need to learn a bit more about Svelte routing.
Not frontend route, a flask HTTP endpoint. See the jump route for what's currently implemented (which already supports setting a time filter with it): https://github.com/beancount/fava/blob/main/src/fava/application.py#L443
Do you mean browser's local storage?
Yes.
It would be one extra click on use but not require any manual configuration (but if you want to have it immediately accessible, you could still add a sidebar link for it)
This would be a useful feature!