瀏覽代碼

fix: can't add existing :many property

Tienson Qin 1 年之前
父節點
當前提交
f944dd2de9
共有 2 個文件被更改,包括 18 次插入10 次删除
  1. 9 2
      deps/outliner/src/logseq/outliner/property.cljs
  2. 9 8
      src/main/frontend/components/property/value.cljs

+ 9 - 2
deps/outliner/src/logseq/outliner/property.cljs

@@ -25,12 +25,19 @@
    (build-property-value-tx-data block property-id value (= property-id :logseq.task/status)))
   ([block property-id value status?]
    (when (some? value)
-     (let [block (assoc (outliner-core/block-with-updated-at {:db/id (:db/id block)})
+     (let [old-value (get block property-id)
+           multiple-values-empty? (and (coll? old-value)
+                                       (= 1 (count old-value))
+                                       (= :logseq.property/empty-placeholder (:db/ident (first old-value))))
+           block (assoc (outliner-core/block-with-updated-at {:db/id (:db/id block)})
                         property-id value)
            block-tx-data (cond-> block
                            status?
                            (assoc :block/tags :logseq.class/task))]
-       [block-tx-data]))))
+       [(when multiple-values-empty?
+          [:db/retract (:db/id block) property-id :logseq.property/empty-placeholder])
+        block-tx-data]))))
+
 
 (defn- get-property-value-schema
   "Gets a malli schema to validate the property value for the given property type and builds

+ 9 - 8
src/main/frontend/components/property/value.cljs

@@ -752,14 +752,15 @@
                      :container-id (:container-id opts)}]
          (block-cp config (sort-by :block/order v)))]
       (let [values-cp (fn [toggle-fn]
-                        (if (seq items)
-                          (concat
-                           (for [item items]
-                             (rum/with-key (select-item property type item opts) (or (:block/uuid item) (str item))))
-                           (when date?
-                             [(property-value-date-picker block property nil {:toggle-fn toggle-fn})]))
-                          (when-not editing?
-                            (property-empty-text-value))))
+                        (let [not-empty-value? (not= (map :db/ident items) [:logseq.property/empty-placeholder])]
+                          (if (and (seq items) not-empty-value?)
+                            (concat
+                             (for [item items]
+                               (rum/with-key (select-item property type item opts) (or (:block/uuid item) (str item))))
+                             (when date?
+                               [(property-value-date-picker block property nil {:toggle-fn toggle-fn})]))
+                            (when-not editing?
+                              (property-empty-text-value)))))
             select-cp (fn [select-opts]
                         (let [select-opts (merge {:multiple-choices? true
                                                   :dropdown? editing?