From 13ef650a917d503ee807c710bd30d1851d0605c0 Mon Sep 17 00:00:00 2001 From: David Disu Date: Tue, 6 Sep 2022 12:15:10 +0100 Subject: [PATCH] Filter branches list and view all branches on dgit --- apps/remix-ide/src/app/files/dgitProvider.js | 6 +-- .../workspace/src/lib/actions/index.ts | 8 ++++ .../workspace/src/lib/actions/workspace.ts | 1 - .../workspace/src/lib/contexts/index.ts | 3 +- .../src/lib/css/remix-ui-workspace.css | 5 +++ .../src/lib/providers/FileSystemProvider.tsx | 11 ++++- .../workspace/src/lib/remix-ui-workspace.tsx | 43 +++++++++++++++---- 7 files changed, 62 insertions(+), 15 deletions(-) diff --git a/apps/remix-ide/src/app/files/dgitProvider.js b/apps/remix-ide/src/app/files/dgitProvider.js index 6f8abe3025..beb8b80c43 100644 --- a/apps/remix-ide/src/app/files/dgitProvider.js +++ b/apps/remix-ide/src/app/files/dgitProvider.js @@ -125,10 +125,10 @@ class DGitProvider extends Plugin { return status } - async remotes () { + async remotes (config) { let remotes = [] try { - remotes = await git.listRemotes({ ...await this.getGitConfig() }) + remotes = await git.listRemotes({ ...config ? config : await this.getGitConfig() }) } catch (e) { // do nothing } @@ -155,7 +155,7 @@ class DGitProvider extends Plugin { async branches (config) { const cmd = config ? config : await this.getGitConfig() - const remotes = await this.remotes() + const remotes = await this.remotes(config) let branches = [] branches = (await git.listBranches(cmd)).map((branch) => { return { remote: undefined, name: branch } }) for (const remote of remotes) { diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 8c48726c98..66d7ec7bc7 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -488,3 +488,11 @@ export const moveFolder = async (src: string, dest: string) => { dispatch(displayPopUp('Oops! An error ocurred while performing moveDir operation.' + error)) } } + + +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') +} \ No newline at end of file diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 9d7a1c5b1e..8800314dc5 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -338,7 +338,6 @@ export const getWorkspaces = async (): Promise<{name: string, isGitRepo: boolean let currentBranch = null branches = await getGitRepoBranches(folder) - console.log('branches: ', branches) currentBranch = await getGitRepoCurrentBranch(folder) return { diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index 2fd6a71b46..5f4cdaee33 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -32,6 +32,7 @@ export const FileSystemContext = createContext<{ dispatchHandleRestoreBackup: () => Promise dispatchCloneRepository: (url: string) => Promise, dispatchMoveFile: (src: string, dest: string) => Promise, - dispatchMoveFolder: (src: string, dest: string) => Promise + dispatchMoveFolder: (src: string, dest: string) => Promise, + dispatchShowAllBranches: () => Promise }>(null) \ No newline at end of file diff --git a/libs/remix-ui/workspace/src/lib/css/remix-ui-workspace.css b/libs/remix-ui/workspace/src/lib/css/remix-ui-workspace.css index 55357dacae..13756a9b94 100644 --- a/libs/remix-ui/workspace/src/lib/css/remix-ui-workspace.css +++ b/libs/remix-ui/workspace/src/lib/css/remix-ui-workspace.css @@ -84,6 +84,7 @@ border-radius: .25rem; background: var(--custom-select); } + .custom-dropdown-items a { border-radius: .25rem; text-transform: none; @@ -133,3 +134,7 @@ color: var(--text) } + .checkout-input { + font-size: 10px !important; + } + diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index 2b1409fe86..ddc12cdfdf 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -7,7 +7,9 @@ import { FileSystemContext } from '../contexts' 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 } from '../actions' + fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder, + showAllBranches +} from '../actions' import { Modal, WorkspaceProps, WorkspaceTemplate } from '../types' // eslint-disable-next-line @typescript-eslint/no-unused-vars import { Workspace } from '../remix-ui-workspace' @@ -136,6 +138,10 @@ export const FileSystemProvider = (props: WorkspaceProps) => { const dispatchMoveFolder = async (src: string, dest: string) => { await moveFolder(src, dest) } + + const dispatchShowAllBranches = async () => { + await showAllBranches() + } useEffect(() => { dispatchInitWorkspace() @@ -241,7 +247,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => { dispatchHandleRestoreBackup, dispatchCloneRepository, dispatchMoveFile, - dispatchMoveFolder + dispatchMoveFolder, + dispatchShowAllBranches } return ( diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 061279be0e..d100f7ac0f 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -16,6 +16,8 @@ export function Workspace () { const [selectedWorkspace, setSelectedWorkspace] = useState<{ name: string, isGitRepo: boolean, branches?: { remote: any; name: string; }[], currentBranch?: string }>(null) const [showDropdown, setShowDropdown] = useState(false) const [showIconsMenu, hideIconsMenu] = useState(false) + const [showBranches, setShowBranches] = useState(false) + const [branchFilter, setBranchFilter] = useState('') const displayOzCustomRef = useRef() const mintableCheckboxRef = useRef() const burnableCheckboxRef = useRef() @@ -198,6 +200,18 @@ export function Workspace () { // @ts-ignore workspaceCreateInput.current.value = `${workspaceCreateTemplateInput.current.value + '_upgradeable'}_${Date.now()}` } + + const toggleBranches = (isOpen: boolean) => { + setShowBranches(isOpen) + } + + const handleBranchFilerChange = (branchFilter: string) => { + setBranchFilter(branchFilter) + } + + const showAllBranches = () => { + global.dispatchShowAllBranches() + } const createModalMessage = () => { return ( @@ -685,18 +699,31 @@ export function Workspace () {
DGIT
- + - { selectedWorkspace.currentBranch || '-none-'} + { selectedWorkspace.currentBranch || '-none-' } - + +
+ Switch branches +
{ toggleBranches(false) }}> +
+
+
+ { handleBranchFilerChange(e.target.value) }} /> +
+
+ { + (selectedWorkspace.branches || []).filter(branch => branch.name.includes(branchFilter) && branch.remote).slice(0, 4).map((branch, index) => { + return ( + { selectedWorkspace.currentBranch === branch.name ? ✓ { branch.name } : { branch.name } } + ) + }) + } +
{ - (selectedWorkspace.branches || []).map((branch, index) => { - return ( - { selectedWorkspace.currentBranch === branch.name ? ✓ { branch.name } : { branch.name } } - ) - }) + (selectedWorkspace.branches || []).length > 4 && }