Fixed label dropdown bugs with pre-selecting the toggle label
This commit is contained in:
parent
bf1d0cbeae
commit
3582861cbc
5 changed files with 13 additions and 8 deletions
|
@ -293,6 +293,7 @@ class @LabelsSelect
|
||||||
else if selectedLabels.length is 1
|
else if selectedLabels.length is 1
|
||||||
selectedLabels[0]
|
selectedLabels[0]
|
||||||
else
|
else
|
||||||
|
console.log selectedLabels.length, defaultLabel
|
||||||
defaultLabel
|
defaultLabel
|
||||||
defaultLabel: defaultLabel
|
defaultLabel: defaultLabel
|
||||||
fieldName: $dropdown.data('field-name')
|
fieldName: $dropdown.data('field-name')
|
||||||
|
|
|
@ -10,10 +10,11 @@ module IssuablesHelper
|
||||||
def multi_label_name(current_labels, default_label)
|
def multi_label_name(current_labels, default_label)
|
||||||
# current_labels may be a string from before
|
# current_labels may be a string from before
|
||||||
if current_labels.is_a?(Array) && current_labels.any?
|
if current_labels.is_a?(Array) && current_labels.any?
|
||||||
|
title = current_labels[0].try(:title) || current_labels[0]
|
||||||
if current_labels.count > 1
|
if current_labels.count > 1
|
||||||
"#{current_labels[0]} +#{current_labels.count - 1} more"
|
"#{title} +#{current_labels.count - 1} more"
|
||||||
else
|
else
|
||||||
current_labels[0]
|
title
|
||||||
end
|
end
|
||||||
elsif current_labels.is_a?(String)
|
elsif current_labels.is_a?(String)
|
||||||
if current_labels.nil? || current_labels.empty?
|
if current_labels.nil? || current_labels.empty?
|
||||||
|
|
|
@ -14,9 +14,11 @@
|
||||||
|
|
||||||
- if selected.present?
|
- if selected.present?
|
||||||
- if selected.respond_to?('any?')
|
- if selected.respond_to?('any?')
|
||||||
- selected = project.labels.find(selected)
|
- selected = project.labels.find_by_id(selected) || selected
|
||||||
- selected.each do |label|
|
- selected.each do |label|
|
||||||
= hidden_field_tag data_options[:field_name], label.id, id: nil, data: { title: label.title }
|
- id = label.try(:id) || label
|
||||||
|
- title = label.try(:title) || label
|
||||||
|
= hidden_field_tag data_options[:field_name], id, id: nil, data: { title: title }
|
||||||
.dropdown
|
.dropdown
|
||||||
%button.dropdown-menu-toggle.js-label-select.js-multiselect{class: classes.join(' '), type: "button", data: dropdown_data}
|
%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?) }
|
%span.dropdown-toggle-text{ class: ("is-default" if selected.nil?) }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
- project = @target_project || @project
|
- project = @target_project || @project
|
||||||
|
- extra_class = extra_class || ''
|
||||||
- selected_text = project.milestones.find_by_id(selected).try(:name)
|
- selected_text = project.milestones.find_by_id(selected).try(:name)
|
||||||
- if selected.present?
|
- if selected.present?
|
||||||
= hidden_field_tag(name, selected)
|
= hidden_field_tag(name, selected)
|
||||||
|
|
|
@ -126,11 +126,11 @@
|
||||||
%span.no-value None
|
%span.no-value None
|
||||||
.selectbox.hide-collapsed
|
.selectbox.hide-collapsed
|
||||||
- issuable.labels_array.each do |label|
|
- issuable.labels_array.each do |label|
|
||||||
= hidden_field_tag "#{issuable.to_ability_name}[label_names][]", label.id, id: nil
|
= hidden_field_tag "#{issuable.to_ability_name}[label_names][]", label.id, id: nil, data: { title: label.title }
|
||||||
.dropdown
|
.dropdown
|
||||||
%button.dropdown-menu-toggle.js-label-select.js-multiselect{type: "button", data: {toggle: "dropdown", field_name: "#{issuable.to_ability_name}[label_names][]", ability_name: issuable.to_ability_name, show_no: "true", show_any: "true", project_id: (@project.id if @project), issue_update: issuable_json_path(issuable), labels: (namespace_project_labels_path(@project.namespace, @project, :json) if @project)}}
|
%button.dropdown-menu-toggle.js-label-select.js-multiselect{type: "button", data: {toggle: "dropdown", default_label: "Labels", field_name: "#{issuable.to_ability_name}[label_names][]", ability_name: issuable.to_ability_name, show_no: "true", show_any: "true", project_id: (@project.id if @project), issue_update: issuable_json_path(issuable), labels: (namespace_project_labels_path(@project.namespace, @project, :json) if @project)}}
|
||||||
%span.dropdown-toggle-text
|
%span.dropdown-toggle-text{ class: ("is-default" if issuable.labels_array.empty?)}
|
||||||
Label
|
= multi_label_name(issuable.labels_array, "Labels")
|
||||||
= icon('chevron-down')
|
= icon('chevron-down')
|
||||||
.dropdown-menu.dropdown-select.dropdown-menu-paging.dropdown-menu-labels.dropdown-menu-selectable
|
.dropdown-menu.dropdown-select.dropdown-menu-paging.dropdown-menu-labels.dropdown-menu-selectable
|
||||||
= render partial: "shared/issuable/label_page_default"
|
= render partial: "shared/issuable/label_page_default"
|
||||||
|
|
Loading…
Reference in a new issue