Skip to content

feat: Adds support for :query-page as an input - #8449

Merged
logseq-cldwalker merged 2 commits into
masterfrom
ben/current-and-query-page-inputs
Jan 31, 2023
Merged

logseq-cldwalker merged 2 commits into
masterfrom
ben/current-and-query-page-inputs

Conversation

@bendyorke

@bendyorke bendyorke commented Jan 27, 2023 •

Copy link
Copy Markdown
Contributor

This adds support for :query-page as an input for advanced queries. This resolves issues such as #6528 (I'll look up more issues in a moment).

Logseq at the moment provides a :current-page and <% current page %> input type that resolves to the page open in the current window. Embedding blocks that contain any queries using these inputs causes the results to change depending on where the block is shown. This adds an alternate input :query-page, that will resolve to the page of the block of that query originally comes from.

Currently this does not add <% query page %> to simple queries, as we are not currently providing the current block id to simple queries which makes it a little tricker, and this is namely to support the journal day queries in advanced queries. That functionality should maybe be added eventually.

Here is a screenshot showing the test cases in action, with four queries from #task-a, and the same four queries embedded from a page on #task-b.

Screenshot 2023-01-27 at 19 12 10

The four queries are:

{{query (and (task TODO) <% current page %>)}}

#+BEGIN_QUERY
{:title "Todos with current page"
 :query [:find (pull ?b [*])
              :in $ ?current-page 
              :where [?p :block/name ?current-page] 
                           [?b :block/marker "TODO"] 
                           [?b :block/ref-pages ?p] 
 :inputs [:current-page]}
#+END_QUERY

{{query (and (task TODO) <% query page %>)}}

#+BEGIN_QUERY
{:title "Todos with query page"
 :query [:find (pull ?b [*])
              :in $ ?query-page 
              :where [?p :block/name ?query-page] 
                           [?b :block/marker "TODO"] 
                           [?b :block/ref-pages ?p]]
 :inputs [:query-page]}
#+END_QUERY

@Bad3r

Bad3r commented Jan 27, 2023 •

Copy link
Copy Markdown
Collaborator

@bendyorke is this a new feature, an enhancement or a bug fix?

@Bad3r Bad3r added this to the 0.8.17 milestone Jan 27, 2023
@bendyorke bendyorke added the :type/feature New feature label Jan 27, 2023
@bendyorke

Copy link
Copy Markdown
Contributor Author

@Bad3r technically a new feature I guess, however it fixes a couple issues people are having embedding queries. I've added the feature label

@Bad3r

Bad3r commented Jan 27, 2023 •

Copy link
Copy Markdown
Collaborator

@Bad3r technically a new feature I guess, however it fixes a couple issues people are having embedding queries. I've added the feature label

I see, thank you! btw, if you add feat: to the start of the PR name; it will automatically add the feature label. Same for fix: or enhance: accordingly.
it also helps when writing release notes.

@logseq-cldwalker

logseq-cldwalker commented Jan 31, 2023 •

Copy link
Copy Markdown
Collaborator

This resolves issues such as #6528 (I'll look up more issues in a moment).

This PR doesn't resolve that issue as it is for a simple query, which has a different implementation than the advanced query that this PR touches. This is noticeable as the two queries have different results for the case that the user shared:

Screen Shot 2023-01-31 at 3 35 50 PM

Here's the steps to reproduce:

  • Create a journal page with:
- https://github.com/logseq/logseq/pull/8449  
	- TODO some  #other-tag  
	- TODO Write [[page 8449]]
	-  {{embed [[page 8449]]}}

In page "page 8449":

- {{query((and (task TODO) <% current page %>))}}
- #+BEGIN_QUERY
{:title "Advanced query todos with current page"
 :query [:find (pull ?b [*])
            :in $ ?current-page 
            :where [?p :block/name ?current-page] 
                         [?b :block/marker "TODO"] 
                         [?b :block/ref-pages ?p]] 
 :inputs [:current-page]}
#+END_QUERY 

A followup PR to add this functionality to the simple query would be nice some time

@logseq-cldwalker logseq-cldwalker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bendyorke Thanks for adding a useful input for embed contexts! 👍 ⚡Would be great to have this documented along with inputs from #8387

(is (= ["+1d" "now"] (blocks-journaled-between-inputs :today :today/+1d))
":today/+1d and today resolve to correct journal range")))

(deftest resolve-input-for-query-page

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

:in $ ?start ?end
:where (between ?b ?start ?end)]})))

; (let [block-uuid (-> (db-utils/q '[:find (pull ?b [:block/uuid])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some debugging stuff to remove. Easy enough to fix

@logseq-cldwalker
logseq-cldwalker force-pushed the ben/current-and-query-page-inputs branch from 8bc52e1 to 19c2f44 Compare January 31, 2023 20:45
@logseq-cldwalker
logseq-cldwalker merged commit c0d81dd into master Jan 31, 2023
@logseq-cldwalker
logseq-cldwalker deleted the ben/current-and-query-page-inputs branch January 31, 2023 21:05
@Bad3r Bad3r changed the title Adds support for :query-page as an input feat: Adds support for :query-page as an input Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants