This repository was archived by the owner on Jan 27, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +26
-34
lines changed Expand file tree Collapse file tree 3 files changed +26
-34
lines changed Original file line number Diff line number Diff line change @@ -54,34 +54,28 @@ class NestedEditableDemo extends React.Component {
54
54
} )
55
55
}
56
56
handleCreateFiles = ( files , prefix ) => {
57
- this . setState ( state => {
57
+ this . setState ( prevState => {
58
58
const newFiles = files . map ( ( file ) => {
59
59
let newKey = prefix
60
60
if ( prefix !== '' && prefix . substring ( prefix . length - 1 , prefix . length ) !== '/' ) {
61
61
newKey += '/'
62
62
}
63
+ const invalidChar = [ '/' , '\\' ]
64
+ if ( invalidChar . some ( char => file . name . indexOf ( char ) !== - 1 ) ) return
63
65
newKey += file . name
64
66
return {
65
67
key : newKey ,
66
68
size : file . size ,
67
69
modified : + Moment ( ) ,
68
70
}
69
71
} )
70
-
71
72
const uniqueNewFiles = [ ]
72
- newFiles . map ( ( newFile ) => {
73
- let exists = false
74
- state . files . map ( ( existingFile ) => {
75
- if ( existingFile . key === newFile . key ) {
76
- exists = true
77
- }
78
- } )
79
- if ( ! exists ) {
80
- uniqueNewFiles . push ( newFile )
81
- }
73
+ newFiles . forEach ( ( newFile ) => {
74
+ const exists = prevState . files . some ( existingFile => ( existingFile . key === newFile . key ) )
75
+ if ( ! exists ) uniqueNewFiles . push ( newFile )
82
76
} )
83
- state . files = state . files . concat ( uniqueNewFiles )
84
- return state
77
+ const updatedFiles = [ ... prevState . files , uniqueNewFiles ]
78
+ return { files : updatedFiles }
85
79
} )
86
80
}
87
81
handleRenameFolder = ( oldKey , newKey ) => {
Original file line number Diff line number Diff line change @@ -65,7 +65,6 @@ class BaseFile extends React.Component {
65
65
66
66
handleFileClick = ( event ) => {
67
67
event && event . preventDefault ( )
68
-
69
68
this . props . browserProps . preview ( {
70
69
url : this . props . url ,
71
70
name : this . getName ( ) ,
@@ -109,15 +108,14 @@ class BaseFile extends React.Component {
109
108
// })
110
109
return
111
110
}
112
- if ( newName . indexOf ( '/' ) !== - 1 ) {
113
- // todo: move to props handler
114
- // window.notify({
115
- // style: 'error',
116
- // title: 'Invalid new file name',
117
- // body: 'File names cannot contain forward slashes.',
118
- // })
119
- return
120
- }
111
+ const invalidChar = [ '/' , '\\' ]
112
+ if ( invalidChar . some ( char => newName . indexOf ( char ) !== - 1 ) ) return
113
+ // todo: move to props handler
114
+ // window.notify({
115
+ // style: 'error',
116
+ // title: 'Invalid new file name',
117
+ // body: 'File names cannot contain forward slashes.',
118
+ // })
121
119
let newKey = newName
122
120
const slashIndex = this . props . fileKey . lastIndexOf ( '/' )
123
121
if ( slashIndex !== - 1 ) {
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ class BaseFolder extends React.Component {
80
80
}
81
81
handleNewNameChange = ( event ) => {
82
82
const newName = this . newNameRef . value
83
- this . setState ( { newName : newName } )
83
+ this . setState ( { newName : newName } )
84
84
}
85
85
handleRenameSubmit = ( event ) => {
86
86
event . preventDefault ( )
@@ -97,15 +97,15 @@ class BaseFolder extends React.Component {
97
97
// })
98
98
return
99
99
}
100
- if ( newName . indexOf ( '/' ) !== - 1 ) {
101
- // todo: move to props handler
102
- // window.notify({
103
- // style: 'error',
104
- // title : 'Invalid new folder name ',
105
- // body : 'Folder names cannot contain forward slashes. ',
106
- // })
107
- return
108
- }
100
+ const invalidChar = [ '/' , '\\' ]
101
+ if ( invalidChar . some ( char => newName . indexOf ( char ) !== - 1 ) ) return
102
+ // todo: move to props handler
103
+ // window.notify({
104
+ // style : 'error ',
105
+ // title : 'Invalid new folder name ',
106
+ // body: 'Folder names cannot contain forward slashes.',
107
+ // })
108
+
109
109
let newKey = this . props . fileKey . substr ( 0 , this . props . fileKey . substr ( 0 , this . props . fileKey . length - 1 ) . lastIndexOf ( '/' ) )
110
110
if ( newKey . length ) {
111
111
newKey += '/'
You can’t perform that action at this time.
0 commit comments