From 6560d2e0e926adbdf1dd40bc9de01b3b2f8022ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 2 Apr 2020 13:56:20 +0200 Subject: [PATCH] NewPanelEdit: Adding variables to new panel editor (#23203) --- .../components/PanelEditor/PanelEditor.tsx | 35 ++++++++++++++++--- .../dashboard/containers/DashboardPage.tsx | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx index 6e2f21f55ac..cd199eabd58 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx @@ -26,6 +26,9 @@ import { getPanelEditorTabs } from './state/selectors'; import { getPanelStateById } from '../../state/selectors'; import { OptionsPaneContent } from './OptionsPaneContent'; import { DashNavButton } from 'app/features/dashboard/components/DashNav/DashNavButton'; +import { VariableModel } from 'app/features/templating/types'; +import { getVariables } from 'app/features/variables/state/selectors'; +import { SubMenuItems } from 'app/features/dashboard/components/SubMenu/SubMenuItems'; enum Pane { Right, @@ -45,6 +48,7 @@ interface ConnectedProps { initDone: boolean; tabs: PanelEditorTab[]; uiState: PanelEditorUIState; + variables: VariableModel[]; } interface DispatchProps { @@ -141,7 +145,7 @@ export class PanelEditorUnconnected extends PureComponent { updatePanelEditorUIState({ isPanelOptionsVisible: !uiState.isPanelOptionsVisible }); }; - renderHorizontalSplit(styles: any) { + renderHorizontalSplit(styles: EditorStyles) { const { dashboard, panel, tabs, data, uiState } = this.props; return ( @@ -158,6 +162,7 @@ export class PanelEditorUnconnected extends PureComponent { >
{this.renderToolbar(styles)} + {this.renderTemplateVariables(styles)}
{({ width, height }) => { @@ -189,7 +194,21 @@ export class PanelEditorUnconnected extends PureComponent { ); } - renderToolbar(styles: any) { + renderTemplateVariables(styles: EditorStyles) { + const { variables } = this.props; + + if (!variables.length) { + return null; + } + + return ( +
+ +
+ ); + } + + renderToolbar(styles: EditorStyles) { const { dashboard, location, uiState } = this.props; return ( @@ -230,7 +249,7 @@ export class PanelEditorUnconnected extends PureComponent { ); } - renderOptionsPane(styles: any) { + renderOptionsPane() { const { plugin, dashboard, data, panel } = this.props; if (!plugin) { @@ -251,7 +270,7 @@ export class PanelEditorUnconnected extends PureComponent { ); } - renderWithOptionsPane(styles: any) { + renderWithOptionsPane(styles: EditorStyles) { const { uiState } = this.props; return ( @@ -266,7 +285,7 @@ export class PanelEditorUnconnected extends PureComponent { onDragFinished={size => this.onDragFinished(Pane.Right, size)} > {this.renderHorizontalSplit(styles)} - {this.renderOptionsPane(styles)} + {this.renderOptionsPane()} ); } @@ -301,6 +320,7 @@ const mapStateToProps: MapStateToProps = ( initDone: state.panelEditorNew.initDone, tabs: getPanelEditorTabs(state.location, plugin), uiState: state.panelEditorNew.ui, + variables: getVariables(state), }; }; @@ -359,6 +379,9 @@ const getStyles = stylesFactory((theme: GrafanaTheme, props: Props) => { width: 100%; padding-right: ${uiState.isPanelOptionsVisible ? 0 : paneSpaceing}; `, + variablesWrapper: css` + padding: 0 ${theme.spacing.sm} ${theme.spacing.sm} ${paneSpaceing}; + `, panelWrapper: css` flex: 1 1 0; min-height: 0; @@ -417,3 +440,5 @@ const getStyles = stylesFactory((theme: GrafanaTheme, props: Props) => { `, }; }); + +type EditorStyles = ReturnType; diff --git a/public/app/features/dashboard/containers/DashboardPage.tsx b/public/app/features/dashboard/containers/DashboardPage.tsx index b2627135e71..b27eb150561 100644 --- a/public/app/features/dashboard/containers/DashboardPage.tsx +++ b/public/app/features/dashboard/containers/DashboardPage.tsx @@ -301,7 +301,7 @@ export class DashboardPage extends PureComponent {
{!getConfig().featureToggles.newVariables && } - {getConfig().featureToggles.newVariables && } + {!editPanel && getConfig().featureToggles.newVariables && }