فهرست منبع

fix: set class scope when using class as property

fixes https://github.com/logseq/db-test-cn/issues/38
Tienson Qin 1 سال پیش
والد
کامیت
1760161dd8
2فایلهای تغییر یافته به همراه19 افزوده شده و 15 حذف شده
  1. 1 14
      src/main/frontend/components/property.cljs
  2. 18 1
      src/main/frontend/components/property/value.cljs

+ 1 - 14
src/main/frontend/components/property.cljs

@@ -236,20 +236,7 @@
 
             ;; using class as property
             (and property (ldb/class? property))
-            (let [schema (assoc (:block/schema property)
-                                :type :node)]
-              (p/do!
-               (db/transact! (state/get-current-repo)
-                             [{:db/id (:db/id property)
-                               :db/ident (:db/ident property)
-                               :db/cardinality :db.cardinality/one
-                               :db/valueType :db.type/ref
-                               :db/index true
-                               :block/tags :logseq.class/Property
-                               :block/schema schema
-                               :property/schema.classes (:db/id property)}]
-                             {:outliner-op :save-block})
-               (reset! *show-new-property-config? false)))
+            (pv/<set-class-as-property! (state/get-current-repo) property)
 
             (or (not= :default type)
                 (and (= :default type) (seq (:property/closed-values property))))

+ 18 - 1
src/main/frontend/components/property/value.cljs

@@ -158,6 +158,20 @@
                                  (remove ldb/property?))]
     (or (seq selected-blocks) [block])))
 
+(defn <set-class-as-property!
+  [repo property]
+  (db/transact! repo
+                [{:db/id (:db/id property)
+                  :db/ident (:db/ident property)
+                  :db/cardinality :db.cardinality/one
+                  :db/valueType :db.type/ref
+                  :db/index true
+                  :block/tags :logseq.class/Property
+                  :block/schema (assoc (:block/schema property)
+                                       :type :node)
+                  :property/schema.classes (:db/id property)}]
+                {:outliner-op :save-block}))
+
 (defn <add-property!
   "If a class and in a class schema context, add the property to its schema.
   Otherwise, add a block's property and its value"
@@ -173,7 +187,10 @@
      (assert (qualified-keyword? property-id) "property to add must be a keyword")
      (p/do!
       (if (and class? class-schema?)
-        (db-property-handler/class-add-property! (:db/id block) property-id)
+        (p/do!
+         (when (ldb/class? property)
+           (<set-class-as-property! repo property))
+         (db-property-handler/class-add-property! (:db/id block) property-id))
         (let [block-ids (map :block/uuid blocks)]
           (if (and (db-property-type/all-ref-property-types (get-in property [:block/schema :type]))
                    (string? property-value))