Datasources: Add the props for the "add datasource" event (#62227)

chore: pass editLink to the add datasource user event
This commit is contained in:
Levente Balogh 2023-01-27 10:47:18 +01:00 committed by GitHub
parent a54d18c1f5
commit 83ff974b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import { ThunkResult, ThunkDispatch } from 'app/types';
import { getMockDataSource } from '../__mocks__'; import { getMockDataSource } from '../__mocks__';
import * as api from '../api'; import * as api from '../api';
import { DATASOURCES_ROUTES } from '../constants';
import { trackDataSourceCreated, trackDataSourceTested } from '../tracking'; import { trackDataSourceCreated, trackDataSourceTested } from '../tracking';
import { GenericDataSourcePlugin } from '../types'; import { GenericDataSourcePlugin } from '../types';
@ -357,6 +358,7 @@ describe('addDataSource', () => {
plugin_version: '1.2.3', plugin_version: '1.2.3',
datasource_uid: 'azure23', datasource_uid: 'azure23',
grafana_version: '1.0', grafana_version: '1.0',
editLink: DATASOURCES_ROUTES.Edit.replace(':uid', 'azure23'),
}); });
}); });
}); });

View File

@ -189,7 +189,7 @@ export function loadDataSourceMeta(dataSource: DataSourceSettings): ThunkResult<
}; };
} }
export function addDataSource(plugin: DataSourcePluginMeta, editLink = DATASOURCES_ROUTES.Edit): ThunkResult<void> { export function addDataSource(plugin: DataSourcePluginMeta, editRoute = DATASOURCES_ROUTES.Edit): ThunkResult<void> {
return async (dispatch, getStore) => { return async (dispatch, getStore) => {
await dispatch(loadDataSources()); await dispatch(loadDataSources());
@ -207,6 +207,7 @@ export function addDataSource(plugin: DataSourcePluginMeta, editLink = DATASOURC
} }
const result = await api.createDataSource(newInstance); const result = await api.createDataSource(newInstance);
const editLink = editRoute.replace(/:uid/gi, result.datasource.uid);
await getDatasourceSrv().reload(); await getDatasourceSrv().reload();
await contextSrv.fetchUserPermissions(); await contextSrv.fetchUserPermissions();
@ -216,9 +217,10 @@ export function addDataSource(plugin: DataSourcePluginMeta, editLink = DATASOURC
plugin_id: plugin.id, plugin_id: plugin.id,
datasource_uid: result.datasource.uid, datasource_uid: result.datasource.uid,
plugin_version: result.meta?.info?.version, plugin_version: result.meta?.info?.version,
editLink,
}); });
locationService.push(editLink.replace(/:uid/gi, result.datasource.uid)); locationService.push(editLink);
}; };
} }

View File

@ -24,6 +24,8 @@ type DataSourceCreatedProps = {
plugin_id: string; plugin_id: string;
/** The plugin version (especially interesting in external plugins - core plugins are aligned with grafana version) */ /** The plugin version (especially interesting in external plugins - core plugins are aligned with grafana version) */
plugin_version?: string; plugin_version?: string;
/** The URL that points to the edit page for the datasoruce. We are using this to be able to distinguish between the performance of different datasource edit locations. */
editLink?: string;
}; };
/** /**