From 83ff974b86bb50a8f14b0c02f76224ebf45633b3 Mon Sep 17 00:00:00 2001 From: Levente Balogh Date: Fri, 27 Jan 2023 10:47:18 +0100 Subject: [PATCH] Datasources: Add the props for the "add datasource" event (#62227) chore: pass editLink to the add datasource user event --- public/app/features/datasources/state/actions.test.ts | 2 ++ public/app/features/datasources/state/actions.ts | 6 ++++-- public/app/features/datasources/tracking.ts | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/public/app/features/datasources/state/actions.test.ts b/public/app/features/datasources/state/actions.test.ts index 81e8cb6bf1c..5d06e3fb211 100644 --- a/public/app/features/datasources/state/actions.test.ts +++ b/public/app/features/datasources/state/actions.test.ts @@ -6,6 +6,7 @@ import { ThunkResult, ThunkDispatch } from 'app/types'; import { getMockDataSource } from '../__mocks__'; import * as api from '../api'; +import { DATASOURCES_ROUTES } from '../constants'; import { trackDataSourceCreated, trackDataSourceTested } from '../tracking'; import { GenericDataSourcePlugin } from '../types'; @@ -357,6 +358,7 @@ describe('addDataSource', () => { plugin_version: '1.2.3', datasource_uid: 'azure23', grafana_version: '1.0', + editLink: DATASOURCES_ROUTES.Edit.replace(':uid', 'azure23'), }); }); }); diff --git a/public/app/features/datasources/state/actions.ts b/public/app/features/datasources/state/actions.ts index 0ce72e58b28..eb8a772ac36 100644 --- a/public/app/features/datasources/state/actions.ts +++ b/public/app/features/datasources/state/actions.ts @@ -189,7 +189,7 @@ export function loadDataSourceMeta(dataSource: DataSourceSettings): ThunkResult< }; } -export function addDataSource(plugin: DataSourcePluginMeta, editLink = DATASOURCES_ROUTES.Edit): ThunkResult { +export function addDataSource(plugin: DataSourcePluginMeta, editRoute = DATASOURCES_ROUTES.Edit): ThunkResult { return async (dispatch, getStore) => { await dispatch(loadDataSources()); @@ -207,6 +207,7 @@ export function addDataSource(plugin: DataSourcePluginMeta, editLink = DATASOURC } const result = await api.createDataSource(newInstance); + const editLink = editRoute.replace(/:uid/gi, result.datasource.uid); await getDatasourceSrv().reload(); await contextSrv.fetchUserPermissions(); @@ -216,9 +217,10 @@ export function addDataSource(plugin: DataSourcePluginMeta, editLink = DATASOURC plugin_id: plugin.id, datasource_uid: result.datasource.uid, plugin_version: result.meta?.info?.version, + editLink, }); - locationService.push(editLink.replace(/:uid/gi, result.datasource.uid)); + locationService.push(editLink); }; } diff --git a/public/app/features/datasources/tracking.ts b/public/app/features/datasources/tracking.ts index 8323f5d1324..5de67f15209 100644 --- a/public/app/features/datasources/tracking.ts +++ b/public/app/features/datasources/tracking.ts @@ -24,6 +24,8 @@ type DataSourceCreatedProps = { plugin_id: string; /** The plugin version (especially interesting in external plugins - core plugins are aligned with grafana version) */ 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; }; /**