Feat: Make expressions work with plugins that set alerting:false but backend:true in their plugin.json files (#102232)
* Making expressions depend on backend parameter instead of alerting * Fallback to old behavior just in case we have weird edge cases * adding render test for the button * prettier fixes
This commit is contained in:
+46
@@ -12,6 +12,7 @@ import {
|
||||
FieldType,
|
||||
LoadingState,
|
||||
PanelData,
|
||||
PluginType,
|
||||
TimeRange,
|
||||
toDataFrame,
|
||||
} from '@grafana/data';
|
||||
@@ -249,6 +250,7 @@ jest.mock('@grafana/runtime', () => ({
|
||||
config: {
|
||||
...jest.requireActual('@grafana/runtime').config,
|
||||
defaultDatasource: 'gdev-testdata',
|
||||
expressionsEnabled: true,
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -353,6 +355,50 @@ describe('PanelDataQueriesTab', () => {
|
||||
|
||||
expect(modelMock.onQueriesChange).toHaveBeenCalledWith([]);
|
||||
});
|
||||
|
||||
it('renders add expression button when datasource meta.backend is true', async () => {
|
||||
// arrange
|
||||
const modelMock = await createModelMock();
|
||||
const dsSettingsMock: DataSourceInstanceSettings<DataSourceJsonData> = {
|
||||
id: 1,
|
||||
uid: 'gdev-testdata',
|
||||
name: 'testDs1',
|
||||
type: 'grafana-testdata-datasource',
|
||||
meta: {
|
||||
id: 'grafana-testdata-datasource',
|
||||
info: {
|
||||
logos: {
|
||||
small: 'test-logo.png',
|
||||
large: 'test-logo.png',
|
||||
},
|
||||
author: {
|
||||
name: '',
|
||||
url: undefined,
|
||||
},
|
||||
description: '',
|
||||
links: [],
|
||||
screenshots: [],
|
||||
updated: '',
|
||||
version: '',
|
||||
},
|
||||
backend: true,
|
||||
name: '',
|
||||
type: PluginType.datasource,
|
||||
module: '',
|
||||
baseUrl: '',
|
||||
},
|
||||
readOnly: false,
|
||||
jsonData: {},
|
||||
access: 'proxy',
|
||||
};
|
||||
modelMock.setState({ datasource: ds1Mock, dsSettings: dsSettingsMock });
|
||||
|
||||
// act
|
||||
render(<PanelDataQueriesTabRendered model={modelMock}></PanelDataQueriesTabRendered>);
|
||||
|
||||
// assert
|
||||
await screen.findByTestId(selectors.components.QueryTab.addExpression);
|
||||
});
|
||||
});
|
||||
|
||||
describe('query options', () => {
|
||||
|
||||
+1
-1
@@ -283,7 +283,7 @@ export class PanelDataQueriesTab extends SceneObjectBase<PanelDataQueriesTabStat
|
||||
};
|
||||
|
||||
public isExpressionsSupported(dsSettings: DataSourceInstanceSettings): boolean {
|
||||
return (dsSettings.meta.alerting || dsSettings.meta.mixed) === true;
|
||||
return (dsSettings.meta.backend || dsSettings.meta.alerting || dsSettings.meta.mixed) === true;
|
||||
}
|
||||
|
||||
public onAddExpressionClick = () => {
|
||||
|
||||
@@ -276,7 +276,7 @@ export class QueryGroup extends PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
isExpressionsSupported(dsSettings: DataSourceInstanceSettings): boolean {
|
||||
return (dsSettings.meta.alerting || dsSettings.meta.mixed) === true;
|
||||
return (dsSettings.meta.backend || dsSettings.meta.alerting || dsSettings.meta.mixed) === true;
|
||||
}
|
||||
|
||||
renderExtraActions() {
|
||||
|
||||
Reference in New Issue
Block a user