From b07b52fed18b55923e9d82592c10c9564635c04c Mon Sep 17 00:00:00 2001 From: Oluwatoyosi Oyegoke <34948675+Tooyosi@users.noreply.github.com> Date: Thu, 10 Oct 2024 06:19:49 +0100 Subject: [PATCH] add logic to toggle reducer keys based off user input (#1610) * add logic to toggle reducer keys based off user input * hound cleanups * add tests * hound cleanups * use jquery, remove form.js and rename mehod --- app/controllers/reducers_controller.rb | 17 +++++++++ app/views/reducers/_form.html.erb | 31 ++++++++++++++++ spec/controllers/reducers_controller_spec.rb | 38 ++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/app/controllers/reducers_controller.rb b/app/controllers/reducers_controller.rb index 3afaabdd6..2a9154066 100644 --- a/app/controllers/reducers_controller.rb +++ b/app/controllers/reducers_controller.rb @@ -46,6 +46,8 @@ def create filters['extractor_keys'] = JSON.parse(filters['extractor_keys']) end + reset_config_reducer_keys(new_params) + @reducer = reducer_class.new(new_params) respond_to do |format| @@ -72,6 +74,8 @@ def update filters['extractor_keys'] = JSON.parse(filters['extractor_keys']) end + reset_config_reducer_keys(params) + @reducer.update(params) respond_to do |format| @@ -122,6 +126,8 @@ def reducer_params(klass) params.require(:reducer).permit( :key, :topic, + :user_reducer_keys, + :subject_reducer_keys, *klass.configuration_fields.keys, filters: {}, grouping: {}, @@ -131,4 +137,15 @@ def reducer_params(klass) def record_not_valid(exception) render json: { error: exception.message }, status: 422 end + + def reset_config_reducer_keys(param_object) + if param_object[:topic] == 'reduce_by_subject' + param_object[:subject_reducer_keys] = nil + elsif param_object[:topic] == 'reduce_by_user' + param_object[:user_reducer_keys] = nil + else + param_object[:subject_reducer_keys] = nil + param_object[:user_reducer_keys] = nil + end + end end diff --git a/app/views/reducers/_form.html.erb b/app/views/reducers/_form.html.erb index 6045e10c5..16b3c5bbd 100644 --- a/app/views/reducers/_form.html.erb +++ b/app/views/reducers/_form.html.erb @@ -15,6 +15,15 @@ <%= f.input :reducible_type, :as => :hidden %> +