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
b45fbdff
Commit
b45fbdff
authored
Oct 14, 2021
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make exposed plugin methods return promises.
Set flag for creating empty workspaces and added workspace initialization event.
parent
c04cedd8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
29 deletions
+74
-29
file-panel.js
apps/remix-ide/src/app/panels/file-panel.js
+34
-9
events.ts
libs/remix-ui/workspace/src/lib/actions/events.ts
+26
-15
index.ts
libs/remix-ui/workspace/src/lib/actions/index.ts
+1
-0
workspace.ts
libs/remix-ui/workspace/src/lib/actions/workspace.ts
+13
-5
No files found.
apps/remix-ide/src/app/panels/file-panel.js
View file @
b45fbdff
...
...
@@ -76,11 +76,21 @@ module.exports = class Filepanel extends ViewPlugin {
* @param callback (...args) => void
*/
registerContextMenuItem
(
item
)
{
this
.
emit
(
'registerContextMenuItem'
,
item
)
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
emit
(
'registerContextMenuItemReducerEvent'
,
item
,
(
err
,
data
)
=>
{
if
(
err
)
reject
(
err
)
else
resolve
(
data
)
})
})
}
removePluginActions
(
plugin
)
{
this
.
emit
(
'removePluginActions'
,
plugin
)
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
emit
(
'removePluginActionsReducerEvent'
,
plugin
,
(
err
,
data
)
=>
{
if
(
err
)
reject
(
err
)
else
resolve
(
data
)
})
})
}
getCurrentWorkspace
()
{
...
...
@@ -95,25 +105,40 @@ module.exports = class Filepanel extends ViewPlugin {
this
.
worspaces
=
workspaces
}
async
createNewFile
()
{
createNewFile
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
provider
=
this
.
fileManager
.
currentFileProvider
()
const
dir
=
provider
.
workspace
||
'/'
this
.
emit
(
'displayNewFileInput'
,
dir
)
this
.
emit
(
'createNewFileInputReducerEvent'
,
dir
,
(
err
,
data
)
=>
{
if
(
err
)
reject
(
err
)
else
resolve
(
data
)
})
})
}
async
uploadFile
(
target
)
{
uploadFile
(
target
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
provider
=
this
.
fileManager
.
currentFileProvider
()
const
dir
=
provider
.
workspace
||
'/'
return
this
.
emit
(
'uploadFileEvent'
,
dir
,
target
)
return
this
.
emit
(
'uploadFileReducerEvent'
,
dir
,
target
,
(
err
,
data
)
=>
{
if
(
err
)
reject
(
err
)
else
resolve
(
data
)
})
})
}
async
createWorkspace
(
workspaceName
)
{
this
.
emit
(
'createWorkspace'
,
workspaceName
)
createWorkspace
(
workspaceName
,
isEmpty
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
emit
(
'createWorkspaceReducerEvent'
,
workspaceName
,
isEmpty
,
(
err
,
data
)
=>
{
if
(
err
)
reject
(
err
)
else
resolve
(
data
||
true
)
})
})
}
async
renameWorkspace
(
oldName
,
workspaceName
)
{
renameWorkspace
(
oldName
,
workspaceName
)
{
this
.
emit
(
'renameWorkspace'
,
oldName
,
workspaceName
)
}
...
...
libs/remix-ui/workspace/src/lib/actions/events.ts
View file @
b45fbdff
...
...
@@ -10,28 +10,28 @@ let plugin, dispatch: React.Dispatch<any>
export
const
listenOnPluginEvents
=
(
filePanelPlugin
)
=>
{
plugin
=
filePanelPlugin
plugin
.
on
(
'filePanel'
,
'createWorkspace
'
,
(
name
:
string
)
=>
{
createWorkspace
(
name
)
plugin
.
on
(
'filePanel'
,
'createWorkspace
ReducerEvent'
,
(
name
:
string
,
isEmpty
=
false
,
cb
:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
createWorkspace
(
name
,
isEmpty
,
cb
)
})
plugin
.
on
(
'filePanel'
,
'renameWorkspace'
,
(
oldName
:
string
,
workspaceName
:
string
)
=>
{
renameWorkspace
(
oldName
,
workspaceName
)
})
plugin
.
on
(
'filePanel'
,
'registerContextMenuItem
'
,
(
item
:
action
)
=>
{
registerContextMenuItem
(
item
)
plugin
.
on
(
'filePanel'
,
'registerContextMenuItem
ReducerEvent'
,
(
item
:
action
,
cb
:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
registerContextMenuItem
(
item
,
cb
)
})
plugin
.
on
(
'filePanel'
,
'removePluginActions
'
,
(
plugin
)
=>
{
removePluginActions
(
plugin
)
plugin
.
on
(
'filePanel'
,
'removePluginActions
ReducerEvent'
,
(
plugin
,
cb
:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
removePluginActions
(
plugin
,
cb
)
})
plugin
.
on
(
'filePanel'
,
'
displayNewFileInput'
,
(
path
)
=>
{
addInputField
(
'file'
,
path
)
plugin
.
on
(
'filePanel'
,
'
createNewFileInputReducerEvent'
,
(
path
,
cb
:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
addInputField
(
'file'
,
path
,
cb
)
})
plugin
.
on
(
'filePanel'
,
'uploadFile
Event'
,
(
dir
:
string
,
target
)
=>
{
uploadFile
(
target
,
dir
)
plugin
.
on
(
'filePanel'
,
'uploadFile
ReducerEvent'
,
(
dir
:
string
,
target
,
cb
:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
uploadFile
(
target
,
dir
,
cb
)
})
plugin
.
on
(
'remixd'
,
'rootFolderChanged'
,
async
(
path
:
string
)
=>
{
...
...
@@ -106,15 +106,26 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp
})
}
const
registerContextMenuItem
=
(
item
:
action
)
=>
{
if
(
!
item
)
return
dispatch
(
displayPopUp
(
'Invalid register context menu argument'
))
if
(
!
item
.
name
||
!
item
.
id
)
return
dispatch
(
displayPopUp
(
'Item name and id is mandatory'
))
if
(
!
item
.
type
&&
!
item
.
path
&&
!
item
.
extension
&&
!
item
.
pattern
)
return
dispatch
(
displayPopUp
(
'Invalid file matching criteria provided'
))
const
registerContextMenuItem
=
(
item
:
action
,
cb
?:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
if
(
!
item
)
{
cb
&&
cb
(
new
Error
(
'Invalid register context menu argument'
))
return
dispatch
(
displayPopUp
(
'Invalid register context menu argument'
))
}
if
(
!
item
.
name
||
!
item
.
id
)
{
cb
&&
cb
(
new
Error
(
'Item name and id is mandatory'
))
return
dispatch
(
displayPopUp
(
'Item name and id is mandatory'
))
}
if
(
!
item
.
type
&&
!
item
.
path
&&
!
item
.
extension
&&
!
item
.
pattern
)
{
cb
&&
cb
(
new
Error
(
'Invalid file matching criteria provided'
))
return
dispatch
(
displayPopUp
(
'Invalid file matching criteria provided'
))
}
dispatch
(
setContextMenuItem
(
item
))
cb
&&
cb
(
null
,
item
)
}
const
removePluginActions
=
(
plugin
)
=>
{
const
removePluginActions
=
(
plugin
,
cb
:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
dispatch
(
removeContextMenuItem
(
plugin
))
cb
&&
cb
(
null
,
true
)
}
const
fileAdded
=
async
(
filePath
:
string
)
=>
{
...
...
libs/remix-ui/workspace/src/lib/actions/index.ts
View file @
b45fbdff
...
...
@@ -50,6 +50,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
listenOnProviderEvents
(
workspaceProvider
)(
dispatch
)
listenOnProviderEvents
(
localhostProvider
)(
dispatch
)
dispatch
(
setMode
(
'browser'
))
plugin
.
emit
(
'workspaceInitializationCompleted'
)
}
}
...
...
libs/remix-ui/workspace/src/lib/actions/workspace.ts
View file @
b45fbdff
...
...
@@ -17,12 +17,16 @@ export const setPlugin = (filePanelPlugin, reducerDispatch) => {
dispatch
=
reducerDispatch
}
export
const
addInputField
=
async
(
type
:
'file'
|
'folder'
,
path
:
string
)
=>
{
export
const
addInputField
=
async
(
type
:
'file'
|
'folder'
,
path
:
string
,
cb
?:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
const
provider
=
plugin
.
fileManager
.
currentFileProvider
()
const
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
provider
.
resolveDirectory
(
path
,
(
error
,
fileTree
)
=>
{
if
(
error
)
reject
(
error
)
if
(
error
)
{
cb
&&
cb
(
error
)
return
reject
(
error
)
}
cb
(
null
,
true
)
resolve
(
fileTree
)
})
})
...
...
@@ -35,17 +39,19 @@ export const addInputField = async (type: 'file' | 'folder', path: string) => {
return
promise
}
export
const
createWorkspace
=
async
(
workspaceName
:
string
)
=>
{
export
const
createWorkspace
=
async
(
workspaceName
:
string
,
isEmpty
=
false
,
cb
?:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
await
plugin
.
fileManager
.
closeAllFiles
()
const
promise
=
createWorkspaceTemplate
(
workspaceName
,
'default-template'
)
dispatch
(
createWorkspaceRequest
(
promise
))
promise
.
then
(
async
()
=>
{
dispatch
(
createWorkspaceSuccess
(
workspaceName
))
await
loadWorkspacePreset
(
'default-template'
)
if
(
!
isEmpty
)
await
loadWorkspacePreset
(
'default-template'
)
plugin
.
emit
(
'setWorkspace'
,
{
name
:
workspaceName
,
isLocalhost
:
false
})
cb
&&
cb
(
null
,
workspaceName
)
}).
catch
((
error
)
=>
{
dispatch
(
createWorkspaceError
({
error
}))
cb
&&
cb
(
error
)
})
return
promise
}
...
...
@@ -204,7 +210,7 @@ export const switchToWorkspace = async (name: string) => {
}
}
export
const
uploadFile
=
async
(
target
,
targetFolder
:
string
)
=>
{
export
const
uploadFile
=
async
(
target
,
targetFolder
:
string
,
cb
?:
(
err
:
Error
,
result
?:
string
|
number
|
boolean
|
Record
<
string
,
any
>
)
=>
void
)
=>
{
// TODO The file explorer is merely a view on the current state of
// the files module. Please ask the user here if they want to overwrite
// a file and then just use `files.add`. The file explorer will
...
...
@@ -231,6 +237,7 @@ export const uploadFile = async (target, targetFolder: string) => {
}
}
fileReader
.
readAsText
(
file
)
cb
(
null
,
true
)
}
const
name
=
`
${
targetFolder
}
/
${
file
.
name
}
`
...
...
@@ -243,6 +250,7 @@ export const uploadFile = async (target, targetFolder: string) => {
},
()
=>
{}))
}
}).
catch
(
error
=>
{
cb
(
error
)
if
(
error
)
console
.
log
(
error
)
})
})
...
...
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