diff --git a/public/app/features/manage-dashboards/components/ImportDashboardForm.tsx b/public/app/features/manage-dashboards/components/ImportDashboardForm.tsx index 230d5828087..332b8ff1c13 100644 --- a/public/app/features/manage-dashboards/components/ImportDashboardForm.tsx +++ b/public/app/features/manage-dashboards/components/ImportDashboardForm.tsx @@ -128,7 +128,7 @@ export const ImportDashboardForm: FC = ({ noDefault={true} placeholder={input.info} pluginId={input.pluginId} - current={current[index]?.name} + current={current[index]?.uid} /> )} control={control} diff --git a/public/app/features/manage-dashboards/state/actions.test.ts b/public/app/features/manage-dashboards/state/actions.test.ts new file mode 100644 index 00000000000..7c55fb72f20 --- /dev/null +++ b/public/app/features/manage-dashboards/state/actions.test.ts @@ -0,0 +1,75 @@ +import { setBackendSrv } from '@grafana/runtime'; +import { thunkTester } from 'test/core/thunk/thunkTester'; +import { importDashboard } from './actions'; +import { DataSourceInput, ImportDashboardDTO, initialImportDashboardState, InputType } from './reducers'; + +describe('importDashboard', () => { + it('Should send data source uid', async () => { + const form: ImportDashboardDTO = { + title: 'Asda', + uid: '12', + gnetId: 'asd', + constants: [], + dataSources: [ + { + id: 1, + uid: 'ds-uid', + name: 'ds-name', + type: 'prometheus', + } as any, + ], + elements: [], + folder: { + id: 1, + title: 'title', + }, + }; + + let postArgs: any; + + setBackendSrv({ + post: (url: string, args: any) => { + postArgs = args; + return Promise.resolve({ + importedUrl: '/my/dashboard', + }); + }, + } as any); + + await thunkTester({ + importDashboard: { + ...initialImportDashboardState, + inputs: { + dataSources: [ + { + name: 'ds-name', + pluginId: 'prometheus', + type: InputType.DataSource, + }, + ] as DataSourceInput[], + constants: [], + libraryPanels: [], + }, + }, + }) + .givenThunk(importDashboard) + .whenThunkIsDispatched(form); + + expect(postArgs).toEqual({ + dashboard: { + title: 'Asda', + uid: '12', + }, + folderId: 1, + inputs: [ + { + name: 'ds-name', + pluginId: 'prometheus', + type: 'datasource', + value: 'ds-uid', + }, + ], + overwrite: true, + }); + }); +}); diff --git a/public/app/features/manage-dashboards/state/actions.ts b/public/app/features/manage-dashboards/state/actions.ts index c0bf60743e3..fecd628bcd5 100644 --- a/public/app/features/manage-dashboards/state/actions.ts +++ b/public/app/features/manage-dashboards/state/actions.ts @@ -1,5 +1,4 @@ import { AppEvents, DataSourceInstanceSettings, locationUtil } from '@grafana/data'; -import { getBackendSrv } from 'app/core/services/backend_srv'; import { clearDashboard, fetchDashboard, @@ -16,7 +15,7 @@ import { import { DashboardDataDTO, DashboardDTO, FolderInfo, PermissionLevelString, ThunkResult } from 'app/types'; import { appEvents } from '../../../core/core'; import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher'; -import { getDataSourceSrv, locationService } from '@grafana/runtime'; +import { getDataSourceSrv, locationService, getBackendSrv } from '@grafana/runtime'; import { DashboardSearchHit } from '../../search/types'; import { getLibraryPanel } from '../../library-panels/state/api'; import { LibraryElementDTO, LibraryElementKind } from '../../library-panels/types'; @@ -139,7 +138,7 @@ export function importDashboard(importDashboardForm: ImportDashboardDTO): ThunkR name: input.name, type: input.type, pluginId: input.pluginId, - value: dataSource.name, + value: dataSource.uid, }); }); @@ -195,7 +194,7 @@ export function moveDashboards(dashboardUids: string[], toFolder: FolderInfo) { } async function moveDashboard(uid: string, toFolder: FolderInfo) { - const fullDash: DashboardDTO = await getBackendSrv().getDashboardByUid(uid); + const fullDash: DashboardDTO = await getBackendSrv().get(`/api/dashboards/uid/${uid}`); if ((!fullDash.meta.folderId && toFolder.id === 0) || fullDash.meta.folderId === toFolder.id) { return { alreadyInFolder: true }; @@ -287,7 +286,7 @@ export function createFolder(payload: any) { } export function searchFolders(query: any, permission?: PermissionLevelString): Promise { - return getBackendSrv().search({ query, type: 'dash-folder', permission }); + return getBackendSrv().get('/api/search', { query, type: 'dash-folder', permission }); } export function getFolderById(id: number): Promise<{ id: number; title: string }> {