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

Enhance: Add :remove-block-children? query option for advanced queries and an advanced query :template fix #9229

Merged
merged 4 commits into from Apr 25, 2023

Conversation

logseq-cldwalker
Copy link
Collaborator

This PR adds an option to make removing block children optional for a query and fixes bugs #3260 and #9045. The query option :remove-block-children? is added because there are times when we want to see block children e.g. when using the :current-block input. I still left children removal as the default as most users probably want the parent block when doing tag/page-ref searches e.g. #6406. To QA this option, try:

- #+BEGIN_QUERY
{:title "Count under current block"
:inputs [:current-block]
:query [:find (count ?b)
  :in $ ?current-block
  :where [?b :block/parent ?current-block]]
  ;; This query only works when this option is added
:remove-block-children? false}
   - b1
   - b2
#+END_QUERY

The second commit removes the removal of template blocks as it prevents using from querying their template blocks e.g. #3260.

@github-actions github-actions bot added the :type/enhancement Enhancement to product. Does not affect the overall basic use. label Apr 24, 2023
(db/custom-query-result-transform query-result remove-blocks q))
(cond-> (db/custom-query-result-transform query-result remove-blocks q)
(get q :remove-block-children? true)
tree/filter-top-level-blocks))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tree filtering was moved here because modifying results outside of get-query-result results in the query counts being wrong

@logseq-cldwalker logseq-cldwalker changed the title Enhance: Add :remove-block-children? query option Enhance: Add :remove-block-children? query option for advanced queries and an advanced query :template fix Apr 24, 2023
Copy link
Contributor

@tiensonqin tiensonqin left a comment

Choose a reason for hiding this comment

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

QAed and works as described!

I made a minor change to apply only tree/filter-top-level-blocks when the query results are blocks, so the blocks count and other queries that return non-blocks don't have to include :remove-block-children: false.

Copy link
Collaborator

@andelf andelf left a comment

Choose a reason for hiding this comment

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

LGTM, work as expected.

logseq-cldwalker and others added 4 commits April 25, 2023 15:20
There are cases where we want to see block children e.g. using the
:current-block input. Still kept the existing behavior as most users
probably still want children removed. Also fix result count when
removing children
@tiensonqin tiensonqin force-pushed the enhance/add-remove-block-children-option branch from fff3f71 to f0dbcf7 Compare April 25, 2023 07:20
@andelf andelf merged commit 1067ffd into master Apr 25, 2023
6 checks passed
@andelf andelf deleted the enhance/add-remove-block-children-option branch April 25, 2023 11:56
@logseq-cldwalker
Copy link
Collaborator Author

I made a minor change to apply only tree/filter-top-level-blocks when the query results are blocks, so the blocks count and other queries that return non-blocks don't have to include :remove-block-children: false.

Makes sense

@stdword
Copy link
Contributor

stdword commented Apr 25, 2023

@logseq-cldwalker is it a way now to position result on the same line as title?

I've tryed to use view, but result appears only on the second line:

#+BEGIN_QUERY
{:title "Count under current block"
:inputs [:current-block]
:query [:find (count ?b)
:in $ ?current-block
:where [?b :block/parent ?current-block]]
:view (fn [count] count)
:remove-block-children? false}
#+END_QUERY

@logseq-cldwalker
Copy link
Collaborator Author

logseq-cldwalker commented Apr 25, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:type/enhancement Enhancement to product. Does not affect the overall basic use.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants