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
a23514ee
Commit
a23514ee
authored
Sep 13, 2021
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename and delete workspaces
parent
736aab3e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
97 additions
and
16 deletions
+97
-16
file-panel.js
apps/remix-ide/src/app/panels/file-panel.js
+0
-4
workspace.ts
libs/remix-ui/workspace/src/lib/actions/workspace.ts
+46
-0
index.ts
libs/remix-ui/workspace/src/lib/contexts/index.ts
+3
-1
FileSystemProvider.tsx
...mix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
+12
-2
workspace.ts
libs/remix-ui/workspace/src/lib/reducers/workspace.ts
+29
-0
remix-ui-workspace.tsx
libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
+7
-9
No files found.
apps/remix-ide/src/app/panels/file-panel.js
View file @
a23514ee
...
@@ -201,10 +201,6 @@ module.exports = class Filepanel extends ViewPlugin {
...
@@ -201,10 +201,6 @@ module.exports = class Filepanel extends ViewPlugin {
}
}
}
}
workspaceRenamed
(
workspace
)
{
this
.
emit
(
'renameWorkspace'
,
workspace
)
}
workspaceDeleted
(
workspace
)
{
workspaceDeleted
(
workspace
)
{
this
.
emit
(
'deleteWorkspace'
,
workspace
)
this
.
emit
(
'deleteWorkspace'
,
workspace
)
}
}
...
...
libs/remix-ui/workspace/src/lib/actions/workspace.ts
View file @
a23514ee
...
@@ -165,6 +165,20 @@ const fetchWorkspaceDirectorySuccess = (path: string, fileTree) => {
...
@@ -165,6 +165,20 @@ const fetchWorkspaceDirectorySuccess = (path: string, fileTree) => {
}
}
}
}
const
setRenameWorkspace
=
(
oldName
:
string
,
workspaceName
:
string
)
=>
{
return
{
type
:
'RENAME_WORKSPACE'
,
payload
:
{
oldName
,
workspaceName
}
}
}
const
setDeleteWorkspace
=
(
workspaceName
:
string
)
=>
{
return
{
type
:
'DELETE_WORKSPACE'
,
payload
:
workspaceName
}
}
const
createWorkspaceTemplate
=
async
(
workspaceName
:
string
,
setDefaults
=
true
,
template
:
'gist-template'
|
'code-template'
|
'default-template'
=
'default-template'
)
=>
{
const
createWorkspaceTemplate
=
async
(
workspaceName
:
string
,
setDefaults
=
true
,
template
:
'gist-template'
|
'code-template'
|
'default-template'
=
'default-template'
)
=>
{
if
(
!
workspaceName
)
throw
new
Error
(
'workspace name cannot be empty'
)
if
(
!
workspaceName
)
throw
new
Error
(
'workspace name cannot be empty'
)
if
(
checkSpecialChars
(
workspaceName
)
||
checkSlash
(
workspaceName
))
throw
new
Error
(
'special characters are not allowed'
)
if
(
checkSpecialChars
(
workspaceName
)
||
checkSlash
(
workspaceName
))
throw
new
Error
(
'special characters are not allowed'
)
...
@@ -259,6 +273,27 @@ const workspaceExists = async (name: string) => {
...
@@ -259,6 +273,27 @@ const workspaceExists = async (name: string) => {
return
browserProvider
.
exists
(
workspacePath
)
return
browserProvider
.
exists
(
workspacePath
)
}
}
const
renameWorkspaceFromProvider
=
async
(
oldName
:
string
,
workspaceName
:
string
)
=>
{
if
(
!
workspaceName
)
throw
new
Error
(
'name cannot be empty'
)
if
(
checkSpecialChars
(
workspaceName
)
||
checkSlash
(
workspaceName
))
throw
new
Error
(
'special characters are not allowed'
)
if
(
await
workspaceExists
(
workspaceName
))
throw
new
Error
(
'workspace already exists'
)
const
browserProvider
=
plugin
.
fileProviders
.
browser
const
workspaceProvider
=
plugin
.
fileProviders
.
workspace
const
workspacesPath
=
workspaceProvider
.
workspacesPath
browserProvider
.
rename
(
'browser/'
+
workspacesPath
+
'/'
+
oldName
,
'browser/'
+
workspacesPath
+
'/'
+
workspaceName
,
true
)
workspaceProvider
.
setWorkspace
(
workspaceName
)
plugin
.
emit
(
'renameWorkspace'
,
{
name
:
workspaceName
})
}
const
deleteWorkspaceFromProvider
=
async
(
workspaceName
:
string
)
=>
{
const
workspacesPath
=
plugin
.
fileProviders
.
workspace
.
workspacesPath
await
plugin
.
fileManager
.
closeAllFiles
()
plugin
.
fileProviders
.
browser
.
remove
(
workspacesPath
+
'/'
+
workspaceName
)
// switchToWorkspace(NO_WORKSPACE)
plugin
.
emit
(
'deleteWorkspace'
,
{
name
:
workspaceName
})
}
const
getWorkspaces
=
async
():
Promise
<
string
[]
>
|
undefined
=>
{
const
getWorkspaces
=
async
():
Promise
<
string
[]
>
|
undefined
=>
{
try
{
try
{
const
workspaces
:
string
[]
=
await
new
Promise
((
resolve
,
reject
)
=>
{
const
workspaces
:
string
[]
=
await
new
Promise
((
resolve
,
reject
)
=>
{
...
@@ -297,6 +332,7 @@ const listenOnEvents = (provider) => {
...
@@ -297,6 +332,7 @@ const listenOnEvents = (provider) => {
})
})
provider
.
event
.
on
(
'fileRenamed'
,
async
(
oldPath
:
string
,
newPath
:
string
)
=>
{
provider
.
event
.
on
(
'fileRenamed'
,
async
(
oldPath
:
string
,
newPath
:
string
)
=>
{
console
.
log
(
'oldPath: '
,
oldPath
,
'newPath: '
,
newPath
)
await
executeEvent
(
'fileRenamed'
,
oldPath
,
newPath
)
await
executeEvent
(
'fileRenamed'
,
oldPath
,
newPath
)
})
})
...
@@ -500,6 +536,16 @@ export const switchToWorkspace = (name: string) => async (dispatch: React.Dispat
...
@@ -500,6 +536,16 @@ export const switchToWorkspace = (name: string) => async (dispatch: React.Dispat
}
}
}
}
export
const
renameWorkspace
=
(
oldName
:
string
,
workspaceName
:
string
)
=>
async
(
dispatch
:
React
.
Dispatch
<
any
>
)
=>
{
await
renameWorkspaceFromProvider
(
oldName
,
workspaceName
)
await
dispatch
(
setRenameWorkspace
(
oldName
,
workspaceName
))
}
export
const
deleteWorkspace
=
(
workspaceName
:
string
)
=>
async
(
dispatch
:
React
.
Dispatch
<
any
>
)
=>
{
await
deleteWorkspaceFromProvider
(
workspaceName
)
await
dispatch
(
setDeleteWorkspace
(
workspaceName
))
}
const
fileAdded
=
async
(
filePath
:
string
)
=>
{
const
fileAdded
=
async
(
filePath
:
string
)
=>
{
await
dispatch
(
fileAddedSuccess
(
filePath
))
await
dispatch
(
fileAddedSuccess
(
filePath
))
if
(
filePath
.
includes
(
'_test.sol'
))
{
if
(
filePath
.
includes
(
'_test.sol'
))
{
...
...
libs/remix-ui/workspace/src/lib/contexts/index.ts
View file @
a23514ee
...
@@ -11,5 +11,7 @@ export const FileSystemContext = createContext<{
...
@@ -11,5 +11,7 @@ export const FileSystemContext = createContext<{
dispatchCreateWorkspace
:
(
workspaceName
:
string
)
=>
Promise
<
void
>
,
dispatchCreateWorkspace
:
(
workspaceName
:
string
)
=>
Promise
<
void
>
,
toast
:
(
toasterMsg
:
string
)
=>
void
,
toast
:
(
toasterMsg
:
string
)
=>
void
,
dispatchFetchWorkspaceDirectory
:
(
path
:
string
)
=>
void
,
dispatchFetchWorkspaceDirectory
:
(
path
:
string
)
=>
void
,
dispatchSwitchToWorkspace
:
(
name
:
string
)
=>
void
dispatchSwitchToWorkspace
:
(
name
:
string
)
=>
void
,
dispatchRenameWorkspace
:
(
oldName
:
string
,
workspaceName
:
string
)
=>
void
,
dispatchDeleteWorkspace
:
(
workspaceName
:
string
)
=>
void
}
>
(
null
)
}
>
(
null
)
libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
View file @
a23514ee
...
@@ -5,7 +5,7 @@ import { Toaster } from '@remix-ui/toaster' // eslint-disable-line
...
@@ -5,7 +5,7 @@ import { Toaster } from '@remix-ui/toaster' // eslint-disable-line
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import
{
FileSystemContext
}
from
'../contexts'
import
{
FileSystemContext
}
from
'../contexts'
import
{
browserReducer
,
browserInitialState
}
from
'../reducers/workspace'
import
{
browserReducer
,
browserInitialState
}
from
'../reducers/workspace'
import
{
initWorkspace
,
fetchDirectory
,
addInputField
,
removeInputField
,
createWorkspace
,
fetchWorkspaceDirectory
,
switchToWorkspace
}
from
'../actions/workspace'
import
{
initWorkspace
,
fetchDirectory
,
addInputField
,
removeInputField
,
createWorkspace
,
fetchWorkspaceDirectory
,
switchToWorkspace
,
renameWorkspace
,
deleteWorkspace
}
from
'../actions/workspace'
import
{
Modal
,
WorkspaceProps
}
from
'../types'
import
{
Modal
,
WorkspaceProps
}
from
'../types'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import
{
Workspace
}
from
'../remix-ui-workspace'
import
{
Workspace
}
from
'../remix-ui-workspace'
...
@@ -54,6 +54,14 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
...
@@ -54,6 +54,14 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await
switchToWorkspace
(
name
)(
fsDispatch
)
await
switchToWorkspace
(
name
)(
fsDispatch
)
}
}
const
dispatchRenameWorkspace
=
async
(
oldName
:
string
,
workspaceName
:
string
)
=>
{
await
renameWorkspace
(
oldName
,
workspaceName
)(
fsDispatch
)
}
const
dispatchDeleteWorkspace
=
async
(
workspaceName
:
string
)
=>
{
await
deleteWorkspace
(
workspaceName
)(
fsDispatch
)
}
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
modals
.
length
>
0
)
{
if
(
modals
.
length
>
0
)
{
setFocusModal
(()
=>
{
setFocusModal
(()
=>
{
...
@@ -127,7 +135,9 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
...
@@ -127,7 +135,9 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
dispatchRemoveInputField
,
dispatchRemoveInputField
,
dispatchCreateWorkspace
,
dispatchCreateWorkspace
,
dispatchFetchWorkspaceDirectory
,
dispatchFetchWorkspaceDirectory
,
dispatchSwitchToWorkspace
dispatchSwitchToWorkspace
,
dispatchRenameWorkspace
,
dispatchDeleteWorkspace
}
}
return
(
return
(
<
FileSystemContext
.
Provider
value=
{
value
}
>
<
FileSystemContext
.
Provider
value=
{
value
}
>
...
...
libs/remix-ui/workspace/src/lib/reducers/workspace.ts
View file @
a23514ee
...
@@ -402,6 +402,35 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
...
@@ -402,6 +402,35 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
}
}
}
case
'RENAME_WORKSPACE'
:
{
const
payload
=
action
.
payload
as
{
oldName
:
string
,
workspaceName
:
string
}
const
workspaces
=
state
.
browser
.
workspaces
.
filter
(
name
=>
name
!==
payload
.
oldName
)
return
{
...
state
,
browser
:
{
...
state
.
browser
,
currentWorkspace
:
payload
.
workspaceName
,
workspaces
:
[...
workspaces
,
payload
.
workspaceName
]
}
}
}
case
'DELETE_WORKSPACE'
:
{
const
payload
=
action
.
payload
as
string
const
workspaces
=
state
.
browser
.
workspaces
.
filter
(
name
=>
name
!==
payload
)
const
currentWorkspace
=
state
.
browser
.
currentWorkspace
===
payload
?
workspaces
.
length
>
0
?
workspaces
[
0
]
:
''
:
state
.
browser
.
currentWorkspace
return
{
...
state
,
browser
:
{
...
state
.
browser
,
currentWorkspace
:
currentWorkspace
,
workspaces
:
workspaces
}
}
}
default
:
default
:
throw
new
Error
()
throw
new
Error
()
}
}
...
...
libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
View file @
a23514ee
...
@@ -97,9 +97,7 @@ export function Workspace (props: WorkspaceProps) {
...
@@ -97,9 +97,7 @@ export function Workspace (props: WorkspaceProps) {
const
workspaceName
=
workspaceRenameInput
.
current
.
value
const
workspaceName
=
workspaceRenameInput
.
current
.
value
try
{
try
{
await
props
.
plugin
.
renameWorkspace
(
currentWorkspace
,
workspaceName
)
await
global
.
dispatchRenameWorkspace
(
currentWorkspace
,
workspaceName
)
setWorkspace
(
workspaceName
)
props
.
plugin
.
workspaceRenamed
({
name
:
workspaceName
})
}
catch
(
e
)
{
}
catch
(
e
)
{
global
.
modal
(
'Rename Workspace'
,
e
.
message
,
'OK'
,
()
=>
{},
''
)
global
.
modal
(
'Rename Workspace'
,
e
.
message
,
'OK'
,
()
=>
{},
''
)
console
.
error
(
e
)
console
.
error
(
e
)
...
@@ -120,12 +118,12 @@ export function Workspace (props: WorkspaceProps) {
...
@@ -120,12 +118,12 @@ export function Workspace (props: WorkspaceProps) {
}
}
const
onFinishDeleteWorkspace
=
async
()
=>
{
const
onFinishDeleteWorkspace
=
async
()
=>
{
await
props
.
plugin
.
fileManager
.
closeAllFiles
()
try
{
const
workspacesPath
=
props
.
plugin
.
workspace
.
workspacesPath
await
global
.
dispatchDeleteWorkspace
(
global
.
fs
.
browser
.
currentWorkspace
)
props
.
plugin
.
browser
.
remove
(
workspacesPath
+
'/'
+
currentWorkspace
)
}
catch
(
e
)
{
const
name
=
currentWorkspace
global
.
modal
(
'Delete Workspace'
,
e
.
message
,
'OK'
,
()
=>
{},
''
)
setWorkspace
(
NO_WORKSPACE
)
console
.
error
(
e
)
props
.
plugin
.
workspaceDeleted
({
name
})
}
}
}
/** ** ****/
/** ** ****/
...
...
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