mirror of https://github.com/logseq/logseq
chore: remove <update-property fn
parent
81ed7cea0e
commit
6e66677da1
|
@ -247,9 +247,10 @@
|
|||
[:div.col-span-3.flex.flex-row.items-center.gap-2
|
||||
(icon-component/icon-picker icon-value
|
||||
{:on-chosen (fn [_e icon]
|
||||
(db-property-handler/<update-property!
|
||||
(db-property-handler/upsert-property!
|
||||
(state/get-current-repo)
|
||||
(:db/ident property)
|
||||
(:block/schema property)
|
||||
{:properties {:logseq.property/icon icon}}))})
|
||||
|
||||
(when icon-value
|
||||
|
@ -585,9 +586,10 @@
|
|||
{:on-chosen
|
||||
(fn [_e icon]
|
||||
(when icon
|
||||
(p/let [_ (db-property-handler/<update-property! repo
|
||||
(:db/ident property)
|
||||
{:properties {:logseq.property/icon icon}})]
|
||||
(p/let [_ (db-property-handler/upsert-property! repo
|
||||
(:db/ident property)
|
||||
(:block/schema property)
|
||||
{:properties {:logseq.property/icon icon}})]
|
||||
(shui/popup-hide! id))))}))]
|
||||
|
||||
(shui/trigger-as :button
|
||||
|
@ -605,34 +607,34 @@
|
|||
(:block/original-name property)]
|
||||
|
||||
(shui/trigger-as :a
|
||||
{:tabIndex 0
|
||||
:title (str "Configure property: " (:block/original-name property))
|
||||
:class "property-k flex select-none jtrigger pl-2"
|
||||
:on-pointer-down (fn [^js e]
|
||||
(when (util/meta-key? e)
|
||||
(route-handler/redirect-to-page! (:block/name property))
|
||||
(.preventDefault e)))
|
||||
:on-click (fn [^js e]
|
||||
(shui/popup-show!
|
||||
(.-target e)
|
||||
(fn [{:keys [id]}]
|
||||
[:div.p-2
|
||||
[:h2.text-lg.font-medium.mb-2.p-1 "Configure property"]
|
||||
[:span.close.absolute.right-2.top-2
|
||||
(shui/button
|
||||
{:variant :ghost :size :sm :class "!w-4 !h-6"
|
||||
:on-click #(shui/popup-hide! id)}
|
||||
(shui/tabler-icon "x" {:size 16}))]
|
||||
(property-config property
|
||||
{:inline-text inline-text
|
||||
:page-cp page-cp})])
|
||||
{:content-props {:class "property-configure-popup-content"
|
||||
:collisionPadding {:bottom 10 :top 10}
|
||||
:avoidCollisions true
|
||||
:align "start"}
|
||||
:auto-side? true
|
||||
:auto-focus? true}))}
|
||||
(:block/original-name property)))]))
|
||||
{:tabIndex 0
|
||||
:title (str "Configure property: " (:block/original-name property))
|
||||
:class "property-k flex select-none jtrigger pl-2"
|
||||
:on-pointer-down (fn [^js e]
|
||||
(when (util/meta-key? e)
|
||||
(route-handler/redirect-to-page! (:block/name property))
|
||||
(.preventDefault e)))
|
||||
:on-click (fn [^js e]
|
||||
(shui/popup-show!
|
||||
(.-target e)
|
||||
(fn [{:keys [id]}]
|
||||
[:div.p-2
|
||||
[:h2.text-lg.font-medium.mb-2.p-1 "Configure property"]
|
||||
[:span.close.absolute.right-2.top-2
|
||||
(shui/button
|
||||
{:variant :ghost :size :sm :class "!w-4 !h-6"
|
||||
:on-click #(shui/popup-hide! id)}
|
||||
(shui/tabler-icon "x" {:size 16}))]
|
||||
(property-config property
|
||||
{:inline-text inline-text
|
||||
:page-cp page-cp})])
|
||||
{:content-props {:class "property-configure-popup-content"
|
||||
:collisionPadding {:bottom 10 :top 10}
|
||||
:avoidCollisions true
|
||||
:align "start"}
|
||||
:auto-side? true
|
||||
:auto-focus? true}))}
|
||||
(:block/original-name property)))]))
|
||||
|
||||
(defn- resolve-linked-block-if-exists
|
||||
"Properties will be updated for the linked page instead of the refed block.
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
[property property-name property-schema]
|
||||
(when (or (not= (:block/original-name property) property-name)
|
||||
(not= (:block/schema property) property-schema))
|
||||
(db-property-handler/<update-property!
|
||||
(state/get-current-repo)
|
||||
(:db/ident property)
|
||||
{:property-name property-name
|
||||
:property-schema property-schema})))
|
||||
(db-property-handler/upsert-property!
|
||||
(state/get-current-repo)
|
||||
(:db/ident property)
|
||||
property-schema
|
||||
{:property-name property-name})))
|
||||
|
|
|
@ -105,21 +105,28 @@
|
|||
:db/cardinality cardinality})))
|
||||
|
||||
(defn upsert-property!
|
||||
[repo property-id schema {:keys [property-name]}]
|
||||
[repo property-id schema {:keys [property-name properties]}]
|
||||
(let [db-ident (or property-id (db-property/get-db-ident-from-name property-name))
|
||||
property (db/entity db-ident)
|
||||
k-name (or (:block/original-name property) (name property-name))]
|
||||
(if property
|
||||
(let [tx-data (->>
|
||||
(conj
|
||||
[(outliner-core/block-with-updated-at
|
||||
{:db/ident db-ident
|
||||
:block/schema schema})]
|
||||
(update-schema property schema))
|
||||
(remove nil?))]
|
||||
(db/transact! repo tx-data {:outliner-op :save-block}))
|
||||
(db/transact! repo [(sqlite-util/build-new-property k-name schema {:db-ident db-ident})]
|
||||
{:outliner-op :new-property}))))
|
||||
type (get-in property [:block/schema :type])
|
||||
type-changed? (and type (:type schema) (not= type (:type schema)))]
|
||||
(when-not type-changed?
|
||||
(cond
|
||||
property
|
||||
(let [tx-data (->>
|
||||
(conj
|
||||
[(merge
|
||||
(outliner-core/block-with-updated-at
|
||||
{:db/ident db-ident
|
||||
:block/schema schema})
|
||||
properties)]
|
||||
(update-schema property schema))
|
||||
(remove nil?))]
|
||||
(db/transact! repo tx-data {:outliner-op :save-block}))
|
||||
:else
|
||||
(let [k-name (or (:block/original-name property) (and property-name (name property-name)))]
|
||||
(db/transact! repo [(sqlite-util/build-new-property k-name schema {:db-ident db-ident})]
|
||||
{:outliner-op :new-property}))))))
|
||||
|
||||
(defn validate-property-value
|
||||
[schema value]
|
||||
|
@ -253,27 +260,6 @@
|
|||
(assoc :block/tags [:logseq.class/task]))]
|
||||
(db/transact! repo [block] {:outliner-op :save-block})))))))))))
|
||||
|
||||
(defn <update-property!
|
||||
[repo property-id {:keys [property-name property-schema properties]}]
|
||||
(assert (keyword? property-id) (str "property-id " property-id " is not a keyword"))
|
||||
(when-let [property (db/entity property-id)]
|
||||
(p/let [type (get-in property [:block/schema :type])
|
||||
type-changed? (and type (:type property-schema) (not= type (:type property-schema)))
|
||||
property-values (db-async/<get-block-property-values repo property-id)]
|
||||
(when (or (not type-changed?)
|
||||
;; only change type if property hasn't been used yet
|
||||
(and (not (ldb/built-in? property)) (empty? property-values)))
|
||||
(let [tx-data (cond-> (merge {:db/ident property-id} properties)
|
||||
property-name (merge
|
||||
{:block/original-name property-name})
|
||||
property-schema (assoc :block/schema
|
||||
;; a property must have a :type when making schema changes
|
||||
(merge {:type :default}
|
||||
property-schema))
|
||||
true outliner-core/block-with-updated-at)]
|
||||
(db/transact! repo [tx-data]
|
||||
{:outliner-op :save-block}))))))
|
||||
|
||||
(defn class-add-property!
|
||||
[repo class-uuid property-id]
|
||||
(when-let [class (db/entity repo [:block/uuid class-uuid])]
|
||||
|
|
Loading…
Reference in New Issue