From 3c0387040fecb626f1e9d482262b86b7097ea78c Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 22 Aug 2022 10:45:29 +0800 Subject: [PATCH] fix: don't show block children in query-table close #6406 --- src/main/frontend/components/block.cljs | 46 +++++++++---------- src/main/frontend/components/query_table.cljs | 6 ++- src/main/frontend/modules/outliner/tree.cljs | 16 ++++--- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 5764a0ae9..99ab08e72 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -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 diff --git a/src/main/frontend/components/query_table.cljs b/src/main/frontend/components/query_table.cljs index cec7f8432..127e790c0 100644 --- a/src/main/frontend/components/query_table.cljs +++ b/src/main/frontend/components/query_table.cljs @@ -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) diff --git a/src/main/frontend/modules/outliner/tree.cljs b/src/main/frontend/modules/outliner/tree.cljs index 8e85f75ab..3ce9f1990 100644 --- a/src/main/frontend/modules/outliner/tree.cljs +++ b/src/main/frontend/modules/outliner/tree.cljs @@ -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