fix: don't show block children in query-table

close #6406
pull/6412/head
Tienson Qin 2022-08-22 10:45:29 +08:00 committed by Andelf
parent e4beb653d4
commit 3c0387040f
3 changed files with 37 additions and 31 deletions

View File

@ -2416,7 +2416,7 @@
*navigating-block (get state ::navigating-block)
navigating-block (rum/react *navigating-block)
navigated? (and (not= (:block/uuid block) navigating-block) navigating-block)
block (if (or navigated? custom-query?)
block (if navigated?
(let [block (db/pull [:block/uuid navigating-block])
blocks (db/get-paginated-blocks repo (:db/id block)
{:scoped-block-id (:db/id block)})
@ -3322,28 +3322,6 @@
(cond-> option
(:document/mode? config) (assoc :class "doc-mode"))
(cond
(and (:ref? config) (:group-by-page? config))
[:div.flex.flex-col
(let [blocks (sort-by (comp :block/journal-day first) > blocks)]
(for [[page parent-blocks] blocks]
(ui/lazy-visible
(fn []
(let [alias? (:block/alias? page)
page (db/entity (:db/id page))]
[:div.my-2 (cond-> {:key (str "page-" (:db/id page))}
(:ref? config)
(assoc :class "color-level px-2 sm:px-7 py-2 rounded"))
(ui/foldable
[:div
(page-cp config page)
(when alias? [:span.text-sm.font-medium.opacity-50 " Alias"])]
(for [block parent-blocks]
(let [block' (update block :block/children tree/non-consecutive-blocks->vec-tree)]
(rum/with-key
(breadcrumb-with-container block' config)
(:db/id block'))))
{:debug-id page})])))))]
(and (:custom-query? config) (:group-by-page? config))
[:div.flex.flex-col
(let [blocks (sort-by (comp :block/journal-day first) > blocks)]
@ -3367,6 +3345,28 @@
{:debug-id page
:trigger-once? false})])))))]
(and (:ref? config) (:group-by-page? config))
[:div.flex.flex-col
(let [blocks (sort-by (comp :block/journal-day first) > blocks)]
(for [[page parent-blocks] blocks]
(ui/lazy-visible
(fn []
(let [alias? (:block/alias? page)
page (db/entity (:db/id page))]
[:div.my-2 (cond-> {:key (str "page-" (:db/id page))}
(:ref? config)
(assoc :class "color-level px-2 sm:px-7 py-2 rounded"))
(ui/foldable
[:div
(page-cp config page)
(when alias? [:span.text-sm.font-medium.opacity-50 " Alias"])]
(for [block parent-blocks]
(let [block' (update block :block/children tree/non-consecutive-blocks->vec-tree)]
(rum/with-key
(breadcrumb-with-container block' config)
(:db/id block'))))
{:debug-id page})])))))]
(and (:group-by-page? config)
(vector? (first blocks)))
[:div.flex.flex-col

View File

@ -10,7 +10,8 @@
[frontend.util.property :as property]
[frontend.format.block :as block]
[medley.core :as medley]
[rum.core :as rum]))
[rum.core :as rum]
[frontend.modules.outliner.tree :as tree]))
;; TODO: extract to table utils
(defn- sort-result-by
@ -82,7 +83,8 @@
(rum/local false ::select?)
[state config current-block result {:keys [page?]} map-inline page-cp ->elem inline-text]
(when current-block
(let [p-sort-by (keyword (get-in current-block [:block/properties :query-sort-by]))
(let [result (tree/filter-top-level-blocks result)
p-sort-by (keyword (get-in current-block [:block/properties :query-sort-by]))
p-desc? (get-in current-block [:block/properties :query-sort-desc])
select? (get state ::select?)
*sort-by-item (get state ::sort-by-item)

View File

@ -93,16 +93,20 @@
:block/page (:block/page e)
:block/refs (:block/refs e)})
(defn filter-top-level-blocks
[blocks]
(let [id->blocks (zipmap (map :db/id blocks) blocks)]
(filter #(nil?
(id->blocks
(:db/id (:block/parent (id->blocks (:db/id %)))))) blocks)))
(defn non-consecutive-blocks->vec-tree
"`blocks` need to be in the same page."
[blocks]
(let [blocks (map block-entity->map blocks)
parent->children (group-by :block/parent blocks)
id->blocks (zipmap (map :db/id blocks) blocks)
top-level-blocks (filter #(nil?
(id->blocks
(:db/id (:block/parent (id->blocks (:db/id %)))))) blocks)
top-level-blocks' (model/try-sort-by-left top-level-blocks (:block/parent (first top-level-blocks)))]
top-level-blocks (filter-top-level-blocks blocks)
top-level-blocks' (model/try-sort-by-left top-level-blocks (:block/parent (first top-level-blocks)))
parent->children (group-by :block/parent blocks)]
(map #(tree parent->children %) top-level-blocks')))
(defn- sort-blocks-aux