Browse Source

fix: closed :default values validate correctly

and values can be selected from UI. Also tweak query to expand
properties if available
Gabriel Horner 1 year ago
parent
commit
0853940a34

+ 4 - 1
deps/db/script/query.cljs

@@ -29,7 +29,10 @@
         conn (sqlite-db/open-db! dir db-name)
         results (if ((set args) "-e")
                   (map #(when-let [ent (d/entity @conn (edn/read-string %))]
-                          (into {:db/id (:db/id ent)} ent)) (drop 2 args))
+                          (cond-> (into {:db/id (:db/id ent)} ent)
+                            (seq (:block/properties ent))
+                            (update :block/properties (fn [props] (map (fn [m] (into {} m)) props)))))
+                       (drop 2 args))
                   ;; assumes no :in are in queries
                   (let [query (into (edn/read-string query*) [:in '$ '%])]
                     (mapv first (d/q query @conn (rules/extract-rules rules/db-query-dsl-rules)))))]

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

@@ -398,7 +398,8 @@
         (do (notification/show! "This is a private built-in property that can't be used." :error)
             (pv/exit-edit-property))
 
-        (= :default (get-in property [:block/schema :type]))
+        (and (= :default (get-in property [:block/schema :type]))
+             (not (seq (get-in property [:block/schema :values]))))
         (do
           (pv/<create-new-block! entity property "")
           nil)

+ 3 - 1
src/main/frontend/handler/db_based/property.cljs

@@ -52,7 +52,9 @@
   (into {}
         (map (fn [[property-type property-val-schema]]
                (cond
-                 (db-property-type/closed-value-property-types property-type)
+                 (and (db-property-type/closed-value-property-types property-type)
+                      ;; FIXME: Remove when closed values are done migrating to refs
+                      (not (#{:default} property-type)))
                  (let [[_ schema-opts schema-fn] property-val-schema
                        schema-fn' (if (db-property-type/property-types-with-db property-type) #(schema-fn (db/get-db) %) schema-fn)]
                    [property-type [:fn