List branches

pull/5370/head
David Disu 3 years ago
parent 64434abc0d
commit 569b189f0a
  1. 1
      apps/remix-ide/src/app/files/dgitProvider.js
  2. 1
      libs/remix-ui/workspace/src/lib/actions/index.ts
  3. 37
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  4. 1
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  5. 39
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -147,7 +147,6 @@ class DGitProvider extends Plugin {
}
async currentbranch (config) {
console.log('config: ', config)
const cmd = config ? config : await this.getGitConfig()
const name = await git.currentBranch(cmd)

@ -53,6 +53,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
const params = queryParams.get() as UrlParametersType
const workspaces = await getWorkspaces() || []
dispatch(setWorkspaces(workspaces))
// console.log('workspaces: ', workspaces)
if (params.gist) {
await createWorkspaceTemplate('gist-sample', 'gist-template')
plugin.setWorkspace({ name: 'gist-sample', isLocalhost: false })

@ -54,25 +54,6 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName)
dispatch(createWorkspaceRequest(promise))
promise.then(async () => {
if (isGitRepo) {
let branches = []
let currentBranch = null
try {
branches = await getGitRepoBranches(`${plugin.fileProviders.workspace.workspacesPath}/${workspaceName}`)
} catch (e) {
console.error(e)
}
try {
currentBranch = await getGitRepoCurrentBranch(`${plugin.fileProviders.workspace.workspacesPath}/${workspaceName}`)
} catch (e) {
console.error(e)
}
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo, branches, currentBranch }))
} else {
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo }))
}
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo }))
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
await plugin.setWorkspaces(await getWorkspaces())
@ -338,9 +319,9 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error,
})
}
export const getWorkspaces = async (): Promise<{name: string, isGitRepo: boolean}[]> | undefined => {
export const getWorkspaces = async (): Promise<{name: string, isGitRepo: boolean, branches?: { remote: any; name: string; }[], currentBranch?: string }[]> | undefined => {
try {
const workspaces: {name: string, isGitRepo: boolean}[] = await new Promise((resolve, reject) => {
const workspaces: {name: string, isGitRepo: boolean, branches?: { remote: any; name: string; }[], currentBranch?: string}[] = await new Promise((resolve, reject) => {
const workspacesPath = plugin.fileProviders.workspace.workspacesPath
plugin.fileProviders.browser.resolveDirectory('/' + workspacesPath, (error, items) => {
@ -350,25 +331,15 @@ export const getWorkspaces = async (): Promise<{name: string, isGitRepo: boolean
Promise.all(Object.keys(items)
.filter((item) => items[item].isDirectory)
.map(async (folder) => {
console.log('folder: ', folder)
const isGitRepo: boolean = await plugin.fileProviders.browser.exists('/' + folder + '/.git')
if (isGitRepo) {
let branches = []
let currentBranch = null
try {
branches = await getGitRepoBranches(folder)
} catch (e) {
console.error(e)
}
try {
currentBranch = await getGitRepoCurrentBranch(folder)
} catch (e) {
console.error(e)
}
branches = await getGitRepoBranches(folder)
console.log('branches: ', branches)
currentBranch = await getGitRepoCurrentBranch(folder)
return {
name: folder.replace(workspacesPath + '/', ''),

@ -136,6 +136,7 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
case 'SET_WORKSPACES': {
console.log('called SET_WORKSPACES')
const payload = action.payload as { name: string; isGitRepo: boolean; branches?: { remote: any; name: string; }[], currentBranch?: string }[]
return {

@ -13,7 +13,7 @@ export function Workspace () {
const LOCALHOST = ' - connect to localhost - '
const NO_WORKSPACE = ' - none - '
const [currentWorkspace, setCurrentWorkspace] = useState<string>(NO_WORKSPACE)
const [selectedWorkspace, setSelectedWorkspace] = useState<{ name: string, isGitRepo: boolean}>(null)
const [selectedWorkspace, setSelectedWorkspace] = useState<{ name: string, isGitRepo: boolean, branches?: { remote: any; name: string; }[], currentBranch?: string }>(null)
const [showDropdown, setShowDropdown] = useState<boolean>(false)
const [showIconsMenu, hideIconsMenu] = useState<boolean>(false)
const displayOzCustomRef = useRef<HTMLDivElement>()
@ -679,22 +679,31 @@ export function Workspace () {
</div>
</div>
</div>
<div className={`bg-light border-top ${selectedWorkspace && selectedWorkspace.isGitRepo ? 'd-block' : 'd-none'}`} style={{ height: '5%' }}>
<div className='d-flex justify-space-between p-1'>
<div className="mr-auto text-uppercase text-dark pt-2 pl-2">DGIT</div>
<div className="pt-1 mr-1">
<Dropdown style={{ height: 30, minWidth: 80 }}>
<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}>
Main
</Dropdown.Toggle>
<Dropdown.Menu as={CustomMenu} className='custom-dropdown-items' data-id="custom-dropdown-items">
<Dropdown.Item><span className="pl-3">setup</span></Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
{
selectedWorkspace &&
<div className='bg-light border-top' style={{ height: '5%' }}>
<div className='d-flex justify-space-between p-1'>
<div className="mr-auto text-uppercase text-dark pt-2 pl-2">DGIT</div>
<div className="pt-1 mr-1">
<Dropdown style={{ height: 30, minWidth: 80 }}>
<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}>
{ selectedWorkspace.currentBranch || '-none-'}
</Dropdown.Toggle>
<Dropdown.Menu as={CustomMenu} className='custom-dropdown-items' data-id="custom-dropdown-items">
{
(selectedWorkspace.branches || []).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.Menu>
</Dropdown>
</div>
</div>
</div>
</div>
}
</>
)
}

Loading…
Cancel
Save