2018-08-27 15:27:09 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
|
|
|
|
import { MenuItem } from '@blueprintjs/core';
|
|
|
|
import { IItemRendererProps, Suggest } from '@blueprintjs/select';
|
|
|
|
|
|
|
|
import { selectInstance } from '../redux/actions';
|
|
|
|
import { IAppState, IInstance } from '../redux/types';
|
|
|
|
|
|
|
|
interface IInstanceSearchProps {
|
|
|
|
currentInstance: IInstance;
|
|
|
|
instances?: IInstance[];
|
|
|
|
selectInstance: (instanceName: string) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class InstanceSearchImpl extends React.Component<IInstanceSearchProps> {
|
2018-08-27 21:31:27 +00:00
|
|
|
|
2018-08-27 15:27:09 +00:00
|
|
|
public render() {
|
|
|
|
return (
|
|
|
|
<Suggest
|
|
|
|
inputValueRenderer={this.inputValueRenderer}
|
|
|
|
itemRenderer={this.itemRenderer}
|
2018-08-27 21:31:27 +00:00
|
|
|
items={this.props.instances || []}
|
2018-08-27 15:27:09 +00:00
|
|
|
onItemSelect={this.onItemSelect}
|
2018-08-27 21:31:27 +00:00
|
|
|
// itemListRenderer={this.itemListRenderer}
|
2018-08-27 15:27:09 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-08-27 21:31:27 +00:00
|
|
|
private inputValueRenderer = (item: IInstance): string => {
|
|
|
|
return item.name;
|
2018-08-27 15:27:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 21:31:27 +00:00
|
|
|
private itemRenderer = (item: IInstance, itemProps: IItemRendererProps): JSX.Element => {
|
|
|
|
return <MenuItem label={item.name} key={item.name} />;
|
2018-08-27 15:27:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 21:31:27 +00:00
|
|
|
private onItemSelect = (item: IInstance, event?: React.SyntheticEvent<HTMLElement>) => {
|
|
|
|
this.props.selectInstance(item.name);
|
2018-08-27 15:27:09 +00:00
|
|
|
}
|
2018-08-27 21:31:27 +00:00
|
|
|
|
|
|
|
// private itemListRenderer = (itemListProps: IItemListRendererProps<IInstance>): JSX.Element => {
|
|
|
|
// return (
|
|
|
|
// <List
|
|
|
|
// height={350}
|
|
|
|
// rowHeight={30}
|
|
|
|
// rowCount={(this.props.instances && this.props.instances.length) || 0}
|
|
|
|
// // tslint:disable-next-line
|
|
|
|
// rowRenderer={this.rowRenderer}
|
|
|
|
// width={214}
|
|
|
|
// />
|
|
|
|
// )
|
|
|
|
// }
|
|
|
|
|
|
|
|
// private rowRenderer = (listRowProps: ListRowProps) => {
|
|
|
|
// const instanceName = (this.props.instances && this.props.instances[listRowProps.index].name) || "";
|
|
|
|
// return <MenuItem label={instanceName} key={instanceName} />;
|
|
|
|
// }
|
2018-08-27 15:27:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state: IAppState) => ({
|
|
|
|
currentInstance: state.currentInstance,
|
|
|
|
instances: state.data.instances,
|
|
|
|
})
|
|
|
|
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
|
|
|
selectInstance: (instanceName: string) => dispatch(selectInstance(instanceName)),
|
|
|
|
})
|
|
|
|
export const InstanceSearch = connect(mapStateToProps, mapDispatchToProps)(InstanceSearchImpl)
|