Skip to content

Commit 2de6597

Browse files
committed
fix: hide tag alias conversion action
1 parent 4914119 commit 2de6597

3 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/main/frontend/components/editor.cljs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@
172172
:other-attrs {:block/link (:db/id page')}}))))
173173
(page-handler/on-chosen-handler input id pos format)))
174174

175+
(defn- class-alias?
176+
[page]
177+
(some ldb/class? (:block/_alias page)))
178+
175179
(defn- matched-pages-with-new-page [partial-matched-pages db-tag? q]
176180
(let [ids (db/page-exists? q (if db-tag?
177181
#{:logseq.class/Tag}
@@ -180,7 +184,7 @@
180184
db-class/page-classes))
181185
page-exists? (some (fn [id] (nil? (:block/parent (db/entity id)))) ids)]
182186
(if (or page-exists?
183-
(and db-tag? (some ldb/class? (:block/_alias (db/get-page q)))))
187+
(and db-tag? (class-alias? (db/get-page q))))
184188
partial-matched-pages
185189
(if db-tag?
186190
(concat
@@ -200,7 +204,8 @@
200204
(let [classes (editor-handler/get-matched-classes q)]
201205
(if (and (ldb/internal-page? block)
202206
(= (:block/title block) q)
203-
(not (ldb/built-in? block)))
207+
(not (ldb/built-in? block))
208+
(not (class-alias? block)))
204209
(cons {:block/title q
205210
:db/id (:db/id block)
206211
:block/uuid (:block/uuid block)

src/main/frontend/handler/editor.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,8 @@
16021602
non-page-block?
16031603
(conj (db/entity :logseq.class/Page)))
16041604
classes (->> all-classes
1605+
(mapcat (fn [class]
1606+
(conj (:block/alias class) class)))
16051607
(common-util/distinct-by :db/id)
16061608
(map (fn [e] (select-keys e [:block/uuid :block/title]))))]
16071609
(search/fuzzy-search classes q {:extract-fn :block/title})))

src/test/frontend/handler/editor_test.cljs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
(ns frontend.handler.editor-test
2-
(:require [clojure.test :refer [deftest is testing use-fixtures]]
2+
(:require [clojure.test :refer [async deftest is testing use-fixtures]]
33
[frontend.commands :as commands]
4+
[frontend.components.editor :as editor-component]
45
[frontend.db :as db]
6+
[frontend.db.async :as db-async]
57
[frontend.db.model :as model]
68
[frontend.handler.editor :as editor]
79
[frontend.state :as state]
810
[frontend.test.helper :as test-helper]
911
[frontend.util :as util]
1012
[frontend.util.cursor :as cursor]
1113
[goog.dom :as gdom]
12-
[logseq.outliner.core :as outliner-core]))
14+
[logseq.outliner.core :as outliner-core]
15+
[promesa.core :as p]))
1316

14-
(use-fixtures :each test-helper/start-and-destroy-db)
17+
(use-fixtures :each {:before test-helper/start-test-db!
18+
:after (fn []
19+
(state/set-current-repo! nil)
20+
(test-helper/destroy-test-db!))})
1521

1622
(deftest extract-nearest-link-from-text-test
1723
(testing "Page, block and tag links"
@@ -122,19 +128,38 @@
122128
;; Reset state
123129
(state/set-editor-action! nil))
124130

125-
(deftest get-matched-classes-excludes-class-aliases
131+
(defn- create-tag-with-alias!
132+
[]
126133
(test-helper/create-page! "Project Tag" :redirect? false :class? true)
127134
(test-helper/create-page! "Alias Only" :redirect? false)
128135
(let [class (db/get-case-page "Project Tag")
129136
alias (db/get-case-page "Alias Only")]
130137
(db/transact! test-helper/test-db [{:db/id (:db/id class)
131-
:block/alias #{(:db/id alias)}}]))
138+
:block/alias #{(:db/id alias)}}])))
139+
140+
(deftest get-matched-classes-includes-class-aliases
141+
(create-tag-with-alias!)
132142
(is (= ["Project Tag"]
133143
(map :block/title (editor/get-matched-classes "Project Tag")))
134144
"Existing tag title matching still works")
135-
(is (empty? (filter #(= "Alias Only" (:block/title %))
136-
(editor/get-matched-classes "Alias Only")))
137-
"Tag aliases are not separate tag completion choices"))
145+
(is (= ["Alias Only"]
146+
(map :block/title (editor/get-matched-classes "Alias Only")))
147+
"Tag aliases stay available as tag completion choices"))
148+
149+
(deftest tag-search-does-not-convert-class-aliases
150+
(async done
151+
(create-tag-with-alias!)
152+
(let [matched-pages (atom nil)]
153+
(-> (p/with-redefs [db-async/<get-block (fn [_repo _title _opts]
154+
(p/resolved (db/get-page "Alias Only")))]
155+
(#'editor-component/search-pages "Alias Only" true #(reset! matched-pages %)))
156+
(.then
157+
(fn []
158+
(is (some #(= "Alias Only" (:block/title %)) @matched-pages)
159+
"The alias is still selectable from tag completion")
160+
(is (not-any? :convert-page-to-tag? @matched-pages)
161+
"A class alias must not show a redundant Convert action")
162+
(done)))))))
138163

139164
(defn- default-keyup-result
140165
[{:keys [value cursor-pos key code action is-processed?]

0 commit comments

Comments
 (0)