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