Commit 6560d2e0 by Torkel Ödegaard Committed by GitHub

NewPanelEdit: Adding variables to new panel editor (#23203)

parent 7e85e4d0
...@@ -26,6 +26,9 @@ import { getPanelEditorTabs } from './state/selectors'; ...@@ -26,6 +26,9 @@ import { getPanelEditorTabs } from './state/selectors';
import { getPanelStateById } from '../../state/selectors'; import { getPanelStateById } from '../../state/selectors';
import { OptionsPaneContent } from './OptionsPaneContent'; import { OptionsPaneContent } from './OptionsPaneContent';
import { DashNavButton } from 'app/features/dashboard/components/DashNav/DashNavButton'; 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 { enum Pane {
Right, Right,
...@@ -45,6 +48,7 @@ interface ConnectedProps { ...@@ -45,6 +48,7 @@ interface ConnectedProps {
initDone: boolean; initDone: boolean;
tabs: PanelEditorTab[]; tabs: PanelEditorTab[];
uiState: PanelEditorUIState; uiState: PanelEditorUIState;
variables: VariableModel[];
} }
interface DispatchProps { interface DispatchProps {
...@@ -141,7 +145,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> { ...@@ -141,7 +145,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> {
updatePanelEditorUIState({ isPanelOptionsVisible: !uiState.isPanelOptionsVisible }); updatePanelEditorUIState({ isPanelOptionsVisible: !uiState.isPanelOptionsVisible });
}; };
renderHorizontalSplit(styles: any) { renderHorizontalSplit(styles: EditorStyles) {
const { dashboard, panel, tabs, data, uiState } = this.props; const { dashboard, panel, tabs, data, uiState } = this.props;
return ( return (
...@@ -158,6 +162,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> { ...@@ -158,6 +162,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> {
> >
<div className={styles.mainPaneWrapper}> <div className={styles.mainPaneWrapper}>
{this.renderToolbar(styles)} {this.renderToolbar(styles)}
{this.renderTemplateVariables(styles)}
<div className={styles.panelWrapper}> <div className={styles.panelWrapper}>
<AutoSizer> <AutoSizer>
{({ width, height }) => { {({ width, height }) => {
...@@ -189,7 +194,21 @@ export class PanelEditorUnconnected extends PureComponent<Props> { ...@@ -189,7 +194,21 @@ export class PanelEditorUnconnected extends PureComponent<Props> {
); );
} }
renderToolbar(styles: any) { renderTemplateVariables(styles: EditorStyles) {
const { variables } = this.props;
if (!variables.length) {
return null;
}
return (
<div className={styles.variablesWrapper}>
<SubMenuItems variables={variables} />
</div>
);
}
renderToolbar(styles: EditorStyles) {
const { dashboard, location, uiState } = this.props; const { dashboard, location, uiState } = this.props;
return ( return (
...@@ -230,7 +249,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> { ...@@ -230,7 +249,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> {
); );
} }
renderOptionsPane(styles: any) { renderOptionsPane() {
const { plugin, dashboard, data, panel } = this.props; const { plugin, dashboard, data, panel } = this.props;
if (!plugin) { if (!plugin) {
...@@ -251,7 +270,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> { ...@@ -251,7 +270,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> {
); );
} }
renderWithOptionsPane(styles: any) { renderWithOptionsPane(styles: EditorStyles) {
const { uiState } = this.props; const { uiState } = this.props;
return ( return (
...@@ -266,7 +285,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> { ...@@ -266,7 +285,7 @@ export class PanelEditorUnconnected extends PureComponent<Props> {
onDragFinished={size => this.onDragFinished(Pane.Right, size)} onDragFinished={size => this.onDragFinished(Pane.Right, size)}
> >
{this.renderHorizontalSplit(styles)} {this.renderHorizontalSplit(styles)}
{this.renderOptionsPane(styles)} {this.renderOptionsPane()}
</SplitPane> </SplitPane>
); );
} }
...@@ -301,6 +320,7 @@ const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = ( ...@@ -301,6 +320,7 @@ const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (
initDone: state.panelEditorNew.initDone, initDone: state.panelEditorNew.initDone,
tabs: getPanelEditorTabs(state.location, plugin), tabs: getPanelEditorTabs(state.location, plugin),
uiState: state.panelEditorNew.ui, uiState: state.panelEditorNew.ui,
variables: getVariables(state),
}; };
}; };
...@@ -359,6 +379,9 @@ const getStyles = stylesFactory((theme: GrafanaTheme, props: Props) => { ...@@ -359,6 +379,9 @@ const getStyles = stylesFactory((theme: GrafanaTheme, props: Props) => {
width: 100%; width: 100%;
padding-right: ${uiState.isPanelOptionsVisible ? 0 : paneSpaceing}; padding-right: ${uiState.isPanelOptionsVisible ? 0 : paneSpaceing};
`, `,
variablesWrapper: css`
padding: 0 ${theme.spacing.sm} ${theme.spacing.sm} ${paneSpaceing};
`,
panelWrapper: css` panelWrapper: css`
flex: 1 1 0; flex: 1 1 0;
min-height: 0; min-height: 0;
...@@ -417,3 +440,5 @@ const getStyles = stylesFactory((theme: GrafanaTheme, props: Props) => { ...@@ -417,3 +440,5 @@ const getStyles = stylesFactory((theme: GrafanaTheme, props: Props) => {
`, `,
}; };
}); });
type EditorStyles = ReturnType<typeof getStyles>;
...@@ -301,7 +301,7 @@ export class DashboardPage extends PureComponent<Props, State> { ...@@ -301,7 +301,7 @@ export class DashboardPage extends PureComponent<Props, State> {
<div className={gridWrapperClasses}> <div className={gridWrapperClasses}>
{!getConfig().featureToggles.newVariables && <AngularSubMenu dashboard={dashboard} />} {!getConfig().featureToggles.newVariables && <AngularSubMenu dashboard={dashboard} />}
{getConfig().featureToggles.newVariables && <SubMenu dashboard={dashboard} />} {!editPanel && getConfig().featureToggles.newVariables && <SubMenu dashboard={dashboard} />}
<DashboardGrid <DashboardGrid
dashboard={dashboard} dashboard={dashboard}
isEditing={isEditing} isEditing={isEditing}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment