Basic checkout implementation

pull/2879/head
David Disu 2 years ago
parent 57ae13a5bb
commit 018a324daf
  1. 37
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  2. 3
      libs/remix-ui/workspace/src/lib/contexts/index.ts
  3. 10
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
  4. 12
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -439,3 +439,40 @@ export const getGitRepoCurrentBranch = async (workspaceName: string) => {
return currentBranch return currentBranch
} }
export const showAllBranches = async () => {
const isActive = await plugin.call('manager', 'isActive', 'dgit')
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit')
plugin.call('menuicons', 'select', 'dgit')
}
export const switchToBranch = async (branch: string) => {
const gitConfig = {
ref: branch
}
const promise = plugin.call('dGitProvider', 'checkout', gitConfig)
dispatch(cloneRepositoryRequest())
promise.then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH)
dispatch(cloneRepositorySuccess())
}).catch((e) => {
const checkoutModal = {
id: 'checkoutGitBranch',
title: 'Checkout Git Branch',
message: 'An error occurred: ' + e,
modalType: 'modal',
okLabel: 'OK',
okFn: async () => {
// await deleteWorkspace(repoName)
dispatch(cloneRepositoryFailed())
},
hideFn: async () => {
// await deleteWorkspace(repoName)
dispatch(cloneRepositoryFailed())
}
}
plugin.call('notification', 'modal', checkoutModal)
})
}

@ -33,6 +33,7 @@ export const FileSystemContext = createContext<{
dispatchCloneRepository: (url: string) => Promise<void>, dispatchCloneRepository: (url: string) => Promise<void>,
dispatchMoveFile: (src: string, dest: string) => Promise<void>, dispatchMoveFile: (src: string, dest: string) => Promise<void>,
dispatchMoveFolder: (src: string, dest: string) => Promise<void>, dispatchMoveFolder: (src: string, dest: string) => Promise<void>,
dispatchShowAllBranches: () => Promise<void> dispatchShowAllBranches: () => Promise<void>,
dispatchSwitchToBranch: (branch: string) => Promise<void>
}>(null) }>(null)

@ -8,7 +8,8 @@ import { browserReducer, browserInitialState } from '../reducers/workspace'
import { initWorkspace, fetchDirectory, removeInputField, deleteWorkspace, clearPopUp, publishToGist, createNewFile, setFocusElement, createNewFolder, import { initWorkspace, fetchDirectory, removeInputField, deleteWorkspace, clearPopUp, publishToGist, createNewFile, setFocusElement, createNewFolder,
deletePath, renamePath, copyFile, copyFolder, runScript, emitContextMenuEvent, handleClickFile, handleExpandPath, addInputField, createWorkspace, deletePath, renamePath, copyFile, copyFolder, runScript, emitContextMenuEvent, handleClickFile, handleExpandPath, addInputField, createWorkspace,
fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder, fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder,
showAllBranches showAllBranches,
switchToBranch
} from '../actions' } from '../actions'
import { Modal, WorkspaceProps, WorkspaceTemplate } from '../types' import { Modal, WorkspaceProps, WorkspaceTemplate } from '../types'
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -143,6 +144,10 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await showAllBranches() await showAllBranches()
} }
const dispatchSwitchToBranch = async (branch: string) => {
await switchToBranch(branch)
}
useEffect(() => { useEffect(() => {
dispatchInitWorkspace() dispatchInitWorkspace()
}, []) }, [])
@ -248,7 +253,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
dispatchCloneRepository, dispatchCloneRepository,
dispatchMoveFile, dispatchMoveFile,
dispatchMoveFolder, dispatchMoveFolder,
dispatchShowAllBranches dispatchShowAllBranches,
dispatchSwitchToBranch
} }
return ( return (
<FileSystemContext.Provider value={value}> <FileSystemContext.Provider value={value}>

@ -213,6 +213,10 @@ export function Workspace () {
global.dispatchShowAllBranches() global.dispatchShowAllBranches()
} }
const switchToBranch = (branch: string) => {
global.dispatchSwitchToBranch(branch)
}
const createModalMessage = () => { const createModalMessage = () => {
return ( return (
<> <>
@ -717,7 +721,13 @@ export function Workspace () {
{ {
(selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.remote).slice(0, 4).map((branch, index) => { (selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.remote).slice(0, 4).map((branch, index) => {
return ( return (
<Dropdown.Item key={index}><span>{ selectedWorkspace.currentBranch === branch.name ? <span>&#10003; { branch.name } </span> : <span className="pl-3">{ branch.name }</span> }</span></Dropdown.Item> <Dropdown.Item key={index}>
{
selectedWorkspace.currentBranch === branch.name ?
<span onClick={() => { switchToBranch(branch.name) }}>&#10003; { branch.name } </span> :
<span className="pl-3" onClick={() => { switchToBranch(branch.name) }}>{ branch.name }</span>
}
</Dropdown.Item>
) )
}) })
} }

Loading…
Cancel
Save