Skip to content

Commit

Permalink
Marketplace: Archived Products are hidden from Products#index
Browse files Browse the repository at this point in the history
- #2023

Archived `Products` are no longer shown on the `Products` page.
  • Loading branch information
zspencer committed Dec 17, 2023
1 parent 23f78e0 commit 4cbb267
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= link_to text, location %>
24 changes: 24 additions & 0 deletions app/furniture/marketplace/archivable/index_link_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Marketplace
class Archivable::IndexLinkComponent < Component
attr_accessor :marketplace, :resource, :to_archive

def initialize(marketplace:, resource:, to_archive:, **kwargs)
self.marketplace = marketplace
self.resource = resource
self.to_archive = to_archive
super(**kwargs)
end

def location
if to_archive
marketplace.location(child: resource, query_params: {archive: true})
else
marketplace.location(child: resource)
end
end

def text
t(".#{resource}.#{to_archive ? :archive : :active}")
end
end
end
7 changes: 7 additions & 0 deletions app/furniture/marketplace/archivable/index_link_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
en:
delivery_areas:
archive: "Archived Delivery Areas"
active: "Active Delivery Areas"
products:
archive: "Archived Products"
active: "Active Products"
4 changes: 4 additions & 0 deletions app/furniture/marketplace/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Marketplace
class Component < ApplicationComponent
end
end
6 changes: 1 addition & 5 deletions app/furniture/marketplace/delivery_areas/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
<%- end %>
</div>
<div class="text-center mt-3">
<%- if params[:archive] %>
<%= link_to "Active Delivery Areas", marketplace.location(child: :delivery_areas) %>
<%- else %>
<%= link_to "Archived Delivery Areas", marketplace.location(child: :delivery_areas, query_params: { archive: true }) %>
<%- end %>
<%= render Marketplace::Archivable::IndexLinkComponent.new(marketplace: marketplace, resource: :products) %>
</div>
</section>
<% end %>
10 changes: 9 additions & 1 deletion app/furniture/marketplace/products/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

<%= render Marketplace::ManagementComponent.new(marketplace: marketplace) do %>
<div class="grid grid-cols-1 md:grid-cols-3 gap-3 sm:gap-5 mt-3 mx-auto">
<%= render Marketplace::ProductComponent.with_collection(marketplace.products) %>
<%- if params[:archive] %>
<%= render Marketplace::ProductComponent.with_collection(marketplace.products.archived) %>
<%- else %>
<%= render Marketplace::ProductComponent.with_collection(marketplace.products.unarchived) %>
<%- end %>
</div>

<div class="text-center mt-3">
Expand All @@ -16,4 +20,8 @@
scheme: :secondary) %>
<%- end %>
</div>

<div class="text-center mt-3">
<%= render Marketplace::Archivable::IndexLinkComponent.new(marketplace: marketplace, resource: :products) %>
</div>
<% end %>
33 changes: 33 additions & 0 deletions spec/furniture/marketplace/archivable/index_link_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "rails_helper"

RSpec.describe Marketplace::Archivable::IndexLinkComponent, type: :component do
subject(:output) { render_inline(component) }

let(:component) { described_class.new(marketplace:, resource:, to_archive: to_archive) }
let(:to_archive) { false }
let(:marketplace) { create(:marketplace) }

context "when the resource is products" do
let(:resource) { :products }

it { is_expected.to have_link("Active Products", href: polymorphic_path(marketplace.location(child: :products))) }

context "when to_archive" do
let(:to_archive) { true }

it { is_expected.to have_link("Archived Products", href: polymorphic_path(marketplace.location(child: :products), {archive: true})) }
end
end

context "when the resource is delivery_areas" do
let(:resource) { :delivery_areas }

it { is_expected.to have_link("Active Delivery Areas", href: polymorphic_path(marketplace.location(child: :delivery_areas))) }

context "when to_archive" do
let(:to_archive) { true }

it { is_expected.to have_link("Archived Delivery Areas", href: polymorphic_path(marketplace.location(child: :delivery_areas), {archive: true})) }
end
end
end

0 comments on commit 4cbb267

Please sign in to comment.