diff --git a/packages/grafana-e2e-selectors/src/selectors/components.ts b/packages/grafana-e2e-selectors/src/selectors/components.ts index 330110051e1..a60a466289a 100644 --- a/packages/grafana-e2e-selectors/src/selectors/components.ts +++ b/packages/grafana-e2e-selectors/src/selectors/components.ts @@ -171,7 +171,7 @@ export const Components = { }, QueryField: { container: 'Query field' }, ValuePicker: { - button: 'Value picker add button', + button: (name: string) => `Value picker button ${name}`, select: (name: string) => `Value picker select ${name}`, }, Search: { diff --git a/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx index ffd305ce9b8..7c7e4f606d3 100644 --- a/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx +++ b/packages/grafana-ui/src/components/ValuePicker/ValuePicker.tsx @@ -44,7 +44,7 @@ export function ValuePicker({ icon={icon || 'plus'} onClick={() => setIsPicking(true)} variant={variant} - aria-label={selectors.components.ValuePicker.button} + aria-label={selectors.components.ValuePicker.button(label)} > {label} diff --git a/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx b/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx index 0035ca8f76f..4f863f2d951 100644 --- a/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx +++ b/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx @@ -32,6 +32,7 @@ class OptionsPaneOptionsTestScenario { state: LoadingState.Done, timeRange: {} as any, }; + plugin = getPanelPlugin({ id: 'TestPanel', }).useFieldConfig({ @@ -56,6 +57,7 @@ class OptionsPaneOptionsTestScenario { }); }, }); + panel = new PanelModel({ title: 'Test title', type: this.plugin.meta.id, @@ -196,4 +198,17 @@ describe('OptionsPaneOptions', () => { expect(screen.queryByLabelText(OptionsPaneSelector.fieldLabel('Panel options Title'))).not.toBeInTheDocument(); expect(screen.getByLabelText(OptionsPaneSelector.fieldLabel('Axis TextPropWithCategory'))).toBeInTheDocument(); }); + + it('should not render field override options non data panel', async () => { + const scenario = new OptionsPaneOptionsTestScenario(); + scenario.plugin = getPanelPlugin({ + id: 'TestPanel', + }); + + scenario.render(); + + expect( + screen.queryByLabelText(selectors.components.ValuePicker.button('Add field override')) + ).not.toBeInTheDocument(); + }); }); diff --git a/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.tsx b/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.tsx index 0b43cec9b84..79ed40cf366 100644 --- a/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.tsx +++ b/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.tsx @@ -66,6 +66,7 @@ export const OptionsPaneOptions: React.FC = (props) => { for (const item of vizOptions) { mainBoxElements.push(item.render()); } + for (const item of justOverrides) { mainBoxElements.push(item.render()); } @@ -85,13 +86,16 @@ export const OptionsPaneOptions: React.FC = (props) => { } } + // only show radio buttons if we are searching or if the plugin has field config + const showSearchRadioButtons = !isSearching && !plugin.fieldConfigRegistry.isEmpty(); + return (
- {!isSearching && ( + {showSearchRadioButtons && (
@@ -109,7 +113,6 @@ export const OptionsPaneOptions: React.FC = (props) => { function getOptionRadioFilters(): Array> { return [ { label: OptionFilter.All, value: OptionFilter.All }, - { label: OptionFilter.Recent, value: OptionFilter.Recent }, { label: OptionFilter.Overrides, value: OptionFilter.Overrides }, ]; } diff --git a/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx b/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx index 75386dbc75b..efa8f1399db 100644 --- a/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx +++ b/public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx @@ -22,6 +22,10 @@ export function getFieldOverrideCategories(props: OptionPaneRenderProps): Option const registry = props.plugin.fieldConfigRegistry; const data = props.data?.series ?? []; + if (registry.isEmpty()) { + return []; + } + const onOverrideChange = (index: number, override: any) => { let overrides = cloneDeep(currentFieldConfig.overrides); overrides[index] = override; @@ -207,7 +211,7 @@ export function getFieldOverrideCategories(props: OptionPaneRenderProps): Option