diff --git a/.rubocop.yml b/.rubocop.yml index a69446c98b4..9bfa2df3a5c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -352,3 +352,6 @@ Rails/FindEach: # tasks should load the rails environment loaded. Rails/RakeEnvironment: Enabled: false + +Rails/LexicallyScopedActionFilter: + Enabled: false diff --git a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb index 8cc79b783f2..f1bd76aeb54 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb index a7ae5b6b6db..520007d4a0b 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb @@ -18,7 +18,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_adjustment_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -26,7 +26,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -52,7 +52,7 @@ def columns data: ->(adjustment_reason) do link_to adjustment_reason.name, edit_path(adjustment_reason), class: 'body-link', - data: { turbo_frame: :resource_modal } + data: { turbo_frame: :resource_form } end }, { @@ -60,7 +60,7 @@ def columns data: ->(adjustment_reason) do link_to adjustment_reason.code, edit_path(adjustment_reason), class: 'body-link', - data: { turbo_frame: :resource_modal } + data: { turbo_frame: :resource_form } end }, { diff --git a/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb index 8cc79b783f2..f1bd76aeb54 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/layout/flashes/component.html.erb b/admin/app/components/solidus_admin/layout/flashes/component.html.erb new file mode 100644 index 00000000000..b909471733f --- /dev/null +++ b/admin/app/components/solidus_admin/layout/flashes/component.html.erb @@ -0,0 +1,5 @@ + diff --git a/admin/app/components/solidus_admin/layout/flashes/component.rb b/admin/app/components/solidus_admin/layout/flashes/component.rb new file mode 100644 index 00000000000..1105b1405fb --- /dev/null +++ b/admin/app/components/solidus_admin/layout/flashes/component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class SolidusAdmin::Layout::Flashes::Component < SolidusAdmin::BaseComponent +end diff --git a/admin/app/components/solidus_admin/option_types/edit/component.html.erb b/admin/app/components/solidus_admin/option_types/edit/component.html.erb new file mode 100644 index 00000000000..a2ef821ac09 --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/edit/component.html.erb @@ -0,0 +1,44 @@ +<%= turbo_frame_tag :resource_form, target: "_top" do %> + <%= page do %> + <%= page_header do %> + <%= page_header_back(back_url) %> + <%= page_header_title(t('.title')) %> + <%= page_header_actions do %> + <%= render component("ui/button").new(text: t(".save"),form: form_id) %> + <% end %> + <% end %> + +
+ <%= form_for @option_type, url: form_url, html: { id: form_id } do |f| %> + <%= render component("ui/panel").new(title: t(".panels.option_type.title")) do |panel| %> + <% panel.with_section(class: "flex flex-col gap-4") do %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> +
+ <% end %> + <% end %> + <% end %> + + <%= render component("ui/panel").new(title: t(".panels.option_values.title")) do |panel| %> + <% panel.with_section(wide: true, high: true, class: "flex flex-col gap-4") do %> +
+ <%= render component("option_values/table").new(@option_type) %> +
+ <% end %> + + <% panel.with_action( + name: t(".panels.option_values.add"), + href: solidus_admin.new_option_type_option_value_path(@option_type), + data: { turbo_frame: :option_value_modal } + ) %> + <% end %> + + <%= page_footer do %> + <%= render component("ui/button").new(text: t(".save"), form: form_id) %> + <% end %> +
+ + <%= turbo_frame_tag :option_value_modal, target: "_top" %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/option_types/edit/component.rb b/admin/app/components/solidus_admin/option_types/edit/component.rb new file mode 100644 index 00000000000..ec40c3e2fd0 --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/edit/component.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionTypes::Edit::Component < SolidusAdmin::Resources::Edit::Component + include SolidusAdmin::Layout::PageHelpers +end diff --git a/admin/app/components/solidus_admin/option_types/edit/component.yml b/admin/app/components/solidus_admin/option_types/edit/component.yml new file mode 100644 index 00000000000..108d8f6fa7f --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/edit/component.yml @@ -0,0 +1,10 @@ +en: + back: "Back" + panels: + option_type: + title: "Option Type" + option_values: + title: "Option Values" + add: "Add new" + save: "Save" + title: "Edit Option Type" diff --git a/admin/app/components/solidus_admin/option_types/index/component.rb b/admin/app/components/solidus_admin/option_types/index/component.rb index 288931a0fd2..86993d22df1 100644 --- a/admin/app/components/solidus_admin/option_types/index/component.rb +++ b/admin/app/components/solidus_admin/option_types/index/component.rb @@ -12,11 +12,16 @@ def sortable_options } end + def turbo_frames + %w[resource_form] + end + def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: spree.new_admin_option_type_path, + href: solidus_admin.new_option_type_path, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end @@ -36,6 +41,7 @@ def batch_actions action: solidus_admin.option_types_path, method: :delete, icon: 'delete-bin-7-line', + require_confirmation: true, }, ] end @@ -60,11 +66,14 @@ def name_column def presentation_column { header: :presentation, - data: ->(option_type) { option_type.presentation } + data: ->(option_type) do + link_to option_type.presentation, edit_path(option_type), + class: 'body-link' + end } end def edit_path(option_type) - spree.edit_admin_option_type_path(option_type) + solidus_admin.edit_option_type_path(option_type) end end diff --git a/admin/app/components/solidus_admin/option_types/new/component.html.erb b/admin/app/components/solidus_admin/option_types/new/component.html.erb new file mode 100644 index 00000000000..6e4dacb5b89 --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/new/component.html.erb @@ -0,0 +1,16 @@ +<%= turbo_frame_tag :resource_form, target: "_top" do %> + <%= render component("ui/modal").new(title: t(".title")) do |modal| %> + <%= form_for @option_type, url: form_url, html: { id: form_id } do |f| %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> +
+ <% modal.with_actions do %> +
+ <%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %> +
+ <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %> + <% end %> + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/option_types/new/component.rb b/admin/app/components/solidus_admin/option_types/new/component.rb new file mode 100644 index 00000000000..fc791bdebc2 --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/new/component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionTypes::New::Component < SolidusAdmin::Resources::New::Component +end diff --git a/admin/app/components/solidus_admin/option_types/new/component.yml b/admin/app/components/solidus_admin/option_types/new/component.yml new file mode 100644 index 00000000000..6b233d44a0c --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/new/component.yml @@ -0,0 +1,4 @@ +en: + title: "New Option Type" + cancel: "Cancel" + submit: "Add Option Type" diff --git a/admin/app/components/solidus_admin/option_values/edit/component.html.erb b/admin/app/components/solidus_admin/option_values/edit/component.html.erb new file mode 100644 index 00000000000..90d343ce8a1 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/edit/component.html.erb @@ -0,0 +1,16 @@ +<%= turbo_frame_tag :option_value_modal, target: "_top" do %> + <%= render component("ui/modal").new(title: t(".title")) do |modal| %> + <%= form_for @option_value, url: form_url, html: { id: form_id } do |f| %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> +
+ <% modal.with_actions do %> +
+ <%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %> +
+ <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %> + <% end %> + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/option_values/edit/component.rb b/admin/app/components/solidus_admin/option_values/edit/component.rb new file mode 100644 index 00000000000..3dd3368e98a --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/edit/component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionValues::Edit::Component < SolidusAdmin::Resources::Edit::Component +end diff --git a/admin/app/components/solidus_admin/option_values/edit/component.yml b/admin/app/components/solidus_admin/option_values/edit/component.yml new file mode 100644 index 00000000000..399dfe74216 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/edit/component.yml @@ -0,0 +1,4 @@ +en: + title: "Edit Option Value" + cancel: "Cancel" + submit: "Update Option Value" diff --git a/admin/app/components/solidus_admin/option_values/new/component.html.erb b/admin/app/components/solidus_admin/option_values/new/component.html.erb new file mode 100644 index 00000000000..90d343ce8a1 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/new/component.html.erb @@ -0,0 +1,16 @@ +<%= turbo_frame_tag :option_value_modal, target: "_top" do %> + <%= render component("ui/modal").new(title: t(".title")) do |modal| %> + <%= form_for @option_value, url: form_url, html: { id: form_id } do |f| %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> +
+ <% modal.with_actions do %> +
+ <%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %> +
+ <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %> + <% end %> + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/option_values/new/component.rb b/admin/app/components/solidus_admin/option_values/new/component.rb new file mode 100644 index 00000000000..9d48574c110 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/new/component.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionValues::New::Component < SolidusAdmin::Resources::New::Component + def form_url + solidus_admin.option_type_option_values_path(@option_value.option_type) + end +end diff --git a/admin/app/components/solidus_admin/option_values/new/component.yml b/admin/app/components/solidus_admin/option_values/new/component.yml new file mode 100644 index 00000000000..11043a335d2 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/new/component.yml @@ -0,0 +1,4 @@ +en: + title: "New Option Value" + cancel: "Cancel" + submit: "Add Option Value" diff --git a/admin/app/components/solidus_admin/option_values/table/component.rb b/admin/app/components/solidus_admin/option_values/table/component.rb new file mode 100644 index 00000000000..0380d187671 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/table/component.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionValues::Table::Component < SolidusAdmin::BaseComponent + def initialize(option_type) + @option_type = option_type + end + + def call + render component("ui/table").new( + id: stimulus_id, + data: { + class: Spree::OptionValue, + rows: @option_type.option_values, + columns: option_value_columns, + batch_actions: [ + { + label: t('.batch_actions.delete'), + action: solidus_admin.option_type_option_values_path(@option_type), + method: :delete, + icon: 'delete-bin-7-line', + require_confirmation: true, + }, + ] + }, + sortable: { + url: ->(option_value) { solidus_admin.move_option_value_path(option_value) }, + param: "position", + }, + embedded: true, + ) + end + + def option_value_columns + [ + { + header: :name, + data: ->(option_value) do + link_to option_value.name, solidus_admin.edit_option_value_path(option_value), + class: 'body-link', + data: { turbo_frame: :option_value_modal } + end + }, + { + header: :presentation, + data: ->(option_value) do + link_to option_value.presentation, solidus_admin.edit_option_value_path(option_value), + class: 'body-link', + data: { turbo_frame: :option_value_modal } + end + }, + ] + end +end diff --git a/admin/app/components/solidus_admin/option_values/table/component.yml b/admin/app/components/solidus_admin/option_values/table/component.yml new file mode 100644 index 00000000000..d6429972d90 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/table/component.yml @@ -0,0 +1,3 @@ +en: + batch_actions: + delete: "Delete" diff --git a/admin/app/components/solidus_admin/properties/edit/component.html.erb b/admin/app/components/solidus_admin/properties/edit/component.html.erb index b2a90586684..cf56ae99a60 100644 --- a/admin/app/components/solidus_admin/properties/edit/component.html.erb +++ b/admin/app/components/solidus_admin/properties/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/properties/index/component.rb b/admin/app/components/solidus_admin/properties/index/component.rb index 9782ba2e624..e902f80aa16 100644 --- a/admin/app/components/solidus_admin/properties/index/component.rb +++ b/admin/app/components/solidus_admin/properties/index/component.rb @@ -22,7 +22,7 @@ def edit_path(property) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -30,7 +30,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_property_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end @@ -58,7 +58,7 @@ def name_column header: :name, data: ->(property) do link_to property.name, edit_path(property), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -69,7 +69,7 @@ def presentation_column header: :presentation, data: ->(property) do link_to property.presentation, edit_path(property), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/admin/app/components/solidus_admin/properties/new/component.html.erb b/admin/app/components/solidus_admin/properties/new/component.html.erb index b2a90586684..cf56ae99a60 100644 --- a/admin/app/components/solidus_admin/properties/new/component.html.erb +++ b/admin/app/components/solidus_admin/properties/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb index 630f10dfd16..e66db8f069c 100644 --- a/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/refund_reasons/index/component.rb b/admin/app/components/solidus_admin/refund_reasons/index/component.rb index 62d4f6b9d06..01c4046fd0a 100644 --- a/admin/app/components/solidus_admin/refund_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/index/component.rb @@ -19,7 +19,7 @@ def edit_path(refund_reason) def turbo_frames %w[ - resource_modal + resource_form ] end @@ -28,7 +28,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_refund_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -51,7 +51,7 @@ def columns header: :name, data: ->(refund_reason) do link_to refund_reason.name, edit_path(refund_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, @@ -59,7 +59,7 @@ def columns header: :code, data: ->(refund_reason) do link_to_if refund_reason.code, refund_reason.code, edit_path(refund_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb index 72a6b996d7c..85482d1dec2 100644 --- a/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb index e1c6af09dc0..ade96525347 100644 --- a/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/return_reasons/index/component.rb b/admin/app/components/solidus_admin/return_reasons/index/component.rb index 594eac21696..e8fb147dd7a 100644 --- a/admin/app/components/solidus_admin/return_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/return_reasons/index/component.rb @@ -19,7 +19,7 @@ def edit_path(return_reason) def turbo_frames %w[ - resource_modal + resource_form ] end @@ -28,7 +28,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_return_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -51,7 +51,7 @@ def columns header: :name, data: ->(return_reason) do link_to return_reason.name, edit_path(return_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/return_reasons/new/component.html.erb b/admin/app/components/solidus_admin/return_reasons/new/component.html.erb index e1c6af09dc0..ade96525347 100644 --- a/admin/app/components/solidus_admin/return_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/return_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/roles/edit/component.html.erb b/admin/app/components/solidus_admin/roles/edit/component.html.erb index ff14e0363df..481132339aa 100644 --- a/admin/app/components/solidus_admin/roles/edit/component.html.erb +++ b/admin/app/components/solidus_admin/roles/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @role, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/roles/index/component.rb b/admin/app/components/solidus_admin/roles/index/component.rb index 97ce166278a..4a8f513301e 100644 --- a/admin/app/components/solidus_admin/roles/index/component.rb +++ b/admin/app/components/solidus_admin/roles/index/component.rb @@ -22,14 +22,14 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_role_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end def turbo_frames %w[ - resource_modal + resource_form ] end @@ -61,7 +61,7 @@ def columns header: :role, data: ->(role) do link_to role.name, edit_path(role), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: "body-link" end, }, @@ -69,7 +69,7 @@ def columns header: :description, data: ->(role) do link_to_if role.description, role.description, edit_path(role), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: "body-link" end } diff --git a/admin/app/components/solidus_admin/roles/new/component.html.erb b/admin/app/components/solidus_admin/roles/new/component.html.erb index 3216408ea58..a921f2e2d27 100644 --- a/admin/app/components/solidus_admin/roles/new/component.html.erb +++ b/admin/app/components/solidus_admin/roles/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @role, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb b/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb index b3e1b61981a..69b2ee08f8e 100644 --- a/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb +++ b/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @shipping_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/shipping_categories/index/component.rb b/admin/app/components/solidus_admin/shipping_categories/index/component.rb index 2302b16417e..2c303296914 100644 --- a/admin/app/components/solidus_admin/shipping_categories/index/component.rb +++ b/admin/app/components/solidus_admin/shipping_categories/index/component.rb @@ -10,7 +10,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_shipping_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -18,7 +18,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -51,7 +51,7 @@ def columns header: :name, data: ->(shipping_category) do link_to shipping_category.name, edit_url(shipping_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: "body-link" end }, diff --git a/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb b/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb index b3e1b61981a..69b2ee08f8e 100644 --- a/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb +++ b/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @shipping_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/stock_items/edit/component.html.erb b/admin/app/components/solidus_admin/stock_items/edit/component.html.erb index a0faf887296..c6d9725b49f 100644 --- a/admin/app/components/solidus_admin/stock_items/edit/component.html.erb +++ b/admin/app/components/solidus_admin/stock_items/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @stock_item, url: form_url, html: { id: form_id } do |f| %>
(stock_item) do link_to stock_item.variant.name, edit_path(stock_item), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -102,7 +102,7 @@ def sku_column header: :sku, data: ->(stock_item) do link_to stock_item.variant.sku, edit_path(stock_item), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -172,6 +172,6 @@ def count_on_hand_column end def turbo_frames - %w[resource_modal] + %w[resource_form] end end diff --git a/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb index 432322ba69a..db080fb6831 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb index 632c314147d..c1186925d28 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb @@ -10,7 +10,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_store_credit_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -18,7 +18,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -51,7 +51,7 @@ def columns header: :name, data: ->(store_credit_reason) do link_to store_credit_reason.name, edit_path(store_credit_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb b/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb index 432322ba69a..db080fb6831 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb b/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb index d5b8b25115b..4fd0f5f25fa 100644 --- a/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb +++ b/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @tax_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/tax_categories/index/component.rb b/admin/app/components/solidus_admin/tax_categories/index/component.rb index 2937b3b2942..d7d2f40567c 100644 --- a/admin/app/components/solidus_admin/tax_categories/index/component.rb +++ b/admin/app/components/solidus_admin/tax_categories/index/component.rb @@ -18,7 +18,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_tax_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -26,7 +26,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -51,7 +51,7 @@ def columns header: :name, data: ->(tax_category) do link_to tax_category.name, edit_path(tax_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, @@ -59,7 +59,7 @@ def columns header: :tax_code, data: ->(tax_category) do link_to_if tax_category.tax_code, tax_category.tax_code, edit_path(tax_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, @@ -67,7 +67,7 @@ def columns header: :description, data: ->(tax_category) do link_to_if tax_category.description, tax_category.description, edit_path(tax_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/tax_categories/new/component.html.erb b/admin/app/components/solidus_admin/tax_categories/new/component.html.erb index d5b8b25115b..4fd0f5f25fa 100644 --- a/admin/app/components/solidus_admin/tax_categories/new/component.html.erb +++ b/admin/app/components/solidus_admin/tax_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @tax_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/ui/icon/component.rb b/admin/app/components/solidus_admin/ui/icon/component.rb index d2736e6afd6..b66e13ea061 100644 --- a/admin/app/components/solidus_admin/ui/icon/component.rb +++ b/admin/app/components/solidus_admin/ui/icon/component.rb @@ -26,6 +26,6 @@ def call # bypass the asset_host configuration to avoid CORS issues with CDNs: # https://github.com/solidusio/solidus/issues/5657 href = asset_path("solidus_admin/remixicon.symbol.svg#ri-#{@name}", host: "") - tag.svg(tag.use("xlink:href": href), **@attrs) + tag.svg(tag.use("xlink:href": href, href:), **@attrs) end end 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 9cbdb312ade..400c745ace1 100644 --- a/admin/app/components/solidus_admin/ui/table/component.html.erb +++ b/admin/app/components/solidus_admin/ui/table/component.html.erb @@ -1,8 +1,6 @@
data-action="click-><%= stimulus_id %>#rowClicked" data-<%= stimulus_id %>-url-param="<%= row_url %>" - <%= "data-sortable-url=#{@sortable.url.call(row)}" if @sortable&.url %> <% end %> + <%= "data-sortable-url=#{@sortable.url.call(row)}" if @sortable&.url %> > <% @data.columns.each do |column| %> <%= render_data_cell(column, row) %> diff --git a/admin/app/components/solidus_admin/ui/table/component.rb b/admin/app/components/solidus_admin/ui/table/component.rb index 1059f8007c4..7649c1f9cfe 100644 --- a/admin/app/components/solidus_admin/ui/table/component.rb +++ b/admin/app/components/solidus_admin/ui/table/component.rb @@ -60,12 +60,14 @@ def value end end - def initialize(id:, data:, search: nil, sortable: nil) + # @option options [Boolean] :embedded if true, does not add border around table + def initialize(id:, data:, search: nil, sortable: nil, **options) @id = id @data = Data.new(**data) @data.columns.unshift selectable_column if @data.batch_actions.present? && @data.rows.present? @search = Search.new(**search) if search @sortable = Sortable.new(**sortable) if sortable + @options = options end def selectable_column diff --git a/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb index 61ff2d48d82..7a1327d4854 100644 --- a/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :put, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb index 54ce226b3a4..e283df9bd7f 100644 --- a/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :put, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb index fd91a48fb88..c838809b383 100644 --- a/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :put, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb index 06e06e1a1bd..ea58963369a 100644 --- a/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb @@ -8,7 +8,7 @@ tag: :a, href: new_store_credit_path, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, text: t(".add_store_credit"), icon: "add-line" @@ -47,7 +47,7 @@ <%= render component("ui/button").new( tag: :a, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: new_store_credit_path, text: t(".create_one"), @@ -61,5 +61,5 @@ <% end %> <% end %> - <%= turbo_frame_tag :resource_modal, target: "_top" %> + <%= turbo_frame_tag :resource_form, target: "_top" %> <% end %> diff --git a/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb index df37ce9b238..6e517fa6be1 100644 --- a/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :post, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb index 239faac3233..9d7fcde977b 100644 --- a/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb @@ -31,7 +31,7 @@ tag: :a, scheme: :danger, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: edit_validity_url, text: t(".invalidate"), @@ -41,7 +41,7 @@ <%= render component("ui/button").new( tag: :a, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: edit_memo_url, text: t(".edit_memo"), @@ -51,7 +51,7 @@ <%= render component("ui/button").new( tag: :a, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: edit_amount_url, text: t(".edit_amount"), @@ -79,5 +79,5 @@ <% end %> <% end %> - <%= turbo_frame_tag :resource_modal, target: "_top" %> + <%= turbo_frame_tag :resource_form, target: "_top" %> <% end %> diff --git a/admin/app/components/solidus_admin/zones/form/component.html.erb b/admin/app/components/solidus_admin/zones/form/component.html.erb index 3fdfecb436b..c96c26a1075 100644 --- a/admin/app/components/solidus_admin/zones/form/component.html.erb +++ b/admin/app/components/solidus_admin/zones/form/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title:) do |modal| %> <%= form_for @zone, url: @form_url, html: { id: @form_id, **stimulus_controller, **stimulus_value(name: :kind, value: @zone.kind) } do |f| %>
diff --git a/admin/app/components/solidus_admin/zones/index/component.rb b/admin/app/components/solidus_admin/zones/index/component.rb index 33390df6bea..747bf3399d1 100644 --- a/admin/app/components/solidus_admin/zones/index/component.rb +++ b/admin/app/components/solidus_admin/zones/index/component.rb @@ -22,7 +22,7 @@ def edit_path(zone) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -30,7 +30,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_zone_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -69,7 +69,7 @@ def name_column header: :name, data: ->(zone) do link_to zone.name, edit_path(zone), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -80,7 +80,7 @@ def description_column header: :description, data: ->(zone) do link_to zone.description, edit_path(zone), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/admin/app/controllers/concerns/solidus_admin/moveable.rb b/admin/app/controllers/concerns/solidus_admin/moveable.rb new file mode 100644 index 00000000000..a1f3756d0de --- /dev/null +++ b/admin/app/controllers/concerns/solidus_admin/moveable.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module SolidusAdmin::Moveable + extend ActiveSupport::Concern + + included do + before_action :load_moveable, only: [:move] + end + + def move + @moveable.insert_at(params.require(:position).to_i) + + respond_to do |format| + format.js { head :no_content } + end + end + + private + + def load_moveable + @moveable = moveable_class.find(params.require(:id)) + authorize! action_name, @moveable + end + + def moveable_class + "Spree::#{self.class.name.demodulize.remove('Controller').singularize}".constantize + rescue NameError + raise NameError, + "could not infer model class from #{self.class.name}. Please override `moveable_class` to specify it explicitly." + end +end diff --git a/admin/app/controllers/solidus_admin/option_types_controller.rb b/admin/app/controllers/solidus_admin/option_types_controller.rb index 444f1bbbafa..08b2e45a32c 100644 --- a/admin/app/controllers/solidus_admin/option_types_controller.rb +++ b/admin/app/controllers/solidus_admin/option_types_controller.rb @@ -1,46 +1,25 @@ # frozen_string_literal: true module SolidusAdmin - class OptionTypesController < SolidusAdmin::BaseController - include SolidusAdmin::ControllerHelpers::Search + class OptionTypesController < SolidusAdmin::ResourcesController + include SolidusAdmin::Moveable - before_action :load_option_type, only: [:move] - - def index - option_types = apply_search_to( - Spree::OptionType.all, - param: :q, - ) - - set_page_and_extract_portion_from(option_types) - - respond_to do |format| - format.html { render component('option_types/index').new(page: @page) } - end - end - - def move - @option_type.insert_at(params[:position].to_i) + private - respond_to do |format| - format.js { head :no_content } - end + def after_create_path + solidus_admin.edit_option_type_path(@resource) end - def destroy - @option_types = Spree::OptionType.where(id: params[:id]) + def resource_class = Spree::OptionType - Spree::OptionType.transaction { @option_types.destroy_all } - - flash[:notice] = t('.success') - redirect_back_or_to option_types_path, status: :see_other + def permitted_resource_params + params.require(:option_type).permit(:name, :presentation) end - private + def resources_collection = Spree::OptionType.unscoped - def load_option_type - @option_type = Spree::OptionType.find(params[:id]) - authorize! action_name, @option_type + def resources_sorting_options + { position: :asc } end end end diff --git a/admin/app/controllers/solidus_admin/option_values_controller.rb b/admin/app/controllers/solidus_admin/option_values_controller.rb new file mode 100644 index 00000000000..a5513f0d641 --- /dev/null +++ b/admin/app/controllers/solidus_admin/option_values_controller.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +module SolidusAdmin + class OptionValuesController < SolidusAdmin::ResourcesController + include SolidusAdmin::Moveable + + before_action :set_option_type, only: [:new, :create, :destroy] + + def new + @resource = @option_type.option_values.build + super + end + + def create + @resource = @option_type.option_values.build(permitted_resource_params) + super + end + + private + + def prefer_turbo_stream? + case params[:action] + when "create", "update", "destroy" then true + else false + end + end + + def resource_class = Spree::OptionValue + + def permitted_resource_params + params.require(:option_value).permit(:name, :presentation) + end + + def resource_form_frame + :option_value_modal + end + + def after_create_path + solidus_admin.edit_option_type_path(@option_type) + end + + def after_update_path + solidus_admin.edit_option_type_path(@option_value.option_type) + end + + def after_destroy_path + solidus_admin.edit_option_type_path(@option_type) + end + + def set_option_type + @option_type = Spree::OptionType.find(params[:option_type_id]) + end + end +end diff --git a/admin/app/controllers/solidus_admin/payment_methods_controller.rb b/admin/app/controllers/solidus_admin/payment_methods_controller.rb index 684eb7381f3..fc3ce0316dd 100644 --- a/admin/app/controllers/solidus_admin/payment_methods_controller.rb +++ b/admin/app/controllers/solidus_admin/payment_methods_controller.rb @@ -3,8 +3,7 @@ module SolidusAdmin class PaymentMethodsController < SolidusAdmin::BaseController include SolidusAdmin::ControllerHelpers::Search - - before_action :load_payment_method, only: [:move] + include SolidusAdmin::Moveable search_scope(:all) search_scope(:active, default: true, &:active) @@ -25,14 +24,6 @@ def index end end - def move - @payment_method.insert_at(params[:position].to_i) - - respond_to do |format| - format.js { head :no_content } - end - end - def destroy @payment_methods = Spree::PaymentMethod.where(id: params[:id]) @@ -41,12 +32,5 @@ def destroy flash[:notice] = t('.success') redirect_back_or_to payment_methods_path, status: :see_other end - - private - - def load_payment_method - @payment_method = Spree::PaymentMethod.find_by!(id: params[:id]) - authorize! action_name, @payment_method - end end end diff --git a/admin/app/controllers/solidus_admin/resources_controller.rb b/admin/app/controllers/solidus_admin/resources_controller.rb index 7ebc49c7eaa..a636c34d24a 100644 --- a/admin/app/controllers/solidus_admin/resources_controller.rb +++ b/admin/app/controllers/solidus_admin/resources_controller.rb @@ -4,7 +4,7 @@ module SolidusAdmin class ResourcesController < SolidusAdmin::BaseController include SolidusAdmin::ControllerHelpers::Search - helper_method :search_filter_params + helper_method :search_filter_params, :resource_form_frame before_action :set_paginated_resources, only: %i[index] before_action :set_resource, only: %i[edit update] @@ -26,16 +26,19 @@ def index end def new - @resource = resource_class.new + @resource ||= resource_class.new render new_component.new(@resource) end def create - @resource = resource_class.new(permitted_resource_params) + @resource ||= resource_class.new(permitted_resource_params) if @resource.save flash[:notice] = t('.success') - redirect_to after_create_path, status: :see_other + respond_to do |format| + format.html { redirect_to after_create_path, status: :see_other } + format.turbo_stream if prefer_turbo_stream? + end else page_component = new_component.new(@resource) render_resource_form_with_errors(page_component) @@ -43,13 +46,18 @@ def create end def edit - render edit_component.new(@resource) + respond_to do |format| + format.html { render edit_component.new(@resource) } + end end def update if @resource.update(permitted_resource_params) flash[:notice] = t('.success') - redirect_to after_update_path, status: :see_other + respond_to do |format| + format.html { redirect_to after_update_path, status: :see_other } + format.turbo_stream if prefer_turbo_stream? + end else page_component = edit_component.new(@resource) render_resource_form_with_errors(page_component) @@ -62,7 +70,10 @@ def destroy resource_class.transaction { @resource.destroy_all } flash[:notice] = t('.success') - redirect_back_or_to after_destroy_path, status: :see_other + respond_to do |format| + format.html { redirect_back_or_to after_destroy_path, status: :see_other } + format.turbo_stream if prefer_turbo_stream? + end end private @@ -129,7 +140,7 @@ def render_resource_form_with_errors(page_component) render page_component, status: :unprocessable_entity end format.turbo_stream do - render turbo_stream: turbo_stream.replace(:resource_modal, page_component), + render turbo_stream: turbo_stream.replace(resource_form_frame, page_component), status: :unprocessable_entity end end @@ -151,5 +162,11 @@ def after_update_path def after_destroy_path solidus_admin.send("#{plural_resource_name}_path", **search_filter_params) end + + def resource_form_frame + :resource_form + end + + def prefer_turbo_stream? = false end end diff --git a/admin/app/controllers/solidus_admin/taxonomies_controller.rb b/admin/app/controllers/solidus_admin/taxonomies_controller.rb index fb0387d075a..3c6b4cdc2db 100644 --- a/admin/app/controllers/solidus_admin/taxonomies_controller.rb +++ b/admin/app/controllers/solidus_admin/taxonomies_controller.rb @@ -3,8 +3,7 @@ module SolidusAdmin class TaxonomiesController < SolidusAdmin::BaseController include SolidusAdmin::ControllerHelpers::Search - - before_action :load_taxonomy, only: [:move] + include SolidusAdmin::Moveable def index taxonomies = apply_search_to( @@ -19,14 +18,6 @@ def index end end - def move - @taxonomy.insert_at(params[:position].to_i) - - respond_to do |format| - format.js { head :no_content } - end - end - def destroy @taxonomies = Spree::Taxonomy.where(id: params[:id]) @@ -35,12 +26,5 @@ def destroy flash[:notice] = t('.success') redirect_back_or_to taxonomies_path, status: :see_other end - - private - - def load_taxonomy - @taxonomy = Spree::Taxonomy.find(params[:id]) - authorize! action_name, @taxonomy - end end end diff --git a/admin/app/views/layouts/solidus_admin/application.html.erb b/admin/app/views/layouts/solidus_admin/application.html.erb index 6755eea3c1d..8bc30dfadf4 100644 --- a/admin/app/views/layouts/solidus_admin/application.html.erb +++ b/admin/app/views/layouts/solidus_admin/application.html.erb @@ -31,10 +31,6 @@
- + <%= render component("layout/flashes").new %> diff --git a/admin/app/views/solidus_admin/option_values/create.turbo_stream.erb b/admin/app/views/solidus_admin/option_values/create.turbo_stream.erb new file mode 100644 index 00000000000..6c5de598916 --- /dev/null +++ b/admin/app/views/solidus_admin/option_values/create.turbo_stream.erb @@ -0,0 +1,3 @@ +<%= turbo_stream.update("option_values_table", component("option_values/table").new(@option_type)) %> +<%= turbo_stream.update(resource_form_frame, nil) %> +<%= turbo_stream.replace("flash_toasts", component("layout/flashes").new) %> diff --git a/admin/app/views/solidus_admin/option_values/destroy.turbo_stream.erb b/admin/app/views/solidus_admin/option_values/destroy.turbo_stream.erb new file mode 100644 index 00000000000..6c5de598916 --- /dev/null +++ b/admin/app/views/solidus_admin/option_values/destroy.turbo_stream.erb @@ -0,0 +1,3 @@ +<%= turbo_stream.update("option_values_table", component("option_values/table").new(@option_type)) %> +<%= turbo_stream.update(resource_form_frame, nil) %> +<%= turbo_stream.replace("flash_toasts", component("layout/flashes").new) %> diff --git a/admin/app/views/solidus_admin/option_values/update.turbo_stream.erb b/admin/app/views/solidus_admin/option_values/update.turbo_stream.erb new file mode 100644 index 00000000000..9e897aafba0 --- /dev/null +++ b/admin/app/views/solidus_admin/option_values/update.turbo_stream.erb @@ -0,0 +1,3 @@ +<%= turbo_stream.update("option_values_table", component("option_values/table").new(@option_value.option_type)) %> +<%= turbo_stream.update(resource_form_frame, nil) %> +<%= turbo_stream.replace("flash_toasts", component("layout/flashes").new) %> diff --git a/admin/config/locales/option_types.en.yml b/admin/config/locales/option_types.en.yml index fb439e8d07b..df3e4da4eb1 100644 --- a/admin/config/locales/option_types.en.yml +++ b/admin/config/locales/option_types.en.yml @@ -2,5 +2,9 @@ en: solidus_admin: option_types: title: "Option Types" + create: + success: "Option type was successfully created." destroy: - success: "Option Types were successfully removed." + success: "Option types were successfully removed." + update: + success: "Option type was successfully updated." diff --git a/admin/config/locales/option_values.en.yml b/admin/config/locales/option_values.en.yml new file mode 100644 index 00000000000..247aff91121 --- /dev/null +++ b/admin/config/locales/option_values.en.yml @@ -0,0 +1,9 @@ +en: + solidus_admin: + option_values: + create: + success: "Option value was successfully created." + destroy: + success: "Option values were successfully removed." + update: + success: "Option value was successfully updated." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index ec215522965..a2164764bd1 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -69,7 +69,10 @@ admin_resources :promotions, only: [:index, :destroy] admin_resources :properties, except: [:show] - admin_resources :option_types, only: [:index, :destroy], sortable: true + admin_resources :option_types, except: [:show], sortable: true do + admin_resources :option_values, only: [:new, :create, :destroy], controller: "option_values", sortable: false + end + admin_resources :option_values, only: [:edit, :update], sortable: true admin_resources :taxonomies, only: [:index, :destroy], sortable: true admin_resources :promotion_categories, only: [:index, :destroy] admin_resources :tax_categories, except: [:show] diff --git a/admin/lib/solidus_admin/testing_support/shared_examples/bulk_delete_resources.rb b/admin/lib/solidus_admin/testing_support/shared_examples/bulk_delete_resources.rb deleted file mode 100644 index 5a64c3fd47f..00000000000 --- a/admin/lib/solidus_admin/testing_support/shared_examples/bulk_delete_resources.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples_for 'feature: bulk delete resources' do - it 'allows to bulk delete resources' do - create(resource_factory, name: 'Bulk delete item 1') - create(resource_factory, name: 'Bulk delete item 2') - - visit index_path - expect(page).to have_content('Bulk delete item 1') - expect(page).to have_content('Bulk delete item 2') - - select_row('Bulk delete item 1') - select_row('Bulk delete item 2') - click_on 'Delete' - - expect(page).to have_content('were successfully removed.') - expect(page).not_to have_content('Bulk delete item 1') - expect(page).not_to have_content('Bulk delete item 2') - end -end diff --git a/admin/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb b/admin/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb index 8049a450da2..3c4311bfbdf 100644 --- a/admin/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb +++ b/admin/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.shared_examples_for 'CRUD resource requests' do |resource_name| +RSpec.shared_examples_for 'CRUD resource requests' do |resource_name, except: []| let(:admin_user) { create(:admin_user) } let(:resource) { create(factory) } @@ -8,40 +8,49 @@ let(:factory) { resource_name.to_sym } let(:url_helpers) { solidus_admin } + let(:resources_path) { url_helpers.public_send("#{resource_name.pluralize}_path") } + let(:new_resource_path) { url_helpers.public_send("new_#{resource_name}_path") } + let(:edit_resource_path) { url_helpers.public_send("edit_#{resource_name}_path", resource) } + let(:resource_path) { url_helpers.public_send("#{resource_name}_path", resource) } + + let(:expected_after_create_path) { resources_path } + let(:expected_after_update_path) { resources_path } + let(:expected_after_destroy_path) { resources_path } + before do allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(admin_user) end - describe "GET /index" do + describe "GET /index", skip: :index.in?(except) && "not applicable" do it "renders the index template with a 200 OK status" do - get url_helpers.public_send("#{resource_name.pluralize}_path") + get resources_path expect(response).to have_http_status(:ok) end end - describe "GET /new" do + describe "GET /new", skip: :new.in?(except) && "not applicable" do it "renders the new template with a 200 OK status" do - get url_helpers.public_send("new_#{resource_name}_path") + get new_resource_path expect(response).to have_http_status(:ok) end end - describe "POST /create" do + describe "POST /create", skip: :create.in?(except) && "not applicable" do context "with valid parameters" do it "creates a new #{resource_name.humanize}" do expect { - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => valid_attributes } + post resources_path, params: { resource_name => valid_attributes } }.to change(resource_class, :count).by(1) end - it "redirects to the index page with a 303 See Other status" do - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => valid_attributes } - expect(response).to redirect_to(url_helpers.public_send("#{resource_name.pluralize}_path")) + it "redirects with a 303 See Other status" do + post resources_path, params: { resource_name => valid_attributes } + expect(response).to redirect_to(expected_after_create_path) expect(response).to have_http_status(:see_other) end it "displays a success flash message" do - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => valid_attributes } + post resources_path, params: { resource_name => valid_attributes } follow_redirect! expect(response.body).to include("#{resource_name.humanize} was successfully created.") end @@ -52,42 +61,42 @@ it "does not create a new #{resource_name.humanize}" do expect { - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => invalid_attributes } + post resources_path, params: { resource_name => invalid_attributes } }.not_to change(resource_class, :count) end it "renders the new template with unprocessable_entity status" do - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => invalid_attributes } + post resources_path, params: { resource_name => invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end end end - describe "GET /edit" do + describe "GET /edit", skip: :edit.in?(except) && "not applicable" do it "renders the edit template with a 200 OK status" do - get url_helpers.public_send("edit_#{resource_name}_path", resource) + get edit_resource_path expect(response).to have_http_status(:ok) end end - describe "PATCH /update" do + describe "PATCH /update", skip: :update.in?(except) && "not applicable" do context "with valid parameters" do it "updates the #{resource_name.humanize}" do - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => valid_attributes } + patch resource_path, params: { resource_name => valid_attributes } resource.reload valid_attributes.each do |attr, value| expect(resource.public_send(attr)).to eq(value) end end - it "redirects to the index page with a 303 See Other status" do - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => valid_attributes } - expect(response).to redirect_to(url_helpers.public_send("#{resource_name.pluralize}_path")) + it "redirects with a 303 See Other status" do + patch resource_path, params: { resource_name => valid_attributes } + expect(response).to redirect_to(expected_after_update_path) expect(response).to have_http_status(:see_other) end it "displays a success flash message" do - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => valid_attributes } + patch resource_path, params: { resource_name => valid_attributes } follow_redirect! expect(response.body).to include("#{resource_name.humanize} was successfully updated.") end @@ -96,42 +105,40 @@ context "with invalid parameters" do it "does not update the #{resource_name.humanize}" do expect { - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => invalid_attributes } + patch resource_path, params: { resource_name => invalid_attributes } }.not_to change { resource.reload } end it "renders the edit template with unprocessable_entity status" do - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => invalid_attributes } + patch resource_path, params: { resource_name => invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end end end - describe "DELETE /destroy" do - it "deletes the #{resource_name.humanize} and redirects to the index page with a 303 See Other status" do + describe "DELETE /destroy single", skip: :destroy_single.in?(except) && "not applicable" do + it "deletes the #{resource_name.humanize} and redirects with a 303 See Other status" do # This ensures resource exists prior to deletion. resource - expect { - delete url_helpers.public_send("#{resource_name}_path", resource) - }.to change(resource_class, :count).by(-1) + expect { delete resource_path }.to change(resource_class, :count).by(-1) - expect(response).to redirect_to(url_helpers.public_send("#{resource_name.pluralize}_path")) + expect(response).to redirect_to(expected_after_destroy_path) expect(response).to have_http_status(:see_other) end it "displays a success flash message after deletion" do - delete url_helpers.public_send("#{resource_name}_path", resource) + delete resource_path follow_redirect! expect(response.body).to include("#{resource_name.humanize.pluralize} were successfully removed.") end + end + describe "DELETE /destroy bulk", skip: :destroy_bulk.in?(except) && "not applicable" do it 'allows to bulk delete resources' do ids = [create(factory), create(factory)].map(&:id) - expect { - delete url_helpers.public_send("#{resource_name.pluralize}_path", id: ids) - }.to change { resource_class.count }.by(-ids.size) + expect { delete resources_path, params: { id: ids } }.to change { resource_class.count }.by(-ids.size) - expect(response).to redirect_to(url_helpers.public_send("#{resource_name.pluralize}_path")) + expect(response).to redirect_to(expected_after_destroy_path) expect(response).to have_http_status(:see_other) end end diff --git a/admin/lib/solidus_admin/testing_support/shared_examples/moveable.rb b/admin/lib/solidus_admin/testing_support/shared_examples/moveable.rb new file mode 100644 index 00000000000..8c942242c15 --- /dev/null +++ b/admin/lib/solidus_admin/testing_support/shared_examples/moveable.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +RSpec.shared_examples_for "requests: moveable" do + let(:admin_user) { create(:admin_user) } + let(:record) { create(factory, position: 1) } + let(:request_path) do + solidus_admin.send("move_#{record.model_name.singular_route_key}_path", record, format: :js) + end + + before do + allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(admin_user) + end + + describe "PATCH /move" do + it "updates record's position" do + expect { patch request_path, params: { position: 2 } }.to change { record.reload.position }.from(1).to(2) + expect(response).to have_http_status(:no_content) + end + end +end + +RSpec.shared_examples_for "features: sortable" do + let(:factory_attrs) { {} } + + before do + create(factory, displayed_attribute => "First", position: 1, **factory_attrs) + create(factory, displayed_attribute => "Second", position: 2, **factory_attrs) + visit path + end + + it "allows sorting via drag and drop" do + row_1 = find_row("First") + row_2 = find_row("Second") + + row_2.drag_to row_1 + + expect(find("table tbody tr:first-child")).to have_text("Second") + expect(find("table tbody tr:last-child")).to have_text("First") + end +end diff --git a/admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb b/admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb index 88a676f1e77..5033bbd2e7b 100644 --- a/admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb +++ b/admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' - RSpec.shared_examples_for 'promotion categories features' do before { sign_in create(:admin_user, email: "admin@example.com") } diff --git a/admin/spec/components/solidus_admin/base_component_spec.rb b/admin/spec/components/solidus_admin/base_component_spec.rb index 6794d308022..5a9cec439ce 100644 --- a/admin/spec/components/solidus_admin/base_component_spec.rb +++ b/admin/spec/components/solidus_admin/base_component_spec.rb @@ -13,7 +13,7 @@ def call render_inline(component) - svg = page.find("svg use")["xlink:href"] + svg = page.find("svg use")["href"] expect(svg).to match(/#ri-user-line/) end end diff --git a/admin/spec/features/adjustment_reasons_spec.rb b/admin/spec/features/adjustment_reasons_spec.rb index 782fadc99ac..0588f1836a6 100644 --- a/admin/spec/features/adjustment_reasons_spec.rb +++ b/admin/spec/features/adjustment_reasons_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Adjustment Reasons", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/option_types_spec.rb b/admin/spec/features/option_types_spec.rb index 10181e7d009..8427fac87ae 100644 --- a/admin/spec/features/option_types_spec.rb +++ b/admin/spec/features/option_types_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'spec_helper' +require "solidus_admin/testing_support/shared_examples/moveable" describe "Option Types", :js, type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } @@ -16,9 +17,157 @@ expect(page).to be_axe_clean select_row("color") - click_on "Delete" - expect(page).to have_content("Option Types were successfully removed.") + accept_confirm("Are you sure you want to delete 1 option type?") { click_on "Delete" } + expect(page).to have_content("Option types were successfully removed.") expect(page).not_to have_content("color") expect(Spree::OptionType.count).to eq(1) end + + it "allows to create option types/values" do + visit "/admin/option_types" + click_on "Add new" + + fill_in "Name", with: "clothing-color" + fill_in "Presentation", with: "Color" + click_on "Add Option Type" + + expect(page).to have_current_path(/\/admin\/option_types\/\d+\/edit/) + click_on "Add new" + + within("dialog") do + fill_in "Name", with: "blue" + fill_in "Presentation", with: "Blue" + click_on "Add Option Value" + end + + expect(page).to have_content("Option value was successfully created.") + end + + it "allows to update option types" do + create(:option_type, name: "color", presentation: "Color") + visit "/admin/option_types" + click_on "Color" + + fill_in "Name", with: "clt-colour" + fill_in "Presentation", with: "Colour" + within("header") { click_on "Save" } + + expect(page).to have_current_path("/admin/option_types") + expect(page).to have_content("Option type was successfully updated.") + expect(page).to have_content("clt-colour") + expect(page).to have_content("Colour") + expect(page).not_to have_content("color") + expect(page).not_to have_content("Color") + end + + it "allows to edit and destroy option values" do + create(:option_type, name: "color", presentation: "Color").tap do |option_type| + option_type.option_values = [ + create(:option_value, name: "blue", presentation: "Blue"), + create(:option_value, name: "green", presentation: "Green"), + ] + end + + visit "/admin/option_types" + click_on "Color" + + click_on "Blue" + within("dialog") do + fill_in "Name", with: "sky-blue" + fill_in "Presentation", with: "Sky Blue" + end + + click_on "Update Option Value" + expect(page).to have_content("Option value was successfully updated.") + expect(find("table")).to have_content("sky-blue") + expect(find("table")).to have_content("Sky Blue") + + select_row("green") + accept_confirm("Are you sure you want to delete 1 option value?") { click_on "Delete" } + expect(page).to have_content("Option values were successfully removed.") + expect(page).not_to have_content("green") + end + + it "preserves user input" do + create(:option_type, name: "color", presentation: "Color") + + visit "/admin/option_types" + click_on "Color" + + fill_in "Name", with: "clothing-colour" + fill_in "Presentation", with: "Colour" + + click_on "Add new" + within("dialog") do + fill_in "Name", with: "blue" + fill_in "Presentation", with: "Blue" + click_on "Add Option Value" + end + + expect(find_field("Name").value).to eq("clothing-colour") + expect(find_field("Presentation").value).to eq("Colour") + end + + context "with invalid attributes" do + context "on option type create" do + it "shows errors" do + visit "/admin/option_types" + click_on "Add new" + click_on "Add Option Type" + expect(page).to have_content("can't be blank") + end + end + + context "on option type update" do + it "shows errors" do + option_type = create(:option_type, name: "color", presentation: "Color") + visit "/admin/option_types/#{option_type.id}/edit" + fill_in "Name", with: "" + within("header") { click_on "Save" } + expect(page).to have_content("can't be blank") + end + end + + context "on option value create" do + it "shows errors" do + option_type = create(:option_type, name: "color", presentation: "Color") + visit "/admin/option_types/#{option_type.id}/edit" + click_on "Add new" + click_on "Add Option Value" + expect(page).to have_content("can't be blank") + end + end + + context "on option value update" do + it "shows errors" do + option_type = create(:option_type, name: "color", presentation: "Color").tap do |option_type| + option_type.option_values = [create(:option_value, name: "blue")] + end + + visit "/admin/option_types/#{option_type.id}/edit" + click_on "blue" + within("dialog") { fill_in "Name", with: "" } + click_on "Update Option Value" + expect(page).to have_content("can't be blank") + end + end + end + + describe "sorting option types" do + include_examples "features: sortable" do + let(:factory) { :option_type } + let(:displayed_attribute) { :name } + let(:path) { solidus_admin.option_types_path } + end + end + + describe "sorting option values" do + include_examples "features: sortable" do + let!(:option_type) { create(:option_type) } + let(:factory) { :option_value } + let(:factory_attrs) { { option_type: } } + let(:displayed_attribute) { :name } + let(:path) { solidus_admin.edit_option_type_path(option_type) } + end + end end diff --git a/admin/spec/features/payment_methods_spec.rb b/admin/spec/features/payment_methods_spec.rb index 55ebf3ec74b..06b4dc0f3ab 100644 --- a/admin/spec/features/payment_methods_spec.rb +++ b/admin/spec/features/payment_methods_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'spec_helper' +require "solidus_admin/testing_support/shared_examples/moveable" describe "Payment Methods", :js, type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } @@ -45,4 +46,10 @@ expect(page).not_to have_content("Check") expect(Spree::PaymentMethod.count).to eq(3) end + + it_behaves_like "features: sortable" do + let(:factory) { :payment_method } + let(:displayed_attribute) { :name } + let(:path) { solidus_admin.payment_methods_path } + end end diff --git a/admin/spec/features/properties_spec.rb b/admin/spec/features/properties_spec.rb index dda90f87642..28e04c95b3b 100644 --- a/admin/spec/features/properties_spec.rb +++ b/admin/spec/features/properties_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Properties", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/refund_reasons_spec.rb b/admin/spec/features/refund_reasons_spec.rb index 60aa1c0765c..9857007345b 100644 --- a/admin/spec/features/refund_reasons_spec.rb +++ b/admin/spec/features/refund_reasons_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Refund Reasons", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/return_reasons_spec.rb b/admin/spec/features/return_reasons_spec.rb index 68f30dc2a31..0cb474b23a3 100644 --- a/admin/spec/features/return_reasons_spec.rb +++ b/admin/spec/features/return_reasons_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Return Reasons", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/roles_spec.rb b/admin/spec/features/roles_spec.rb index a35b58978a3..08572087034 100644 --- a/admin/spec/features/roles_spec.rb +++ b/admin/spec/features/roles_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Roles", type: :feature do before do diff --git a/admin/spec/features/shipping_categories_spec.rb b/admin/spec/features/shipping_categories_spec.rb index 8a4e362f8c4..d953146925f 100644 --- a/admin/spec/features/shipping_categories_spec.rb +++ b/admin/spec/features/shipping_categories_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Shipping Categories", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/store_credit_reasons_spec.rb b/admin/spec/features/store_credit_reasons_spec.rb index 85ef3fb1ff5..1fa6e5006bb 100644 --- a/admin/spec/features/store_credit_reasons_spec.rb +++ b/admin/spec/features/store_credit_reasons_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Store Credit Reasons", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/tax_categories_spec.rb b/admin/spec/features/tax_categories_spec.rb index 69c267db8e2..c056e689b55 100644 --- a/admin/spec/features/tax_categories_spec.rb +++ b/admin/spec/features/tax_categories_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Tax categories", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/taxonomies_spec.rb b/admin/spec/features/taxonomies_spec.rb index 88cb0ec782a..33fab23194e 100644 --- a/admin/spec/features/taxonomies_spec.rb +++ b/admin/spec/features/taxonomies_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'spec_helper' +require "solidus_admin/testing_support/shared_examples/moveable" describe "Taxonomies", :js, type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } @@ -21,4 +22,10 @@ expect(page).not_to have_content("Categories") expect(Spree::Taxonomy.count).to eq(1) end + + it_behaves_like "features: sortable" do + let(:factory) { :taxonomy } + let(:displayed_attribute) { :name } + let(:path) { solidus_admin.taxonomies_path } + end end diff --git a/admin/spec/requests/solidus_admin/option_types_spec.rb b/admin/spec/requests/solidus_admin/option_types_spec.rb new file mode 100644 index 00000000000..3cfe16b148b --- /dev/null +++ b/admin/spec/requests/solidus_admin/option_types_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require "spec_helper" +require 'solidus_admin/testing_support/shared_examples/crud_resource_requests' +require "solidus_admin/testing_support/shared_examples/moveable" + +RSpec.describe "SolidusAdmin::OptionTypesController", type: :request do + it_behaves_like "CRUD resource requests", "option_type" do + let(:resource_class) { Spree::OptionType } + let(:valid_attributes) { { name: "color", presentation: "Color" } } + let(:invalid_attributes) { { name: "" } } + let(:expected_after_create_path) { %r(/admin/option_types/\d+/edit) } + end + + it_behaves_like "requests: moveable" do + let(:factory) { :option_type } + end +end diff --git a/admin/spec/requests/solidus_admin/option_values_spec.rb b/admin/spec/requests/solidus_admin/option_values_spec.rb new file mode 100644 index 00000000000..a89a84d4eca --- /dev/null +++ b/admin/spec/requests/solidus_admin/option_values_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require "spec_helper" +require "solidus_admin/testing_support/shared_examples/crud_resource_requests" +require "solidus_admin/testing_support/shared_examples/moveable" + +RSpec.describe "SolidusAdmin::OptionValuesController", type: :request do + it_behaves_like "CRUD resource requests", "option_value", except: %i[index destroy_single] do + let(:resource_class) { Spree::OptionValue } + let(:valid_attributes) { { name: "yellow", presentation: "Yellow" } } + let(:invalid_attributes) { { name: "" } } + + let!(:resources_path) { solidus_admin.option_type_option_values_path(resource.option_type, format:) } + let!(:new_resource_path) { solidus_admin.new_option_type_option_value_path(resource.option_type) } + let!(:edit_resource_path) { solidus_admin.edit_option_value_path(resource) } + let!(:resource_path) { solidus_admin.option_value_path(resource, format:) } + + let(:format) { :html } + + let(:expected_after_create_path) { %r(/admin/option_types/\d+/edit) } + let(:expected_after_update_path) { %r(/admin/option_types/\d+/edit) } + let(:expected_after_destroy_path) { %r(/admin/option_types/\d+/edit) } + + context "when format is turbo_stream" do + let(:format) { :turbo_stream } + + shared_examples_for "responds with turbo stream" do + it "responds with turbo stream" do + expect(response.content_type).to include("text/vnd.turbo-stream.html") + expect(response).to have_http_status(:ok) + end + end + + context "#create" do + include_examples "responds with turbo stream" do + before { post resources_path, params: { option_value: valid_attributes } } + end + end + + context "#update" do + include_examples "responds with turbo stream" do + before { patch resource_path, params: { option_value: valid_attributes } } + end + end + + context "#destroy" do + include_examples "responds with turbo stream" do + before { delete resources_path, params: { ids: [resource.id] } } + end + end + end + end + + it_behaves_like "requests: moveable" do + let(:factory) { :option_value } + end +end diff --git a/admin/spec/requests/solidus_admin/payment_methods_spec.rb b/admin/spec/requests/solidus_admin/payment_methods_spec.rb new file mode 100644 index 00000000000..5cc99dae2ab --- /dev/null +++ b/admin/spec/requests/solidus_admin/payment_methods_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require "spec_helper" +require "solidus_admin/testing_support/shared_examples/moveable" + +RSpec.describe "SolidusAdmin::PaymentMethodsController", type: :request do + it_behaves_like "requests: moveable" do + let(:factory) { :payment_method } + let(:request_path) { solidus_admin.move_payment_method_path(record, format: :js) } + end +end diff --git a/admin/spec/requests/solidus_admin/taxonomies_spec.rb b/admin/spec/requests/solidus_admin/taxonomies_spec.rb new file mode 100644 index 00000000000..0c93d5551c1 --- /dev/null +++ b/admin/spec/requests/solidus_admin/taxonomies_spec.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require "spec_helper" +require "solidus_admin/testing_support/shared_examples/moveable" + +RSpec.describe "SolidusAdmin::TaxonomiesController", type: :request do + it_behaves_like "requests: moveable" do + let(:factory) { :taxonomy } + end +end diff --git a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb +++ b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb index 35f8574f999..e8d0fa6ea81 100644 --- a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb +++ b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb @@ -14,7 +14,7 @@ def edit_path(record) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -22,7 +22,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_promotion_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end @@ -50,7 +50,7 @@ def name_column header: :name, data: ->(record) do link_to record.name, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -61,7 +61,7 @@ def code_column header: :code, data: ->(record) do link_to record.code, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb +++ b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb b/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb +++ b/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb b/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb index d908005d267..9ff6b534244 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb +++ b/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb @@ -14,7 +14,7 @@ def edit_path(record) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -22,7 +22,7 @@ def page_actions tag: :a, text: t(".add"), href: solidus_promotions.new_promotion_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line" ) end @@ -50,7 +50,7 @@ def name_column header: :name, data: ->(record) do link_to record.name, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -61,7 +61,7 @@ def code_column header: :code, data: ->(record) do link_to record.code, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb b/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb +++ b/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>