From e505325d796524eec52785ed48518a74f0bc220f Mon Sep 17 00:00:00 2001 From: Ryan Wold <64987852+ryanwoldatwork@users.noreply.github.com> Date: Wed, 8 Jan 2025 08:20:59 -0800 Subject: [PATCH 1/2] refactor submissions status to a single-click --- .../admin/submissions_controller.rb | 2 +- app/models/submission.rb | 2 +- .../admin/submissions/_status_form.html.erb | 71 ++++++++++--------- app/views/admin/submissions/show.html.erb | 14 ---- spec/features/admin/submissions_spec.rb | 5 +- 5 files changed, 40 insertions(+), 54 deletions(-) diff --git a/app/controllers/admin/submissions_controller.rb b/app/controllers/admin/submissions_controller.rb index 6cef38022..0bb14edc1 100644 --- a/app/controllers/admin/submissions_controller.rb +++ b/app/controllers/admin/submissions_controller.rb @@ -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 diff --git a/app/models/submission.rb b/app/models/submission.rb index 328ff7995..734dc3b74 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -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 diff --git a/app/views/admin/submissions/_status_form.html.erb b/app/views/admin/submissions/_status_form.html.erb index 5834194be..41b825843 100644 --- a/app/views/admin/submissions/_status_form.html.erb +++ b/app/views/admin/submissions/_status_form.html.erb @@ -1,39 +1,42 @@ -<%= form_with(model: submission, url: admin_form_submission_path(form, submission), local: true) do |f| %> - <%- if form.errors.any? %> -
-

<%= pluralize(form.errors.count, "error") %> prohibited this form from being saved:

+
+ Submission status + <%= link_to "https://github.com/GSA/touchpoints/wiki/Feedback-lifecyle", target: "_blank", rel: "noopener" do %> + + <% end %> + +

+ Every response begins with a "received" status. + You have the option to track additional states of a response by updating its status. +

- <% form.errors.full_messages.each do |message| %> -
-
-

Error

-

- <%= message %> -

+
    + <% @submission.aasm.states.each do |state| %> +
  1. +

    + "> + <%= state.name.capitalize %> + +
    +

    + <% 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 + %>  + <% end %> + <% end %> + <% end %> + <% end %>
    -
- <% end %> -
- <% end %> - -
-
-

- Every response begins with a "received" status. - You have the option to track - additional states of a response by updating its status. -

-
-
- <%= f.label :aasm_state, "Status", class: "usa-label" %> - <%= f.select :aasm_state, [:received, :acknowledged, :dispatched, :responded], {}, class: "usa-select" %> -
-
-
-
-
- <%= f.submit "Update status", class: "usa-button" %> -<% end %> +

+ + <% end %> + +