Commit ebe84166 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'project-topics-projects-finder' into 'master'

ProjectsFinder: add parameter 'topic' in place of 'tag' [RUN ALL RSPEC]

See merge request gitlab-org/gitlab!62093
parents b91754b9 434b1281
......@@ -14,7 +14,8 @@
# starred: boolean
# sort: string
# visibility_level: int
# tags: string[]
# tag: string[] - deprecated, use 'topic' instead
# topic: string[]
# personal: boolean
# search: string
# search_namespaces: boolean
......@@ -37,6 +38,8 @@ class ProjectsFinder < UnionFinder
@params = params
@current_user = current_user
@project_ids_relation = project_ids_relation
@params[:topic] ||= @params.delete(:tag) if @params[:tag].present?
end
def execute
......@@ -76,7 +79,7 @@ class ProjectsFinder < UnionFinder
collection = by_starred(collection)
collection = by_trending(collection)
collection = by_visibility_level(collection)
collection = by_tags(collection)
collection = by_topics(collection)
collection = by_search(collection)
collection = by_archived(collection)
collection = by_custom_attributes(collection)
......@@ -176,8 +179,8 @@ class ProjectsFinder < UnionFinder
end
# rubocop: enable CodeReuse/ActiveRecord
def by_tags(items)
params[:tag].present? ? items.tagged_with(params[:tag]) : items
def by_topics(items)
params[:topic].present? ? items.tagged_with(params[:topic]) : items
end
def by_search(items)
......
......@@ -25,14 +25,14 @@
%span.access-request-links.gl-ml-3
= render 'shared/members/access_request_links', source: @project
- if @project.tag_list.present?
= cache_if(cache_enabled, [@project, :tag_list], expires_in: 1.day) do
- if @project.topic_list.present?
= cache_if(cache_enabled, [@project, :topic_list], expires_in: 1.day) do
%span.home-panel-topic-list.mt-2.w-100.d-inline-flex.gl-font-base.gl-font-weight-normal.gl-align-items-center
= sprite_icon('tag', css_class: 'icon gl-relative gl-mr-2')
- @project.topics_to_show.each do |topic|
- project_topics_classes = "badge badge-pill badge-secondary gl-mr-2"
- explore_project_topic_path = explore_projects_path(tag: topic)
- explore_project_topic_path = explore_projects_path(topic: topic)
- if topic.length > max_project_topic_length
%a{ class: "#{ project_topics_classes } str-truncated-30 has-tooltip", data: { container: "body" }, title: topic, href: explore_project_topic_path, itemprop: 'keywords' }
= topic.titleize
......
......@@ -599,6 +599,7 @@ module API
:custom_attributes,
:last_activity_after,
:last_activity_before,
:topic,
:repository_storage)
.symbolize_keys
.compact
......@@ -611,7 +612,6 @@ module API
finder_params[:user] = params.delete(:user) if params[:user]
finder_params[:id_after] = sanitize_id_param(params[:id_after]) if params[:id_after]
finder_params[:id_before] = sanitize_id_param(params[:id_before]) if params[:id_before]
finder_params[:tag] = params[:topic] if params[:topic].present?
finder_params
end
......
......@@ -128,23 +128,23 @@ RSpec.describe 'Project' do
end
it 'shows project topics' do
project.update_attribute(:tag_list, 'topic1')
project.update_attribute(:topic_list, 'topic1')
visit path
expect(page).to have_css('.home-panel-topic-list')
expect(page).to have_link('Topic1', href: explore_projects_path(tag: 'topic1'))
expect(page).to have_link('Topic1', href: explore_projects_path(topic: 'topic1'))
end
it 'shows up to 3 project tags' do
project.update_attribute(:tag_list, 'topic1, topic2, topic3, topic4')
it 'shows up to 3 project topics' do
project.update_attribute(:topic_list, 'topic1, topic2, topic3, topic4')
visit path
expect(page).to have_css('.home-panel-topic-list')
expect(page).to have_link('Topic1', href: explore_projects_path(tag: 'topic1'))
expect(page).to have_link('Topic2', href: explore_projects_path(tag: 'topic2'))
expect(page).to have_link('Topic3', href: explore_projects_path(tag: 'topic3'))
expect(page).to have_link('Topic1', href: explore_projects_path(topic: 'topic1'))
expect(page).to have_link('Topic2', href: explore_projects_path(topic: 'topic2'))
expect(page).to have_link('Topic3', href: explore_projects_path(topic: 'topic3'))
expect(page).to have_content('+ 1 more')
end
end
......
......@@ -137,9 +137,9 @@ RSpec.describe ProjectsFinder do
end
end
describe 'filter by tags' do
describe 'filter by tags (deprecated)' do
before do
public_project.tag_list = 'foo'
public_project.topic_list = 'foo'
public_project.save!
end
......@@ -148,6 +148,17 @@ RSpec.describe ProjectsFinder do
it { is_expected.to eq([public_project]) }
end
describe 'filter by topics' do
before do
public_project.topic_list = 'foo'
public_project.save!
end
let(:params) { { topic: 'foo' } }
it { is_expected.to eq([public_project]) }
end
describe 'filter by personal' do
let!(:personal_project) { create(:project, namespace: user.namespace) }
let(:params) { { personal: true } }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment