-
-
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
7 changed files
with
87 additions
and
20 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
4 changes: 0 additions & 4 deletions
4
admin/app/components/solidus_admin/products/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
31 changes: 31 additions & 0 deletions
31
admin/app/components/solidus_admin/products/stock/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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Products::Stock::Component < SolidusAdmin::BaseComponent | ||
def self.from_product(product) | ||
new( | ||
on_hand: product.total_on_hand, | ||
variants_count: product.variants.count, | ||
) | ||
end | ||
|
||
def initialize(on_hand:, variants_count:) | ||
@on_hand = on_hand | ||
@variants_count = variants_count | ||
end | ||
|
||
def call | ||
stock_info = | ||
case @on_hand | ||
when Float::INFINITY | ||
tag.span t('.stock.in_stock', on_hand: t('.stock.infinity')), class: 'text-forest' | ||
when 1..Float::INFINITY | ||
tag.span t('.stock.in_stock', on_hand: @on_hand), class: 'text-forest' | ||
else | ||
tag.span t('.stock.in_stock', on_hand: @on_hand), class: 'text-red-500' | ||
end | ||
|
||
variant_info = t('.for_variants', count: @variants_count) | ||
|
||
tag.div safe_join([stock_info, variant_info], ' ') | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
admin/app/components/solidus_admin/products/stock/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,5 @@ | ||
en: | ||
stock: | ||
infinity: '∞' | ||
in_stock: '%{on_hand} in stock' | ||
for_variants: 'for %{count} variants' |
10 changes: 10 additions & 0 deletions
10
admin/spec/components/previews/solidus_admin/products/stock/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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
# @component "products/stock" | ||
class SolidusAdmin::Products::Stock::ComponentPreview < ViewComponent::Preview | ||
include SolidusAdmin::Preview | ||
|
||
def overview | ||
render_with_template | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
...spec/components/previews/solidus_admin/products/stock/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,31 @@ | ||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
In Stock | ||
</h6> | ||
|
||
<%= render current_component.new(on_hand: 32, variants_count: 12) %> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Infinite stock | ||
</h6> | ||
|
||
<%= render current_component.new(on_hand: Float::INFINITY, variants_count: 12) %> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Out of stock | ||
</h6> | ||
|
||
<%= render current_component.new(on_hand: 0, variants_count: 12) %> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Negative stock | ||
</h6> | ||
|
||
<%= render current_component.new(on_hand: -10, variants_count: 12) %> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
admin/spec/components/solidus_admin/products/stock/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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe SolidusAdmin::Products::Stock::Component, type: :component do | ||
it "renders the overview preview" do | ||
render_preview(:overview) | ||
end | ||
end |