Removable labels from filtered issuables label bar

When filtering by labels, a remove button appears next to each label. This then removes that label & refreshes the issuable filter form

Closes #15474
This commit is contained in:
Phil Hughes 2016-05-17 12:07:11 +01:00
parent 915ad255cd
commit 519c758fa9
3 changed files with 36 additions and 2 deletions

View File

@ -6,12 +6,20 @@ issuable_created = false
Issuable.initTemplates()
Issuable.initSearch()
Issuable.initChecks()
Issuable.initLabelFilterRemove()
initTemplates: ->
Issuable.labelRow = _.template(
'<% _.each(labels, function(label){ %>
<span class="label-row">
<a href="#"><span class="label color-label has-tooltip" style="background-color: <%= label.color %>; color: <%= label.text_color %>" title="<%= _.escape(label.description) %>" data-container="body"><%= _.escape(label.title) %></span></a>
<a href="#">
<span class="label color-label has-tooltip" style="background-color: <%= label.color %>; color: <%= label.text_color %>" title="<%= _.escape(label.description) %>" data-container="body">
<%= _.escape(label.title) %>
</span>
</a>
<button type="button" class="btn btn-sm btn-transparent append-right-5 js-label-filter-remove" data-label="<%= _.escape(label.title) %>">
<i class="fa fa-times"></i>
</button>
</span>
<% }); %>'
)
@ -35,6 +43,20 @@ issuable_created = false
Issuable.filterResults $form
, 500)
initLabelFilterRemove: ->
$(document)
.off 'click', '.js-label-filter-remove'
.on 'click', '.js-label-filter-remove', (e) ->
$button = $(@)
# Remove the label input box
$('input[name="label_name[]"]')
.filter -> @value is $button.data('label')
.remove()
# Submit the form to get new data
Issuable.filterResults $('.filter-form')
toggleLabelFilters: ->
$filteredLabels = $('.filtered-labels')
if $filteredLabels.find('.label-row').length > 0

View File

@ -1,3 +1,5 @@
- labels.each do |label|
%span.label-row
= link_to_label(label, tooltip: false)
= link_to_label(label, tooltip: true)
%button.btn.btn-sm.btn-transparent.append-right-5.js-label-filter-remove{ type: "button", data: { label: label.title } }
= icon("times")

View File

@ -54,6 +54,11 @@ feature 'Issue filtering by Labels', feature: true do
expect(find('.filtered-labels')).not_to have_content "feature"
expect(find('.filtered-labels')).not_to have_content "enhancement"
end
it 'should remove label "bug"' do
first('.js-label-filter-remove').click
expect(find('.filtered-labels')).to have_no_content "bug"
end
end
context 'filter by label feature', js: true do
@ -135,6 +140,11 @@ feature 'Issue filtering by Labels', feature: true do
it 'should not show label "bug" in filtered-labels' do
expect(find('.filtered-labels')).not_to have_content "bug"
end
it 'should remove label "enhancement"' do
first('.js-label-filter-remove').click
expect(find('.filtered-labels')).to have_no_content "enhancement"
end
end
context 'filter by label enhancement and bug in issues list', js: true do