瀏覽代碼

enhance(ux): display tag extends before tag name

format: `#parent/child`, `#parent1 | parent2/child`, built-in tags
are ignored.
Tienson Qin 1 月之前
父節點
當前提交
48fb2b8179

+ 14 - 6
deps/db/src/logseq/db/frontend/db.cljs

@@ -4,6 +4,7 @@
             [clojure.string :as string]
             [datascript.core :as d]
             [logseq.common.config :as common-config]
+            [logseq.common.util :as common-util]
             [logseq.common.util.namespace :as ns-util]
             [logseq.common.util.page-ref :as page-ref]
             [logseq.common.uuid :as common-uuid]
@@ -57,12 +58,19 @@
 
 (defn get-class-title-with-extends
   [entity]
-  (let [parents' (->> (db-class/get-class-extends entity)
-                      (remove (fn [e] (= :logseq.class/Root (:db/ident e))))
-                      vec)]
-    (string/join
-     ns-util/parent-char
-     (map :block/title (conj parents' entity)))))
+  (let [extends (some->> (:logseq.property.class/extends entity)
+                         (remove (fn [extend]
+                                   (or (:logseq.property/built-in? extend)
+                                       (= (:block/title entity) (:block/title extend)))))
+                         vec)]
+    (if (seq extends)
+      (str (if (= 1 (count extends))
+             (:block/title (first extends))
+             (->> (take 2 extends)
+                  (map :block/title)
+                  (string/join " | ")))
+           ns-util/parent-char (:block/title entity))
+      (:block/title entity))))
 
 (defn get-title-with-parents
   [entity]

+ 2 - 1
src/main/frontend/components/all_pages.cljs

@@ -15,7 +15,8 @@
          :name (t :block/name)
          :cell (fn [_table row _column]
                  (component-block/page-cp {:show-non-exists-page? true
-                                           :skip-async-load? true} row))
+                                           :skip-async-load? true
+                                           :with-tags? false} row))
          :type :string}
         (when (not (config/db-based-graph? (state/get-current-repo)))
           {:id :block/type

+ 23 - 57
src/main/frontend/components/block.cljs

@@ -34,7 +34,6 @@
             [frontend.extensions.latex :as latex]
             [frontend.extensions.lightbox :as lightbox]
             [frontend.extensions.pdf.assets :as pdf-assets]
-            [frontend.extensions.pdf.utils :as pdf-utils]
             [frontend.extensions.sci :as sci]
             [frontend.extensions.video.youtube :as youtube]
             [frontend.extensions.zotero :as zotero]
@@ -84,7 +83,6 @@
             [logseq.common.util.page-ref :as page-ref]
             [logseq.db :as ldb]
             [logseq.db.common.entity-plus :as entity-plus]
-            [logseq.db.frontend.content :as db-content]
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.text :as text]
@@ -715,9 +713,9 @@
 
    All page-names are sanitized except page-name-in-block"
   [state
-   {:keys [contents-page? whiteboard-page? other-position? show-unique-title?
-           on-context-menu with-parent? stop-event-propagation?]
-    :or {with-parent? true}
+   {:keys [contents-page? whiteboard-page? other-position?
+           on-context-menu stop-event-propagation? with-tags?]
+    :or {with-tags? true}
     :as config}
    page-entity children label]
   (let [*mouse-down? (::mouse-down? state)
@@ -780,11 +778,6 @@
            [:span {:class (str "icon-emoji-wrap " (when emoji? "as-emoji"))}
             icon])))
 
-     (when (and (ldb/page? page-entity) with-parent?)
-       (when-let [parent (:block/parent page-entity)]
-         (when-not (ldb/library? parent)
-           [:span.select-none (str (:block/title parent) "/")])))
-
      [:span
       (if (and (coll? children) (seq children))
         (for [child children]
@@ -793,51 +786,25 @@
             (let [{:keys [content children]} (last child)
                   page-name (subs content 2 (- (count content) 2))]
               (rum/with-key (page-reference (assoc config :children children) page-name nil) page-name))))
-        (let [page-component (cond
-                               (and label
-                                    (string? label)
-                                    (not (string/blank? label)))                    ; alias
-                               label
-
-                               (coll? label)
-                               (->elem :span (map-inline config label))
-
-                               show-unique-title?
-                               (block-handler/block-unique-title page-entity)
-
-                               :else
-                               (let [title (:block/title page-entity)
-                                     s (cond untitled?
-                                             (t :untitled)
-
-                                             ;; The page-name-in-block generated by the auto-complete is not page-name-sanitized
-                                             (pdf-utils/hls-file? page-name)
-                                             (pdf-utils/fix-local-asset-pagename page-name)
-
-                                             (not= (util/safe-page-name-sanity-lc title) page-name)
-                                             page-name                  ;; page-name-in-block might be overridden (legacy))
-
-                                             title
-                                             (util/trim-safe title)
-
-                                             :else
-                                             (util/trim-safe page-name))
-                                     _ (when-not page-entity (js/console.warn "page-inner's page-entity is nil, given page-name: " page-name))
-                                     s (cond
-                                         (not (string? s))
-                                         (do
-                                           (prn :debug :unknown-title-error :title s
-                                                :data (db/pull (:db/id page-entity)))
-                                           "Unknown title")
-                                         (re-find db-content/id-ref-pattern s)
-                                         (db-content/content-id-ref->page s (:block/refs page-entity))
-                                         :else
-                                         s)
-                                     s (if (and tag? (not (:hide-tag-symbol? config))) (str "#" s) s)]
-                                 (if (ldb/page? page-entity)
-                                   s
-                                   (block-title (assoc config :page-ref? true) page-entity {}))))]
-          page-component))]]))
+        (cond
+          (and label
+               (string? label)
+               (not (string/blank? label)))                    ; alias
+          label
+
+          (coll? label)
+          (->elem :span (map-inline config label))
+
+          (ldb/page? page-entity)
+          (if untitled?
+            (t :untitled)
+            (let [s (util/trim-safe (block-handler/block-unique-title page-entity {:with-tags? with-tags?}))]
+              (if (and tag? (not (:hide-tag-symbol? config)))
+                (str "#" s)
+                s)))
+
+          :else
+          (block-title (assoc config :page-ref? true) page-entity {})))]]))
 
 (rum/defc popup-preview-impl
   [children {:keys [*timer *timer1 visible? set-visible! render *el-popup]}]
@@ -3302,8 +3269,7 @@
       (let [parents-props (doall
                            (for [{:block/keys [uuid name title] :as block} parents]
                              (if name
-                               [block (page-cp {:disable-preview? true
-                                                :with-parent? false} block) true]
+                               [block (page-cp {:disable-preview? true} block) true]
                                (let [result (block/parse-title-and-body
                                              uuid
                                              (get block :block/format :markdown)

+ 1 - 12
src/main/frontend/components/left_sidebar.cljs

@@ -12,7 +12,6 @@
             [frontend.db-mixins :as db-mixins]
             [frontend.db.model :as db-model]
             [frontend.extensions.fsrs :as fsrs]
-            [frontend.extensions.pdf.utils :as pdf-utils]
             [frontend.handler.block :as block-handler]
             [frontend.handler.page :as page-handler]
             [frontend.handler.recent :as recent-handler]
@@ -26,8 +25,6 @@
             [frontend.util :as util]
             [frontend.util.page :as page-util]
             [goog.object :as gobj]
-            [logseq.common.config :as common-config]
-            [logseq.common.util.namespace :as ns-util]
             [logseq.db :as ldb]
             [logseq.shui.hooks :as hooks]
             [logseq.shui.ui :as shui]
@@ -124,15 +121,7 @@
           (not (db/page? page))
           (block/inline-text :markdown (string/replace (apply str (take 64 (:block/title page))) "\n" " "))
           untitled? (t :untitled)
-          :else (let [title' (pdf-utils/fix-local-asset-pagename title)
-                      parent (:block/parent page)]
-                  (if (and parent
-                           (not (or (ldb/class? page)
-                                    (and (:logseq.property/built-in? parent)
-                                         (= (:block/title parent)
-                                            common-config/library-page-name)))))
-                    (str (:block/title parent) ns-util/parent-char title')
-                    title')))]
+          :else (block-handler/block-unique-title page))]
 
      ;; dots trigger
        (shui/button

+ 3 - 2
src/main/frontend/handler/block.cljs

@@ -134,7 +134,8 @@
 (defn block-unique-title
   "Multiple pages/objects may have the same `:block/title`.
    Notice: this doesn't prevent for pages/objects that have the same tag or created by different clients."
-  [block]
+  [block & {:keys [with-tags?]
+            :or {with-tags? true}}]
   (let [block-e (cond
                   (de/entity? block)
                   block
@@ -150,7 +151,7 @@
       (ldb/class? block)
       (ldb/get-class-title-with-extends block)
 
-      (seq tags)
+      (and with-tags? (seq tags))
       (str (:block/title block)
            " "
            (string/join