From 5cc4c4b6761ebfcf74ce020546f1135feb8f73af Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Wed, 13 Sep 2023 14:04:45 +0800 Subject: [PATCH] fix: can't switch back to single input value for :default property https://linear.app/logseq/issue/LOG-2810/cant-switch-back-to-single-input-value-for-default-property --- .../frontend/components/property/value.cljs | 3 ++- .../frontend/handler/db_based/property.cljs | 22 +++++++++++-------- .../frontend/modules/outliner/datascript.cljs | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/frontend/components/property/value.cljs b/src/main/frontend/components/property/value.cljs index 62c004fa6..ad57cab0d 100644 --- a/src/main/frontend/components/property/value.cljs +++ b/src/main/frontend/components/property/value.cljs @@ -292,7 +292,8 @@ empty-block? (or (nil? parent) (zero? children-count))] (when empty-block? (when parent - (db/transact! repo [[:db/retractEntity (:db/id parent)]])) + (db/transact! repo [[:db/retractEntity (:db/id parent)]] + {:outliner-op :delete-blocks})) (property-handler/delete-property-value! repo block (:block/uuid property) value)) (when (seq children) [:div.property-block-container.w-full diff --git a/src/main/frontend/handler/db_based/property.cljs b/src/main/frontend/handler/db_based/property.cljs index c5d21f112..eba97dd8a 100644 --- a/src/main/frontend/handler/db_based/property.cljs +++ b/src/main/frontend/handler/db_based/property.cljs @@ -339,8 +339,8 @@ :block/tags)] (when property-value-id (db/transact! repo - [[:db/retract (:db/id block) attribute property-value-id]] - {:outliner-op :save-block}))) + [[:db/retract (:db/id block) attribute property-value-id]] + {:outliner-op :save-block}))) (if (= :many (:cardinality schema)) (let [properties (:block/properties block) properties' (update properties property-id @@ -348,13 +348,17 @@ (set (remove #{property-value} col)))) refs (outliner-core/rebuild-block-refs block properties')] (db/transact! repo - [[:db/retract (:db/id block) :block/refs] - {:block/uuid (:block/uuid block) - :block/properties properties' - :block/refs refs}] - {:outliner-op :save-block})) - ;; remove block property if cardinality is not many - (remove-block-property! repo (:block/uuid block) property-id)))))))) + [[:db/retract (:db/id block) :block/refs] + {:block/uuid (:block/uuid block) + :block/properties properties' + :block/refs refs}] + {:outliner-op :save-block})) + (if (= :default (get-in property [:block/schema :type])) + (set-block-property! repo (:block/uuid block) + (:block/original-name property) + "" + {}) + (remove-block-property! repo (:block/uuid block) property-id))))))))) (defn replace-key-with-id! "Notice: properties need to be created first" diff --git a/src/main/frontend/modules/outliner/datascript.cljs b/src/main/frontend/modules/outliner/datascript.cljs index fe5774985..c30ece634 100644 --- a/src/main/frontend/modules/outliner/datascript.cljs +++ b/src/main/frontend/modules/outliner/datascript.cljs @@ -28,6 +28,7 @@ (pipelines/invoke-hooks tx-report) (when (or (:outliner/transact? tx-meta) + (:outliner-op tx-meta) (:whiteboard/transact? tx-meta)) (undo-redo/listen-db-changes! tx-report))