Skip to content

Feature: filter presets#1994

Open
Evernight wants to merge 1 commit into
beancount:mainfrom
Evernight:filter-presets-pr
Open

Feature: filter presets#1994
Evernight wants to merge 1 commit into
beancount:mainfrom
Evernight:filter-presets-pr

Conversation

@Evernight

@Evernight Evernight commented Apr 29, 2025

Copy link
Copy Markdown

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

Screenshot 2025-04-29 at 14 16 01

Notes

Currently doesn't include documentation or tests, will add if the feature is generally approved.

@yagebu

yagebu commented May 20, 2025

Copy link
Copy Markdown
Member

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.

@Evernight

Copy link
Copy Markdown
Author

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:

  1. It adds one additional click to access functinality
  2. Needs some design so that current suggestions, recents, etc don't get all mixed up and there's some visual separation
  3. 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.

@yagebu

yagebu commented May 22, 2025

Copy link
Copy Markdown
Member

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)

@jgauth

jgauth commented Nov 14, 2025

Copy link
Copy Markdown

This would be a useful feature!

@Evernight

Copy link
Copy Markdown
Author

@jgauth thanks! if you're interesed in testing and using it, I patch Fava with this change relatively regularly to use in https://github.com/Evernight/lazy-beancount releases.

@yagebu

yagebu commented Jan 24, 2026

Copy link
Copy Markdown
Member

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

@Evernight are you planning to continue on this along those lines?

@Evernight

Copy link
Copy Markdown
Author

@yagebu do you think that would be useful? I could add something like that but not sure about real demand vs cost to support.

That wouldn't be able to tick all the same boxes of the functionality here because:

  1. Not sure how to implement having a highlight on what filters are enabled (in this implementation filter alias/link is highlighted as bold) in that case which is quite helpful. Practically, the extended filter box is currently mostly useful as an input, or for simple filterings (for example, a bunch of tags). But if the expression is more complex (e.g. like "any(account:...)"), it becomes impossible to tell what exactly is in there without copying the contents over to a separate text editor.
  2. More minor but my sidebar would become too crowded if all the links went there. Maybe an ability to group or add separators would help but then it adds a bit of complexity to the sidebar feature which not sure if you were considering.

If you think any additional work in that direction would be useful, I can look into that! I'm currently okay running that small patch on the side otherwise. In any case, feel free to close this PR, for anything discussed it would make more sense to send a new one.

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.

3 participants