Browse Source

fix: wrong arguments

Tienson Qin 1 year ago
parent
commit
9115ca72ad

+ 1 - 3
deps/db/src/logseq/db/frontend/property.cljs

@@ -6,9 +6,6 @@
             [logseq.common.util :as common-util]
             [clojure.string :as string]))
 
-(def first-stage-properties
-  #{:built-in? :created-from-property})
-
 ;; FIXME: no support for built-in-extended-properties
 (def ^:large-vars/data-var built-in-properties
   "Map of built in properties for db graphs. Each property has a config map with
@@ -251,6 +248,7 @@
   [k]
   (contains? #{:logseq.property :user.property} (keyword (namespace k))))
 
+;; TODO: db ident should obey clojure's rules for keywords
 (defn get-db-ident-from-name
   [property-name]
   (let [n (-> (string/lower-case property-name)

+ 2 - 2
src/main/frontend/components/block.cljs

@@ -645,8 +645,8 @@
              (util/stop e)
              (db-property-handler/delete-property-value! repo
                                                          block
-                                                         (db-pu/get-built-in-property-uuid repo :tags)
-                                                         (:block/uuid page-entity)))}
+                                                         :block/tags
+                                                         (:db/id page-entity)))}
           (ui/icon "x" {:size 15})]))]))
 
 (rum/defc page-preview-trigger

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

@@ -14,7 +14,6 @@
             [frontend.handler.notification :as notification]
             [frontend.handler.property :as property-handler]
             [frontend.handler.page :as page-handler]
-            [frontend.handler.db-based.property.util :as db-pu]
             [frontend.modules.shortcut.core :as shortcut]
             [frontend.search :as search]
             [frontend.state :as state]
@@ -202,7 +201,7 @@
   {:init (fn [state]
            (let [*values (atom :loading)]
              (p/let [result (db-async/<get-block-property-values (state/get-current-repo)
-                                                                 (:block/uuid (first (:rum/args state))))]
+                                                                 (:db/ident (first (:rum/args state))))]
                (reset! *values result))
              (assoc state ::values *values)))
    :will-mount (fn [state]

+ 1 - 2
src/main/frontend/components/property/closed_value.cljs

@@ -16,7 +16,6 @@
             [frontend.db :as db]
             [frontend.db.async :as db-async]
             [frontend.state :as state]
-            [frontend.handler.property.util :as pu]
             [promesa.core :as p]
             [logseq.db.frontend.property :as db-property]))
 
@@ -222,7 +221,7 @@
          :size :sm
          :on-click
          (fn [e]
-           (p/let [values (db-async/<get-block-property-values (state/get-current-repo) (:block/uuid property))]
+           (p/let [values (db-async/<get-block-property-values (state/get-current-repo) (:db/ident property))]
              (shui/popup-show! (.-target e)
                                (fn [{:keys [id]}]
                                  (let [opts {:toggle-fn (fn [] (shui/popup-hide! id))}

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

@@ -20,7 +20,6 @@
             [lambdaisland.glogi :as log]
             [rum.core :as rum]
             [frontend.handler.route :as route-handler]
-            [frontend.handler.property.util :as pu]
             [promesa.core :as p]
             [frontend.db.async :as db-async]
             [logseq.common.util.macro :as macro-util]
@@ -398,7 +397,7 @@
   {:init (fn [state]
            (let [*values (atom :loading)]
              (p/let [result (db-async/<get-block-property-values (state/get-current-repo)
-                                                                 (:block/uuid (nth (:rum/args state) 1)))]
+                                                                 (:db/ident (nth (:rum/args state) 1)))]
                (reset! *values result))
              (assoc state ::values *values)))}
   [state block property

+ 21 - 31
src/main/frontend/handler/db_based/property.cljs

@@ -132,16 +132,15 @@
             tags-or-alias? (contains? #{:block/tags :block/alias} property-id)
             old-values (if tags-or-alias?
                          (->> (get block property-id)
-                              (map (fn [e] (:block/uuid e))))
+                              (map (fn [e] (:db/id e))))
                          (get block (:db/ident property)))]
         (when (not= old-values values')
           (if tags-or-alias?
-            (let [property-value-ids (map (fn [id] (:db/id (db/entity [:block/uuid id]))) values')]
-              (db/transact! repo
-                            [[:db/retract (:db/id block) property-id]
-                             {:block/uuid block-id
-                              property-id property-value-ids}]
-                            {:outliner-op :save-block}))
+            (db/transact! repo
+                          [[:db/retract (:db/id block) property-id]
+                           {:block/uuid block-id
+                            property-id values'}]
+                          {:outliner-op :save-block})
             (if-let [msg (some #(validate-property-value schema %) values')]
               (let [msg' (str "\"" property-name "\"" " " (if (coll? msg) (first msg) msg))]
                 (notification/show! msg' :warning))
@@ -152,7 +151,7 @@
                   (db/transact! repo [block] {:outliner-op :save-block}))))))))))
 
 (defn- resolve-tag
-  "Change `v` to a tag's UUID if v is a string tag, e.g. `#book`"
+  "Change `v` to a tag's db id if v is a string tag, e.g. `#book`"
   [v]
   (when (and (string? v)
              (util/tag? (string/trim v)))
@@ -170,7 +169,7 @@
                                   :block/type #{"class"})]
                      (db/transact! [m])
                      m))]
-          (:block/uuid e'))))))
+          (:db/id e'))))))
 
 (defn set-block-property!
   [repo block-eid property-id v {:keys [old-value] :as opts}]
@@ -204,7 +203,7 @@
                          nil)))
                 tags-or-alias? (and (contains? #{:block/tags :block/alias} property-id) (uuid? v*))]
             (if tags-or-alias?
-              (let [property-value-id (:db/id (db/entity [:block/uuid v*]))]
+              (let [property-value-id v*]
                 (db/transact! repo
                               [[:db/add (:db/id block) property-id property-value-id]]
                               {:outliner-op :save-block}))
@@ -281,18 +280,13 @@
                       {:outliner-op :save-block})))))
 
 (defn class-remove-property!
-  [repo class-uuid k-uuid]
+  [repo class-uuid property-id]
   (when-let [class (db/entity repo [:block/uuid class-uuid])]
     (when (contains? (:block/type class) "class")
-      (when-let [property (db/entity repo [:block/uuid k-uuid])]
+      (when-let [property (db/entity repo property-id)]
         (when-not (ldb/built-in-class-property? (db/get-db) class property)
-          (let [property-uuid (:block/uuid property)
-                {:keys [properties] :as class-schema} (:block/schema class)
-                new-properties (vec (distinct (remove #{property-uuid} properties)))
-                class-new-schema (assoc class-schema :properties new-properties)]
-            (db/transact! repo [{:db/id (:db/id class)
-                                 :block/schema class-new-schema}]
-                          {:outliner-op :save-block})))))))
+          (db/transact! repo [[:db/retract (:db/id class) :class/schema.properties property-id]]
+            {:outliner-op :save-block}))))))
 
 (defn class-set-schema!
   [repo class-uuid schema]
@@ -376,20 +370,16 @@
 (defn delete-property-value!
   "Delete value if a property has multiple values"
   [repo block property-id property-value]
-  (when (and block (uuid? property-id))
-    (when (not= property-id (:block/uuid block))
-      (when-let [property (db/pull [:block/uuid property-id])]
+  (when block
+    (when (not= property-id (:db/ident block))
+      (when-let [property (db/entity property-id)]
         (let [schema (:block/schema property)
               db-ident (:db/ident property)
-              property-id (:db/ident property)
-              tags-or-alias? (and (contains? #{:block/tags :block/alias} db-ident)
-                                  (uuid? property-value))]
+              tags-or-alias? (contains? #{:block/tags :block/alias} db-ident)]
           (if tags-or-alias?
-            (let [property-value-id (:db/id (db/entity [:block/uuid property-value]))]
-              (when property-value-id
-                (db/transact! repo
-                              [[:db/retract (:db/id block) db-ident property-value-id]]
-                              {:outliner-op :save-block})))
+            (db/transact! repo
+                          [[:db/retract (:db/id block) db-ident property-value]]
+                          {:outliner-op :save-block})
             (if (= :many (:cardinality schema))
               (db/transact! repo
                             [[:db/retract (:db/id block) property-id]]
@@ -688,7 +678,7 @@
                 new-value-ids (mapv :block/uuid closed-value-blocks)
                 property-tx {:db/id (:db/id property)
                              :block/schema (assoc property-schema :values new-value-ids)}
-                property-values (db-async/<get-block-property-values (state/get-current-repo) (:block/uuid property))
+                property-values (db-async/<get-block-property-values (state/get-current-repo) (:db/ident property))
                 block-values (->> property-values
                                   (remove #(uuid? (first %))))
                 tx-data (concat