obsidian-meta-bind-plugin icon indicating copy to clipboard operation
obsidian-meta-bind-plugin copied to clipboard

The ability to limit optionQuery results based on frontmatter data

Open Davve37 opened this issue 1 year ago • 8 comments

Is your Feature Request Related to a Problem?

No response

Describe the Feature you'd Like

Currently optionQuery() only takes data sources input to limit the alternatives, but I need/want to specify notes more specifically, and would like to be able to restrict the options on frontmatter/property data as well.

Additional Context

No response

Davve37 avatar Feb 02 '24 13:02 Davve37

The current results are generated with dataview, so this would be a breaking change.

mProjectsCode avatar Mar 29 '24 16:03 mProjectsCode

The current results are generated with dataview, so this would be a breaking change.

Can you just extend the dataview input/return to include the .where attribute?

LynetteCullens avatar Jul 16 '24 20:07 LynetteCullens

I am not sure I get what you mean. Could you elaborate?

mProjectsCode avatar Jul 16 '24 21:07 mProjectsCode

I am not sure I get what you mean. Could you elaborate?

optionQuery("Glossary") is equivalent to dv.pages('"Glossary"').

I am asking if the .where can be used in addition to the dv.pages argument. Like this: dv.pages('"Glossary"').where(p => p.fileClass == 'Dimensions');

LynetteCullens avatar Jul 17 '24 01:07 LynetteCullens

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/4dc698adac1563765bb429d4454e12f13e87c4d2/packages/obsidian/src/modals/SuggesterModalHelper.ts#L46C55-L46C108

That could actually work, the only downside is that this would require users to write JS expressions.

mProjectsCode avatar Jul 17 '24 09:07 mProjectsCode

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/4dc698adac1563765bb429d4454e12f13e87c4d2/packages/obsidian/src/modals/SuggesterModalHelper.ts#L46C55-L46C108

That could actually work, the only downside is that this would require users to write JS expressions.

The where works the same in datviewjs as it does in normal DQL, but DQL does have less words. The query would be: FROM "Glossary" Where contains(fileClass, "Dimensions")

LynetteCullens avatar Jul 17 '24 16:07 LynetteCullens

The where works the same in datviewjs as it does in normal DQL, but DQL does have less words.

https://github.com/blacksmithgu/obsidian-dataview/blob/3c29f7cb5bb76f62b5342b88050e054a7272667f/src/api/data-array.ts#L27

Are you sure about that?

mProjectsCode avatar Jul 17 '24 16:07 mProjectsCode

The where works the same in datviewjs as it does in normal DQL, but DQL does have less words.

https://github.com/blacksmithgu/obsidian-dataview/blob/3c29f7cb5bb76f62b5342b88050e054a7272667f/src/api/data-array.ts#L27

Are you sure about that?

If you need an example....

Query One

Dataview

Table without ID
file.link, file.frontmatter.mathLink
From "Glossary"
Where contains(fileClass, "Dimensions")

image

Dataviewjs

const rows = dv.pages('"Glossary"').where(p => p.fileClass == 'Dimensions').map(p => [
		p.file.link, 
		p.file.frontmatter.mathLink]);
dv.table(["Link", "mathLink"], rows);

image

Query Two

Dataview

Table without ID
file.link, file.frontmatter.mathLink
From "Glossary"
Where !contains(fileClass, "Dimensions")
Limit 10

image

Dataviewjs

const rows = dv.pages('"Glossary"').where(p => p.fileClass !== 'Dimensions').map(p => [
		p.file.link, 
		p.file.frontmatter.mathLink]).limit(10);
dv.table(["Link", "mathLink"], rows);

image

LynetteCullens avatar Jul 18 '24 03:07 LynetteCullens