mirror of
https://github.com/grafana/grafana.git
synced 2026-09-05 04:40:13 -05:00
Plugins: Added hook to make it easier to track interactions in plugins (#56126)
* first stab at context away plugin tracking. * adding a plugin context and a hook to get hold of a tracker that always appends the plugin context information. * wip * improved the code a bit. * wip * Fixed type errors. * added datasource_uid to data sources. * fixed error message when trying to use hook outside of context. * small refactoring according to feedback. * using the correct provider for data source context. * check not needed. * enforcing the interaction name to start with grafana_plugin_ * exposing guards for the other context type. * added structure for writing reporter hook tests. * added some more tests. * added tests. * reverted back to inheritance between context types. * adding mock for getDataSourceSrv
This commit is contained in:
@@ -2,7 +2,15 @@ import { css, cx } from '@emotion/css';
|
||||
import React, { PureComponent } from 'react';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
import { AnnotationEventMappings, AnnotationQuery, DataQuery, DataSourceApi, LoadingState } from '@grafana/data';
|
||||
import {
|
||||
AnnotationEventMappings,
|
||||
AnnotationQuery,
|
||||
DataQuery,
|
||||
DataSourceApi,
|
||||
DataSourceInstanceSettings,
|
||||
DataSourcePluginContextProvider,
|
||||
LoadingState,
|
||||
} from '@grafana/data';
|
||||
import { Button, Icon, IconName, Spinner } from '@grafana/ui';
|
||||
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
|
||||
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
@@ -16,6 +24,7 @@ import { AnnotationFieldMapper } from './AnnotationResultMapper';
|
||||
|
||||
interface Props {
|
||||
datasource: DataSourceApi;
|
||||
datasourceInstanceSettings: DataSourceInstanceSettings;
|
||||
annotation: AnnotationQuery<DataQuery>;
|
||||
onChange: (annotation: AnnotationQuery<DataQuery>) => void;
|
||||
}
|
||||
@@ -168,7 +177,7 @@ export default class StandardAnnotationQueryEditor extends PureComponent<Props,
|
||||
};
|
||||
|
||||
render() {
|
||||
const { datasource, annotation } = this.props;
|
||||
const { datasource, annotation, datasourceInstanceSettings } = this.props;
|
||||
const { response } = this.state;
|
||||
|
||||
// Find the annotation runner
|
||||
@@ -180,17 +189,19 @@ export default class StandardAnnotationQueryEditor extends PureComponent<Props,
|
||||
const query = annotation.target ?? { refId: 'Anno' };
|
||||
return (
|
||||
<>
|
||||
<QueryEditor
|
||||
key={datasource?.name}
|
||||
query={query}
|
||||
datasource={datasource}
|
||||
onChange={this.onQueryChange}
|
||||
onRunQuery={this.onRunQuery}
|
||||
data={response?.panelData}
|
||||
range={getTimeSrv().timeRange()}
|
||||
annotation={annotation}
|
||||
onAnnotationChange={this.onAnnotationChange}
|
||||
/>
|
||||
<DataSourcePluginContextProvider instanceSettings={datasourceInstanceSettings}>
|
||||
<QueryEditor
|
||||
key={datasource?.name}
|
||||
query={query}
|
||||
datasource={datasource}
|
||||
onChange={this.onQueryChange}
|
||||
onRunQuery={this.onRunQuery}
|
||||
data={response?.panelData}
|
||||
range={getTimeSrv().timeRange()}
|
||||
annotation={annotation}
|
||||
onAnnotationChange={this.onAnnotationChange}
|
||||
/>
|
||||
</DataSourcePluginContextProvider>
|
||||
{shouldUseMappingUI(datasource) && (
|
||||
<>
|
||||
{this.renderStatus()}
|
||||
|
||||
Reference in New Issue
Block a user