Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Eastwood <contact@ericeastwood.com>2018-01-18 11:02:21 +0300
committerEric Eastwood <contact@ericeastwood.com>2018-01-19 08:04:50 +0300
commitea04d1ab3a77f737181ddf84de840330158bbf89 (patch)
tree9b94ab3f41765095513b507a7ad206234f48149f /app/assets/javascripts/create_item_dropdown.js
parent5392568e1eb3f666280a6c6f329a8ed2afcbd7d8 (diff)
Fix duplicate item in protected branch/tag dropdown
Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/42157 Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/41989
Diffstat (limited to 'app/assets/javascripts/create_item_dropdown.js')
-rw-r--r--app/assets/javascripts/create_item_dropdown.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/assets/javascripts/create_item_dropdown.js b/app/assets/javascripts/create_item_dropdown.js
index c3eceb285f5..488db023ee7 100644
--- a/app/assets/javascripts/create_item_dropdown.js
+++ b/app/assets/javascripts/create_item_dropdown.js
@@ -65,7 +65,17 @@ export default class CreateItemDropdown {
getData(term, callback) {
this.getDataOption(term, (data = []) => {
- callback(data.concat(this.selectedItem || []));
+ // Ensure the selected item isn't already in the data to avoid duplicates
+ const alreadyHasSelectedItem = this.selectedItem && data.some(item =>
+ item.id === this.selectedItem.id,
+ );
+
+ let uniqueData = data;
+ if (!alreadyHasSelectedItem) {
+ uniqueData = data.concat(this.selectedItem || []);
+ }
+
+ callback(uniqueData);
});
}