Skip to content

Commit

Permalink
Replace Consumers Dataset dropdown an autoselect
Browse files Browse the repository at this point in the history
In production, the amount of datasets to pick from was getting large and
unsorted, so the UX was really bad.

This change mimics the Region selection, with an autoselect control for
the users to filter the available options.

See #717
  • Loading branch information
matiasgarciaisaia committed Mar 12, 2024
1 parent 71a17f0 commit 28c3be2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
(when-not read-only
[sources-type-component {:label "Data type"}])
[sources-dropdown-component {:label "Consumer Dataset"
:value (:source-set-id @current-project)
:model (:source-set-id @current-project)
:on-change #(dispatch [:projects2/save-key :source-set-id %])
:disabled? read-only}]
[current-project-input {:label "Consumers Unit" :path [:config :demographics :unit-name] :type "text" :disabled read-only :empty-label (capitalize consumer-unit)}]
Expand Down
31 changes: 10 additions & 21 deletions client/src/planwise/client/sources/components/dropdown.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[planwise.client.asdf :as asdf]
[planwise.client.components.common2 :as common2]
[planwise.client.utils :as utils]
[planwise.client.ui.filter-select :as filter-select]
[planwise.client.ui.rmwc :as m]))

(def in-sources (rf/path [:sources]))
Expand All @@ -14,29 +15,17 @@
[(subscribe [:sources/list])
(subscribe [:projects2/source-types])])
(fn [[list types] _]
(->> list
(filter (fn [{:keys [type]}] (types type)))
(mapv (fn [{:keys [id name type]}] {:value id :label name :type type})))))
(filter (fn [{:keys [type]}] (types type)) list)))

;; ----------------------------------------------------------------------------
;; Views

(defn- sources-select-component
[{:keys [label value options empty-label on-change]}]
[m/Select {:label (if (empty? options) empty-label label)
:disabled (empty? options)
:value (str value)
:options options
:onChange #(on-change (js/parseInt (-> % .-target .-value)))}])

(defn sources-dropdown-component
[{:keys [label value on-change disabled?]}]
(let [options (subscribe [:sources/dropdown-options])
component (if (or disabled? (empty? @options))
common2/disabled-input-component
sources-select-component)]
[component {:label label
:value value
:options @options
:empty-label "No sources layer available."
:on-change on-change}]))
[attrs]
(let [props (merge {:choices @(rf/subscribe [:sources/dropdown-options])
:label-fn :name
:render-fn (fn [source] [:div.option-row
[:span (:name source)]
[:span.option-context (:value source)]])}
attrs)]
(into [filter-select/single-dropdown] (mapcat identity props))))

0 comments on commit 28c3be2

Please sign in to comment.