mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelEditorTabs: adds counter to Query, Alert and Transform (#23645)
This commit is contained in:
parent
89c8855f9d
commit
ed8c3430c4
@ -67,7 +67,7 @@ export const Tab: FC<TabProps> = ({ label, active, icon, onChangeTab, counter })
|
||||
<li className={cx(tabsStyles.tabItem, active && tabsStyles.activeStyle)} onClick={onChangeTab}>
|
||||
{icon && <Icon name={icon} />}
|
||||
{label}
|
||||
{!!counter && <Counter value={counter} />}
|
||||
{typeof counter === 'number' && <Counter value={counter} />}
|
||||
</li>
|
||||
);
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useCallback } from 'react';
|
||||
import { config } from 'app/core/config';
|
||||
import { css } from 'emotion';
|
||||
import { IconName, stylesFactory, Tab, TabContent, TabsBar } from '@grafana/ui';
|
||||
@ -22,6 +22,22 @@ interface PanelEditorTabsProps {
|
||||
export const PanelEditorTabs: React.FC<PanelEditorTabsProps> = ({ panel, dashboard, tabs, data, onChangeTab }) => {
|
||||
const styles = getPanelEditorTabsStyles();
|
||||
const activeTab = tabs.find(item => item.active);
|
||||
const getCounter = useCallback(
|
||||
(tab: PanelEditorTab) => {
|
||||
switch (tab.id) {
|
||||
case PanelEditorTabId.Query:
|
||||
return panel.targets.length;
|
||||
case PanelEditorTabId.Alert:
|
||||
return panel.alert ? 1 : 0;
|
||||
case PanelEditorTabId.Transform:
|
||||
const transformations = panel.getTransformations() ?? [];
|
||||
return transformations.length;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
[panel]
|
||||
);
|
||||
|
||||
if (tabs.length === 0) {
|
||||
return null;
|
||||
@ -42,6 +58,7 @@ export const PanelEditorTabs: React.FC<PanelEditorTabsProps> = ({ panel, dashboa
|
||||
active={tab.active}
|
||||
onChangeTab={() => onChangeTab(tab)}
|
||||
icon={tab.icon as IconName}
|
||||
counter={getCounter(tab)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
Loading…
Reference in New Issue
Block a user