From b12df9d64c139be9d43922db368b4ae9213bde68 Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Tue, 2 Jun 2020 13:21:49 +0200 Subject: [PATCH] Do not show alerts tab when alerting is disabled (#25285) * Do not show alerts tab when alerting is disabled * Add tests --- .../PanelEditor/state/selectors.test.ts | 74 +++++++++++++++++++ .../components/PanelEditor/state/selectors.ts | 3 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 public/app/features/dashboard/components/PanelEditor/state/selectors.test.ts diff --git a/public/app/features/dashboard/components/PanelEditor/state/selectors.test.ts b/public/app/features/dashboard/components/PanelEditor/state/selectors.test.ts new file mode 100644 index 00000000000..6f10ec42bd1 --- /dev/null +++ b/public/app/features/dashboard/components/PanelEditor/state/selectors.test.ts @@ -0,0 +1,74 @@ +import { getPanelEditorTabs } from './selectors'; +import { LocationState } from 'app/types'; +import { PanelPlugin } from '@grafana/data'; +import { PanelEditorTabId } from '../types'; +import { updateConfig } from '../../../../../core/config'; + +describe('getPanelEditorTabs selector', () => { + it('return no tabs when no plugin provided', () => { + expect(getPanelEditorTabs({} as LocationState)).toEqual([]); + }); + + it('return no tabs when plugin do not support queries', () => { + expect(getPanelEditorTabs({} as LocationState, { meta: { skipDataQuery: true } } as PanelPlugin)).toEqual([]); + }); + + describe('alerts tab', () => { + describe('when alerting enabled', () => { + beforeAll(() => { + updateConfig({ + alertingEnabled: true, + }); + }); + + it('returns Alerts tab for graph panel', () => { + const tabs = getPanelEditorTabs( + { query: {} } as LocationState, + { + meta: { + id: 'graph', + }, + } as PanelPlugin + ); + + expect(tabs.length).toEqual(3); + expect(tabs[2].id).toEqual(PanelEditorTabId.Alert); + }); + + it('does not returns tab for panel other than graph', () => { + const tabs = getPanelEditorTabs( + { query: {} } as LocationState, + { + meta: { + id: 'table', + }, + } as PanelPlugin + ); + expect(tabs.length).toEqual(2); + expect(tabs[1].id).toEqual(PanelEditorTabId.Transform); + }); + }); + + describe('when alerting disabled', () => { + beforeAll(() => { + updateConfig({ + alertingEnabled: false, + }); + }); + + it('does not return Alerts tab', () => { + const tabs = getPanelEditorTabs( + { query: {} } as LocationState, + { + meta: { + id: 'graph', + }, + } as PanelPlugin + ); + + expect(tabs.length).toEqual(2); + expect(tabs[1].id).toEqual(PanelEditorTabId.Transform); + }); + }); + }); +}); diff --git a/public/app/features/dashboard/components/PanelEditor/state/selectors.ts b/public/app/features/dashboard/components/PanelEditor/state/selectors.ts index 195caa45c7f..3dcaffe154f 100644 --- a/public/app/features/dashboard/components/PanelEditor/state/selectors.ts +++ b/public/app/features/dashboard/components/PanelEditor/state/selectors.ts @@ -2,6 +2,7 @@ import memoizeOne from 'memoize-one'; import { LocationState } from 'app/types'; import { PanelPlugin } from '@grafana/data'; import { PanelEditorTab, PanelEditorTabId } from '../types'; +import { getConfig } from 'app/core/config'; export const getPanelEditorTabs = memoizeOne((location: LocationState, plugin?: PanelPlugin) => { const tabs: PanelEditorTab[] = []; @@ -34,7 +35,7 @@ export const getPanelEditorTabs = memoizeOne((location: LocationState, plugin?: }); } - if (plugin.meta.id === 'graph') { + if (getConfig().alertingEnabled && plugin.meta.id === 'graph') { tabs.push({ id: PanelEditorTabId.Alert, text: 'Alert',