Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cable_ready responses with turbo_stream OFN-12794 #12896

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2935fb6
Handle user session responses with turbo_stream
wandji20 Oct 12, 2024
edeaa89
Handle user confirmation responses with turbo_stream
wandji20 Oct 12, 2024
c2792bc
Handle user password responses with turbo_stream
wandji20 Oct 12, 2024
afc9e31
Handle user registration responses with turbo_stream
wandji20 Oct 13, 2024
5a2dd1b
Handle order checkout responses with turbo_stream
wandji20 Oct 13, 2024
e9fa008
Handle order voucher responses with turbo_stream
wandji20 Oct 13, 2024
8a2863e
Handle enterprise edit response with turbo_stream
wandji20 Oct 13, 2024
3054b0b
Handle admin search orders with turbo_stream
wandji20 Oct 13, 2024
36254fe
remove cable ready from application controller and refactor shared/al…
wandji20 Oct 13, 2024
44d4e22
Replace bulk invoice CableReady broadcast with ActionCable
wandji20 Oct 15, 2024
9ffd68b
Replace connected app CableReady broadcast with ActionCable
wandji20 Oct 15, 2024
92016a4
Replace admin report CableReady broadcast with ActionCable
wandji20 Oct 15, 2024
09d5d4e
Remove white_label reflex and handle remove enterprise logo wth turbo…
wandji20 Oct 19, 2024
b1df050
Move orders reflex logic to admin orders controller
wandji20 Oct 19, 2024
933aaa4
Refactor bulk_action stimulus controller and handle orders bulk actio…
wandji20 Oct 19, 2024
663a36c
Handle single order actions with turbo_stream
wandji20 Oct 19, 2024
fd9667a
Small improvements
wandji20 Oct 19, 2024
c5e9602
Remove cable ready and mrujs dependencies
wandji20 Oct 20, 2024
7af0ac6
Fix rubocop errors
wandji20 Oct 20, 2024
ad13f2e
Refactor confirm modal conponent to handle forms
wandji20 Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'app/controllers/spree/admin/orders_controller.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLines:
Expand Down Expand Up @@ -35,15 +41,8 @@ Lint/EmptyClass:
- 'spec/lib/reports/report_loader_spec.rb'

# Offense count: 1
# Configuration parameters: AllowComments.
Lint/EmptyFile:
Exclude:
- 'spec/lib/open_food_network/enterprise_injection_data_spec.rb'

# Offense count: 2
Lint/FloatComparison:
Exclude:
- 'app/models/product_import/entry_validator.rb'
- 'app/models/spree/gateway/pay_pal_express.rb'

# Offense count: 1
Expand Down Expand Up @@ -85,14 +84,13 @@ Lint/UselessMethodDefinition:
Exclude:
- 'app/models/spree/gateway.rb'

# Offense count: 24
# Offense count: 23
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Exclude:
- 'app/controllers/admin/enterprises_controller.rb'
- 'app/controllers/payment_gateways/paypal_controller.rb'
- 'app/controllers/spree/admin/payments_controller.rb'
- 'app/controllers/spree/admin/taxons_controller.rb'
- 'app/controllers/spree/admin/variants_controller.rb'
- 'app/controllers/spree/orders_controller.rb'
- 'app/helpers/spree/admin/navigation_helper.rb'
Expand Down Expand Up @@ -137,6 +135,7 @@ Metrics/ClassLength:
- 'app/controllers/admin/resource_controller.rb'
- 'app/controllers/admin/subscriptions_controller.rb'
- 'app/controllers/application_controller.rb'
- 'app/controllers/checkout_controller.rb'
- 'app/controllers/payment_gateways/paypal_controller.rb'
- 'app/controllers/spree/admin/orders_controller.rb'
- 'app/controllers/spree/admin/payment_methods_controller.rb'
Expand All @@ -162,7 +161,6 @@ Metrics/ClassLength:
- 'app/models/spree/user.rb'
- 'app/models/spree/variant.rb'
- 'app/models/spree/zone.rb'
- 'app/reflexes/admin/orders_reflex.rb'
- 'app/serializers/api/cached_enterprise_serializer.rb'
- 'app/serializers/api/enterprise_shopfront_serializer.rb'
- 'app/services/cart_service.rb'
Expand All @@ -178,12 +176,11 @@ Metrics/ClassLength:
- 'lib/reporting/reports/enterprise_fee_summary/scope.rb'
- 'lib/reporting/reports/xero_invoices/base.rb'

# Offense count: 32
# Offense count: 30
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Metrics/CyclomaticComplexity:
Exclude:
- 'app/controllers/admin/enterprises_controller.rb'
- 'app/controllers/spree/admin/taxons_controller.rb'
- 'app/controllers/spree/orders_controller.rb'
- 'app/helpers/checkout_helper.rb'
- 'app/helpers/order_cycles_helper.rb'
Expand All @@ -199,7 +196,6 @@ Metrics/CyclomaticComplexity:
- 'app/models/spree/preferences/preferable_class_methods.rb'
- 'app/models/spree/return_authorization.rb'
- 'app/models/spree/tax_rate.rb'
- 'app/models/spree/variant.rb'
- 'app/models/spree/zone.rb'
- 'lib/open_food_network/enterprise_issue_validator.rb'
- 'lib/reporting/reports/xero_invoices/base.rb'
Expand All @@ -208,13 +204,12 @@ Metrics/CyclomaticComplexity:
- 'lib/spree/localized_number.rb'
- 'spec/models/product_importer_spec.rb'

# Offense count: 24
# Offense count: 23
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Exclude:
- 'app/controllers/admin/enterprises_controller.rb'
- 'app/controllers/payment_gateways/paypal_controller.rb'
- 'app/controllers/spree/admin/taxons_controller.rb'
- 'app/controllers/spree/orders_controller.rb'
- 'app/helpers/spree/admin/navigation_helper.rb'
- 'app/models/spree/ability.rb'
Expand Down Expand Up @@ -293,19 +288,17 @@ Metrics/ParameterLists:
- 'spec/support/controller_requests_helper.rb'
- 'spec/system/admin/reports_spec.rb'

# Offense count: 4
# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Metrics/PerceivedComplexity:
Exclude:
- 'app/controllers/spree/admin/taxons_controller.rb'
- 'app/models/enterprise_relationship.rb'
- 'app/models/spree/ability.rb'
- 'app/models/spree/order/checkout.rb'

# Offense count: 8
# Offense count: 7
Naming/AccessorMethodName:
Exclude:
- 'app/controllers/spree/admin/taxonomies_controller.rb'
- 'app/mailers/producer_mailer.rb'
- 'app/models/spree/order.rb'
- 'app/services/checkout/post_checkout_actions.rb'
Expand Down Expand Up @@ -353,7 +346,7 @@ Naming/VariableNumber:
- 'spec/models/spree/tax_rate_spec.rb'
- 'spec/requests/api/orders_spec.rb'

# Offense count: 142
# Offense count: 141
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ResponseMethods.
# ResponseMethods: response, last_response
Expand Down Expand Up @@ -557,7 +550,7 @@ RSpecRails/InferredSpecType:
- 'spec/requests/voucher_adjustments_spec.rb'
- 'spec/routing/stripe_spec.rb'

# Offense count: 22
# Offense count: 21
# Configuration parameters: IgnoreScopes, Include.
# Include: app/models/**/*.rb
Rails/InverseOf:
Expand All @@ -572,11 +565,10 @@ Rails/InverseOf:
- 'app/models/spree/price.rb'
- 'app/models/spree/product.rb'
- 'app/models/spree/stock_item.rb'
- 'app/models/spree/taxonomy.rb'
- 'app/models/spree/variant.rb'
- 'app/models/subscription_line_item.rb'

# Offense count: 35
# Offense count: 36
# Configuration parameters: Include.
# Include: app/controllers/**/*.rb, app/mailers/**/*.rb
Rails/LexicallyScopedActionFilter:
Expand Down Expand Up @@ -720,17 +712,15 @@ Style/GlobalStdStream:
- 'lib/tasks/subscriptions/debug.rake'
- 'lib/tasks/subscriptions/test.rake'

# Offense count: 12
# Offense count: 10
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSplatArgument.
Style/HashConversion:
Exclude:
- 'app/controllers/admin/column_preferences_controller.rb'
- 'app/controllers/admin/variant_overrides_controller.rb'
- 'app/controllers/spree/admin/products_controller.rb'
- 'app/models/order_cycle.rb'
- 'app/models/product_import/product_importer.rb'
- 'app/models/spree/shipping_method.rb'
- 'app/serializers/api/admin/exchange_serializer.rb'
- 'app/services/variants_stock_levels.rb'
- 'spec/controllers/admin/inventory_items_controller_spec.rb'
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ gem 'redis'
gem 'sidekiq'
gem 'sidekiq-scheduler'

gem "cable_ready"
gem "stimulus_reflex"

gem "turbo_power"
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,6 @@ DEPENDENCIES
bootsnap
bugsnag
bullet
cable_ready
cancancan (~> 1.15.0)
capybara
catalog!
Expand Down
4 changes: 2 additions & 2 deletions app/components/confirm_modal_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(
controller: nil,
message: nil,
confirm_actions: nil,
confirm_reflexes: nil,
form_url: nil,
confirm_button_class: :primary,
confirm_button_text: I18n.t('js.admin.modals.confirm'),
cancel_button_text: I18n.t('js.admin.modals.cancel'),
Expand All @@ -17,7 +17,7 @@ def initialize(
super(id:, close_button: true)
@confirm_actions = confirm_actions
@reflex = reflex
@confirm_reflexes = confirm_reflexes
@form_url = form_url
@controller = controller
@message = message
@confirm_button_class = confirm_button_class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
%div{ id: @id, "data-controller": "modal #{@controller}", "data-action": "keyup@document->modal#closeIfEscapeKey", "data-#{@controller}-reflex-value": @reflex }
.reveal-modal-bg.fade{ "data-modal-target": "background", "data-action": "click->modal#close" }
.reveal-modal.fade.tiny.modal-component{ "data-modal-target": "modal" }
= content
- if @confirm_actions
= content

= render @message if @message
= render @message if @message

%div{ class: "modal-actions #{@actions_alignment_class}" }
%input{ class: "button icon-plus #{close_button_class}", type: 'button', value: @cancel_button_text, "data-action": "click->modal#close" }
%input{ id: 'modal-confirm-button', class: "button icon-plus #{@confirm_button_class}", type: 'button', value: @confirm_button_text, "data-action": @confirm_actions, "data-reflex": @confirm_reflexes }
%div{ class: "modal-actions #{@actions_alignment_class}" }
%input{ class: "button icon-plus #{close_button_class}", type: 'button', value: @cancel_button_text, "data-action": "click->modal#close" }
%input{ id: 'modal-confirm-button', class: "button icon-plus #{@confirm_button_class}", type: 'button', value: @confirm_button_text, "data-action": @confirm_actions }
- elsif @form_url
= form_with(url: @form_url, method: :post, data: { turbo: true, controller: 'bulk-actions' }) do
= content
%p{ class: "modal-actions #{@actions_alignment_class}" }
%button.button.secondary{ type: "button", 'data-action': 'click->modal#close' }
= @cancel_button_text
%button.button.primary{ type: 'submit' }
= @confirm_button_text
23 changes: 15 additions & 8 deletions app/components/ship_order_component.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
= render ConfirmModalComponent.new(id: dom_id(@order, :ship), confirm_reflexes: "click->Admin::OrdersReflex#ship", controller: "orders", reflex: "Admin::Orders#ship") do
%div{class: "margin-bottom-30"}
%p= t('spree.admin.orders.shipment.mark_as_shipped_message_html')
%div{class: "margin-bottom-30"}
= hidden_field_tag :id, @order.id
= label_tag do
= check_box_tag :send_shipment_email, "1", true
= t('spree.admin.orders.shipment.mark_as_shipped_label_message')
= render ModalComponent.new(id: dom_id(@order, :ship), modal_class: 'tiny', close_button: false) do
= form_with(url: helpers.ship_admin_order_url(@order), method: :post, data: { turbo: true }) do
%div{class: "margin-bottom-30"}
%p= t('spree.admin.orders.shipment.mark_as_shipped_message_html')
%div{class: "margin-bottom-30"}
= hidden_field_tag :id, @order.id
= hidden_field_tag :current_page, @current_page
= label_tag do
= check_box_tag :send_shipment_email, "1", true
= t('spree.admin.orders.shipment.mark_as_shipped_label_message')
%p.modal-actions.justify-space-around
%button.button.secondary{ type: "button", 'data-action': 'click->modal#close' }
= t('js.admin.modals.cancel')
%button.button.primary{ type: 'submit' }
= t('js.admin.modals.confirm')
3 changes: 2 additions & 1 deletion app/components/ship_order_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

class ShipOrderComponent < ViewComponent::Base
def initialize(order:)
def initialize(order:, current_page:)
@order = order
@current_page = current_page
end
end
36 changes: 32 additions & 4 deletions app/controllers/admin/enterprises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
module Admin
class EnterprisesController < Admin::ResourceController
include GeocodeEnterpriseAddress
include CablecarResponses
include Pagy::Backend

# These need to run before #load_resource so that @object is initialised with sanitised values
prepend_before_action :override_owner, only: :create
prepend_before_action :override_sells, only: :create

before_action :load_countries, except: [:index, :register, :check_permalink]
before_action :load_countries, except: [:index, :register, :check_permalink, :remove_logo]
before_action :load_methods_and_fees, only: [:edit, :update]
before_action :load_groups, only: [:new, :edit, :update, :create]
before_action :load_taxons, only: [:new, :edit, :update, :create]
Expand Down Expand Up @@ -51,8 +50,10 @@ def edit

@enterprise.is_primary_producer = params[:is_primary_producer]
@enterprise.sells = params[:enterprise_sells]
render cable_ready: cable_car.morph("#side_menu", partial("admin/shared/side_menu"))
.morph("#permalink", partial("admin/enterprises/form/permalink"))
respond_to do |format|
format.html { head :ok }
format.turbo_stream { render :edit }
end
end

def welcome
Expand Down Expand Up @@ -141,6 +142,33 @@ def visible
end
end

def remove_logo
# delete the white_label_logo_link attribute as well since it has no meaning without the logo
@object.update!(white_label_logo: nil, white_label_logo_link: "")

f = ActionView::Helpers::FormBuilder.new(:enterprise, @object, view_context, {})

respond_to do |format|
format.html do
flash[:success] = I18n.t("admin.enterprises.form.white_label.remove_logo_success")
redirect_to edit_admin_enterprise_path
end
format.turbo_stream do
flash.now[:success] = I18n.t("admin.enterprises.form.white_label.remove_logo_success")
render turbo_stream: [
turbo_stream.replace(
'white_label_panel',
partial: "admin/enterprises/form/white_label", locals: { f:, enterprise: @object }
),
turbo_stream.append(
"flashes",
partial: 'admin/shared/flashes', locals: { flashes: flash }
)
]
end
end
end

protected

def delete_custom_tab
Expand Down
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
require 'open_food_network/referer_parser'

class ApplicationController < ActionController::Base
include CablecarResponses
include Pagy::Backend
include RequestTimeouts

Expand Down
14 changes: 8 additions & 6 deletions app/controllers/checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class CheckoutController < BaseController
include CheckoutCallbacks
include CheckoutSteps
include OrderCompletion
include CablecarResponses
include WhiteLabel

helper 'terms_and_conditions'
Expand Down Expand Up @@ -49,17 +48,20 @@ def update
rescue Spree::Core::GatewayError => e
flash[:error] = I18n.t(:spree_gateway_error_flash_for_checkout, error: e.message)
@order.update_column(:state, "payment")
render cable_ready: cable_car.redirect_to(url: checkout_step_path(:payment))
redirect_to checkout_step_path(:payment)
end

private

def render_error
flash.now[:error] ||= I18n.t('checkout.errors.saving_failed')

render status: :unprocessable_entity, cable_ready: cable_car.
replace("#checkout", partial("checkout/checkout")).
replace("#flashes", partial("shared/flashes", locals: { flashes: flash }))
respond_to do |format|
format.html { head :unprocessable_entity }
format.turbo_stream do
render :render_error, status: :unprocessable_entity
end
end
end

def check_payments_adjustments
Expand Down Expand Up @@ -87,7 +89,7 @@ def redirect_to_payment_gateway
return unless selected_payment_method&.external_gateway?
return unless (redirect_url = selected_payment_method.external_payment_url(order: @order))

render cable_ready: cable_car.redirect_to(url: redirect_url)
redirect_to redirect_url
true
end

Expand Down
15 changes: 0 additions & 15 deletions app/controllers/concerns/cablecar_responses.rb

This file was deleted.

Loading
Loading