@@ -31,6 +31,7 @@ export class FileNode extends React.Component {
3131 isOptionsOpen : false ,
3232 isEditingName : false ,
3333 isFocused : false ,
34+ updatedName : this . props . name
3435 } ;
3536 }
3637
@@ -48,8 +49,16 @@ export class FileNode extends React.Component {
4849 }
4950
5051 getName ( ) {
51- const { updatedName, name } = this . props ;
52- return updatedName || name ;
52+ return this . state . updatedName ;
53+ }
54+
55+ commitFileNameChange ( ) {
56+ const { updatedName } = this . state ;
57+ const { name, updateFileName, id } = this . props ;
58+
59+ if ( updatedName !== name ) {
60+ updateFileName ( id , updatedName ) ;
61+ }
5362 }
5463
5564 handleFileClick ( e ) {
@@ -59,9 +68,9 @@ export class FileNode extends React.Component {
5968 }
6069 }
6170
62-
6371 handleFileNameChange ( event ) {
64- this . props . updateFileName ( this . props . id , event . target . value , this . getName ( ) ) ;
72+ const newname = event . target . value ;
73+ this . setState ( { updatedName : newname } ) ;
6574 }
6675
6776 handleKeyPress ( event ) {
@@ -82,7 +91,7 @@ export class FileNode extends React.Component {
8291 const hasEmptyFilename = newFileName === '' ;
8392 const hasOnlyExtension = newFileExtension && newFileName === newFileExtension [ 0 ] ;
8493 if ( hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension || hasExtensionIfFolder ) {
85- this . props . updateFileName ( this . props . id , this . originalFileName , this . getName ( ) ) ;
94+ this . props . updateFileName ( this . props . id , this . originalFileName ) ;
8695 }
8796 }
8897
@@ -109,6 +118,7 @@ export class FileNode extends React.Component {
109118
110119 hideEditFileName ( ) {
111120 this . setState ( { isEditingName : false } ) ;
121+ this . commitFileNameChange ( ) ;
112122 }
113123
114124 renderChild ( childId ) {
@@ -284,7 +294,6 @@ FileNode.propTypes = {
284294 parentId : PropTypes . string ,
285295 children : PropTypes . arrayOf ( PropTypes . string . isRequired ) . isRequired ,
286296 name : PropTypes . string . isRequired ,
287- updatedName : PropTypes . string ,
288297 fileType : PropTypes . string . isRequired ,
289298 isSelectedFile : PropTypes . bool ,
290299 isFolderClosed : PropTypes . bool ,
@@ -303,7 +312,6 @@ FileNode.defaultProps = {
303312 parentId : '0' ,
304313 isSelectedFile : false ,
305314 isFolderClosed : false ,
306- updatedName : '' ,
307315} ;
308316
309317function mapStateToProps ( state , ownProps ) {
0 commit comments