Browse Source

feat: allow tags to be hidden from node

By introducing a new property `:logseq.property.class/hide-from-node`.
Tienson Qin 1 year ago
parent
commit
f454e23120

+ 4 - 0
deps/db/src/logseq/db/frontend/property.cljs

@@ -47,6 +47,10 @@
                                                :cardinality :many
                                                :public? true
                                                :view-context :never}}
+   :logseq.property.class/hide-from-node {:title "Hide from node"
+                                          :schema {:type :checkbox
+                                                   :public? true
+                                                   :view-context :class}}
    :logseq.property/page-tags {:title "pageTags"
                                :schema {:type :page
                                         :public? true

+ 1 - 1
deps/db/src/logseq/db/frontend/schema.cljs

@@ -2,7 +2,7 @@
   "Main datascript schemas for the Logseq app"
   (:require [clojure.set :as set]))
 
-(def version 15)
+(def version 16)
 ;; A page is a special block, a page can corresponds to multiple files with the same ":block/name".
 (def ^:large-vars/data-var schema
   {:db/ident        {:db/unique :db.unique/identity}

+ 10 - 14
src/main/frontend/components/block.cljs

@@ -2387,15 +2387,14 @@
                    (str uuid "-" idx)))))]))))
 
 (rum/defc tags
-  "Tags without inline tags"
-  [config block hover? edit?]
+  "Tags without inline or hidden tags"
+  [config block]
   (when (:block/raw-title block)
-    (let [tags' (->>
-                 (:block/tags block)
-                 (remove (fn [t] (ldb/inline-tag? (:block/raw-title block) t))))
-          block-tags (if (and (not hover?) (not edit?) (= [:logseq.class/Task] (map :db/ident tags')))
-                       (remove (fn [t] (= (:db/ident t) :logseq.class/Task)) tags')
-                       tags')]
+    (let [block-tags (->>
+                      (:block/tags block)
+                      (remove (fn [t]
+                                (or (ldb/inline-tag? (:block/raw-title block) t)
+                                    (:logseq.property.class/hide-from-node t)))))]
       (when (seq block-tags)
         [:div.block-tags
          (for [tag block-tags]
@@ -2575,8 +2574,7 @@
                     ::hide-block-refs? (atom default-hide?)
                     ::refs-count *refs-count)))}
   [state config {:block/keys [uuid format] :as block} {:keys [edit-input-id block-id edit? hide-block-refs-count?]}]
-  (let [*hover? (::hover? state)
-        *hide-block-refs? (get state ::hide-block-refs?)
+  (let [*hide-block-refs? (get state ::hide-block-refs?)
         *refs-count (get state ::refs-count)
         hide-block-refs? (rum/react *hide-block-refs?)
         editor-box (state/get-component :editor/box)
@@ -2594,9 +2592,7 @@
                      (rum/react *refs-count))
         table? (:table? config)]
     [:div.block-content-or-editor-wrap
-     {:class (when (:page-title? config) "ls-page-title-container")
-      :on-mouse-over #(reset! *hover? true)
-      :on-mouse-leave #(reset! *hover? false)}
+     {:class (when (:page-title? config) "ls-page-title-container")}
      (when (and db-based? (not table?)) (block-positioned-properties config block :block-left))
      [:div.flex.flex-1.flex-col
       [:div.flex.flex-1.flex-row.gap-1.items-center
@@ -2646,7 +2642,7 @@
 
        (when-not (or (:block-ref? config) (:table? config))
          (when (and db-based? (seq (:block/tags block)))
-           (tags (assoc config :block/uuid (:block/uuid block)) block @*hover? edit?)))
+           (tags (assoc config :block/uuid (:block/uuid block)) block)))
 
        (when-not (or (:table? config) (:page-title? config))
          (block-refs-count block refs-count *hide-block-refs?))]

+ 2 - 1
src/main/frontend/worker/db/migrate.cljs

@@ -211,7 +211,8 @@
    [14 {:properties [:logseq.property/parent]
         :fix deprecate-class-parent}]
    [15 {:properties [:logseq.property.class/properties]
-        :fix deprecate-class-schema-properties}]])
+        :fix deprecate-class-schema-properties}]
+   [16 {:properties [:logseq.property.class/hide-from-node]}]])
 
 (let [max-schema-version (apply max (map first schema-version->updates))]
   (assert (<= db-schema/version max-schema-version))