Commit 0eedf4a3 authored by Brett Walker's avatar Brett Walker

Allow sorting of issues with milestone_due_asc

in GraphQL
parent 59e842e5
......@@ -52,7 +52,9 @@ module Resolvers
type Types::IssueType, null: true
NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc label_priority_asc label_priority_desc].freeze
NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc
label_priority_asc label_priority_desc
milestone_due_asc milestone_due_desc].freeze
def resolve(**args)
# The project could have been loaded in batch by `BatchLoader`.
......
......@@ -9,5 +9,7 @@ module Types
value 'PRIORITY_DESC', 'Priority by descending order', value: :priority_desc
value 'LABEL_PRIORITY_ASC', 'Label priority by ascending order', value: :label_priority_asc
value 'LABEL_PRIORITY_DESC', 'Label priority by descending order', value: :label_priority_desc
value 'MILESTONE_DUE_ASC', 'Milestone due date by ascending order', value: :milestone_due_asc
value 'MILESTONE_DUE_DESC', 'Milestone due date by descending order', value: :milestone_due_desc
end
end
---
title: GraphQL issue queries can now be sorted by milestone due date
merge_request: 29992
author:
type: added
......@@ -4677,6 +4677,16 @@ enum IssueSort {
"""
LABEL_PRIORITY_DESC
"""
Milestone due date by ascending order
"""
MILESTONE_DUE_ASC
"""
Milestone due date by descending order
"""
MILESTONE_DUE_DESC
"""
Priority by ascending order
"""
......
......@@ -13272,6 +13272,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "MILESTONE_DUE_ASC",
"description": "Milestone due date by ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "MILESTONE_DUE_DESC",
"description": "Milestone due date by descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "DUE_DATE_ASC",
"description": "Due date by ascending order",
......
......@@ -190,6 +190,23 @@ describe Resolvers::IssuesResolver do
expect(resolve_issues(sort: :label_priority_desc).items).to eq([label_issue2, label_issue3, label_issue1, label_issue4])
end
end
context 'when sorting by milestone due date' do
let_it_be(:project) { create(:project) }
let_it_be(:early_milestone) { create(:milestone, project: project, due_date: 10.days.from_now) }
let_it_be(:late_milestone) { create(:milestone, project: project, due_date: 30.days.from_now) }
let_it_be(:milestone_issue1) { create(:issue, project: project) }
let_it_be(:milestone_issue2) { create(:issue, project: project, milestone: early_milestone) }
let_it_be(:milestone_issue3) { create(:issue, project: project, milestone: late_milestone) }
it 'sorts issues ascending' do
expect(resolve_issues(sort: :milestone_due_asc).items).to eq([milestone_issue2, milestone_issue3, milestone_issue1])
end
it 'sorts issues descending' do
expect(resolve_issues(sort: :milestone_due_desc).items).to eq([milestone_issue3, milestone_issue2, milestone_issue1])
end
end
end
it 'returns issues user can see' do
......
......@@ -6,6 +6,10 @@ describe Types::IssuableSortEnum do
it { expect(described_class.graphql_name).to eq('IssuableSort') }
it 'exposes all the existing issuable sort values' do
expect(described_class.values.keys).to include(*%w[PRIORITY_ASC PRIORITY_DESC])
expect(described_class.values.keys).to include(
*%w[PRIORITY_ASC PRIORITY_DESC
LABEL_PRIORITY_ASC LABEL_PRIORITY_DESC
MILESTONE_DUE_ASC MILESTONE_DUE_DESC
])
end
end
......@@ -9,7 +9,7 @@ describe GitlabSchema.types['IssueSort'] do
it 'exposes all the existing issue sort values' do
expect(described_class.values.keys).to include(
*%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC LABEL_PRIORITY_ASC LABEL_PRIORITY_DESC]
*%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC]
)
end
end
......@@ -119,7 +119,21 @@ describe 'getting an issue list for a project' do
describe 'sorting and pagination' do
let(:start_cursor) { graphql_data['project']['issues']['pageInfo']['startCursor'] }
let(:end_cursor) { graphql_data['project']['issues']['pageInfo']['endCursor'] }
let(:end_cursor) { graphql_data['project']['issues']['pageInfo']['endCursor'] }
let(:data_path) { [:project, :issues] }
def pagination_query(params, page_info)
graphql_query_for(
'project',
{ 'fullPath' => sort_project.full_path },
"issues(#{params}) { #{page_info} edges { node { iid dueDate } } }"
)
end
def pagination_results_data(data)
data.map { |issue| issue.dig('node', 'iid').to_i }
end
context 'when sorting by due date' do
let_it_be(:sort_project) { create(:project, :public) }
......@@ -387,6 +401,31 @@ describe 'getting an issue list for a project' do
end
end
end
context 'when sorting by milestone due date' do
let_it_be(:sort_project) { create(:project, :public) }
let_it_be(:early_milestone) { create(:milestone, project: sort_project, due_date: 10.days.from_now) }
let_it_be(:late_milestone) { create(:milestone, project: sort_project, due_date: 30.days.from_now) }
let_it_be(:milestone_issue1) { create(:issue, project: sort_project) }
let_it_be(:milestone_issue2) { create(:issue, project: sort_project, milestone: early_milestone) }
let_it_be(:milestone_issue3) { create(:issue, project: sort_project, milestone: late_milestone) }
context 'when ascending' do
it_behaves_like 'sorted paginated query' do
let(:sort_param) { 'MILESTONE_DUE_ASC' }
let(:first_param) { 2 }
let(:expected_results) { [milestone_issue2.iid, milestone_issue3.iid, milestone_issue1.iid] }
end
end
context 'when descending' do
it_behaves_like 'sorted paginated query' do
let(:sort_param) { 'MILESTONE_DUE_DESC' }
let(:first_param) { 2 }
let(:expected_results) { [milestone_issue3.iid, milestone_issue2.iid, milestone_issue1.iid] }
end
end
end
end
def grab_iids(data = issues_data)
......
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