From 827ccd72bc824ae2069f488819a84e078fa0cb88 Mon Sep 17 00:00:00 2001 From: Damian Legawiec Date: Mon, 13 Dec 2021 21:18:41 +0100 Subject: [PATCH 1/9] Fix turbo select 2 & calendars (#74) * Fixed Select2 when using back button with Turbo * Fixed flatpickr when using back button with Turbo --- app/assets/javascripts/spree/backend/global/flatpickr.es6 | 6 ++++++ .../spree/backend/global/select2_autocomplete.es6 | 7 +++++++ app/assets/javascripts/spree/backend/spree-select2.js | 7 +++++++ app/views/spree/admin/products/_form.html.erb | 1 - 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/spree/backend/global/flatpickr.es6 b/app/assets/javascripts/spree/backend/global/flatpickr.es6 index ebe0b82614..cdf033f063 100644 --- a/app/assets/javascripts/spree/backend/global/flatpickr.es6 +++ b/app/assets/javascripts/spree/backend/global/flatpickr.es6 @@ -21,3 +21,9 @@ document.addEventListener("spree:load", function() { flatpickr('.datepicker', {}) }) +document.addEventListener("turbo:before-cache", function() { + document.querySelectorAll('.datePickerFrom, .datePickerTo, .datepicker').forEach(function(element) { + element._flatpickr.destroy() + }) +}) + diff --git a/app/assets/javascripts/spree/backend/global/select2_autocomplete.es6 b/app/assets/javascripts/spree/backend/global/select2_autocomplete.es6 index 5e08e33c3b..925ba9e475 100644 --- a/app/assets/javascripts/spree/backend/global/select2_autocomplete.es6 +++ b/app/assets/javascripts/spree/backend/global/select2_autocomplete.es6 @@ -25,6 +25,13 @@ document.addEventListener("spree:load", function() { loadAutoCompleteParams() }) +// we need to delete select2 instances before document is saved to cache +// https://stackoverflow.com/questions/36497723/select2-with-ajax-gets-initialized-several-times-with-rails-turbolinks-events +document.addEventListener("turbo:before-cache", function() { + const select2Autocompletes = document.querySelectorAll('select[data-autocomplete-url-value]') + select2Autocompletes.forEach(element => $(element).select2('destroy')) +}) + // eslint-disable-next-line no-unused-vars function loadAutoCompleteParams() { const select2Autocompletes = document.querySelectorAll('select[data-autocomplete-url-value]') diff --git a/app/assets/javascripts/spree/backend/spree-select2.js b/app/assets/javascripts/spree/backend/spree-select2.js index 19f240f4a5..fb0e67283f 100644 --- a/app/assets/javascripts/spree/backend/spree-select2.js +++ b/app/assets/javascripts/spree/backend/spree-select2.js @@ -1,3 +1,10 @@ +// we need to delete select2 instances before document is saved to cache +// https://stackoverflow.com/questions/36497723/select2-with-ajax-gets-initialized-several-times-with-rails-turbolinks-events +document.addEventListener("turbo:before-cache", function() { + $('select.select2').select2('destroy') + $('select.select2-clear').select2('destroy') +}) + document.addEventListener("spree:load", function() { // Initiate a standard Select2 on any select element with the class .select2 // Remember to add a place holder in the HTML as needed. diff --git a/app/views/spree/admin/products/_form.html.erb b/app/views/spree/admin/products/_form.html.erb index 360d08bee2..e008970316 100644 --- a/app/views/spree/admin/products/_form.html.erb +++ b/app/views/spree/admin/products/_form.html.erb @@ -231,7 +231,6 @@ <%= f.select :option_type_ids, options_from_collection_for_select(@product.option_types, :id, :name, @product.option_type_ids), { include_hidden: true }, multiple: true, - class: 'select2-hidden-accessible', data: { autocomplete_url_value: 'option_types_api_v2', autocomplete_return_attr_value: 'name', autocomplete_multiple_value: true } %> From 5ca901ad07dbc7ca196b384684b6775641591b9e Mon Sep 17 00:00:00 2001 From: Damian Legawiec Date: Sun, 19 Dec 2021 23:28:14 +0100 Subject: [PATCH 2/9] Don't try to make a call to the countries API when there's no Country ID present (#82) --- app/assets/javascripts/spree/backend/address_states.es6 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/javascripts/spree/backend/address_states.es6 b/app/assets/javascripts/spree/backend/address_states.es6 index 781704a480..6ba7ac5ef3 100644 --- a/app/assets/javascripts/spree/backend/address_states.es6 +++ b/app/assets/javascripts/spree/backend/address_states.es6 @@ -4,6 +4,8 @@ function updateAddressState(region, successCallback) { const stateSelect = $('#' + region + 'state select') const stateInput = $('#' + region + 'state input.state_name') + if (!countryId) { return } + fetch(Spree.routes.countries_api_v2 + '/' + countryId + '?include=states', { headers: Spree.apiV2Authentication() }).then((response) => { From 16ee1dbdb4798f812168a7998e15da755d87efec Mon Sep 17 00:00:00 2001 From: Aleksandar Petrushev Date: Tue, 21 Dec 2021 11:43:51 +0100 Subject: [PATCH 3/9] Show Return Authorizations for current store only (#84) --- app/controllers/spree/admin/return_index_controller.rb | 5 ++--- .../controllers/spree/admin/return_index_controller_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/spree/admin/return_index_controller.rb b/app/controllers/spree/admin/return_index_controller.rb index 12f5f83281..fcb1d78431 100644 --- a/app/controllers/spree/admin/return_index_controller.rb +++ b/app/controllers/spree/admin/return_index_controller.rb @@ -2,7 +2,7 @@ module Spree module Admin class ReturnIndexController < BaseController def return_authorizations - collection(Spree::ReturnAuthorization) + collection(Spree::ReturnAuthorization.for_store(current_store)) respond_with(@collection) end @@ -18,9 +18,8 @@ def collection(resource) params[:q] ||= {} - @collection = resource.all # @search needs to be defined as this is passed to search_form_for - @search = @collection.ransack(params[:q]) + @search = resource.ransack(params[:q]) per_page = params[:per_page] || Spree::Backend::Config[:admin_customer_returns_per_page] @collection = @search.result.order(created_at: :desc).page(params[:page]).per(per_page) end diff --git a/spec/controllers/spree/admin/return_index_controller_spec.rb b/spec/controllers/spree/admin/return_index_controller_spec.rb index 28cb2b7aa2..f75887f93e 100644 --- a/spec/controllers/spree/admin/return_index_controller_spec.rb +++ b/spec/controllers/spree/admin/return_index_controller_spec.rb @@ -11,12 +11,18 @@ module Admin end let(:return_authorization) { create(:return_authorization) } + let(:order_other_store) { create(:shipped_order, store: create(:store)) } + let(:return_authorization_other_store) { create(:return_authorization, order: order_other_store) } before { subject } it 'loads return authorizations' do expect(assigns(:collection)).to include(return_authorization) end + + it 'does not include other store return authorization' do + expect(assigns(:collection)).not_to include(return_authorization_other_store) + end end describe '#customer_returns' do From 162e5e334b54195ae27702caf68cbc1cf8676fd3 Mon Sep 17 00:00:00 2001 From: Aleksandar Petrushev Date: Wed, 22 Dec 2021 14:38:03 +0100 Subject: [PATCH 4/9] Do not set checkout zone for new store --- app/views/spree/admin/stores/_form.html.erb | 2 +- spec/features/admin/configuration/stores_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/spree/admin/stores/_form.html.erb b/app/views/spree/admin/stores/_form.html.erb index 3a24354172..4e21c02c2d 100644 --- a/app/views/spree/admin/stores/_form.html.erb +++ b/app/views/spree/admin/stores/_form.html.erb @@ -152,7 +152,7 @@ <% end %> <%= f.field_container :checkout_zone_id do %> <%= f.label :checkout_zone_id, Spree.t(:zone) %> - <%= f.select :checkout_zone_id, options_for_select(@zones, selected_checkout_zone(@store)&.id), { include_blank: Spree.t(:no_limits_zone) }, { class: 'select2' } %> + <%= f.select :checkout_zone_id, options_for_select(@zones), { include_blank: Spree.t(:no_limits_zone) }, { class: 'select2' } %> <%= raw(Spree.t('store_form.checkout_zone_help')) %> diff --git a/spec/features/admin/configuration/stores_spec.rb b/spec/features/admin/configuration/stores_spec.rb index f7e4218c81..704178661c 100644 --- a/spec/features/admin/configuration/stores_spec.rb +++ b/spec/features/admin/configuration/stores_spec.rb @@ -48,6 +48,7 @@ expect(page).to have_current_path(spree.new_admin_store_path) expect(page).to have_selector(:id, 'select2-store_default_currency-container', text: 'United States Dollar (USD)') + expect(page).to have_field('store_checkout_zone_id', text: 'No Limits') end it 'saving store' do From ba0d0dcba3b315cfb29ae9778fa2a5c30923573a Mon Sep 17 00:00:00 2001 From: Damian Legawiec Date: Mon, 10 Jan 2022 12:55:53 +0100 Subject: [PATCH 5/9] Test against Spree 4.4 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5aa392922e..d4f45e4d28 100644 --- a/Gemfile +++ b/Gemfile @@ -55,7 +55,7 @@ group :development do gem 'solargraph' end -spree_opts = { github: 'spree/spree', branch: 'main' } +spree_opts = { github: 'spree/spree', branch: '4-4-stable' } gem 'spree_core', spree_opts gem 'spree_api', spree_opts From 1efa5b376579013dd6675207e2764ef9a10a865e Mon Sep 17 00:00:00 2001 From: Roc Yu Date: Tue, 28 Dec 2021 16:35:13 +0800 Subject: [PATCH 6/9] Remove un-used locals variable (#91) --- app/views/spree/admin/products/index.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/spree/admin/products/index.html.erb b/app/views/spree/admin/products/index.html.erb index d67426da4b..87179d73eb 100644 --- a/app/views/spree/admin/products/index.html.erb +++ b/app/views/spree/admin/products/index.html.erb @@ -10,7 +10,6 @@
<%= search_form_for [:admin, @search] do |f| %> - <%- locals = {f: f} %>
From 0ff2bd066f45938ac5f12130cdd4ed28359ef81d Mon Sep 17 00:00:00 2001 From: Damian Legawiec Date: Mon, 10 Jan 2022 12:58:53 +0100 Subject: [PATCH 7/9] Bump version to 4.4 RC2 --- lib/spree/backend/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spree/backend/version.rb b/lib/spree/backend/version.rb index db1437df2a..26511e091c 100644 --- a/lib/spree/backend/version.rb +++ b/lib/spree/backend/version.rb @@ -1,6 +1,6 @@ module Spree module Backend - VERSION = '4.4.0.rc1'.freeze + VERSION = '4.4.0.rc2'.freeze def self.version VERSION From 4f35aaea949e172ec951ba515d84edd9f530e839 Mon Sep 17 00:00:00 2001 From: Damian Legawiec Date: Wed, 26 Jan 2022 14:16:13 +0100 Subject: [PATCH 8/9] Update version to 4.4.0 --- lib/spree/backend/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spree/backend/version.rb b/lib/spree/backend/version.rb index 26511e091c..c855c204c9 100644 --- a/lib/spree/backend/version.rb +++ b/lib/spree/backend/version.rb @@ -1,6 +1,6 @@ module Spree module Backend - VERSION = '4.4.0.rc2'.freeze + VERSION = '4.4.0'.freeze def self.version VERSION From af7507f0db6099876978427e55a7d6e4f32d25b9 Mon Sep 17 00:00:00 2001 From: Hendra Nicholas Date: Tue, 9 Aug 2022 08:02:57 +0700 Subject: [PATCH 9/9] Fixed thumbnail images --- app/assets/stylesheets/spree/backend/shared/_base.scss | 2 -- app/views/spree/admin/images/index.html.erb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/assets/stylesheets/spree/backend/shared/_base.scss b/app/assets/stylesheets/spree/backend/shared/_base.scss index 2c720af18e..6abd0a3942 100644 --- a/app/assets/stylesheets/spree/backend/shared/_base.scss +++ b/app/assets/stylesheets/spree/backend/shared/_base.scss @@ -44,8 +44,6 @@ div.admin-product-image-container { img { max-width: 100%; height: auto; - align-self: center; - transform: scale(1.6); } svg { diff --git a/app/views/spree/admin/images/index.html.erb b/app/views/spree/admin/images/index.html.erb index e98db044eb..40e5c2810d 100644 --- a/app/views/spree/admin/images/index.html.erb +++ b/app/views/spree/admin/images/index.html.erb @@ -42,7 +42,7 @@
- <%= link_to image_tag(main_app.url_for(image.url(:product))), main_app.rails_blob_url(image.attachment) %> + <%= link_to image_tag(main_app.url_for(image.url(:mini))), main_app.rails_blob_url(image.attachment) %>
<% if has_variants %>