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
837490e9
Commit
837490e9
authored
Apr 22, 2021
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix file added bug
parent
be2341a0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
66 deletions
+61
-66
fileProvider.js
apps/remix-ide/src/app/files/fileProvider.js
+1
-1
workspaceFileProvider.js
apps/remix-ide/src/app/files/workspaceFileProvider.js
+1
-1
helper.js
apps/remix-ide/src/lib/helper.js
+21
-0
fileSystem.ts
libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts
+5
-7
file-explorer.tsx
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
+32
-57
fileSystem.ts
libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts
+1
-0
No files found.
apps/remix-ide/src/app/files/fileProvider.js
View file @
837490e9
...
...
@@ -67,7 +67,7 @@ class FileProvider {
// todo check the type (directory/file) as well #2386
// currently it is not possible to have a file and folder with same path
const
ret
=
this
.
_exists
(
path
)
if
(
cb
)
cb
(
null
,
ret
)
return
ret
}
...
...
apps/remix-ide/src/app/files/workspaceFileProvider.js
View file @
837490e9
...
...
@@ -33,7 +33,7 @@ class WorkspaceFileProvider extends FileProvider {
if
(
!
this
.
workspace
)
this
.
createWorkspace
()
path
=
path
.
replace
(
/^
\/
|
\/
$/g
,
''
)
// remove first and last slash
if
(
path
.
startsWith
(
this
.
workspacesPath
+
'/'
+
this
.
workspace
))
return
path
if
(
path
.
startsWith
(
this
.
workspace
))
return
this
.
workspacesPath
+
'/'
+
this
.
workspace
if
(
path
.
startsWith
(
this
.
workspace
))
return
path
.
replace
(
this
.
workspace
,
this
.
workspacesPath
+
'/'
+
this
.
workspace
)
path
=
super
.
removePrefix
(
path
)
let
ret
=
this
.
workspacesPath
+
'/'
+
this
.
workspace
+
'/'
+
(
path
===
'/'
?
''
:
path
)
...
...
apps/remix-ide/src/lib/helper.js
View file @
837490e9
...
...
@@ -52,6 +52,27 @@ module.exports = {
createNonClashingName
(
name
,
fileProvider
,
cb
)
{
this
.
createNonClashingNameWithPrefix
(
name
,
fileProvider
,
''
,
cb
)
},
async
checkNonClashingNameAsync
(
name
,
fileManager
,
prefix
=
''
)
{
if
(
!
name
)
name
=
'Undefined'
let
counter
=
''
let
ext
=
'sol'
const
reg
=
/
(
.*
)\.([^
.
]
+
)
/g
const
split
=
reg
.
exec
(
name
)
if
(
split
)
{
name
=
split
[
1
]
ext
=
split
[
2
]
}
let
exist
=
true
do
{
const
isDuplicate
=
await
fileManager
.
exists
(
name
+
counter
+
prefix
+
'.'
+
ext
)
if
(
isDuplicate
)
counter
=
(
counter
|
0
)
+
1
else
exist
=
false
}
while
(
exist
)
return
name
+
counter
+
prefix
+
'.'
+
ext
},
checkSpecialChars
(
name
)
{
return
name
.
match
(
/
[
:*?"<>
\\
'|
]
/
)
!=
null
},
...
...
libs/remix-ui/file-explorer/src/lib/actions/fileSystem.ts
View file @
837490e9
...
...
@@ -151,9 +151,13 @@ export const fetchProviderSuccess = (provider: any) => {
}
}
export
const
setProvider
=
(
provider
)
=>
(
dispatch
:
React
.
Dispatch
<
any
>
)
=>
{
export
const
setProvider
=
(
provider
,
workspaceName
)
=>
(
dispatch
:
React
.
Dispatch
<
any
>
)
=>
{
if
(
provider
)
{
provider
.
event
.
register
(
'fileAdded'
,
async
(
filePath
)
=>
{
resolveDirectory
(
provider
,
extractParentFromKey
(
filePath
)
||
workspaceName
)(
dispatch
)
})
dispatch
(
fetchProviderSuccess
(
provider
))
dispatch
(
setCurrentWorkspace
(
workspaceName
))
}
else
{
dispatch
(
fetchProviderError
(
'No provider available'
))
}
...
...
@@ -166,12 +170,6 @@ export const setCurrentWorkspace = (name: string) => {
}
}
export
const
setWorkspace
=
(
name
:
string
)
=>
(
dispatch
:
React
.
Dispatch
<
any
>
)
=>
{
if
(
name
)
{
dispatch
(
setCurrentWorkspace
(
name
))
}
}
export
const
addInputFieldSuccess
=
(
path
:
string
,
files
:
File
[])
=>
{
return
{
type
:
'ADD_INPUT_FIELD'
,
...
...
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
View file @
837490e9
...
...
@@ -8,7 +8,7 @@ import { FileExplorerMenu } from './file-explorer-menu' // eslint-disable-line
import
{
FileExplorerContextMenu
}
from
'./file-explorer-context-menu'
// eslint-disable-line
import
{
FileExplorerProps
,
File
}
from
'./types'
import
{
fileSystemReducer
,
fileSystemInitialState
}
from
'./reducers/fileSystem'
import
{
fetchDirectory
,
setProvider
,
resolveDirectory
,
setWorkspace
,
addInputField
,
removeInputField
}
from
'./actions/fileSystem'
import
{
fetchDirectory
,
setProvider
,
resolveDirectory
,
addInputField
,
removeInputField
}
from
'./actions/fileSystem'
import
*
as
helper
from
'../../../../../apps/remix-ide/src/lib/helper'
import
QueryParams
from
'../../../../../apps/remix-ide/src/lib/query-params'
...
...
@@ -108,8 +108,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
useEffect
(()
=>
{
if
(
props
.
filesProvider
)
{
setProvider
(
props
.
filesProvider
)(
dispatch
)
setWorkspace
(
props
.
name
)(
dispatch
)
setProvider
(
props
.
filesProvider
,
props
.
name
)(
dispatch
)
}
},
[
props
.
filesProvider
])
...
...
@@ -217,7 +216,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
},
[
state
.
modals
])
const
extractNameFromKey
=
(
key
:
string
):
string
=>
{
const
keyPath
=
key
.
split
(
'/'
)
...
...
@@ -232,36 +230,28 @@ export const FileExplorer = (props: FileExplorerProps) => {
return
keyPath
.
join
(
'/'
)
}
// const createNewFile =
(newFilePath: string) => {
//
const fileManager = state.fileManager
const
createNewFile
=
async
(
newFilePath
:
string
)
=>
{
const
fileManager
=
state
.
fileManager
// try {
// helper.createNonClashingName(newFilePath, filesProvider, async (error, newName) => {
// if (error) {
// modal('Create File Failed', error, {
// label: 'Close',
// fn: async () => {}
// }, null)
// } else {
// const createFile = await fileManager.writeFile(newName, '')
// if (!createFile) {
// return toast('Failed to create file ' + newName)
// } else {
// await fileManager.open(newName)
// setState(prevState => {
// return { ...prevState, focusElement: [{ key: newName, type: 'file' }] }
// })
// }
// }
// })
// } catch (error) {
// return modal('File Creation Failed', typeof error === 'string' ? error : error.message, {
// label: 'Close',
// fn: async () => {}
// }, null)
// }
// }
try
{
const
newName
=
await
helper
.
checkNonClashingNameAsync
(
newFilePath
,
fileManager
)
const
createFile
=
await
fileManager
.
writeFile
(
newName
,
''
)
if
(
!
createFile
)
{
return
toast
(
'Failed to create file '
+
newName
)
}
else
{
await
fileManager
.
open
(
newName
)
setState
(
prevState
=>
{
return
{
...
prevState
,
focusElement
:
[{
key
:
newName
,
type
:
'file'
}]
}
})
}
}
catch
(
error
)
{
return
modal
(
'File Creation Failed'
,
typeof
error
===
'string'
?
error
:
error
.
message
,
{
label
:
'Close'
,
fn
:
async
()
=>
{}
},
null
)
}
}
// const createNewFolder = async (newFolderPath: string) => {
// const fileManager = state.fileManager
...
...
@@ -347,23 +337,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
// })
// }
// const fileAdded = async (filePath: string) => {
// const pathArr = filePath.split('/')
// const expandPath = pathArr.map((path, index) => {
// return [...pathArr.slice(0, index)].join('/')
// }).filter(path => path && (path !== props.name))
// const files = await fetchDirectoryContent(props.name)
// setState(prevState => {
// const uniquePaths = [...new Set([...prevState.expandPath, ...expandPath])]
// return { ...prevState, files, expandPath: uniquePaths }
// })
// if (filePath.includes('_test.sol')) {
// plugin.event.trigger('newTestFileCreated', [filePath])
// }
// }
// const folderAdded = async (folderPath: string) => {
// const pathArr = folderPath.split('/')
// const expandPath = pathArr.map((path, index) => {
...
...
@@ -659,6 +632,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
const
handleClickFile
=
(
path
:
string
)
=>
{
console
.
log
(
'path: '
,
path
)
state
.
fileManager
.
open
(
path
)
setState
(
prevState
=>
{
return
{
...
prevState
,
focusElement
:
[{
key
:
path
,
type
:
'file'
}]
}
...
...
@@ -750,6 +724,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
else
{
if
(
state
.
focusEdit
.
isNew
)
{
// state.focusEdit.type === 'file' ? createNewFile(joinPath(parentFolder, content)) : createNewFolder(joinPath(parentFolder, content))
createNewFile
(
joinPath
(
parentFolder
,
content
))
removeInputField
(
fileSystem
.
provider
.
provider
,
parentFolder
)(
dispatch
)
}
else
{
const
oldPath
:
string
=
state
.
focusEdit
.
element
...
...
@@ -767,7 +742,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
const
handleNewFileInput
=
async
(
parentFolder
?:
string
)
=>
{
if
(
!
parentFolder
)
parentFolder
=
state
.
focusElement
[
0
]
?
state
.
focusElement
[
0
].
type
===
'folder'
?
state
.
focusElement
[
0
].
key
?
state
.
focusElement
[
0
].
key
:
name
:
extractParentFromKey
(
state
.
focusElement
[
0
].
key
)
:
name
if
(
!
parentFolder
)
parentFolder
=
state
.
focusElement
[
0
]
?
state
.
focusElement
[
0
].
type
===
'folder'
?
state
.
focusElement
[
0
].
key
?
state
.
focusElement
[
0
].
key
:
name
:
extractParentFromKey
(
state
.
focusElement
[
0
].
key
)
?
extractParentFromKey
(
state
.
focusElement
[
0
].
key
)
:
name
:
name
const
expandPath
=
[...
new
Set
([...
state
.
expandPath
,
parentFolder
])]
await
addInputField
(
fileSystem
.
provider
.
provider
,
'file'
,
parentFolder
)(
dispatch
)
...
...
@@ -778,7 +753,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
const
handleNewFolderInput
=
async
(
parentFolder
?:
string
)
=>
{
if
(
!
parentFolder
)
parentFolder
=
state
.
focusElement
[
0
]
?
state
.
focusElement
[
0
].
type
===
'folder'
?
state
.
focusElement
[
0
].
key
?
state
.
focusElement
[
0
].
key
:
name
:
extractParentFromKey
(
state
.
focusElement
[
0
].
key
)
:
name
if
(
!
parentFolder
)
parentFolder
=
state
.
focusElement
[
0
]
?
state
.
focusElement
[
0
].
type
===
'folder'
?
state
.
focusElement
[
0
].
key
?
state
.
focusElement
[
0
].
key
:
name
:
extractParentFromKey
(
state
.
focusElement
[
0
].
key
)
?
extractParentFromKey
(
state
.
focusElement
[
0
].
key
)
:
name
:
name
else
if
((
parentFolder
.
indexOf
(
'.sol'
)
!==
-
1
)
||
(
parentFolder
.
indexOf
(
'.js'
)
!==
-
1
))
parentFolder
=
extractParentFromKey
(
parentFolder
)
const
expandPath
=
[...
new
Set
([...
state
.
expandPath
,
parentFolder
])]
...
...
@@ -1008,8 +983,8 @@ async function packageFiles (filesProvider, directory, callback) {
}
}
//
function joinPath (...paths) {
//
paths = paths.filter((value) => value !== '').map((path) => path.replace(/^\/|\/$/g, '')) // remove first and last slash)
//
if (paths.length === 1) return paths[0]
//
return paths.join('/')
//
}
function
joinPath
(...
paths
)
{
paths
=
paths
.
filter
((
value
)
=>
value
!==
''
).
map
((
path
)
=>
path
.
replace
(
/^
\/
|
\/
$/g
,
''
))
// remove first and last slash)
if
(
paths
.
length
===
1
)
return
paths
[
0
]
return
paths
.
join
(
'/'
)
}
libs/remix-ui/file-explorer/src/lib/reducers/fileSystem.ts
View file @
837490e9
...
...
@@ -167,6 +167,7 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action
}
const
resolveDirectory
=
(
root
,
path
:
string
,
files
,
content
)
=>
{
if
(
path
===
root
)
return
{
[
root
]:
{
...
content
[
root
],
...
files
[
root
]
}
}
const
pathArr
=
path
.
split
(
'/'
)
if
(
pathArr
[
0
]
!==
root
)
pathArr
.
unshift
(
root
)
...
...
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