Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
59afc288
Commit
59afc288
authored
Apr 24, 2021
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renames but appends to bottom
parent
ed03204f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
37 deletions
+86
-37
fileSystem.ts
libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts
+15
-1
file-explorer.tsx
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
+23
-35
fileSystem.ts
libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts
+48
-1
No files found.
libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts
View file @
59afc288
...
...
@@ -172,6 +172,13 @@ export const fileRemovedSuccess = (path: string, removePath: string) => {
}
}
export
const
fileRenamedSuccess
=
(
parentPath
:
string
,
oldPath
:
string
,
newPath
:
string
)
=>
{
return
{
type
:
'FILE_RENAMED'
,
payload
:
{
parentPath
,
oldPath
,
newPath
}
}
}
export
const
init
=
(
provider
,
workspaceName
:
string
,
plugin
)
=>
(
dispatch
:
React
.
Dispatch
<
any
>
)
=>
{
if
(
provider
)
{
provider
.
event
.
register
(
'fileAdded'
,
async
(
filePath
)
=>
{
...
...
@@ -179,6 +186,9 @@ export const init = (provider, workspaceName: string, plugin) => (dispatch: Reac
const
data
=
await
fetchDirectoryContent
(
provider
,
path
)
dispatch
(
fileAddedSuccess
(
path
,
data
))
if
(
filePath
.
includes
(
'_test.sol'
))
{
plugin
.
event
.
trigger
(
'newTestFileCreated'
,
[
filePath
])
}
})
provider
.
event
.
register
(
'folderAdded'
,
async
(
folderPath
)
=>
{
const
path
=
extractParentFromKey
(
folderPath
)
||
workspaceName
...
...
@@ -191,8 +201,12 @@ export const init = (provider, workspaceName: string, plugin) => (dispatch: Reac
dispatch
(
fileRemovedSuccess
(
path
,
removePath
))
})
provider
.
event
.
register
(
'fileRenamed'
,
async
()
=>
{
provider
.
event
.
register
(
'fileRenamed'
,
async
(
oldPath
,
newPath
)
=>
{
console
.
log
(
'oldPath: '
,
oldPath
)
console
.
log
(
'newPath: '
,
newPath
)
const
parentPath
=
extractParentFromKey
(
oldPath
)
||
workspaceName
dispatch
(
fileRenamedSuccess
(
parentPath
,
oldPath
,
newPath
))
})
dispatch
(
fetchProviderSuccess
(
provider
))
dispatch
(
setCurrentWorkspace
(
workspaceName
))
...
...
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
View file @
59afc288
...
...
@@ -148,18 +148,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
// }
// }, [state.fileManager])
// useEffect(() => {
// // unregister event to update state in callback
// if (filesProvider.event.registered.fileAdded) filesProvider.event.unregister('fileAdded', fileAdded)
// if (filesProvider.event.registered.folderAdded) filesProvider.event.unregister('folderAdded', folderAdded)
// if (filesProvider.event.registered.fileRemoved) filesProvider.event.unregister('fileRemoved', fileRemoved)
// if (filesProvider.event.registered.fileRenamed) filesProvider.event.unregister('fileRenamed', fileRenamed)
// filesProvider.event.register('fileAdded', fileAdded)
// filesProvider.event.register('folderAdded', folderAdded)
// filesProvider.event.register('fileRemoved', fileRemoved)
// filesProvider.event.register('fileRenamed', fileRenamed)
// }, [state.files])
useEffect
(()
=>
{
if
(
focusRoot
)
{
setState
(
prevState
=>
{
...
...
@@ -303,26 +291,26 @@ export const FileExplorer = (props: FileExplorerProps) => {
})
}
//
const renamePath = async (oldPath: string, newPath: string) => {
//
try {
//
const fileManager = state.fileManager
//
const exists = await fileManager.exists(newPath)
//
if (exists) {
//
modal('Rename File Failed', `A file or folder ${extractNameFromKey(newPath)} already exists at this location. Please choose a different name.`, {
//
label: 'Close',
//
fn: () => {}
//
}, null)
//
} else {
//
await fileManager.rename(oldPath, newPath)
//
}
//
} catch (error) {
//
modal('Rename File Failed', 'Unexpected error while renaming: ' + typeof error === 'string' ? error : error.message, {
//
label: 'Close',
//
fn: async () => {}
//
}, null)
//
}
//
}
const
renamePath
=
async
(
oldPath
:
string
,
newPath
:
string
)
=>
{
try
{
const
fileManager
=
state
.
fileManager
const
exists
=
await
fileManager
.
exists
(
newPath
)
if
(
exists
)
{
modal
(
'Rename File Failed'
,
`A file or folder
${
extractNameFromKey
(
newPath
)}
already exists at this location. Please choose a different name.`
,
{
label
:
'Close'
,
fn
:
()
=>
{}
},
null
)
}
else
{
await
fileManager
.
rename
(
oldPath
,
newPath
)
}
}
catch
(
error
)
{
modal
(
'Rename File Failed'
,
'Unexpected error while renaming: '
+
typeof
error
===
'string'
?
error
:
error
.
message
,
{
label
:
'Close'
,
fn
:
async
()
=>
{}
},
null
)
}
}
const
fileExternallyChanged
=
(
path
:
string
,
file
:
{
content
:
string
})
=>
{
const
config
=
registry
.
get
(
'config'
).
api
...
...
@@ -686,11 +674,11 @@ export const FileExplorer = (props: FileExplorerProps) => {
removeInputField
(
parentFolder
)(
dispatch
)
}
else
{
const
oldPath
:
string
=
state
.
focusEdit
.
element
//
const oldName = extractNameFromKey(oldPath)
//
const newPath = oldPath.replace(oldName, content)
const
oldName
=
extractNameFromKey
(
oldPath
)
const
newPath
=
oldPath
.
replace
(
oldName
,
content
)
editRef
.
current
.
textContent
=
extractNameFromKey
(
oldPath
)
//
renamePath(oldPath, newPath)
renamePath
(
oldPath
,
newPath
)
}
setState
(
prevState
=>
{
return
{
...
prevState
,
focusEdit
:
{
element
:
null
,
isNew
:
false
,
type
:
''
,
lastEdit
:
''
}
}
...
...
libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts
View file @
59afc288
...
...
@@ -215,6 +215,18 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action
}
}
}
case
'FILE_RENAMED'
:
{
return
{
...
state
,
files
:
{
...
state
.
files
,
files
:
fileRenamed
(
state
.
files
.
workspaceName
,
action
.
payload
.
parentPath
,
action
.
payload
.
oldPath
,
action
.
payload
.
newPath
,
state
.
files
.
files
),
isRequesting
:
false
,
isSuccessful
:
true
,
error
:
null
}
}
}
default
:
throw
new
Error
()
}
...
...
@@ -250,7 +262,7 @@ const removePath = (root, path: string, pathName, files) => {
},
[])
const
prevFiles
=
_
.
get
(
files
,
_path
)
p
athName
&&
delete
prevFiles
.
child
[
pathName
]
p
revFiles
.
child
[
pathName
]
&&
delete
prevFiles
.
child
[
pathName
]
files
=
_
.
set
(
files
,
_path
,
{
isDirectory
:
true
,
path
,
...
...
@@ -292,3 +304,38 @@ const fileRemoved = (root, path: string, removedPath: string, files) => {
}
return
removePath
(
root
,
path
,
extractNameFromKey
(
removedPath
),
files
)
}
const
fileRenamed
=
(
root
,
parentPath
:
string
,
oldPath
:
string
,
newPath
:
string
,
files
)
=>
{
if
(
parentPath
===
root
)
{
const
newPathName
=
extractNameFromKey
(
newPath
)
||
newPath
files
[
root
][
newPathName
]
=
{
...
files
[
root
][
oldPath
],
path
:
newPath
,
name
:
newPathName
}
delete
files
[
root
][
extractNameFromKey
(
oldPath
)
||
oldPath
]
return
files
}
const
pathArr
:
string
[]
=
parentPath
.
split
(
'/'
).
filter
(
value
=>
value
)
if
(
pathArr
[
0
]
!==
root
)
pathArr
.
unshift
(
root
)
const
_path
=
pathArr
.
map
((
key
,
index
)
=>
index
>
1
?
[
'child'
,
key
]
:
key
).
reduce
((
acc
:
string
[],
cur
)
=>
{
return
Array
.
isArray
(
cur
)
?
[...
acc
,
...
cur
]
:
[...
acc
,
cur
]
},
[])
const
prevFiles
=
_
.
get
(
files
,
_path
)
prevFiles
.
child
[
extractNameFromKey
(
newPath
)]
=
{
...
prevFiles
.
child
[
oldPath
],
path
:
newPath
,
name
:
extractNameFromKey
(
newPath
)
}
delete
prevFiles
.
child
[
extractNameFromKey
(
oldPath
)]
files
=
_
.
set
(
files
,
_path
,
{
isDirectory
:
true
,
path
:
parentPath
,
name
:
extractNameFromKey
(
parentPath
),
child
:
prevFiles
.
child
})
return
files
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment