Skip to content

Commit

Permalink
Admin stock items: Load modal with turbo frame
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Dec 20, 2024
1 parent 2de5810 commit 3776427
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<%= link_to spree.edit_admin_product_variant_path(
@stock_item.variant.product,
@stock_item.variant,
), class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %>
),
data: {turbo_frame: "_top"},
class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %>
<%= render component("ui/resource_item").new(
thumbnail:
(
Expand All @@ -23,7 +25,9 @@
"#{@stock_item.variant.sku}#{@stock_item.variant.options_text.presence&.prepend(" - ")}",
) %>
<% end %>
<%= link_to spree.edit_admin_stock_location_path(@stock_item.stock_location), class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %>
<%= link_to spree.edit_admin_stock_location_path(@stock_item.stock_location),
data: {turbo_frame: "_top"},
class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %>
<%= render component("ui/resource_item").new(
title: @stock_item.stock_location.name,
subtitle: "#{Spree::StockLocation.model_name.human} #{@stock_item.stock_location.code}",
Expand Down Expand Up @@ -78,6 +82,4 @@
<% end %>
<% end %>
<% end %>

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

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

def title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def search_url
solidus_admin.stock_items_path
end

def row_url(stock_item)
solidus_admin.edit_stock_item_path(stock_item, _turbo_frame: :edit_stock_item_modal)
def edit_path(stock_item)
solidus_admin.edit_stock_item_path(stock_item)
end

def scopes
Expand Down Expand Up @@ -90,7 +90,9 @@ def name_column
{
header: :name,
data: ->(stock_item) do
content_tag :div, stock_item.variant.name
link_to stock_item.variant.name, edit_path(stock_item),
data: { turbo_frame: :edit_stock_item_modal, turbo_prefetch: false },
class: 'body-link'
end
}
end
Expand All @@ -99,7 +101,9 @@ def sku_column
{
header: :sku,
data: ->(stock_item) do
content_tag :div, stock_item.variant.sku
link_to stock_item.variant.sku, edit_path(stock_item),
data: { turbo_frame: :edit_stock_item_modal, turbo_prefetch: false },
class: 'body-link'
end
}
end
Expand Down
7 changes: 4 additions & 3 deletions admin/app/controllers/solidus_admin/stock_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module SolidusAdmin
class StockItemsController < SolidusAdmin::BaseController
include SolidusAdmin::ControllerHelpers::Search
before_action :load_stock_items, only: [:index, :edit, :update]
before_action :load_stock_items, only: [:index]
before_action :load_stock_item, only: [:edit, :update]

search_scope(:all, default: true) { _1 }
Expand All @@ -20,7 +20,7 @@ def index

def edit
respond_to do |format|
format.html { render component('stock_items/edit').new(stock_item: @stock_item, page: @page) }
format.html { render component('stock_items/edit').new(stock_item: @stock_item) }
end
end

Expand All @@ -36,7 +36,8 @@ def update
end
else
respond_to do |format|
format.html { render component('stock_items/edit').new(stock_item: @stock_item, page: @page), status: :unprocessable_entity }
format.html { render component('stock_items/edit').new(stock_item: @stock_item),
status: :unprocessable_entity }
end
end
end
Expand Down

0 comments on commit 3776427

Please sign in to comment.