NestedFolders: Support moving folders into other folders (#65519)

* wip for move folders

* hello

* Polish up move dashboard results messages

* tests

* fix other test

* tweak messages when things can't be moved

* tweak messages when things can't be moved

* fix tests

* remove comment

* restore failOnConsole

* .

* Fix move modal not opening due to dodgy rebase
This commit is contained in:
Josh Hunt
2023-03-31 12:31:06 +01:00
committed by GitHub
parent c2813869e4
commit 9f4ab1b6dd
5 changed files with 287 additions and 31 deletions

View File

@@ -182,6 +182,26 @@ const getDataSourceOptions = (input: { pluginId: string; pluginName: string }, i
}
};
export async function moveFolders(folderUIDs: string[], toFolder: FolderInfo) {
const result = {
totalCount: folderUIDs.length,
successCount: 0,
};
for (const folderUID of folderUIDs) {
try {
const newFolderDTO = await moveFolder(folderUID, toFolder);
if (newFolderDTO !== null) {
result.successCount += 1;
}
} catch (err) {
console.error('Failed to move a folder', err);
}
}
return result;
}
export function moveDashboards(dashboardUids: string[], toFolder: FolderInfo) {
const tasks = [];
@@ -284,6 +304,13 @@ export function createFolder(payload: any) {
return getBackendSrv().post('/api/folders', payload);
}
export function moveFolder(uid: string, toFolder: FolderInfo) {
const payload = {
parentUid: toFolder.uid,
};
return getBackendSrv().post(`/api/folders/${uid}/move`, payload, { showErrorAlert: false });
}
export const SLICE_FOLDER_RESULTS_TO = 1000;
export function searchFolders(
@@ -311,7 +338,7 @@ export function deleteDashboard(uid: string, showSuccessAlert: boolean) {
return getBackendSrv().delete<DeleteDashboardResponse>(`/api/dashboards/uid/${uid}`, { showSuccessAlert });
}
function executeInOrder(tasks: any[]) {
function executeInOrder(tasks: any[]): Promise<unknown> {
return tasks.reduce((acc, task) => {
return Promise.resolve(acc).then(task);
}, []);