mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Library Panels: Change unsaved change detection logic Change logic from diffing panel models to setting dirty flag
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { getBackendSrv } from '@grafana/runtime';
|
|
import { LibraryPanelDTO, PanelModelWithLibraryPanel } from '../types';
|
|
|
|
export async function getLibraryPanels(): Promise<LibraryPanelDTO[]> {
|
|
const { result } = await getBackendSrv().get(`/api/library-panels`);
|
|
return result;
|
|
}
|
|
|
|
export async function getLibraryPanel(uid: string): Promise<LibraryPanelDTO> {
|
|
const { result } = await getBackendSrv().get(`/api/library-panels/${uid}`);
|
|
return result;
|
|
}
|
|
|
|
export async function addLibraryPanel(
|
|
panelSaveModel: PanelModelWithLibraryPanel,
|
|
folderId: number
|
|
): Promise<LibraryPanelDTO> {
|
|
const { result } = await getBackendSrv().post(`/api/library-panels`, {
|
|
folderId,
|
|
name: panelSaveModel.title,
|
|
model: panelSaveModel,
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export async function updateLibraryPanel(
|
|
panelSaveModel: PanelModelWithLibraryPanel,
|
|
folderId: number
|
|
): Promise<LibraryPanelDTO> {
|
|
const { result } = await getBackendSrv().patch(`/api/library-panels/${panelSaveModel.libraryPanel.uid}`, {
|
|
folderId,
|
|
name: panelSaveModel.title,
|
|
model: panelSaveModel,
|
|
version: panelSaveModel.libraryPanel.version,
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export function deleteLibraryPanel(uid: string): Promise<{ message: string }> {
|
|
return getBackendSrv().delete(`/api/library-panels/${uid}`);
|
|
}
|
|
|
|
export async function getLibraryPanelConnectedDashboards(libraryPanelUid: string): Promise<number[]> {
|
|
const { result } = await getBackendSrv().get(`/api/library-panels/${libraryPanelUid}/dashboards`);
|
|
return result;
|
|
}
|