NewPageNameInputter.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. <SearchTypeahead
  42. crowi={this.crowi}
  43. onSearchError={this.onSearchError}
  44. emptyLabel={emptyLabel}
  45. placeholder="Input page name"
  46. keywordOnInit={this.getParentPageName(this.props.parentPageName)}
  47. />
  48. );
  49. }
  50. }
  51. NewPageNameInputter.propTypes = {
  52. crowi: PropTypes.object.isRequired,
  53. parentPageName: PropTypes.string,
  54. };
  55. NewPageNameInputter.defaultProps = {
  56. parentPageName: '',
  57. };