From 9d96b9eb27efb5b2ca6c2e298be07df6cb42d98f Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 16 Jun 2016 16:27:46 -0500 Subject: Fixes icon state when selecting issues that have the same labels assigned --- app/assets/javascripts/gl_dropdown.js.coffee | 3 +++ app/assets/javascripts/labels_select.js.coffee | 25 ++++++++++++++++++++++ spec/features/issues/bulk_assigment_labels_spec.rb | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index b49bd4565a7..2a8a1f05b35 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -302,6 +302,9 @@ class GitLabDropdown if @options.setIndeterminateIds @options.setIndeterminateIds.call(@) + if @options.setActiveIds + @options.setActiveIds.call(@) + # Makes indeterminate items effective if @fullData and @dropdown.find('.dropdown-menu-toggle').hasClass('js-filter-bulk-update') @parseData @fullData diff --git a/app/assets/javascripts/labels_select.js.coffee b/app/assets/javascripts/labels_select.js.coffee index d350a7c0e7f..6a10db10eb1 100644 --- a/app/assets/javascripts/labels_select.js.coffee +++ b/app/assets/javascripts/labels_select.js.coffee @@ -210,9 +210,21 @@ class @LabelsSelect if $dropdown.hasClass('js-filter-bulk-update') indeterminate = instance.indeterminateIds + active = instance.activeIds + if indeterminate.indexOf(label.id) isnt -1 selectedClass.push 'is-indeterminate' + if active.indexOf(label.id) isnt -1 + # Remove is-indeterminate class if the item will be marked as active + i = selectedClass.indexOf 'is-indeterminate' + selectedClass.splice i, 1 unless i is -1 + + selectedClass.push 'is-active' + + # Add input manually + instance.addInput @fieldName, label.id + if $form.find("input[type='hidden']\ [name='#{$dropdown.data('fieldName')}']\ [value='#{this.id(label)}']").length @@ -328,6 +340,10 @@ class @LabelsSelect setIndeterminateIds: -> if @dropdown.find('.dropdown-menu-toggle').hasClass('js-filter-bulk-update') @indeterminateIds = _this.getIndeterminateIds() + + setActiveIds: -> + if @dropdown.find('.dropdown-menu-toggle').hasClass('js-filter-bulk-update') + @activeIds = _this.getActiveIds() ) @bindEvents() @@ -352,3 +368,12 @@ class @LabelsSelect label_ids.push $("#issue_#{issue_id}").data('labels') _.flatten(label_ids) + + getActiveIds: -> + label_ids = [] + + $('.selected_issue:checked').each (i, el) -> + issue_id = $(el).data('id') + label_ids.push $("#issue_#{issue_id}").data('labels') + + _.intersection.apply _, label_ids diff --git a/spec/features/issues/bulk_assigment_labels_spec.rb b/spec/features/issues/bulk_assigment_labels_spec.rb index 0fbc2062e39..309d2435e28 100644 --- a/spec/features/issues/bulk_assigment_labels_spec.rb +++ b/spec/features/issues/bulk_assigment_labels_spec.rb @@ -190,7 +190,8 @@ feature 'Issues > Labels bulk assignment', feature: true do end if unmark items.map do |item| - click_link item + # Make sure we are unmarking the item no matter the state it has currently + click_link item while find('a', text: item)[:class] == 'label-item' end end end -- cgit v1.2.1