import React from 'react'; import PropTypes from 'prop-types'; import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Form, FormGroup, Label, Col, FormText } from 'reactstrap'; import { gettext } from '../../utils/constants'; const propTypes = { fileType: PropTypes.string, parentPath: PropTypes.string.isRequired, onAddFile: PropTypes.func.isRequired, addFileCancel: PropTypes.func.isRequired, }; class CreateFile extends React.Component { constructor(props) { super(props); this.state = { parentPath: '', childName: props.fileType, }; this.newInput = React.createRef(); } handleChange = (e) => { this.setState({ childName: e.target.value, }) ; } handleSubmit = () => { let path = this.state.parentPath + this.state.childName; this.props.onAddFile(path); } handleKeyPress = (e) => { if (e.key === 'Enter') { this.handleSubmit(); } } toggle = () => { this.props.addFileCancel(); } componentDidMount() { if (this.props.parentPath === '/') { this.setState({parentPath: this.props.parentPath}); } else { this.setState({parentPath: this.props.parentPath + '/'}); } this.newInput.focus(); this.newInput.setSelectionRange(0,0); } render() { return ( {gettext('New File')}
{this.state.parentPath} {this.newInput = input;}} id="fileName" placeholder={gettext('newName')} value={this.state.childName} onChange={this.handleChange}/>
); } } CreateFile.propTypes = propTypes; export default CreateFile;