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

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
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,30 @@ 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,
turbo_prefetch: false
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved
},
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 +49,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, turbo_prefetch: false }
end
},
{
header: :code,
data: ->(adjustment_reason) do
link_to adjustment_reason.code, edit_path(adjustment_reason),
class: 'body-link',
data: { turbo_frame: :resource_modal, turbo_prefetch: false }
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_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,24 @@ 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,
turbo_prefetch: false
},
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -38,7 +40,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 +49,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, turbo_prefetch: false },
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, turbo_prefetch: false },
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")
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
11 changes: 11 additions & 0 deletions admin/app/components/solidus_admin/resources/new/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

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

def form_url
solidus_admin.send("#{plural_resource_name}_path", **search_filter_params)
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :edit_return_reason_modal do %>
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @return_reason, url: solidus_admin.return_reason_path(@return_reason), html: { id: form_id } do |f| %>
<%= form_for @return_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") %>
<label class="flex gap-2 items-center">
Expand All @@ -23,4 +23,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("return_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::ReturnReasons::Edit::Component < SolidusAdmin::BaseComponent
def initialize(page:, return_reason:)
@page = page
@return_reason = return_reason
end

def form_id
dom_id(@return_reason, "#{stimulus_id}_edit_return_reason_form")
end
class SolidusAdmin::ReturnReasons::Edit::Component < SolidusAdmin::Resources::Edit::Component
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ def search_key
:name_cont
end

def row_url(return_reason)
spree.edit_admin_return_reason_path(return_reason, _turbo_frame: :edit_return_reason_modal)
def edit_path(return_reason)
spree.edit_admin_return_reason_path(return_reason, **search_filter_params)
end

def turbo_frames
%w[
new_return_reason_modal
edit_return_reason_modal
resource_modal
]
end

def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_return_reason_path,
data: { turbo_frame: :new_return_reason_modal },
href: solidus_admin.new_return_reason_path(**search_filter_params),
data: { turbo_frame: :resource_modal, turbo_prefetch: false },
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -48,7 +47,14 @@ def batch_actions

def columns
[
:name,
{
header: :name,
data: ->(return_reason) do
link_to return_reason.name, edit_path(return_reason),
data: { turbo_frame: :resource_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :active,
data: ->(return_reason) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :new_return_reason_modal do %>
<%= turbo_frame_tag :resource_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @return_reason, url: solidus_admin.return_reasons_path, html: { id: form_id } do |f| %>
<%= form_for @return_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") %>
<label class="flex gap-2 items-center">
Expand All @@ -23,5 +23,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("return_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::ReturnReasons::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, return_reason:)
@page = page
@return_reason = return_reason
end

def form_id
dom_id(@return_reason, "#{stimulus_id}_new_return_reason_form")
end
class SolidusAdmin::ReturnReasons::New::Component < SolidusAdmin::Resources::New::Component
end
Loading
Loading