11import { AppEvents , InterpolateFunction , PanelProps } from '@grafana/data' ;
2- import { getBackendSrv , getDataSourceSrv , SystemJS } from '@grafana/runtime' ;
2+ import { getAppEvents , getBackendSrv , getDataSourceSrv } from '@grafana/runtime' ;
33import { Button , HorizontalGroup , VerticalGroup } from '@grafana/ui' ;
44import React from 'react' ;
55import { ButtonOptions , Options } from 'types' ;
@@ -9,6 +9,7 @@ interface Props extends PanelProps<Options> {}
99async function postQuery ( button : ButtonOptions , text : string , replaceVariables : InterpolateFunction ) {
1010 const payload = JSON . parse ( replaceVariables ( button . query || '{}' ) ) ;
1111 const ds = await getDataSourceSrv ( ) . get ( button . datasource ) ;
12+ const appEvents = getAppEvents ( ) ;
1213 try {
1314 const resp = await getBackendSrv ( ) . datasourceRequest ( {
1415 method : 'POST' ,
@@ -23,11 +24,15 @@ async function postQuery(button: ButtonOptions, text: string, replaceVariables:
2324 ] ,
2425 } ,
2526 } ) ;
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+ } ) ;
2831 } 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+ } ) ;
3136 }
3237}
3338
0 commit comments