Can I use existing logseq react (rum) components in a advanced query view function?

After digging in deep on how advanced queries are processed in the code, I am interested in leveraging advanced query custom view rendering but I don’t want to reinvent the wheel of what Logseq already renders.

Specifically, I would like to render a list of tasks blocks returned by an advanced query, NOT grouped by page, but displayed individually, sorted by some custom sorting logic and showing the breadcrumb for each. Pretty much what the Journal page shows under the NOW when there are open NOW tasks.

Is this possible? Can anyone show me some quick code snippets? TIA!


I would also really appreciate more transparency here, i.e. some insight into how logseq constructs its default query result renditions, what is actually returned by the database fetch and why and how to control it (what even is ?h in [:find (pull ?h [*])?). I find it difficult to even formulate what I would like to know exactly, that much is unclear to me.

Anyways. @webmonarch, you can see the default “NOW” query in the config.edn.

What seems to trigger your desired behaviour, though, is to run the fetched results through :result-transform. That will change the results in some way to which logseq then responds differently in some way. Here is also the place for custom sorting logic.

One thing I had been struggling to realize is to group tasks that are under the same parent block and to display them together under same breadcrumb. The default behavior now is that every block comes with its own breadcrumbs with potentially lots of repetitions all over the place. Those blocks will also not be displayed one after another, but again all over the place. Perhaps somebody could help with that?

Now, I beleive this is what you’re looking for:

  {:title [:h6 "Task List with Breadcrumbs"]
   :query [:find (pull ?h [*])
           [?h :block/marker ?m]
           [(= "TODO" ?m)]]
   (fn [result]
     ;; this is where the custom sorting logic would take place
     ;; unfortunately, I haven't had much success with it yet
     ;; from what I can tell, it is also here that you can put 
     ;; together lists and maps of data, you would like to access
     ;; in the subsequent `:view` section to construct completely
     ;; unique renditions of the output. How this all integrates
     ;; with logseq's peculiarities, however, is not at all clear to me.
     (->> result
          (sort-by (fn [h]
	        (get-in h [:block/page :block/name])))))
   :table-view? false} 
1 Like

Thanks @zeitlings, I essentially came to the conclusion you did. The default view logic built into Logseq has two code paths AFAICT, (1) grouped by page and (2) does not group by page. The existence of the :result-transform causes the code to NOT group by page and gives me the behavior I am looking for (code here) along with a few other conditions.

I am settling for the default non-grouped rendering with breadcrumbs for now. It’s a little noisy but working for my needs. I created a custom :result-transform function which I store in config.edn and refer to by name.

As for using Logseq components in custom view functions, I am not sure it is possible. It seems the user provided view functions are run in a sandbox that doesn’t have access to the Logseq namespaces :frowning: But I’d love to hear otherwise!

I second this notion - how do I recreate the grouped view with advanced queries? At least the rendering of the content, so that I get the styling on my todos etc.