From 62c96c7463ed7ac845b98cd397d4ac3f0f5dc007 Mon Sep 17 00:00:00 2001 From: Kenji Garland Date: Wed, 18 Sep 2019 16:49:59 -0400 Subject: [PATCH 1/3] Populate file rename field with current name by default (fixes #113) --- web/src/modal-get-name.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/web/src/modal-get-name.js b/web/src/modal-get-name.js index 46e6885..a9e5ed6 100644 --- a/web/src/modal-get-name.js +++ b/web/src/modal-get-name.js @@ -26,6 +26,7 @@ class ModalGetName extends Component { this.state = { showError: false, errorMessage: '', + newName: this.props.initialName, }; this.siblingNames = props.getSiblingNames(this.props.selectedResource); @@ -56,17 +57,21 @@ class ModalGetName extends Component { }; handleOnChange = () => { + const newName = this.textArea.value; if (this.siblingNames.has(this.textArea.value)) { this.setState({ errorMessage: 'name already in use', + newName, }); } else if (this.textArea.value.startsWith(".")) { this.setState({ - errorMessage: 'name cannot start with "."' + errorMessage: 'name cannot start with "."', + newName, }); } else { this.setState({ errorMessage: '', + newName, }); } }; @@ -74,14 +79,18 @@ class ModalGetName extends Component { isValidName = name => !this.siblingNames.has(name) && !name.startsWith("."); complete = choice => { - const name = this.textArea.value; + const name = this.state.newName; if (choice === 'ok' && !this.isValidName(name)) { // prevent completion if name is bad return; } - this.props.buttonAction(choice, this.textArea.value); + this.props.buttonAction(choice, this.state.newName); }; + componentDidMount() { + this.textArea.select(); + } + render() { return (
@@ -92,7 +101,7 @@ class ModalGetName extends Component {