-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
1 parent
02ceafa
commit 335fe51
Showing
28 changed files
with
227 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace::Tag::AdminComponent < ApplicationComponent | ||
with_collection_parameter :tag | ||
attr_accessor :tag | ||
delegate :label, to: :tag | ||
|
||
def initialize(tag:, data: {}, classes: "") | ||
super(data: data, classes: classes) | ||
|
||
self.tag = tag | ||
end | ||
|
||
def edit_button? | ||
tag.persisted? && policy(tag).edit? | ||
end | ||
|
||
def destroy_button? | ||
tag.persisted? && policy(tag).destroy? | ||
end | ||
|
||
def assigned_product_count | ||
# Consider optimizing this query with a counter cache or other method | ||
# if it becomes a performance bottleneck. | ||
@assigned_product_count ||= tag.product_tags.count | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
app/components/marketplace/tag/admin_component/admin_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,28 @@ | ||
<%= render CardComponent.new(dom_id: dom_id(tag)) do |card| %> | ||
<div class="flex flex-col gap-2"> | ||
<h3><%= tag.label %></h3> | ||
<span class="text-xs">Assigned to <%= assigned_product_count %> <%= "Product".pluralize(assigned_product_count) %></span> | ||
</div> | ||
<%- card.with_footer(variant: :action_bar) do %> | ||
<% if edit_button? %> | ||
<%= render ButtonComponent.new( | ||
label: "#{t("edit.link_to")}", | ||
title: t("marketplace.tags.edit.link_to", label: tag.label), | ||
href: tag.location(:edit), | ||
method: :get, | ||
scheme: :secondary | ||
) %> | ||
<%- end %> | ||
<% if destroy_button? %> | ||
<%= render ButtonComponent.new( | ||
label: "#{t("destroy.link_to")}", | ||
title: t("marketplace.tags.destroy.link_to", label: tag.label), | ||
href: tag.location, | ||
turbo_stream: true, | ||
method: :delete, | ||
confirm: t("destroy.confirm"), | ||
scheme: :secondary | ||
) %> | ||
<%- end %> | ||
<%- end %> | ||
<%- end %> |
1 change: 1 addition & 0 deletions
1
app/components/marketplace/tag/admin_component/admin_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 @@ | ||
--- |
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace::Tag::DisplayComponent < ApplicationComponent | ||
with_collection_parameter :tag | ||
attr_accessor :tag | ||
delegate :label, to: :tag | ||
|
||
def initialize(tag:, data: {}, classes: "") | ||
super(data: data, classes: classes) | ||
|
||
self.tag = tag | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
app/components/marketplace/tag/display_component/display_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 @@ | ||
<span class="text-xs px-2 py-1 rounded-full bg-gray-200/50 text-gray-700"><%= tag.label %></span> |
1 change: 1 addition & 0 deletions
1
app/components/marketplace/tag/display_component/display_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 @@ | ||
--- |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
<%- marketplace.tags.group_tag.by_position.each do |tag| %> | ||
<%- marketplace.tags.menu_tag.by_position.each do |tag| %> | ||
<%- unless tag.products.empty? %> | ||
<h1><%= tag.label %></h1> | ||
<div class="grid lg:grid-cols-3 gap-3"> | ||
<%- tag.products.with_all_rich_text.unarchived.each do |product| %> | ||
<%- tag.products.with_all_rich_text.unarchived.sort_alpha.each do |product| %> | ||
<%= render Marketplace::Menu::ProductComponent.new(product:, cart:) %> | ||
<%- end %> | ||
</div> | ||
<%- end %> | ||
<%- end %> | ||
<h1>Other</h1> | ||
<div class="grid lg:grid-cols-3 gap-3"> | ||
<%- marketplace.products.unarchived.without_group_tag.each do |product| %> | ||
<%- marketplace.products.unarchived.without_menu_tag.sort_alpha.each do |product| %> | ||
<%= render Marketplace::Menu::ProductComponent.new(product:, cart:) %> | ||
<%- end %> | ||
</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
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,8 +1,11 @@ | ||
<h3><%= name %></h3> | ||
<div class="mb-2"> | ||
<h3><%= name %></h3> | ||
</div> | ||
<%- if servings.present? %> | ||
<p class="text-sm">Serves <%= servings %></p> | ||
<%- end %> | ||
|
||
<%- if product.tags.present? %> | ||
<p>(<%= product.tags.pluck(:label).join(", ") %>)</p> | ||
<div class="flex gap-1"> | ||
<%= render Marketplace::Tag::DisplayComponent.with_collection(product.tags.not_menu) %> | ||
</div> | ||
<%- 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class AddIsGroupToMarketplaceTag < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :marketplace_tags, :is_group, :boolean, default: false, null: false | ||
add_column :marketplace_tags, :is_menu, :boolean, default: false, null: false | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20240531200256_rename_marketplace_tag_is_group_to_is_menu.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,5 @@ | ||
class RenameMarketplaceTagIsGroupToIsMenu < ActiveRecord::Migration[7.1] | ||
def change | ||
safety_assured { rename_column :marketplace_tags, :is_group, :is_menu } | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Marketplace::Tag::AdminComponent, type: :component do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
|
||
# it "renders something useful" do | ||
# expect( | ||
# render_inline(described_class.new(attr: "value")) { "Hello, components!" }.css("p").to_html | ||
# ).to include( | ||
# "Hello, components!" | ||
# ) | ||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Marketplace::Tag::DisplayComponent, type: :component do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
|
||
# it "renders something useful" do | ||
# expect( | ||
# render_inline(described_class.new(attr: "value")) { "Hello, components!" }.css("p").to_html | ||
# ).to include( | ||
# "Hello, components!" | ||
# ) | ||
# end | ||
end |
7 changes: 7 additions & 0 deletions
7
spec/components/previews/marketplace/tag/admin_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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace::Tag::AdminComponentPreview < ViewComponent::Preview | ||
def default | ||
render(Marketplace::Tag::AdminComponent.new) | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
spec/components/previews/marketplace/tag/display_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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace::Tag::DisplayComponentPreview < ViewComponent::Preview | ||
def default | ||
render(Marketplace::Tag::DisplayComponent.new) | ||
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
Oops, something went wrong.