Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/buttonPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import {
getBackendSrv,
getDataSourceSrv,
getTemplateSrv,
SystemJS,
} from '@grafana/runtime';
import { Button, HorizontalGroup, VerticalGroup } from '@grafana/ui';
Expand Down Expand Up @@ -40,7 +39,7 @@ describe('button panel', () => {
onFieldConfigChange: () => {},
onOptionsChange: () => {},
renderCounter: 1,
replaceVariables: () => '',
replaceVariables: () => '{}',
timeRange: DefaultTimeRange,
timeZone: DefaultTimeZone,
options: {
Expand Down Expand Up @@ -68,11 +67,6 @@ describe('button panel', () => {
{ text: 'b', variant: 'primary', datasource: 'b' },
];
wrapper.setProps({ options: { buttons: buttons } });

const mockTemplate = jest.fn().mockReturnValue('{}');
(getTemplateSrv as jest.Mock<any>).mockImplementation(() => ({
replace: mockTemplate,
}));
const mockGet = jest.fn().mockReturnValue({ id: 1 });
(getDataSourceSrv as jest.Mock<any>).mockImplementation(() => ({
get: mockGet,
Expand All @@ -97,7 +91,6 @@ describe('button panel', () => {
expect(b.text()).toBe(buttons[i].text);
b.simulate('click');
setImmediate(() => {
expect(mockTemplate).toHaveBeenCalled();
expect(mockGet).toHaveBeenCalledWith(buttons[i].datasource);
expect(mockDataSourceRequest).toHaveBeenCalled();
expect(mockEmit).toHaveBeenCalledWith(AppEvents.alertSuccess, [
Expand All @@ -118,10 +111,6 @@ describe('button panel', () => {
(getDataSourceSrv as jest.Mock<any>).mockImplementation(() => ({
get: mockGet,
}));
const mockTemplate = jest.fn().mockReturnValue('{}');
(getTemplateSrv as jest.Mock<any>).mockImplementation(() => ({
replace: mockTemplate,
}));
const msg = 'msg';
const mockDataSourceRequest = jest.fn().mockRejectedValue({
status: statusError,
Expand Down
5 changes: 2 additions & 3 deletions src/buttonPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AppEvents, PanelProps } from '@grafana/data';
import {
getBackendSrv,
getDataSourceSrv,
getTemplateSrv,
SystemJS,
} from '@grafana/runtime';
import { Button, HorizontalGroup, VerticalGroup } from '@grafana/ui';
Expand All @@ -11,7 +10,7 @@ import { ButtonOptions, Options } from 'types';

interface Props extends PanelProps<Options> {}

export const ButtonPanel: React.FC<Props> = ({ options }) => {
export const ButtonPanel: React.FC<Props> = ({ options, replaceVariables }) => {
const renderButtons = (buttons: ButtonOptions[]) => {
return buttons.map((b: ButtonOptions, index: number) => {
const text = b.text || 'Button';
Expand All @@ -21,7 +20,7 @@ export const ButtonPanel: React.FC<Props> = ({ options }) => {
variant={b.variant}
onClick={async () => {
const payload = JSON.parse(
await getTemplateSrv().replace(b.query || '{}')
replaceVariables(b.query || '{}')
);
const ds = await getDataSourceSrv().get(b.datasource);
try {
Expand Down