Skip to content

Commit

Permalink
Use autoselect control for Providers (#725)
Browse files Browse the repository at this point in the history
* Use autoselect control for Providers

So it matches both the Region and Consumers pickers.

See #724

* Move providers-set loading into dropdown component

See #724

* Fix source code formatting
  • Loading branch information
matiasgarciaisaia authored Apr 3, 2024
1 parent ce906de commit 3e3ee6c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
[:section {:class-name "project-settings-section"}
[section-header 3 "Providers"]
[providers-set-dropdown-component {:label "Provider Dataset"
:value (:provider-set-id @current-project)
:model (:provider-set-id @current-project)
:on-change #(dispatch [:projects2/save-key :provider-set-id %])
:disabled? read-only}]

Expand Down
39 changes: 11 additions & 28 deletions client/src/planwise/client/providers_set/components/dropdown.cljs
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
(ns planwise.client.providers-set.components.dropdown
(:require [re-frame.core :refer [subscribe dispatch]]
[reagent.core :as r]
[clojure.string :as string]
(:require [re-frame.core :as rf]
[planwise.client.asdf :as asdf]
[planwise.client.utils :as utils]
[planwise.client.components.common2 :as common2]
[planwise.client.providers-set.db :as db]
[planwise.client.ui.rmwc :as m]
[re-frame.utils :as c]))

(defn- providers-set-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
:on-change #(on-change (js/parseInt (-> % .-target .-value)))}])
[planwise.client.ui.filter-select :as filter-select]))

(defn providers-set-dropdown-component
[{:keys [label value on-change disabled?]}]
(let [list (subscribe [:providers-set/list])
options (subscribe [:providers-set/dropdown-options])
component (if (or disabled? (empty? @options))
common2/disabled-input-component
providers-set-select-component)]
[attrs]
(let [list (rf/subscribe [:providers-set/list])
props (merge {:choices @(rf/subscribe [:providers-set/dropdown-options])
:label-fn :label
:render-fn (fn [provider-set] [:div.option-row
[:span (:label provider-set)]])}
attrs)]
(when (asdf/should-reload? @list)
(dispatch [:providers-set/load-providers-set]))
[component {:label label
:value value
:options @options
:empty-label "There are no providers-set defined."
:on-change on-change}]))
(rf/dispatch [:providers-set/load-providers-set]))
(into [filter-select/single-dropdown] (mapcat identity props))))
4 changes: 2 additions & 2 deletions client/src/planwise/client/providers_set/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
(->> providers
(map (fn [provider-set]
(let [{:keys [id name]} provider-set]
{:value id :label name})))
{:value id :label name :id id})))
(sort-by :label)
(into [{:value nil :label "None"}])))))
(into [{:value nil :label "None" :id nil}])))))

(rf/reg-sub
:providers-set/view-state
Expand Down

0 comments on commit 3e3ee6c

Please sign in to comment.