diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb index f6e4120e..310de924 100644 --- a/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.html.erb @@ -11,8 +11,8 @@ - <%= form_with model: Current.tenant, url: admin_tenant_feature_flags_path(Current.tenant), title: "Toggle feature state", method: :patch do |form| %> - <%= form.hidden_field :feature_flags, value: @features_changed.join(",") %> + <%= form_with model: Current.tenant, url: admin_tenant_feature_flag_path(Current.tenant, @feature_flag), title: "Toggle feature state", method: :patch do |form| %> + <%= form.hidden_field :enabled, value: !@enabled %> <%= form.button name: @feature_flag, class: "#{@enabled ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @enabled } do %> Use setting diff --git a/app/components/admin/feature_flags/feature_flags_list_row_component.rb b/app/components/admin/feature_flags/feature_flags_list_row_component.rb index 87aef480..65e5d154 100644 --- a/app/components/admin/feature_flags/feature_flags_list_row_component.rb +++ b/app/components/admin/feature_flags/feature_flags_list_row_component.rb @@ -2,6 +2,5 @@ class Admin::FeatureFlags::FeatureFlagsListRowComponent < ViewComponent::Base def initialize(flag, enabled_features) @feature_flag = flag @enabled = enabled_features.include?(flag) - @features_changed = enabled_features.include?(flag) ? enabled_features - [flag] : enabled_features + [flag] end end diff --git a/app/controllers/admin/feature_flags_controller.rb b/app/controllers/admin/feature_flags_controller.rb index 70713c7c..c52acfaf 100644 --- a/app/controllers/admin/feature_flags_controller.rb +++ b/app/controllers/admin/feature_flags_controller.rb @@ -9,7 +9,7 @@ def index def update authorize([:admin, :feature_flag]) - @tenant.feature_flags = feature_flags_params["feature_flags"].split(",") + @tenant.feature_flags = feature_flags_params[:enabled] == "true" ? @tenant.feature_flags.union([params[:id]]) : @tenant.feature_flags - [params[:id]] @tenant.save! redirect_to admin_tenant_feature_flags_path end @@ -21,6 +21,6 @@ def set_tenant end def feature_flags_params - params.require(:tenant).permit(:feature_flags) + params.require(:tenant).permit(:enabled) end end diff --git a/config/routes.rb b/config/routes.rb index 9d8cc224..ead461a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,9 +37,7 @@ end resources :users - - get "/feature_flags/", to: "feature_flags#index" - patch "/feature_flags/", to: "feature_flags#update" + resources :feature_flags, only: [:index, :update] resources :boxes, only: :index namespace :boxes do