From 33b48f7c6effc738efd98e28da0a7e3a4d69c835 Mon Sep 17 00:00:00 2001 From: Adela Almasan <88068998+adela-almasan@users.noreply.github.com> Date: Wed, 12 Feb 2025 04:46:00 -0600 Subject: [PATCH] PanelPlugin: Allow inverting `hideFromDefaults` (#100473) --- .../src/panel/registryFactories.ts | 2 +- .../PanelEditor/OptionsPaneOptions.test.tsx | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/grafana-data/src/panel/registryFactories.ts b/packages/grafana-data/src/panel/registryFactories.ts index a312d0c128e..98d8acb660d 100644 --- a/packages/grafana-data/src/panel/registryFactories.ts +++ b/packages/grafana-data/src/panel/registryFactories.ts @@ -55,7 +55,7 @@ export function createFieldConfigRegistry( const customDefault = config.standardOptions[id]?.defaultValue; const customSettings = config.standardOptions[id]?.settings; - if (customHideFromDefaults) { + if (customHideFromDefaults !== undefined) { fieldConfigProp = { ...fieldConfigProp, hideFromDefaults: customHideFromDefaults, diff --git a/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx b/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx index ad8c19ee30b..6387aac97a8 100644 --- a/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx +++ b/public/app/features/dashboard/components/PanelEditor/OptionsPaneOptions.test.tsx @@ -143,6 +143,29 @@ describe('OptionsPaneOptions', () => { expect(screen.queryByLabelText(OptionsPaneSelector.fieldLabel('TestPanel HiddenFromDef'))).not.toBeInTheDocument(); }); + it('should render options that are specifically not marked as hidden from defaults', () => { + const scenario = new OptionsPaneOptionsTestScenario(); + + scenario.plugin = getPanelPlugin({ + id: 'TestPanel', + }).useFieldConfig({ + standardOptions: {}, + useCustomConfig: (b) => { + b.addBooleanSwitch({ + name: 'CustomBool', + path: 'CustomBool', + }).addBooleanSwitch({ + name: 'HiddenFromDef', + path: 'HiddenFromDef', + hideFromDefaults: false, + }); + }, + }); + + scenario.render(); + expect(screen.queryByLabelText(OptionsPaneSelector.fieldLabel('TestPanel HiddenFromDef'))).toBeInTheDocument(); + }); + it('should create categories for field options with category', () => { const scenario = new OptionsPaneOptionsTestScenario(); scenario.render();