Commit 519c758f authored by Phil Hughes's avatar Phil Hughes

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
parent 915ad255
......@@ -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
......
- 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")
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment