From 1e18c00ab91d6da8ba4185ae59472e9d84ffb943 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 15 Nov 2023 17:53:24 +0100 Subject: [PATCH 01/15] Improve the copy of the legacy UI switch --- core/config/locales/en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 8c0cd525e3a..3077f7b364d 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -1800,8 +1800,8 @@ en: name_on_card: Name on card name_or_sku: Name or SKU (enter at least first 4 characters of product name) navigation: - switch_to_legacy: Switch to legacy admin - switch_to_solidus_admin: Switch to new admin + switch_to_legacy: Show Legacy UI + switch_to_solidus_admin: Show Legacy UI negative_movement_absent_item: Cannot create negative movement for absent stock item. new: New new_adjustment: New Adjustment From bd9e0485794d21b296435af948567d2645d3ecae Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 16 Nov 2023 16:02:21 +0100 Subject: [PATCH 02/15] Restore creating a new order from the new admin dashboard --- .../app/controllers/solidus_admin/orders_controller.rb | 10 ++++++++++ admin/config/routes.rb | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/admin/app/controllers/solidus_admin/orders_controller.rb b/admin/app/controllers/solidus_admin/orders_controller.rb index 8570029ffd8..9b45c6bce3b 100644 --- a/admin/app/controllers/solidus_admin/orders_controller.rb +++ b/admin/app/controllers/solidus_admin/orders_controller.rb @@ -20,6 +20,16 @@ def index end end + def new + order = Spree::Order.create!( + created_by: current_solidus_admin_user, + frontend_viewable: false, + store_id: current_store.try(:id) + ) + + redirect_to order_url(order), status: :see_other + end + def show load_order diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 6b45f676195..271e8b33b26 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -18,7 +18,7 @@ get 'states', to: 'countries#states' end - resources :orders, only: [:index, :show, :edit, :update] do + resources :orders, except: [:destroy] do resources :line_items, only: [:destroy, :create, :update] resource :customer resource :ship_address, only: [:show, :edit, :update], controller: "addresses", type: "ship" From d2a637bf01a7475f4ad7aa528819fc0478c73eb3 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 15 Nov 2023 17:52:44 +0100 Subject: [PATCH 03/15] Extract a `ui/dropdown` component from `ui/panel` --- .../navigation/account/component.html.erb | 3 +- .../layout/navigation/account/component.js | 16 ++++++ .../orders/show/address/component.html.erb | 40 ++++++--------- .../ui/dropdown/component.html.erb | 50 +++++++++++++++++++ .../solidus_admin/ui/dropdown/component.js | 16 ++++++ .../solidus_admin/ui/dropdown/component.rb | 27 ++++++++++ .../solidus_admin/ui/dropdown/component.yml | 2 + .../solidus_admin/ui/panel/component.html.erb | 34 ++----------- .../solidus_admin/ui/panel/component.rb | 4 +- .../ui/dropdown/component_preview.rb | 26 ++++++++++ .../component_preview/overview.html.erb | 35 +++++++++++++ .../ui/dropdown/component_spec.rb | 9 ++++ 12 files changed, 205 insertions(+), 57 deletions(-) create mode 100644 admin/app/components/solidus_admin/layout/navigation/account/component.js create mode 100644 admin/app/components/solidus_admin/ui/dropdown/component.html.erb create mode 100644 admin/app/components/solidus_admin/ui/dropdown/component.js create mode 100644 admin/app/components/solidus_admin/ui/dropdown/component.rb create mode 100644 admin/app/components/solidus_admin/ui/dropdown/component.yml create mode 100644 admin/spec/components/previews/solidus_admin/ui/dropdown/component_preview.rb create mode 100644 admin/spec/components/previews/solidus_admin/ui/dropdown/component_preview/overview.html.erb create mode 100644 admin/spec/components/solidus_admin/ui/dropdown/component_spec.rb diff --git a/admin/app/components/solidus_admin/layout/navigation/account/component.html.erb b/admin/app/components/solidus_admin/layout/navigation/account/component.html.erb index 4b10ff51939..84b59dfe07e 100644 --- a/admin/app/components/solidus_admin/layout/navigation/account/component.html.erb +++ b/admin/app/components/solidus_admin/layout/navigation/account/component.html.erb @@ -1,7 +1,8 @@
> <%= form_for @order, url: solidus_admin.send("order_#{@type}_address_path", @order), html: { id: form_id } do |form| %>
-
+

<%= t(".subtitle.#{@type}") %>

- <% if @user&.addresses&.any? %> -
-target="addresses"> - - <%= t(".select_address") %> - <%= render component("ui/icon").new(name: 'arrow-down-s-fill', class: 'w-5 h-5') %> - - -
- <% @user.addresses.each do |address| %> - <%= tag.a( - href: solidus_admin.send("order_#{@type}_address_path", @order, address_id: address.id), - class: 'block text-black text-sm hover:bg-gray-50 p-2 mx-2 w-auto rounded-lg', - 'data-action': "#{stimulus_id}#close", - 'data-turbo-frame': address_frame_id - ) do %> - <%= format_address(address) %> - <% end %> - <% end %> -
-
+ <% if @addresses.present? %> + <%= render component('ui/dropdown').new( + text: t(".select_address"), + "data-#{stimulus_id}-target": "addresses", + class: "max-h-[26rem] overflow-y-auto" + ) do %> + <% @addresses.each do |address| %> + <%= tag.a( + format_address(address), + href: solidus_admin.send("order_#{@type}_address_path", @order, address_id: address.id), + 'data-turbo-frame': address_frame_id, + 'data-action': "#{component('ui/dropdown').stimulus_id}#close", + ) %> + <% end %> + <% end %> <% end %>
diff --git a/admin/app/components/solidus_admin/ui/dropdown/component.html.erb b/admin/app/components/solidus_admin/ui/dropdown/component.html.erb new file mode 100644 index 00000000000..d8c9c70aedc --- /dev/null +++ b/admin/app/components/solidus_admin/ui/dropdown/component.html.erb @@ -0,0 +1,50 @@ +
+> + " + data-action="keydown.esc-><%= stimulus_id %>#close" + > + <% if @text %> + <%= @text %> + <%= icon_tag "arrow-down-s-fill", class: SIZES.fetch(@size) %> + <% else %> + <%= icon_tag "more-line", class: SIZES.fetch(@size) %> + <% end %> + + +
+ <%= content %> +
+
diff --git a/admin/app/components/solidus_admin/ui/dropdown/component.js b/admin/app/components/solidus_admin/ui/dropdown/component.js new file mode 100644 index 00000000000..82080b800aa --- /dev/null +++ b/admin/app/components/solidus_admin/ui/dropdown/component.js @@ -0,0 +1,16 @@ +import { Controller } from '@hotwired/stimulus' +import { useClickOutside } from 'stimulus-use' + +export default class extends Controller { + connect() { + useClickOutside(this) + } + + clickOutside() { + this.close() + } + + close() { + this.element.removeAttribute('open') + } +} diff --git a/admin/app/components/solidus_admin/ui/dropdown/component.rb b/admin/app/components/solidus_admin/ui/dropdown/component.rb new file mode 100644 index 00000000000..e45707f3d01 --- /dev/null +++ b/admin/app/components/solidus_admin/ui/dropdown/component.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class SolidusAdmin::UI::Dropdown::Component < SolidusAdmin::BaseComponent + DIRECTIONS = { + left: "right-0", + right: "left-0", + } + + SIZES = { + s: "w-5 h-5", + m: "w-[22px] h-[22px]", + } + + def initialize(text: nil, size: :m, direction: :left, **attributes) + @text = text + @size = size + @attributes = attributes + @direction = direction + + @attributes[:"data-controller"] = "#{stimulus_id} #{attributes[:"data-controller"]}" + @attributes[:"data-action"] = "turbo:before-cache@window->#{stimulus_id}#close #{attributes[:"data-action"]}" + @attributes[:class] = " + #{@size == :m ? 'body-text' : 'body-small'} + #{@attributes[:class]} + " + end +end diff --git a/admin/app/components/solidus_admin/ui/dropdown/component.yml b/admin/app/components/solidus_admin/ui/dropdown/component.yml new file mode 100644 index 00000000000..fe3f3f93212 --- /dev/null +++ b/admin/app/components/solidus_admin/ui/dropdown/component.yml @@ -0,0 +1,2 @@ +en: + more: "More" diff --git a/admin/app/components/solidus_admin/ui/panel/component.html.erb b/admin/app/components/solidus_admin/ui/panel/component.html.erb index a89d6d72138..d74f69482d9 100644 --- a/admin/app/components/solidus_admin/ui/panel/component.html.erb +++ b/admin/app/components/solidus_admin/ui/panel/component.html.erb @@ -15,36 +15,10 @@ data-controller="<%= stimulus_id %>" > <% if menus? %> -
- "> - <%= render component("ui/icon").new( - name: "more-line", - class: "cursor-pointer w-[22px] h-[22px] hover:fill-gray-500 [[open]_&]:fill-gray-500" - ) %> - -
- <% menus.each do |menu| %> - <%= menu %> - <% end %> -
-
+ <%= render component('ui/dropdown').new( + size: :s, + class: "absolute top-0 right-0 m-6", + ).with_content(safe_join(menus)) %> <% end %> <% if @title %> diff --git a/admin/app/components/solidus_admin/ui/panel/component.rb b/admin/app/components/solidus_admin/ui/panel/component.rb index 2925ecebb15..b2f353eca07 100644 --- a/admin/app/components/solidus_admin/ui/panel/component.rb +++ b/admin/app/components/solidus_admin/ui/panel/component.rb @@ -21,9 +21,9 @@ class SolidusAdmin::UI::Panel::Component < SolidusAdmin::BaseComponent renders_many :menus, ->(name, url, **args) do if args[:method] - button_to(name, url, **args, class: "p-2 hover:bg-gray-25 rounded-sm text-black #{args[:class]}") + button_to(name, url, **args) else - link_to(name, url, **args, class: "p-2 hover:bg-gray-25 rounded-sm text-black #{args[:class]}") + link_to(name, url, **args) end end diff --git a/admin/spec/components/previews/solidus_admin/ui/dropdown/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/dropdown/component_preview.rb new file mode 100644 index 00000000000..6bdbcf4b900 --- /dev/null +++ b/admin/spec/components/previews/solidus_admin/ui/dropdown/component_preview.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +# @component "ui/dropdown" +class SolidusAdmin::UI::Dropdown::ComponentPreview < ViewComponent::Preview + include SolidusAdmin::Preview + + def overview + render_with_template + end + + # @param text text + # @param size select { choices: [s, m] } + # @param direction select { choices: [left, right] } + # @param open toggle + def playground(text: "text", size: :m, direction: :right, open: false) + render component("ui/dropdown").new( + text: text, + size: size.to_sym, + direction: direction.to_sym, + style: "float: #{direction == :left ? 'right' : 'left'}", + open: open, + ).with_content( + tag.span("Lorem ipsum dolor sit amet"), + ) + end +end diff --git a/admin/spec/components/previews/solidus_admin/ui/dropdown/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/dropdown/component_preview/overview.html.erb new file mode 100644 index 00000000000..0bfdf48b970 --- /dev/null +++ b/admin/spec/components/previews/solidus_admin/ui/dropdown/component_preview/overview.html.erb @@ -0,0 +1,35 @@ +
+
+ More icon, direction right +
+ + <%= render current_component.new(direction: :right) do %> + <%= link_to "Link 1", "#" %> + <%= link_to "Link 2", "#" %> + <%= link_to "Link 3", "#" %> + <%= link_to "Link 4", "#" %> + <% end %> +
+ +
+
+ With text, direction right +
+ + <%= render current_component.new(direction: :right, text: "Select address") do %> + <%= link_to "Address 1", "#" %> + <%= link_to "Address 2", "#" %> + <%= link_to "Address 3", "#" %> + <%= link_to "Address 4", "#" %> + <% end %> +
+ +
+
+ Small size, long content +
+ + <%= render current_component.new(direction: :right, size: :s) do %> + <%= link_to "Address 1 Address 2 Address 3 Address 4", "#" %> + <% end %> +
diff --git a/admin/spec/components/solidus_admin/ui/dropdown/component_spec.rb b/admin/spec/components/solidus_admin/ui/dropdown/component_spec.rb new file mode 100644 index 00000000000..adda19a5ac0 --- /dev/null +++ b/admin/spec/components/solidus_admin/ui/dropdown/component_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe SolidusAdmin::UI::Dropdown::Component, type: :component do + it "renders the overview preview" do + render_preview(:overview) + end +end From b9c85c681ced249eae7dace60f07fdd4fe06a471 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 17 Nov 2023 11:32:07 +0100 Subject: [PATCH 04/15] Improve row clicking for the `ui/table` component - Use stimulus params instead of arbitrary data attributes - Only attach the url if the url proc is defined - Improve detection of default-clickable elements for which the row url shouldn't be used --- .../solidus_admin/ui/table/component.html.erb | 6 ++++-- .../solidus_admin/ui/table/component.js | 17 +++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/admin/app/components/solidus_admin/ui/table/component.html.erb b/admin/app/components/solidus_admin/ui/table/component.html.erb index 241ce89aa02..a029b592e26 100644 --- a/admin/app/components/solidus_admin/ui/table/component.html.erb +++ b/admin/app/components/solidus_admin/ui/table/component.html.erb @@ -111,8 +111,10 @@ <% @rows.each do |row| %> + data-action="click-><%= stimulus_id %>#rowClicked" + data-<%= stimulus_id %>-url-param="<%= @row_url.call(row) %>" + <% end %> > <% @columns.each do |column| %> <%= render_data_cell(column.data, row) %> diff --git a/admin/app/components/solidus_admin/ui/table/component.js b/admin/app/components/solidus_admin/ui/table/component.js index 4f411ce4740..d8e4ca7bf54 100644 --- a/admin/app/components/solidus_admin/ui/table/component.js +++ b/admin/app/components/solidus_admin/ui/table/component.js @@ -84,14 +84,13 @@ export default class extends Controller { } rowClicked(event) { - if (event.target.closest('a') || event.target.tagName === 'BUTTON' || event.target.type === 'checkbox') return + // If the user clicked on a link, button, input or summary, skip the row url visit + if (event.target.closest("td").contains(event.target.closest("a,select,textarea,button,input,summary"))) return - const row = event.currentTarget - - if (this.modeValue === 'batch') { - this.toggleCheckbox(row) + if (this.modeValue === "batch") { + this.toggleCheckbox(event.currentTarget) } else { - this.navigateToRow(row) + window.Turbo.visit(event.params.url) } } @@ -104,12 +103,6 @@ export default class extends Controller { } } - navigateToRow(row) { - const url = row.dataset.primaryUrl - - if (url) window.location.href = url - } - render() { const selectedRows = this.checkboxTargets.filter((checkbox) => checkbox.checked) From 1057b1af2bd34fc7e2a2496d8e10e319a98c7511 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 20 Nov 2023 18:16:47 +0100 Subject: [PATCH 05/15] Add a spec for managing order addresses --- admin/spec/features/order_spec.rb | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/admin/spec/features/order_spec.rb b/admin/spec/features/order_spec.rb index ccd5efffeeb..5c94831c190 100644 --- a/admin/spec/features/order_spec.rb +++ b/admin/spec/features/order_spec.rb @@ -37,6 +37,65 @@ expect(page).to be_axe_clean end + it "allows setting and changing the addresses" do + create(:order, number: "R123456789", total: 19.99) + + visit "/admin/orders/R123456789/edit" + + expect(page).to have_content("Order R123456789") + open_customer_menu + click_on "Edit billing address" + expect(page).to have_css("dialog", wait: 30) + + within("dialog") do + fill_in "Name", with: "John Doe" + fill_in "Street Address", with: "1 John Doe Street" + fill_in "Street Address (cont'd)", with: "Apartment 2" + fill_in "City", with: "John Doe City" + fill_in "Zip Code", with: "12345" + fill_in "Phone", with: "555-555-5555" + select "United States", from: "order[bill_address_attributes][country_id]" + select "Alabama", from: "order[bill_address_attributes][state_id]" + click_on "Save" + end + + expect(page).to have_content("The address has been successfully updated.") + expect(page).to have_content("John Doe") + expect(page).to have_content("1 John Doe Street") + expect(page).to have_content("Apartment 2") + expect(page).to have_content("John Doe City") + expect(page).to have_content("12345") + expect(page).to have_content("United States") + expect(page).to have_content("Alabama") + expect(page).to have_content("555-555-5555") + + open_customer_menu + click_on "Edit shipping address" + expect(page).to have_css("dialog", wait: 30) + + within("dialog") do + fill_in "Name", with: "Jane Doe" + fill_in "Street Address", with: "1 Jane Doe Street" + fill_in "Street Address (cont'd)", with: "Apartment 3" + fill_in "City", with: "Jane Doe City" + fill_in "Zip Code", with: "54321" + fill_in "Phone", with: "555-555-5555" + select "United States", from: "order[ship_address_attributes][country_id]" + select "Alabama", from: "order[ship_address_attributes][state_id]" + click_on "Save" + end + + expect(page).to have_content("The address has been successfully updated.") + expect(page).to have_content("Jane Doe") + expect(page).to have_content("1 Jane Doe Street") + expect(page).to have_content("Apartment 3") + expect(page).to have_content("Jane Doe City") + expect(page).to have_content("54321") + expect(page).to have_content("United States") + expect(page).to have_content("Alabama") + expect(page).to have_content("555-555-5555") + end + context "in cart state" do it "allows managing the cart" do create(:product, name: "Just a product", slug: 'just-a-prod', price: 19.99) From 9c03173473a3dd8f5391ee7549a6566585623bee Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 20 Nov 2023 19:08:42 +0100 Subject: [PATCH 06/15] Allow thumbnails to contain an icon --- .../solidus_admin/ui/thumbnail/component.rb | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/admin/app/components/solidus_admin/ui/thumbnail/component.rb b/admin/app/components/solidus_admin/ui/thumbnail/component.rb index 6198e4dbbad..4bfd1a77653 100644 --- a/admin/app/components/solidus_admin/ui/thumbnail/component.rb +++ b/admin/app/components/solidus_admin/ui/thumbnail/component.rb @@ -7,23 +7,25 @@ class SolidusAdmin::UI::Thumbnail::Component < SolidusAdmin::BaseComponent l: 'h-20 w-20', }.freeze - def initialize(size: :m, **attributes) + def initialize(icon: nil, size: :m, **attributes) + @icon = icon @size = size @attributes = attributes end def call - tag.div( - tag.img( - **@attributes, - class: "object-contain h-full w-full", - ), - class: " - #{SIZES[@size]} - rounded border border-gray-100 - bg-white overflow-hidden - #{@attributes[:class]} - " - ) + icon = if @icon + icon_tag(@icon, class: "bg-gray-25 fill-gray-700 #{SIZES[@size]} p-2") + else + tag.img(**@attributes, class: "object-contain #{SIZES[@size]}") + end + + tag.div(icon, class: " + #{SIZES[@size]} + rounded border border-gray-100 + bg-white overflow-hidden + content-box + #{@attributes[:class]} + ") end end From 7c2314ed0214de15cae818e177d46ea2b2f3ea96 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 20 Nov 2023 19:09:32 +0100 Subject: [PATCH 07/15] Add a `.for` method to `ui/thumbnail` with a standard icon/image for each model --- .../solidus_admin/ui/thumbnail/component.rb | 15 +++ .../component_preview/overview.html.erb | 103 ++++++++++++------ 2 files changed, 82 insertions(+), 36 deletions(-) diff --git a/admin/app/components/solidus_admin/ui/thumbnail/component.rb b/admin/app/components/solidus_admin/ui/thumbnail/component.rb index 4bfd1a77653..7776e0a2ccd 100644 --- a/admin/app/components/solidus_admin/ui/thumbnail/component.rb +++ b/admin/app/components/solidus_admin/ui/thumbnail/component.rb @@ -28,4 +28,19 @@ def call #{@attributes[:class]} ") end + + def self.for(record, **attrs) + case record + when Spree::PromotionAction then new(icon: "megaphone-line", **attrs) + when Spree::UnitCancel then new(icon: "close-circle-line", **attrs) + when Spree::TaxRate then new(icon: "percent-line", **attrs) + when Spree::LineItem then self.for(record.variant, **attrs) + when Spree::Product then self.for((record.images.first || record.master.images.first), **attrs) + when Spree::Variant then self.for((record.images.first || record.product), **attrs) + when Spree::Image then new(src: record.attachment&.url(:small), alt: record.alt, **attrs) + when Spree::Order then new(icon: "shopping-bag-line", **attrs) + when Spree::Shipment then new(icon: "truck-line", **attrs) + else new(icon: "question-line", **attrs) + end + end end diff --git a/admin/spec/components/previews/solidus_admin/ui/thumbnail/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/thumbnail/component_preview/overview.html.erb index 411ebee7ee5..ed774adf1e6 100644 --- a/admin/spec/components/previews/solidus_admin/ui/thumbnail/component_preview/overview.html.erb +++ b/admin/spec/components/previews/solidus_admin/ui/thumbnail/component_preview/overview.html.erb @@ -1,45 +1,76 @@ -
-
- Empty -
- <% current_component::SIZES.keys.each do |size| %> - (size: <%= size.inspect %>) - <%= render current_component.new(size: size) %> - <% end %> -
+
+
+
+ Empty +
+ <% current_component::SIZES.keys.each do |size| %> + (size: <%= size.inspect %>) + <%= render current_component.new(size: size) %> + <% end %> +
-
-
- Square -
+
+
+ Square +
- <% current_component::SIZES.keys.each do |size| %> - (size: <%= size.inspect %>) - <%= render current_component.new(size: size, src: "https://placekitten.com/200/200") %> - <%= render current_component.new(size: size, src: "https://placekitten.com/20/20") %> - <% end %> -
+ <% current_component::SIZES.keys.each do |size| %> + (size: <%= size.inspect %>) + <%= render current_component.new(size: size, src: "https://placekitten.com/200/200") %> + <%= render current_component.new(size: size, src: "https://placekitten.com/20/20") %> + <% end %> +
-
-
- Portrait -
+
+
+ Portrait +
- <% current_component::SIZES.keys.each do |size| %> - (size: <%= size.inspect %>) - <%= render current_component.new(size: size, src: "https://placekitten.com/200/286") %> - <%= render current_component.new(size: size, src: "https://placekitten.com/20/28") %> - <% end %> + <% current_component::SIZES.keys.each do |size| %> + (size: <%= size.inspect %>) + <%= render current_component.new(size: size, src: "https://placekitten.com/200/286") %> + <%= render current_component.new(size: size, src: "https://placekitten.com/20/28") %> + <% end %> +
+ +
+
+ Landscape +
+ + <% current_component::SIZES.keys.each do |size| %> + (size: <%= size.inspect %>) + <%= render current_component.new(size: size, src: "https://placekitten.com/280/200") %> + <%= render current_component.new(size: size, src: "https://placekitten.com/28/20") %> + <% end %> +
-
-
- Landscape -
+

Auto thumbnail

+
+ <% product = Spree::Product.new(name: "A good product") %> + <% attachment = Object.new.tap { def _1.url(*) "https://placekitten.com/280/200"; end } %> + <% image = Spree::Image.new.tap { _1.define_singleton_method(:attachment) { attachment } } %> + <% [ + Spree::PromotionAction.new, + Spree::UnitCancel.new, + Spree::TaxRate.new, + image, + Spree::LineItem.new(variant: Spree::Variant.new(images: [image], product: product)), + Spree::Variant.new(images: [image], product: product), + Spree::Order.new, + Spree::Shipment.new, + Object.new, + ].each do |object| %> +
+
+ <%= object.class.name %> +
- <% current_component::SIZES.keys.each do |size| %> - (size: <%= size.inspect %>) - <%= render current_component.new(size: size, src: "https://placekitten.com/280/200") %> - <%= render current_component.new(size: size, src: "https://placekitten.com/28/20") %> + <% current_component::SIZES.keys.each do |size| %> + (size: <%= size.inspect %>) + <%= render current_component.for(object, size: size) %> + <% end %> +
<% end %>
From a290b9638f8b378038fc8d8527e22f44df4579fc Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 20 Nov 2023 19:10:05 +0100 Subject: [PATCH 08/15] Fix calling `Set#sample` in the `ui/icon` component --- .../previews/solidus_admin/ui/icon/component_preview.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/spec/components/previews/solidus_admin/ui/icon/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/icon/component_preview.rb index 28c7f99add7..d94b80022f8 100644 --- a/admin/spec/components/previews/solidus_admin/ui/icon/component_preview.rb +++ b/admin/spec/components/previews/solidus_admin/ui/icon/component_preview.rb @@ -16,6 +16,6 @@ def playground(name: name_options.first) private def name_options - @name_options ||= current_component::NAMES.sample(10) + @name_options ||= current_component::NAMES.to_a.sample(10) end end From b2d114595a0a608093220cdc4cff3042b48df75a Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 20 Nov 2023 19:11:12 +0100 Subject: [PATCH 09/15] Add standard Rails meta tags and fix `turbo-rails` data attributes This is why `data-turbo-method` wasn't working. --- admin/app/views/layouts/solidus_admin/application.html.erb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/admin/app/views/layouts/solidus_admin/application.html.erb b/admin/app/views/layouts/solidus_admin/application.html.erb index 615cb0cab31..7c976011c2a 100644 --- a/admin/app/views/layouts/solidus_admin/application.html.erb +++ b/admin/app/views/layouts/solidus_admin/application.html.erb @@ -2,7 +2,12 @@ <%= favicon_link_tag 'solidus_admin/favicon.ico' %> + <%= solidus_admin_title %> + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + <%= stylesheet_link_tag "inter-font", "data-turbo-track": "reload" %> <%= stylesheet_link_tag SolidusAdmin::Config.theme_path(session[:admin_light_theme]), media: '(prefers-color-scheme: light)', "data-turbo-track": "reload" %> <%= stylesheet_link_tag SolidusAdmin::Config.theme_path(session[:admin_dark_theme]), media: '(prefers-color-scheme: dark)', "data-turbo-track": "reload" %> From 5341f35f7e629b285805e40d94f9ec008a276e9e Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 20 Nov 2023 19:14:02 +0100 Subject: [PATCH 10/15] Memoize the country object instead of the id Should save one or two extra roundtrips to the database. --- .../controllers/solidus_admin/addresses_controller.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/admin/app/controllers/solidus_admin/addresses_controller.rb b/admin/app/controllers/solidus_admin/addresses_controller.rb index 83a8da3a91e..9eb291e9afd 100644 --- a/admin/app/controllers/solidus_admin/addresses_controller.rb +++ b/admin/app/controllers/solidus_admin/addresses_controller.rb @@ -58,9 +58,7 @@ def find_address end def build_new_address - @order.send("build_#{address_type}_address", country_id: default_country_id).tap do |address| - address.country_id ||= default_country_id if address.country.nil? - end + @order.send("build_#{address_type}_address", country: default_country) end def address_type @@ -74,10 +72,10 @@ def validate_address_type end end - def default_country_id - @default_country_id ||= begin + def default_country + @default_country ||= begin country = Spree::Country.default - country.id if Spree::Country.available.exists?(id: country.id) + country if Spree::Country.available.exists?(id: country.id) end end From bf0c4314deb321e733161b43b5a4b4c51b3f04e1 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 21 Nov 2023 15:47:30 +0100 Subject: [PATCH 11/15] Allow to opt-out of cell-wrapping in `ui/table` Also changes how `` attributes are provided. --- .../solidus_admin/orders/index/component.rb | 2 +- .../solidus_admin/products/index/component.rb | 2 +- .../solidus_admin/ui/table/component.html.erb | 4 ++-- .../solidus_admin/ui/table/component.rb | 21 +++++++++---------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/admin/app/components/solidus_admin/orders/index/component.rb b/admin/app/components/solidus_admin/orders/index/component.rb index b24952b846e..57df251d56e 100644 --- a/admin/app/components/solidus_admin/orders/index/component.rb +++ b/admin/app/components/solidus_admin/orders/index/component.rb @@ -125,7 +125,7 @@ def date_column def customer_column { - class_name: "w-[400px]", + col: { class: "w-[400px]" }, header: :customer, data: ->(order) do customer_email = order.user&.email diff --git a/admin/app/components/solidus_admin/products/index/component.rb b/admin/app/components/solidus_admin/products/index/component.rb index 5061741de40..eca8bee1509 100644 --- a/admin/app/components/solidus_admin/products/index/component.rb +++ b/admin/app/components/solidus_admin/products/index/component.rb @@ -71,7 +71,7 @@ def columns def image_column { - class_name: "w-[72px]", + col: { class: "w-[72px]" }, header: tag.span('aria-label': t('.product_image'), role: 'text'), data: ->(product) do image = product.gallery.images.first or return diff --git a/admin/app/components/solidus_admin/ui/table/component.html.erb b/admin/app/components/solidus_admin/ui/table/component.html.erb index a029b592e26..bf456657e1d 100644 --- a/admin/app/components/solidus_admin/ui/table/component.html.erb +++ b/admin/app/components/solidus_admin/ui/table/component.html.erb @@ -76,7 +76,7 @@ <% @columns.each do |column| %> - + "> <% end %> @@ -117,7 +117,7 @@ <% end %> > <% @columns.each do |column| %> - <%= render_data_cell(column.data, row) %> + <%= render_data_cell(column, row) %> <% end %> <% end %> diff --git a/admin/app/components/solidus_admin/ui/table/component.rb b/admin/app/components/solidus_admin/ui/table/component.rb index 83df04be06e..8008d4f38cd 100644 --- a/admin/app/components/solidus_admin/ui/table/component.rb +++ b/admin/app/components/solidus_admin/ui/table/component.rb @@ -45,7 +45,7 @@ def initialize( prev_page_link: nil, next_page_link: nil ) - @columns = columns.map { Column.new(**_1) } + @columns = columns.map { Column.new(wrap: true, **_1) } @batch_actions = batch_actions.map { BatchAction.new(**_1) } @filters = filters.map { Filter.new(**_1) } @id = id @@ -86,7 +86,7 @@ def selectable_column "aria-label": t('.select_row'), ) }, - class_name: 'w-[52px]', + col: { class: 'w-[52px]' }, ) end @@ -148,21 +148,20 @@ def render_header_cell(cell, **attrs) }, **attrs) end - def render_data_cell(cell, data) + def render_data_cell(column, data) + cell = column.data cell = cell.call(data) if cell.respond_to?(:call) cell = data.public_send(cell) if cell.is_a?(Symbol) cell = cell.render_in(self) if cell.respond_to?(:render_in) + cell = tag.div(cell, class: "flex items-center gap-1.5 justify-start overflow-hidden") if column.wrap - tag.td( - tag.div(cell, class: "flex items-center gap-1.5"), - class: " - py-2 px-4 h-10 vertical-align-middle leading-none - [tr:last-child_&:first-child]:rounded-bl-lg [tr:last-child_&:last-child]:rounded-br-lg - ", - ) + tag.td(cell, class: " + py-2 px-4 h-10 vertical-align-middle leading-none + [tr:last-child_&:first-child]:rounded-bl-lg [tr:last-child_&:last-child]:rounded-br-lg + ") end - Column = Struct.new(:header, :data, :class_name, keyword_init: true) + Column = Struct.new(:header, :data, :col, :wrap, keyword_init: true) BatchAction = Struct.new(:display_name, :icon, :action, :method, keyword_init: true) # rubocop:disable Lint/StructNewOverride Filter = Struct.new(:presentation, :combinator, :attribute, :predicate, :options, keyword_init: true) private_constant :Column, :BatchAction, :Filter From 7c39ea76ee38600f260d9ceba220bbb83014a37f Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 21 Nov 2023 15:48:45 +0100 Subject: [PATCH 12/15] Load the current address with a standard `load_address` before action --- .../orders/show/address/component.html.erb | 2 +- .../orders/show/address/component.rb | 1 + .../solidus_admin/addresses_controller.rb | 21 ++++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/admin/app/components/solidus_admin/orders/show/address/component.html.erb b/admin/app/components/solidus_admin/orders/show/address/component.html.erb index b9f2da40f15..d97d4ebbefb 100644 --- a/admin/app/components/solidus_admin/orders/show/address/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/address/component.html.erb @@ -38,7 +38,7 @@ <%= render component("ui/forms/checkbox").new( name: "#{form.object_name}[#{use_attribute}]", - checked: form.object.send("#{@type}_address").new_record? || form.object.bill_address == form.object.ship_address, + checked: @address == (@type == 'ship' ? @order.bill_address : @order.ship_address), value: '1' ) %> diff --git a/admin/app/components/solidus_admin/orders/show/address/component.rb b/admin/app/components/solidus_admin/orders/show/address/component.rb index 4ab9208ebf5..343c70e4f9b 100644 --- a/admin/app/components/solidus_admin/orders/show/address/component.rb +++ b/admin/app/components/solidus_admin/orders/show/address/component.rb @@ -9,6 +9,7 @@ def initialize(order:, address:, user: nil, type: 'ship') @order = order @user = user @address = address + @addresses = user&.addresses.to_a.reject(&:new_record?) @type = validate_address_type(type) end diff --git a/admin/app/controllers/solidus_admin/addresses_controller.rb b/admin/app/controllers/solidus_admin/addresses_controller.rb index 9eb291e9afd..e4ee6085f3d 100644 --- a/admin/app/controllers/solidus_admin/addresses_controller.rb +++ b/admin/app/controllers/solidus_admin/addresses_controller.rb @@ -4,18 +4,16 @@ module SolidusAdmin class AddressesController < BaseController include Spree::Core::ControllerHelpers::StrongParameters - before_action :load_order + before_action :load_order, :load_address before_action :validate_address_type def show - address = find_address || build_new_address - respond_to do |format| format.html do render component('orders/show/address').new( order: @order, user: @order.user, - address: address, + address: @address, type: address_type, ) end @@ -48,19 +46,18 @@ def update private - def find_address + def load_address if params[:address_id].present? && @order.user - address = @order.user.addresses.find_by(id: params[:address_id]) - @order.send("#{address_type}_address=", address) if address + @address = + @order.user.addresses.find_by(id: params[:address_id]) || + @order.user.addresses.build(country: default_country) else - @order.send("#{address_type}_address") + @address = + @order.public_send("#{address_type}_address") || + @order.public_send("build_#{address_type}_address", country: default_country) end end - def build_new_address - @order.send("build_#{address_type}_address", country: default_country) - end - def address_type params[:type].presence_in(%w[bill ship]) end From 8340c4bc96dc40888dd8565204a38d5041ed6091 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 21 Nov 2023 15:50:19 +0100 Subject: [PATCH 13/15] Fix typo sending the response status to the component --- admin/app/controllers/solidus_admin/addresses_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/admin/app/controllers/solidus_admin/addresses_controller.rb b/admin/app/controllers/solidus_admin/addresses_controller.rb index e4ee6085f3d..817d2c1f7be 100644 --- a/admin/app/controllers/solidus_admin/addresses_controller.rb +++ b/admin/app/controllers/solidus_admin/addresses_controller.rb @@ -37,8 +37,7 @@ def update user: @order.user, address: @order.send("#{address_type}_address"), type: address_type, - status: :unprocessable_entity, - ) + ), status: :unprocessable_entity end end end From d0692d869b5e358c85fdcb10c96e03bbb18d3b94 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 22 Nov 2023 09:56:04 +0100 Subject: [PATCH 14/15] Update to the latest codecov ORB version --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a0dbe00e273..1433bea522c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 orbs: browser-tools: circleci/browser-tools@1.4.6 - codecov: codecov/codecov@3.2.3 + codecov: codecov/codecov@3.3.0 executors: base: From 854301de20526730bd80fdea004e9f2adce013bf Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 22 Nov 2023 13:05:18 +0100 Subject: [PATCH 15/15] Restore pointer events on the `ui/toast` component --- admin/app/components/solidus_admin/ui/toast/component.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/admin/app/components/solidus_admin/ui/toast/component.html.erb b/admin/app/components/solidus_admin/ui/toast/component.html.erb index 559fdc0dd5c..65a176f9e92 100644 --- a/admin/app/components/solidus_admin/ui/toast/component.html.erb +++ b/admin/app/components/solidus_admin/ui/toast/component.html.erb @@ -3,6 +3,7 @@ flex items-center justify-between rounded px-3 py-2 transform translate-y-full opacity-0 transition-all duration-500 + pointer-events-auto <%= SCHEMES.fetch(@scheme.to_sym).join(' ') %> " data-controller="<%= stimulus_id %>"