enhance: make property type immutable for db safety

pull/10438/head
Tienson Qin 2023-10-09 21:30:51 +08:00
parent 9a69518e96
commit 5f6e2596e8
3 changed files with 29 additions and 23 deletions

View File

@ -293,7 +293,8 @@
disabled? (or built-in-property? config/publishing?)
hide-delete? (or (= (:db/id block) (:db/id property)) ; property page
add-new-property?)
class? (contains? (:block/type block) "class")]
class? (contains? (:block/type block) "class")
property-type (get-in property [:block/schema :type])]
[:div.property-configure.flex.flex-1.flex-col
[:div.grid.gap-2.p-1
[:div.grid.grid-cols-4.gap-1.items-center.leading-8
@ -329,10 +330,14 @@
:selected (= (keyword (string/lower-case type))
(:type @*property-schema))})))]
[:div.col-span-2
(if property-type
(if (= property-type :default)
"Text"
((comp string/capitalize name) property-type))
(ui/select schema-types
(fn [_e v]
(let [type (keyword (string/lower-case v))]
(swap! *property-schema assoc :type type))))])]
(swap! *property-schema assoc :type type)))))])]
(case (:type @*property-schema)
:page
@ -454,7 +459,7 @@
(if (and (contains? (:block/type entity) "class") page-configure?)
(pv/add-property! entity property-name "" {:class-schema? class-schema? :exit-edit? page-configure?})
(do
(db-property-handler/upsert-property! repo property-name {:type :default} {})
(db-property-handler/upsert-property! repo property-name {} {})
(when *show-new-property-config?
(reset! *show-new-property-config? true))))
(do (notification/show! "This is an invalid property name. A property name cannot start with page reference characters '#' or '[['." :error)

View File

@ -261,6 +261,8 @@
properties]}]
{:pre [(uuid? property-uuid)]}
(when-let [property (db/entity [:block/uuid property-uuid])]
(let [type (get property [:block/schema :type])]
(when-not (and type (:type property-schema) (not= type (:type property-schema))) ; property type changed
(when (and (= :many (:cardinality property-schema))
(not= :many (:cardinality (:block/schema property))))
;; cardinality changed from :one to :many
@ -275,7 +277,7 @@
properties))
true outliner-core/block-with-updated-at)]
(db/transact! repo [tx-data]
{:outliner-op :save-block}))))
{:outliner-op :save-block}))))))
(defn class-add-property!
[repo class k-name]

View File

@ -9,8 +9,7 @@
[frontend.db :as db]
[frontend.format.block :as block]
[frontend.db.model :as model]
[frontend.modules.outliner.core :as outliner-core]
[clojure.string :as string]))
[frontend.modules.outliner.core :as outliner-core]))
(defn remove-block-property!
[repo block-id key]