stackdriver: cleanup

pull/14007/head
Erik Sundell 7 years ago
parent a46b9cb0bb
commit b3c34be648
  1. 8
      public/app/plugins/datasource/stackdriver/StackdriverMetricFindQuery.ts
  2. 4
      public/app/plugins/datasource/stackdriver/components/SimpleSelect.tsx
  3. 20
      public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx
  4. 2
      public/app/plugins/datasource/stackdriver/functions.ts

@ -1,13 +1,13 @@
import has from 'lodash/has';
import isString from 'lodash/isString';
import { alignmentPeriods } from './constants';
import { MetricFindQueryTypes } from './types';
import { import {
extractServicesFromMetricDescriptors, extractServicesFromMetricDescriptors,
getMetricTypesByService, getMetricTypesByService,
getAlignmentOptionsByMetric, getAlignmentOptionsByMetric,
getAggregationOptionsByMetric, getAggregationOptionsByMetric,
} from './functions'; } from './functions';
import { alignmentPeriods } from './constants';
import has from 'lodash/has';
import isString from 'lodash/isString';
import { MetricFindQueryTypes } from './types';
export default class StackdriverMetricFindQuery { export default class StackdriverMetricFindQuery {
constructor(private datasource) {} constructor(private datasource) {}

@ -7,7 +7,7 @@ interface Props {
label: string; label: string;
} }
const SimpleDropdown: SFC<Props> = props => { const SimpleSelect: SFC<Props> = props => {
const { label, onValueChange, value, options } = props; const { label, onValueChange, value, options } = props;
return ( return (
<div className="gf-form max-width-21"> <div className="gf-form max-width-21">
@ -25,4 +25,4 @@ const SimpleDropdown: SFC<Props> = props => {
); );
}; };
export default SimpleDropdown; export default SimpleSelect;

@ -1,8 +1,8 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import SimpleDropdown from './SimpleDropdown';
import { TemplateQueryProps } from 'app/types/plugins'; import { TemplateQueryProps } from 'app/types/plugins';
import { getMetricTypes, extractServicesFromMetricDescriptors } from '../functions';
import defaultsDeep from 'lodash/defaultsDeep'; import defaultsDeep from 'lodash/defaultsDeep';
import SimpleSelect from './SimpleSelect';
import { getMetricTypes, extractServicesFromMetricDescriptors } from '../functions';
import { MetricFindQueryTypes, TemplateQueryComponentData } from '../types'; import { MetricFindQueryTypes, TemplateQueryComponentData } from '../types';
export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQueryProps, TemplateQueryComponentData> { export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQueryProps, TemplateQueryComponentData> {
@ -109,7 +109,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
const refId = 'StackdriverTemplateQueryComponent'; const refId = 'StackdriverTemplateQueryComponent';
const response = await this.props.datasource.getLabels(selectedMetricType, refId); const response = await this.props.datasource.getLabels(selectedMetricType, refId);
const labels = Object.keys(response.meta[selectedQueryType]); const labels = Object.keys(response.meta[selectedQueryType]);
const labelKey = labels.indexOf(this.state.labelKey) !== -1 ? this.state.labelKey : labels[0]; const labelKey = labels.some(l => l === this.state.labelKey) ? this.state.labelKey : labels[0];
result = { labels, labelKey }; result = { labels, labelKey };
} }
return result; return result;
@ -119,7 +119,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
switch (queryType) { switch (queryType) {
case MetricFindQueryTypes.MetricTypes: case MetricFindQueryTypes.MetricTypes:
return ( return (
<SimpleDropdown <SimpleSelect
value={this.state.selectedService} value={this.state.selectedService}
options={this.state.services} options={this.state.services}
onValueChange={this.onServiceChange} onValueChange={this.onServiceChange}
@ -131,19 +131,19 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
case MetricFindQueryTypes.ResourceTypes: case MetricFindQueryTypes.ResourceTypes:
return ( return (
<React.Fragment> <React.Fragment>
<SimpleDropdown <SimpleSelect
value={this.state.selectedService} value={this.state.selectedService}
options={this.state.services} options={this.state.services}
onValueChange={this.onServiceChange} onValueChange={this.onServiceChange}
label="Services" label="Services"
/> />
<SimpleDropdown <SimpleSelect
value={this.state.selectedMetricType} value={this.state.selectedMetricType}
options={this.state.metricTypes} options={this.state.metricTypes}
onValueChange={this.onMetricTypeChange} onValueChange={this.onMetricTypeChange}
label="Metric Types" label="Metric Types"
/> />
<SimpleDropdown <SimpleSelect
value={this.state.labelKey} value={this.state.labelKey}
options={this.state.labels.map(l => ({ value: l, name: l }))} options={this.state.labels.map(l => ({ value: l, name: l }))}
onValueChange={this.onLabelKeyChange} onValueChange={this.onLabelKeyChange}
@ -159,13 +159,13 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
case MetricFindQueryTypes.Aggregations: case MetricFindQueryTypes.Aggregations:
return ( return (
<React.Fragment> <React.Fragment>
<SimpleDropdown <SimpleSelect
value={this.state.selectedService} value={this.state.selectedService}
options={this.state.services} options={this.state.services}
onValueChange={this.onServiceChange} onValueChange={this.onServiceChange}
label="Services" label="Services"
/> />
<SimpleDropdown <SimpleSelect
value={this.state.selectedMetricType} value={this.state.selectedMetricType}
options={this.state.metricTypes} options={this.state.metricTypes}
onValueChange={this.onMetricTypeChange} onValueChange={this.onMetricTypeChange}
@ -181,7 +181,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
render() { render() {
return ( return (
<React.Fragment> <React.Fragment>
<SimpleDropdown <SimpleSelect
value={this.state.selectedQueryType} value={this.state.selectedQueryType}
options={this.queryTypes} options={this.queryTypes}
onValueChange={this.handleQueryTypeChange} onValueChange={this.handleQueryTypeChange}

@ -1,5 +1,5 @@
import { alignOptions, aggOptions } from './constants';
import uniqBy from 'lodash/uniqBy'; import uniqBy from 'lodash/uniqBy';
import { alignOptions, aggOptions } from './constants';
export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(metricDescriptors, 'service'); export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(metricDescriptors, 'service');

Loading…
Cancel
Save