Skip to content

Commit

Permalink
fix: set class scope when using class as property
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 30, 2024
1 parent 7425e01 commit 1760161
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
15 changes: 1 addition & 14 deletions src/main/frontend/components/property.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,7 @@

;; using class as property
(and property (ldb/class? property))
(let [schema (assoc (:block/schema property)
:type :node)]
(p/do!
(db/transact! (state/get-current-repo)
[{:db/id (:db/id property)
:db/ident (:db/ident property)
:db/cardinality :db.cardinality/one
:db/valueType :db.type/ref
:db/index true
:block/tags :logseq.class/Property
:block/schema schema
:property/schema.classes (:db/id property)}]
{:outliner-op :save-block})
(reset! *show-new-property-config? false)))
(pv/<set-class-as-property! (state/get-current-repo) property)

(or (not= :default type)
(and (= :default type) (seq (:property/closed-values property))))
Expand Down
19 changes: 18 additions & 1 deletion src/main/frontend/components/property/value.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@
(remove ldb/property?))]
(or (seq selected-blocks) [block])))

(defn <set-class-as-property!
[repo property]
(db/transact! repo
[{:db/id (:db/id property)
:db/ident (:db/ident property)
:db/cardinality :db.cardinality/one
:db/valueType :db.type/ref
:db/index true
:block/tags :logseq.class/Property
:block/schema (assoc (:block/schema property)
:type :node)
:property/schema.classes (:db/id property)}]
{:outliner-op :save-block}))

(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"
Expand All @@ -173,7 +187,10 @@
(assert (qualified-keyword? property-id) "property to add must be a keyword")
(p/do!
(if (and class? class-schema?)
(db-property-handler/class-add-property! (:db/id block) property-id)
(p/do!
(when (ldb/class? property)
(<set-class-as-property! repo property))
(db-property-handler/class-add-property! (:db/id block) property-id))
(let [block-ids (map :block/uuid blocks)]
(if (and (db-property-type/all-ref-property-types (get-in property [:block/schema :type]))
(string? property-value))
Expand Down

0 comments on commit 1760161

Please sign in to comment.