Skip to content

Commit

Permalink
Merge pull request #728 from bitzesty/bulk-qa
Browse files Browse the repository at this point in the history
Fix: fixes for bulk assign buttons
  • Loading branch information
TheDancingClown authored Sep 30, 2024
2 parents cfd0384 + 222bda2 commit bafd8a8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application-admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ $todo-black: #333;
}

.govuk-notification-banner__heading {
max-width: 700px
max-width: 100%
}
22 changes: 17 additions & 5 deletions app/controllers/concerns/form_answer_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def save_or_load_search!

unless @processor.valid?
flash[:bulk_error] = @processor.base_error_messages
redirect_to admin_form_answers_path(year: params[:year], search_id: @processor.search_id) and return
redirect_to admin_form_answers_path(year: params[:year], search_id: @processor.search_id, anchor: "bulk_error") and return
end

redirect_url = @processor.redirect_url
Expand All @@ -120,19 +120,31 @@ def save_or_load_search!
end
end

# If search is present, save it and clean up the params.
# Do not pass params[:year] to the redirect as this does not work with the non-js search
if params[:search] && params[:search][:search_filter] != FormAnswerSearch.default_search[:search_filter]
search = NominationSearch.create(serialized_query: params[:search].to_json)
redirect_to [namespace_name, :form_answers, search_id: search.id, year: params[:year]] and return
end
year = JSON.parse(search.serialized_query)[:year]
redirect_to [namespace_name, :form_answers, search_id: search.id, year: year] and return

if params[:search_id]
elsif params[:search_id]
search = NominationSearch.find_by_id(params[:search_id])

if search.present?
payload = JSON.parse(search.serialized_query)
search_params[:search_filter] = payload["search_filter"]
search_params[:query] = payload["query"]
search_params[:sort] = payload["sort"]
search_params[:year] = payload["year"]

# Update the year parameter if it is different
if params[:year] && search_params[:year] != params[:year]
search_params[:year] = params[:year]
search.update_attribute(:serialized_query, search_params.to_json)

# Redirect to include the year parameter if it is not present
elsif !params[:year] && namespace_name == :admin
redirect_to [namespace_name, :form_answers, search_id: search.id, year: search_params[:year]] and return
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
' Bulk actions:
' select groups from the list below and click an appropriate bulk action button.
- if flash[:bulk_error].present?
p.govuk-body.govuk-bulk-error-message
p.govuk-body.govuk-bulk-error-message#bulk_error
= flash[:bulk_error]
.bulk-assignment-buttons-container
= f.submit "Bulk assign to Lord Lieutenancy office", class: "govuk-button bulk-assign-lieutenants-link", name: "bulk_assign_lieutenants"
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions app/views/admin/form_answers/bulk_assign_assessors.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
h3.govuk-heading-m
| Bulk assign groups to national assessor sub-group

.govuk-body
| Please select the national assessor sub-group that you would like to assign the selected groups to.

= form_for [namespace_name, @form] do |f|
.govuk-grid-row
.govuk-form-group.primary-subgroup-group.govuk-grid-column-one-third
Expand Down
4 changes: 1 addition & 3 deletions app/views/admin/form_answers/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ h1.govuk-heading-xl
| Nominations

= simple_form_for @search, url: admin_form_answers_path(year: params[:year]), method: :post, as: :search, html: { class: 'search-form'} do |f|
.govuk-grid-row
.govuk-grid-row.if-no-js-hide
= render "layouts/vertical_admin_award_year"

.govuk-grid-row
Expand Down Expand Up @@ -46,5 +46,3 @@ h1.govuk-heading-xl
= render("admin/form_answers/list_components/table", f: f)

= paginate @form_answers

= render("admin/form_answers/bulk_assignment_modal")
4 changes: 2 additions & 2 deletions spec/controllers/admin/form_answers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
it "deserializes search params" do
search = NominationSearch.create(serialized_query: { sort: "company_or_nominee_name.asc" }.to_json)
expect {
get :index, params: { search_id: search.id }
get :index, params: { search_id: search.id, year: "all_years" }
}.not_to change {
NominationSearch.count
}
Expand All @@ -40,7 +40,7 @@
search = NominationSearch.create(serialized_query: { sort: "company_or_nominee_name.desc" }.to_json)

expect {
get :index, params: { search_id: search.id }
get :index, params: { search_id: search.id, year: "all_years" }
}.not_to change {
NominationSearch.count
}
Expand Down

0 comments on commit bafd8a8

Please sign in to comment.