Replace cable_ready report loading w/ Turbo stream

I'm adding TurboPower for the scroll_into_view action. It adds all the
nice CableReady actions to Turbo Streams.

Note that I omitted `block: "start"` because that option is the default
in Javascript. And the generic `action` method doesn't support
parameters like this anyway. I'll work on that in the next commit.

I also re-introduced a race condition by rendering the "loading"
indicator after triggering the report rendering job. I'm planning to
resolve that later.
This commit is contained in:
Maikel Linke
2024-08-15 09:49:31 +10:00
parent 19ef047193
commit d354317c73
8 changed files with 19 additions and 16 deletions

View File

@@ -58,18 +58,6 @@ module Admin
end
def render_in_background
cable_ready[ScopedChannel.for_id(params[:uuid])]
.inner_html(
selector: "#report-go",
html: helpers.button(t(:go), "report__submit-btn", "submit", disabled: true)
).inner_html(
selector: "#report-table",
html: render_to_string(partial: "admin/reports/loading")
).scroll_into_view(
selector: "#report-table",
block: "start"
).broadcast
blob = ReportBlob.create_for_upload_later!(report_filename)
ReportJob.perform_later(
@@ -78,8 +66,6 @@ module Admin
blob:,
channel: ScopedChannel.for_id(params[:uuid]),
)
head :no_content
end
end
end

View File

@@ -0,0 +1,5 @@
= turbo_stream.update "report-go" do
= button t(:go), "report__submit-btn", "submit", disabled: true
= turbo_stream.update "report-table" do
= render "admin/reports/loading"
= turbo_stream.action(:scroll_into_view, "report-table")

View File

@@ -3,7 +3,7 @@
- content_for :minimal_js, true
= form_for @report.search, { url: url_for, data: { remote: "true" } } do |f|
= form_for @report.search, { url: url_for, data: { turbo: "true" } } do |f|
= hidden_field_tag "uuid", request.uuid
%fieldset.no-border-bottom.print-hidden

View File

@@ -1,5 +1,8 @@
import "@hotwired/turbo";
import TurboPower from "turbo_power";
TurboPower.initialize(Turbo.StreamActions);
document.addEventListener("turbo:frame-missing", (event) => {
// don't replace frame contents
event.preventDefault();

View File

@@ -34,6 +34,7 @@
"stimulus_reflex": "3.5.1",
"tom-select": "^2.3.1",
"trix": "^2.1.5",
"turbo_power": "^0.6.2",
"webpack": "~4"
},
"devDependencies": {

View File

@@ -311,13 +311,14 @@ RSpec.describe Admin::ReportsController, type: :controller do
it "triggers the delivery report" do
spree_post :create, {
format: :turbo,
q: { completed_at_lt: 1.day.ago },
shipping_method_in: ["123"], # We just need to search for shipping methods
report_type: :order_cycle_management,
report_subtype: "delivery",
}
expect(response).to have_http_status(:no_content)
expect(response).to have_http_status(:ok)
end
end

View File

@@ -115,6 +115,8 @@ RSpec.describe '
end
it "allows the report to finish before the loading screen is rendered" do
pending "Race condition between loading message and report rendering"
login_as_admin
visit admin_report_path(report_type: :customers)

View File

@@ -8825,6 +8825,11 @@ tty-browserify@0.0.0:
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"
integrity sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=
turbo_power@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/turbo_power/-/turbo_power-0.6.2.tgz#d2320ffd18d7dba641bfbddaba388ffef5d90cb6"
integrity sha512-GCrwi6+rSLVORqb1LwP9pf/jP1Zo5lJgzGbLVu8g79T6LvB/9GGg7VWdLlWB0RvvDE1/+3hm32MPtEL5g89fsg==
type-check@~0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72"