mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
LibraryPanels: Adds version column (#31590)
* Refactor: adds version column and fixes tests * Chore: adds version check when patching the library panel * Refactor: adds support for version in FrontEnd
This commit is contained in:
@@ -5,11 +5,10 @@ import { css } from 'emotion';
|
||||
import { useAsync, useDebounce } from 'react-use';
|
||||
import { getBackendSrv } from 'app/core/services/backend_srv';
|
||||
import { usePanelSave } from '../../utils/usePanelSave';
|
||||
import { PanelModel } from 'app/features/dashboard/state';
|
||||
import { getLibraryPanelConnectedDashboards, LibraryPanelDTO } from '../../state/api';
|
||||
import { getLibraryPanelConnectedDashboards, PanelModelWithLibraryPanel } from '../../state/api';
|
||||
|
||||
interface Props {
|
||||
panel: PanelModel & { libraryPanel: Pick<LibraryPanelDTO, 'uid' | 'name' | 'meta'> };
|
||||
panel: PanelModelWithLibraryPanel;
|
||||
folderId: number;
|
||||
isOpen: boolean;
|
||||
onConfirm: () => void;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { getBackendSrv } from 'app/core/services/backend_srv';
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
|
||||
import { PanelModel } from '../../dashboard/state';
|
||||
|
||||
export interface LibraryPanelDTO {
|
||||
id: number;
|
||||
@@ -7,6 +9,7 @@ export interface LibraryPanelDTO {
|
||||
uid: string;
|
||||
name: string;
|
||||
model: any;
|
||||
version: number;
|
||||
meta: LibraryPanelDTOMeta;
|
||||
}
|
||||
|
||||
@@ -25,12 +28,19 @@ export interface LibraryPanelDTOMetaUser {
|
||||
avatarUrl: string;
|
||||
}
|
||||
|
||||
export interface PanelModelWithLibraryPanel extends PanelModel {
|
||||
libraryPanel: Pick<LibraryPanelDTO, 'uid' | 'name' | 'meta' | 'version'>;
|
||||
}
|
||||
|
||||
export async function getLibraryPanels(): Promise<LibraryPanelDTO[]> {
|
||||
const { result } = await getBackendSrv().get(`/api/library-panels`);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function addLibraryPanel(panelSaveModel: any, folderId: number): Promise<LibraryPanelDTO> {
|
||||
export async function addLibraryPanel(
|
||||
panelSaveModel: PanelModelWithLibraryPanel,
|
||||
folderId: number
|
||||
): Promise<LibraryPanelDTO> {
|
||||
const { result } = await getBackendSrv().post(`/api/library-panels`, {
|
||||
folderId,
|
||||
name: panelSaveModel.title,
|
||||
@@ -39,11 +49,15 @@ export async function addLibraryPanel(panelSaveModel: any, folderId: number): Pr
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function updateLibraryPanel(panelSaveModel: any, folderId: number): Promise<LibraryPanelDTO> {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user