Skip to content

Commit

Permalink
Add Turbo 8 Beta - page refreshes
Browse files Browse the repository at this point in the history
  • Loading branch information
forsbergplustwo committed Dec 1, 2023
1 parent 66ddd07 commit 93bc505
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gem "rubyzip"
# Frontend
gem "sprockets-rails"
gem "jsbundling-rails"
gem "turbo-rails"
gem "turbo-rails", "= 2.0.0.pre.beta.1"
gem "stimulus-rails"
gem "devise"
gem "polaris_view_components"
Expand Down
24 changes: 12 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ GEM
erubi (1.12.0)
ffi (1.15.5)
foreman (0.87.2)
globalid (1.1.0)
activesupport (>= 5.0)
globalid (1.2.1)
activesupport (>= 6.1)
graphql (2.0.26)
graphql-client (0.18.0)
activesupport (>= 3.0)
Expand Down Expand Up @@ -163,7 +163,7 @@ GEM
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.21.3)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
Expand All @@ -189,11 +189,11 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.4-arm64-darwin)
nokogiri (1.15.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-darwin)
nokogiri (1.15.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
numo-narray (0.9.2.1)
orm_adapter (0.5.0)
Expand All @@ -217,7 +217,7 @@ GEM
public_suffix (5.0.3)
puma (6.3.1)
nio4r (~> 2.0)
racc (1.7.1)
racc (1.7.3)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
Expand Down Expand Up @@ -251,7 +251,7 @@ GEM
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
rake (13.1.0)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
Expand Down Expand Up @@ -342,9 +342,9 @@ GEM
stimulus-rails (1.2.2)
railties (>= 6.0.0)
tabreader (1.0.1)
thor (1.2.2)
thor (1.3.0)
timeout (0.4.0)
turbo-rails (1.4.0)
turbo-rails (2.0.0.pre.beta.1)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
Expand Down Expand Up @@ -372,7 +372,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.11)
zeitwerk (2.6.12)

PLATFORMS
arm64-darwin-21
Expand Down Expand Up @@ -417,7 +417,7 @@ DEPENDENCIES
standard-rails
standard-thread_safety
stimulus-rails
turbo-rails
turbo-rails (= 2.0.0.pre.beta.1)
tzinfo-data
web-console
webdrivers
Expand Down
26 changes: 3 additions & 23 deletions app/models/import.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Import < ApplicationRecord
include ActionView::RecordIdentifier

belongs_to :user
broadcasts_refreshes

belongs_to :user, touch: true
has_many :payments, dependent: :delete_all
has_many :metrics, dependent: :delete_all
has_one_attached :payouts_file, dependent: :destroy
Expand Down Expand Up @@ -31,8 +33,6 @@ class Import < ApplicationRecord
validates :status, presence: true, inclusion: {in: statuses.keys}

after_create_commit :schedule
after_update_commit :broadcast_details_update
after_update_commit :broadcast_status_update, if: -> { saved_change_to_status? }

scope :in_progress, -> { where(status: %i[scheduled importing calculating]) }

Expand Down Expand Up @@ -98,24 +98,4 @@ def import_metrics_before_date
# Don't include the latest day, because it may not be complete
user.payments.maximum(:payment_date) - 1.day
end

private

def broadcast_details_update
broadcast_replace_to(
[user, :imports],
target: dom_id(self, :details),
partial: "imports/import",
locals: {import: self}
)
end

def broadcast_status_update
broadcast_replace_to(
[user, :imports],
target: dom_id(self, :status),
partial: "shared/status",
locals: {resource: self}
)
end
end
6 changes: 4 additions & 2 deletions app/models/import/metrics_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def calculate_new_metrics
end
end
end
Metric.import!(metrics, validate: false, no_returning: true) if metrics.present?
@import.touch
if metrics.present?
Metric.import!(metrics, validate: false, no_returning: true)
@import.touch
end
end
end

Expand Down
6 changes: 4 additions & 2 deletions app/models/import/payments_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def import_new_payments
payments << new_payment(transaction)
end

Payment.import!(payments.compact, validate: false, no_returning: true) if payments.present?
@import.touch
if payments.present?
Payment.import!(payments.compact, validate: false, no_returning: true)
@import.touch
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

broadcasts_refreshes

has_many :payments, dependent: :delete_all
has_many :metrics, dependent: :delete_all
has_many :imports, dependent: :delete_all
Expand Down
2 changes: 1 addition & 1 deletion app/views/imports/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
accept: Import::ACCEPTED_FILE_TYPES.join(","),
multiple: false,
data: {
action: "ondrop@window->form#markAsDirty"
action: "polaris-dropzone:drop-accepted->form#markAsDirty"
}
) %>
<% end %>
Expand Down
56 changes: 28 additions & 28 deletions app/views/imports/_import.html.erb
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<%= tag.div id: dom_id(import, :details) do %>
<%= polaris_card do %>
<%= polaris_vertical_stack(gap: "6") do |stack| %>
<%= turbo_stream_from import %>

<%= polaris_stack(alignment: :center) do |nested_stack| %>
<% nested_stack.with_item do %>
<%= polaris_icon(name: "DynamicSourceMajor", color: :base) %>
<% end %>
<% nested_stack.with_item do %>
<%= polaris_text_strong { t("imports.source") } %><br>
<%= t("imports.sources.#{import.source}") %>
<% end %>
<% end %>
<%= polaris_card do %>
<%= polaris_vertical_stack(gap: "6") do |stack| %>

<%= polaris_stack(alignment: :center) do |nested_stack| %>
<% nested_stack.with_item do %>
<%= polaris_icon(name: "CashDollarMajor", color: :base) %>
<% end %>
<% nested_stack.with_item do %>
<%= polaris_text_strong { t("imports.imported") } %><br>
<%= number_with_delimiter(import.payments.count) %> <%= t("imports.payments") %>
<% end %>
<%= polaris_stack(alignment: :center) do |nested_stack| %>
<% nested_stack.with_item do %>
<%= polaris_icon(name: "DynamicSourceMajor", color: :base) %>
<% end %>
<% nested_stack.with_item do %>
<%= polaris_text_strong { t("imports.source") } %><br>
<%= t("imports.sources.#{import.source}") %>
<% end %>
<% end %>

<%= polaris_stack(alignment: :center) do |nested_stack| %>
<% nested_stack.with_item do %>
<%= polaris_icon(name: "CalendarTimeMinor", color: :base) %>
<% end %>
<% nested_stack.with_item do %>
<%= polaris_text_strong { t("imports.metrics_date_range") } %><br>
<%= metrics_date_range_text(import)%>
<% end %>
<%= polaris_stack(alignment: :center) do |nested_stack| %>
<% nested_stack.with_item do %>
<%= polaris_icon(name: "CashDollarMajor", color: :base) %>
<% end %>
<% nested_stack.with_item do %>
<%= polaris_text_strong { t("imports.imported") } %><br>
<%= number_with_delimiter(import.payments.count) %> <%= t("imports.payments") %>
<% end %>
<% end %>

<%= polaris_stack(alignment: :center) do |nested_stack| %>
<% nested_stack.with_item do %>
<%= polaris_icon(name: "CalendarTimeMinor", color: :base) %>
<% end %>
<% nested_stack.with_item do %>
<%= polaris_text_strong { t("imports.metrics_date_range") } %><br>
<%= metrics_date_range_text(import)%>
<% end %>
<% end %>

<% end %>
<% end %>
5 changes: 4 additions & 1 deletion app/views/imports/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= turbo_stream_from current_user %>

<%= polaris_page(
title: t(".title"),
subtitle: t(".subtitle")
Expand Down Expand Up @@ -51,5 +53,6 @@
url: destroy_all_imports_path,
title: t("actions.delete", resource: resource_name_for(Import, true)) + "?",
message: t("imports.confirm_destroy"),
primary_action_text: t("actions.delete", resource: resource_name_for(Import, true))
primary_action_text: t("actions.delete", resource: resource_name_for(Import, true)),
data: {"turbo-permanent": true}
%>
2 changes: 0 additions & 2 deletions app/views/imports/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<%= turbo_stream_from [current_user, :imports] %>

<%= polaris_page(
narrow_width: true,
title: t(".title"),
Expand Down
8 changes: 4 additions & 4 deletions app/views/imports/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<%= turbo_stream_from [current_user, :imports] %>

<%= polaris_page(
narrow_width: true,
title: t(".title"),
Expand All @@ -25,12 +23,14 @@

<% end %>

<%= turbo_frame_tag :globe, src: import_globe_path(@import) %>
<%= turbo_frame_tag :globe, src: import_globe_path(@import), data: {"turbo-permanent": true} %>

<%= render "modals/destroy",
id: "destroy-modal",
url: @import,
title: t("actions.delete", resource: resource_name_for(Import)) + "?",
message: t("imports.confirm_destroy"),
primary_action_text: t("actions.delete", resource: resource_name_for(Import))
primary_action_text: t("actions.delete", resource: resource_name_for(Import),
data: {"turbo-permanent": true}
)
%>
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<%= javascript_include_tag "application" %>
<%= hotwire_livereload_tags if Rails.env.development? %>
<%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %>

<%= turbo_refreshes_with method: :morph, scroll: :preserve %>
<%= yield :head %>
</head>

<body style="<%= polaris_html_styles %>">
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
ssl_params: {verify_mode: OpenSSL::SSL::VERIFY_NONE}
}
end

# TODO: Remove this once turbo-rails v8 is stable
# Required due to: https://github.com/hotwired/turbo-rails/pull/525/files
Sidekiq.strict_args!(false)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": "true",
"dependencies": {
"@hotwired/stimulus": "^3.2.1",
"@hotwired/turbo-rails": "^7.3.0",
"@hotwired/turbo-rails": "^8.0.0",
"@rails/activestorage": "7.0.8",
"@rails/request.js": "^0.0.8",
"chartkick": "^5.0.1",
Expand Down
24 changes: 15 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,20 @@
resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.2.2.tgz#071aab59c600fed95b97939e605ff261a4251608"
integrity sha512-eGeIqNOQpXoPAIP7tC1+1Yc1yl1xnwYqg+3mzqxyrbE5pg5YFBZcA6YoTiByJB6DKAEsiWtl6tjTJS4IYtbB7A==

"@hotwired/turbo-rails@^7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-7.3.0.tgz#422c21752509f3edcd6c7b2725bbe9e157815f51"
integrity sha512-fvhO64vp/a2UVQ3jue9WTc2JisMv9XilIC7ViZmXAREVwiQ2S4UC7Go8f9A1j4Xu7DBI6SbFdqILk5ImqVoqyA==
"@hotwired/turbo-rails@^8.0.0":
version "8.0.0-beta.1"
resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-8.0.0-beta.1.tgz#7d5bd2843caa5d8d224eb36f22078311163128bd"
integrity sha512-x9G95vehf5LR4yYGvhD4z6wBMbmAVi0V87FTfenrmXPru4SfOVDsCwdEINBWsLqOvCgRPQD9eY2nGyDfZlsukg==
dependencies:
"@hotwired/turbo" "^7.3.0"
"@hotwired/turbo" "^8.0.0-beta.1"
"@rails/actioncable" "^7.0"

"@hotwired/turbo@^7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.3.0.tgz#2226000fff1aabda9fd9587474565c9929dbf15d"
integrity sha512-Dcu+NaSvHLT7EjrDrkEmH4qET2ZJZ5IcCWmNXxNQTBwlnE5tBZfN6WxZ842n5cHV52DH/AKNirbPBtcEXDLW4g==
"@hotwired/turbo@^8.0.0-beta.1":
version "8.0.0-beta.1"
resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-8.0.0-beta.1.tgz#35a7086c4c959445db059ea4a9b9af85cdafa616"
integrity sha512-g66YmO/Oa+EThB3KkNDhrM9mFnNyRn6tqgwGiBHh4Vf+d3XjCznuWSG2o2e2cO/RlddVRtCwvBSMuG6sYQWX+g==
dependencies:
idiomorph "https://github.com/basecamp/idiomorph#rollout-build"

"@kurkle/color@^0.3.0":
version "0.3.2"
Expand Down Expand Up @@ -381,6 +383,10 @@ h3-js@4:
resolved "https://registry.yarnpkg.com/h3-js/-/h3-js-4.1.0.tgz#f8c4a8ad36612489a954f1a0bb3f4b7657d364e5"
integrity sha512-LQhmMl1dRQQjMXPzJc7MpZ/CqPOWWuAvVEoVJM9n/s7vHypj+c3Pd5rLQCkAsOgAoAYKbNCsYFE++LF7MvSfCQ==

"idiomorph@git+https://github.com/basecamp/idiomorph.git#rollout-build":
version "0.0.8"
resolved "git+https://github.com/basecamp/idiomorph.git#e906820368e4c9c52489a3336b8c3826b1bf6de5"

index-array-by@1, index-array-by@^1.4.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/index-array-by/-/index-array-by-1.4.1.tgz#425f26cf0c744a47ebadf47366692e52043cf17b"
Expand Down

0 comments on commit 93bc505

Please sign in to comment.