-
-
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.
Accept basic values when creating products/status components
- Loading branch information
Showing
6 changed files
with
31 additions
and
60 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
26 changes: 9 additions & 17 deletions
26
admin/app/components/solidus_admin/products/status/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 |
---|---|---|
@@ -1,31 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Products::Status::Component < SolidusAdmin::BaseComponent | ||
COLORS = { | ||
STATUSES = { | ||
available: :green, | ||
discontinued: :red | ||
}.freeze | ||
|
||
# @param product [Spree::Product] | ||
def initialize(product:) | ||
@product = product | ||
def self.from_product(product) | ||
new(status: product.available? ? :available : :discontinued) | ||
end | ||
|
||
def initialize(status:) | ||
@status = status | ||
end | ||
|
||
def call | ||
render component('ui/badge').new( | ||
name: t(".#{status}"), | ||
color: COLORS.fetch(status) | ||
name: t(".#{@status}"), | ||
color: STATUSES.fetch(@status) | ||
) | ||
end | ||
|
||
# @return [Symbol] | ||
# :available when the product is available | ||
# :discontinued when the product is not available | ||
def status | ||
if @product.available? | ||
:available | ||
else | ||
:discontinued | ||
end | ||
end | ||
end |
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: 15 additions & 16 deletions
31
...pec/components/previews/solidus_admin/products/status/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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
<table> | ||
<thead> | ||
<tr> | ||
<% definitions.each_key do |status| %> | ||
<th class="px-3 py-1 text-gray-500 text-center"><%= status.to_s.humanize %></th> | ||
<% end %> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<% definitions.each_value do |component| %> | ||
<th class="px-3 py-1"><%= render component %></th> | ||
<% end %> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Available | ||
</h6> | ||
|
||
<%= render current_component.new(status: :available) %> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Discontinued | ||
</h6> | ||
|
||
<%= render current_component.new(status: :discontinued) %> | ||
</div> |
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