mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Types: Adds type safety to appEvents (#19418)
* Types: Add type safety to appEvents
This commit is contained in:
@@ -7,6 +7,7 @@ import { getAngularLoader, AngularComponent } from '@grafana/runtime';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import StackdriverDatasource from '../datasource';
|
||||
import '../query_filter_ctrl';
|
||||
import { AppEvents } from '@grafana/data';
|
||||
|
||||
export interface Props {
|
||||
filtersChanged: (filters: string[]) => void;
|
||||
@@ -102,7 +103,7 @@ export class Filter extends React.Component<Props, State> {
|
||||
}
|
||||
resolve();
|
||||
} catch (error) {
|
||||
appEvents.emit('alert-error', ['Error', 'Error loading metric labels for ' + this.props.metricType]);
|
||||
appEvents.emit(AppEvents.alertError, ['Error', 'Error loading metric labels for ' + this.props.metricType]);
|
||||
scope.labelData = labelData;
|
||||
resolve();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import appEvents from 'app/core/app_events';
|
||||
import { MetricDescriptor } from '../types';
|
||||
import { MetricSelect } from 'app/core/components/Select/MetricSelect';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { CoreEvents } from 'app/types';
|
||||
|
||||
export interface Props {
|
||||
onChange: (metricDescriptor: MetricDescriptor) => void;
|
||||
@@ -58,7 +59,7 @@ export class Metrics extends React.Component<Props, State> {
|
||||
}
|
||||
resolve(this.state.defaultProject);
|
||||
} catch (error) {
|
||||
appEvents.emit('ds-request-error', error);
|
||||
appEvents.emit(CoreEvents.dsRequestError, error);
|
||||
reject();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ import { StackdriverQuery, MetricDescriptor } from '../types';
|
||||
import { getAlignmentPickerData } from '../functions';
|
||||
import StackdriverDatasource from '../datasource';
|
||||
import { TimeSeries, SelectableValue } from '@grafana/data';
|
||||
import { PanelEvents } from '@grafana/ui';
|
||||
|
||||
export interface Props {
|
||||
onQueryChange: (target: StackdriverQuery) => void;
|
||||
@@ -56,8 +57,8 @@ export class QueryEditor extends React.Component<Props, State> {
|
||||
|
||||
componentDidMount() {
|
||||
const { events, target, templateSrv } = this.props;
|
||||
events.on('data-received', this.onDataReceived.bind(this));
|
||||
events.on('data-error', this.onDataError.bind(this));
|
||||
events.on(PanelEvents.dataReceived, this.onDataReceived.bind(this));
|
||||
events.on(PanelEvents.dataError, this.onDataError.bind(this));
|
||||
const { perSeriesAligner, alignOptions } = getAlignmentPickerData(target, templateSrv);
|
||||
this.setState({
|
||||
...this.props.target,
|
||||
@@ -67,8 +68,8 @@ export class QueryEditor extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.events.off('data-received', this.onDataReceived);
|
||||
this.props.events.off('data-error', this.onDataError);
|
||||
this.props.events.off(PanelEvents.dataReceived, this.onDataReceived);
|
||||
this.props.events.off(PanelEvents.dataError, this.onDataError);
|
||||
}
|
||||
|
||||
onDataReceived(dataList: TimeSeries[]) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { ScopedVars } from '@grafana/data';
|
||||
import { BackendSrv } from 'app/core/services/backend_srv';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
import { CoreEvents } from 'app/types';
|
||||
|
||||
export default class StackdriverDatasource extends DataSourceApi<StackdriverQuery, StackdriverOptions> {
|
||||
url: string;
|
||||
@@ -287,7 +288,7 @@ export default class StackdriverDatasource extends DataSourceApi<StackdriverQuer
|
||||
|
||||
return this.metricTypes;
|
||||
} catch (error) {
|
||||
appEvents.emit('ds-request-error', this.formatStackdriverError(error));
|
||||
appEvents.emit(CoreEvents.dsRequestError, { error: { data: { error: this.formatStackdriverError(error) } } });
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user