diff --git a/public/app/plugins/datasource/stackdriver/components/OptionGroupPicker.tsx b/public/app/plugins/datasource/stackdriver/components/OptionGroupPicker.tsx deleted file mode 100644 index f7863dd2a16..00000000000 --- a/public/app/plugins/datasource/stackdriver/components/OptionGroupPicker.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import React from 'react'; -import Select from 'react-select'; -import _ from 'lodash'; - -import GroupHeading from 'app/core/components/Picker/GroupHeading'; -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'; - -export interface Props { - onChange: (value: string) => void; - groups: any[]; - searchable: boolean; - selected: string; - placeholder?: string; - className?: string; -} - -export class OptionGroupPicker extends React.Component { - constructor(props) { - super(props); - } - - render() { - const { onChange, groups, selected, placeholder, className, searchable } = this.props; - const options = _.flatten(groups.map(o => o.options)); - const selectedOption = options.find(option => option.value === selected); - - return ( - onChange(option.value)} - getOptionValue={i => i.value} - getOptionLabel={i => i.label} - value={selectedOption} - noOptionsMessage={() => 'No metrics found'} - /> - ); - } -} diff --git a/public/app/plugins/datasource/stackdriver/components/StackdriverPicker.tsx b/public/app/plugins/datasource/stackdriver/components/StackdriverPicker.tsx new file mode 100644 index 00000000000..b2c447feeff --- /dev/null +++ b/public/app/plugins/datasource/stackdriver/components/StackdriverPicker.tsx @@ -0,0 +1,53 @@ +import React from 'react'; +import _ from 'lodash'; +import Select from 'app/core/components/Select/Select'; + +export interface Props { + onChange: (value: string) => void; + options: any[]; + searchable: boolean; + selected: string; + placeholder?: string; + className?: string; + groups?: boolean; +} + +export class StackdriverPicker extends React.Component { + constructor(props) { + super(props); + } + + extractOptions(options) { + return options.length > 0 && options.every(o => o.options) ? _.flatten(options.map(o => o.options)) : options; + } + + onChange = item => { + const extractedOptions = this.extractOptions(this.props.options); + const option = extractedOptions.find(option => option.value === item.value); + this.props.onChange(option.value); + }; + + render() { + const { options, selected, placeholder, className, searchable } = this.props; + const extractedOptions = this.extractOptions(options); + const selectedOption = extractedOptions.find(option => option.value === selected); + + return ( +