Basic checkout implementation

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

@ -495,4 +495,4 @@ export const showAllBranches = async () => {
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit')
plugin.call('menuicons', 'select', 'dgit')
}
}

@ -439,3 +439,40 @@ export const getGitRepoCurrentBranch = async (workspaceName: string) => {
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>,
dispatchMoveFile: (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)

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

@ -213,6 +213,10 @@ export function Workspace () {
global.dispatchShowAllBranches()
}
const switchToBranch = (branch: string) => {
global.dispatchSwitchToBranch(branch)
}
const createModalMessage = () => {
return (
<>
@ -717,7 +721,13 @@ export function Workspace () {
{
(selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.remote).slice(0, 4).map((branch, index) => {
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