Dashboards - Schema V2 - Implement move dashboards using v2 api (#99664)
* Dashboards - Schema V2 - Implement move dashboards using v2 api * Fix root folder uid not being picked by FolderPicker
This commit is contained in:
@@ -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 }) => {
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user