Commit 8d852684 authored by Frédéric Caplette's avatar Frédéric Caplette

Merge branch '250839-check-usage-of-app-views-admin-labels-destroy-js-haml-2' into 'master'

Remove unneeded dynamic javascript from rails templates

See merge request gitlab-org/gitlab!56803
parents ba85626b 003adefd
import initDeprecatedRemoveRowBehavior from '~/behaviors/deprecated_remove_row_behavior'; document.addEventListener('DOMContentLoaded', () => {
const pagination = document.querySelector('.labels .gl-pagination');
const emptyState = document.querySelector('.labels .nothing-here-block.hidden');
document.addEventListener('DOMContentLoaded', initDeprecatedRemoveRowBehavior); function removeLabelSuccessCallback() {
this.closest('li').classList.add('gl-display-none!');
const labelsCount = document.querySelectorAll(
'ul.manage-labels-list li:not(.gl-display-none\\!)',
).length;
// display the empty state if there are no more labels
if (labelsCount < 1 && !pagination && emptyState) {
emptyState.classList.remove('hidden');
}
}
document.querySelectorAll('.js-remove-label').forEach((row) => {
row.addEventListener('ajax:success', removeLabelSuccessCallback);
});
});
...@@ -47,7 +47,7 @@ class Admin::LabelsController < Admin::ApplicationController ...@@ -47,7 +47,7 @@ class Admin::LabelsController < Admin::ApplicationController
format.html do format.html do
redirect_to admin_labels_path, status: :found, notice: _('Label was removed') redirect_to admin_labels_path, status: :found, notice: _('Label was removed')
end end
format.js format.js { head :ok }
end end
end end
......
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
.label-actions-list .label-actions-list
= link_to edit_admin_label_path(label), class: 'btn btn-default gl-button btn-default-tertiary label-action has-tooltip', title: _('Edit'), data: { placement: 'bottom' }, aria_label: _('Edit') do = link_to edit_admin_label_path(label), class: 'btn btn-default gl-button btn-default-tertiary label-action has-tooltip', title: _('Edit'), data: { placement: 'bottom' }, aria_label: _('Edit') do
= sprite_icon('pencil') = sprite_icon('pencil')
= link_to admin_label_path(label), class: 'btn btn-default gl-button btn-default-tertiary hover-red js-remove-row label-action has-tooltip', title: _('Delete'), data: { placement: 'bottom', confirm: "Delete this label? Are you sure?" }, aria_label: _('Delete'), method: :delete, remote: true do = link_to admin_label_path(label), class: 'btn btn-default gl-button btn-default-tertiary hover-red js-remove-label label-action has-tooltip', title: _('Delete'), data: { placement: 'bottom', confirm: "Delete this label? Are you sure?" }, aria_label: _('Delete'), method: :delete, remote: true do
= sprite_icon('remove') = sprite_icon('remove')
- if @labels.size == 0
var emptyState = document.querySelector('.labels .nothing-here-block.hidden');
if (emptyState) emptyState.classList.remove('hidden');
...@@ -36,7 +36,7 @@ RSpec.describe 'admin issues labels' do ...@@ -36,7 +36,7 @@ RSpec.describe 'admin issues labels' do
it 'deletes all labels', :js do it 'deletes all labels', :js do
page.within '.labels' do page.within '.labels' do
page.all('.js-remove-row').each do |remove| page.all('.js-remove-label').each do |remove|
accept_confirm { remove.click } accept_confirm { remove.click }
wait_for_requests wait_for_requests
end end
......
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