Sfoglia il codice sorgente

refactored panel-option-section into react component

Torkel Ödegaard 7 anni fa
parent
commit
0823712c9a

+ 7 - 9
public/app/features/dashboard/dashgrid/EditorTabBody.tsx

@@ -1,6 +1,10 @@
+// Libraries
 import React, { PureComponent } from 'react';
 import React, { PureComponent } from 'react';
+
+// Components
 import CustomScrollbar from 'app/core/components/CustomScrollbar/CustomScrollbar';
 import CustomScrollbar from 'app/core/components/CustomScrollbar/CustomScrollbar';
 import { FadeIn } from 'app/core/components/Animations/FadeIn';
 import { FadeIn } from 'app/core/components/Animations/FadeIn';
+import { PanelOptionSection } from './PanelOptionSection';
 
 
 interface Props {
 interface Props {
   children: JSX.Element;
   children: JSX.Element;
@@ -89,15 +93,9 @@ export class EditorTabBody extends PureComponent<Props, State> {
 
 
   renderOpenView(view: EditorToolBarView) {
   renderOpenView(view: EditorToolBarView) {
     return (
     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>
     );
     );
   }
   }
 
 

+ 26 - 0
public/app/features/dashboard/dashgrid/PanelOptionSection.tsx

@@ -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>
+  );
+};

+ 23 - 28
public/app/features/dashboard/dashgrid/QueriesTab.tsx

@@ -10,6 +10,7 @@ import { DataSourcePicker } from './DataSourcePicker';
 import { QueryInspector } from './QueryInspector';
 import { QueryInspector } from './QueryInspector';
 import { QueryOptions } from './QueryOptions';
 import { QueryOptions } from './QueryOptions';
 import { AngularQueryComponentScope } from 'app/features/panel/metrics_tab';
 import { AngularQueryComponentScope } from 'app/features/panel/metrics_tab';
+import { PanelOptionSection } from './PanelOptionSection';
 
 
 // Services
 // Services
 import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
 import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
@@ -256,37 +257,31 @@ export class QueriesTab extends PureComponent<Props, State> {
     return (
     return (
       <EditorTabBody heading="Queries" renderToolbar={this.renderToolbar} toolbarItems={[queryInspector, dsHelp]}>
       <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)} />
-
-                <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>
+          <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>
               </div>
               </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>
       </EditorTabBody>
     );
     );

+ 10 - 5
public/app/features/dashboard/dashgrid/VisualizationTab.tsx

@@ -8,6 +8,7 @@ import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoa
 import { EditorTabBody } from './EditorTabBody';
 import { EditorTabBody } from './EditorTabBody';
 import { VizTypePicker } from './VizTypePicker';
 import { VizTypePicker } from './VizTypePicker';
 import { FadeIn } from 'app/core/components/Animations/FadeIn';
 import { FadeIn } from 'app/core/components/Animations/FadeIn';
+import { PanelOptionSection } from './PanelOptionSection';
 
 
 // Types
 // Types
 import { PanelModel } from '../panel_model';
 import { PanelModel } from '../panel_model';
@@ -59,11 +60,15 @@ export class VisualizationTab extends PureComponent<Props, State> {
       return <div ref={element => (this.element = element)} />;
       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() {
   componentDidMount() {

+ 15 - 15
public/app/features/datasources/settings/__snapshots__/DataSourceSettings.test.tsx.snap

@@ -12,17 +12,17 @@ exports[`Render should render alpha info text 1`] = `
       <form
       <form
         onSubmit={[Function]}
         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
         <BasicSettings
           dataSourceName="gdev-cloudwatch"
           dataSourceName="gdev-cloudwatch"
           isDefault={false}
           isDefault={false}
           onDefaultChange={[Function]}
           onDefaultChange={[Function]}
           onNameChange={[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
         <PluginSettings
           dataSource={
           dataSource={
             Object {
             Object {
@@ -111,17 +111,17 @@ exports[`Render should render beta info text 1`] = `
       <form
       <form
         onSubmit={[Function]}
         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
         <BasicSettings
           dataSourceName="gdev-cloudwatch"
           dataSourceName="gdev-cloudwatch"
           isDefault={false}
           isDefault={false}
           onDefaultChange={[Function]}
           onDefaultChange={[Function]}
           onNameChange={[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
         <PluginSettings
           dataSource={
           dataSource={
             Object {
             Object {
@@ -304,17 +304,17 @@ exports[`Render should render is ready only message 1`] = `
       <form
       <form
         onSubmit={[Function]}
         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
         <BasicSettings
           dataSourceName="gdev-cloudwatch"
           dataSourceName="gdev-cloudwatch"
           isDefault={false}
           isDefault={false}
           onDefaultChange={[Function]}
           onDefaultChange={[Function]}
           onNameChange={[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
         <PluginSettings
           dataSource={
           dataSource={
             Object {
             Object {