NewPageNameInputter.js 1.6 KB

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