Browse Source

fix: update commands after modifying status && property values

fixes LOG-3048
Tienson Qin 1 year ago
parent
commit
83d864adc5

+ 23 - 20
src/main/frontend/components/property/closed_value.cljs

@@ -23,8 +23,10 @@
   "Create new closed value and returns its block UUID."
   [property item]
   (let [{:keys [block-id tx-data]} (db-property-handler/upsert-closed-value property item)]
-    (when (seq tx-data) (db/transact! tx-data))
-    block-id))
+    (p/do!
+     (when (seq tx-data) (db/transact! tx-data))
+     (when (seq tx-data) (db-property-handler/re-init-commands! property))
+     block-id)))
 
 (rum/defc item-value
   [type *value]
@@ -136,27 +138,28 @@
             (fn [{:keys [id]}]
               (let [opts {:toggle-fn #(shui/popup-hide! id)}]
                 (item-config
-                  property
-                  block
-                  (assoc opts :on-save
-                              (fn [value icon description]
-                                (<upsert-closed-value! property {:id          uuid
-                                                                 :value       value
-                                                                 :description description
-                                                                 :icon        icon})))))))
+                 property
+                 block
+                 (assoc opts :on-save
+                        (fn [value icon description]
+                          (<upsert-closed-value! property {:id          uuid
+                                                           :value       value
+                                                           :description description
+                                                           :icon        icon})))))))
           opts {:toggle-fn #(shui/popup-show! % content-fn {:as-menu? true})}]
 
       (choice-with-close
-        block
-        (assoc opts
-          :delete-choice
-          (fn []
-            (db-property-handler/delete-closed-value! property block)
-            (swap! *property-schema update :values (fn [vs] (vec (remove #(= uuid %) vs)))))
-          :update-icon
-          (fn [icon]
-            (property-handler/set-block-property! (state/get-current-repo) (:block/uuid block) :icon icon)))
-        parent-opts))))
+       block
+       (assoc opts
+              :delete-choice
+              (fn []
+                (p/do!
+                  (db-property-handler/delete-closed-value! property block)
+                  (swap! *property-schema update :values (fn [vs] (vec (remove #(= uuid %) vs))))))
+              :update-icon
+              (fn [icon]
+                (property-handler/set-block-property! (state/get-current-repo) (:block/uuid block) :icon icon)))
+       parent-opts))))
 
 (rum/defc add-existing-values
   [property *property-schema values {:keys [toggle-fn]}]

+ 9 - 1
src/main/frontend/handler/db_based/property.cljs

@@ -670,6 +670,12 @@
     (or (db/entity [:block/name page-name])
         (db-property-util/build-property-hidden-page property))))
 
+(defn re-init-commands!
+  "Update commands after task status and priority's closed values has been changed"
+  [property]
+  (when (contains? #{:task/status :task/priority} (:db/ident property))
+    (state/pub-event! [:init/commands])))
+
 (defn upsert-closed-value
   "id should be a block UUID or nil"
   [property {:keys [id value icon description]
@@ -802,7 +808,9 @@
                     :block/schema (update schema :values
                                           (fn [values]
                                             (vec (remove #{(:block/uuid value-block)} values))))}]]
-      (db/transact! tx-data))))
+      (p/do!
+       (db/transact! tx-data)
+       (re-init-commands! property)))))
 
 (defn get-property-block-created-block
   "Get the root block and property that created this property block."