enhance(ux): add an apply button to multiple selects

pull/9042/head
Tienson Qin 2023-04-04 14:42:18 +08:00
parent b2e6e3d16b
commit a1c3804e96
2 changed files with 15 additions and 10 deletions

View File

@ -170,17 +170,19 @@
;; Need the existing choices later to improve the UX ;; Need the existing choices later to improve the UX
:selected-choices #{} :selected-choices #{}
:prompt-key :select/default-select-multiple :prompt-key :select/default-select-multiple
:close-modal? false}) :close-modal? false
:on-apply (:toggle-fn opts)})
"priority" "priority"
(select db-default/built-in-priorities (select db-default/built-in-priorities
(fn [value] (fn [value]
(when (seq value) (when (seq value)
(append-tree! *tree opts loc (vec (cons :priority value))))) (append-tree! *tree opts loc (vec (cons :priority value)))))
{:multiple-choices? true {:multiple-choices? true
:selected-choices #{} :selected-choices #{}
:prompt-key :select/default-select-multiple :prompt-key :select/default-select-multiple
:close-modal? false}) :close-modal? false
:on-apply (:toggle-fn opts)})
"page" "page"
(let [pages (sort (db-model/get-all-page-original-names repo))] (let [pages (sort (db-model/get-all-page-original-names repo))]

View File

@ -47,7 +47,7 @@
prompt-key input-default-placeholder close-modal? prompt-key input-default-placeholder close-modal?
extract-fn host-opts on-input input-opts extract-fn host-opts on-input input-opts
item-cp transform-fn tap-*input-val item-cp transform-fn tap-*input-val
multiple-choices? _selected-choices] multiple-choices? on-apply _selected-choices]
:or {limit 100 :or {limit 100
prompt-key :select/default-prompt prompt-key :select/default-prompt
empty-placeholder (fn [_t] [:div]) empty-placeholder (fn [_t] [:div])
@ -90,7 +90,10 @@
(when close-modal? (state/close-modal!)) (when close-modal? (state/close-modal!))
(when on-chosen (when on-chosen
(on-chosen (if multiple-choices? @*selected-choices x)))))) (on-chosen (if multiple-choices? @*selected-choices x))))))
:empty-placeholder (empty-placeholder t)})]])) :empty-placeholder (empty-placeholder t)})]
(when multiple-choices?
[:div.p-4 (ui/button "Apply updates" :on-click on-apply)])]))
(defn select-config (defn select-config
"Config that supports multiple types (uses) of this component. To add a new "Config that supports multiple types (uses) of this component. To add a new