Kaynağa Gözat

refactor: use :string type only for internal properties

Tienson Qin 1 yıl önce
ebeveyn
işleme
4a9aa50a7d

+ 5 - 5
deps/db/src/logseq/db/frontend/property/type.cljs

@@ -12,17 +12,17 @@
 
 (def internal-built-in-property-types
   "Valid property types only for use by internal built-in-properties"
-  #{:keyword :map :coll :any :entity})
+  #{:string :keyword :map :coll :any :entity})
 
 (def user-built-in-property-types
   "Valid property types for users in order they appear in the UI"
-  [:default :string :number :date :checkbox :url :page :template])
+  [:default :number :date :checkbox :url :page :template])
 
 (def closed-value-property-types
   "Valid schema :type for closed values"
-  #{:string :number :url})
+  #{:default :string :number :url})
 
-(assert (set/subset? closed-value-property-types (set user-built-in-property-types))
+(assert (set/subset? closed-value-property-types (set (conj user-built-in-property-types :string)))
         "All closed value types are valid property types")
 
 (def ref-property-types
@@ -47,7 +47,7 @@
                :template #{:classes}
                :checkbox #{}}))
 
-(assert (= (set user-built-in-property-types) (set (keys user-built-in-allowed-schema-attributes)))
+(assert (= (set user-built-in-property-types) (set (remove #{:string} (keys user-built-in-allowed-schema-attributes))))
         "Each user built in type should have an allowed schema attribute")
 
 ;; Property value validation

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

@@ -98,7 +98,7 @@
   [property-type]
   (case property-type
     :default
-    "Text block"
+    "Text"
     :string
     "Text"
     ((comp string/capitalize name) property-type)))

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

@@ -599,7 +599,7 @@
           popup-content (fn content-fn [_]
                           [:div.property-select
                            (case type
-                             (:string :number :url)
+                             (:string :number :url :default)
                              (select block property select-opts' opts)
 
                              (:page :date)

+ 8 - 5
src/main/frontend/handler/db_based/property.cljs

@@ -594,16 +594,19 @@
     (let [values' (remove string/blank? values)
           property-schema (:block/schema property)]
       (if (every? uuid? values')
-        (p/let [value-ids (vec (remove #(nil? (db/entity [:block/uuid %])) values'))]
-          (when (seq value-ids)
+        (p/let [values (keep #(db/entity [:block/uuid %]) values')]
+          (when (seq values)
             (let [property-tx {:db/ident (:db/ident property)
                                :db/valueType :db.type/ref
                                :db/cardinality (:db/cardinality property)
                                :block/schema property-schema}
-                  value-property-tx (map (fn [id] [:db/add [:block/uuid id] :property/value-property (:db/id property)]) value-ids)]
+                  value-property-tx (map (fn [id]
+                                           {:db/id id
+                                            :block/type "closed value"
+                                            :block/closed-value-property (:db/id property)})
+                                         (map :db/id values))]
               (db/transact! (state/get-current-repo) (cons property-tx value-property-tx)
-                            {:outliner-op :insert-blocks})
-              value-ids)))
+                            {:outliner-op :insert-blocks}))))
         (p/let [property-id (:db/ident property)
                 page (get-property-hidden-page property)
                 page-tx (when-not (e/entity? page) page)