Browse Source

fix: update schema for latest changes to closed values

part of LOG-2871
Gabriel Horner 2 years ago
parent
commit
86eb1b394d

+ 6 - 5
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -78,8 +78,8 @@
   [[:block/uuid :uuid]
    [:block/created-at :int]
    [:block/updated-at :int]
-   [:block/properties {:optional true} block-properties]
    [:block/format [:enum :markdown]]
+   [:block/properties {:optional true} block-properties]
    [:block/refs {:optional true} [:set :int]]
    [:block/tags {:optional true} [:set :int]]
    [:block/tx-id {:optional true} :int]])
@@ -130,9 +130,9 @@
    [:description {:optional true} :string]
    ;; For any types except for :checkbox :default :template :enum
    [:cardinality {:optional true} [:enum :one :many]]
-   ;; closed values
+   ;; For closed values
    [:values {:optional true}  [:vector :uuid]]
-   ;; Just for :enum
+   ;; For closed values
    [:position {:optional true} :string]
    ;; For :page and :template
    [:classes {:optional true} [:set [:or :uuid :keyword]]]])
@@ -240,11 +240,12 @@
     [[:block/type [:= #{"closed value"}]]
      [:block/schema {:optional true}
       [:map
-       [:description :string]]]
+       [:value [:or :string :double]]
+       [:description {:optional true} :string]]]
      [:block/metadata
       [:map
        [:created-from-property :uuid]]]]
-    (remove #(= :block/metadata (first %)) block-attrs)
+    (remove #(#{:block/metadata :block/content} (first %)) block-attrs)
     page-or-block-attrs)))
 
 (def normal-block

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

@@ -1,6 +1,7 @@
 (ns logseq.db.frontend.property.type
   "Provides property types including fns to validate them"
-  (:require [datascript.core :as d]))
+  (:require [datascript.core :as d]
+            [clojure.set :as set]))
 
 (def internal-builtin-schema-types
   "Valid schema :type only to be used by built-in-properties"
@@ -11,9 +12,12 @@
   [:default :number :date :checkbox :url :page :template])
 
 (def closed-values-schema-types
-  "Valid schema :type for close values"
+  "Valid schema :type for closed values"
   #{:default :number :date :url :page})
 
+(assert (set/subset? closed-values-schema-types (set user-builtin-schema-types))
+        "All closed value types are valid property types")
+
 ;; TODO:
 ;; Validate && list fixes for non-validated values when updating property schema
 
@@ -47,14 +51,16 @@
   {:default  [:fn
               {:error/message "should be a text or UUID"}
               text-or-uuid?]                     ; refs/tags will not be extracted
-   :number   number?
+   :number   [:fn
+              {:error/message "should be a number or UUID"}
+              (some-fn number? uuid?)]
    :date     [:fn
               {:error/message "should be a journal date"}
               logseq-page?]
    :checkbox boolean?
    :url      [:fn
-              {:error/message "should be a URL"}
-              url?]
+              {:error/message "should be a URL or UUID"}
+              (some-fn url? uuid?)]
    :page     [:fn
               {:error/message "should be a page"}
               logseq-page?]

+ 1 - 0
src/main/frontend/handler/property.cljs

@@ -305,6 +305,7 @@
                                           :block/page page-id
                                           :block/metadata metadata
                                           :block/schema {:value resolved-value}
+                                          :block/format :markdown
                                           :block/parent page-id
                                           :block/left (or (when page-entity (model/get-block-last-direct-child (db/get-db) (:db/id page-entity)))
                                                           page-id)}