Implement renameWorkspace and deleteWorkspace API

pull/5370/head
ioedeveloper 3 years ago
parent 9b563316a3
commit 3cb393d81c
  1. 28
      apps/remix-ide/src/app/panels/file-panel.js
  2. 10
      libs/remix-ui/workspace/src/lib/actions/events.ts
  3. 16
      libs/remix-ui/workspace/src/lib/actions/index.ts
  4. 22
      libs/remix-ui/workspace/src/lib/actions/workspace.ts

@ -29,8 +29,8 @@ const globalRegistry = require('../../global/registry')
const profile = {
name: 'filePanel',
displayName: 'File explorers',
methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getWorkspaces', 'createWorkspace', 'setWorkspace', 'registerContextMenuItem', 'renameWorkspace'],
events: ['setWorkspace', 'workspaceRenamed', 'deleteWorkspace', 'createWorkspace'],
methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getWorkspaces', 'createWorkspace', 'setWorkspace', 'registerContextMenuItem', 'renameWorkspace', 'deleteWorkspace'],
events: ['setWorkspace', 'workspaceRenamed', 'workspaceDeleted', 'workspaceCreated'],
icon: 'assets/img/fileManager.webp',
description: ' - ',
kind: 'fileexplorer',
@ -139,7 +139,21 @@ module.exports = class Filepanel extends ViewPlugin {
}
renameWorkspace (oldName, workspaceName) {
this.emit('renameWorkspace', oldName, workspaceName)
return new Promise((resolve, reject) => {
this.emit('renameWorkspaceReducerEvent', oldName, workspaceName, (err, data) => {
if (err) reject(err)
else resolve(data || true)
})
})
}
deleteWorkspace (workspaceName) {
return new Promise((resolve, reject) => {
this.emit('deleteWorkspaceReducerEvent', workspaceName, (err, data) => {
if (err) reject(err)
else resolve(data || true)
})
})
}
setWorkspace (workspace) {
@ -149,12 +163,16 @@ module.exports = class Filepanel extends ViewPlugin {
this.emit('setWorkspace', workspace)
}
workspaceRenamed (oldName, workspaceName) {
this.emit('workspaceRenamed', oldName, workspaceName)
}
workspaceDeleted (workspace) {
this.emit('deleteWorkspace', workspace)
this.emit('workspaceDeleted', workspace)
}
workspaceCreated (workspace) {
this.emit('createWorkspace', workspace)
this.emit('workspaceCreated', workspace)
}
/** end section */
}

@ -2,7 +2,7 @@ import { extractParentFromKey } from '@remix-ui/helper'
import React from 'react'
import { action } from '../types'
import { displayNotification, displayPopUp, fileAddedSuccess, fileRemovedSuccess, fileRenamedSuccess, folderAddedSuccess, loadLocalhostError, loadLocalhostRequest, loadLocalhostSuccess, removeContextMenuItem, rootFolderChangedSuccess, setContextMenuItem, setMode, setReadOnlyMode } from './payload'
import { addInputField, createWorkspace, fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile } from './workspace'
import { addInputField, createWorkspace, deleteWorkspace, fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile } from './workspace'
const LOCALHOST = ' - connect to localhost - '
let plugin, dispatch: React.Dispatch<any>
@ -14,8 +14,12 @@ export const listenOnPluginEvents = (filePanelPlugin) => {
createWorkspace(name, isEmpty, cb)
})
plugin.on('filePanel', 'renameWorkspace', (oldName: string, workspaceName: string) => {
renameWorkspace(oldName, workspaceName)
plugin.on('filePanel', 'renameWorkspaceReducerEvent', (oldName: string, workspaceName: string, cb: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
renameWorkspace(oldName, workspaceName, cb)
})
plugin.on('filePanel', 'deleteWorkspaceReducerEvent', (workspaceName: string, cb: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
deleteWorkspace(workspaceName, cb)
})
plugin.on('filePanel', 'registerContextMenuItemReducerEvent', (item: action, cb: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {

@ -2,7 +2,7 @@ import React from 'react'
import { extractNameFromKey, createNonClashingNameAsync } from '@remix-ui/helper'
import Gists from 'gists'
import { customAction } from '@remixproject/plugin-api/lib/file-system/file-panel/type'
import { displayNotification, displayPopUp, fetchDirectoryError, fetchDirectoryRequest, fetchDirectorySuccess, focusElement, hidePopUp, removeInputFieldSuccess, setCurrentWorkspace, setDeleteWorkspace, setExpandPath, setMode, setWorkspaces } from './payload'
import { displayNotification, displayPopUp, fetchDirectoryError, fetchDirectoryRequest, fetchDirectorySuccess, focusElement, hidePopUp, removeInputFieldSuccess, setCurrentWorkspace, setExpandPath, setMode, setWorkspaces } from './payload'
import { listenOnPluginEvents, listenOnProviderEvents } from './events'
import { createWorkspaceTemplate, getWorkspaces, loadWorkspacePreset, setPlugin } from './workspace'
@ -82,11 +82,6 @@ export const removeInputField = async (path: string) => {
dispatch(removeInputFieldSuccess(path))
}
export const deleteWorkspace = async (workspaceName: string) => {
await deleteWorkspaceFromProvider(workspaceName)
await dispatch(setDeleteWorkspace(workspaceName))
}
export const publishToGist = async (path?: string, type?: string) => {
// If 'id' is not defined, it is not a gist update but a creation so we have to take the files from the browser explorer.
const folder = path || '/'
@ -258,15 +253,6 @@ export const handleExpandPath = (paths: string[]) => {
dispatch(setExpandPath(paths))
}
const deleteWorkspaceFromProvider = async (workspaceName: string) => {
const workspacesPath = plugin.fileProviders.workspace.workspacesPath
await plugin.fileManager.closeAllFiles()
plugin.fileProviders.browser.remove(workspacesPath + '/' + workspaceName)
plugin.emit('deleteWorkspace', { name: workspaceName })
plugin.setWorkspaces(await getWorkspaces())
}
const packageGistFiles = (directory) => {
return new Promise((resolve, reject) => {
const workspaceProvider = plugin.fileProviders.workspace

@ -1,7 +1,7 @@
import React from 'react'
import { bufferToHex, keccakFromString } from 'ethereumjs-util'
import axios, { AxiosResponse } from 'axios'
import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload'
import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload'
import { checkSlash, checkSpecialChars } from '@remix-ui/helper'
const examples = require('../../../../../../apps/remix-ide/src/app/editor/examples')
@ -48,6 +48,7 @@ export const createWorkspace = async (workspaceName: string, isEmpty = false, cb
dispatch(createWorkspaceSuccess(workspaceName))
plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
plugin.setWorkspaces(await getWorkspaces())
plugin.workspaceCreated(workspaceName)
if (!isEmpty) await loadWorkspacePreset('default-template')
cb && cb(null, workspaceName)
}).catch((error) => {
@ -172,10 +173,12 @@ export const fetchWorkspaceDirectory = async (path: string) => {
return promise
}
export const renameWorkspace = async (oldName: string, workspaceName: string) => {
export const renameWorkspace = async (oldName: string, workspaceName: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
await renameWorkspaceFromProvider(oldName, workspaceName)
await dispatch(setRenameWorkspace(oldName, workspaceName))
plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
plugin.workspaceRenamed(oldName, workspaceName)
cb && cb(null, workspaceName)
}
export const renameWorkspaceFromProvider = async (oldName: string, workspaceName: string) => {
@ -190,6 +193,21 @@ export const renameWorkspaceFromProvider = async (oldName: string, workspaceName
plugin.setWorkspaces(await getWorkspaces())
}
export const deleteWorkspace = async (workspaceName: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
await deleteWorkspaceFromProvider(workspaceName)
await dispatch(setDeleteWorkspace(workspaceName))
plugin.workspaceDeleted(workspaceName)
cb && cb(null, workspaceName)
}
const deleteWorkspaceFromProvider = async (workspaceName: string) => {
const workspacesPath = plugin.fileProviders.workspace.workspacesPath
await plugin.fileManager.closeAllFiles()
plugin.fileProviders.browser.remove(workspacesPath + '/' + workspaceName)
plugin.setWorkspaces(await getWorkspaces())
}
export const switchToWorkspace = async (name: string) => {
await plugin.fileManager.closeAllFiles()
if (name === LOCALHOST) {

Loading…
Cancel
Save