|
@@ -2,13 +2,14 @@ import React, { PureComponent } from 'react';
|
|
|
import classNames from 'classnames';
|
|
import classNames from 'classnames';
|
|
|
import _ from 'lodash';
|
|
import _ from 'lodash';
|
|
|
|
|
|
|
|
-import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
|
|
|
|
import { DataSourceSelectItem } from 'app/types';
|
|
import { DataSourceSelectItem } from 'app/types';
|
|
|
|
|
|
|
|
-interface Props {}
|
|
|
|
|
|
|
+interface Props {
|
|
|
|
|
+ onChangeDataSource: (ds: any) => void;
|
|
|
|
|
+ datasources: DataSourceSelectItem[];
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
interface State {
|
|
interface State {
|
|
|
- datasources: DataSourceSelectItem[];
|
|
|
|
|
searchQuery: string;
|
|
searchQuery: string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -17,31 +18,32 @@ export class DataSourcePicker extends PureComponent<Props, State> {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
|
-
|
|
|
|
|
this.state = {
|
|
this.state = {
|
|
|
- datasources: getDatasourceSrv().getMetricSources(),
|
|
|
|
|
searchQuery: '',
|
|
searchQuery: '',
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
getDataSources() {
|
|
getDataSources() {
|
|
|
- const { datasources, searchQuery } = this.state;
|
|
|
|
|
|
|
+ const { searchQuery } = this.state;
|
|
|
const regex = new RegExp(searchQuery, 'i');
|
|
const regex = new RegExp(searchQuery, 'i');
|
|
|
|
|
+ const { datasources } = this.props;
|
|
|
|
|
|
|
|
const filtered = datasources.filter(item => {
|
|
const filtered = datasources.filter(item => {
|
|
|
return regex.test(item.name) || regex.test(item.meta.name);
|
|
return regex.test(item.name) || regex.test(item.meta.name);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- return _.sortBy(filtered, 'sort');
|
|
|
|
|
|
|
+ return filtered;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- renderDataSource = (ds: DataSourceSelectItem, index) => {
|
|
|
|
|
|
|
+ renderDataSource = (ds: DataSourceSelectItem, index: number) => {
|
|
|
|
|
+ const { onChangeDataSource } = this.props;
|
|
|
|
|
+ const onClick = () => onChangeDataSource(ds);
|
|
|
const cssClass = classNames({
|
|
const cssClass = classNames({
|
|
|
'ds-picker-list__item': true,
|
|
'ds-picker-list__item': true,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <div key={index} className={cssClass} title={ds.name}>
|
|
|
|
|
|
|
+ <div key={index} className={cssClass} title={ds.name} onClick={onClick}>
|
|
|
<img className="ds-picker-list__img" src={ds.meta.info.logos.small} />
|
|
<img className="ds-picker-list__img" src={ds.meta.info.logos.small} />
|
|
|
<div className="ds-picker-list__name">{ds.name}</div>
|
|
<div className="ds-picker-list__name">{ds.name}</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -54,7 +56,16 @@ export class DataSourcePicker extends PureComponent<Props, State> {
|
|
|
}, 300);
|
|
}, 300);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ onSearchQueryChange = evt => {
|
|
|
|
|
+ const value = evt.target.value;
|
|
|
|
|
+ this.setState(prevState => ({
|
|
|
|
|
+ ...prevState,
|
|
|
|
|
+ searchQuery: value,
|
|
|
|
|
+ }));
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
renderFilters() {
|
|
renderFilters() {
|
|
|
|
|
+ const { searchQuery } = this.state;
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
<label className="gf-form--has-input-icon">
|
|
<label className="gf-form--has-input-icon">
|
|
@@ -63,6 +74,8 @@ export class DataSourcePicker extends PureComponent<Props, State> {
|
|
|
className="gf-form-input width-13"
|
|
className="gf-form-input width-13"
|
|
|
placeholder=""
|
|
placeholder=""
|
|
|
ref={elem => (this.searchInput = elem)}
|
|
ref={elem => (this.searchInput = elem)}
|
|
|
|
|
+ onChange={this.onSearchQueryChange}
|
|
|
|
|
+ value={searchQuery}
|
|
|
/>
|
|
/>
|
|
|
<i className="gf-form-input-icon fa fa-search" />
|
|
<i className="gf-form-input-icon fa fa-search" />
|
|
|
</label>
|
|
</label>
|