diff --git a/Gemfile b/Gemfile index 3304387..39ab846 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 9da1f70..4f890a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/app/models/import.rb b/app/models/import.rb index e83bc38..b050345 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -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 @@ -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]) } @@ -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 diff --git a/app/models/import/metrics_processor.rb b/app/models/import/metrics_processor.rb index 05bbc46..b828d0f 100644 --- a/app/models/import/metrics_processor.rb +++ b/app/models/import/metrics_processor.rb @@ -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 diff --git a/app/models/import/payments_processor.rb b/app/models/import/payments_processor.rb index 6a2e8c2..653c274 100644 --- a/app/models/import/payments_processor.rb +++ b/app/models/import/payments_processor.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 6f54bbe..4914703 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/imports/_form.html.erb b/app/views/imports/_form.html.erb index a17cde5..a07f0b3 100644 --- a/app/views/imports/_form.html.erb +++ b/app/views/imports/_form.html.erb @@ -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 %> diff --git a/app/views/imports/_import.html.erb b/app/views/imports/_import.html.erb index 8baf645..02603e3 100644 --- a/app/views/imports/_import.html.erb +++ b/app/views/imports/_import.html.erb @@ -1,4 +1,5 @@ -<%= tag.div id: dom_id(import, :details) do %> +<%= turbo_stream_from import %> + <%= polaris_card do %> <%= polaris_vertical_stack(gap: "6") do |stack| %> @@ -34,4 +35,3 @@ <% end %> <% end %> -<% end %> diff --git a/app/views/imports/index.html.erb b/app/views/imports/index.html.erb index 414e001..0d6f1df 100644 --- a/app/views/imports/index.html.erb +++ b/app/views/imports/index.html.erb @@ -1,3 +1,5 @@ +<%= turbo_stream_from current_user %> + <%= polaris_page( title: t(".title"), subtitle: t(".subtitle") @@ -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} %> diff --git a/app/views/imports/new.html.erb b/app/views/imports/new.html.erb index f407d00..08bb73d 100644 --- a/app/views/imports/new.html.erb +++ b/app/views/imports/new.html.erb @@ -1,5 +1,3 @@ -<%= turbo_stream_from [current_user, :imports] %> - <%= polaris_page( narrow_width: true, title: t(".title"), diff --git a/app/views/imports/show.html.erb b/app/views/imports/show.html.erb index 1027857..60cdec6 100644 --- a/app/views/imports/show.html.erb +++ b/app/views/imports/show.html.erb @@ -1,5 +1,3 @@ -<%= turbo_stream_from [current_user, :imports] %> - <%= polaris_page( narrow_width: true, title: t(".title"), @@ -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} + ) %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a3481d3..96bed36 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -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 %> diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index b19e2fd..d48832c 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -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) diff --git a/package.json b/package.json index d9e6e77..0172c38 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": "true", "dependencies": { "@hotwired/stimulus": "^3.2.1", - "@hotwired/turbo-rails": "^7.3.0", + "@hotwired/turbo-rails": "^8.0.0-beta.1", "@rails/activestorage": "7.0.8", "@rails/request.js": "^0.0.8", "chartkick": "^5.0.1", diff --git a/yarn.lock b/yarn.lock index 31f89ee..c3937aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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-beta.1": + 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" @@ -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@https://github.com/basecamp/idiomorph#rollout-build": + version "0.0.8" + resolved "https://github.com/basecamp/idiomorph#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"