From 2998170cdda66a39f81f582db90372c1f33d98d7 Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Tue, 5 Apr 2022 16:14:25 +0100 Subject: [PATCH] Remove hotwire turbo (#406) * Remove turbo * No turbo so redirect form response * Handle multiple errors per field * Remove turbo styles --- Gemfile | 4 +- Gemfile.lock | 9 +-- app/controllers/form_controller.rb | 10 ++- app/frontend/application.js | 1 - app/frontend/styles/application.scss | 6 -- app/views/case_logs/edit.html.erb | 47 +++++++------- app/views/form/check_answers.html.erb | 44 +++++++------- app/views/form/page.html.erb | 84 ++++++++++++-------------- app/views/layouts/application.html.erb | 4 +- package.json | 2 - spec/features/form/validations_spec.rb | 24 ++++---- spec/requests/form_controller_spec.rb | 2 +- yarn.lock | 18 ------ 13 files changed, 108 insertions(+), 147 deletions(-) diff --git a/Gemfile b/Gemfile index e08f126a0..09562e673 100644 --- a/Gemfile +++ b/Gemfile @@ -25,8 +25,8 @@ gem "govuk_design_system_formbuilder" gem "govuk_markdown" # GOV UK Notify gem "notifications-ruby-client" -# Turbo and Stimulus -gem "hotwire-rails" +# A modest javascript framework for the html you already have +gem "stimulus-rails" # Administration framework gem "activeadmin" # Admin charts diff --git a/Gemfile.lock b/Gemfile.lock index b09b5b1da..05f784cd2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -188,10 +188,6 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) hashdiff (1.0.1) - hotwire-rails (0.1.3) - rails (>= 6.0.0) - stimulus-rails - turbo-rails i18n (1.10.0) concurrent-ruby (~> 1.0) inherited_resources (1.13.1) @@ -432,9 +428,6 @@ GEM thor (1.2.1) timecop (0.9.5) timeout (0.2.0) - turbo-rails (1.0.1) - actionpack (>= 6.0.0) - railties (>= 6.0.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) uk_postcode (2.1.7) @@ -482,7 +475,6 @@ DEPENDENCIES govuk-components govuk_design_system_formbuilder govuk_markdown - hotwire-rails jsbundling-rails json-schema listen (~> 3.3) @@ -510,6 +502,7 @@ DEPENDENCIES sentry-rails sentry-ruby simplecov + stimulus-rails timecop (~> 0.9.4) two_factor_authentication! tzinfo-data diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index b24632b31..787017186 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -17,8 +17,9 @@ class FormController < ApplicationController redirect_to(send(redirect_path, @case_log)) end else - @subsection = @case_log.form.subsection_for_page(@page) - render "form/page", status: :unprocessable_entity + redirect_path = "case_log_#{@page.id}_path" + session[:errors] = @case_log.errors.to_json + redirect_to(send(redirect_path, @case_log)) end else render_not_found @@ -39,6 +40,11 @@ class FormController < ApplicationController form.pages.map do |page| define_method(page.id) do |_errors = {}| if @case_log + if session["errors"] + JSON(session["errors"]).each do |field, messages| + messages.each { |message| @case_log.errors.add field.to_sym, message } + end + end @subsection = @case_log.form.subsection_for_page(page) @page = @case_log.form.get_page(page.id) if @page.routed_to?(@case_log) && @page.subsection.enabled?(@case_log) diff --git a/app/frontend/application.js b/app/frontend/application.js index d3a684d94..98742bb09 100644 --- a/app/frontend/application.js +++ b/app/frontend/application.js @@ -16,6 +16,5 @@ require.context("govuk-frontend/govuk/assets") import { initAll } from "govuk-frontend" import "./styles/application.scss" import "./controllers" -import "@hotwired/turbo-rails" initAll() diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index 17a5a97cf..a89fa2cce 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -25,12 +25,6 @@ $govuk-global-styles: true; @import "pagination"; @import "panel"; -// Turbo -.turbo-progress-bar { - height: govuk-spacing(1); - background-color: $govuk-brand-colour; -} - // App utilities .app-\!-colour-muted { color: $govuk-secondary-text-colour !important; diff --git a/app/views/case_logs/edit.html.erb b/app/views/case_logs/edit.html.erb index fe7e2d661..015db4454 100644 --- a/app/views/case_logs/edit.html.erb +++ b/app/views/case_logs/edit.html.erb @@ -4,30 +4,27 @@ content_for(:title) => "" }) %> -<%= turbo_frame_tag "case_log_form", target: "_top" do %> -
<%= get_subsections_count(@case_log, :completed) %> of <%= get_subsections_count(@case_log, :all) %> sections completed.
-- <% next_incomplete_section = get_next_incomplete_section(@case_log) %> -
-- <% if next_incomplete_section.present? %> - - Skip to next incomplete section: <%= next_incomplete_section.label %> - - <% end %> -
- <% elsif @case_log.status == "not_started" %> -This log has not been started.
- <% end %> - - <%= render "tasklist" %> -<%= get_subsections_count(@case_log, :completed) %> of <%= get_subsections_count(@case_log, :all) %> sections completed.
++ <% next_incomplete_section = get_next_incomplete_section(@case_log) %> +
++ <% if next_incomplete_section.present? %> + + Skip to next incomplete section: <%= next_incomplete_section.label %> + + <% end %> +
+ <% elsif @case_log.status == "not_started" %> +This log has not been started.
+ <% end %> + <%= render "tasklist" %><%= @page.description.html_safe %>
- <% end %> +<%= form_with model: @case_log, url: form_case_log_path(@case_log), method: "post", local: true do |f| %> +<%= @page.description.html_safe %>
+ <% end %> + + <% @page.non_conditional_questions.map do |question| %> +