import React from 'react'; import PropTypes from 'prop-types'; import { createSubscribedElement } from './UnstatedUtils'; import AppContainer from '../services/AppContainer'; import SearchTypeahead from './SearchTypeahead'; // SearchTypeahead wrapper class SearchForm extends React.Component { constructor(props) { super(props); this.state = { searchError: null, }; this.onSearchError = this.onSearchError.bind(this); this.onChange = this.onChange.bind(this); } componentDidMount() { } componentWillUnmount() { } onSearchError(err) { this.setState({ searchError: err, }); } onChange(selected) { const page = selected[0]; // should be single page selected // navigate to page if (page != null) { window.location = page.path; } } getHelpElement() { const { t, appContainer } = this.props; const config = appContainer.getConfig(); const isReachable = config.isSearchServiceReachable; if (!isReachable) { return ( <>
Error occured on Search Service
Try to reconnect from management page. ); } return (
{ t('search_help.title') }
word1 word2

({ t('search_help.and.syntax help') })
{ t('search_help.and.desc', { word1: 'word1', word2: 'word2' }) }
"This is GROWI"

({ t('search_help.phrase.syntax help') })
{ t('search_help.phrase.desc', { phrase: 'This is GROWI' }) }
-keyword
{ t('search_help.exclude.desc', { word: 'keyword' }) }
prefix:/user/
{ t('search_help.prefix.desc', { path: '/user/' }) }
-prefix:/user/
{ t('search_help.exclude_prefix.desc', { path: '/user/' }) }
tag:wiki
{ t('search_help.tag.desc', { tag: 'wiki' }) }
-tag:wiki
{ t('search_help.exclude_tag.desc', { tag: 'wiki' }) }
); } render() { const { t, appContainer } = this.props; const config = appContainer.getConfig(); const isReachable = config.isSearchServiceReachable; const placeholder = isReachable ? 'Search ...' : 'Error on Search Service'; const emptyLabel = (this.state.searchError !== null) ? 'Error on searching.' : t('search.search page bodies'); return ( ); } } /** * Wrapper component for using unstated */ const SearchFormWrapper = (props) => { return createSubscribedElement(SearchForm, props, [AppContainer]); }; SearchForm.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, keyword: PropTypes.string, onSubmit: PropTypes.func.isRequired, onInputChange: PropTypes.func, }; SearchForm.defaultProps = { onInputChange: () => {}, }; export default SearchFormWrapper;