瀏覽代碼

update schema

rcmerci 2 年之前
父節點
當前提交
b4c547654b
共有 3 個文件被更改,包括 25 次插入19 次删除
  1. 2 2
      deps/db/src/logseq/db/schema.cljs
  2. 3 3
      src/main/frontend/components/property.cljs
  3. 20 14
      src/main/frontend/handler/property.cljs

+ 2 - 2
deps/db/src/logseq/db/schema.cljs

@@ -20,6 +20,7 @@
    ;; "macros" for macro
    ;; "property" for property blocks
    :block/type {:db/index true}
+   :block/schema {}
    :block/uuid {:db/unique :db.unique/identity}
    :block/parent {:db/valueType :db.type/ref
                   :db/index true}
@@ -109,8 +110,7 @@
 (def schema-for-db-based-graph
   (merge
    schema
-   {:property/schema {}
-    :property/name {:db/unique :db.unique/identity}}))
+   {}))
 
 (defn get-schema
   ([]

+ 3 - 3
src/main/frontend/components/property.cljs

@@ -22,8 +22,8 @@
   (rum/local nil ::property-schema)
   {:will-mount (fn [state]
                  (let [[repo property-uuid] (:rum/args state)]
-                   (reset! (::property-name state) (:property/name (db/pull repo '[*] [:block/uuid property-uuid])))
-                   (reset! (::property-schema state) (:property/schema (db/pull repo '[*] [:block/uuid property-uuid])))
+                   (reset! (::property-name state) (:block/name (db/pull repo '[*] [:block/uuid property-uuid])))
+                   (reset! (::property-schema state) (:block/schema (db/pull repo '[*] [:block/uuid property-uuid])))
                    state))}
   [state repo property-uuid]
   (let [*property-name (::property-name state)
@@ -95,7 +95,7 @@
               [:div
                [:a.mr-2
                 {:on-click (fn [] (state/set-modal! #(property-class-config repo (uuid prop-uuid-or-built-in-prop))))}
-                (:property/name property-class)]
+                (:block/name property-class)]
                [:span v]
                [:a.ml-8 {:on-click
                          (fn []

+ 20 - 14
src/main/frontend/handler/property.cljs

@@ -12,20 +12,26 @@
             [frontend.modules.outliner.core :as outliner-core]
             [frontend.modules.outliner.transaction :as outliner-tx]
             [frontend.util.property-edit :as property-edit]
-            [malli.core :as m]))
+            [malli.core :as m]
+            [clojure.edn :as edn]
+            [frontend.handler.notification :as notification]))
 
 (defn add-property!
   [repo block k-name v]
-  (let [property-class      (db/pull repo '[*] [:property/name k-name])
-        property-class-uuid (or (:block/uuid property-class) (random-uuid))
-        tx-data (cond-> []
-                  (nil? property-class) (conj {:property/schema {}
-                                               :property/name k-name
-                                               :block/uuid property-class-uuid
-                                               :block/type "property"})
-                  true (conj {:block/uuid (:block/uuid block)
-                              :block/properties (assoc (:block/properties block) (str property-class-uuid) v)}))]
-    (db/transact! repo tx-data)))
+  (let [v*                  (edn/read-string v)
+        property-class      (db/pull repo '[*] [:block/name k-name])
+        property-class-uuid (or (:block/uuid property-class) (random-uuid))]
+    (if-let [msg (some-> (:block/schema property-class)
+                         (m/explain v*))]
+      (notification/show! msg :error false)
+      (let [tx-data (cond-> []
+                      (nil? property-class) (conj {:block/schema :any
+                                                   :block/name k-name
+                                                   :block/uuid property-class-uuid
+                                                   :block/type "property"})
+                      true (conj {:block/uuid (:block/uuid block)
+                                  :block/properties (assoc (:block/properties block) (str property-class-uuid) v*)}))]
+        (db/transact! repo tx-data)))))
 
 (defn remove-property!
   [repo block k-uuid-or-builtin-k-name]
@@ -41,8 +47,8 @@
   [repo property-uuid {:keys [property-name property-schema]}]
   {:pre [(uuid? property-uuid)]}
   (let [tx-data (cond-> {:block/uuid property-uuid}
-                  property-name (assoc :property/name property-name)
-                  property-schema (assoc :property/schema property-schema))]
+                  property-name (assoc :block/name property-name)
+                  property-schema (assoc :block/schema property-schema))]
     (db/transact! repo [tx-data])))
 
 (defn explain-property-value
@@ -50,7 +56,7 @@
   {:pre [(uuid? property-uuid)]}
   (let [prop-entity (db/entity repo [:block/uuid property-uuid])]
     (assert (= "property" (:block/type prop-entity)) prop-entity)
-    (when-let [schema (:property/schema prop-entity)]
+    (when-let [schema (:block/schema prop-entity)]
       (m/explain schema property-value))))
 
 (defn- extract-refs