From 02ce5fba8d7aa94d5fb53bd717e77c93c6bd61b7 Mon Sep 17 00:00:00 2001
From: Alfredo Sumaran <alfredo@gitlab.com>
Date: Sun, 17 Jul 2016 02:34:46 -0500
Subject: [PATCH] Fixes preselected label

---
 app/views/shared/issuable/_filter.html.haml    |  2 +-
 .../shared/issuable/_label_dropdown.html.haml  | 18 +++++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/app/views/shared/issuable/_filter.html.haml b/app/views/shared/issuable/_filter.html.haml
index be8248876b4..1a0f1fff056 100644
--- a/app/views/shared/issuable/_filter.html.haml
+++ b/app/views/shared/issuable/_filter.html.haml
@@ -24,7 +24,7 @@
           = render "shared/issuable/milestone_dropdown", selected: params[:milestone_title], name: :milestone_title, show_any: true, show_upcoming: true
 
         .filter-item.inline.labels-filter
-          = render "shared/issuable/label_dropdown", selected: params[:label_name], data_options: { field_name: "label_name[]" }
+          = render "shared/issuable/label_dropdown", selected_toggle: params[:label_name], data_options: { field_name: "label_name[]" }
 
         .pull-right
           = render 'shared/sort_dropdown'
diff --git a/app/views/shared/issuable/_label_dropdown.html.haml b/app/views/shared/issuable/_label_dropdown.html.haml
index 6518f448253..113447d48b7 100644
--- a/app/views/shared/issuable/_label_dropdown.html.haml
+++ b/app/views/shared/issuable/_label_dropdown.html.haml
@@ -13,16 +13,20 @@
 - classes << 'js-filter-submit' if filter_submit
 
 - if selected.present?
-  - if selected.respond_to?('any?')
-    - selected = project.labels.where(id: selected) || selected
-    - selected.each do |label|
-      - id = label.try(:id) || label
-      - title = label.try(:title) || label
-      = hidden_field_tag data_options[:field_name], id, id: nil, data: { title: title }
+  - labelQuery = { id: selected }
+  - useId = true
+- if selected_toggle.present?
+  - labelQuery = { title: selected_toggle }
+- if labelQuery
+  - selected = project.labels.where(labelQuery)
+  - selected.each do |label|
+    - id = label.try(:id) || label
+    - title = label.try(:title) || label
+    = hidden_field_tag data_options[:field_name], useId ? id : title, id: nil, data: { title: title }
 .dropdown
   %button.dropdown-menu-toggle.js-label-select.js-multiselect{class: classes.join(' '), type: "button", data: dropdown_data}
     %span.dropdown-toggle-text{ class: ("is-default" if selected.nil?) }
-      = h(multi_label_name(selected_toggle || selected, "Label"))
+      = h(multi_label_name(selected.to_a, "Label"))
     = icon('chevron-down')
   .dropdown-menu.dropdown-select.dropdown-menu-paging.dropdown-menu-labels.dropdown-menu-selectable
     = render partial: "shared/issuable/label_page_default", locals: { title: "Filter by label", show_footer: show_footer, show_create: show_create }
-- 
GitLab