Skip to content

Commit

Permalink
refactor submissions status to a single-click
Browse files Browse the repository at this point in the history
update long dropdowns with comboboxes
  • Loading branch information
ryanwoldatwork authored Jan 8, 2025
2 parents a99edfb + dcfebab commit 8e1a674
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 79 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def set_submission
end

def status_params
params.require(:submission).permit(:aasm_state)
params.permit(:aasm_state)
end

def tag_params
Expand Down
2 changes: 1 addition & 1 deletion app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Submission < ApplicationRecord
transitions from: [:acknowledged], to: :dispatched
end
event :respond do
transitions from: %i[dispatched archived], to: :responded
transitions from: %i[dispatched], to: :responded
end
event :archive do
transitions to: :archived
Expand Down
24 changes: 14 additions & 10 deletions app/views/admin/cx_collections/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_with(model: cx_collection, url: (cx_collection.persisted? ? admin_cx_collection_path(cx_collection) : admin_cx_collections_path), class: "usa-form", local: true, data: { turbo: false }) do |form| %>
<%= form_with(model: cx_collection, url: (cx_collection.persisted? ? admin_cx_collection_path(cx_collection) : admin_cx_collections_path), local: true, data: { turbo: false }) do |form| %>
<%- if cx_collection.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(cx_collection.errors.count, "error") %> prohibited this cx_collection from being saved:</h2>
Expand Down Expand Up @@ -27,20 +27,24 @@

<div class="field">
<%= form.label :service_provider_id, "HISP Service Provider", class: "usa-label" %>
<%= form.select :service_provider_id, ServiceProvider.active.includes(:organization).order("organizations.abbreviation", :name).map { |h| ["#{h.organization.abbreviation} - #{h.organization.name} - #{h.name}", h.id] }, { include_blank: true }, { class: "usa-select", required: true } %>
<div class="usa-combo-box" data-default-value="<%= cx_collection.service_provider_id %>">
<%= form.select :service_provider_id, ServiceProvider.active.includes(:organization).order("organizations.abbreviation", :name).map { |h| ["#{h.organization.abbreviation} - #{h.organization.name} - #{h.name}", h.id] }, { include_blank: true }, { class: "usa-select", required: true } %>
</div>
</div>

<div class="field">
<%= form.label :service_id, "Service", class: "usa-label" %>
<%= form.select :service_id, { include_blank: true }, {}, { class: "usa-select", required: true } do %>
<% Service.hisp.includes(:organization).each do |h| %>
<%= content_tag :option,
"#{h.organization.abbreviation} - #{h.organization.name} - #{h.name}", value: h.id,
"data-service-provider-id" => h.service_provider_id,
selected: (h.id == cx_collection.service_id)
%>
<div class="usa-combo-box" data-default-value="<%= cx_collection.service_id %>">
<%= form.select :service_id, { include_blank: true }, {}, { class: "usa-select", required: true } do %>
<% Service.hisp.includes(:organization).each do |h| %>
<%= content_tag :option,
"#{h.organization.abbreviation} - #{h.organization.name} - #{h.name}", value: h.id,
"data-service-provider-id" => h.service_provider_id,
selected: (h.id == cx_collection.service_id)
%>
<% end %>
<% end %>
<% end %>
</div>
</div>

<div class="field">
Expand Down
4 changes: 3 additions & 1 deletion app/views/admin/forms/_admin_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
<div class="grid-col-6">
<div class="field">
<%= f.label :organization_id, "Organization", class: "usa-label" %>
<%= f.select :organization_id, options_for_select(organization_dropdown_options, selected: (@form.organization ? @form.organization.id : nil)), { prompt: "Select an Organization" }, { class: "usa-select" } %>
<div class="usa-combo-box" data-default-value="<%= @form.organization_id %>">
<%= f.select :organization_id, options_for_select(organization_dropdown_options, selected: (@form.organization ? @form.organization.id : nil)), { prompt: "Select an Organization" }, { class: "usa-select" } %>
</div>
</div>
</div>
<div class="grid-col-6">
Expand Down
19 changes: 8 additions & 11 deletions app/views/admin/forms/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
<i class="far fa-flag" aria-hidden="true"></i>
Create a new form
</div>
<p class="usa-prose">
Create a new form from scratch.
</p>
<%= render 'form', form: @form %>
</div>
</div>
Expand All @@ -76,16 +73,16 @@
<i class="far fa-copy" aria-hidden="true"></i>
Copy a form
</div>
<p class="usa-prose">
Copy an existing form and give it a new name.
</p>
<%- if @surveys.present? %>
<%= form_tag(copy_id_admin_forms_path) do %>
<%= select_tag "id", options_from_collection_for_select(@surveys, "short_uuid", "name"), {
prompt: "Select a form",
class: "usa-select",
"aria-labelledby" => "copy-form-label"
} %>
<label class="usa-label" for="id">Select an existing form</label>
<div class="usa-combo-box">
<%= select_tag "id", options_from_collection_for_select(@surveys, "short_uuid", "name"), {
prompt: "Select a form",
class: "usa-select",
"aria-labelledby" => "copy-form-label"
} %>
</div>
<p>
<%= submit_tag "Copy Form", class: "usa-button", disabled: true %>
</p>
Expand Down
71 changes: 37 additions & 34 deletions app/views/admin/submissions/_status_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
<%= form_with(model: submission, url: admin_form_submission_path(form, submission), local: true) do |f| %>
<%- if form.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(form.errors.count, "error") %> prohibited this form from being saved:</h2>
<fieldset class="usa-fieldset">
<legend class="usa-legend font-serif-md">Submission status
<%= link_to "https://github.com/GSA/touchpoints/wiki/Feedback-lifecyle", target: "_blank", rel: "noopener" do %>
<span class="fa fa-info-circle"></span>
<% end %>
</legend>
<p class="font-sans-xs">
Every response begins with a "received" status.
You have the option to track additional states of a response by updating its status.
</p>

<% form.errors.full_messages.each do |message| %>
<div class="usa-alert usa-alert--error">
<div class="usa-alert__body">
<h3 class="usa-alert__heading">Error</h3>
<p class="usa-alert__text">
<%= message %>
</p>
<ol class="usa-process-list">
<% @submission.aasm.states.each do |state| %>
<li class="usa-process-list__item padding-bottom-4">
<p class="usa-process-list__heading font-sans-md line-height-sans-4">
<span class="<%= @submission.aasm_state == state.name.to_s ? "" : "text-normal text-base-lighter" %>">
<%= state.name.capitalize %>
</span>
<br>
<div class="font-sans-xs">
<% unique_transitions = Set.new %>
<% @submission.aasm.events(permitted: true).each do |event| %>
<% if @submission.aasm_state == state.to_s %>
<% event.transitions.each do |transition| %>
<% if unique_transitions.add?(transition.to) && @submission.aasm_state != transition.to.to_s %>
<%= link_to event.to_s.capitalize,
admin_form_submission_path(form, @submission, aasm_state: transition.to),
method: :patch
%>&nbsp;
<% end %>
<% end %>
<% end %>
<% end %>
</div>
</div>
<% end %>
</div>
<% end %>

<div class="grid-row grid-gap-md">
<div class="grid-col-12">
<p>
Every response begins with a "received" status.
You have the option to track
additional states of a response by updating its status.
</p>
<fieldset class="usa-fieldset">
<div>
<%= f.label :aasm_state, "Status", class: "usa-label" %>
<%= f.select :aasm_state, [:received, :acknowledged, :dispatched, :responded], {}, class: "usa-select" %>
</div>
</fieldset>
</div>
</div>
<br>
<%= f.submit "Update status", class: "usa-button" %>
<% end %>
</p>
</li>
<% end %>
</ol>
</fieldset>

<script>
$(function(){
Expand Down
14 changes: 0 additions & 14 deletions app/views/admin/submissions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,8 @@
</div>
<div class="grid-col-4">
<div class="well usa-section usa-section--dark">
<div class="text-uppercase font-body-3xs">
Processing each response
</div>
<%= render 'admin/submissions/status_form', { form: @form, submission: @submission } %>
</div>
<div class="usa-alert usa-alert--info usa-alert--slim">
<div class="usa-alert__body">
<p class="usa-alert__text">
About the
<%= link_to "https://github.com/GSA/touchpoints/wiki/Feedback-lifecyle", target: "_blank", rel: "noopener" do %>
Feedback lifecycle
<% end %>
</p>
</div>
</div>
<br>
<div class="tags-div well">
<%= render 'admin/submissions/tags', submission: @submission %>
</div>
Expand Down
8 changes: 5 additions & 3 deletions spec/features/admin/cx_collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@
let(:current_year) { Time.zone.now.strftime('%Y') }

before do
select(service_provider.name, from: 'cx_collection_service_provider_id')
select(service.name, from: 'cx_collection_service_id')
expect(page).to have_content('After creating this collection, you can add survey results in the following screen.')
fill_in("cx_collection_service_provider_id", with: service_provider.name)
find("#cx_collection_service_provider_id--list").click
fill_in("cx_collection_service_id", with: service.name)
find("#cx_collection_service_id--list").click
select(current_year, from: 'cx_collection_fiscal_year')
select(4, from: 'cx_collection_quarter')
wait_for_ajax
click_on 'Create Cx collection'
end

Expand Down
5 changes: 1 addition & 4 deletions spec/features/admin/submissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@
end

it 'try to update a submission that has had its question validations changed' do
select("acknowledged", from: 'submission_aasm_state')
select("responded", from: 'submission_aasm_state')
click_on("Update status")

click_on("Acknowledge")
expect(page).to have_content("Response could not be updated.")
end
end
Expand Down

0 comments on commit 8e1a674

Please sign in to comment.