mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
752453f204
commit
e85abf6810
@ -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',
|
||||
|
@ -2,9 +2,9 @@ import {DashboardListCtrl} from '../dashboard_list_ctrl';
|
||||
import q from 'q';
|
||||
|
||||
describe('DashboardListCtrl', () => {
|
||||
describe('when fetching dashboards', () => {
|
||||
let ctrl;
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user