-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
277 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
admin/app/components/solidus_admin/orders/show/adjustments/index/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<%= page do %> | ||
<%= page_header do %> | ||
<%= page_header_back(solidus_admin.order_path(@order)) %> | ||
<%= page_header_title(t(".title", number: @order.number)) %> | ||
<%= page_header_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :button, | ||
scheme: :secondary, | ||
text: t(".discard"), | ||
form: form_id | ||
) %> | ||
<%= render component("ui/button").new(tag: :button, text: t(".save"), form: form_id) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= page_with_sidebar do %> | ||
<%= page_with_sidebar_main do %> | ||
<%= render component("ui/table").new( | ||
id: "order-adjustments-list", | ||
model_class: Spree::Adjustment, | ||
rows: @adjustments, | ||
search_key: :label_cont, | ||
search_url: solidus_admin.order_adjustments_path(@order), | ||
batch_actions: [ | ||
{ | ||
display_name: t(".batch_actions.delete"), | ||
action: spree.admin_order_adjustment_path(@order, '[]'), | ||
method: :delete, | ||
icon: "delete-bin-7-line" | ||
}, | ||
{ | ||
display_name: t(".batch_actions.edit"), | ||
action: spree.edit_admin_order_adjustment_path(@order, '[]'), | ||
method: :put, | ||
icon: "edit-line" | ||
}, | ||
], | ||
filters: [], | ||
columns: [ | ||
{ | ||
header: :adjustable_type, | ||
data: -> { _1.adjustable_type.constantize.model_name.human } | ||
}, | ||
{ | ||
header: :adjustable, | ||
data: ->(adjustment) do | ||
adjustable = adjustment.adjustable | ||
|
||
case adjustable | ||
when Spree::LineItem | ||
safe_join( | ||
[ | ||
render(component("ui/thumbnail").for_variant(adjustable.variant)), | ||
tag.span( | ||
adjustable.variant.options_text.presence || | ||
adjustable.variant.sku, | ||
class: "ml-2" | ||
), | ||
tag.span(adjustable.quantity, class: "ml-2 text-sm text-gray-500") | ||
] | ||
) | ||
when Spree::Shipment | ||
adjustable.inspect | ||
when Spree::Order | ||
adjustable.number | ||
when Spree::TaxRate | ||
adjustable.inspect | ||
end | ||
end | ||
}, | ||
{ header: :label, data: ->(adjustment) { adjustment.label } }, | ||
{ | ||
header: :amount, | ||
data: ->(adjustment) { tag.span adjustment.display_amount.to_html } | ||
}, | ||
{ | ||
header: :state, | ||
data: ->(adjustment) do | ||
icon = adjustment.finalized? ? "lock-line" : "lock-unlock-line" | ||
icon_tag(icon, class: "w-6 h-6") | ||
end | ||
}, | ||
{ | ||
header: '', | ||
data: ->(adjustment) do | ||
tag.div(class: "relative") do | ||
render component('ui/dropdown').new(size: :s, direction: :right, "data-action": "click:stop->#{stimulus_id}#noop").with_content(safe_join([ | ||
link_to('edit', spree.edit_admin_order_adjustment_path(@order, adjustment)), | ||
button_to('delete', spree.admin_order_adjustment_path(@order, adjustment), method: :delete, class: "text-left"), | ||
])) | ||
end | ||
end | ||
}, | ||
] | ||
) %> | ||
<% end %> | ||
|
||
<%= page_with_sidebar_aside do %> | ||
<%= render component('ui/panel').new(title: "Summary") do %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% end %> |
4 changes: 4 additions & 0 deletions
4
admin/app/components/solidus_admin/orders/show/adjustments/index/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
} |
15 changes: 15 additions & 0 deletions
15
admin/app/components/solidus_admin/orders/show/adjustments/index/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Orders::Show::Adjustments::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(order:, adjustments:) | ||
@order = order | ||
@adjustments = adjustments | ||
end | ||
|
||
def form_id | ||
@form_id ||= "#{stimulus_id}--form-#{@order.id}" | ||
end | ||
|
||
end |
7 changes: 7 additions & 0 deletions
7
admin/app/components/solidus_admin/orders/show/adjustments/index/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
en: | ||
title: "Order %{number} / Adjustments" | ||
save: "Save" | ||
discard: "Discard" | ||
batch_actions: | ||
delete: "Delete selected adjustments" | ||
edit: "Edit selected adjustments" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
admin/app/controllers/solidus_admin/adjustments_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::AdjustmentsController < SolidusAdmin::BaseController | ||
before_action :load_order | ||
|
||
def index | ||
@adjustments = @order.all_adjustments.eligible.order("created_at ASC") | ||
|
||
set_page_and_extract_portion_from(@adjustments) | ||
|
||
respond_to do |format| | ||
format.html { render component('orders/show/adjustments/index').new( | ||
order: @order, | ||
adjustments: @adjustments, | ||
) } | ||
end | ||
end | ||
|
||
private | ||
|
||
def load_order | ||
@order = Spree::Order.find_by!(number: params[:order_id]) | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
...spec/components/previews/solidus_admin/orders/show/adjustments/index/component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# @component "orders/show/adjustments/index" | ||
class SolidusAdmin::Orders::Show::Adjustments::Index::ComponentPreview < ViewComponent::Preview | ||
include SolidusAdmin::Preview | ||
|
||
def overview | ||
render_with_template | ||
end | ||
|
||
# @param order text | ||
# @param adjustments text | ||
def playground(order: "order", adjustments: "adjustments") | ||
render component("orders/show/adjustments/index").new(order: order, adjustments: adjustments) | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
.../previews/solidus_admin/orders/show/adjustments/index/component_preview/overview.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Scenario 1 | ||
</h6> | ||
|
||
<%= render current_component.new(order: "order", adjustments: "adjustments") %> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
admin/spec/components/solidus_admin/orders/show/adjustments/index/component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe SolidusAdmin::Orders::Show::Adjustments::Index::Component, type: :component do | ||
it "renders the overview preview" do | ||
render_preview(:overview) | ||
end | ||
|
||
# it "renders something useful" do | ||
# render_inline(described_class.new(order: "order", adjustments: "adjustments")) | ||
# | ||
# expect(page).to have_text "Hello, components!" | ||
# expect(page).to have_css '.value' | ||
# end | ||
end |
Oops, something went wrong.