From d5745603f579d06ebc94bb0afa55a072004e2ee9 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Wed, 16 Aug 2017 14:36:09 -0700 Subject: [PATCH] Move SearchBar into separate file --- ui/src/hosts/components/HostsTable.js | 45 ++---------------------- ui/src/hosts/components/SearchBar.js | 49 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 43 deletions(-) create mode 100644 ui/src/hosts/components/SearchBar.js diff --git a/ui/src/hosts/components/HostsTable.js b/ui/src/hosts/components/HostsTable.js index bd0494272..5ed775c6a 100644 --- a/ui/src/hosts/components/HostsTable.js +++ b/ui/src/hosts/components/HostsTable.js @@ -1,9 +1,10 @@ import React, {PropTypes} from 'react' import {Link} from 'react-router' import _ from 'lodash' - import shallowCompare from 'react-addons-shallow-compare' import classnames from 'classnames' + +import SearchBar from 'src/hosts/components/SearchBar' import {HOSTS_TABLE} from 'src/hosts/constants/tableSizing' const {arrayOf, bool, number, shape, string} = PropTypes @@ -244,46 +245,4 @@ const HostRow = React.createClass({ }, }) -const SearchBar = React.createClass({ - propTypes: { - onSearch: PropTypes.func.isRequired, - }, - - getInitialState() { - return { - searchTerm: '', - } - }, - - componentWillMount() { - const waitPeriod = 300 - this.handleSearch = _.debounce(this.handleSearch, waitPeriod) - }, - - handleSearch() { - this.props.onSearch(this.state.searchTerm) - }, - - handleChange() { - this.setState({searchTerm: this.refs.searchInput.value}, this.handleSearch) - }, - - render() { - return ( -
- -
-
-
- ) - }, -}) - export default HostsTable diff --git a/ui/src/hosts/components/SearchBar.js b/ui/src/hosts/components/SearchBar.js new file mode 100644 index 000000000..bdefd5791 --- /dev/null +++ b/ui/src/hosts/components/SearchBar.js @@ -0,0 +1,49 @@ +import React, {PropTypes, Component} from 'react' +import _ from 'lodash' + +class SearchBar extends Component { + constructor(props) { + super(props) + this.state = { + searchTerm: '', + } + } + + componentWillMount() { + const waitPeriod = 300 + this.handleSearch = _.debounce(this.handleSearch, waitPeriod) + } + + handleSearch = () => { + this.props.onSearch(this.state.searchTerm) + } + + handleChange = () => { + this.setState({searchTerm: this.refs.searchInput.value}, this.handleSearch) + } + + render() { + return ( +
+ +
+
+
+ ) + } +} + +const {func} = PropTypes + +SearchBar.propTypes = { + onSearch: func.isRequired, +} + +export default SearchBar