dashboards: bulk edit delete

If both a parent folder and a child is chosen then
only sends the parent folder for deletion as the
child folder will be deleted anyway.
This commit is contained in:
Daniel Lee 2017-10-29 22:08:26 +01:00
parent 752453f204
commit e85abf6810
2 changed files with 41 additions and 3 deletions

View File

@ -81,8 +81,28 @@ export class DashboardListCtrl {
this.canMove = selectedDashboards > 0 && selectedFolders === 0;
}
getDashboardsToDelete() {
const selectedFolderIds = this.getFolderIds(this.dashboards);
return _.filter(this.dashboards, o => {
return o.checked && (
o.type !== 'dash-child' ||
(o.type === 'dash-child' && !_.includes(selectedFolderIds, o.folderId))
);
});
}
getFolderIds(dashboards) {
const ids = [];
for (let dash of dashboards) {
if (dash.type === 'dash-folder') {
ids.push(dash.id);
}
}
return ids;
}
delete() {
const selectedDashboards = _.filter(this.dashboards, {checked: true});
const selectedDashboards = this.getDashboardsToDelete();
appEvents.emit('confirm-modal', {
title: 'Delete',

View File

@ -2,9 +2,9 @@ import {DashboardListCtrl} from '../dashboard_list_ctrl';
import q from 'q';
describe('DashboardListCtrl', () => {
describe('when fetching dashboards', () => {
let ctrl;
describe('when fetching dashboards', () => {
describe('and dashboard has parent that is not in search result', () => {
beforeEach(() => {
const response = [
@ -171,4 +171,22 @@ describe('DashboardListCtrl', () => {
});
});
});
describe('when deleting dashboards', () => {
beforeEach(() => {
ctrl = new DashboardListCtrl({get: () => q.resolve([])}, {getNav: () => {}}, q);
ctrl.dashboards = [
{id: 1, type: 'dash-folder', checked: true},
{id: 2, type: 'dash-child', checked: true, folderId: 1},
{id: 3, type: 'dash-db', checked: true}
];
});
it('should filter out children if parent is selected', () => {
const toBeDeleted = ctrl.getDashboardsToDelete();
expect(toBeDeleted.length).toEqual(2);
expect(toBeDeleted[0].id).toEqual(1);
expect(toBeDeleted[1].id).toEqual(3);
});
});
});