Commit 215f2e00 by Hugo Häggmark Committed by GitHub

PanelInspector: hides Query tab for plugins without Query ability (#24216)

* PanelInspector: fixes so Query tab is hidden for plugins without Query ability

* Refactor: changes after PR comments
parent 2d5e675d
......@@ -27,6 +27,7 @@ import { config } from 'app/core/config';
import { getPanelInspectorStyles } from './styles';
import { StoreState } from 'app/types';
import { InspectDataTab } from './InspectDataTab';
import { supportsDataQuery } from '../PanelEditor/utils';
interface OwnProps {
dashboard: DashboardModel;
......@@ -269,7 +270,7 @@ export class PanelInspectorUnconnected extends PureComponent<Props, State> {
const error = last?.error;
const tabs = [];
if (plugin && !plugin.meta.skipDataQuery) {
if (supportsDataQuery(plugin)) {
tabs.push({ label: 'Data', value: InspectTab.Data });
tabs.push({ label: 'Stats', value: InspectTab.Stats });
}
......@@ -284,7 +285,7 @@ export class PanelInspectorUnconnected extends PureComponent<Props, State> {
tabs.push({ label: 'Error', value: InspectTab.Error });
}
if (dashboard.meta.canEdit) {
if (dashboard.meta.canEdit && supportsDataQuery(plugin)) {
tabs.push({ label: 'Query', value: InspectTab.Query });
}
return tabs;
......
......@@ -8,6 +8,7 @@ import { CopyToClipboard } from 'app/core/components/CopyToClipboard/CopyToClipb
import { CoreEvents } from 'app/types';
import { PanelModel } from 'app/features/dashboard/state';
import { getPanelInspectorStyles } from './styles';
import { supportsDataQuery } from '../PanelEditor/utils';
interface DsQuery {
isLoading: boolean;
......@@ -188,6 +189,10 @@ export class QueryInspector extends PureComponent<Props, State> {
const styles = getPanelInspectorStyles();
const haveData = Object.keys(response).length > 0;
if (!supportsDataQuery(this.props.panel.plugin)) {
return null;
}
return (
<>
<div aria-label={selectors.components.PanelInspector.Query.content}>
......
import { FieldConfig, standardFieldConfigEditorRegistry } from '@grafana/data';
import { FieldConfig, PanelPlugin, standardFieldConfigEditorRegistry } from '@grafana/data';
import { supportsDataQuery } from './utils';
describe('standardFieldConfigEditorRegistry', () => {
const dummyConfig: FieldConfig = {
......@@ -20,3 +21,32 @@ describe('standardFieldConfigEditorRegistry', () => {
});
});
});
describe('supportsDataQuery', () => {
describe('when called with plugin that supports queries', () => {
it('then it should return true', () => {
const plugin = ({ meta: { skipDataQuery: false } } as unknown) as PanelPlugin;
expect(supportsDataQuery(plugin)).toBe(true);
});
});
describe('when called with plugin that does not support queries', () => {
it('then it should return false', () => {
const plugin = ({ meta: { skipDataQuery: true } } as unknown) as PanelPlugin;
expect(supportsDataQuery(plugin)).toBe(false);
});
});
describe('when called without skipDataQuery', () => {
it('then it should return false', () => {
const plugin = ({ meta: {} } as unknown) as PanelPlugin;
expect(supportsDataQuery(plugin)).toBe(false);
});
});
describe('when called without plugin', () => {
it('then it should return false', () => {
expect(supportsDataQuery(undefined)).toBe(false);
});
});
});
......@@ -2,6 +2,7 @@ import { CSSProperties } from 'react';
import { PanelModel } from '../../state/PanelModel';
import { DisplayMode } from './types';
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, GRID_COLUMN_COUNT } from 'app/core/constants';
import { PanelPlugin } from '@grafana/data';
export function calculatePanelSize(mode: DisplayMode, width: number, height: number, panel: PanelModel): CSSProperties {
if (mode === DisplayMode.Fill) {
......@@ -24,3 +25,7 @@ export function calculatePanelSize(mode: DisplayMode, width: number, height: num
height: pHeight * scale,
};
}
export function supportsDataQuery(plugin: PanelPlugin | undefined): boolean {
return plugin?.meta.skipDataQuery === false;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment