mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
history UI
This commit is contained in:
parent
2fab168fb1
commit
afe0848d16
@ -18,8 +18,8 @@ export interface VersionModel {
|
|||||||
|
|
||||||
export interface HistorySrv {
|
export interface HistorySrv {
|
||||||
getHistoryList(dashboardUID: string, options: HistoryListOpts): Promise<VersionModel[]>;
|
getHistoryList(dashboardUID: string, options: HistoryListOpts): Promise<VersionModel[]>;
|
||||||
getDashboardVersion(dashboardUID: string, version: number | string): Promise<Dashboard>; // Just the spec (for now)
|
getDashboardVersion(dashboardUID: string, version: number | string): Promise<Dashboard | {}>; // Just the spec (for now)
|
||||||
restoreDashboard(dashboardUID: string, version: number | string): Promise<SaveDashboardResponseDTO>;
|
restoreDashboard(dashboardUID: string, version: number | string): Promise<SaveDashboardResponseDTO | {}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LegacyHistorySrv implements HistorySrv {
|
class LegacyHistorySrv implements HistorySrv {
|
||||||
@ -31,18 +31,18 @@ class LegacyHistorySrv implements HistorySrv {
|
|||||||
return getBackendSrv().get<VersionModel[]>(`api/dashboards/uid/${dashboardUID}/versions`, options);
|
return getBackendSrv().get<VersionModel[]>(`api/dashboards/uid/${dashboardUID}/versions`, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDashboardVersion(dashboardUID: string, version: number): Promise<Dashboard> {
|
async getDashboardVersion(dashboardUID: string, version: number): Promise<Dashboard | {}> {
|
||||||
if (typeof dashboardUID !== 'string') {
|
if (typeof dashboardUID !== 'string') {
|
||||||
return Promise.reject('invalid uid')
|
return Promise.resolve({})
|
||||||
}
|
}
|
||||||
|
|
||||||
const info = await getBackendSrv().get(`api/dashboards/uid/${dashboardUID}/versions/${version}`);
|
const info = await getBackendSrv().get(`api/dashboards/uid/${dashboardUID}/versions/${version}`);
|
||||||
return info.data; // the dashboard body
|
return info.data; // the dashboard body
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreDashboard(dashboardUID: string, version: number): Promise<SaveDashboardResponseDTO> {
|
restoreDashboard(dashboardUID: string, version: number): Promise<SaveDashboardResponseDTO | {}> {
|
||||||
if (typeof dashboardUID !== 'string') {
|
if (typeof dashboardUID !== 'string') {
|
||||||
return Promise.reject('invalid uid')
|
return Promise.resolve({})
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `api/dashboards/uid/${dashboardUID}/restore`;
|
const url = `api/dashboards/uid/${dashboardUID}/restore`;
|
||||||
|
@ -5,7 +5,7 @@ import { BrowserRouter } from 'react-router-dom';
|
|||||||
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
|
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
|
||||||
|
|
||||||
import { GrafanaContext } from 'app/core/context/GrafanaContext';
|
import { GrafanaContext } from 'app/core/context/GrafanaContext';
|
||||||
import { historySrv } from 'app/features/dashboard-scene/settings/version-history/HistorySrv';
|
import { getHistorySrv } from 'app/features/dashboard-scene/settings/version-history/HistorySrv';
|
||||||
|
|
||||||
import { configureStore } from '../../../../store/configureStore';
|
import { configureStore } from '../../../../store/configureStore';
|
||||||
import { createDashboardModelFixture } from '../../state/__fixtures__/dashboardFixtures';
|
import { createDashboardModelFixture } from '../../state/__fixtures__/dashboardFixtures';
|
||||||
@ -135,7 +135,7 @@ describe('VersionSettings', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('clicking show more appends results to the table', async () => {
|
test('clicking show more appends results to the table', async () => {
|
||||||
historySrv.getHistoryList
|
getHistorySrv().getHistoryList
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.mockImplementationOnce(() => Promise.resolve(versions.slice(0, VERSIONS_FETCH_LIMIT)))
|
.mockImplementationOnce(() => Promise.resolve(versions.slice(0, VERSIONS_FETCH_LIMIT)))
|
||||||
.mockImplementationOnce(
|
.mockImplementationOnce(
|
||||||
@ -144,7 +144,7 @@ describe('VersionSettings', () => {
|
|||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
expect(historySrv.getHistoryList).toBeCalledTimes(1);
|
expect(getHistorySrv().getHistoryList).toBeCalledTimes(1);
|
||||||
|
|
||||||
await waitFor(() => expect(screen.getByRole('table')).toBeInTheDocument());
|
await waitFor(() => expect(screen.getByRole('table')).toBeInTheDocument());
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ describe('VersionSettings', () => {
|
|||||||
const showMoreButton = screen.getByRole('button', { name: /show more versions/i });
|
const showMoreButton = screen.getByRole('button', { name: /show more versions/i });
|
||||||
await user.click(showMoreButton);
|
await user.click(showMoreButton);
|
||||||
|
|
||||||
expect(historySrv.getHistoryList).toBeCalledTimes(2);
|
expect(getHistorySrv().getHistoryList).toBeCalledTimes(2);
|
||||||
expect(screen.getByText(/Fetching more entries/i)).toBeInTheDocument();
|
expect(screen.getByText(/Fetching more entries/i)).toBeInTheDocument();
|
||||||
jest.advanceTimersByTime(1000);
|
jest.advanceTimersByTime(1000);
|
||||||
|
|
||||||
@ -166,14 +166,14 @@ describe('VersionSettings', () => {
|
|||||||
test('selecting two versions and clicking compare button should render compare view', async () => {
|
test('selecting two versions and clicking compare button should render compare view', async () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
historySrv.getHistoryList.mockResolvedValue(versions.slice(0, VERSIONS_FETCH_LIMIT));
|
historySrv.getHistoryList.mockResolvedValue(versions.slice(0, VERSIONS_FETCH_LIMIT));
|
||||||
historySrv.getDashboardVersion
|
getHistorySrv().getDashboardVersion
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.mockImplementationOnce(() => Promise.resolve(diffs.lhs))
|
.mockImplementationOnce(() => Promise.resolve(diffs.lhs))
|
||||||
.mockImplementationOnce(() => Promise.resolve(diffs.rhs));
|
.mockImplementationOnce(() => Promise.resolve(diffs.rhs));
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
expect(historySrv.getHistoryList).toBeCalledTimes(1);
|
expect(getHistorySrv().getHistoryList).toBeCalledTimes(1);
|
||||||
|
|
||||||
await waitFor(() => expect(screen.getByRole('table')).toBeInTheDocument());
|
await waitFor(() => expect(screen.getByRole('table')).toBeInTheDocument());
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import { useAsyncFn } from 'react-use';
|
|||||||
import { locationUtil } from '@grafana/data';
|
import { locationUtil } from '@grafana/data';
|
||||||
import { locationService } from '@grafana/runtime';
|
import { locationService } from '@grafana/runtime';
|
||||||
import { useAppNotification } from 'app/core/copy/appNotification';
|
import { useAppNotification } from 'app/core/copy/appNotification';
|
||||||
import { historySrv } from 'app/features/dashboard-scene/settings/version-history';
|
import { getHistorySrv } from 'app/features/dashboard-scene/settings/version-history/HistorySrv';
|
||||||
import { useSelector } from 'app/types';
|
import { useSelector } from 'app/types';
|
||||||
|
|
||||||
import { dashboardWatcher } from '../../../live/dashboard/dashboardWatcher';
|
import { dashboardWatcher } from '../../../live/dashboard/dashboardWatcher';
|
||||||
@ -13,7 +13,7 @@ import { DashboardModel } from '../../state';
|
|||||||
const restoreDashboard = async (version: number, dashboard: DashboardModel) => {
|
const restoreDashboard = async (version: number, dashboard: DashboardModel) => {
|
||||||
// Skip the watcher logic for this save since it's handled by the hook
|
// Skip the watcher logic for this save since it's handled by the hook
|
||||||
dashboardWatcher.ignoreNextSave();
|
dashboardWatcher.ignoreNextSave();
|
||||||
return await historySrv.restoreDashboard(dashboard.uid, version);
|
return await getHistorySrv().restoreDashboard(dashboard.uid, version);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useDashboardRestore = (version: number) => {
|
export const useDashboardRestore = (version: number) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user