Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a35ad43
Inherit from resources controller
chaimann May 15, 2025
1829357
Rename resource form turbo frame
chaimann May 8, 2025
74f3ceb
Add modal to create new option type
chaimann May 15, 2025
79910a2
Allow option types sorting
chaimann May 15, 2025
825fc6e
Require confirmation on batch delete
chaimann May 15, 2025
96d88d8
Allow UI table to be embedded
chaimann May 16, 2025
69ee724
Use `href` in `<use>`
chaimann May 15, 2025
a65d599
Add option types edit component with simple fields
chaimann May 15, 2025
f9288fe
Redirect to edit page after creation
chaimann May 15, 2025
ff8e669
Add panel container for option values table
chaimann May 15, 2025
7a8820f
Add table for option values
chaimann May 16, 2025
ba2f169
Add batch delete functionality for option values
chaimann May 21, 2025
983c22c
Enable sorting of existing option values
chaimann May 21, 2025
5572bd6
Create controller concern for `move` action
chaimann May 21, 2025
bd470e1
Cleanup controllers with moveable concern
chaimann May 21, 2025
aafe0b0
Update elements nesting
chaimann May 22, 2025
1a65817
Update CRUD for option values
chaimann May 22, 2025
9952195
Add feature tests
chaimann May 23, 2025
25a54e7
Move option values table to its own component
chaimann May 23, 2025
29fa2bd
Move flash toasts to a component
chaimann May 23, 2025
6e909d9
Make `resource_form_frame` available in views
chaimann May 23, 2025
a059185
Make #create action respond with turbo-stream
chaimann May 23, 2025
fb1d32e
Make #update action respond with turbo-stream
chaimann May 23, 2025
c4e198d
Make #destroy action respond with turbo-stream
chaimann May 23, 2025
97268d8
Cleanup option_values_controller.rb
chaimann May 23, 2025
2b38410
Add feature tests
chaimann May 23, 2025
6ddcccd
Update CRUD resources shared examples
chaimann May 26, 2025
d1917a5
Add request tests
chaimann May 26, 2025
4c425ed
Delete redundant shared example
chaimann May 26, 2025
4e67cba
Add shared examples for sorting
chaimann May 26, 2025
e5d44ed
Add sorting tests for option types
chaimann May 26, 2025
cb02414
Add sorting tests for option values
chaimann May 26, 2025
0db9344
Use it_behaves_like instead of include_examples
chaimann May 26, 2025
0416377
Add missing specs for other sortables
chaimann May 27, 2025
988b9a1
Disable Rails/LexicallyScopedActionFilter cop
chaimann May 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,6 @@ Rails/FindEach:
# tasks should load the rails environment loaded.
Rails/RakeEnvironment:
Enabled: false

Rails/LexicallyScopedActionFilter:
Enabled: false
Original file line number Diff line number Diff line change
@@ -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| %>
<div class="flex flex-col gap-6 pb-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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",
)
end

def turbo_frames
%w[
resource_modal
resource_form
]
end

Expand All @@ -52,15 +52,15 @@ 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
},
{
header: :code,
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
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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| %>
<div class="flex flex-col gap-6 pb-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="flash_toasts" class="fixed inset-x-0 bottom-3 flex items-center justify-center flex-col gap-3 pointer-events-none" role="alert">
<% flash.each do |key, message| %>
<%= render component("ui/toast").new(text: message, scheme: key.to_sym == :error ? :error : :default) %>
<% end %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class SolidusAdmin::Layout::Flashes::Component < SolidusAdmin::BaseComponent
end
Original file line number Diff line number Diff line change
@@ -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 %>

<div class="flex flex-col gap-4">
<%= 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 %>
<div class="flex gap-4 w-full">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %>
</div>
<% 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 %>
<div id="option_values_table">
<%= render component("option_values/table").new(@option_type) %>
</div>
<% 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 %>
</div>

<%= turbo_frame_tag :option_value_modal, target: "_top" %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class SolidusAdmin::OptionTypes::Edit::Component < SolidusAdmin::Resources::Edit::Component
include SolidusAdmin::Layout::PageHelpers
end
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +41,7 @@ def batch_actions
action: solidus_admin.option_types_path,
method: :delete,
icon: 'delete-bin-7-line',
require_confirmation: true,
},
]
end
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class SolidusAdmin::OptionTypes::New::Component < SolidusAdmin::Resources::New::Component
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
title: "New Option Type"
cancel: "Cancel"
submit: "Add Option Type"
Original file line number Diff line number Diff line change
@@ -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| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class SolidusAdmin::OptionValues::Edit::Component < SolidusAdmin::Resources::Edit::Component
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
title: "Edit Option Value"
cancel: "Cancel"
submit: "Update Option Value"
Original file line number Diff line number Diff line change
@@ -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| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
title: "New Option Value"
cancel: "Cancel"
submit: "Add Option Value"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
en:
batch_actions:
delete: "Delete"
Original file line number Diff line number Diff line change
@@ -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| %>
<div class="flex flex-col gap-6 pb-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def edit_path(property)
end

def turbo_frames
%w[resource_modal]
%w[resource_form]
end

def page_actions
render component("ui/button").new(
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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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| %>
<div class="flex flex-col gap-6 pb-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -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| %>
<div class="flex flex-col gap-6 pb-4">
Expand Down
Loading