Browse Source

fix: bulk set property with type checkbox

requires box to be checked

fixed https://github.com/logseq/db-test/issues/306
Tienson Qin 4 months ago
parent
commit
691f5534ab
1 changed files with 21 additions and 13 deletions
  1. 21 13
      src/main/frontend/components/property/value.cljs

+ 21 - 13
src/main/frontend/components/property/value.cljs

@@ -963,10 +963,17 @@
                                 {:label label
                                 {:label label
                                  :value (:db/id value)}))
                                  :value (:db/id value)}))
                          (distinct)))
                          (distinct)))
-            items (->> (if (= :date type)
+            items (->> (cond
+                         (= :checkbox type)
+                         [{:label "True"
+                           :value true}
+                          {:label "False"
+                           :value false}]
+                         (= :date type)
                          (map (fn [m] (let [label (:block/title (db/entity (:value m)))]
                          (map (fn [m] (let [label (:block/title (db/entity (:value m)))]
                                         (when label
                                         (when label
                                           (assoc m :label label)))) items)
                                           (assoc m :label label)))) items)
+                         :else
                          items)
                          items)
                        (remove nil?))
                        (remove nil?))
             on-chosen (fn [chosen selected?]
             on-chosen (fn [chosen selected?]
@@ -976,9 +983,10 @@
                                                          :exit-edit? exit-edit?
                                                          :exit-edit? exit-edit?
                                                          :refresh-result-f refresh-result-f})))
                                                          :refresh-result-f refresh-result-f})))
             selected-choices' (get block (:db/ident property))
             selected-choices' (get block (:db/ident property))
-            selected-choices (if (every? #(and (map? %) (:db/id %)) selected-choices')
-                               (map :db/id selected-choices')
-                               [selected-choices'])]
+            selected-choices (when-not (= type :checkbox)
+                               (if (every? #(and (map? %) (:db/id %)) selected-choices')
+                                 (map :db/id selected-choices')
+                                 [selected-choices']))]
         (select-aux block property
         (select-aux block property
                     {:multiple-choices? multiple-choices?
                     {:multiple-choices? multiple-choices?
                      :items items
                      :items items
@@ -1161,7 +1169,7 @@
         popup-content (fn content-fn [target]
         popup-content (fn content-fn [target]
                         [:div.property-select
                         [:div.property-select
                          (case type
                          (case type
-                           (:entity :number :default :url)
+                           (:entity :number :default :url :checkbox)
                            (select block property select-opts' opts)
                            (select block property select-opts' opts)
 
 
                            (:node :class :property :page :date)
                            (:node :class :property :page :date)
@@ -1303,7 +1311,7 @@
         batch? (batch-operation?)
         batch? (batch-operation?)
         closed-values? (seq (:property/closed-values property))
         closed-values? (seq (:property/closed-values property))
         select-type?' (or (select-type? block property)
         select-type?' (or (select-type? block property)
-                          (and editing? batch? (contains? #{:default :url} type) (not closed-values?)))
+                          (and editing? batch? (contains? #{:default :url :checkbox} type) (not closed-values?)))
         select-opts {:on-chosen on-chosen}
         select-opts {:on-chosen on-chosen}
         value (if (and (entity-map? value*) (= (:db/ident value*) :logseq.property/empty-placeholder))
         value (if (and (entity-map? value*) (= (:db/ident value*) :logseq.property/empty-placeholder))
                 nil
                 nil
@@ -1346,20 +1354,20 @@
           (property-value-date-picker block property value (merge opts {:editing? editing?}))
           (property-value-date-picker block property value (merge opts {:editing? editing?}))
 
 
           :checkbox
           :checkbox
-          (let [add-property! (fn []
-                                (let [value' (boolean (not value))]
-                                  (<add-property! block (:db/ident property) value' opts)
-                                  (when-let [on-checked-change (:on-checked-change opts)]
-                                    (on-checked-change value'))))]
+          (let [add-property! (fn [value]
+                                (<add-property! block (:db/ident property) value opts)
+                                (when-let [on-checked-change (:on-checked-change opts)]
+                                  (on-checked-change value)))]
             [:label.flex.w-full.as-scalar-value-wrap.cursor-pointer
             [:label.flex.w-full.as-scalar-value-wrap.cursor-pointer
              (shui/checkbox {:class "jtrigger flex flex-row items-center"
              (shui/checkbox {:class "jtrigger flex flex-row items-center"
                              :disabled config/publishing?
                              :disabled config/publishing?
                              :auto-focus editing?
                              :auto-focus editing?
                              :checked value
                              :checked value
-                             :on-checked-change add-property!
+                             :on-checked-change (fn []
+                                                  (add-property! (boolean (not value))))
                              :on-key-down (fn [e]
                              :on-key-down (fn [e]
                                             (when (= (util/ekey e) "Enter")
                                             (when (= (util/ekey e) "Enter")
-                                              (add-property!))
+                                              (add-property! (boolean (not value))))
                                             (when (contains? #{"Backspace" "Delete"} (util/ekey e))
                                             (when (contains? #{"Backspace" "Delete"} (util/ekey e))
                                               (delete-block-property! block property)))})])
                                               (delete-block-property! block property)))})])
           ;; :others
           ;; :others