@@ -25,12 +25,18 @@ import { Node } from "./types";
25
25
interface FileSystemManagerProps {
26
26
path : string ;
27
27
nodes : Node [ ] ;
28
+ oldName : string ;
29
+ newName : string ;
30
+ renameOpen : boolean ;
31
+ onNewNameChange : ( ) => ( event : ChangeEvent < HTMLInputElement > ) => Promise < void > ;
32
+ onCloseRenameModal : ( ) => ( ) => Promise < void > ;
28
33
onFileUpload : (
29
34
isText : boolean
30
35
) => ( event : ChangeEvent < HTMLInputElement > ) => Promise < void > ;
31
36
onDirClick : ( name : string ) => ( ) => Promise < void > ;
32
37
onFileClick : ( name : string ) => ( option : string ) => Promise < void > ;
33
38
onDirCreate : ( name : string ) => ( ) => Promise < void > ;
39
+ onRename : ( old_name : string , new_name : string ) => ( ) => Promise < void > ;
34
40
onRefresh : ( ) => Promise < void > ;
35
41
onLoadSamples : ( ) => Promise < void > ;
36
42
}
@@ -46,6 +52,7 @@ const modalStyle = {
46
52
} ;
47
53
48
54
export const options = [
55
+ { text : "Rename" , key : "rename" } ,
49
56
{ text : "Download" , key : "download" } ,
50
57
{ text : "Download as Text File" , key : "download-text" } ,
51
58
{ text : "Delete" , key : "delete" } ,
@@ -54,17 +61,23 @@ export const options = [
54
61
export default function FileSystemManager ( {
55
62
path = "/" ,
56
63
nodes = [ ] ,
64
+ oldName = "" ,
65
+ newName = "" ,
66
+ renameOpen = false ,
67
+ onNewNameChange = ( ) => ( ) => Promise . resolve ( ) ,
68
+ onCloseRenameModal = ( ) => ( ) => Promise . resolve ( ) ,
57
69
onFileUpload = ( ) => ( ) => Promise . resolve ( ) ,
58
70
onFileClick = ( ) => ( ) => Promise . resolve ( ) ,
59
71
onDirClick = ( ) => ( ) => Promise . resolve ( ) ,
60
72
onDirCreate = ( ) => ( ) => Promise . resolve ( ) ,
73
+ onRename = ( ) => ( ) => Promise . resolve ( ) ,
61
74
onRefresh = ( ) => Promise . resolve ( ) ,
62
75
onLoadSamples = ( ) => Promise . resolve ( ) ,
63
76
} : FileSystemManagerProps ) {
64
- const [ open , setOpen ] = useState ( false ) ;
77
+ const [ newFolderOpen , setNewFolderOpen ] = useState ( false ) ;
65
78
const [ dirName , setDirName ] = useState ( "" ) ;
66
- const handleModalOpen = ( ) => setOpen ( true ) ;
67
- const handleModalClose = ( ) => setOpen ( false ) ;
79
+ const handleNewFolderModalOpen = ( ) => setNewFolderOpen ( true ) ;
80
+ const handleNewFolderModalClose = ( ) => setNewFolderOpen ( false ) ;
68
81
69
82
return (
70
83
< >
@@ -113,7 +126,7 @@ export default function FileSystemManager({
113
126
< IconButton
114
127
onClick = { ( ) => {
115
128
setDirName ( "" ) ;
116
- handleModalOpen ( ) ;
129
+ handleNewFolderModalOpen ( ) ;
117
130
} }
118
131
aria-label = "create-a-new-folder"
119
132
size = "small"
@@ -165,8 +178,8 @@ export default function FileSystemManager({
165
178
</ Stack >
166
179
</ Paper >
167
180
< Modal
168
- open = { open }
169
- onClose = { handleModalClose }
181
+ open = { newFolderOpen }
182
+ onClose = { handleNewFolderModalClose }
170
183
aria-labelledby = "new-folder-name"
171
184
aria-describedby = "new-folder-name-description"
172
185
>
@@ -183,12 +196,12 @@ export default function FileSystemManager({
183
196
onChange = { ( event ) => setDirName ( event . target . value ) }
184
197
/>
185
198
< Stack direction = "row" justifyContent = "flex-end" >
186
- < Button onClick = { handleModalClose } > Cancel</ Button >
199
+ < Button onClick = { handleNewFolderModalClose } > Cancel</ Button >
187
200
< Button
188
201
variant = "contained"
189
202
onClick = { ( ) => {
190
203
onDirCreate ( dirName ) ;
191
- handleModalClose ( ) ;
204
+ handleNewFolderModalClose ( ) ;
192
205
} }
193
206
>
194
207
Create
@@ -197,6 +210,36 @@ export default function FileSystemManager({
197
210
</ Stack >
198
211
</ Box >
199
212
</ Modal >
213
+ < Modal
214
+ open = { renameOpen }
215
+ onClose = { onCloseRenameModal ( ) }
216
+ aria-labelledby = "new-name"
217
+ aria-describedby = "new-name-description"
218
+ >
219
+ < Box sx = { modalStyle } >
220
+ < Stack spacing = { 4 } >
221
+ < Typography id = "modal-modal-title" variant = "h6" component = "h2" >
222
+ New Name:
223
+ </ Typography >
224
+ < TextField
225
+ id = "outlined-basic"
226
+ label = "my-file"
227
+ variant = "outlined"
228
+ value = { newName }
229
+ onChange = { onNewNameChange ( ) }
230
+ />
231
+ < Stack direction = "row" justifyContent = "flex-end" >
232
+ < Button onClick = { onCloseRenameModal ( ) } > Cancel</ Button >
233
+ < Button
234
+ variant = "contained"
235
+ onClick = { onRename ( oldName , newName ) }
236
+ >
237
+ Rename
238
+ </ Button >
239
+ </ Stack >
240
+ </ Stack >
241
+ </ Box >
242
+ </ Modal >
200
243
</ >
201
244
) ;
202
245
}
0 commit comments