diff --git a/public/app/features/dashboard-scene/settings/version-history/HistorySrv.ts b/public/app/features/dashboard-scene/settings/version-history/HistorySrv.ts index ece6206c22c..e4393f6620a 100644 --- a/public/app/features/dashboard-scene/settings/version-history/HistorySrv.ts +++ b/public/app/features/dashboard-scene/settings/version-history/HistorySrv.ts @@ -18,8 +18,8 @@ export interface VersionModel { export interface HistorySrv { getHistoryList(dashboardUID: string, options: HistoryListOpts): Promise; - getDashboardVersion(dashboardUID: string, version: number | string): Promise; // Just the spec (for now) - restoreDashboard(dashboardUID: string, version: number | string): Promise; + getDashboardVersion(dashboardUID: string, version: number | string): Promise; // Just the spec (for now) + restoreDashboard(dashboardUID: string, version: number | string): Promise; } class LegacyHistorySrv implements HistorySrv { @@ -31,18 +31,18 @@ class LegacyHistorySrv implements HistorySrv { return getBackendSrv().get(`api/dashboards/uid/${dashboardUID}/versions`, options); } - async getDashboardVersion(dashboardUID: string, version: number): Promise { + async getDashboardVersion(dashboardUID: string, version: number): Promise { if (typeof dashboardUID !== 'string') { - return Promise.reject('invalid uid') + return Promise.resolve({}) } const info = await getBackendSrv().get(`api/dashboards/uid/${dashboardUID}/versions/${version}`); return info.data; // the dashboard body } - restoreDashboard(dashboardUID: string, version: number): Promise { + restoreDashboard(dashboardUID: string, version: number): Promise { if (typeof dashboardUID !== 'string') { - return Promise.reject('invalid uid') + return Promise.resolve({}) } const url = `api/dashboards/uid/${dashboardUID}/restore`; diff --git a/public/app/features/dashboard/components/DashboardSettings/VersionsSettings.test.tsx b/public/app/features/dashboard/components/DashboardSettings/VersionsSettings.test.tsx index 77983e110fb..fd6ad2799d0 100644 --- a/public/app/features/dashboard/components/DashboardSettings/VersionsSettings.test.tsx +++ b/public/app/features/dashboard/components/DashboardSettings/VersionsSettings.test.tsx @@ -5,7 +5,7 @@ import { BrowserRouter } from 'react-router-dom'; import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock'; 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 { createDashboardModelFixture } from '../../state/__fixtures__/dashboardFixtures'; @@ -135,7 +135,7 @@ describe('VersionSettings', () => { }); test('clicking show more appends results to the table', async () => { - historySrv.getHistoryList + getHistorySrv().getHistoryList // @ts-ignore .mockImplementationOnce(() => Promise.resolve(versions.slice(0, VERSIONS_FETCH_LIMIT))) .mockImplementationOnce( @@ -144,7 +144,7 @@ describe('VersionSettings', () => { setup(); - expect(historySrv.getHistoryList).toBeCalledTimes(1); + expect(getHistorySrv().getHistoryList).toBeCalledTimes(1); await waitFor(() => expect(screen.getByRole('table')).toBeInTheDocument()); @@ -153,7 +153,7 @@ describe('VersionSettings', () => { const showMoreButton = screen.getByRole('button', { name: /show more versions/i }); await user.click(showMoreButton); - expect(historySrv.getHistoryList).toBeCalledTimes(2); + expect(getHistorySrv().getHistoryList).toBeCalledTimes(2); expect(screen.getByText(/Fetching more entries/i)).toBeInTheDocument(); jest.advanceTimersByTime(1000); @@ -166,14 +166,14 @@ describe('VersionSettings', () => { test('selecting two versions and clicking compare button should render compare view', async () => { // @ts-ignore historySrv.getHistoryList.mockResolvedValue(versions.slice(0, VERSIONS_FETCH_LIMIT)); - historySrv.getDashboardVersion + getHistorySrv().getDashboardVersion // @ts-ignore .mockImplementationOnce(() => Promise.resolve(diffs.lhs)) .mockImplementationOnce(() => Promise.resolve(diffs.rhs)); setup(); - expect(historySrv.getHistoryList).toBeCalledTimes(1); + expect(getHistorySrv().getHistoryList).toBeCalledTimes(1); await waitFor(() => expect(screen.getByRole('table')).toBeInTheDocument()); diff --git a/public/app/features/dashboard/components/VersionHistory/useDashboardRestore.tsx b/public/app/features/dashboard/components/VersionHistory/useDashboardRestore.tsx index af1f894d3f2..b92b77d1a1c 100644 --- a/public/app/features/dashboard/components/VersionHistory/useDashboardRestore.tsx +++ b/public/app/features/dashboard/components/VersionHistory/useDashboardRestore.tsx @@ -4,7 +4,7 @@ import { useAsyncFn } from 'react-use'; import { locationUtil } from '@grafana/data'; import { locationService } from '@grafana/runtime'; 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 { dashboardWatcher } from '../../../live/dashboard/dashboardWatcher'; @@ -13,7 +13,7 @@ import { DashboardModel } from '../../state'; const restoreDashboard = async (version: number, dashboard: DashboardModel) => { // Skip the watcher logic for this save since it's handled by the hook dashboardWatcher.ignoreNextSave(); - return await historySrv.restoreDashboard(dashboard.uid, version); + return await getHistorySrv().restoreDashboard(dashboard.uid, version); }; export const useDashboardRestore = (version: number) => {