NewPageNameInputter.js 1.3 KB

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