From 35ca66cbb73473765b80fbda7448f14ad6d0e414 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 15 Dec 2023 12:19:22 +1100 Subject: [PATCH] Respond fast by rendering only partial --- app/jobs/connect_app_job.rb | 2 +- app/reflexes/admin/connected_app_reflex.rb | 10 ++++++++++ .../admin/enterprises/form/_connected_apps.html.haml | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/jobs/connect_app_job.rb b/app/jobs/connect_app_job.rb index 5be6b4f56a..2db9826508 100644 --- a/app/jobs/connect_app_job.rb +++ b/app/jobs/connect_app_job.rb @@ -17,7 +17,7 @@ class ConnectAppJob < ApplicationJob return unless channel - selector = "#edit_enterprise_#{enterprise.id} #connected_apps_panel div" + selector = "#edit_enterprise_#{enterprise.id} #connected-app-discover-regen" html = ApplicationController.render( partial: "admin/enterprises/form/connected_apps", locals: { enterprise: }, diff --git a/app/reflexes/admin/connected_app_reflex.rb b/app/reflexes/admin/connected_app_reflex.rb index 50f0df0e32..8bfb83d562 100644 --- a/app/reflexes/admin/connected_app_reflex.rb +++ b/app/reflexes/admin/connected_app_reflex.rb @@ -7,10 +7,20 @@ module Admin authorize! :admin, enterprise app = ConnectedApp.create!(enterprise_id: enterprise.id) + selector = "#edit_enterprise_#{enterprise.id} #connected-app-discover-regen" + html = ApplicationController.render( + partial: "admin/enterprises/form/connected_apps", + locals: { enterprise: }, + ) + + # Avoid race condition by sending before enqueuing job: + cable_ready.morph(selector:, html:).broadcast + ConnectAppJob.perform_later( app, current_user.spree_api_key, channel: SessionChannel.for_request(request), ) + morph :nothing end end end diff --git a/app/views/admin/enterprises/form/_connected_apps.html.haml b/app/views/admin/enterprises/form/_connected_apps.html.haml index a370b91380..ae816b9999 100644 --- a/app/views/admin/enterprises/form/_connected_apps.html.haml +++ b/app/views/admin/enterprises/form/_connected_apps.html.haml @@ -1,5 +1,5 @@ - enterprise ||= f.object -%div{ data: {reflex: {root: ".connected-app__head, .connected-app__connection"}} } +#connected-app-discover-regen .connected-app__head %div %h3= t ".title"