Commit c6ad4822 authored by Coung Ngo's avatar Coung Ngo

Add snippets autocomplete to tribute

We are migrating from jQuery-based at.js to tribute behind
the feature flag :tribute_autocomplete. This commit
adds snippets autocomplete to tribute.
parent 8188bc2d
...@@ -11,6 +11,7 @@ const AutoComplete = { ...@@ -11,6 +11,7 @@ const AutoComplete = {
Members: 'members', Members: 'members',
MergeRequests: 'mergeRequests', MergeRequests: 'mergeRequests',
Milestones: 'milestones', Milestones: 'milestones',
Snippets: 'snippets',
}; };
const groupType = 'Group'; // eslint-disable-line @gitlab/require-i18n-strings const groupType = 'Group'; // eslint-disable-line @gitlab/require-i18n-strings
...@@ -129,6 +130,14 @@ const autoCompleteMap = { ...@@ -129,6 +130,14 @@ const autoCompleteMap = {
return escape(original.title); return escape(original.title);
}, },
}, },
[AutoComplete.Snippets]: {
filterValues() {
return this[AutoComplete.Snippets];
},
menuItemTemplate({ original }) {
return `<small>${original.id}</small> ${escape(original.title)}`;
},
},
}; };
export default { export default {
...@@ -184,6 +193,13 @@ export default { ...@@ -184,6 +193,13 @@ export default {
selectTemplate: ({ original }) => `%"${escape(original.title)}"`, selectTemplate: ({ original }) => `%"${escape(original.title)}"`,
values: this.getValues(AutoComplete.Milestones), values: this.getValues(AutoComplete.Milestones),
}, },
{
trigger: '$',
fillAttr: 'id',
lookup: value => value.id + value.title,
menuItemTemplate: autoCompleteMap[AutoComplete.Snippets].menuItemTemplate,
values: this.getValues(AutoComplete.Snippets),
},
], ],
}); });
......
...@@ -177,7 +177,7 @@ export default { ...@@ -177,7 +177,7 @@ export default {
epics: this.enableAutocomplete, epics: this.enableAutocomplete,
milestones: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete, milestones: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete,
labels: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete, labels: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete,
snippets: this.enableAutocomplete, snippets: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete,
}, },
true, true,
); );
......
...@@ -814,6 +814,13 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -814,6 +814,13 @@ RSpec.describe 'GFM autocomplete', :js do
end end
end end
context 'issues' do
let(:object) { issue }
let(:expected_body) { object.to_reference }
it_behaves_like 'autocomplete suggestions'
end
context 'merge requests' do context 'merge requests' do
let(:object) { create(:merge_request, source_project: project) } let(:object) { create(:merge_request, source_project: project) }
let(:expected_body) { object.to_reference } let(:expected_body) { object.to_reference }
...@@ -821,6 +828,27 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -821,6 +828,27 @@ RSpec.describe 'GFM autocomplete', :js do
it_behaves_like 'autocomplete suggestions' it_behaves_like 'autocomplete suggestions'
end end
context 'project snippets' do
let!(:object) { create(:project_snippet, project: project, title: 'code snippet') }
let(:expected_body) { object.to_reference }
it_behaves_like 'autocomplete suggestions'
end
context 'label' do
let!(:object) { label }
let(:expected_body) { object.title }
it_behaves_like 'autocomplete suggestions'
end
context 'milestone' do
let!(:object) { create(:milestone, project: project) }
let(:expected_body) { object.to_reference }
it_behaves_like 'autocomplete suggestions'
end
context 'when other notes are destroyed' do context 'when other notes are destroyed' do
let!(:discussion) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) } let!(:discussion) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) }
......
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