Skip to content

Commit

Permalink
Merge pull request monome#164 from synthetiv/feature/file-rename-modal
Browse files Browse the repository at this point in the history
File rename modal polish
  • Loading branch information
ngwese authored Sep 23, 2019
2 parents 0207db7 + 39c2940 commit 551e31b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions web/src/modal-get-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ModalGetName extends Component {
this.state = {
showError: false,
errorMessage: '',
newName: this.props.initialName,
};

this.siblingNames = props.getSiblingNames(this.props.selectedResource);
Expand Down Expand Up @@ -56,32 +57,40 @@ class ModalGetName extends Component {
};

handleOnChange = () => {
if (this.siblingNames.has(this.textArea.value)) {
const newName = this.textArea.value;
if (newName !== this.props.initialName && this.siblingNames.has(newName)) {
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,
});
}
};

isValidName = name => !this.siblingNames.has(name) && !name.startsWith(".");
isValidName = name => (name === this.props.initialName || !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 (
<div className="modal-content">
Expand All @@ -92,7 +101,7 @@ class ModalGetName extends Component {
<textarea
className="get-name-modal-text-area"
ref={e => (this.textArea = e)}
placeholder={this.props.initialName || ''}
value={this.state.newName || ''}
rows="1"
maxLength="128"
wrap="false"
Expand Down
1 change: 1 addition & 0 deletions web/src/model/edit-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const handleResourceRenameSuccess = (action, state) => {
activeBuffer,
rootNodes,
buffers,
activeNode: newResource,
};
};

Expand Down

0 comments on commit 551e31b

Please sign in to comment.