From a1a3aa06659cdd5133a51c636a4d3d96aef67862 Mon Sep 17 00:00:00 2001 From: Timur Olzhabayev Date: Thu, 20 Mar 2025 10:49:10 +0100 Subject: [PATCH] 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 --- .../PanelDataQueriesTab.test.tsx | 46 +++++++++++++++++++ .../PanelDataPane/PanelDataQueriesTab.tsx | 2 +- .../features/query/components/QueryGroup.tsx | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.test.tsx b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.test.tsx index c0131b6847d..f3c58622b27 100644 --- a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.test.tsx +++ b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.test.tsx @@ -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 = { + 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(); + + // assert + await screen.findByTestId(selectors.components.QueryTab.addExpression); + }); }); describe('query options', () => { diff --git a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx index 31dbfc108e5..867fd35a06a 100644 --- a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx +++ b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx @@ -283,7 +283,7 @@ export class PanelDataQueriesTab extends SceneObjectBase { diff --git a/public/app/features/query/components/QueryGroup.tsx b/public/app/features/query/components/QueryGroup.tsx index d7604d11670..278b05ffb8f 100644 --- a/public/app/features/query/components/QueryGroup.tsx +++ b/public/app/features/query/components/QueryGroup.tsx @@ -276,7 +276,7 @@ export class QueryGroup extends PureComponent { } isExpressionsSupported(dsSettings: DataSourceInstanceSettings): boolean { - return (dsSettings.meta.alerting || dsSettings.meta.mixed) === true; + return (dsSettings.meta.backend || dsSettings.meta.alerting || dsSettings.meta.mixed) === true; } renderExtraActions() {