Skip to content

Commit

Permalink
Exclude current page from most popular searches
Browse files Browse the repository at this point in the history
We don't want to show the page that a user is on in any navigation.  It's
confusing and confers no benefit.

https://trello.com/c/ljVuTZUL/80-exclude-current-page-from-navigation
  • Loading branch information
sihugh committed Jul 26, 2018
1 parent 94869b3 commit df767e6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def load_taxonomy_navigation
taxons = @content_item.taxons.select { |taxon| taxon["phase"] == "live" }

taxon_ids = taxons.map { |taxon| taxon["content_id"] }
services = Supergroups::Services.new(taxon_ids)
services = Supergroups::Services.new(content_item_path, taxon_ids)

@taxonomy_navigation = {
services: (services.all_services if services.any_services?),
Expand Down
8 changes: 6 additions & 2 deletions app/presenters/supergroups/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ module Supergroups
class Services
attr_reader :content

def initialize(taxon_ids)
def initialize(current_path, taxon_ids)
@taxon_ids = taxon_ids
@content = MostPopularContent.fetch(content_ids: @taxon_ids, filter_content_purpose_supergroup: "services")
@content = MostPopularContent.fetch(
content_ids: @taxon_ids,
current_path: current_path,
filter_content_purpose_supergroup: "services"
)
end

def all_services
Expand Down
10 changes: 6 additions & 4 deletions app/services/most_popular_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
class MostPopularContent
include RummagerFields

attr_reader :content_ids, :filter_content_purpose_supergroup, :number_of_links
attr_reader :content_ids, :current_path, :filter_content_purpose_supergroup, :number_of_links

def initialize(content_ids:, filter_content_purpose_supergroup:, number_of_links: 5)
def initialize(content_ids:, current_path:, filter_content_purpose_supergroup:, number_of_links: 5)
@content_ids = content_ids
@current_path = current_path
@filter_content_purpose_supergroup = filter_content_purpose_supergroup
@number_of_links = number_of_links
end

def self.fetch(content_ids:, filter_content_purpose_supergroup:)
new(content_ids: content_ids, filter_content_purpose_supergroup: filter_content_purpose_supergroup).fetch
def self.fetch(content_ids:, current_path:, filter_content_purpose_supergroup:)
new(content_ids: content_ids, current_path: current_path, filter_content_purpose_supergroup: filter_content_purpose_supergroup).fetch
end

def fetch
Expand All @@ -28,6 +29,7 @@ def search_response
fields: RummagerFields::TAXON_SEARCH_FIELDS,
filter_part_of_taxonomy_tree: content_ids,
order: '-popularity',
reject_link: current_path,
}
params[:filter_content_purpose_supergroup] = filter_content_purpose_supergroup if filter_content_purpose_supergroup.present?

Expand Down
7 changes: 7 additions & 0 deletions test/services/most_popular_content_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class MostPopularContentTest < ActiveSupport::TestCase
def most_popular_content
@most_popular_content ||= MostPopularContent.new(
content_ids: taxon_content_ids,
current_path: "/how-to-ride-a-bike",
filter_content_purpose_supergroup: 'guidance_and_regulation'
)
end
Expand Down Expand Up @@ -69,6 +70,12 @@ def taxon_content_ids
end
end

test 'rejects the originating page from the results' do
assert_includes_params(reject_link: '/how-to-ride-a-bike') do
most_popular_content.fetch
end
end

def assert_includes_params(expected_params)
search_results = {
'results' => [
Expand Down

0 comments on commit df767e6

Please sign in to comment.