1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

120 lines
2.7 KiB
React
Raw Normal View History

2017-05-16 13:34:00 +02:00
2017-06-26 15:35:54 +02:00
/*
* Alice (Prefix-)Lookup
*/
2018-09-17 15:35:46 +02:00
import {debounce} from 'underscore'
2017-05-16 13:34:00 +02:00
import React from 'react'
import {connect} from 'react-redux'
2018-09-17 15:35:46 +02:00
import {replace} from 'react-router-redux'
2017-05-16 13:34:00 +02:00
2018-09-17 15:35:46 +02:00
import {setLookupQueryValue} from './actions'
2017-06-26 15:35:54 +02:00
import LookupResults from './results'
2018-09-17 15:35:46 +02:00
import SearchInput from 'components/search-input'
2017-06-26 15:35:54 +02:00
2018-10-02 10:28:25 +02:00
import QuickLinks from 'components/routeservers/routes/quick-links'
2017-07-03 10:47:08 +02:00
class LookupHelp extends React.Component {
render() {
if(this.props.query != '') {
return null;
}
return (
<div className="lookup-help">
<h3>Did you know?</h3>
<p>You can search for</p>
<ul>
2018-03-21 15:12:57 +01:00
<li><b>Prefixes</b>,</li>
2017-07-03 10:47:08 +02:00
<li><b>Peers</b> by entering their name and</li>
<li><b>ASNs</b> by prefixing them with 'AS'</li>
</ul>
<p>Just start typing!</p>
</div>
);
}
}
2017-06-26 15:35:54 +02:00
class Lookup extends React.Component {
2018-09-17 15:35:46 +02:00
constructor(props) {
super(props);
this.debouncedDispatch = debounce(this.props.dispatch, 400);
}
2017-06-26 15:35:54 +02:00
doLookup(q) {
2018-10-01 15:12:26 +02:00
// Make path
const destination = {
pathname: "/search",
search: `?q=${q}`
};
2018-10-23 20:00:42 +02:00
2018-09-17 15:35:46 +02:00
// Set lookup params
this.props.dispatch(setLookupQueryValue(q));
2018-10-01 15:12:26 +02:00
this.debouncedDispatch(replace(destination));
2017-06-26 15:35:54 +02:00
}
2017-07-03 10:47:08 +02:00
componentDidMount() {
// this is yucky but the debounced
// search input seems to kill the ref=
let input = document.getElementById('lookup-search-input');
input.focus();
2018-09-17 15:35:46 +02:00
let value = input.value;
input.value = "";
input.value = value;
2017-07-03 10:47:08 +02:00
}
2017-06-26 15:35:54 +02:00
render() {
return (
<div className="lookup-container">
<div className="card">
<SearchInput
2018-09-17 15:35:46 +02:00
ref="searchInput"
2017-07-03 10:47:08 +02:00
id="lookup-search-input"
2018-09-17 15:35:46 +02:00
value={this.props.queryValue}
2018-03-21 15:12:57 +01:00
placeholder="Search for prefixes, peers or ASNs on all route servers"
2017-06-26 15:35:54 +02:00
onChange={(e) => this.doLookup(e.target.value)} />
</div>
2018-10-02 10:28:25 +02:00
<QuickLinks routes={this.props.routes}
excludeNotExported={true} />
2017-07-03 10:47:08 +02:00
<LookupHelp query={this.props.query} />
2017-06-26 15:35:54 +02:00
<LookupResults />
</div>
)
}
2017-05-16 13:34:00 +02:00
}
export default connect(
2017-06-26 15:35:54 +02:00
(state) => {
2018-10-02 10:28:25 +02:00
const lookup = state.lookup;
2017-06-26 15:35:54 +02:00
return {
2018-10-02 10:28:25 +02:00
query: state.lookup.query,
queryValue: state.lookup.queryValue,
isLoading: state.lookup.isLoading,
error: state.lookup.error,
routes: {
filtered: {
2018-10-23 20:00:42 +02:00
loading: lookup.isLoading,
2018-10-02 10:28:25 +02:00
totalResults: lookup.totalRoutesFiltered,
},
received: {
2018-10-23 20:00:42 +02:00
loading: lookup.isLoading,
2018-10-02 10:28:25 +02:00
totalResults: lookup.totalRoutesImported,
},
notExported: {
loading: false,
totalResults: 0,
}
}
2017-06-26 15:35:54 +02:00
}
}
)(Lookup);
2017-05-16 13:34:00 +02:00