Parcourir la source

stackdriver: extract variables for pickers

Erik Sundell il y a 7 ans
Parent
commit
2780ef27fd

+ 35 - 42
public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx

@@ -115,62 +115,55 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
     return result;
     return result;
   }
   }
 
 
+  servicePicker = (
+    <SimpleSelect
+      value={this.state.selectedService}
+      options={this.state.services}
+      onValueChange={this.onServiceChange}
+      label="Services"
+    />
+  );
+
+  metricTypesPicker = (
+    <SimpleSelect
+      value={this.state.selectedMetricType}
+      options={this.state.metricTypes}
+      onValueChange={this.onMetricTypeChange}
+      label="Metric Types"
+    />
+  );
+
+  labelPicker = (
+    <SimpleSelect
+      value={this.state.labelKey}
+      options={this.state.labels.map(l => ({ value: l, name: l }))}
+      onValueChange={this.onLabelKeyChange}
+      label={
+        this.state.selectedQueryType === MetricFindQueryTypes.ResourceLabels ? 'Resource Label Key' : 'Metric Label Key'
+      }
+    />
+  );
+
   renderQueryTypeSwitch(queryType) {
   renderQueryTypeSwitch(queryType) {
     switch (queryType) {
     switch (queryType) {
       case MetricFindQueryTypes.MetricTypes:
       case MetricFindQueryTypes.MetricTypes:
-        return (
-          <SimpleSelect
-            value={this.state.selectedService}
-            options={this.state.services}
-            onValueChange={this.onServiceChange}
-            label="Services"
-          />
-        );
+        return this.servicePicker;
       case MetricFindQueryTypes.MetricLabels:
       case MetricFindQueryTypes.MetricLabels:
       case MetricFindQueryTypes.ResourceLabels:
       case MetricFindQueryTypes.ResourceLabels:
       case MetricFindQueryTypes.ResourceTypes:
       case MetricFindQueryTypes.ResourceTypes:
         return (
         return (
           <React.Fragment>
           <React.Fragment>
-            <SimpleSelect
-              value={this.state.selectedService}
-              options={this.state.services}
-              onValueChange={this.onServiceChange}
-              label="Services"
-            />
-            <SimpleSelect
-              value={this.state.selectedMetricType}
-              options={this.state.metricTypes}
-              onValueChange={this.onMetricTypeChange}
-              label="Metric Types"
-            />
-            <SimpleSelect
-              value={this.state.labelKey}
-              options={this.state.labels.map(l => ({ value: l, name: l }))}
-              onValueChange={this.onLabelKeyChange}
-              label={
-                this.state.selectedQueryType === MetricFindQueryTypes.ResourceLabels
-                  ? 'Resource Label Key'
-                  : 'Metric Label Key'
-              }
-            />
+            {this.servicePicker}
+            {this.metricTypesPicker}
+            {queryType !== MetricFindQueryTypes.ResourceTypes && this.labelPicker}
           </React.Fragment>
           </React.Fragment>
         );
         );
       case MetricFindQueryTypes.Alignerns:
       case MetricFindQueryTypes.Alignerns:
       case MetricFindQueryTypes.Aggregations:
       case MetricFindQueryTypes.Aggregations:
         return (
         return (
           <React.Fragment>
           <React.Fragment>
-            <SimpleSelect
-              value={this.state.selectedService}
-              options={this.state.services}
-              onValueChange={this.onServiceChange}
-              label="Services"
-            />
-            <SimpleSelect
-              value={this.state.selectedMetricType}
-              options={this.state.metricTypes}
-              onValueChange={this.onMetricTypeChange}
-              label="Metric Types"
-            />
+            {this.servicePicker}
+            {this.metricTypesPicker}
           </React.Fragment>
           </React.Fragment>
         );
         );
       default:
       default: