|
@@ -1,66 +1,103 @@
|
|
|
-// This is the root component for #search-top
|
|
|
|
|
-
|
|
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
import { FormGroup, Button, InputGroup } from 'react-bootstrap';
|
|
import { FormGroup, Button, InputGroup } from 'react-bootstrap';
|
|
|
|
|
|
|
|
import { AsyncTypeahead } from 'react-bootstrap-typeahead';
|
|
import { AsyncTypeahead } from 'react-bootstrap-typeahead';
|
|
|
|
|
|
|
|
-import SearchForm from './HeaderSearchBox/SearchForm';
|
|
|
|
|
-// import SearchSuggest from './HeaderSearchBox/SearchSuggest'; // omit since using react-bootstrap-typeahead in SearchForm
|
|
|
|
|
-
|
|
|
|
|
|
|
+import UserPicture from './User/UserPicture';
|
|
|
|
|
+import PageListMeta from './PageList/PageListMeta';
|
|
|
import PagePath from './PageList/PagePath';
|
|
import PagePath from './PageList/PagePath';
|
|
|
-
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
+import SearchTypeahead from './SearchTypeahead';
|
|
|
|
|
|
|
|
-export default class NewPageNameInputter extends SearchForm {
|
|
|
|
|
|
|
+export default class NewPageNameInputter extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
|
|
+
|
|
|
super(props);
|
|
super(props);
|
|
|
|
|
|
|
|
- this.state.keyword = props.keyword
|
|
|
|
|
|
|
+ this.crowi = window.crowi; // FIXME
|
|
|
|
|
+
|
|
|
|
|
+ this.state = {
|
|
|
|
|
+ input: '',
|
|
|
|
|
+ keyword: '',
|
|
|
|
|
+ searchedKeyword: '',
|
|
|
|
|
+ pages: [],
|
|
|
|
|
+ isLoading: false,
|
|
|
|
|
+ searchError: null,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ this.crowi = window.crowi; // FIXME
|
|
|
|
|
+
|
|
|
|
|
+ this.onSearchSuccess = this.onSearchSuccess.bind(this);
|
|
|
|
|
+ this.onSearchError = this.onSearchError.bind(this);
|
|
|
|
|
+ this.restoreForm = this.restoreForm.bind(this);
|
|
|
|
|
+ this.renderMenuItemChildren = this.renderMenuItemChildren.bind(this);
|
|
|
|
|
+ this.onInputChange = this.onInputChange.bind(this);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ componentDidMount() {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ componentWillUnmount() {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onSearchSuccess(res) {
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ isLoading: false,
|
|
|
|
|
+ keyword: '',
|
|
|
|
|
+ pages: res.data,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onSearchError(err) {
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ isLoading: false,
|
|
|
|
|
+ searchError: err,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onInputChange(text) {
|
|
|
|
|
+ this.setState({input: text});
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ restoreForm() {
|
|
|
|
|
+ this._searchtypeahead._typeahead.getInstance().clear();
|
|
|
|
|
+ this._searchtypeahead._typeahead.getInstance().input = 'hoge';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ renderMenuItemChildren(option, props, index) {
|
|
|
|
|
+ const page = option;
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span>
|
|
|
|
|
+ <UserPicture user={page.revision.author} />
|
|
|
|
|
+ <PagePath page={page} />
|
|
|
|
|
+ <PageListMeta page={page} />
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
const emptyLabel = (this.state.searchError !== null)
|
|
const emptyLabel = (this.state.searchError !== null)
|
|
|
? 'Error on searching.'
|
|
? 'Error on searching.'
|
|
|
: 'No matches found on title...';
|
|
: 'No matches found on title...';
|
|
|
- const formClear = this.getFormClearComponent();
|
|
|
|
|
- const keyword = "hoge";
|
|
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <form
|
|
|
|
|
- action="/_search"
|
|
|
|
|
- className=""
|
|
|
|
|
- >
|
|
|
|
|
- <AsyncTypeahead
|
|
|
|
|
- ref={ref => this._typeahead = ref}
|
|
|
|
|
- inputProps={{name: "q", autoComplete: "off"}}
|
|
|
|
|
- isLoading={this.state.isLoading}
|
|
|
|
|
- labelKey="path"
|
|
|
|
|
- minLength={2}
|
|
|
|
|
- options={this.state.pages}
|
|
|
|
|
- placeholder="Input page name"
|
|
|
|
|
- emptyLabel={emptyLabel}
|
|
|
|
|
- align='left'
|
|
|
|
|
- submitFormOnEnter={true}
|
|
|
|
|
- onSearch={this.search}
|
|
|
|
|
- onInputChange={this.onInputChange}
|
|
|
|
|
- renderMenuItemChildren={this.renderMenuItemChildren}
|
|
|
|
|
- caseSensitive={false}
|
|
|
|
|
- keyword={keyword} // 検索キーワードを表示中のページの親ページにしたいがやり方不明。[TODO]
|
|
|
|
|
- />
|
|
|
|
|
- {formClear}
|
|
|
|
|
- <span>page: {this.state.keyword}</span> {/* 検索キーワードを表示デバッグ用 */ }
|
|
|
|
|
-
|
|
|
|
|
- </form>
|
|
|
|
|
-
|
|
|
|
|
|
|
+ <SearchTypeahead
|
|
|
|
|
+ ref={searchTypeahead => this._searchtypeahead = searchTypeahead}
|
|
|
|
|
+ crowi={this.crowi}
|
|
|
|
|
+ onSearchSuccess={this.onSearchSuccess}
|
|
|
|
|
+ onSearchError={this.onSearchError}
|
|
|
|
|
+ onResetButton={this.restoreForm}
|
|
|
|
|
+ emptyLabel={emptyLabel}
|
|
|
|
|
+ keywordOnInit={this.props.parentPageName}
|
|
|
|
|
+ />
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
NewPageNameInputter.propTypes = {
|
|
NewPageNameInputter.propTypes = {
|
|
|
- keyword: PropTypes.string.isRequired,
|
|
|
|
|
|
|
+ parentPageName: PropTypes.string.isRequired,
|
|
|
};
|
|
};
|
|
|
NewPageNameInputter.defaultProps = {
|
|
NewPageNameInputter.defaultProps = {
|
|
|
- keyword: "",
|
|
|
|
|
|
|
+ parentPageName: "",
|
|
|
};
|
|
};
|