mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
History: list, compare and restore versions using UID (#51989)
This commit is contained in:
@@ -83,8 +83,8 @@ export class VersionsSettings extends PureComponent<Props, State> {
|
|||||||
isLoading: true,
|
isLoading: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const lhs = await historySrv.getDashboardVersion(this.props.dashboard.id, baseInfo.version);
|
const lhs = await historySrv.getDashboardVersion(this.props.dashboard.uid, baseInfo.version);
|
||||||
const rhs = await historySrv.getDashboardVersion(this.props.dashboard.id, newInfo.version);
|
const rhs = await historySrv.getDashboardVersion(this.props.dashboard.uid, newInfo.version);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
baseInfo,
|
baseInfo,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 249,
|
id: 249,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 10,
|
parentVersion: 10,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 11,
|
version: 11,
|
||||||
@@ -12,6 +13,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 247,
|
id: 247,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 9,
|
parentVersion: 9,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 10,
|
version: 10,
|
||||||
@@ -22,6 +24,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 246,
|
id: 246,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 8,
|
parentVersion: 8,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 9,
|
version: 9,
|
||||||
@@ -32,6 +35,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 245,
|
id: 245,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 7,
|
parentVersion: 7,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 8,
|
version: 8,
|
||||||
@@ -42,6 +46,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 239,
|
id: 239,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 6,
|
parentVersion: 6,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 7,
|
version: 7,
|
||||||
@@ -52,6 +57,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 237,
|
id: 237,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 5,
|
parentVersion: 5,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 6,
|
version: 6,
|
||||||
@@ -62,6 +68,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 236,
|
id: 236,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 4,
|
parentVersion: 4,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 5,
|
version: 5,
|
||||||
@@ -72,6 +79,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 218,
|
id: 218,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 3,
|
parentVersion: 3,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 4,
|
version: 4,
|
||||||
@@ -82,6 +90,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 217,
|
id: 217,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 2,
|
parentVersion: 2,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 3,
|
version: 3,
|
||||||
@@ -92,6 +101,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 216,
|
id: 216,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 1,
|
parentVersion: 1,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 2,
|
version: 2,
|
||||||
@@ -102,6 +112,7 @@ export const versions = [
|
|||||||
{
|
{
|
||||||
id: 215,
|
id: 215,
|
||||||
dashboardId: 74,
|
dashboardId: 74,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 1,
|
parentVersion: 1,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 1,
|
version: 1,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ describe('historySrv', () => {
|
|||||||
|
|
||||||
let historySrv = new HistorySrv();
|
let historySrv = new HistorySrv();
|
||||||
|
|
||||||
const dash = new DashboardModel({ id: 1 });
|
const dash = new DashboardModel({ uid: '_U4zObQMz' });
|
||||||
const emptyDash = new DashboardModel({});
|
const emptyDash = new DashboardModel({});
|
||||||
const historyListOpts = { limit: 10, start: 0 };
|
const historyListOpts = { limit: 10, start: 0 };
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export interface HistoryListOpts {
|
|||||||
export interface RevisionsModel {
|
export interface RevisionsModel {
|
||||||
id: number;
|
id: number;
|
||||||
checked: boolean;
|
checked: boolean;
|
||||||
dashboardId: number;
|
dashboardUID: string;
|
||||||
parentVersion: number;
|
parentVersion: number;
|
||||||
version: number;
|
version: number;
|
||||||
created: Date;
|
created: Date;
|
||||||
@@ -21,26 +21,26 @@ export interface RevisionsModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DiffTarget {
|
export interface DiffTarget {
|
||||||
dashboardId: number;
|
dashboardUID: string;
|
||||||
version: number;
|
version: number;
|
||||||
unsavedDashboard?: DashboardModel; // when doing diffs against unsaved dashboard version
|
unsavedDashboard?: DashboardModel; // when doing diffs against unsaved dashboard version
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HistorySrv {
|
export class HistorySrv {
|
||||||
getHistoryList(dashboard: DashboardModel, options: HistoryListOpts) {
|
getHistoryList(dashboard: DashboardModel, options: HistoryListOpts) {
|
||||||
const id = dashboard && dashboard.id ? dashboard.id : void 0;
|
const uid = dashboard && dashboard.uid ? dashboard.uid : void 0;
|
||||||
return id ? getBackendSrv().get(`api/dashboards/id/${id}/versions`, options) : Promise.resolve([]);
|
return uid ? getBackendSrv().get(`api/dashboards/uid/${uid}/versions`, options) : Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDashboardVersion(id: number, version: number) {
|
getDashboardVersion(uid: string, version: number) {
|
||||||
return getBackendSrv().get(`api/dashboards/id/${id}/versions/${version}`);
|
return getBackendSrv().get(`api/dashboards/uid/${uid}/versions/${version}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreDashboard(dashboard: DashboardModel, version: number) {
|
restoreDashboard(dashboard: DashboardModel, version: number) {
|
||||||
const id = dashboard && dashboard.id ? dashboard.id : void 0;
|
const uid = dashboard && dashboard.uid ? dashboard.uid : void 0;
|
||||||
const url = `api/dashboards/id/${id}/restore`;
|
const url = `api/dashboards/uid/${uid}/restore`;
|
||||||
|
|
||||||
return id && isNumber(version) ? getBackendSrv().post(url, { version }) : Promise.resolve({});
|
return uid && isNumber(version) ? getBackendSrv().post(url, { version }) : Promise.resolve({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ export function versions() {
|
|||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
dashboardId: 1,
|
dashboardId: 1,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 3,
|
parentVersion: 3,
|
||||||
restoredFrom: 0,
|
restoredFrom: 0,
|
||||||
version: 4,
|
version: 4,
|
||||||
@@ -13,6 +14,7 @@ export function versions() {
|
|||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
dashboardId: 1,
|
dashboardId: 1,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 1,
|
parentVersion: 1,
|
||||||
restoredFrom: 1,
|
restoredFrom: 1,
|
||||||
version: 3,
|
version: 3,
|
||||||
@@ -23,6 +25,7 @@ export function versions() {
|
|||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
dashboardId: 1,
|
dashboardId: 1,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 0,
|
parentVersion: 0,
|
||||||
restoredFrom: -1,
|
restoredFrom: -1,
|
||||||
version: 2,
|
version: 2,
|
||||||
@@ -33,6 +36,7 @@ export function versions() {
|
|||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
dashboardId: 1,
|
dashboardId: 1,
|
||||||
|
dashboardUID: '_U4zObQMz',
|
||||||
parentVersion: 0,
|
parentVersion: 0,
|
||||||
restoredFrom: -1,
|
restoredFrom: -1,
|
||||||
slug: 'history-dashboard',
|
slug: 'history-dashboard',
|
||||||
@@ -73,6 +77,7 @@ export function restore(version: any, restoredFrom?: any): any {
|
|||||||
gnetId: null,
|
gnetId: null,
|
||||||
graphTooltip: 0,
|
graphTooltip: 0,
|
||||||
id: 1,
|
id: 1,
|
||||||
|
uid: '_U4zObQMz',
|
||||||
links: [],
|
links: [],
|
||||||
restoredFrom: restoredFrom,
|
restoredFrom: restoredFrom,
|
||||||
rows: [
|
rows: [
|
||||||
|
|||||||
Reference in New Issue
Block a user