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
Show 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 {
}
}
workspaceRenamed
(
workspace
)
{
this
.
emit
(
'renameWorkspace'
,
workspace
)
}
workspaceDeleted
(
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) => {
}
}
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'
)
=>
{
if
(
!
workspaceName
)
throw
new
Error
(
'workspace name cannot be empty'
)
if
(
checkSpecialChars
(
workspaceName
)
||
checkSlash
(
workspaceName
))
throw
new
Error
(
'special characters are not allowed'
)
...
...
@@ -259,6 +273,27 @@ const workspaceExists = async (name: string) => {
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
=>
{
try
{
const
workspaces
:
string
[]
=
await
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -297,6 +332,7 @@ const listenOnEvents = (provider) => {
})
provider
.
event
.
on
(
'fileRenamed'
,
async
(
oldPath
:
string
,
newPath
:
string
)
=>
{
console
.
log
(
'oldPath: '
,
oldPath
,
'newPath: '
,
newPath
)
await
executeEvent
(
'fileRenamed'
,
oldPath
,
newPath
)
})
...
...
@@ -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
)
=>
{
await
dispatch
(
fileAddedSuccess
(
filePath
))
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<{
dispatchCreateWorkspace
:
(
workspaceName
:
string
)
=>
Promise
<
void
>
,
toast
:
(
toasterMsg
:
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
)
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
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import
{
FileSystemContext
}
from
'../contexts'
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'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import
{
Workspace
}
from
'../remix-ui-workspace'
...
...
@@ -54,6 +54,14 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
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
(()
=>
{
if
(
modals
.
length
>
0
)
{
setFocusModal
(()
=>
{
...
...
@@ -127,7 +135,9 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
dispatchRemoveInputField
,
dispatchCreateWorkspace
,
dispatchFetchWorkspaceDirectory
,
dispatchSwitchToWorkspace
dispatchSwitchToWorkspace
,
dispatchRenameWorkspace
,
dispatchDeleteWorkspace
}
return
(
<
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) => {
}
}
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
:
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) {
const
workspaceName
=
workspaceRenameInput
.
current
.
value
try
{
await
props
.
plugin
.
renameWorkspace
(
currentWorkspace
,
workspaceName
)
setWorkspace
(
workspaceName
)
props
.
plugin
.
workspaceRenamed
({
name
:
workspaceName
})
await
global
.
dispatchRenameWorkspace
(
currentWorkspace
,
workspaceName
)
}
catch
(
e
)
{
global
.
modal
(
'Rename Workspace'
,
e
.
message
,
'OK'
,
()
=>
{},
''
)
console
.
error
(
e
)
...
...
@@ -120,12 +118,12 @@ export function Workspace (props: WorkspaceProps) {
}
const
onFinishDeleteWorkspace
=
async
()
=>
{
await
props
.
plugin
.
fileManager
.
closeAllFiles
()
const
workspacesPath
=
props
.
plugin
.
workspace
.
workspacesPath
props
.
plugin
.
browser
.
remove
(
workspacesPath
+
'/'
+
currentWorkspace
)
const
name
=
currentWorkspace
setWorkspace
(
NO_WORKSPACE
)
props
.
plugin
.
workspaceDeleted
({
name
})
try
{
await
global
.
dispatchDeleteWorkspace
(
global
.
fs
.
browser
.
currentWorkspace
)
}
catch
(
e
)
{
global
.
modal
(
'Delete Workspace'
,
e
.
message
,
'OK'
,
()
=>
{},
''
)
console
.
error
(
e
)
}
}
/** ** ****/
...
...
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