瀏覽代碼

stackdriver: refactoring - rename react components and file structure changes

Erik Sundell 7 年之前
父節點
當前提交
33c9217cc9

+ 3 - 3
public/app/features/plugins/pluginTemplateQueryComponentLoader.tsx

@@ -6,10 +6,10 @@ import DefaultTemplateQueryCtrl from '../templating/defaultTemplateQueryCtrl';
 
 async function loadComponent(module) {
   const component = await importPluginModule(module);
-  if (!component.TemplateQueryCtrl) {
-    return DefaultTemplateQueryCtrl;
+  if (component && component.TemplateQueryComponent) {
+    return component.TemplateQueryComponent;
   } else {
-    return component.TemplateQueryCtrl;
+    return DefaultTemplateQueryCtrl;
   }
 }
 

+ 6 - 6
public/app/plugins/datasource/stackdriver/metricTypes.tsx → public/app/plugins/datasource/stackdriver/components/MetricTypeSelector.tsx

@@ -1,13 +1,13 @@
 import React, { SFC } from 'react';
 
 interface Props {
-  onMetricTypeChanged: any;
+  onMetricTypeChange: any;
   selectedService: string;
   metricDescriptors: any[];
 }
 
-const MetricTypes: SFC<Props> = props => {
-  const extractMetricTypes = () => {
+const MetricTypeSelector: SFC<Props> = props => {
+  const filterMetricTypes = () => {
     if (!props.selectedService) {
       return [];
     }
@@ -22,8 +22,8 @@ const MetricTypes: SFC<Props> = props => {
     <div className="gf-form max-width-21">
       <span className="gf-form-label width-7">Metric Types</span>
       <div className="gf-form-select-wrapper max-width-14">
-        <select className="gf-form-input" required onChange={props.onMetricTypeChanged}>
-          {extractMetricTypes().map((qt, i) => (
+        <select className="gf-form-input" required onChange={props.onMetricTypeChange}>
+          {filterMetricTypes().map((qt, i) => (
             <option key={i} value={qt.value} ng-if="false">
               {qt.name}
             </option>
@@ -34,4 +34,4 @@ const MetricTypes: SFC<Props> = props => {
   );
 };
 
-export default MetricTypes;
+export default MetricTypeSelector;

+ 2 - 2
public/app/plugins/datasource/stackdriver/services.tsx → public/app/plugins/datasource/stackdriver/components/ServiceSelector.tsx

@@ -6,7 +6,7 @@ interface Props {
   metricDescriptors: any[];
 }
 
-const Services: SFC<Props> = props => {
+const ServiceSelector: SFC<Props> = props => {
   const extractServices = () =>
     uniqBy(props.metricDescriptors, 'service').map(m => ({
       value: m.service,
@@ -29,4 +29,4 @@ const Services: SFC<Props> = props => {
   );
 };
 
-export default Services;
+export default ServiceSelector;

+ 16 - 14
public/app/plugins/datasource/stackdriver/templateQueryCtrl.tsx → public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx

@@ -1,15 +1,15 @@
 import React, { PureComponent } from 'react';
-import StackdriverDatasource from './datasource';
-import Services from './services';
-import MetricTypes from './metricTypes';
+import StackdriverDatasource from '../datasource';
+import ServiceSelector from './ServiceSelector';
+import MetricTypeSelector from './MetricTypeSelector';
 
 interface Props {
   datasource: StackdriverDatasource;
-  query: string;
+  query: any;
   onChange: (c: string) => void;
 }
 
-export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
+export class StackdriverTemplateQueryComponent extends PureComponent<Props, any> {
   queryTypes: Array<{ value: string; name: string }> = [
     { value: 'services', name: 'Services' },
     { value: 'metricTypes', name: 'Metric Types' },
@@ -18,9 +18,9 @@ export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
 
   constructor(props) {
     super(props);
-    this.handleChange = this.handleChange.bind(this);
+    this.handleQueryTypeChange = this.handleQueryTypeChange.bind(this);
     this.onServiceChange = this.onServiceChange.bind(this);
-    this.onMetricTypeChanged = this.onMetricTypeChanged.bind(this);
+    this.onMetricTypeChange = this.onMetricTypeChange.bind(this);
     this.state = { queryType: undefined, metricDescriptors: [], service: undefined, metricType: undefined };
   }
 
@@ -29,7 +29,7 @@ export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
     this.setState({ metricDescriptors });
   }
 
-  handleChange(event) {
+  handleQueryTypeChange(event) {
     this.setState({ queryType: event.target.value });
   }
 
@@ -37,22 +37,24 @@ export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
     this.setState({ service: event.target.value });
   }
 
-  onMetricTypeChanged(event) {
+  onMetricTypeChange(event) {
     this.setState({ metricType: event.target.value });
   }
 
   renderSwitch(queryType) {
     switch (queryType) {
       case 'metricTypes':
-        return <Services metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />;
+        return (
+          <ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
+        );
       case 'metricLabels':
         return (
           <React.Fragment>
-            <Services metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
-            <MetricTypes
+            <ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
+            <MetricTypeSelector
               selectedService={this.state.service}
               metricDescriptors={this.state.metricDescriptors}
-              onMetricTypeChanged={this.onMetricTypeChanged}
+              onMetricTypeChange={this.onMetricTypeChange}
             />
           </React.Fragment>
         );
@@ -67,7 +69,7 @@ export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
         <div className="gf-form max-width-21">
           <span className="gf-form-label width-7">Query Type</span>
           <div className="gf-form-select-wrapper max-width-14">
-            <select className="gf-form-input" required onChange={this.handleChange}>
+            <select className="gf-form-input" required onChange={this.handleQueryTypeChange}>
               {this.queryTypes.map((qt, i) => (
                 <option key={i} value={qt.value} ng-if="false">
                   {qt.name}

+ 2 - 2
public/app/plugins/datasource/stackdriver/module.ts

@@ -2,12 +2,12 @@ import StackdriverDatasource from './datasource';
 import { StackdriverQueryCtrl } from './query_ctrl';
 import { StackdriverConfigCtrl } from './config_ctrl';
 import { StackdriverAnnotationsQueryCtrl } from './annotations_query_ctrl';
-import { StackdriverTemplateQueryCtrl } from './templateQueryCtrl';
+import { StackdriverTemplateQueryComponent } from './components/TemplateQueryComponent';
 
 export {
   StackdriverDatasource as Datasource,
   StackdriverQueryCtrl as QueryCtrl,
   StackdriverConfigCtrl as ConfigCtrl,
   StackdriverAnnotationsQueryCtrl as AnnotationsQueryCtrl,
-  StackdriverTemplateQueryCtrl as TemplateQueryCtrl,
+  StackdriverTemplateQueryComponent as TemplateQueryComponent,
 };

+ 1 - 1
public/app/types/plugins.ts

@@ -6,7 +6,7 @@ export interface PluginExports {
   QueryCtrl?: any;
   ConfigCtrl?: any;
   AnnotationsQueryCtrl?: any;
-  TemplateQueryCtrl?: any;
+  TemplateQueryComponent?: any;
   ExploreQueryField?: any;
   ExploreStartPage?: any;