mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
DashboardSrv: add saveDashboard method (#45627)
* DashboardSrv: add saveDashboard method * revert external changes * use DashboardModel instead of DashboardDataDTO * use fetch instead of request * use getSaveModelClone in saveDashboard
This commit is contained in:
parent
e152ae4cf1
commit
c014f8b806
@ -5,6 +5,25 @@ import { DashboardMeta } from 'app/types';
|
||||
import { getBackendSrv } from 'app/core/services/backend_srv';
|
||||
import { saveDashboard } from 'app/features/manage-dashboards/state/actions';
|
||||
import { RemovePanelEvent } from '../../../types/events';
|
||||
import { BackendSrvRequest } from '@grafana/runtime';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
export interface SaveDashboardOptions {
|
||||
/** The complete dashboard model. If `dashboard.id` is not set a new dashboard will be created. */
|
||||
dashboard: DashboardModel;
|
||||
/** Set a commit message for the version history. */
|
||||
message?: string;
|
||||
/** The id of the folder to save the dashboard in. */
|
||||
folderId?: number;
|
||||
/** The UID of the folder to save the dashboard in. Overrides `folderId`. */
|
||||
folderUid?: string;
|
||||
/** Set to `true` if you want to overwrite existing dashboard with newer version,
|
||||
* same dashboard title in folder or same dashboard uid. */
|
||||
overwrite?: boolean;
|
||||
/** Set the dashboard refresh interval.
|
||||
* If this is lower than the minimum refresh interval, Grafana will ignore it and will enforce the minimum refresh interval. */
|
||||
refresh?: string;
|
||||
}
|
||||
|
||||
export class DashboardSrv {
|
||||
dashboard?: DashboardModel;
|
||||
@ -43,6 +62,23 @@ export class DashboardSrv {
|
||||
});
|
||||
}
|
||||
|
||||
saveDashboard(
|
||||
data: SaveDashboardOptions,
|
||||
requestOptions?: Pick<BackendSrvRequest, 'showErrorAlert' | 'showSuccessAlert'>
|
||||
) {
|
||||
return lastValueFrom(
|
||||
getBackendSrv().fetch({
|
||||
url: '/api/dashboards/db/',
|
||||
method: 'POST',
|
||||
data: {
|
||||
...data,
|
||||
dashboard: data.dashboard.getSaveModelClone(),
|
||||
},
|
||||
...requestOptions,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
starDashboard(dashboardId: string, isStarred: any) {
|
||||
const backendSrv = getBackendSrv();
|
||||
let promise;
|
||||
|
Loading…
Reference in New Issue
Block a user