NewPageNameInputter.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React from 'react';
  2. import { FormGroup, Button, InputGroup } from 'react-bootstrap';
  3. import UserPicture from './User/UserPicture';
  4. import PageListMeta from './PageList/PageListMeta';
  5. import PagePath from './PageList/PagePath';
  6. import PropTypes from 'prop-types';
  7. import SearchTypeahead from './SearchTypeahead';
  8. export default class NewPageNameInputter extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. searchError: null,
  13. };
  14. this.crowi = this.props.crowi;
  15. this.onSearchError = this.onSearchError.bind(this);
  16. this.getParentPageName = this.getParentPageName.bind(this);
  17. }
  18. componentDidMount() {
  19. }
  20. componentWillUnmount() {
  21. }
  22. onSearchError(err) {
  23. this.setState({
  24. searchError: err,
  25. });
  26. }
  27. getParentPageName(path) {
  28. if (path == '/') {
  29. return path;
  30. }
  31. if (path.match(/.+\/$/)) {
  32. return path;
  33. }
  34. return path + '/';
  35. }
  36. render() {
  37. const emptyLabel = (this.state.searchError !== null)
  38. ? 'Error on searching.'
  39. : 'No matches found on title...';
  40. return (
  41. <form
  42. action="/_search"
  43. className=""
  44. >
  45. <SearchTypeahead
  46. crowi={this.crowi}
  47. onSearchError={this.onSearchError}
  48. emptyLabel={emptyLabel}
  49. placeholder="Input page name"
  50. keywordOnInit={this.getParentPageName(this.props.parentPageName)}
  51. />
  52. </form>
  53. );
  54. }
  55. }
  56. NewPageNameInputter.propTypes = {
  57. crowi: PropTypes.object.isRequired,
  58. parentPageName: PropTypes.string,
  59. };
  60. NewPageNameInputter.defaultProps = {
  61. parentPageName: '',
  62. };