Skip to content

Commit b17d14b

Browse files
committed
using getAppEvents to publish events
1 parent 8526832 commit b17d14b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/buttonPanel.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppEvents, InterpolateFunction, PanelProps } from '@grafana/data';
2-
import { getBackendSrv, getDataSourceSrv, SystemJS } from '@grafana/runtime';
2+
import { getAppEvents, getBackendSrv, getDataSourceSrv } from '@grafana/runtime';
33
import { Button, HorizontalGroup, VerticalGroup } from '@grafana/ui';
44
import React from 'react';
55
import { ButtonOptions, Options } from 'types';
@@ -9,6 +9,7 @@ interface Props extends PanelProps<Options> {}
99
async 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

Comments
 (0)