Fix clone bug

pull/2879/head
David Disu 2 years ago
parent 6a370e714a
commit 8a803824da
  1. 14
      libs/remix-ui/workspace/src/lib/actions/payload.ts
  2. 21
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  3. 30
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  4. 12
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -264,3 +264,17 @@ export const cloneRepositoryFailed = () => {
type: 'CLONE_REPOSITORY_FAILED' type: 'CLONE_REPOSITORY_FAILED'
} }
} }
export const setCurrentWorkspaceBranches = (branches?: { remote: any, name: string }[]) => {
return {
type: 'SET_CURRENT_WORKSPACE_BRANCHES',
payload: branches
}
}
export const setCurrentWorkspaceCurrentBranch = (currentBranch?: string) => {
return {
type: 'SET_CURRENT_WORKSPACE_CURRENT_BRANCH',
payload: currentBranch
}
}

@ -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, cloneRepositoryFailed, cloneRepositoryRequest, cloneRepositorySuccess, 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, setCurrentWorkspaceBranches, setCurrentWorkspaceCurrentBranch, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload'
import { addSlash, checkSlash, checkSpecialChars } from '@remix-ui/helper' import { addSlash, checkSlash, checkSpecialChars } from '@remix-ui/helper'
import { JSONStandardInput, WorkspaceTemplate } from '../types' import { JSONStandardInput, WorkspaceTemplate } from '../types'
@ -339,7 +339,6 @@ export const getWorkspaces = async (): Promise<{name: string, isGitRepo: boolean
branches = await getGitRepoBranches(folder) branches = await getGitRepoBranches(folder)
currentBranch = await getGitRepoCurrentBranch(folder) currentBranch = await getGitRepoCurrentBranch(folder)
return { return {
name: folder.replace(workspacesPath + '/', ''), name: folder.replace(workspacesPath + '/', ''),
isGitRepo, isGitRepo,
@ -377,6 +376,13 @@ export const cloneRepository = async (url: string) => {
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit') if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit')
await fetchWorkspaceDirectory(ROOT_PATH) await fetchWorkspaceDirectory(ROOT_PATH)
const workspacesPath = plugin.fileProviders.workspace.workspacesPath
const branches = await getGitRepoBranches(workspacesPath + '/' + repoName)
dispatch(setCurrentWorkspaceBranches(branches))
const currentBranch = await getGitRepoCurrentBranch(workspacesPath + '/' + repoName)
dispatch(setCurrentWorkspaceCurrentBranch(currentBranch))
dispatch(cloneRepositorySuccess()) dispatch(cloneRepositorySuccess())
}).catch(() => { }).catch(() => {
const cloneModal = { const cloneModal = {
@ -456,8 +462,9 @@ export const switchToBranch = async (branch: string) => {
dispatch(cloneRepositoryRequest()) dispatch(cloneRepositoryRequest())
promise.then(async () => { promise.then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH) await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch))
dispatch(cloneRepositorySuccess()) dispatch(cloneRepositorySuccess())
}).catch((e) => { }).catch(() => {
dispatch(cloneRepositoryFailed()) dispatch(cloneRepositoryFailed())
}) })
return promise return promise
@ -471,8 +478,14 @@ export const switchToNewBranch = async (branch: string) => {
dispatch(cloneRepositoryRequest()) dispatch(cloneRepositoryRequest())
promise.then(async () => { promise.then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(setCurrentWorkspaceCurrentBranch(branch))
const workspacesPath = plugin.fileProviders.workspace.workspacesPath
const branches = await getGitRepoBranches(workspacesPath + '/' + branch)
dispatch(setCurrentWorkspaceBranches(branches))
dispatch(cloneRepositorySuccess()) dispatch(cloneRepositorySuccess())
}).catch((e) => { }).catch(() => {
dispatch(cloneRepositoryFailed()) dispatch(cloneRepositoryFailed())
}) })
return promise return promise

@ -674,6 +674,36 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
} }
} }
case 'SET_CURRENT_WORKSPACE_BRANCHES': {
const payload: { remote: any, name: string }[] = action.payload
return {
...state,
browser: {
...state.browser,
workspaces: state.browser.workspaces.map((workspace) => {
if (workspace.name === state.browser.currentWorkspace) workspace.branches = payload
return workspace
})
}
}
}
case 'SET_CURRENT_WORKSPACE_CURRENT_BRANCH': {
const payload: string = action.payload
return {
...state,
browser: {
...state.browser,
workspaces: state.browser.workspaces.map((workspace) => {
if (workspace.name === state.browser.currentWorkspace) workspace.currentBranch = payload
return workspace
})
}
}
}
default: default:
throw new Error() throw new Error()
} }

@ -18,7 +18,6 @@ export function Workspace () {
const [showIconsMenu, hideIconsMenu] = useState<boolean>(false) const [showIconsMenu, hideIconsMenu] = useState<boolean>(false)
const [showBranches, setShowBranches] = useState<boolean>(false) const [showBranches, setShowBranches] = useState<boolean>(false)
const [branchFilter, setBranchFilter] = useState<string>('') const [branchFilter, setBranchFilter] = useState<string>('')
const [selectedBranch, setSelectedBranch] = useState<string>('')
const displayOzCustomRef = useRef<HTMLDivElement>() const displayOzCustomRef = useRef<HTMLDivElement>()
const mintableCheckboxRef = useRef() const mintableCheckboxRef = useRef()
const burnableCheckboxRef = useRef() const burnableCheckboxRef = useRef()
@ -32,6 +31,7 @@ export function Workspace () {
const cloneUrlRef = useRef<HTMLInputElement>() const cloneUrlRef = useRef<HTMLInputElement>()
const initGitRepoRef = useRef<HTMLInputElement>() const initGitRepoRef = useRef<HTMLInputElement>()
const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.remote).slice(0, 20) : [] const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.remote).slice(0, 20) : []
const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null
useEffect(() => { useEffect(() => {
let workspaceName = localStorage.getItem('currentWorkspace') let workspaceName = localStorage.getItem('currentWorkspace')
@ -67,7 +67,7 @@ export function Workspace () {
const workspace = global.fs.browser.workspaces.find(workspace => workspace.name === currentWorkspace) const workspace = global.fs.browser.workspaces.find(workspace => workspace.name === currentWorkspace)
setSelectedWorkspace(workspace) setSelectedWorkspace(workspace)
workspace && setSelectedBranch(workspace.currentBranch) // workspace && setSelectedBranch(workspace.currentBranch)
}, [currentWorkspace]) }, [currentWorkspace])
const renameCurrentWorkspace = () => { const renameCurrentWorkspace = () => {
@ -221,7 +221,6 @@ export function Workspace () {
const switchToBranch = async (branch: string) => { const switchToBranch = async (branch: string) => {
try { try {
await global.dispatchSwitchToBranch(branch) await global.dispatchSwitchToBranch(branch)
setSelectedBranch(branch)
} catch (e) { } catch (e) {
global.modal('Checkout Git Branch', e.message, 'OK', () => {}) global.modal('Checkout Git Branch', e.message, 'OK', () => {})
} }
@ -230,7 +229,6 @@ export function Workspace () {
const switchToNewBranch = async () => { const switchToNewBranch = async () => {
try { try {
await global.dispatchSwitchToNewBranch(branchFilter) await global.dispatchSwitchToNewBranch(branchFilter)
setSelectedBranch(branchFilter)
} catch (e) { } catch (e) {
global.modal('Checkout Git Branch', e.message, 'OK', () => {}) global.modal('Checkout Git Branch', e.message, 'OK', () => {})
} }
@ -725,7 +723,7 @@ export function Workspace () {
<div className="pt-1 mr-1"> <div className="pt-1 mr-1">
<Dropdown style={{ height: 30, minWidth: 80 }} onToggle={toggleBranches} show={showBranches} drop={'up'}> <Dropdown style={{ height: 30, minWidth: 80 }} onToggle={toggleBranches} show={showBranches} drop={'up'}>
<Dropdown.Toggle as={CustomToggle} id="dropdown-custom-components" className="btn btn-light btn-block w-100 d-inline-block border border-dark form-control h-100 p-0 pl-2 pr-2 text-dark" icon={null}> <Dropdown.Toggle as={CustomToggle} id="dropdown-custom-components" className="btn btn-light btn-block w-100 d-inline-block border border-dark form-control h-100 p-0 pl-2 pr-2 text-dark" icon={null}>
{ global.fs.browser.isRequestingCloning ? <i className="fad fa-spinner fa-spin"></i> : selectedBranch || '-none-' } { global.fs.browser.isRequestingCloning ? <i className="fad fa-spinner fa-spin"></i> : currentBranch || '-none-' }
</Dropdown.Toggle> </Dropdown.Toggle>
<Dropdown.Menu as={CustomMenu} className='custom-dropdown-items branches-dropdown' data-id="custom-dropdown-items"> <Dropdown.Menu as={CustomMenu} className='custom-dropdown-items branches-dropdown' data-id="custom-dropdown-items">
@ -748,7 +746,7 @@ export function Workspace () {
return ( return (
<Dropdown.Item key={index} onClick={() => { switchToBranch(branch.name) }}> <Dropdown.Item key={index} onClick={() => { switchToBranch(branch.name) }}>
{ {
selectedBranch === branch.name ? currentBranch === branch.name ?
<span>&#10003; { branch.name } </span> : <span>&#10003; { branch.name } </span> :
<span className="pl-3">{ branch.name }</span> <span className="pl-3">{ branch.name }</span>
} }
@ -757,7 +755,7 @@ export function Workspace () {
}) : }) :
<Dropdown.Item onClick={switchToNewBranch}> <Dropdown.Item onClick={switchToNewBranch}>
<div className="pl-1 pr-1"> <div className="pl-1 pr-1">
<i className="fas fa-code-branch pr-2"></i><span>Create branch: { branchFilter } from '{selectedBranch}'</span> <i className="fas fa-code-branch pr-2"></i><span>Create branch: { branchFilter } from '{currentBranch}'</span>
</div> </div>
</Dropdown.Item> </Dropdown.Item>
} }

Loading…
Cancel
Save