diff options
author | Mike Greiling <mike@pixelcog.com> | 2018-08-07 19:29:53 +0000 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2018-08-07 19:29:53 +0000 |
commit | 9814c646ff872fb29a2390196c116a9a41c0f258 (patch) | |
tree | f32b9c9e031e914765b02640a60235d387eedfe2 | |
parent | 821f1a6496db422d339bb413874a5dac6fa112cd (diff) | |
parent | 0b3ff7267c147bb490acaef9c6054c19ced4c637 (diff) | |
download | gitlab-ce-9814c646ff872fb29a2390196c116a9a41c0f258.tar.gz |
Merge branch '44127-board-label-edit-drop-down-is-showing-incorrect-selected-labels-summary' into 'master'
Resolve "Board label edit drop down is showing incorrect selected labels summary"
Closes #44127
See merge request gitlab-org/gitlab-ce!20673
5 files changed, 34 insertions, 6 deletions
diff --git a/app/assets/javascripts/boards/components/board_sidebar.js b/app/assets/javascripts/boards/components/board_sidebar.js index 371be109229..a9102743bf9 100644 --- a/app/assets/javascripts/boards/components/board_sidebar.js +++ b/app/assets/javascripts/boards/components/board_sidebar.js @@ -51,6 +51,16 @@ gl.issueBoards.BoardSidebar = Vue.extend({ canRemove() { return !this.list.preset; }, + hasLabels() { + return this.issue.labels && this.issue.labels.length; + }, + labelDropdownTitle() { + return this.hasLabels ? + `${this.issue.labels[0].title} ${this.issue.labels.length - 1}+ more` : 'Label'; + }, + selectedLabels() { + return this.hasLabels ? this.issue.labels.map(l => l.title).join(',') : ''; + } }, watch: { detail: { diff --git a/app/assets/javascripts/gl_dropdown.js b/app/assets/javascripts/gl_dropdown.js index cbc05b229cb..c3959ef3e9e 100644 --- a/app/assets/javascripts/gl_dropdown.js +++ b/app/assets/javascripts/gl_dropdown.js @@ -616,7 +616,11 @@ GitLabDropdown = (function() { } if (this.options.opened) { - this.options.opened.call(this, e); + if (this.options.preserveContext) { + this.options.opened(e); + } else { + this.options.opened.call(this, e); + } } return this.dropdown.trigger('shown.gl.dropdown'); diff --git a/app/assets/javascripts/labels_select.js b/app/assets/javascripts/labels_select.js index 37a45d1d1a2..cb851ff6745 100644 --- a/app/assets/javascripts/labels_select.js +++ b/app/assets/javascripts/labels_select.js @@ -39,7 +39,7 @@ export default class LabelsSelect { showNo = $dropdown.data('showNo'); showAny = $dropdown.data('showAny'); showMenuAbove = $dropdown.data('showMenuAbove'); - defaultLabel = $dropdown.data('defaultLabel'); + defaultLabel = $dropdown.data('defaultLabel') || 'Label'; abilityName = $dropdown.data('abilityName'); $selectbox = $dropdown.closest('.selectbox'); $block = $selectbox.closest('.block'); @@ -244,21 +244,21 @@ export default class LabelsSelect { var $dropdownInputField = $dropdownParent.find('.dropdown-input-field'); var isSelected = el !== null ? el.hasClass('is-active') : false; - var { title } = selected; + var title = selected ? selected.title : null; var selectedLabels = this.selected; if ($dropdownInputField.length && $dropdownInputField.val().length) { $dropdownParent.find('.dropdown-input-clear').trigger('click'); } - if (selected.id === 0) { + if (selected && selected.id === 0) { this.selected = []; return 'No Label'; } else if (isSelected) { this.selected.push(title); } - else { + else if (!isSelected && title) { var index = this.selected.indexOf(title); this.selected.splice(index, 1); } @@ -409,6 +409,14 @@ export default class LabelsSelect { } } }, + opened: function(e) { + if ($dropdown.hasClass('js-issue-board-sidebar')) { + const previousSelection = $dropdown.attr('data-selected'); + this.selected = previousSelection ? previousSelection.split(',') : []; + $dropdown.data('glDropdown').updateLabel(); + } + }, + preserveContext: true, }); // Set dropdown data diff --git a/app/views/shared/boards/components/sidebar/_labels.html.haml b/app/views/shared/boards/components/sidebar/_labels.html.haml index 607e7f471c9..532045f3697 100644 --- a/app/views/shared/boards/components/sidebar/_labels.html.haml +++ b/app/views/shared/boards/components/sidebar/_labels.html.haml @@ -19,6 +19,7 @@ ":value" => "label.id" } .dropdown %button.dropdown-menu-toggle.js-label-select.js-multiselect.js-issue-board-sidebar{ type: "button", + "v-bind:data-selected" => "selectedLabels", data: { toggle: "dropdown", field_name: "issue[label_names][]", show_no: "true", @@ -28,7 +29,7 @@ namespace_path: @namespace_path, project_path: @project.try(:path) } } %span.dropdown-toggle-text - = _("Label") + {{ labelDropdownTitle }} = icon('chevron-down') .dropdown-menu.dropdown-select.dropdown-menu-paging.dropdown-menu-labels.dropdown-menu-selectable = render partial: "shared/issuable/label_page_default" diff --git a/changelogs/unreleased/44127-board-label-edit-drop-down-is-showing-incorrect-selected-labels-summary.yml b/changelogs/unreleased/44127-board-label-edit-drop-down-is-showing-incorrect-selected-labels-summary.yml new file mode 100644 index 00000000000..de991ef475a --- /dev/null +++ b/changelogs/unreleased/44127-board-label-edit-drop-down-is-showing-incorrect-selected-labels-summary.yml @@ -0,0 +1,5 @@ +--- +title: Board label edit dropdown shows incorrect selected labels summary +merge_request: 20673 +author: +type: fixed |