Просмотр исходного кода

fix: page can have an alias block which doesn't work

Updates :block/tags to be type of `:class` and :block/alias to be
`:page`.

fixes https://linear.app/logseq/issue/LOG-3210/page-can-have-an-alias-block-which-doesnt-work
Tienson Qin 1 год назад
Родитель
Сommit
c90505c9a5

+ 2 - 2
deps/db/src/logseq/db/frontend/property.cljs

@@ -28,13 +28,13 @@
   (ordered-map
    :block/alias           {:title "Alias"
                            :attribute :block/alias
-                           :schema {:type :node
+                           :schema {:type :page
                                     :cardinality :many
                                     :view-context :page
                                     :public? true}}
    :block/tags           {:title "Tags"
                           :attribute :block/tags
-                          :schema {:type :node
+                          :schema {:type :class
                                    :cardinality :many
                                    :public? true
                                    :classes #{:logseq.class/Root}}}

+ 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 16)
+(def version 17)
 ;; 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}

+ 16 - 12
src/main/frontend/components/property/value.cljs

@@ -397,17 +397,22 @@
             classes)
 
            :else
-           (if (empty? result)
-             (let [v (get block (:db/ident property))]
-               (remove #(= :logseq.property/empty-placeholder (:db/ident %))
-                       (if (every? de/entity? v) v [v])))
-             (remove (fn [node]
-                       (or (= (:db/id block) (:db/id node))
-                            ;; A page's alias can't be itself
-                           (and alias? (= (or (:db/id (:block/page block))
-                                              (:db/id block))
-                                          (:db/id node)))))
-                     result))))
+           (let [property-type (get-in property [:block/schema :type])]
+             (if (empty? result)
+               (let [v (get block (:db/ident property))]
+                 (remove #(= :logseq.property/empty-placeholder (:db/ident %))
+                         (if (every? de/entity? v) v [v])))
+               (remove (fn [node]
+                         (or (= (:db/id block) (:db/id node))
+                             ;; A page's alias can't be itself
+                             (and alias? (= (or (:db/id (:block/page block))
+                                                (:db/id block))
+                                            (:db/id node)))
+                             (and property-type
+                                  (not= property-type :node)
+                                  (not= property-type (some-> (:block/type node) keyword)))))
+                       result)))))
+
         options (map (fn [node]
                        (let [id (or (:value node) (:db/id node))
                              label (if (integer? id)
@@ -493,7 +498,6 @@
                           "Escape"
                           (when-let [f (:on-chosen opts)] (f))
                           nil))})
-
         opts' (assoc opts
                      :block block
                      :input-opts input-opts

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

@@ -156,6 +156,21 @@
                       [:db/add id :logseq.property.class/properties value])
                     values))))))))))
 
+(defn- update-db-attrs-type
+  [conn _search-db]
+  (let [db @conn]
+    (when (ldb/db-based-graph? db)
+      (let [alias (d/entity db :block/alias)
+            tags (d/entity db :block/tags)]
+        [[:db/add (:db/id alias) :block/schema {:type :page
+                                                :cardinality :many
+                                                :view-context :page
+                                                :public? true}]
+         [:db/add (:db/id tags) :block/schema {:type :class
+                                               :cardinality :many
+                                               :public? true
+                                               :classes #{:logseq.class/Root}}]]))))
+
 (defn- add-addresses-in-kvs-table
   [^Object sqlite-db]
   (let [columns (->> (.exec sqlite-db #js {:sql "SELECT NAME FROM PRAGMA_TABLE_INFO('kvs')"
@@ -212,7 +227,8 @@
         :fix deprecate-class-parent}]
    [15 {:properties [:logseq.property.class/properties]
         :fix deprecate-class-schema-properties}]
-   [16 {:properties [:logseq.property.class/hide-from-node]}]])
+   [16 {:properties [:logseq.property.class/hide-from-node]}]
+   [17 {:fix update-db-attrs-type}]])
 
 (let [max-schema-version (apply max (map first schema-version->updates))]
   (assert (<= db-schema/version max-schema-version))

+ 1 - 1
src/main/frontend/worker/search.cljs

@@ -256,7 +256,7 @@ DROP TRIGGER IF EXISTS blocks_au;
    * :limit - Number of result to limit search results. Defaults to 100
    * :dev? - Allow all nodes to be seen for development. Defaults to false
    * :built-in?  - Whether to return public built-in nodes for db graphs. Defaults to false"
-  [repo conn search-db q {:keys [limit page enable-snippet?  built-in? dev?]
+  [repo conn search-db q {:keys [limit page enable-snippet? built-in? dev?]
                           :as option
                           :or {enable-snippet? true}}]
   (when-not (string/blank? q)