diff --git a/public/app/plugins/datasource/stackdriver/components/OptionPicker.tsx b/public/app/plugins/datasource/stackdriver/components/OptionPicker.tsx new file mode 100644 index 00000000000..f83777e5f79 --- /dev/null +++ b/public/app/plugins/datasource/stackdriver/components/OptionPicker.tsx @@ -0,0 +1,48 @@ +import React from 'react'; +// import SimplePicker from 'app/core/components/Picker/SimplePicker'; +import Select from 'react-select'; +// import DescriptionPicker from 'app/core/components/Picker/DescriptionPicker'; +import DescriptionOption from 'app/core/components/Picker/DescriptionOption'; +import IndicatorsContainer from 'app/core/components/Picker/IndicatorsContainer'; +import ResetStyles from 'app/core/components/Picker/ResetStyles'; +import NoOptionsMessage from 'app/core/components/Picker/NoOptionsMessage'; +import _ from 'lodash'; + +export interface Props { + onChange: (value: string) => void; + options: any[]; + selected: string; + placeholder?: string; + className?: string; +} + +export class OptionPicker extends React.Component { + constructor(props) { + super(props); + } + + render() { + const { onChange, options, selected, placeholder, className } = this.props; + const selectedOption = options.find(metric => metric.value === selected); + return ( + + +
+ +
Metric - +
diff --git a/public/app/plugins/datasource/stackdriver/query_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_ctrl.ts index c2607964456..3186a5e2012 100644 --- a/public/app/plugins/datasource/stackdriver/query_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/query_ctrl.ts @@ -2,6 +2,8 @@ import _ from 'lodash'; import { QueryCtrl } from 'app/plugins/sdk'; import './query_aggregation_ctrl'; import './query_filter_ctrl'; +import { OptionPicker } from './components/OptionPicker'; +import { react2AngularDirective } from 'app/core/utils/react2angular'; export interface QueryMeta { alignmentPeriod: string; @@ -64,6 +66,13 @@ export class StackdriverQueryCtrl extends QueryCtrl { _.defaultsDeep(this.target, this.defaults); this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope); this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope); + react2AngularDirective('optionPicker', OptionPicker, [ + 'options', + 'onChange', + 'selected', + 'className', + 'placeholder', + ]); } onDataReceived(dataList) { diff --git a/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts index 0f5dce559fd..7926da9aa1c 100644 --- a/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts @@ -59,6 +59,13 @@ export class StackdriverFilterCtrl { .then(this.getLabels.bind(this)); this.initSegments($scope.hideGroupBys); + this.handleMetricTypeChange = this.handleMetricTypeChange.bind(this); + this.handleServiceChange = this.handleServiceChange.bind(this); + } + + handleMetricTypeChange(value) { + this.metricType = value; + this.onMetricTypeChange(); } initSegments(hideGroupBys: boolean) { @@ -110,7 +117,7 @@ export class StackdriverFilterCtrl { const services = this.metricDescriptors.map(m => { return { value: m.service, - text: m.serviceShortName, + label: m.serviceShortName, }; }); @@ -128,7 +135,8 @@ export class StackdriverFilterCtrl { value: m.type, serviceShortName: m.serviceShortName, text: m.displayName, - title: m.description, + label: m.displayName, + description: m.description, }; }); @@ -167,8 +175,8 @@ export class StackdriverFilterCtrl { }); } - onServiceChange() { - this.target.service = this.service; + handleServiceChange(service) { + this.target.service = this.service = service; this.metrics = this.getMetricsList(); this.setMetricType(); this.getLabels();