Clone cleanup

pull/2554/head
David Disu 2 years ago
parent d6fedba4bb
commit 9edfd398c8
  1. 13
      apps/remix-ide/src/app/files/dgitProvider.js
  2. 5
      libs/remix-ui/workspace/src/lib/actions/index.ts
  3. 18
      libs/remix-ui/workspace/src/lib/actions/payload.ts
  4. 26
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  5. 58
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  6. 68
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -233,12 +233,11 @@ class DGitProvider extends Plugin {
return this.calculateLocalStorage() return this.calculateLocalStorage()
} }
async clone (input, workspaceName) { async clone (input, workspaceName, workspaceExists = false) {
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.') const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.')
if (!permission) return false if (!permission) return false
if (this.calculateLocalStorage() > 10000) throw new Error('The local storage of the browser is full.') if (this.calculateLocalStorage() > 10000) throw new Error('The local storage of the browser is full.')
await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true) if (!workspaceExists) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true)
const cmd = { const cmd = {
url: input.url, url: input.url,
singleBranch: input.singleBranch, singleBranch: input.singleBranch,
@ -249,9 +248,11 @@ class DGitProvider extends Plugin {
} }
const result = await git.clone(cmd) const result = await git.clone(cmd)
setTimeout(async () => { if (!workspaceExists) {
await this.call('fileManager', 'refresh') setTimeout(async () => {
}, 1000) await this.call('fileManager', 'refresh')
}, 1000)
}
return result return result
} }

@ -33,9 +33,10 @@ const basicWorkspaceInit = async (workspaces: { name: string; isGitRepo: boolean
} else { } else {
if (workspaces.length > 0) { if (workspaces.length > 0) {
const workspace = workspaces[workspaces.length - 1] const workspace = workspaces[workspaces.length - 1]
const workspaceName = (workspace || {}).name
workspaceProvider.setWorkspace(workspace.name) workspaceProvider.setWorkspace(workspaceName)
plugin.setWorkspace({ name: (workspace || {}).name, isLocalhost: false }) plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
dispatch(setCurrentWorkspace(workspace)) dispatch(setCurrentWorkspace(workspace))
} }
} }

@ -239,3 +239,21 @@ export const fsInitializationCompleted = () => {
type: 'FS_INITIALIZATION_COMPLETED' type: 'FS_INITIALIZATION_COMPLETED'
} }
} }
export const cloneRepositoryRequest = () => {
return {
type: 'CLONE_REPOSITORY_REQUEST'
}
}
export const cloneRepositorySuccess = () => {
return {
type: 'CLONE_REPOSITORY_SUCCESS'
}
}
export const cloneRepositoryFailed = () => {
return {
type: 'CLONE_REPOSITORY_FAILED'
}
}

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import { bufferToHex, keccakFromString } from 'ethereumjs-util' import { bufferToHex, keccakFromString } from 'ethereumjs-util'
import axios, { AxiosResponse } from 'axios' import axios, { AxiosResponse } from 'axios'
import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload' import { addInputFieldSuccess, cloneRepositoryFailed, cloneRepositoryRequest, cloneRepositorySuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload'
import { checkSlash, checkSpecialChars, createNonClashingTitle } from '@remix-ui/helper' import { checkSlash, checkSpecialChars, createNonClashingTitle } from '@remix-ui/helper'
import { JSONStandardInput, WorkspaceTemplate } from '../types' import { JSONStandardInput, WorkspaceTemplate } from '../types'
@ -42,13 +42,13 @@ export const addInputField = async (type: 'file' | 'folder', path: string, cb?:
return promise return promise
} }
export const createWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => { export const createWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void, isGitRepo: boolean = false) => {
await plugin.fileManager.closeAllFiles() await plugin.fileManager.closeAllFiles()
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName) const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName)
dispatch(createWorkspaceRequest(promise)) dispatch(createWorkspaceRequest(promise))
promise.then(async () => { promise.then(async () => {
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo: false })) dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo }))
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) await plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
await plugin.setWorkspaces(await getWorkspaces()) await plugin.setWorkspaces(await getWorkspaces())
await plugin.workspaceCreated(workspaceName) await plugin.workspaceCreated(workspaceName)
@ -334,12 +334,26 @@ export const cloneRepository = async (url: string) => {
const token = config.get('currentFile') const token = config.get('currentFile')
const repoConfig = { url, token } const repoConfig = { url, token }
const urlArray = url.split('/') const urlArray = url.split('/')
let repoName = urlArray[urlArray.length - 1] let repoName = urlArray.length > 0 ? urlArray[urlArray.length - 1] : ''
try { try {
repoName = await createNonClashingTitle(repoName, plugin.fileManager) repoName = await createNonClashingTitle(repoName, plugin.fileManager)
await plugin.call('dGitProvider', 'clone', repoConfig, repoName) await createWorkspace(repoName, 'blank', true, null, true)
await plugin.call('manager', 'activatePlugin', 'dgit') const promise = plugin.call('dGitProvider', 'clone', repoConfig, repoName, true)
dispatch(cloneRepositoryRequest())
promise.then(async () => {
const isActive = await plugin.call('manager', 'isActive', 'dgit')
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit')
await fetchWorkspaceDirectory(repoName)
dispatch(cloneRepositorySuccess())
}).catch((e) => {
dispatch(displayNotification('Clone Git Repository', 'An error occured: ' + e, 'Ok', null, async () => {
await deleteWorkspace(repoName)
dispatch(cloneRepositoryFailed())
}))
})
} catch (e) { } catch (e) {
dispatch(displayPopUp('An error occured: ' + e)) dispatch(displayPopUp('An error occured: ' + e))
} }

@ -18,6 +18,8 @@ export interface BrowserState {
isSuccessfulDirectory: boolean, isSuccessfulDirectory: boolean,
isRequestingWorkspace: boolean, isRequestingWorkspace: boolean,
isSuccessfulWorkspace: boolean, isSuccessfulWorkspace: boolean,
isRequestingCloning: boolean,
isSuccessfulCloning: boolean,
error: string, error: string,
contextMenu: { contextMenu: {
registeredMenuItems: action[], registeredMenuItems: action[],
@ -53,8 +55,7 @@ export interface BrowserState {
popup: string, popup: string,
focusEdit: string, focusEdit: string,
focusElement: { key: string, type: 'file' | 'folder' | 'gist' }[], focusElement: { key: string, type: 'file' | 'folder' | 'gist' }[],
initializingFS: boolean, initializingFS: boolean
isGitRepo: boolean
} }
export const browserInitialState: BrowserState = { export const browserInitialState: BrowserState = {
@ -67,6 +68,8 @@ export const browserInitialState: BrowserState = {
isSuccessfulDirectory: false, isSuccessfulDirectory: false,
isRequestingWorkspace: false, isRequestingWorkspace: false,
isSuccessfulWorkspace: false, isSuccessfulWorkspace: false,
isRequestingCloning: false,
isSuccessfulCloning: false,
error: null, error: null,
contextMenu: { contextMenu: {
registeredMenuItems: [], registeredMenuItems: [],
@ -102,8 +105,7 @@ export const browserInitialState: BrowserState = {
popup: '', popup: '',
focusEdit: '', focusEdit: '',
focusElement: [], focusElement: [],
initializingFS: true, initializingFS: true
isGitRepo: false
} }
export const browserReducer = (state = browserInitialState, action: Action) => { export const browserReducer = (state = browserInitialState, action: Action) => {
@ -451,14 +453,25 @@ 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 && (name !== payload.oldName)) let renamedWorkspace
const workspaces = state.browser.workspaces.filter(({ name, isGitRepo }) => {
if (name && (name !== payload.oldName)) {
return true
} else {
renamedWorkspace = {
name: payload.workspaceName,
isGitRepo
}
return false
}
})
return { return {
...state, ...state,
browser: { browser: {
...state.browser, ...state.browser,
currentWorkspace: payload.workspaceName, currentWorkspace: payload.workspaceName,
workspaces: [...workspaces, payload.workspaceName], workspaces: [...workspaces, renamedWorkspace],
expandPath: [] expandPath: []
} }
} }
@ -597,6 +610,39 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
} }
} }
case 'CLONE_REPOSITORY_REQUEST': {
return {
...state,
browser: {
...state.browser,
isRequestingCloning: true,
isSuccessfulCloning: false
}
}
}
case 'CLONE_REPOSITORY_SUCCESS': {
return {
...state,
browser: {
...state.browser,
isRequestingCloning: false,
isSuccessfulCloning: true
}
}
}
case 'CLONE_REPOSITORY_FAILED': {
return {
...state,
browser: {
...state.browser,
isRequestingCloning: false,
isSuccessfulCloning: false
}
}
}
case 'FS_INITIALIZATION_COMPLETED': { case 'FS_INITIALIZATION_COMPLETED': {
return { return {
...state, ...state,

@ -290,39 +290,41 @@ export function Workspace () {
</div> </div>
<div className='h-100 remixui_fileExplorerTree'> <div className='h-100 remixui_fileExplorerTree'>
<div className='h-100'> <div className='h-100'>
<div className='pl-2 remixui_treeview' data-id='filePanelFileExplorerTree'> { global.fs.browser.isRequestingWorkspace || global.fs.browser.isRequestingCloning ? <div className="text-center py-5"><i className="fas fa-spinner fa-pulse fa-2x"></i></div>
{ (global.fs.mode === 'browser') && (currentWorkspace !== NO_WORKSPACE) && : <div className='pl-2 remixui_treeview' data-id='filePanelFileExplorerTree'>
<FileExplorer { (global.fs.mode === 'browser') && (currentWorkspace !== NO_WORKSPACE) &&
name={currentWorkspace} <FileExplorer
menuItems={['createNewFile', 'createNewFolder', 'publishToGist', canUpload ? 'uploadFile' : '']} name={currentWorkspace}
contextMenuItems={global.fs.browser.contextMenu.registeredMenuItems} menuItems={['createNewFile', 'createNewFolder', 'publishToGist', canUpload ? 'uploadFile' : '']}
removedContextMenuItems={global.fs.browser.contextMenu.removedMenuItems} contextMenuItems={global.fs.browser.contextMenu.registeredMenuItems}
files={global.fs.browser.files} removedContextMenuItems={global.fs.browser.contextMenu.removedMenuItems}
expandPath={global.fs.browser.expandPath} files={global.fs.browser.files}
focusEdit={global.fs.focusEdit} expandPath={global.fs.browser.expandPath}
focusElement={global.fs.focusElement} focusEdit={global.fs.focusEdit}
dispatchCreateNewFile={global.dispatchCreateNewFile} focusElement={global.fs.focusElement}
modal={global.modal} dispatchCreateNewFile={global.dispatchCreateNewFile}
dispatchCreateNewFolder={global.dispatchCreateNewFolder} modal={global.modal}
readonly={global.fs.readonly} dispatchCreateNewFolder={global.dispatchCreateNewFolder}
toast={global.toast} readonly={global.fs.readonly}
dispatchDeletePath={global.dispatchDeletePath} toast={global.toast}
dispatchRenamePath={global.dispatchRenamePath} dispatchDeletePath={global.dispatchDeletePath}
dispatchUploadFile={global.dispatchUploadFile} dispatchRenamePath={global.dispatchRenamePath}
dispatchCopyFile={global.dispatchCopyFile} dispatchUploadFile={global.dispatchUploadFile}
dispatchCopyFolder={global.dispatchCopyFolder} dispatchCopyFile={global.dispatchCopyFile}
dispatchPublishToGist={global.dispatchPublishToGist} dispatchCopyFolder={global.dispatchCopyFolder}
dispatchRunScript={global.dispatchRunScript} dispatchPublishToGist={global.dispatchPublishToGist}
dispatchEmitContextMenuEvent={global.dispatchEmitContextMenuEvent} dispatchRunScript={global.dispatchRunScript}
dispatchHandleClickFile={global.dispatchHandleClickFile} dispatchEmitContextMenuEvent={global.dispatchEmitContextMenuEvent}
dispatchSetFocusElement={global.dispatchSetFocusElement} dispatchHandleClickFile={global.dispatchHandleClickFile}
dispatchFetchDirectory={global.dispatchFetchDirectory} dispatchSetFocusElement={global.dispatchSetFocusElement}
dispatchRemoveInputField={global.dispatchRemoveInputField} dispatchFetchDirectory={global.dispatchFetchDirectory}
dispatchAddInputField={global.dispatchAddInputField} dispatchRemoveInputField={global.dispatchRemoveInputField}
dispatchHandleExpandPath={global.dispatchHandleExpandPath} dispatchAddInputField={global.dispatchAddInputField}
/> dispatchHandleExpandPath={global.dispatchHandleExpandPath}
} />
</div> }
</div>
}
{ {
global.fs.localhost.isRequestingLocalhost ? <div className="text-center py-5"><i className="fas fa-spinner fa-pulse fa-2x"></i></div> global.fs.localhost.isRequestingLocalhost ? <div className="text-center py-5"><i className="fas fa-spinner fa-pulse fa-2x"></i></div>
: <div className='pl-2 filesystemexplorer remixui_treeview'> : <div className='pl-2 filesystemexplorer remixui_treeview'>

Loading…
Cancel
Save