Commit 3e4b0007 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch '229534-incident-sorting-backend' into 'master'

Add severity and published sorting for incidents

See merge request gitlab-org/gitlab!42800
parents bcc3eddf 9cbaa6da
......@@ -8,6 +8,8 @@ module Types
value 'DUE_DATE_ASC', 'Due date by ascending order', value: :due_date_asc
value 'DUE_DATE_DESC', 'Due date by descending order', value: :due_date_desc
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_DESC', 'Severity from more critical to less critical', value: :severity_desc
end
end
......
......@@ -5,9 +5,16 @@ module Types
graphql_name 'Sort'
description 'Common sort values'
# Deprecated, as we prefer uppercase enums
# https://gitlab.com/groups/gitlab-org/-/epics/1838
value 'updated_desc', 'Updated at descending order'
value 'updated_asc', 'Updated at ascending order'
value 'created_desc', 'Created at descending order'
value 'created_asc', 'Created at ascending order'
value 'UPDATED_DESC', 'Updated at descending order', value: :updated_desc
value 'UPDATED_ASC', 'Updated at ascending order', value: :updated_asc
value 'CREATED_DESC', 'Created at descending order', value: :created_desc
value 'CREATED_ASC', 'Created at ascending order', value: :created_asc
end
end
......@@ -101,6 +101,8 @@ class Issue < ApplicationRecord
scope :order_relative_position_asc, -> { reorder(::Gitlab::Database.nulls_last_order('relative_position', 'ASC')) }
scope :order_closed_date_desc, -> { reorder(closed_at: :desc) }
scope :order_created_at_desc, -> { reorder(created_at: :desc) }
scope :order_severity_asc, -> { includes(:issuable_severity).order('issuable_severities.severity ASC NULLS FIRST') }
scope :order_severity_desc, -> { includes(:issuable_severity).order('issuable_severities.severity DESC NULLS LAST') }
scope :preload_associated_models, -> { preload(:assignees, :labels, project: :namespace) }
scope :with_web_entity_associations, -> { preload(:author, :project) }
......@@ -232,6 +234,8 @@ class Issue < ApplicationRecord
when 'due_date', 'due_date_asc' then order_due_date_asc.with_order_id_desc
when 'due_date_desc' then order_due_date_desc.with_order_id_desc
when 'relative_position', 'relative_position_asc' then order_relative_position_asc.with_order_id_desc
when 'severity_asc' then order_severity_asc.with_order_id_desc
when 'severity_desc' then order_severity_desc.with_order_id_desc
else
super
end
......
---
title: Add severity and published sorting for incident issues
merge_request: 42800
author:
type: added
......@@ -434,6 +434,16 @@ type AlertManagementAlertEdge {
Values for sorting alerts
"""
enum AlertManagementAlertSort {
"""
Created at ascending order
"""
CREATED_ASC
"""
Created at descending order
"""
CREATED_DESC
"""
Created time by ascending order
"""
......@@ -494,6 +504,16 @@ enum AlertManagementAlertSort {
"""
STATUS_DESC
"""
Updated at ascending order
"""
UPDATED_ASC
"""
Updated at descending order
"""
UPDATED_DESC
"""
Created time by ascending order
"""
......@@ -8712,6 +8732,16 @@ type IssueSetWeightPayload {
Values for sorting issues
"""
enum IssueSort {
"""
Created at ascending order
"""
CREATED_ASC
"""
Created at descending order
"""
CREATED_DESC
"""
Due date by ascending order
"""
......@@ -8752,11 +8782,41 @@ enum IssueSort {
"""
PRIORITY_DESC
"""
Published issues shown last
"""
PUBLISHED_ASC
"""
Published issues shown first
"""
PUBLISHED_DESC
"""
Relative position by ascending order
"""
RELATIVE_POSITION_ASC
"""
Severity from less critical to more critical
"""
SEVERITY_ASC
"""
Severity from more critical to less critical
"""
SEVERITY_DESC
"""
Updated at ascending order
"""
UPDATED_ASC
"""
Updated at descending order
"""
UPDATED_DESC
"""
Weight by ascending order
"""
......@@ -10488,6 +10548,16 @@ type MergeRequestSetWipPayload {
Values for sorting merge requests
"""
enum MergeRequestSort {
"""
Created at ascending order
"""
CREATED_ASC
"""
Created at descending order
"""
CREATED_DESC
"""
Label priority by ascending order
"""
......@@ -10528,6 +10598,16 @@ enum MergeRequestSort {
"""
PRIORITY_DESC
"""
Updated at ascending order
"""
UPDATED_ASC
"""
Updated at descending order
"""
UPDATED_DESC
"""
Created at ascending order
"""
......@@ -16761,6 +16841,26 @@ type SnippetPermissions {
Common sort values
"""
enum Sort {
"""
Created at ascending order
"""
CREATED_ASC
"""
Created at descending order
"""
CREATED_DESC
"""
Updated at ascending order
"""
UPDATED_ASC
"""
Updated at descending order
"""
UPDATED_DESC
"""
Created at ascending order
"""
......
......@@ -1248,6 +1248,30 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "UPDATED_DESC",
"description": "Updated at descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "UPDATED_ASC",
"description": "Updated at ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CREATED_DESC",
"description": "Created at descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CREATED_ASC",
"description": "Created at ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "STARTED_AT_ASC",
"description": "Start time by ascending order",
......@@ -24108,6 +24132,30 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "UPDATED_DESC",
"description": "Updated at descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "UPDATED_ASC",
"description": "Updated at ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CREATED_DESC",
"description": "Created at descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CREATED_ASC",
"description": "Created at ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "PRIORITY_ASC",
"description": "Priority by ascending order",
......@@ -24162,6 +24210,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "SEVERITY_ASC",
"description": "Severity from less critical to more critical",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "SEVERITY_DESC",
"description": "Severity from more critical to less critical",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "WEIGHT_ASC",
"description": "Weight by ascending order",
......@@ -24173,6 +24233,18 @@
"description": "Weight by descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "PUBLISHED_ASC",
"description": "Published issues shown last",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "PUBLISHED_DESC",
"description": "Published issues shown first",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
......@@ -29154,6 +29226,30 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "UPDATED_DESC",
"description": "Updated at descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "UPDATED_ASC",
"description": "Updated at ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CREATED_DESC",
"description": "Created at descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CREATED_ASC",
"description": "Created at ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "PRIORITY_ASC",
"description": "Priority by ascending order",
......@@ -49085,6 +49181,30 @@
"description": "Created at ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "UPDATED_DESC",
"description": "Updated at descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "UPDATED_ASC",
"description": "Updated at ascending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CREATED_DESC",
"description": "Created at descending order",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "CREATED_ASC",
"description": "Created at ascending order",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
......@@ -2935,6 +2935,8 @@ Values for sorting alerts.
| Value | Description |
| ----- | ----------- |
| `CREATED_ASC` | Created at ascending order |
| `CREATED_DESC` | Created at descending order |
| `CREATED_TIME_ASC` | Created time by ascending order |
| `CREATED_TIME_DESC` | Created time by descending order |
| `ENDED_AT_ASC` | End time by ascending order |
......@@ -2947,6 +2949,8 @@ Values for sorting alerts.
| `STARTED_AT_DESC` | Start time by descending order |
| `STATUS_ASC` | Status by order: Ignored > Resolved > Acknowledged > Triggered |
| `STATUS_DESC` | Status by order: Triggered > Acknowledged > Resolved > Ignored |
| `UPDATED_ASC` | Updated at ascending order |
| `UPDATED_DESC` | Updated at descending order |
| `UPDATED_TIME_ASC` | Created time by ascending order |
| `UPDATED_TIME_DESC` | Created time by descending order |
| `created_asc` | Created at ascending order |
......@@ -3170,6 +3174,8 @@ Values for sorting issues.
| Value | Description |
| ----- | ----------- |
| `CREATED_ASC` | Created at ascending order |
| `CREATED_DESC` | Created at descending order |
| `DUE_DATE_ASC` | Due date by ascending order |
| `DUE_DATE_DESC` | Due date by descending order |
| `LABEL_PRIORITY_ASC` | Label priority by ascending order |
......@@ -3178,7 +3184,13 @@ Values for sorting issues.
| `MILESTONE_DUE_DESC` | Milestone due date by descending order |
| `PRIORITY_ASC` | Priority by ascending order |
| `PRIORITY_DESC` | Priority by descending order |
| `PUBLISHED_ASC` | Published issues shown last |
| `PUBLISHED_DESC` | Published issues shown first |
| `RELATIVE_POSITION_ASC` | Relative position by ascending order |
| `SEVERITY_ASC` | Severity from less critical to more critical |
| `SEVERITY_DESC` | Severity from more critical to less critical |
| `UPDATED_ASC` | Updated at ascending order |
| `UPDATED_DESC` | Updated at descending order |
| `WEIGHT_ASC` | Weight by ascending order |
| `WEIGHT_DESC` | Weight by descending order |
| `created_asc` | Created at ascending order |
......@@ -3252,6 +3264,8 @@ Values for sorting merge requests.
| Value | Description |
| ----- | ----------- |
| `CREATED_ASC` | Created at ascending order |
| `CREATED_DESC` | Created at descending order |
| `LABEL_PRIORITY_ASC` | Label priority by ascending order |
| `LABEL_PRIORITY_DESC` | Label priority by descending order |
| `MERGED_AT_ASC` | Merge time by ascending order |
......@@ -3260,6 +3274,8 @@ Values for sorting merge requests.
| `MILESTONE_DUE_DESC` | Milestone due date by descending order |
| `PRIORITY_ASC` | Priority by ascending order |
| `PRIORITY_DESC` | Priority by descending order |
| `UPDATED_ASC` | Updated at ascending order |
| `UPDATED_DESC` | Updated at descending order |
| `created_asc` | Created at ascending order |
| `created_desc` | Created at descending order |
| `updated_asc` | Updated at ascending order |
......@@ -3488,6 +3504,10 @@ Common sort values.
| Value | Description |
| ----- | ----------- |
| `CREATED_ASC` | Created at ascending order |
| `CREATED_DESC` | Created at descending order |
| `UPDATED_ASC` | Updated at ascending order |
| `UPDATED_DESC` | Updated at descending order |
| `created_asc` | Created at ascending order |
| `created_desc` | Created at descending order |
| `updated_asc` | Updated at ascending order |
......
......@@ -8,6 +8,8 @@ module EE
prepended do
value 'WEIGHT_ASC', 'Weight by ascending order', value: 'weight_asc'
value 'WEIGHT_DESC', 'Weight by descending order', value: 'weight_desc'
value 'PUBLISHED_ASC', 'Published issues shown last', value: :published_asc
value 'PUBLISHED_DESC', 'Published issues shown first', value: :published_desc
end
end
end
......
......@@ -21,6 +21,8 @@ module EE
scope :order_blocking_issues_desc, -> { reorder(blocking_issues_count: :desc) }
scope :order_weight_desc, -> { reorder ::Gitlab::Database.nulls_last_order('weight', 'DESC') }
scope :order_weight_asc, -> { reorder ::Gitlab::Database.nulls_last_order('weight') }
scope :order_status_page_published_first, -> { includes(:status_page_published_incident).order('status_page_published_incidents.id ASC NULLS LAST') }
scope :order_status_page_published_last, -> { includes(:status_page_published_incident).order('status_page_published_incidents.id ASC NULLS FIRST') }
scope :no_epic, -> { left_outer_joins(:epic_issue).where(epic_issues: { epic_id: nil }) }
scope :any_epic, -> { joins(:epic_issue) }
scope :in_epics, ->(epics) { joins(:epic_issue).where(epic_issues: { epic_id: epics }) }
......@@ -184,6 +186,8 @@ module EE
when 'blocking_issues_desc' then order_blocking_issues_desc.with_order_id_desc
when 'weight', 'weight_asc' then order_weight_asc.with_order_id_desc
when 'weight_desc' then order_weight_desc.with_order_id_desc
when 'published_asc' then order_status_page_published_last.with_order_id_desc
when 'published_desc' then order_status_page_published_first.with_order_id_desc
else
super
end
......
......@@ -30,6 +30,19 @@ RSpec.describe Resolvers::IssuesResolver do
expect(resolve_issues(sort: :weight_desc)).to eq [weight_issue1, weight_issue3, weight_issue4, weight_issue2]
end
end
context 'when sorting by published' do
let_it_be(:not_published) { create(:issue, project: project) }
let_it_be(:published) { create(:issue, :published, project: project) }
it 'sorts issues ascending' do
expect(resolve_issues(sort: :published_asc)).to eq [not_published, published]
end
it 'sorts issues descending' do
expect(resolve_issues(sort: :published_desc)).to eq [published, not_published]
end
end
end
describe 'filtering by iteration' do
......
......@@ -8,6 +8,6 @@ RSpec.describe GitlabSchema.types['IssueSort'] do
it_behaves_like 'common sort values'
it 'exposes all the existing EE issue sort values' do
expect(described_class.values.keys).to include(*%w[WEIGHT_ASC WEIGHT_DESC])
expect(described_class.values.keys).to include(*%w[WEIGHT_ASC WEIGHT_DESC PUBLISHED_ASC PUBLISHED_DESC])
end
end
......@@ -182,6 +182,23 @@ RSpec.describe Issue do
end
end
end
context 'status page published' do
let_it_be(:not_published) { create(:issue) }
let_it_be(:published) { create(:issue, :published) }
describe '.order_status_page_published_first' do
subject { described_class.order_status_page_published_first }
it { is_expected.to eq([published, not_published]) }
end
describe '.order_status_page_published_last' do
subject { described_class.order_status_page_published_last }
it { is_expected.to eq([not_published, published]) }
end
end
end
describe 'validations' do
......
......@@ -223,6 +223,21 @@ RSpec.describe Resolvers::IssuesResolver do
expect(resolve_issues(sort: :milestone_due_desc).items).to eq([milestone_issue3, milestone_issue2, milestone_issue1])
end
end
context 'when sorting by severity' do
let_it_be(:project) { create(:project) }
let_it_be(:issue_high_severity) { create_issue_with_severity(project, severity: :high) }
let_it_be(:issue_low_severity) { create_issue_with_severity(project, severity: :low) }
let_it_be(:issue_no_severity) { create(:incident, project: project) }
it 'sorts issues ascending' do
expect(resolve_issues(sort: :severity_asc)).to eq([issue_no_severity, issue_low_severity, issue_high_severity])
end
it 'sorts issues descending' do
expect(resolve_issues(sort: :severity_desc)).to eq([issue_high_severity, issue_low_severity, issue_no_severity])
end
end
end
it 'returns issues user can see' do
......@@ -308,6 +323,13 @@ RSpec.describe Resolvers::IssuesResolver do
expect(field.to_graphql.complexity.call({}, { labelName: 'foo' }, 1)).to eq 8
end
def create_issue_with_severity(project, severity:)
issue = create(:incident, project: project)
create(:issuable_severity, issue: issue, severity: severity)
issue
end
def resolve_issues(args = {}, context = { current_user: current_user })
resolve(described_class, obj: project, args: args, ctx: context)
end
......
......@@ -9,7 +9,7 @@ RSpec.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]
*%w[DUE_DATE_ASC DUE_DATE_DESC RELATIVE_POSITION_ASC SEVERITY_ASC SEVERITY_DESC]
)
end
end
......@@ -145,6 +145,24 @@ RSpec.describe Issue do
end
end
describe '.order_severity' do
let_it_be(:issue_high_severity) { create(:issuable_severity, severity: :high).issue }
let_it_be(:issue_low_severity) { create(:issuable_severity, severity: :low).issue }
let_it_be(:issue_no_severity) { create(:incident) }
context 'sorting ascending' do
subject { described_class.order_severity_asc }
it { is_expected.to eq([issue_no_severity, issue_low_severity, issue_high_severity]) }
end
context 'sorting descending' do
subject { described_class.order_severity_desc }
it { is_expected.to eq([issue_high_severity, issue_low_severity, issue_no_severity]) }
end
end
describe '#order_by_position_and_priority' do
let(:project) { reusable_project }
let(:p1) { create(:label, title: 'P1', project: project, priority: 1) }
......
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