Delete workspaces

pull/5370/head
ioedeveloper 3 years ago
parent f522059ec8
commit d1d26df1ae
  1. 5
      apps/remix-ide/src/app/files/workspaceFileProvider.js
  2. 2
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  3. 8
      libs/remix-ui/workspace/src/lib/contexts/index.ts
  4. 14
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  5. 22
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -13,6 +13,7 @@ class WorkspaceFileProvider extends FileProvider {
} }
setWorkspace (workspace) { setWorkspace (workspace) {
if (!workspace) return
workspace = workspace.replace(/^\/|\/$/g, '') // remove first and last slash workspace = workspace.replace(/^\/|\/$/g, '') // remove first and last slash
this.workspace = workspace this.workspace = workspace
} }
@ -30,7 +31,7 @@ class WorkspaceFileProvider extends FileProvider {
} }
removePrefix (path) { removePrefix (path) {
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 path.replace(this.workspace, this.workspacesPath + '/' + this.workspace) if (path.startsWith(this.workspace)) return path.replace(this.workspace, this.workspacesPath + '/' + this.workspace)
@ -76,7 +77,7 @@ class WorkspaceFileProvider extends FileProvider {
} }
_normalizePath (path) { _normalizePath (path) {
if (!this.workspace) this.createWorkspace() // if (!this.workspace) this.createWorkspace()
return path.replace(this.workspacesPath + '/' + this.workspace + '/', '') return path.replace(this.workspacesPath + '/' + this.workspace + '/', '')
} }

@ -290,7 +290,6 @@ const deleteWorkspaceFromProvider = async (workspaceName: string) => {
await plugin.fileManager.closeAllFiles() await plugin.fileManager.closeAllFiles()
plugin.fileProviders.browser.remove(workspacesPath + '/' + workspaceName) plugin.fileProviders.browser.remove(workspacesPath + '/' + workspaceName)
// switchToWorkspace(NO_WORKSPACE)
plugin.emit('deleteWorkspace', { name: workspaceName }) plugin.emit('deleteWorkspace', { name: workspaceName })
} }
@ -523,6 +522,7 @@ export const switchToWorkspace = (name: string) => async (dispatch: React.Dispat
plugin.emit('setWorkspace', { name: LOCALHOST, isLocalhost: true }) plugin.emit('setWorkspace', { name: LOCALHOST, isLocalhost: true })
} else if (name === NO_WORKSPACE) { } else if (name === NO_WORKSPACE) {
plugin.fileProviders.workspace.clearWorkspace() plugin.fileProviders.workspace.clearWorkspace()
dispatch(setCurrentWorkspace(null))
} else { } else {
plugin.fileManager.setMode('browser') plugin.fileManager.setMode('browser')
const isActive = await plugin.call('manager', 'isActive', 'remixd') const isActive = await plugin.call('manager', 'isActive', 'remixd')

@ -10,8 +10,8 @@ export const FileSystemContext = createContext<{
dispatchRemoveInputField:(path: string) => Promise<void>, dispatchRemoveInputField:(path: string) => Promise<void>,
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) => Promise<void>,
dispatchSwitchToWorkspace: (name: string) => void, dispatchSwitchToWorkspace: (name: string) => Promise<void>,
dispatchRenameWorkspace: (oldName: string, workspaceName: string) => void, dispatchRenameWorkspace: (oldName: string, workspaceName: string) => Promise<void>,
dispatchDeleteWorkspace: (workspaceName: string) => void dispatchDeleteWorkspace: (workspaceName: string) => Promise<void>
}>(null) }>(null)

@ -68,13 +68,14 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
switch (action.type) { switch (action.type) {
case 'SET_CURRENT_WORKSPACE': { case 'SET_CURRENT_WORKSPACE': {
const payload = action.payload as string const payload = action.payload as string
const workspaces = state.browser.workspaces.includes(payload) ? state.browser.workspaces : [...state.browser.workspaces, action.payload]
return { return {
...state, ...state,
browser: { browser: {
...state.browser, ...state.browser,
currentWorkspace: payload, currentWorkspace: payload,
workspaces: state.browser.workspaces.includes(payload) ? state.browser.workspaces : [...state.browser.workspaces, action.payload] workspaces: workspaces.filter(workspace => workspace)
} }
} }
} }
@ -86,7 +87,7 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
...state, ...state,
browser: { browser: {
...state.browser, ...state.browser,
workspaces: payload workspaces: payload.filter(workspace => workspace)
} }
} }
} }
@ -376,13 +377,14 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
case 'CREATE_WORKSPACE_SUCCESS': { case 'CREATE_WORKSPACE_SUCCESS': {
const payload = action.payload as string const payload = action.payload as string
const workspaces = state.browser.workspaces.includes(payload) ? state.browser.workspaces : [...state.browser.workspaces, action.payload]
return { return {
...state, ...state,
browser: { browser: {
...state.browser, ...state.browser,
currentWorkspace: payload, currentWorkspace: payload,
workspaces: state.browser.workspaces.includes(payload) ? state.browser.workspaces : [...state.browser.workspaces, action.payload], workspaces: workspaces.filter(workspace => workspace),
isRequesting: false, isRequesting: false,
isSuccessful: true, isSuccessful: true,
error: null error: null
@ -404,7 +406,7 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
case 'RENAME_WORKSPACE': { case 'RENAME_WORKSPACE': {
const payload = action.payload as { oldName: string, workspaceName: string } const payload = action.payload as { oldName: string, workspaceName: string }
const workspaces = state.browser.workspaces.filter(name => name !== payload.oldName) const workspaces = state.browser.workspaces.filter(name => name && (name !== payload.oldName))
return { return {
...state, ...state,
@ -418,14 +420,12 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
case 'DELETE_WORKSPACE': { case 'DELETE_WORKSPACE': {
const payload = action.payload as string const payload = action.payload as string
const workspaces = state.browser.workspaces.filter(name => name !== payload) const workspaces = state.browser.workspaces.filter(name => name && (name !== payload))
const currentWorkspace = state.browser.currentWorkspace === payload ? workspaces.length > 0 ? workspaces[0] : '' : state.browser.currentWorkspace
return { return {
...state, ...state,
browser: { browser: {
...state.browser, ...state.browser,
currentWorkspace: currentWorkspace,
workspaces: workspaces workspaces: workspaces
} }
} }

@ -26,7 +26,8 @@ export function Workspace (props: WorkspaceProps) {
useEffect(() => { useEffect(() => {
if (global.fs.mode === 'browser') { if (global.fs.mode === 'browser') {
setCurrentWorkspace(global.fs.browser.currentWorkspace) if (global.fs.browser.currentWorkspace) setCurrentWorkspace(global.fs.browser.currentWorkspace)
else setCurrentWorkspace(NO_WORKSPACE)
global.dispatchFetchWorkspaceDirectory(global.fs.browser.currentWorkspace) global.dispatchFetchWorkspaceDirectory(global.fs.browser.currentWorkspace)
} else if (global.fs.mode === 'localhost') { } else if (global.fs.mode === 'localhost') {
// global.dispatchFetchWorkspaceDirectory('/') // global.dispatchFetchWorkspaceDirectory('/')
@ -34,6 +35,16 @@ export function Workspace (props: WorkspaceProps) {
} }
}, [global.fs.browser.currentWorkspace, global.fs.localhost.sharedFolder, global.fs.mode]) }, [global.fs.browser.currentWorkspace, global.fs.localhost.sharedFolder, global.fs.mode])
useEffect(() => {
if (global.fs.browser.currentWorkspace && !global.fs.browser.workspaces.includes(global.fs.browser.currentWorkspace)) {
if (global.fs.browser.workspaces.length > 0) {
switchWorkspace(global.fs.browser.workspaces[global.fs.browser.workspaces.length - 1])
} else {
switchWorkspace(NO_WORKSPACE)
}
}
}, [global.fs.browser.workspaces])
props.plugin.resetNewFile = () => { props.plugin.resetNewFile = () => {
setState(prevState => { setState(prevState => {
return { ...prevState, displayNewFile: !state.displayNewFile } return { ...prevState, displayNewFile: !state.displayNewFile }
@ -134,7 +145,12 @@ export function Workspace (props: WorkspaceProps) {
} }
const switchWorkspace = async (name: string) => { const switchWorkspace = async (name: string) => {
global.dispatchSwitchToWorkspace(name) try {
await global.dispatchSwitchToWorkspace(name)
} catch (e) {
global.modal('Switch To Workspace', e.message, 'OK', () => {}, '')
console.error(e)
}
} }
const createModalMessage = () => { const createModalMessage = () => {
@ -212,7 +228,7 @@ export function Workspace (props: WorkspaceProps) {
<div className='remixui_fileExplorerTree'> <div className='remixui_fileExplorerTree'>
<div> <div>
<div className='pl-2 remixui_treeview' data-id='filePanelFileExplorerTree'> <div className='pl-2 remixui_treeview' data-id='filePanelFileExplorerTree'>
{ global.fs.mode === 'browser' && { (global.fs.mode === 'browser') && (currentWorkspace !== NO_WORKSPACE) &&
<FileExplorer <FileExplorer
name={currentWorkspace} name={currentWorkspace}
registry={props.plugin.registry} registry={props.plugin.registry}

Loading…
Cancel
Save