@@ -47,13 +47,19 @@ export class FileNode extends React.Component {
47
47
} , 200 ) ;
48
48
}
49
49
50
+ getName ( ) {
51
+ const { updatedName, name } = this . props ;
52
+ return updatedName || name ;
53
+ }
54
+
50
55
handleFileClick ( e ) {
51
56
e . stopPropagation ( ) ;
52
- if ( this . props . name !== 'root' && ! this . isDeleting ) {
57
+ if ( this . getName ( ) !== 'root' && ! this . isDeleting ) {
53
58
this . props . setSelectedFile ( this . props . id ) ;
54
59
}
55
60
}
56
61
62
+
57
63
handleFileNameChange ( event ) {
58
64
this . props . updateFileName ( this . props . id , event . target . value ) ;
59
65
}
@@ -66,9 +72,9 @@ export class FileNode extends React.Component {
66
72
67
73
validateFileName ( ) {
68
74
const oldFileExtension = this . originalFileName . match ( / \. [ 0 - 9 a - z ] + $ / i) ;
69
- const newFileExtension = this . props . name . match ( / \. [ 0 - 9 a - z ] + $ / i) ;
70
- const hasPeriod = this . props . name . match ( / \. + / ) ;
71
- const newFileName = this . props . name ;
75
+ const newFileExtension = this . getName ( ) . match ( / \. [ 0 - 9 a - z ] + $ / i) ;
76
+ const hasPeriod = this . getName ( ) . match ( / \. + / ) ;
77
+ const newFileName = this . getName ( ) ;
72
78
const hasNoExtension = oldFileExtension && ! newFileExtension ;
73
79
const hasExtensionIfFolder = this . props . fileType === 'folder' && hasPeriod ;
74
80
const notSameExtension = oldFileExtension && newFileExtension
@@ -115,8 +121,8 @@ export class FileNode extends React.Component {
115
121
116
122
render ( ) {
117
123
const itemClass = classNames ( {
118
- 'sidebar__root-item' : this . props . name === 'root' ,
119
- 'sidebar__file-item' : this . props . name !== 'root' ,
124
+ 'sidebar__root-item' : this . getName ( ) === 'root' ,
125
+ 'sidebar__file-item' : this . getName ( ) !== 'root' ,
120
126
'sidebar__file-item--selected' : this . props . isSelectedFile ,
121
127
'sidebar__file-item--open' : this . state . isOptionsOpen ,
122
128
'sidebar__file-item--editing' : this . state . isEditingName ,
@@ -126,7 +132,7 @@ export class FileNode extends React.Component {
126
132
return (
127
133
< div className = { itemClass } >
128
134
{ ( ( ) => { // eslint-disable-line
129
- if ( this . props . name !== 'root' ) {
135
+ if ( this . getName ( ) !== 'root' ) {
130
136
return (
131
137
< div className = "file-item__content" onContextMenu = { this . toggleFileOptions } >
132
138
< span className = "file-item__spacer" > </ span >
@@ -155,11 +161,11 @@ export class FileNode extends React.Component {
155
161
</ div >
156
162
) ;
157
163
} ) ( ) }
158
- < button className = "sidebar__file-item-name" onClick = { this . handleFileClick } > { this . props . name } </ button >
164
+ < button className = "sidebar__file-item-name" onClick = { this . handleFileClick } > { this . getName ( ) } </ button >
159
165
< input
160
166
type = "text"
161
167
className = "sidebar__file-item-input"
162
- value = { this . props . name }
168
+ value = { this . getName ( ) }
163
169
maxLength = "128"
164
170
onChange = { this . handleFileNameChange }
165
171
ref = { ( element ) => { this . fileNameInput = element ; } }
@@ -225,7 +231,7 @@ export class FileNode extends React.Component {
225
231
< li >
226
232
< button
227
233
onClick = { ( ) => {
228
- this . originalFileName = this . props . name ;
234
+ this . originalFileName = this . getName ( ) ;
229
235
this . showEditFileName ( ) ;
230
236
setTimeout ( ( ) => this . fileNameInput . focus ( ) , 0 ) ;
231
237
setTimeout ( ( ) => this . hideFileOptions ( ) , 0 ) ;
@@ -240,7 +246,7 @@ export class FileNode extends React.Component {
240
246
< li >
241
247
< button
242
248
onClick = { ( ) => {
243
- if ( window . confirm ( `Are you sure you want to delete ${ this . props . name } ?` ) ) {
249
+ if ( window . confirm ( `Are you sure you want to delete ${ this . getName ( ) } ?` ) ) {
244
250
this . isDeleting = true ;
245
251
this . props . resetSelectedFile ( this . props . id ) ;
246
252
setTimeout ( ( ) => this . props . deleteFile ( this . props . id , this . props . parentId ) , 100 ) ;
@@ -278,6 +284,7 @@ FileNode.propTypes = {
278
284
parentId : PropTypes . string ,
279
285
children : PropTypes . arrayOf ( PropTypes . string . isRequired ) . isRequired ,
280
286
name : PropTypes . string . isRequired ,
287
+ updatedName : PropTypes . string ,
281
288
fileType : PropTypes . string . isRequired ,
282
289
isSelectedFile : PropTypes . bool ,
283
290
isFolderClosed : PropTypes . bool ,
@@ -295,7 +302,8 @@ FileNode.propTypes = {
295
302
FileNode . defaultProps = {
296
303
parentId : '0' ,
297
304
isSelectedFile : false ,
298
- isFolderClosed : false
305
+ isFolderClosed : false ,
306
+ updatedName : '' ,
299
307
} ;
300
308
301
309
function mapStateToProps ( state , ownProps ) {
0 commit comments