1
1
import { AppEvents , InterpolateFunction , PanelProps } from '@grafana/data' ;
2
- import { getBackendSrv , getDataSourceSrv , SystemJS } from '@grafana/runtime' ;
2
+ import { getAppEvents , getBackendSrv , getDataSourceSrv } from '@grafana/runtime' ;
3
3
import { Button , HorizontalGroup , VerticalGroup } from '@grafana/ui' ;
4
4
import React from 'react' ;
5
5
import { ButtonOptions , Options } from 'types' ;
@@ -9,6 +9,7 @@ interface Props extends PanelProps<Options> {}
9
9
async function postQuery ( button : ButtonOptions , text : string , replaceVariables : InterpolateFunction ) {
10
10
const payload = JSON . parse ( replaceVariables ( button . query || '{}' ) ) ;
11
11
const ds = await getDataSourceSrv ( ) . get ( button . datasource ) ;
12
+ const appEvents = getAppEvents ( ) ;
12
13
try {
13
14
const resp = await getBackendSrv ( ) . datasourceRequest ( {
14
15
method : 'POST' ,
@@ -23,11 +24,15 @@ async function postQuery(button: ButtonOptions, text: string, replaceVariables:
23
24
] ,
24
25
} ,
25
26
} ) ;
26
- const events = await SystemJS . load ( 'app/core/app_events' ) ;
27
- events . emit ( AppEvents . alertSuccess , [ text + ': ' + resp . status + ' (' + resp . statusText + ')' ] ) ;
27
+ appEvents . publish ( {
28
+ type : AppEvents . alertSuccess . name ,
29
+ payload : [ text + ': ' + resp . status + ' (' + resp . statusText + ')' ] ,
30
+ } ) ;
28
31
} catch ( error : any ) {
29
- const events = await SystemJS . load ( 'app/core/app_events' ) ;
30
- events . emit ( AppEvents . alertError , [ text + ': ' + error . status + ' (' + error . statusText + ')' , error . data . message ] ) ;
32
+ appEvents . publish ( {
33
+ type : AppEvents . alertError . name ,
34
+ payload : [ text + ': ' + error . status + ' (' + error . statusText + ') ' + error . data . message ] ,
35
+ } ) ;
31
36
}
32
37
}
33
38
0 commit comments