Skip to content

Commit 48fb2b8

Browse files
committed
enhance(ux): display tag extends before tag name
format: `#parent/child`, `#parent1 | parent2/child`, built-in tags are ignored.
1 parent 9eb65b4 commit 48fb2b8

File tree

5 files changed

+43
-78
lines changed

5 files changed

+43
-78
lines changed

deps/db/src/logseq/db/frontend/db.cljs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[clojure.string :as string]
55
[datascript.core :as d]
66
[logseq.common.config :as common-config]
7+
[logseq.common.util :as common-util]
78
[logseq.common.util.namespace :as ns-util]
89
[logseq.common.util.page-ref :as page-ref]
910
[logseq.common.uuid :as common-uuid]
@@ -57,12 +58,19 @@
5758

5859
(defn get-class-title-with-extends
5960
[entity]
60-
(let [parents' (->> (db-class/get-class-extends entity)
61-
(remove (fn [e] (= :logseq.class/Root (:db/ident e))))
62-
vec)]
63-
(string/join
64-
ns-util/parent-char
65-
(map :block/title (conj parents' entity)))))
61+
(let [extends (some->> (:logseq.property.class/extends entity)
62+
(remove (fn [extend]
63+
(or (:logseq.property/built-in? extend)
64+
(= (:block/title entity) (:block/title extend)))))
65+
vec)]
66+
(if (seq extends)
67+
(str (if (= 1 (count extends))
68+
(:block/title (first extends))
69+
(->> (take 2 extends)
70+
(map :block/title)
71+
(string/join " | ")))
72+
ns-util/parent-char (:block/title entity))
73+
(:block/title entity))))
6674

6775
(defn get-title-with-parents
6876
[entity]

src/main/frontend/components/all_pages.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
:name (t :block/name)
1616
:cell (fn [_table row _column]
1717
(component-block/page-cp {:show-non-exists-page? true
18-
:skip-async-load? true} row))
18+
:skip-async-load? true
19+
:with-tags? false} row))
1920
:type :string}
2021
(when (not (config/db-based-graph? (state/get-current-repo)))
2122
{:id :block/type

src/main/frontend/components/block.cljs

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
[frontend.extensions.latex :as latex]
3535
[frontend.extensions.lightbox :as lightbox]
3636
[frontend.extensions.pdf.assets :as pdf-assets]
37-
[frontend.extensions.pdf.utils :as pdf-utils]
3837
[frontend.extensions.sci :as sci]
3938
[frontend.extensions.video.youtube :as youtube]
4039
[frontend.extensions.zotero :as zotero]
@@ -84,7 +83,6 @@
8483
[logseq.common.util.page-ref :as page-ref]
8584
[logseq.db :as ldb]
8685
[logseq.db.common.entity-plus :as entity-plus]
87-
[logseq.db.frontend.content :as db-content]
8886
[logseq.graph-parser.block :as gp-block]
8987
[logseq.graph-parser.mldoc :as gp-mldoc]
9088
[logseq.graph-parser.text :as text]
@@ -715,9 +713,9 @@
715713
716714
All page-names are sanitized except page-name-in-block"
717715
[state
718-
{:keys [contents-page? whiteboard-page? other-position? show-unique-title?
719-
on-context-menu with-parent? stop-event-propagation?]
720-
:or {with-parent? true}
716+
{:keys [contents-page? whiteboard-page? other-position?
717+
on-context-menu stop-event-propagation? with-tags?]
718+
:or {with-tags? true}
721719
:as config}
722720
page-entity children label]
723721
(let [*mouse-down? (::mouse-down? state)
@@ -780,11 +778,6 @@
780778
[:span {:class (str "icon-emoji-wrap " (when emoji? "as-emoji"))}
781779
icon])))
782780

783-
(when (and (ldb/page? page-entity) with-parent?)
784-
(when-let [parent (:block/parent page-entity)]
785-
(when-not (ldb/library? parent)
786-
[:span.select-none (str (:block/title parent) "/")])))
787-
788781
[:span
789782
(if (and (coll? children) (seq children))
790783
(for [child children]
@@ -793,51 +786,25 @@
793786
(let [{:keys [content children]} (last child)
794787
page-name (subs content 2 (- (count content) 2))]
795788
(rum/with-key (page-reference (assoc config :children children) page-name nil) page-name))))
796-
(let [page-component (cond
797-
(and label
798-
(string? label)
799-
(not (string/blank? label))) ; alias
800-
label
801-
802-
(coll? label)
803-
(->elem :span (map-inline config label))
804-
805-
show-unique-title?
806-
(block-handler/block-unique-title page-entity)
807-
808-
:else
809-
(let [title (:block/title page-entity)
810-
s (cond untitled?
811-
(t :untitled)
812-
813-
;; The page-name-in-block generated by the auto-complete is not page-name-sanitized
814-
(pdf-utils/hls-file? page-name)
815-
(pdf-utils/fix-local-asset-pagename page-name)
816-
817-
(not= (util/safe-page-name-sanity-lc title) page-name)
818-
page-name ;; page-name-in-block might be overridden (legacy))
819-
820-
title
821-
(util/trim-safe title)
822-
823-
:else
824-
(util/trim-safe page-name))
825-
_ (when-not page-entity (js/console.warn "page-inner's page-entity is nil, given page-name: " page-name))
826-
s (cond
827-
(not (string? s))
828-
(do
829-
(prn :debug :unknown-title-error :title s
830-
:data (db/pull (:db/id page-entity)))
831-
"Unknown title")
832-
(re-find db-content/id-ref-pattern s)
833-
(db-content/content-id-ref->page s (:block/refs page-entity))
834-
:else
835-
s)
836-
s (if (and tag? (not (:hide-tag-symbol? config))) (str "#" s) s)]
837-
(if (ldb/page? page-entity)
838-
s
839-
(block-title (assoc config :page-ref? true) page-entity {}))))]
840-
page-component))]]))
789+
(cond
790+
(and label
791+
(string? label)
792+
(not (string/blank? label))) ; alias
793+
label
794+
795+
(coll? label)
796+
(->elem :span (map-inline config label))
797+
798+
(ldb/page? page-entity)
799+
(if untitled?
800+
(t :untitled)
801+
(let [s (util/trim-safe (block-handler/block-unique-title page-entity {:with-tags? with-tags?}))]
802+
(if (and tag? (not (:hide-tag-symbol? config)))
803+
(str "#" s)
804+
s)))
805+
806+
:else
807+
(block-title (assoc config :page-ref? true) page-entity {})))]]))
841808

842809
(rum/defc popup-preview-impl
843810
[children {:keys [*timer *timer1 visible? set-visible! render *el-popup]}]
@@ -3302,8 +3269,7 @@
33023269
(let [parents-props (doall
33033270
(for [{:block/keys [uuid name title] :as block} parents]
33043271
(if name
3305-
[block (page-cp {:disable-preview? true
3306-
:with-parent? false} block) true]
3272+
[block (page-cp {:disable-preview? true} block) true]
33073273
(let [result (block/parse-title-and-body
33083274
uuid
33093275
(get block :block/format :markdown)

src/main/frontend/components/left_sidebar.cljs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
[frontend.db-mixins :as db-mixins]
1313
[frontend.db.model :as db-model]
1414
[frontend.extensions.fsrs :as fsrs]
15-
[frontend.extensions.pdf.utils :as pdf-utils]
1615
[frontend.handler.block :as block-handler]
1716
[frontend.handler.page :as page-handler]
1817
[frontend.handler.recent :as recent-handler]
@@ -26,8 +25,6 @@
2625
[frontend.util :as util]
2726
[frontend.util.page :as page-util]
2827
[goog.object :as gobj]
29-
[logseq.common.config :as common-config]
30-
[logseq.common.util.namespace :as ns-util]
3128
[logseq.db :as ldb]
3229
[logseq.shui.hooks :as hooks]
3330
[logseq.shui.ui :as shui]
@@ -124,15 +121,7 @@
124121
(not (db/page? page))
125122
(block/inline-text :markdown (string/replace (apply str (take 64 (:block/title page))) "\n" " "))
126123
untitled? (t :untitled)
127-
:else (let [title' (pdf-utils/fix-local-asset-pagename title)
128-
parent (:block/parent page)]
129-
(if (and parent
130-
(not (or (ldb/class? page)
131-
(and (:logseq.property/built-in? parent)
132-
(= (:block/title parent)
133-
common-config/library-page-name)))))
134-
(str (:block/title parent) ns-util/parent-char title')
135-
title')))]
124+
:else (block-handler/block-unique-title page))]
136125

137126
;; dots trigger
138127
(shui/button

src/main/frontend/handler/block.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@
134134
(defn block-unique-title
135135
"Multiple pages/objects may have the same `:block/title`.
136136
Notice: this doesn't prevent for pages/objects that have the same tag or created by different clients."
137-
[block]
137+
[block & {:keys [with-tags?]
138+
:or {with-tags? true}}]
138139
(let [block-e (cond
139140
(de/entity? block)
140141
block
@@ -150,7 +151,7 @@
150151
(ldb/class? block)
151152
(ldb/get-class-title-with-extends block)
152153

153-
(seq tags)
154+
(and with-tags? (seq tags))
154155
(str (:block/title block)
155156
" "
156157
(string/join

0 commit comments

Comments
 (0)