From 3e3ee6c7bfd6a30d33deb6423b188471bbdedabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Garc=C3=ADa=20Isa=C3=ADa?= Date: Wed, 3 Apr 2024 13:02:52 -0300 Subject: [PATCH] Use autoselect control for Providers (#725) * 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 --- .../client/projects2/components/settings.cljs | 2 +- .../providers_set/components/dropdown.cljs | 39 ++++++------------- .../planwise/client/providers_set/subs.cljs | 4 +- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/client/src/planwise/client/projects2/components/settings.cljs b/client/src/planwise/client/projects2/components/settings.cljs index a4a2f6f1b..9d508502d 100644 --- a/client/src/planwise/client/projects2/components/settings.cljs +++ b/client/src/planwise/client/projects2/components/settings.cljs @@ -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}] diff --git a/client/src/planwise/client/providers_set/components/dropdown.cljs b/client/src/planwise/client/providers_set/components/dropdown.cljs index e15284b26..ade04ec3f 100644 --- a/client/src/planwise/client/providers_set/components/dropdown.cljs +++ b/client/src/planwise/client/providers_set/components/dropdown.cljs @@ -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)))) diff --git a/client/src/planwise/client/providers_set/subs.cljs b/client/src/planwise/client/providers_set/subs.cljs index 2fbfce8dc..3474a97fe 100644 --- a/client/src/planwise/client/providers_set/subs.cljs +++ b/client/src/planwise/client/providers_set/subs.cljs @@ -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