@@ -31,6 +31,7 @@ export class FileNode extends React.Component {
31
31
isOptionsOpen : false ,
32
32
isEditingName : false ,
33
33
isFocused : false ,
34
+ updatedName : this . props . name
34
35
} ;
35
36
}
36
37
@@ -48,8 +49,16 @@ export class FileNode extends React.Component {
48
49
}
49
50
50
51
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
+ }
53
62
}
54
63
55
64
handleFileClick ( e ) {
@@ -59,9 +68,9 @@ export class FileNode extends React.Component {
59
68
}
60
69
}
61
70
62
-
63
71
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 } ) ;
65
74
}
66
75
67
76
handleKeyPress ( event ) {
@@ -82,7 +91,7 @@ export class FileNode extends React.Component {
82
91
const hasEmptyFilename = newFileName === '' ;
83
92
const hasOnlyExtension = newFileExtension && newFileName === newFileExtension [ 0 ] ;
84
93
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 ) ;
86
95
}
87
96
}
88
97
@@ -109,6 +118,7 @@ export class FileNode extends React.Component {
109
118
110
119
hideEditFileName ( ) {
111
120
this . setState ( { isEditingName : false } ) ;
121
+ this . commitFileNameChange ( ) ;
112
122
}
113
123
114
124
renderChild ( childId ) {
@@ -284,7 +294,6 @@ FileNode.propTypes = {
284
294
parentId : PropTypes . string ,
285
295
children : PropTypes . arrayOf ( PropTypes . string . isRequired ) . isRequired ,
286
296
name : PropTypes . string . isRequired ,
287
- updatedName : PropTypes . string ,
288
297
fileType : PropTypes . string . isRequired ,
289
298
isSelectedFile : PropTypes . bool ,
290
299
isFolderClosed : PropTypes . bool ,
@@ -303,7 +312,6 @@ FileNode.defaultProps = {
303
312
parentId : '0' ,
304
313
isSelectedFile : false ,
305
314
isFolderClosed : false ,
306
- updatedName : '' ,
307
315
} ;
308
316
309
317
function mapStateToProps ( state , ownProps ) {
0 commit comments