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 {
...
@@ -67,7 +67,7 @@ class FileProvider {
// todo check the type (directory/file) as well #2386
// todo check the type (directory/file) as well #2386
// currently it is not possible to have a file and folder with same path
// currently it is not possible to have a file and folder with same path
const
ret
=
this
.
_exists
(
path
)
const
ret
=
this
.
_exists
(
path
)
if
(
cb
)
cb
(
null
,
ret
)
return
ret
return
ret
}
}
...
...
apps/remix-ide/src/app/files/workspaceFileProvider.js
View file @
837490e9
...
@@ -33,7 +33,7 @@ class WorkspaceFileProvider extends FileProvider {
...
@@ -33,7 +33,7 @@ class WorkspaceFileProvider extends FileProvider {
if
(
!
this
.
workspace
)
this
.
createWorkspace
()
if
(
!
this
.
workspace
)
this
.
createWorkspace
()
path
=
path
.
replace
(
/^
\/
|
\/
$/g
,
''
)
// remove first and last slash
path
=
path
.
replace
(
/^
\/
|
\/
$/g
,
''
)
// remove first and last slash
if
(
path
.
startsWith
(
this
.
workspacesPath
+
'/'
+
this
.
workspace
))
return
path
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
)
path
=
super
.
removePrefix
(
path
)
let
ret
=
this
.
workspacesPath
+
'/'
+
this
.
workspace
+
'/'
+
(
path
===
'/'
?
''
:
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 = {
...
@@ -52,6 +52,27 @@ module.exports = {
createNonClashingName
(
name
,
fileProvider
,
cb
)
{
createNonClashingName
(
name
,
fileProvider
,
cb
)
{
this
.
createNonClashingNameWithPrefix
(
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
)
{
checkSpecialChars
(
name
)
{
return
name
.
match
(
/
[
:*?"<>
\\
'|
]
/
)
!=
null
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) => {
...
@@ -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
)
{
if
(
provider
)
{
provider
.
event
.
register
(
'fileAdded'
,
async
(
filePath
)
=>
{
resolveDirectory
(
provider
,
extractParentFromKey
(
filePath
)
||
workspaceName
)(
dispatch
)
})
dispatch
(
fetchProviderSuccess
(
provider
))
dispatch
(
fetchProviderSuccess
(
provider
))
dispatch
(
setCurrentWorkspace
(
workspaceName
))
}
else
{
}
else
{
dispatch
(
fetchProviderError
(
'No provider available'
))
dispatch
(
fetchProviderError
(
'No provider available'
))
}
}
...
@@ -166,12 +170,6 @@ export const setCurrentWorkspace = (name: string) => {
...
@@ -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
[])
=>
{
export
const
addInputFieldSuccess
=
(
path
:
string
,
files
:
File
[])
=>
{
return
{
return
{
type
:
'ADD_INPUT_FIELD'
,
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
...
@@ -8,7 +8,7 @@ import { FileExplorerMenu } from './file-explorer-menu' // eslint-disable-line
import
{
FileExplorerContextMenu
}
from
'./file-explorer-context-menu'
// eslint-disable-line
import
{
FileExplorerContextMenu
}
from
'./file-explorer-context-menu'
// eslint-disable-line
import
{
FileExplorerProps
,
File
}
from
'./types'
import
{
FileExplorerProps
,
File
}
from
'./types'
import
{
fileSystemReducer
,
fileSystemInitialState
}
from
'./reducers/fileSystem'
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
*
as
helper
from
'../../../../../apps/remix-ide/src/lib/helper'
import
QueryParams
from
'../../../../../apps/remix-ide/src/lib/query-params'
import
QueryParams
from
'../../../../../apps/remix-ide/src/lib/query-params'
...
@@ -108,8 +108,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -108,8 +108,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
props
.
filesProvider
)
{
if
(
props
.
filesProvider
)
{
setProvider
(
props
.
filesProvider
)(
dispatch
)
setProvider
(
props
.
filesProvider
,
props
.
name
)(
dispatch
)
setWorkspace
(
props
.
name
)(
dispatch
)
}
}
},
[
props
.
filesProvider
])
},
[
props
.
filesProvider
])
...
@@ -217,7 +216,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -217,7 +216,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
},
[
state
.
modals
])
},
[
state
.
modals
])
const
extractNameFromKey
=
(
key
:
string
):
string
=>
{
const
extractNameFromKey
=
(
key
:
string
):
string
=>
{
const
keyPath
=
key
.
split
(
'/'
)
const
keyPath
=
key
.
split
(
'/'
)
...
@@ -232,36 +230,28 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -232,36 +230,28 @@ export const FileExplorer = (props: FileExplorerProps) => {
return
keyPath
.
join
(
'/'
)
return
keyPath
.
join
(
'/'
)
}
}
// const createNewFile =
(newFilePath: string) => {
const
createNewFile
=
async
(
newFilePath
:
string
)
=>
{
//
const fileManager = state.fileManager
const
fileManager
=
state
.
fileManager
// try {
try
{
// helper.createNonClashingName(newFilePath, filesProvider, async (error, newName) => {
const
newName
=
await
helper
.
checkNonClashingNameAsync
(
newFilePath
,
fileManager
)
// if (error) {
const
createFile
=
await
fileManager
.
writeFile
(
newName
,
''
)
// modal('Create File Failed', error, {
// label: 'Close',
if
(
!
createFile
)
{
// fn: async () => {}
return
toast
(
'Failed to create file '
+
newName
)
// }, null)
}
else
{
// } else {
await
fileManager
.
open
(
newName
)
// const createFile = await fileManager.writeFile(newName, '')
setState
(
prevState
=>
{
return
{
...
prevState
,
focusElement
:
[{
key
:
newName
,
type
:
'file'
}]
}
// if (!createFile) {
})
// return toast('Failed to create file ' + newName)
}
// } else {
}
catch
(
error
)
{
// await fileManager.open(newName)
return
modal
(
'File Creation Failed'
,
typeof
error
===
'string'
?
error
:
error
.
message
,
{
// setState(prevState => {
label
:
'Close'
,
// return { ...prevState, focusElement: [{ key: newName, type: 'file' }] }
fn
:
async
()
=>
{}
// })
},
null
)
// }
}
// }
}
// })
// } catch (error) {
// return modal('File Creation Failed', typeof error === 'string' ? error : error.message, {
// label: 'Close',
// fn: async () => {}
// }, null)
// }
// }
// const createNewFolder = async (newFolderPath: string) => {
// const createNewFolder = async (newFolderPath: string) => {
// const fileManager = state.fileManager
// const fileManager = state.fileManager
...
@@ -347,23 +337,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -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 folderAdded = async (folderPath: string) => {
// const pathArr = folderPath.split('/')
// const pathArr = folderPath.split('/')
// const expandPath = pathArr.map((path, index) => {
// const expandPath = pathArr.map((path, index) => {
...
@@ -659,6 +632,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -659,6 +632,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
const
handleClickFile
=
(
path
:
string
)
=>
{
const
handleClickFile
=
(
path
:
string
)
=>
{
console
.
log
(
'path: '
,
path
)
state
.
fileManager
.
open
(
path
)
state
.
fileManager
.
open
(
path
)
setState
(
prevState
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
focusElement
:
[{
key
:
path
,
type
:
'file'
}]
}
return
{
...
prevState
,
focusElement
:
[{
key
:
path
,
type
:
'file'
}]
}
...
@@ -750,6 +724,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -750,6 +724,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
else
{
}
else
{
if
(
state
.
focusEdit
.
isNew
)
{
if
(
state
.
focusEdit
.
isNew
)
{
// state.focusEdit.type === 'file' ? createNewFile(joinPath(parentFolder, content)) : createNewFolder(joinPath(parentFolder, content))
// state.focusEdit.type === 'file' ? createNewFile(joinPath(parentFolder, content)) : createNewFolder(joinPath(parentFolder, content))
createNewFile
(
joinPath
(
parentFolder
,
content
))
removeInputField
(
fileSystem
.
provider
.
provider
,
parentFolder
)(
dispatch
)
removeInputField
(
fileSystem
.
provider
.
provider
,
parentFolder
)(
dispatch
)
}
else
{
}
else
{
const
oldPath
:
string
=
state
.
focusEdit
.
element
const
oldPath
:
string
=
state
.
focusEdit
.
element
...
@@ -767,7 +742,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -767,7 +742,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
const
handleNewFileInput
=
async
(
parentFolder
?:
string
)
=>
{
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
])]
const
expandPath
=
[...
new
Set
([...
state
.
expandPath
,
parentFolder
])]
await
addInputField
(
fileSystem
.
provider
.
provider
,
'file'
,
parentFolder
)(
dispatch
)
await
addInputField
(
fileSystem
.
provider
.
provider
,
'file'
,
parentFolder
)(
dispatch
)
...
@@ -778,7 +753,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -778,7 +753,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
const
handleNewFolderInput
=
async
(
parentFolder
?:
string
)
=>
{
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
)
else
if
((
parentFolder
.
indexOf
(
'.sol'
)
!==
-
1
)
||
(
parentFolder
.
indexOf
(
'.js'
)
!==
-
1
))
parentFolder
=
extractParentFromKey
(
parentFolder
)
const
expandPath
=
[...
new
Set
([...
state
.
expandPath
,
parentFolder
])]
const
expandPath
=
[...
new
Set
([...
state
.
expandPath
,
parentFolder
])]
...
@@ -1008,8 +983,8 @@ async function packageFiles (filesProvider, directory, callback) {
...
@@ -1008,8 +983,8 @@ async function packageFiles (filesProvider, directory, callback) {
}
}
}
}
//
function joinPath (...paths) {
function
joinPath
(...
paths
)
{
//
paths = paths.filter((value) => value !== '').map((path) => path.replace(/^\/|\/$/g, '')) // remove first and last slash)
paths
=
paths
.
filter
((
value
)
=>
value
!==
''
).
map
((
path
)
=>
path
.
replace
(
/^
\/
|
\/
$/g
,
''
))
// remove first and last slash)
//
if (paths.length === 1) return paths[0]
if
(
paths
.
length
===
1
)
return
paths
[
0
]
//
return paths.join('/')
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
...
@@ -167,6 +167,7 @@ export const fileSystemReducer = (state = fileSystemInitialState, action: Action
}
}
const
resolveDirectory
=
(
root
,
path
:
string
,
files
,
content
)
=>
{
const
resolveDirectory
=
(
root
,
path
:
string
,
files
,
content
)
=>
{
if
(
path
===
root
)
return
{
[
root
]:
{
...
content
[
root
],
...
files
[
root
]
}
}
const
pathArr
=
path
.
split
(
'/'
)
const
pathArr
=
path
.
split
(
'/'
)
if
(
pathArr
[
0
]
!==
root
)
pathArr
.
unshift
(
root
)
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