fix: can't add a new page property

pull/11177/head
Gabriel Horner 2024-04-15 16:10:45 -04:00
parent 09f65cf842
commit eb9f422a6b
2 changed files with 16 additions and 4 deletions

View File

@ -69,7 +69,7 @@
(defn <add-property!
"If a class and in a class schema context, add the property to its schema.
Otherwise, add a block's property and its value"
Otherwise, add a block's property and its value. Creates a new property as needed"
([block property-key property-value] (<add-property! block property-key property-value {}))
([block property-key property-value {:keys [exit-edit? class-schema?]
:or {exit-edit? true}}]
@ -79,7 +79,17 @@
(when property-key
(if (and class? class-schema?)
(db-property-handler/class-add-property! repo (:block/uuid block) property-key)
(property-handler/set-block-property! repo (:block/uuid block) property-key property-value)))
(let [[property-id property-value']
(if (string? property-key)
(if-let [ent (db/entity [:block/original-name property-key])]
[(:db/ident ent) property-value]
;; This is a new property. Create a new property id to use of set-block-property!
[(db-property-handler/ensure-unique-db-ident
(db/get-db (state/get-current-repo))
(db-property/create-user-property-ident-from-name property-key))
:logseq.property/empty-placeholder])
[property-key property-value])]
(property-handler/set-block-property! repo (:block/uuid block) property-id property-value'))))
(when exit-edit?
(shui/popup-hide!)
(exit-edit-property))))))

View File

@ -121,7 +121,7 @@
{:db/ident ident
:db/cardinality cardinality})))
(defn- ensure-unique-db-ident
(defn ensure-unique-db-ident
"Ensures the given db-ident is unique. If a db-ident conflicts, it is made
unique by adding a suffix with a unique number e.g. :db-ident-1 :db-ident-2"
[db db-ident]
@ -247,9 +247,11 @@
(if (uuid? id) [:block/uuid id] id))
(defn set-block-property!
"Updates a block property's value for the an existing property-id. If possibly
creating a new property, use upsert-property!"
[repo block-eid property-id v {:keys [property-name] :as opts}]
(let [block-eid (->eid block-eid)
_ (assert (keyword? property-id) "property-id should be a keyword")
_ (assert (qualified-keyword? property-id) "property-id should be a keyword")
block (db/entity repo block-eid)
property (db/entity property-id)
v (if (and (uuid? v)