summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/gfm_auto_complete.js.es66
-rw-r--r--app/controllers/projects_controller.rb4
-rw-r--r--app/services/projects/autocomplete_service.rb9
-rw-r--r--changelogs/unreleased/22680-unlabel-limit-autocomplete-to-selected-items.yml4
4 files changed, 21 insertions, 2 deletions
diff --git a/app/assets/javascripts/gfm_auto_complete.js.es6 b/app/assets/javascripts/gfm_auto_complete.js.es6
index e72e2194be8..3101b306080 100644
--- a/app/assets/javascripts/gfm_auto_complete.js.es6
+++ b/app/assets/javascripts/gfm_auto_complete.js.es6
@@ -51,6 +51,11 @@
if (!GitLab.GfmAutoComplete.dataLoaded) {
return this.at;
} else {
+ if (value.indexOf("unlabel") !== -1) {
+ GitLab.GfmAutoComplete.input.atwho('load', '~', GitLab.GfmAutoComplete.cachedData.unlabels);
+ } else {
+ GitLab.GfmAutoComplete.input.atwho('load', '~', GitLab.GfmAutoComplete.cachedData.labels);
+ }
return value;
}
}
@@ -352,3 +357,4 @@
};
}).call(this);
+
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index a8a18b4fa16..7376c2bfeb7 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -144,13 +144,15 @@ class ProjectsController < Projects::ApplicationController
autocomplete = ::Projects::AutocompleteService.new(@project, current_user)
participants = ::Projects::ParticipantsService.new(@project, current_user).execute(noteable)
+ unlabels = autocomplete.unlabels(noteable)
@suggestions = {
emojis: Gitlab::AwardEmoji.urls,
issues: autocomplete.issues,
milestones: autocomplete.milestones,
mergerequests: autocomplete.merge_requests,
- labels: autocomplete.labels,
+ labels: autocomplete.labels - unlabels,
+ unlabels: unlabels,
members: participants,
commands: autocomplete.commands(noteable, params[:type])
}
diff --git a/app/services/projects/autocomplete_service.rb b/app/services/projects/autocomplete_service.rb
index 015f2828921..223461e88b6 100644
--- a/app/services/projects/autocomplete_service.rb
+++ b/app/services/projects/autocomplete_service.rb
@@ -13,7 +13,14 @@ module Projects
end
def labels
- LabelsFinder.new(current_user, project_id: project.id).execute.select([:title, :color])
+ LabelsFinder.new(current_user, project_id: project.id).execute.
+ pluck(:title, :color).map { |l| { title: l.first, color: l.second } }
+ end
+
+ def unlabels(noteable)
+ return [] unless noteable && noteable.respond_to?(:labels)
+
+ noteable.labels.pluck(:title, :color).map { |l| { title: l.first, color: l.second } }
end
def commands(noteable, type)
diff --git a/changelogs/unreleased/22680-unlabel-limit-autocomplete-to-selected-items.yml b/changelogs/unreleased/22680-unlabel-limit-autocomplete-to-selected-items.yml
new file mode 100644
index 00000000000..95fd07c12e1
--- /dev/null
+++ b/changelogs/unreleased/22680-unlabel-limit-autocomplete-to-selected-items.yml
@@ -0,0 +1,4 @@
+---
+title: Limit autocomplete to currently selected items for unlabel slash command
+merge_request: 22680
+author: Akram Fares