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

Add ability to use Dataview expressions in custom rules #353

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ngsilverman
Copy link

Goal

I wanted the ability to define file icons based on dynamic rules, for example:

  • If the file has uncompleted tasks, show a particular icon.
  • If a property satisfies a given predicate.

Related Issues

Proposed Solution

I thought we could leverage Dataview expressions to create concise, powerful rules. And since Dataview functions can do various string operations, including regex matching, these new rules would be a superset of the current string/regex-powered rules.

Match a plain string

contains(this.file.path, "search string")

Match a regular expression

regextest("yes|no", this.file.name)

Match if the file has tasks and they are all complete

this.file.tasks and all(this.file.tasks, (t) => t.completed)

Match if a file property is present and has a non-null value

this.my-property

Match if a file is tagged

icontains(this.file.tags, "#my-tag")

And much more!

This should work with any Dataview expression so the custom rules can take into account any metadata provided by Dataview like outlinks, inlinks, aliases, bookmark status…

PR Status

This is a draft because I haven't fully wrapped my mind around how icons are refreshed. There seem to be a lot of events and conditions that factor in so I'm hoping to get some help from more knowledgeable contributors if this idea gets traction. With that said, this appears mostly functional, at least for the file explorer. I left some questions in the code diff.

TODO

  • Makes this backwards compatible with the previous rules system. For example, each rule could opt-in to use Dataview expressions, and the default could remain string/regex.
  • Test for all icon locations.
  • Write automated tests.

Testing

  • This has been loosely tested for files in the file explorer.
    • It seems to work with a few kinks—for example I noticed that sometimes some icons aren't refreshed when the rules change.
  • I did not test other possible icon locations (like tabs for example).

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.

1 participant