Commit e27a4b3c authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'sy-expose-icon-name' into 'master'

Use server-defined icon for alert system notes

See merge request gitlab-org/gitlab!35902
parents d05d2e09 a846bc27
...@@ -24,7 +24,7 @@ export default { ...@@ -24,7 +24,7 @@ export default {
return { ...author, id: id?.split('/').pop() }; return { ...author, id: id?.split('/').pop() };
}, },
iconHtml() { iconHtml() {
return spriteIcon('user'); return spriteIcon(this.note?.systemNoteIconName);
}, },
}, },
}; };
......
#import "~/graphql_shared/fragments/author.fragment.graphql" #import "~/graphql_shared/fragments/author.fragment.graphql"
fragment AlertNote on Note { fragment AlertNote on Note {
id
author {
id id
author { state
id ...Author
state }
...Author body
} bodyHtml
body createdAt
bodyHtml discussion {
createdAt id
discussion { }
id systemNoteIconName
}
} }
...@@ -27,6 +27,8 @@ module Types ...@@ -27,6 +27,8 @@ module Types
field :system, GraphQL::BOOLEAN_TYPE, field :system, GraphQL::BOOLEAN_TYPE,
null: false, null: false,
description: 'Indicates whether this note was created by the system or by a user' description: 'Indicates whether this note was created by the system or by a user'
field :system_note_icon_name, GraphQL::STRING_TYPE, null: true,
description: 'Name of the icon corresponding to a system note'
field :body, GraphQL::STRING_TYPE, field :body, GraphQL::STRING_TYPE,
null: false, null: false,
...@@ -46,6 +48,10 @@ module Types ...@@ -46,6 +48,10 @@ module Types
field :confidential, GraphQL::BOOLEAN_TYPE, null: true, field :confidential, GraphQL::BOOLEAN_TYPE, null: true,
description: 'Indicates if this note is confidential', description: 'Indicates if this note is confidential',
method: :confidential? method: :confidential?
def system_note_icon_name
SystemNoteHelper.system_note_icon_name(object) if object.system?
end
end end
end end
end end
...@@ -8255,6 +8255,11 @@ type Note implements ResolvableInterface { ...@@ -8255,6 +8255,11 @@ type Note implements ResolvableInterface {
""" """
system: Boolean! system: Boolean!
"""
Name of the icon corresponding to a system note
"""
systemNoteIconName: String
""" """
Timestamp of the note's last activity Timestamp of the note's last activity
""" """
......
...@@ -24601,6 +24601,20 @@ ...@@ -24601,6 +24601,20 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "systemNoteIconName",
"description": "Name of the icon corresponding to a system note",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "updatedAt", "name": "updatedAt",
"description": "Timestamp of the note's last activity", "description": "Timestamp of the note's last activity",
...@@ -1262,6 +1262,7 @@ Contains statistics about a milestone ...@@ -1262,6 +1262,7 @@ Contains statistics about a milestone
| `resolvedAt` | Time | Timestamp of when the object was resolved | | `resolvedAt` | Time | Timestamp of when the object was resolved |
| `resolvedBy` | User | User who resolved the object | | `resolvedBy` | User | User who resolved the object |
| `system` | Boolean! | Indicates whether this note was created by the system or by a user | | `system` | Boolean! | Indicates whether this note was created by the system or by a user |
| `systemNoteIconName` | String | Name of the icon corresponding to a system note |
| `updatedAt` | Time! | Timestamp of the note's last activity | | `updatedAt` | Time! | Timestamp of the note's last activity |
| `userPermissions` | NotePermissions! | Permissions for the current user on the resource | | `userPermissions` | NotePermissions! | Permissions for the current user on the resource |
......
...@@ -159,6 +159,11 @@ FactoryBot.define do ...@@ -159,6 +159,11 @@ FactoryBot.define do
system { true } system { true }
end end
trait :with_system_note_metadata do
system
system_note_metadata
end
trait :downvote do trait :downvote do
note { "thumbsdown" } note { "thumbsdown" }
end end
......
...@@ -28,7 +28,11 @@ describe('Alert Details System Note', () => { ...@@ -28,7 +28,11 @@ describe('Alert Details System Note', () => {
}); });
it('renders the correct system note', () => { it('renders the correct system note', () => {
expect(wrapper.find('.note-wrapper').attributes('id')).toBe('note_1628'); const noteId = wrapper.find('.note-wrapper').attributes('id');
const iconRoute = wrapper.find('use').attributes('href');
expect(noteId).toBe('note_1628');
expect(iconRoute.includes('user')).toBe(true);
}); });
}); });
}); });
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
"name": "Administrator", "name": "Administrator",
"username": "root", "username": "root",
"webUrl": "http://192.168.1.4:3000/root" "webUrl": "http://192.168.1.4:3000/root"
} },
"systemNoteIconName": "user"
} }
] ]
} }
......
...@@ -19,6 +19,7 @@ RSpec.describe GitlabSchema.types['Note'] do ...@@ -19,6 +19,7 @@ RSpec.describe GitlabSchema.types['Note'] do
resolved_at resolved_at
resolved_by resolved_by
system system
system_note_icon_name
updated_at updated_at
user_permissions user_permissions
] ]
......
...@@ -9,8 +9,8 @@ RSpec.describe 'getting Alert Management Alert Notes' do ...@@ -9,8 +9,8 @@ RSpec.describe 'getting Alert Management Alert Notes' do
let_it_be(:current_user) { create(:user) } let_it_be(:current_user) { create(:user) }
let_it_be(:first_alert) { create(:alert_management_alert, project: project, assignees: [current_user]) } let_it_be(:first_alert) { create(:alert_management_alert, project: project, assignees: [current_user]) }
let_it_be(:second_alert) { create(:alert_management_alert, project: project) } let_it_be(:second_alert) { create(:alert_management_alert, project: project) }
let_it_be(:first_system_note) { create(:note_on_alert, noteable: first_alert, project: project) } let_it_be(:first_system_note) { create(:note_on_alert, :with_system_note_metadata, noteable: first_alert, project: project) }
let_it_be(:second_system_note) { create(:note_on_alert, noteable: first_alert, project: project) } let_it_be(:second_system_note) { create(:note_on_alert, :with_system_note_metadata, noteable: first_alert, project: project) }
let(:params) { {} } let(:params) { {} }
...@@ -21,6 +21,8 @@ RSpec.describe 'getting Alert Management Alert Notes' do ...@@ -21,6 +21,8 @@ RSpec.describe 'getting Alert Management Alert Notes' do
notes { notes {
nodes { nodes {
id id
body
systemNoteIconName
} }
} }
} }
...@@ -44,7 +46,17 @@ RSpec.describe 'getting Alert Management Alert Notes' do ...@@ -44,7 +46,17 @@ RSpec.describe 'getting Alert Management Alert Notes' do
project.add_developer(current_user) project.add_developer(current_user)
end end
it 'returns the notes ordered by createdAt' do it 'includes expected data' do
post_graphql(query, current_user: current_user)
expect(first_notes_result.first).to include(
'id' => first_system_note.to_global_id.to_s,
'systemNoteIconName' => 'git-merge',
'body' => first_system_note.note
)
end
it 'returns the notes ordered by createdAt with sufficient content' do
post_graphql(query, current_user: current_user) post_graphql(query, current_user: current_user)
expect(first_notes_result.length).to eq(2) expect(first_notes_result.length).to eq(2)
...@@ -64,4 +76,18 @@ RSpec.describe 'getting Alert Management Alert Notes' do ...@@ -64,4 +76,18 @@ RSpec.describe 'getting Alert Management Alert Notes' do
expect { post_graphql(query, current_user: current_user) }.not_to exceed_query_limit(base_count) expect { post_graphql(query, current_user: current_user) }.not_to exceed_query_limit(base_count)
expect(alerts_result.length).to eq(3) expect(alerts_result.length).to eq(3)
end end
context 'for non-system notes' do
let_it_be(:user_note) { create(:note_on_alert, noteable: second_alert, project: project) }
it 'includes expected data' do
post_graphql(query, current_user: current_user)
expect(second_notes_result.first).to include(
'id' => user_note.to_global_id.to_s,
'systemNoteIconName' => nil,
'body' => user_note.note
)
end
end
end end
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