Clone with repo name and activate dgit after clone

pull/2554/head
David Disu 2 years ago
parent 59d8478906
commit e9989f7f81
  1. 4
      apps/remix-ide/src/app/files/dgitProvider.js
  2. 16
      libs/remix-ui/helper/src/lib/remix-ui-helper.ts
  3. 8
      libs/remix-ui/tooltip-popup/src/lib/tooltip-popup.tsx
  4. 14
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  5. 2
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -233,11 +233,11 @@ class DGitProvider extends Plugin {
return this.calculateLocalStorage() return this.calculateLocalStorage()
} }
async clone (input) { async clone (input, workspaceName) {
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', `workspace_${Date.now()}`, true) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true)
const cmd = { const cmd = {
url: input.url, url: input.url,

@ -47,6 +47,22 @@ export const createNonClashingNameAsync = async (name: string, fileManager, pref
return name + counter + prefix + '.' + ext return name + counter + prefix + '.' + ext
} }
export const createNonClashingTitle = async (name: string, fileManager) => {
if (!name) name = 'Undefined'
let _counter
let exist = true
do {
const isDuplicate = await fileManager.exists(name + (_counter || ''))
if (isDuplicate) _counter = (_counter || 0) + 1
else exist = false
} while (exist)
const counter = _counter || ''
return name + counter
}
export const joinPath = (...paths) => { export const joinPath = (...paths) => {
paths = paths.filter((value) => value !== '').map((path) => path.replace(/^\/|\/$/g, '')) // remove first and last slash) paths = paths.filter((value) => value !== '').map((path) => path.replace(/^\/|\/$/g, '')) // remove first and last slash)
if (paths.length === 1) return paths[0] if (paths.length === 1) return paths[0]

@ -1,4 +1,4 @@
import React from 'react' import React, { useState } from 'react'
import { OverlayTrigger, Popover } from 'react-bootstrap' import { OverlayTrigger, Popover } from 'react-bootstrap'
import { TooltipPopupProps } from '../types' import { TooltipPopupProps } from '../types'
import './tooltip-popup.module.css' import './tooltip-popup.module.css'
@ -13,8 +13,12 @@ const popover = (title?: string, content?: string | React.ReactNode) => (
) )
export function TooltipPopup(props: TooltipPopupProps) { export function TooltipPopup(props: TooltipPopupProps) {
const [show, setShow] = useState<boolean>(false)
return ( return (
<OverlayTrigger trigger="click" placement={"bottom"} overlay={popover(props.title, props.children || props.content)}> <OverlayTrigger trigger="click" placement={"bottom"} overlay={popover(props.title, props.children || props.content)} show={show} onToggle={(nextShow) => {
setShow(nextShow)
}}>
<i className={`${props.icon} remixui_menuicon pr-0 mr-2`}></i> <i className={`${props.icon} remixui_menuicon pr-0 mr-2`}></i>
</OverlayTrigger> </OverlayTrigger>
) )

@ -1,8 +1,8 @@
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, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload' import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload'
import { checkSlash, checkSpecialChars } from '@remix-ui/helper' import { checkSlash, checkSpecialChars, createNonClashingTitle } from '@remix-ui/helper'
import { JSONStandardInput, WorkspaceTemplate } from '../types' import { JSONStandardInput, WorkspaceTemplate } from '../types'
import { QueryParams } from '@remix-project/remix-lib' import { QueryParams } from '@remix-project/remix-lib'
@ -326,6 +326,14 @@ export const cloneRepository = async (url: string) => {
const config = plugin.registry.get('config').api const config = plugin.registry.get('config').api
const token = config.get('currentFile') const token = config.get('currentFile')
const repoConfig = { url, token } const repoConfig = { url, token }
const urlArray = url.split('/')
let repoName = urlArray[urlArray.length - 1]
plugin.call('dGitProvider', 'clone', repoConfig) try {
repoName = await createNonClashingTitle(repoName, plugin.fileManager)
await plugin.call('dGitProvider', 'clone', repoConfig, repoName)
await plugin.call('manager', 'activatePlugin', 'dgit')
} catch (e) {
dispatch(displayPopUp('An error occured: ' + e))
}
} }

@ -131,7 +131,7 @@ export function Workspace () {
const url = cloneUrlRef.current.value const url = cloneUrlRef.current.value
if (url) { if (url) {
global.dispatchCloneRepository() global.dispatchCloneRepository(url)
} else { } else {
console.log('Please provide a valid github repository url.') console.log('Please provide a valid github repository url.')
} }

Loading…
Cancel
Save