Commit 89de38a6 authored by Eulyeon Ko's avatar Eulyeon Ko

Allow sort by popularity for issues via GraphQL

Changelog: added
parent 552576ff
...@@ -15,6 +15,7 @@ module Resolvers ...@@ -15,6 +15,7 @@ module Resolvers
type Types::IssueType.connection_type, null: true type Types::IssueType.connection_type, null: true
NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc
popularity_asc popularity_desc
label_priority_asc label_priority_desc label_priority_asc label_priority_desc
milestone_due_asc milestone_due_desc].freeze milestone_due_asc milestone_due_desc].freeze
......
...@@ -10,6 +10,8 @@ module Types ...@@ -10,6 +10,8 @@ module Types
value 'RELATIVE_POSITION_ASC', 'Relative position by ascending order.', value: :relative_position_asc value 'RELATIVE_POSITION_ASC', 'Relative position by ascending order.', value: :relative_position_asc
value 'SEVERITY_ASC', 'Severity from less critical to more critical.', value: :severity_asc value 'SEVERITY_ASC', 'Severity from less critical to more critical.', value: :severity_asc
value 'SEVERITY_DESC', 'Severity from more critical to less critical.', value: :severity_desc value 'SEVERITY_DESC', 'Severity from more critical to less critical.', value: :severity_desc
value 'POPULARITY_ASC', 'Number of upvotes (awarded "thumbs up" emoji) by ascending order.', value: :popularity_asc
value 'POPULARITY_DESC', 'Number of upvotes (awarded "thumbs up" emoji) by descending order.', value: :popularity_desc
end end
end end
......
...@@ -14607,6 +14607,8 @@ Values for sorting issues. ...@@ -14607,6 +14607,8 @@ Values for sorting issues.
| <a id="issuesortlabel_priority_desc"></a>`LABEL_PRIORITY_DESC` | Label priority by descending order. | | <a id="issuesortlabel_priority_desc"></a>`LABEL_PRIORITY_DESC` | Label priority by descending order. |
| <a id="issuesortmilestone_due_asc"></a>`MILESTONE_DUE_ASC` | Milestone due date by ascending order. | | <a id="issuesortmilestone_due_asc"></a>`MILESTONE_DUE_ASC` | Milestone due date by ascending order. |
| <a id="issuesortmilestone_due_desc"></a>`MILESTONE_DUE_DESC` | Milestone due date by descending order. | | <a id="issuesortmilestone_due_desc"></a>`MILESTONE_DUE_DESC` | Milestone due date by descending order. |
| <a id="issuesortpopularity_asc"></a>`POPULARITY_ASC` | Number of upvotes (awarded "thumbs up" emoji) by ascending order. |
| <a id="issuesortpopularity_desc"></a>`POPULARITY_DESC` | Number of upvotes (awarded "thumbs up" emoji) by descending order. |
| <a id="issuesortpriority_asc"></a>`PRIORITY_ASC` | Priority by ascending order. | | <a id="issuesortpriority_asc"></a>`PRIORITY_ASC` | Priority by ascending order. |
| <a id="issuesortpriority_desc"></a>`PRIORITY_DESC` | Priority by descending order. | | <a id="issuesortpriority_desc"></a>`PRIORITY_DESC` | Priority by descending order. |
| <a id="issuesortpublished_asc"></a>`PUBLISHED_ASC` | Published issues shown last. | | <a id="issuesortpublished_asc"></a>`PUBLISHED_ASC` | Published issues shown last. |
......
...@@ -290,6 +290,44 @@ RSpec.describe Resolvers::IssuesResolver do ...@@ -290,6 +290,44 @@ RSpec.describe Resolvers::IssuesResolver do
expect(resolve_issues(sort: :severity_desc).to_a).to eq([issue_high_severity, issue_low_severity, issue_no_severity]) expect(resolve_issues(sort: :severity_desc).to_a).to eq([issue_high_severity, issue_low_severity, issue_no_severity])
end end
end end
context 'when sorting by popularity' do
let_it_be(:project) { create(:project, :public) }
let_it_be(:issue1) { create(:issue, project: project) } # has one upvote
let_it_be(:issue2) { create(:issue, project: project) } # has two upvote
let_it_be(:issue3) { create(:issue, project: project) }
let_it_be(:issue4) { create(:issue, project: project) } # has one upvote
before do
create(:award_emoji, :upvote, awardable: issue1)
create(:award_emoji, :upvote, awardable: issue2)
create(:award_emoji, :upvote, awardable: issue2)
create(:award_emoji, :upvote, awardable: issue4)
end
it 'sorts issues ascending (ties broken by id in desc order)', :aggregate_failures do
expect(issue1.id).to be < (issue4.id)
expect(resolve_issues(sort: :popularity_asc).to_a).to eq([issue3, issue4, issue1, issue2])
end
it 'sorts issues descending (ties broken by id in desc order)', :aggregate_failures do
expect(issue1.id).to be < (issue4.id)
expect(resolve_issues(sort: :popularity_desc).to_a).to eq([issue2, issue4, issue1, issue3])
end
end
context 'when sorting with non-stable cursors' do
%i[priority_asc priority_desc
popularity_asc popularity_desc
label_priority_asc label_priority_desc
milestone_due_asc milestone_due_desc].each do |sort_by|
it "uses offset-pagination when sorting by #{sort_by}" do
resolved = resolve_issues(sort: sort_by)
expect(resolved).to be_a(::Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection)
end
end
end
end end
it 'returns issues user can see' do it 'returns issues user can see' do
......
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