From ccf35df6998184ccd3ce7c46773e27a534ee5f64 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 3 Jul 2023 12:31:26 +0800 Subject: [PATCH] fix: don't add property value if it's multiple values and blank value --- src/main/frontend/handler/property.cljs | 71 +++++++++++++------------ 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/main/frontend/handler/property.cljs b/src/main/frontend/handler/property.cljs index 9d5c7f444d..98312a2ed6 100644 --- a/src/main/frontend/handler/property.cljs +++ b/src/main/frontend/handler/property.cljs @@ -95,41 +95,42 @@ schema (get builtin-schema-types property-type) properties (:block/properties block) value (get properties property-uuid)] - (when-let [v* (try - (convert-property-input-string property-type v) - (catch :default e - (notification/show! (str e) :error false) - nil))] - (when-not (contains? (if (set? value) value #{value}) v*) - (if-let [msg (me/humanize (mu/explain-data schema v*))] - (notification/show! msg :error false) - (do - (when (nil? property) ;if property not exists yet - (db/transact! repo [(outliner-core/block-with-timestamps - {:block/schema {:type property-type} - :block/original-name k-name - :block/name (util/page-name-sanity-lc k-name) - :block/uuid property-uuid - :block/type "property"})])) - (let [refs (when (= property-type :default) (extract-page-refs-from-prop-str-value v*)) - refs' (when (seq refs) - (concat (:block/refs (db/pull [:block/uuid (:block/uuid block)])) - refs)) - v' (if (= property-type :default) - (if (seq refs) refs v*) - v*) - new-value (if multiple-values? (vec (distinct (conj value v'))) v') - block-properties (assoc properties property-uuid new-value) - block-properties-text-values - (if (and (not multiple-values?) (= property-type :default)) - (assoc (:block/properties-text-values block) property-uuid v*) - (dissoc (:block/properties-text-values block) property-uuid))] - ;; TODO: fix block/properties-order - (db/transact! repo - [{:block/uuid (:block/uuid block) - :block/properties block-properties - :block/properties-text-values block-properties-text-values - :block/refs refs'}])))))))) + (when-not (and multiple-values? (string/blank? (str v))) + (when-let [v* (try + (convert-property-input-string property-type v) + (catch :default e + (notification/show! (str e) :error false) + nil))] + (when-not (contains? (if (set? value) value #{value}) v*) + (if-let [msg (me/humanize (mu/explain-data schema v*))] + (notification/show! msg :error false) + (do + (when (nil? property) ;if property not exists yet + (db/transact! repo [(outliner-core/block-with-timestamps + {:block/schema {:type property-type} + :block/original-name k-name + :block/name (util/page-name-sanity-lc k-name) + :block/uuid property-uuid + :block/type "property"})])) + (let [refs (when (= property-type :default) (extract-page-refs-from-prop-str-value v*)) + refs' (when (seq refs) + (concat (:block/refs (db/pull [:block/uuid (:block/uuid block)])) + refs)) + v' (if (= property-type :default) + (if (seq refs) refs v*) + v*) + new-value (if multiple-values? (vec (distinct (conj value v'))) v') + block-properties (assoc properties property-uuid new-value) + block-properties-text-values + (if (and (not multiple-values?) (= property-type :default)) + (assoc (:block/properties-text-values block) property-uuid v*) + (dissoc (:block/properties-text-values block) property-uuid))] + ;; TODO: fix block/properties-order + (db/transact! repo + [{:block/uuid (:block/uuid block) + :block/properties block-properties + :block/properties-text-values block-properties-text-values + :block/refs refs'}]))))))))) (defn remove-property! [repo block k-uuid-or-builtin-k-name]