Skip to content

Commit

Permalink
fix: filters not working for children blocks in linked references
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Aug 24, 2022
1 parent 43124f2 commit 1ee294e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,8 @@
*navigating-block (get state ::navigating-block)
navigating-block (rum/react *navigating-block)
navigated? (and (not= (:block/uuid block) navigating-block) navigating-block)
block (if navigated?
block (if (or (and custom-query? (empty? (:block/children block)))
navigated?)
(let [block (db/pull [:block/uuid navigating-block])
blocks (db/get-paginated-blocks repo (:db/id block)
{:scoped-block-id (:db/id block)})
Expand Down
3 changes: 2 additions & 1 deletion src/main/frontend/components/reference.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@
filters (when (seq filter-state)
(-> (group-by second filter-state)
(update-vals #(map first %))))
filtered-ref-blocks (block-handler/filter-blocks ref-blocks filters)
filtered-ref-blocks (->> (block-handler/filter-blocks ref-blocks filters)
(block-handler/get-filtered-ref-blocks-with-parents ref-blocks))
total (count top-level-blocks)
filtered-top-blocks (filter (fn [b] (top-level-blocks-ids (:db/id b))) filtered-ref-blocks)
filter-n (count filtered-top-blocks)
Expand Down
23 changes: 19 additions & 4 deletions src/main/frontend/handler/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,17 @@

(defn get-blocks-refed-pages
[aliases ref-blocks]
(let [refs (->> (mapcat (fn [b] (conj (:block/path-refs b) (:block/page b))) ref-blocks)
distinct
(remove #(aliases (:db/id %))))]
(let [refs (->> (mapcat :block/refs ref-blocks)
(remove #(aliases (:db/id %))))
pages (->> (map :block/page ref-blocks)
(distinct)
(remove #(aliases (:db/id %))))
all-refs (concat pages refs)]
(keep (fn [ref]
(when (:block/name ref)
{:db/id (:db/id ref)
:block/name (:block/name ref)
:block/original-name (:block/original-name ref)})) refs)))
:block/original-name (:block/original-name ref)})) all-refs)))

(defn filter-blocks
[ref-blocks filters]
Expand All @@ -276,3 +279,15 @@
(filter (fn [block]
(let [ids (set (map :db/id (:block/path-refs block)))]
(set/subset? include-ids ids))))))))

(defn get-filtered-ref-blocks-with-parents
[all-ref-blocks filtered-ref-blocks]
(when (seq filtered-ref-blocks)
(let [id->block (zipmap (map :db/id all-ref-blocks) all-ref-blocks)
get-parents (fn [block]
(loop [block block
result [block]]
(if-let [parent (id->block (:db/id (:block/parent block)))]
(recur parent (conj result parent))
result)))]
(distinct (mapcat get-parents filtered-ref-blocks)))))
12 changes: 6 additions & 6 deletions templates/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@
:default-queries
{:journals
[{:title "🔨 NOW"
:query [:find (pull ?h [*])
:query [:find (pull ?b [*])
:in $ ?start ?today
:where
[?h :block/marker ?marker]
[?b :block/marker ?marker]
[(contains? #{"NOW" "DOING"} ?marker)]
[?h :block/page ?p]
[?b :block/page ?p]
[?p :block/journal? true]
[?p :block/journal-day ?d]
[(>= ?d ?start)]
Expand All @@ -157,12 +157,12 @@
(get h :block/priority "Z")) result))
:collapsed? false}
{:title "📅 NEXT"
:query [:find (pull ?h [*])
:query [:find (pull ?b [*])
:in $ ?start ?next
:where
[?h :block/marker ?marker]
[?b :block/marker ?marker]
[(contains? #{"NOW" "LATER" "TODO"} ?marker)]
[?h :block/ref-pages ?p]
[?b :block/page ?p]
[?p :block/journal? true]
[?p :block/journal-day ?d]
[(> ?d ?start)]
Expand Down

0 comments on commit 1ee294e

Please sign in to comment.