2020-04-17 07:46:32 -05:00
|
|
|
import React, { useCallback } from 'react';
|
2020-02-12 03:42:57 -06:00
|
|
|
import { config } from 'app/core/config';
|
2020-02-09 08:39:46 -06:00
|
|
|
import { css } from 'emotion';
|
2020-04-16 14:28:19 -05:00
|
|
|
import { IconName, stylesFactory, Tab, TabContent, TabsBar } from '@grafana/ui';
|
2020-02-12 03:42:57 -06:00
|
|
|
import { DataTransformerConfig, LoadingState, PanelData } from '@grafana/data';
|
|
|
|
import { PanelEditorTab, PanelEditorTabId } from './types';
|
2020-02-09 08:39:46 -06:00
|
|
|
import { DashboardModel } from '../../state';
|
|
|
|
import { QueriesTab } from '../../panel_editor/QueriesTab';
|
|
|
|
import { PanelModel } from '../../state/PanelModel';
|
2020-02-09 10:39:26 -06:00
|
|
|
import { AlertTab } from 'app/features/alerting/AlertTab';
|
2020-04-06 23:54:09 -05:00
|
|
|
import { TransformationsEditor } from '../TransformationsEditor/TransformationsEditor';
|
2020-02-09 08:39:46 -06:00
|
|
|
|
|
|
|
interface PanelEditorTabsProps {
|
|
|
|
panel: PanelModel;
|
|
|
|
dashboard: DashboardModel;
|
2020-02-12 03:42:57 -06:00
|
|
|
tabs: PanelEditorTab[];
|
|
|
|
onChangeTab: (tab: PanelEditorTab) => void;
|
|
|
|
data: PanelData;
|
2020-02-09 08:39:46 -06:00
|
|
|
}
|
|
|
|
|
2020-02-12 03:42:57 -06:00
|
|
|
export const PanelEditorTabs: React.FC<PanelEditorTabsProps> = ({ panel, dashboard, tabs, data, onChangeTab }) => {
|
|
|
|
const styles = getPanelEditorTabsStyles();
|
|
|
|
const activeTab = tabs.find(item => item.active);
|
2020-04-17 07:46:32 -05:00
|
|
|
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]
|
|
|
|
);
|
2020-02-12 03:42:57 -06:00
|
|
|
|
|
|
|
if (tabs.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const onTransformersChange = (transformers: DataTransformerConfig[]) => {
|
|
|
|
panel.setTransformations(transformers);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.wrapper}>
|
|
|
|
<TabsBar className={styles.tabBar}>
|
|
|
|
{tabs.map(tab => {
|
2020-03-20 09:15:04 -05:00
|
|
|
return (
|
|
|
|
<Tab
|
|
|
|
key={tab.id}
|
|
|
|
label={tab.text}
|
|
|
|
active={tab.active}
|
|
|
|
onChangeTab={() => onChangeTab(tab)}
|
@grafana/ui: Create Icon component and replace part of the icons (#23402)
* Part1: Unicons implementation (#23197)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Remove color prop from icon, remove color implemetation in mono icons
* Update navbar styling
* Move toPascalCase to utils/string
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Resolve type errors resulted from merge
* Part2: Unicons implementation (#23266)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Implment icons in Tabs
* Implement icons in search items and empty list
* Update buttons
* Update button-related snapshot tests
* Update icons in modals and page headers
* Create anfular wrapper and update all icons on search screen
* Update sizing, remove colors, update snapshot tests
* Remove color prop from icon, remove color implemetation in mono icons
* Remove color props from monochrome icons
* Complete update of icons for search screen
* Update icons for infor tooltips, playlist, permissions
* Support temporarly font awesome icons used in enterprise grafana
* Part1: Unicons implementation (#23197)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Remove color prop from icon, remove color implemetation in mono icons
* Update navbar styling
* Move toPascalCase to utils/string
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Icons update
* Add optional chaining to for isFontAwesome variable
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Part3: Unicons implementation (#23356)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Implment icons in Tabs
* Implement icons in search items and empty list
* Update buttons
* Update button-related snapshot tests
* Update icons in modals and page headers
* Create anfular wrapper and update all icons on search screen
* Update sizing, remove colors, update snapshot tests
* Remove color prop from icon, remove color implemetation in mono icons
* Remove color props from monochrome icons
* Complete update of icons for search screen
* Update icons for infor tooltips, playlist, permissions
* Support temporarly font awesome icons used in enterprise grafana
* Part1: Unicons implementation (#23197)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Remove color prop from icon, remove color implemetation in mono icons
* Update navbar styling
* Move toPascalCase to utils/string
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Update icons in Explore
* Update icons in alerting
* Update + and x buttons
* Update icons in configurations and settings
* Update close icons
* Update icons in rich history
* Update alert messages
* Add optional chaining to for isFontAwesome variable
* Remove icon mock, set up jest.config
* Fix navbar plus icon
* Fir enable-bacground to enableBackgournd
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Merge remote branch origin master to icons-unicons
* Revert "Merge remote branch origin master to icons-unicons"
This reverts commit 3f25d50a39a940883fefe73ce51219139c1ed37f.
* Size-up dashnav icons
* Fix alerting icons, panel headers, update tests
* Fix typecheck error
* Adjustments - add panel icon, spacing
* Set TerserPlugin sourceMap to false to prevent running out of memory when publishing storybook
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2020-04-08 07:33:31 -05:00
|
|
|
icon={tab.icon as IconName}
|
2020-04-17 07:46:32 -05:00
|
|
|
counter={getCounter(tab)}
|
2020-03-20 09:15:04 -05:00
|
|
|
/>
|
|
|
|
);
|
2020-02-12 03:42:57 -06:00
|
|
|
})}
|
|
|
|
</TabsBar>
|
|
|
|
<TabContent className={styles.tabContent}>
|
2020-04-04 08:44:55 -05:00
|
|
|
{activeTab.id === PanelEditorTabId.Query && <QueriesTab panel={panel} dashboard={dashboard} />}
|
2020-02-12 03:42:57 -06:00
|
|
|
{activeTab.id === PanelEditorTabId.Alert && <AlertTab panel={panel} dashboard={dashboard} />}
|
|
|
|
{activeTab.id === PanelEditorTabId.Transform && data.state !== LoadingState.NotStarted && (
|
|
|
|
<TransformationsEditor
|
|
|
|
transformations={panel.transformations || []}
|
|
|
|
onChange={onTransformersChange}
|
|
|
|
dataFrames={data.series}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</TabContent>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-02-09 08:39:46 -06:00
|
|
|
const getPanelEditorTabsStyles = stylesFactory(() => {
|
2020-02-12 03:42:57 -06:00
|
|
|
const { theme } = config;
|
|
|
|
|
2020-02-09 08:39:46 -06:00
|
|
|
return {
|
|
|
|
wrapper: css`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
height: 100%;
|
|
|
|
`,
|
2020-02-25 10:58:20 -06:00
|
|
|
tabBar: css`
|
2020-03-30 07:39:18 -05:00
|
|
|
padding-left: ${theme.spacing.md};
|
2020-02-25 10:58:20 -06:00
|
|
|
`,
|
2020-02-12 03:42:57 -06:00
|
|
|
tabContent: css`
|
|
|
|
padding: 0;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2020-02-09 08:39:46 -06:00
|
|
|
flex-grow: 1;
|
2020-02-12 03:42:57 -06:00
|
|
|
min-height: 0;
|
2020-03-24 04:30:53 -05:00
|
|
|
background: ${theme.colors.panelBg};
|
2020-03-30 07:39:18 -05:00
|
|
|
border-right: 1px solid ${theme.colors.pageHeaderBorder};
|
2020-02-12 03:42:57 -06:00
|
|
|
|
|
|
|
.toolbar {
|
|
|
|
background: transparent;
|
|
|
|
}
|
2020-02-09 08:39:46 -06:00
|
|
|
`,
|
|
|
|
};
|
|
|
|
});
|