refactored panel-option-section into react component

This commit is contained in:
Torkel Ödegaard
2018-12-14 08:34:54 +01:00
parent ec035d6847
commit 0823712c9a
5 changed files with 80 additions and 56 deletions

View File

@@ -1,6 +1,10 @@
// Libraries
import React, { PureComponent } from 'react';
// Components
import CustomScrollbar from 'app/core/components/CustomScrollbar/CustomScrollbar';
import { FadeIn } from 'app/core/components/Animations/FadeIn';
import { PanelOptionSection } from './PanelOptionSection';
interface Props {
children: JSX.Element;
@@ -89,15 +93,9 @@ export class EditorTabBody extends PureComponent<Props, State> {
renderOpenView(view: EditorToolBarView) {
return (
<div className="panel-option-section">
<div className="panel-option-section__header">
{view.title || view.heading}
<button className="btn btn-link" onClick={this.onCloseOpenView}>
<i className="fa fa-remove" />
</button>
</div>
<div className="panel-option-section__body">{view.render(this.onCloseOpenView)}</div>
</div>
<PanelOptionSection title={view.title || view.heading} onClose={this.onCloseOpenView}>
{view.render()}
</PanelOptionSection>
);
}

View File

@@ -0,0 +1,26 @@
// Libraries
import React, { SFC } from 'react';
interface Props {
title?: string;
onClose?: () => void;
children: JSX.Element | JSX.Element[];
}
export const PanelOptionSection: SFC<Props> = props => {
return (
<div className="panel-option-section">
{props.title && (
<div className="panel-option-section__header">
{props.title}
{props.onClose && (
<button className="btn btn-link" onClick={props.onClose}>
<i className="fa fa-remove" />
</button>
)}
</div>
)}
<div className="panel-option-section__body">{props.children}</div>
</div>
);
};

View File

@@ -10,6 +10,7 @@ import { DataSourcePicker } from './DataSourcePicker';
import { QueryInspector } from './QueryInspector';
import { QueryOptions } from './QueryOptions';
import { AngularQueryComponentScope } from 'app/features/panel/metrics_tab';
import { PanelOptionSection } from './PanelOptionSection';
// Services
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
@@ -256,37 +257,31 @@ export class QueriesTab extends PureComponent<Props, State> {
return (
<EditorTabBody heading="Queries" renderToolbar={this.renderToolbar} toolbarItems={[queryInspector, dsHelp]}>
<>
<div className="panel-option-section">
{/*<div className="panel-option-section__header">Queries</div>*/}
<div className="panel-option-section__body">
<div className="query-editor-rows gf-form-group">
<div ref={element => (this.element = element)} />
<PanelOptionSection>
<div className="query-editor-rows gf-form-group">
<div ref={element => (this.element = element)} />
<div className="gf-form-query">
<div className="gf-form gf-form-query-letter-cell">
<label className="gf-form-label">
<span className="gf-form-query-letter-cell-carret muted">
<i className="fa fa-caret-down" />
</span>
<span className="gf-form-query-letter-cell-letter">{panel.getNextQueryLetter()}</span>
</label>
{!isAddingMixed && (
<button className="btn btn-secondary gf-form-btn" onClick={this.onAddQueryClick}>
Add Query
</button>
)}
{isAddingMixed && this.renderMixedPicker()}
</div>
<div className="gf-form-query">
<div className="gf-form gf-form-query-letter-cell">
<label className="gf-form-label">
<span className="gf-form-query-letter-cell-carret muted">
<i className="fa fa-caret-down" />
</span>
<span className="gf-form-query-letter-cell-letter">{panel.getNextQueryLetter()}</span>
</label>
{!isAddingMixed && (
<button className="btn btn-secondary gf-form-btn" onClick={this.onAddQueryClick}>
Add Query
</button>
)}
{isAddingMixed && this.renderMixedPicker()}
</div>
</div>
</div>
</div>
<div className="panel-option-section">
{/*<div className="panel-option-section__header">Options</div>*/}
<div className="panel-option-section__body">
<QueryOptions panel={panel} datasource={currentDS} />
</div>
</div>
</PanelOptionSection>
<PanelOptionSection>
<QueryOptions panel={panel} datasource={currentDS} />
</PanelOptionSection>
</>
</EditorTabBody>
);

View File

@@ -8,6 +8,7 @@ import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoa
import { EditorTabBody } from './EditorTabBody';
import { VizTypePicker } from './VizTypePicker';
import { FadeIn } from 'app/core/components/Animations/FadeIn';
import { PanelOptionSection } from './PanelOptionSection';
// Types
import { PanelModel } from '../panel_model';
@@ -59,11 +60,15 @@ export class VisualizationTab extends PureComponent<Props, State> {
return <div ref={element => (this.element = element)} />;
}
if (PanelOptions) {
return <PanelOptions options={this.getPanelDefaultOptions()} onChange={this.onPanelOptionsChanged} />;
} else {
return <p>Visualization has no options</p>;
}
return (
<PanelOptionSection>
{PanelOptions ? (
<PanelOptions options={this.getPanelDefaultOptions()} onChange={this.onPanelOptionsChanged} />
) : (
<p>Visualization has no options</p>
)}
</PanelOptionSection>
);
}
componentDidMount() {

View File

@@ -12,17 +12,17 @@ exports[`Render should render alpha info text 1`] = `
<form
onSubmit={[Function]}
>
<div
className="grafana-info-box"
>
This plugin is marked as being in alpha state, which means it is in early development phase and updates will include breaking changes.
</div>
<BasicSettings
dataSourceName="gdev-cloudwatch"
isDefault={false}
onDefaultChange={[Function]}
onNameChange={[Function]}
/>
<div
className="grafana-info-box"
>
This plugin is marked as being in alpha state, which means it is in early development phase and updates will include breaking changes.
</div>
<PluginSettings
dataSource={
Object {
@@ -111,17 +111,17 @@ exports[`Render should render beta info text 1`] = `
<form
onSubmit={[Function]}
>
<div
className="grafana-info-box"
>
This plugin is marked as being in a beta development state. This means it is in currently in active development and could be missing important features.
</div>
<BasicSettings
dataSourceName="gdev-cloudwatch"
isDefault={false}
onDefaultChange={[Function]}
onNameChange={[Function]}
/>
<div
className="grafana-info-box"
>
This plugin is marked as being in a beta development state. This means it is in currently in active development and could be missing important features.
</div>
<PluginSettings
dataSource={
Object {
@@ -304,17 +304,17 @@ exports[`Render should render is ready only message 1`] = `
<form
onSubmit={[Function]}
>
<div
className="grafana-info-box span8"
>
This datasource was added by config and cannot be modified using the UI. Please contact your server admin to update this datasource.
</div>
<BasicSettings
dataSourceName="gdev-cloudwatch"
isDefault={false}
onDefaultChange={[Function]}
onNameChange={[Function]}
/>
<div
className="grafana-info-box span8"
>
This datasource was added by config and cannot be modified using the UI. Please contact your server admin to update this datasource.
</div>
<PluginSettings
dataSource={
Object {