瀏覽代碼

refactor: provide default for build/prorties-ref-types

Reasonable default reduces building config which could change
Gabriel Horner 7 月之前
父節點
當前提交
103af910d0

+ 6 - 2
deps/db/src/logseq/db/sqlite/build.cljs

@@ -111,7 +111,10 @@
                    (let [property-map {:db/ident k
                                        :logseq.property/type built-in-type}]
                      [property-map v])
-                   (when-let [built-in-type' (get (:build/properties-ref-types new-block) built-in-type)]
+                   (when-let [built-in-type' (get (or (:build/properties-ref-types new-block)
+                                                      ;; Reasonable default for properties like logseq.property/default-value
+                                                      {:entity :number})
+                                                  built-in-type)]
                      (let [property-map {:db/ident k
                                          :logseq.property/type built-in-type'}]
                        [property-map v])))
@@ -730,7 +733,8 @@
      * :build/closed-values - Define closed values with a vec of maps. A map contains keys :uuid, :value and :icon.
      * :build/property-classes - Vec of class name keywords. Defines a property's range classes
      * :build/properties-ref-types - Map of internal ref types to public ref types that are valid only for this property.
-       Useful when remapping value ref types e.g. for :logseq.property/default-value
+       Useful when remapping value ref types e.g. for :logseq.property/default-value.
+       Default is `{:entity :number}`
      * :build/keep-uuid? - Keeps :block/uuid because another block depends on it
    * :classes - This is a map to configure classes where the keys are class name keywords
      and the values are maps of datascript attributes e.g. `{:block/title \"Foo\"}`.

+ 1 - 4
deps/db/src/logseq/db/sqlite/export.cljs

@@ -119,10 +119,7 @@
                     [(:db/ident ent)
                      (cond-> build-property
                        (seq ent-properties)
-                       (assoc :build/properties (buildable-properties db ent-properties properties-config options))
-                       ;; built-in properties with :entity need additional config
-                       (contains? ent-properties :logseq.property/default-value)
-                       (assoc :build/properties-ref-types {:entity :number}))])))
+                       (assoc :build/properties (buildable-properties db ent-properties properties-config options)))])))
            (into {}))
       properties-config)))
 

+ 2 - 5
deps/db/test/logseq/db/sqlite/export_test.cljs

@@ -264,7 +264,7 @@
 
     (import-second-time-assertions conn conn2 "page1" original-data)))
 
-(deftest ^:focus3 import-page-with-different-ref-types
+(deftest import-page-with-different-ref-types
   (let [block-uuid (random-uuid)
         internal-block-uuid (random-uuid)
         class-uuid (random-uuid)
@@ -548,7 +548,6 @@
          {:user.property/num {:logseq.property/type :number
                               :block/uuid property-uuid
                               :build/keep-uuid? true
-                              :build/properties-ref-types {:entity :number}
                               :build/properties (if exclude-namespaces?
                                                   {}
                                                   {:user.property/node #{[:block/uuid property-pvalue-uuid]}
@@ -641,7 +640,7 @@
            :file/content "// comment"}]}]
     original-data))
 
-(deftest ^:focus import-graph
+(deftest import-graph
   (let [original-data (build-original-graph-data)
         conn (db-test/create-conn-with-blocks (dissoc original-data ::sqlite-export/graph-files))
         _ (d/transact! conn (::sqlite-export/graph-files original-data))
@@ -687,8 +686,6 @@
         conn2 (db-test/create-conn)
         imported-graph (export-graph-and-import-to-another-graph conn conn2 {:include-timestamps? true})]
 
-    ;; (cljs.pprint/pprint (set (:pages-and-blocks original-data)))
-    ;; (cljs.pprint/pprint (set (:pages-and-blocks imported-graph)))
     ;; (cljs.pprint/pprint (butlast (clojure.data/diff (sort-pages-and-blocks (:pages-and-blocks original-data))
     ;;                                                 (:pages-and-blocks imported-graph))))
     (is (= (sort-pages-and-blocks (:pages-and-blocks original-data)) (:pages-and-blocks imported-graph)))

+ 0 - 1
src/main/frontend/handler/db_based/import.cljs

@@ -55,7 +55,6 @@
       {:error "An unexpected error occurred building the import. See the javascript console for details."})))
 
 (defn- import-edn-data-from-file
-  "Similar to import-submit"
   [export-map]
   (let [{:keys [init-tx block-props-tx misc-tx error] :as _txs} (safe-build-edn-import export-map {})]
     ;; (cljs.pprint/pprint _txs)