Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Admin] Open edit and new forms in dialog with turbo frame #6046

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :edit_adjustment_reason_modal do %>
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @adjustment_reason, url: solidus_admin.adjustment_reason_path(@adjustment_reason), html: { id: form_id } do |f| %>
<%= form_for @adjustment_reason, 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, :code, class: "required") %>
Expand All @@ -24,4 +24,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("adjustment_reasons/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# frozen_string_literal: true

class SolidusAdmin::AdjustmentReasons::Edit::Component < SolidusAdmin::BaseComponent
def initialize(page:, adjustment_reason:)
@page = page
@adjustment_reason = adjustment_reason
end

def form_id
dom_id(@adjustment_reason, "#{stimulus_id}_edit_adjustment_reason_form")
end
class SolidusAdmin::AdjustmentReasons::Edit::Component < SolidusAdmin::Resources::Edit::Component
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_adjustment_reason_path, data: { turbo_frame: :new_adjustment_reason_modal },
href: solidus_admin.new_adjustment_reason_path(**search_filter_params),
data: { turbo_frame: :resource_modal },
icon: "add-line",
class: "align-self-end w-full",
)
end

def turbo_frames
%w[
new_adjustment_reason_modal
edit_adjustment_reason_modal
resource_modal
]
end

def row_url(adjustment_reason)
spree.edit_admin_adjustment_reason_path(adjustment_reason, _turbo_frame: :edit_adjustment_reason_modal)
def edit_path(adjustment_reason)
spree.edit_admin_adjustment_reason_path(adjustment_reason, **search_filter_params)
end

def batch_actions
[
{
label: t('.batch_actions.delete'),
action: solidus_admin.adjustment_reasons_path,
action: solidus_admin.adjustment_reasons_path(**search_filter_params),
method: :delete,
icon: 'delete-bin-7-line',
},
Expand All @@ -47,8 +47,22 @@ def batch_actions

def columns
[
:name,
:code,
{
header: :name,
data: ->(adjustment_reason) do
link_to adjustment_reason.name, edit_path(adjustment_reason),
class: 'body-link',
data: { turbo_frame: :resource_modal }
end
},
{
header: :code,
data: ->(adjustment_reason) do
link_to adjustment_reason.code, edit_path(adjustment_reason),
class: 'body-link',
data: { turbo_frame: :resource_modal }
end
},
{
header: :active,
data: ->(adjustment_reason) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :new_adjustment_reason_modal do %>
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @adjustment_reason, url: solidus_admin.adjustment_reasons_path, html: { id: form_id } do |f| %>
<%= form_for @adjustment_reason, 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, :code, class: "required") %>
Expand All @@ -24,5 +24,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("adjustment_reasons/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# frozen_string_literal: true

class SolidusAdmin::AdjustmentReasons::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, adjustment_reason:)
@page = page
@adjustment_reason = adjustment_reason
end

def form_id
dom_id(@adjustment_reason, "#{stimulus_id}_new_adjustment_reason_form")
end
class SolidusAdmin::AdjustmentReasons::New::Component < SolidusAdmin::Resources::New::Component
end
1 change: 1 addition & 0 deletions admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ def self.stimulus_id
end

delegate :stimulus_id, to: :class
delegate :search_filter_params, to: :helpers
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :edit_property_modal do %>
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @property, url: solidus_admin.property_path(@property), html: { id: form_id } do |f| %>
<%= form_for @property, 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") %>
Expand All @@ -14,4 +14,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("properties/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# frozen_string_literal: true

class SolidusAdmin::Properties::Edit::Component < SolidusAdmin::BaseComponent
def initialize(page:, property:)
@page = page
@property = property
end

def form_id
dom_id(@property, "#{stimulus_id}_edit_property_form")
end
class SolidusAdmin::Properties::Edit::Component < SolidusAdmin::Resources::Edit::Component
end
22 changes: 12 additions & 10 deletions admin/app/components/solidus_admin/properties/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ def search_url
solidus_admin.properties_path
end

def row_url(property)
solidus_admin.edit_property_path(property, _turbo_frame: :edit_property_modal)
def edit_path(property)
solidus_admin.edit_property_path(property, **search_filter_params)
end

def turbo_frames
%w[
new_property_modal
edit_property_modal
]
%w[resource_modal]
end

def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_property_path, data: { turbo_frame: :new_property_modal },
href: solidus_admin.new_property_path(**search_filter_params),
data: { turbo_frame: :resource_modal },
icon: "add-line",
)
end
Expand All @@ -41,7 +39,7 @@ def batch_actions
[
{
label: t('.batch_actions.delete'),
action: solidus_admin.properties_path,
action: solidus_admin.properties_path(**search_filter_params),
method: :delete,
icon: 'delete-bin-7-line',
},
Expand All @@ -59,7 +57,9 @@ def name_column
{
header: :name,
data: ->(property) do
content_tag :div, property.name
link_to property.name, edit_path(property),
data: { turbo_frame: :resource_modal },
class: 'body-link'
end
}
end
Expand All @@ -68,7 +68,9 @@ def presentation_column
{
header: :presentation,
data: ->(property) do
content_tag :div, property.presentation
link_to property.presentation, edit_path(property),
data: { turbo_frame: :resource_modal },
class: 'body-link'
end
}
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :new_property_modal do %>
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @property, url: solidus_admin.properties_path, html: { id: form_id } do |f| %>
<%= form_for @property, 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") %>
Expand All @@ -14,5 +14,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("properties/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# frozen_string_literal: true

class SolidusAdmin::Properties::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, property:)
@page = page
@property = property
end

def form_id
dom_id(@property, "#{stimulus_id}_new_property_form")
end
class SolidusAdmin::Properties::New::Component < SolidusAdmin::Resources::New::Component
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :edit_refund_reason_modal do %>
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @refund_reason, url: solidus_admin.refund_reason_path(@refund_reason), html: { id: form_id } do |f| %>
<%= form_for @refund_reason, 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, :code, class: "required") %>
Expand All @@ -24,4 +24,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("refund_reasons/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# frozen_string_literal: true

class SolidusAdmin::RefundReasons::Edit::Component < SolidusAdmin::BaseComponent
def initialize(page:, refund_reason:)
@page = page
@refund_reason = refund_reason
end

def form_id
dom_id(@refund_reason, "#{stimulus_id}_edit_refund_reason_form")
end
class SolidusAdmin::RefundReasons::Edit::Component < SolidusAdmin::Resources::Edit::Component
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ def search_key
:name_or_code_cont
end

def row_url(refund_reason)
spree.edit_admin_refund_reason_path(refund_reason, _turbo_frame: :edit_refund_reason_modal)
def edit_path(refund_reason)
spree.edit_admin_refund_reason_path(refund_reason, **search_filter_params)
end

def turbo_frames
%w[
new_refund_reason_modal
edit_refund_reason_modal
resource_modal
]
end

def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_refund_reason_path, data: { turbo_frame: :new_refund_reason_modal },
href: solidus_admin.new_refund_reason_path(**search_filter_params),
data: { turbo_frame: :resource_modal },
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -38,7 +38,7 @@ def batch_actions
[
{
label: t('.batch_actions.delete'),
action: solidus_admin.refund_reasons_path,
action: solidus_admin.refund_reasons_path(**search_filter_params),
method: :delete,
icon: 'delete-bin-7-line',
},
Expand All @@ -47,8 +47,22 @@ def batch_actions

def columns
[
:name,
:code,
{
header: :name,
data: ->(refund_reason) do
link_to refund_reason.name, edit_path(refund_reason),
data: { turbo_frame: :resource_modal },
class: 'body-link'
end
},
{
header: :code,
data: ->(refund_reason) do
link_to_if refund_reason.code, refund_reason.code, edit_path(refund_reason),
data: { turbo_frame: :resource_modal },
class: 'body-link'
end
},
{
header: :active,
data: ->(refund_reason) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :new_refund_reason_modal do %>
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @refund_reason, url: solidus_admin.refund_reasons_path, html: { id: form_id } do |f| %>
<%= form_for @refund_reason, 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, :code, class: "required") %>
Expand All @@ -23,5 +23,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("refund_reasons/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# frozen_string_literal: true

class SolidusAdmin::RefundReasons::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, refund_reason:)
@page = page
@refund_reason = refund_reason
end

def form_id
dom_id(@refund_reason, "#{stimulus_id}_new_refund_reason_form")
end
class SolidusAdmin::RefundReasons::New::Component < SolidusAdmin::Resources::New::Component
end
20 changes: 20 additions & 0 deletions admin/app/components/solidus_admin/resources/base_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

class SolidusAdmin::Resources::BaseComponent < SolidusAdmin::BaseComponent
def initialize(resource)
@resource = resource
instance_variable_set("@#{resource_name}", resource)
end

def back_url
solidus_admin.send("#{plural_resource_name}_path")

Check warning on line 10 in admin/app/components/solidus_admin/resources/base_component.rb

View check run for this annotation

Codecov / codecov/patch

admin/app/components/solidus_admin/resources/base_component.rb#L10

Added line #L10 was not covered by tests
end

def resource_name
@resource.model_name.singular_route_key
end

def plural_resource_name
@resource.model_name.route_key
end
end
11 changes: 11 additions & 0 deletions admin/app/components/solidus_admin/resources/edit/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class SolidusAdmin::Resources::Edit::Component < SolidusAdmin::Resources::BaseComponent
def form_id
dom_id(@resource, "#{stimulus_id}_edit_#{resource_name}_form")
end

def form_url
solidus_admin.send("#{resource_name}_path", @resource, **search_filter_params)
end
end
Loading
Loading