Alerting: Fixed logic on how to render alert tab (#43339)

* fixed logic on how to render alert tab

* remove console logs move some logic
This commit is contained in:
Peter Holmberg 2021-12-20 15:30:31 +01:00 committed by GitHub
parent 18fdb89554
commit dda84dbf1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,18 +40,8 @@ export const PanelEditorTabs: FC<PanelEditorTabsProps> = React.memo(({ panel, da
<div className={styles.wrapper}>
<TabsBar className={styles.tabBar} hideBorder>
{tabs.map((tab) => {
if (config.unifiedAlertingEnabled && tab.id === PanelEditorTabId.Alert) {
return (
<PanelAlertTab
key={tab.id}
label={tab.text}
active={tab.active}
onChangeTab={() => onChangeTab(tab)}
icon={tab.icon as IconName}
panel={panel}
dashboard={dashboard}
/>
);
if (tab.id === PanelEditorTabId.Alert) {
renderAlertTab(tab, panel, dashboard, onChangeTab);
}
return (
<Tab
@ -90,6 +80,42 @@ function getCounter(panel: PanelModel, tab: PanelEditorTab) {
return null;
}
function renderAlertTab(
tab: PanelEditorTab,
panel: PanelModel,
dashboard: DashboardModel,
onChangeTab: (tab: PanelEditorTab) => void
) {
if (!config.alertingEnabled || !config.unifiedAlertingEnabled) {
return null;
} else if (config.unifiedAlertingEnabled) {
return (
<PanelAlertTab
key={tab.id}
label={tab.text}
active={tab.active}
onChangeTab={() => onChangeTab(tab)}
icon={tab.icon as IconName}
panel={panel}
dashboard={dashboard}
/>
);
} else if (config.alertingEnabled) {
return (
<Tab
key={tab.id}
label={tab.text}
active={tab.active}
onChangeTab={() => onChangeTab(tab)}
icon={tab.icon as IconName}
counter={getCounter(panel, tab)}
/>
);
}
return null;
}
const getStyles = (theme: GrafanaTheme2) => {
return {
wrapper: css`