Browse Source

fix: can't add or update closed values

Gabriel Horner 1 year ago
parent
commit
4a7dab2763

+ 7 - 6
deps/db/src/logseq/db/frontend/property/type.cljs

@@ -94,11 +94,12 @@
           ;; FIXME: UI concerns shouldn't be in this layer
           (number? (some-> (:block/content entity) parse-double))))))
 
-(defn- property-value-block?
-  [db s]
-  (when-let [ent (d/entity db s)]
-    (and (:block/content ent)
-         (:logseq.property/created-from-property ent))))
+(defn- text-entity?
+  [db s {:keys [new-closed-value?]}]
+  (if new-closed-value?
+    (string? s)
+    (when-let [ent (d/entity db s)]
+      (string? (:block/content ent)))))
 
 (defn- page?
   [db val]
@@ -116,7 +117,7 @@
   "Map of types to malli validation schemas that validate a property value for that type"
   {:default  [:fn
               {:error/message "should be a text block"}
-              property-value-block?]
+              text-entity?]
    :string   [:fn
               {:error/message "should be a string"}
               string-entity?]

+ 5 - 14
deps/outliner/src/logseq/outliner/property.cljs

@@ -443,15 +443,6 @@
         property-type (get property-schema :type :default)]
     (when (contains? db-property-type/closed-value-property-types property-type)
       (let [value (if (string? value) (string/trim value) value)
-            closed-values (:property/closed-values property)
-            default-closed-values? (and (= :default property-type) (seq closed-values))
-            value (if (and default-closed-values? (string? value) (not (string/blank? value)))
-                    (let [result (create-property-text-block! conn nil
-                                                              (:db/id property)
-                                                              value
-                                                              {})]
-                      (:db/id (d/entity @conn [:block/uuid (:block-id result)])))
-                    value)
             resolved-value (try
                              (convert-property-input-string (:type property-schema) value)
                              (catch :default e
@@ -466,15 +457,16 @@
           (some (fn [b]
                   (and (= (str resolved-value) (str (or (db-property/property-value-when-closed b)
                                                         (:block/uuid b))))
-                       (not= id (:block/uuid b)))) closed-values)
+                       (not= id (:block/uuid b))))
+                (:property/closed-values property))
           (do
             ;; (notification/show! "Choice already exists" :warning)
-            :value-exists)
+            (doto :value-exists prn))
 
           validate-message
           (do
             ;; (notification/show! validate-message :warning)
-            :value-invalid)
+            (doto :value-invalid prn))
 
           (nil? resolved-value)
           nil
@@ -505,8 +497,7 @@
                             [new-block
                              (outliner-core/block-with-updated-at
                               {:db/id (:db/id property)})]))]
-            {:block-id block-id
-             :tx-data tx-data}))))))
+            (d/transact! conn tx-data {:outliner-op :save-block})))))))
 
 (defn add-existing-values-to-closed-values!
   "Adds existing values as closed values and returns their new block uuids"

+ 3 - 5
src/main/frontend/components/property/closed_value.cljs

@@ -30,11 +30,9 @@
 (defn- <upsert-closed-value!
   "Create new closed value and returns its block UUID."
   [property item]
-  (p/let [{:keys [block-id tx-data]} (db-property-handler/upsert-closed-value! property item)]
-    (p/do!
-     (when (seq tx-data) (db/transact! (state/get-current-repo) tx-data {:outliner-op :upsert-closed-value}))
-     (when (seq tx-data) (re-init-commands! property))
-     block-id)))
+  (p/do!
+   (db-property-handler/upsert-closed-value! (:db/ident property) item)
+   (re-init-commands! property)))
 
 (rum/defc item-value
   [type *value]