diff --git a/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts b/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts index 27b46514d70..bbe79f9cdb3 100644 --- a/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts +++ b/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts @@ -263,16 +263,27 @@ export const browseDashboardsAPI = createApi({ // Move all the dashboards sequentially // TODO error handling here for (const dashboardUID of selectedDashboards) { - const fullDash: DashboardDTO = await getDashboardAPI().getDashboardDTO(dashboardUID); + if (config.featureToggles.useV2DashboardsAPI) { + const fullDash = await getDashboardAPI('v2').getDashboardDTO(dashboardUID); - await getDashboardAPI().saveDashboard({ - dashboard: fullDash.dashboard, - folderUid: destinationUID, - overwrite: false, - message: '', - }); + await getDashboardAPI('v2').saveDashboard({ + dashboard: fullDash.spec, + folderUid: destinationUID, + overwrite: false, + message: '', + k8s: fullDash.metadata, + }); + } else { + const fullDash: DashboardDTO = await getDashboardAPI().getDashboardDTO(dashboardUID); + + await getDashboardAPI().saveDashboard({ + dashboard: fullDash.dashboard, + folderUid: destinationUID, + overwrite: false, + message: '', + }); + } } - return { data: undefined }; }, onQueryStarted: ({ destinationUID, selectedItems }, { queryFulfilled, dispatch }) => { diff --git a/public/app/features/dashboard/api/v2.ts b/public/app/features/dashboard/api/v2.ts index 3a283071091..ec4fa199386 100644 --- a/public/app/features/dashboard/api/v2.ts +++ b/public/app/features/dashboard/api/v2.ts @@ -56,6 +56,11 @@ export class K8sDashboardV2API } catch (e) { throw new Error('Failed to load folder'); } + } else if (result.metadata.annotations && !result.metadata.annotations[AnnoKeyFolder]) { + // Set AnnoKeyFolder to empty string for top-level dashboards + // This ensures NestedFolderPicker correctly identifies it as being in the "Dashboard" root folder + // AnnoKeyFolder undefined -> top-level dashboard -> empty string + result.metadata.annotations[AnnoKeyFolder] = ''; } // Depending on the ui components readiness, we might need to convert the response to v1 @@ -117,6 +122,8 @@ export class K8sDashboardV2API } if (obj.metadata.name) { + // remove resource version when updating + delete obj.metadata.resourceVersion; return this.client.update(obj).then((v) => this.asSaveDashboardResponseDTO(v)); } return await this.client.create(obj).then((v) => this.asSaveDashboardResponseDTO(v));