mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Wrap react select component in angular directive
This commit is contained in:
parent
3c6bcde8b2
commit
73b5bc680f
@ -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<Props, any> {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { onChange, options, selected, placeholder, className } = this.props;
|
||||||
|
const selectedOption = options.find(metric => metric.value === selected);
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
placeholder={placeholder}
|
||||||
|
classNamePrefix={`gf-form-select-box`}
|
||||||
|
className={className}
|
||||||
|
options={options}
|
||||||
|
components={{
|
||||||
|
Option: DescriptionOption,
|
||||||
|
IndicatorsContainer,
|
||||||
|
NoOptionsMessage,
|
||||||
|
}}
|
||||||
|
styles={ResetStyles}
|
||||||
|
isDisabled={false}
|
||||||
|
onChange={option => onChange(option.value)}
|
||||||
|
getOptionValue={i => i.value}
|
||||||
|
getOptionLabel={i => i.label}
|
||||||
|
value={selectedOption}
|
||||||
|
noOptionsMessage={() => 'No metrics found'}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +1,26 @@
|
|||||||
<div class="gf-form-inline">
|
<div class="gf-form-inline">
|
||||||
<div class="gf-form">
|
<div class="gf-form">
|
||||||
<span class="gf-form-label width-9 query-keyword">Service</span>
|
<span class="gf-form-label width-9 query-keyword">Service</span>
|
||||||
<select
|
<option-picker
|
||||||
class="gf-form-input width-12"
|
onChange="ctrl.handleServiceChange"
|
||||||
ng-model="ctrl.service"
|
selected="ctrl.service"
|
||||||
ng-options="f.value as f.text for f in ctrl.services"
|
options="ctrl.services"
|
||||||
ng-change="ctrl.onServiceChange(ctrl.service)"
|
placeholder="ctrl.defaultDropdownValue"
|
||||||
></select>
|
className="width-12"
|
||||||
|
></option-picker>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="gf-form gf-form--grow"><div class="gf-form-label gf-form-label--grow"></div></div>
|
||||||
|
</div>
|
||||||
|
<div class="gf-form-inline">
|
||||||
<div class="gf-form">
|
<div class="gf-form">
|
||||||
<span class="gf-form-label width-9 query-keyword">Metric</span>
|
<span class="gf-form-label width-9 query-keyword">Metric</span>
|
||||||
<gf-form-dropdown
|
<option-picker
|
||||||
model="ctrl.metricType"
|
onChange="ctrl.handleMetricTypeChange"
|
||||||
get-options="ctrl.metrics"
|
selected="ctrl.metricType"
|
||||||
class="min-width-20"
|
options="ctrl.metrics"
|
||||||
disabled
|
placeholder="ctrl.defaultDropdownValue"
|
||||||
type="text"
|
className="width-12"
|
||||||
allow-custom="true"
|
></option-picker>
|
||||||
lookup-text="true"
|
|
||||||
css-class="min-width-12"
|
|
||||||
on-change="ctrl.onMetricTypeChange()"
|
|
||||||
></gf-form-dropdown>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="gf-form gf-form--grow"><div class="gf-form-label gf-form-label--grow"></div></div>
|
<div class="gf-form gf-form--grow"><div class="gf-form-label gf-form-label--grow"></div></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,6 +2,8 @@ import _ from 'lodash';
|
|||||||
import { QueryCtrl } from 'app/plugins/sdk';
|
import { QueryCtrl } from 'app/plugins/sdk';
|
||||||
import './query_aggregation_ctrl';
|
import './query_aggregation_ctrl';
|
||||||
import './query_filter_ctrl';
|
import './query_filter_ctrl';
|
||||||
|
import { OptionPicker } from './components/OptionPicker';
|
||||||
|
import { react2AngularDirective } from 'app/core/utils/react2angular';
|
||||||
|
|
||||||
export interface QueryMeta {
|
export interface QueryMeta {
|
||||||
alignmentPeriod: string;
|
alignmentPeriod: string;
|
||||||
@ -64,6 +66,13 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
|||||||
_.defaultsDeep(this.target, this.defaults);
|
_.defaultsDeep(this.target, this.defaults);
|
||||||
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
|
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
|
||||||
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
|
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
|
||||||
|
react2AngularDirective('optionPicker', OptionPicker, [
|
||||||
|
'options',
|
||||||
|
'onChange',
|
||||||
|
'selected',
|
||||||
|
'className',
|
||||||
|
'placeholder',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDataReceived(dataList) {
|
onDataReceived(dataList) {
|
||||||
|
@ -59,6 +59,13 @@ export class StackdriverFilterCtrl {
|
|||||||
.then(this.getLabels.bind(this));
|
.then(this.getLabels.bind(this));
|
||||||
|
|
||||||
this.initSegments($scope.hideGroupBys);
|
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) {
|
initSegments(hideGroupBys: boolean) {
|
||||||
@ -110,7 +117,7 @@ export class StackdriverFilterCtrl {
|
|||||||
const services = this.metricDescriptors.map(m => {
|
const services = this.metricDescriptors.map(m => {
|
||||||
return {
|
return {
|
||||||
value: m.service,
|
value: m.service,
|
||||||
text: m.serviceShortName,
|
label: m.serviceShortName,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -128,7 +135,8 @@ export class StackdriverFilterCtrl {
|
|||||||
value: m.type,
|
value: m.type,
|
||||||
serviceShortName: m.serviceShortName,
|
serviceShortName: m.serviceShortName,
|
||||||
text: m.displayName,
|
text: m.displayName,
|
||||||
title: m.description,
|
label: m.displayName,
|
||||||
|
description: m.description,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -167,8 +175,8 @@ export class StackdriverFilterCtrl {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onServiceChange() {
|
handleServiceChange(service) {
|
||||||
this.target.service = this.service;
|
this.target.service = this.service = service;
|
||||||
this.metrics = this.getMetricsList();
|
this.metrics = this.getMetricsList();
|
||||||
this.setMetricType();
|
this.setMetricType();
|
||||||
this.getLabels();
|
this.getLabels();
|
||||||
|
Loading…
Reference in New Issue
Block a user