2018-10-02 09:18:42 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { hot } from 'react-hot-loader';
|
2019-01-28 09:25:03 -06:00
|
|
|
import Page from 'app/core/components/Page/Page';
|
|
|
|
import { NavModel, Plugin, StoreState } from 'app/types';
|
2018-10-04 04:42:17 -05:00
|
|
|
import { addDataSource, loadDataSourceTypes, setDataSourceTypeSearchQuery } from './state/actions';
|
2018-10-02 09:18:42 -05:00
|
|
|
import { getNavModel } from 'app/core/selectors/navModel';
|
2018-10-04 04:42:17 -05:00
|
|
|
import { getDataSourceTypes } from './state/selectors';
|
2019-02-12 09:22:57 -06:00
|
|
|
import { FilterInput } from 'app/core/components/FilterInput/FilterInput';
|
2018-10-02 09:18:42 -05:00
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
navModel: NavModel;
|
2018-10-03 09:04:30 -05:00
|
|
|
dataSourceTypes: Plugin[];
|
2019-01-28 09:25:03 -06:00
|
|
|
isLoading: boolean;
|
2018-10-02 09:50:34 -05:00
|
|
|
addDataSource: typeof addDataSource;
|
2018-10-03 02:56:15 -05:00
|
|
|
loadDataSourceTypes: typeof loadDataSourceTypes;
|
2018-10-04 04:42:17 -05:00
|
|
|
dataSourceTypeSearchQuery: string;
|
|
|
|
setDataSourceTypeSearchQuery: typeof setDataSourceTypeSearchQuery;
|
2018-10-02 09:18:42 -05:00
|
|
|
}
|
|
|
|
|
2018-10-03 09:04:30 -05:00
|
|
|
class NewDataSourcePage extends PureComponent<Props> {
|
2018-10-03 02:56:15 -05:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.loadDataSourceTypes();
|
|
|
|
}
|
|
|
|
|
2019-01-28 09:25:03 -06:00
|
|
|
onDataSourceTypeClicked = (plugin: Plugin) => {
|
|
|
|
this.props.addDataSource(plugin);
|
2018-10-02 09:18:42 -05:00
|
|
|
};
|
|
|
|
|
2019-02-12 01:03:43 -06:00
|
|
|
onSearchQueryChange = (value: string) => {
|
|
|
|
this.props.setDataSourceTypeSearchQuery(value);
|
2018-10-04 04:42:17 -05:00
|
|
|
};
|
|
|
|
|
2018-10-02 09:18:42 -05:00
|
|
|
render() {
|
2019-01-28 09:25:03 -06:00
|
|
|
const { navModel, dataSourceTypes, dataSourceTypeSearchQuery, isLoading } = this.props;
|
2018-10-02 09:18:42 -05:00
|
|
|
return (
|
2019-01-28 09:25:03 -06:00
|
|
|
<Page navModel={navModel}>
|
|
|
|
<Page.Contents isLoading={isLoading}>
|
2019-02-12 05:49:40 -06:00
|
|
|
<h2 className="add-data-source-header">Choose data source type</h2>
|
|
|
|
<div className="add-data-source-search">
|
2019-02-12 09:47:57 -06:00
|
|
|
<FilterInput
|
|
|
|
labelClassName="gf-form--has-input-icon"
|
|
|
|
inputClassName="gf-form-input width-20"
|
|
|
|
value={dataSourceTypeSearchQuery}
|
|
|
|
onChange={this.onSearchQueryChange}
|
|
|
|
placeholder="Filter by name or type"
|
|
|
|
/>
|
2019-02-12 05:49:40 -06:00
|
|
|
</div>
|
|
|
|
<div className="add-data-source-grid">
|
|
|
|
{dataSourceTypes.map((plugin, index) => {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
onClick={() => this.onDataSourceTypeClicked(plugin)}
|
|
|
|
className="add-data-source-grid-item"
|
|
|
|
key={`${plugin.id}-${index}`}
|
|
|
|
>
|
|
|
|
<img className="add-data-source-grid-item-logo" src={plugin.info.logos.small} />
|
|
|
|
<span className="add-data-source-grid-item-text">{plugin.name}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
2018-10-03 09:04:30 -05:00
|
|
|
</div>
|
2019-01-28 09:25:03 -06:00
|
|
|
</Page.Contents>
|
|
|
|
</Page>
|
2018-10-02 09:18:42 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 09:25:03 -06:00
|
|
|
function mapStateToProps(state: StoreState) {
|
2018-10-02 09:18:42 -05:00
|
|
|
return {
|
|
|
|
navModel: getNavModel(state.navIndex, 'datasources'),
|
2018-10-04 04:42:17 -05:00
|
|
|
dataSourceTypes: getDataSourceTypes(state.dataSources),
|
2019-03-06 15:30:40 -06:00
|
|
|
dataSourceTypeSearchQuery: state.dataSources.dataSourceTypeSearchQuery,
|
2019-02-12 01:03:43 -06:00
|
|
|
isLoading: state.dataSources.isLoadingDataSources,
|
2018-10-02 09:18:42 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-02 09:50:34 -05:00
|
|
|
const mapDispatchToProps = {
|
|
|
|
addDataSource,
|
2018-10-03 02:56:15 -05:00
|
|
|
loadDataSourceTypes,
|
2018-10-04 04:42:17 -05:00
|
|
|
setDataSourceTypeSearchQuery,
|
2018-10-02 09:50:34 -05:00
|
|
|
};
|
|
|
|
|
2019-02-19 08:41:35 -06:00
|
|
|
export default hot(module)(
|
|
|
|
connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(NewDataSourcePage)
|
|
|
|
);
|