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

wip #1

Open
wants to merge 16 commits into
base: open-modal-content-remotely
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
Expand Up @@ -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,8 +1,7 @@
# frozen_string_literal: true

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ 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, data: {
turbo_frame: :new_adjustment_reason_modal,
turbo_prefetch: false
},
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -30,8 +33,8 @@ def turbo_frames
]
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)
end

def batch_actions
Expand All @@ -47,8 +50,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: :edit_adjustment_reason_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: :edit_adjustment_reason_modal, turbo_prefetch: false }
end
},
{
header: :active,
data: ->(adjustment_reason) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,8 +1,7 @@
# frozen_string_literal: true

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

Expand Down
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 :turbo_frame_request?, :search_filter_params, to: :helpers
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -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,8 +1,7 @@
# frozen_string_literal: true

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ 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)
end

def turbo_frames
Expand All @@ -28,7 +28,10 @@ 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, data: {
turbo_frame: :new_refund_reason_modal,
turbo_prefetch: false
},
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -47,8 +50,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: :edit_refund_reason_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: :edit_refund_reason_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
Expand Up @@ -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,8 +1,7 @@
# frozen_string_literal: true

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

Expand Down
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
21 changes: 21 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,21 @@
# frozen_string_literal: true

class SolidusAdmin::Resources::Edit::Component < SolidusAdmin::Resources::BaseComponent
def initialize(resource)
@resource = resource
end

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

def closable?
return false if request.referer&.include? "/edit"

turbo_frame_request? || @resource.errors.any?
end
end
20 changes: 20 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,20 @@
# frozen_string_literal: true

class SolidusAdmin::Resources::New::Component < SolidusAdmin::Resources::BaseComponent
def initialize(resource, closable: true)
super(resource)
@closable = closable
end

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

def closable?
@closable
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :edit_return_reason_modal 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| %>
<%= turbo_frame_tag :edit_return_reason_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title"), closable: closable?) do |modal| %>
<%= 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 @@ -15,12 +15,20 @@
</label>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<% if closable? %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<% else %>
<%= render component("ui/button").new(
tag: :a,
href: back_url,
scheme: :secondary,
text: t('.cancel')
) %>
<% end %>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
<% end %>
<% end %>
<% end %>
<%= render component("return_reasons/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# frozen_string_literal: true

class SolidusAdmin::ReturnReasons::Edit::Component < SolidusAdmin::BaseComponent
def initialize(page:, return_reason:)
@page = page
class SolidusAdmin::ReturnReasons::Edit::Component < SolidusAdmin::Resources::Edit::Component
def initialize(return_reason:)
@return_reason = return_reason
end

def form_id
dom_id(@return_reason, "#{stimulus_id}_edit_return_reason_form")
super(return_reason)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ 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
Expand All @@ -28,8 +28,8 @@ 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: :new_return_reason_modal, turbo_prefetch: false },
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -48,7 +48,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: :edit_return_reason_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 %>
<%= 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| %>
<%= turbo_frame_tag :new_return_reason_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title"), closable: closable?) do |modal| %>
<%= 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 @@ -15,13 +15,20 @@
</label>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<% if closable? %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<% else %>
<%= render component("ui/button").new(
tag: :a,
href: back_url,
scheme: :secondary,
text: t('.cancel')
) %>
<% end %>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
<% end %>
<% end %>
<% end %>

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

class SolidusAdmin::ReturnReasons::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, return_reason:)
@page = page
@return_reason = return_reason
end
class SolidusAdmin::ReturnReasons::New::Component < SolidusAdmin::Resources::New::Component

def form_id
dom_id(@return_reason, "#{stimulus_id}_new_return_reason_form")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("roles/index").new(page: @page) %>
3 changes: 1 addition & 2 deletions admin/app/components/solidus_admin/roles/edit/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
class SolidusAdmin::Roles::Edit::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::PermissionSetsHelper

def initialize(page:, role:)
@page = page
def initialize(role:)
@role = role
end

Expand Down
Loading
Loading