setdefaultremote

git4refactor
filip mertens 7 months ago
parent ede22d886a
commit b3252a04a6
  1. 5
      libs/remix-ui/git/src/components/gitui.tsx
  2. 14
      libs/remix-ui/git/src/components/navigation/remotesdetails.tsx
  3. 8
      libs/remix-ui/git/src/lib/gitactions.ts
  4. 3
      libs/remix-ui/git/src/state/context.tsx
  5. 7
      libs/remix-ui/git/src/state/gitpayload.ts
  6. 8
      libs/remix-ui/git/src/state/gitreducer.tsx
  7. 9
      libs/remix-ui/git/src/types/index.ts

@ -1,5 +1,5 @@
import React, { useEffect, useReducer, useState } from 'react' import React, { useEffect, useReducer, useState } from 'react'
import { add, addall, checkout, checkoutfile, clone, commit, createBranch, remoteBranches, repositories, rm, getCommitChanges, diff, resolveRef, getBranchCommits, setUpstreamRemote, getGitHubUser, getBranches, getRemotes, remoteCommits, saveGitHubCredentials, getGitHubCredentials, fetch, pull, push } from '../lib/gitactions' import { add, addall, checkout, checkoutfile, clone, commit, createBranch, remoteBranches, repositories, rm, getCommitChanges, diff, resolveRef, getBranchCommits, setUpstreamRemote, getGitHubUser, getBranches, getRemotes, remoteCommits, saveGitHubCredentials, getGitHubCredentials, fetch, pull, push, setDefaultRemote } from '../lib/gitactions'
import { loadFiles, setCallBacks } from '../lib/listeners' import { loadFiles, setCallBacks } from '../lib/listeners'
import { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntrackedDecorator, statusChanged } from '../lib/pluginActions' import { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntrackedDecorator, statusChanged } from '../lib/pluginActions'
import { gitActionsContext, pluginActionsContext } from '../state/context' import { gitActionsContext, pluginActionsContext } from '../state/context'
@ -110,7 +110,8 @@ export const GitUI = (props: IGitUi) => {
getRemotes, getRemotes,
fetch, fetch,
pull, pull,
push push,
setDefaultRemote
} }
const pluginActionsProviderValue = { const pluginActionsProviderValue = {

@ -1,6 +1,7 @@
import { faCaretDown, faCaretRight, faArrowRightArrowLeft, faGlobe } from "@fortawesome/free-solid-svg-icons"; import { faCaretDown, faCaretRight, faArrowRightArrowLeft, faGlobe, faToggleOff, faToggleOn } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React, { useContext, useEffect } from "react"; import React, { useContext, useEffect } from "react";
import { gitActionsContext } from "../../state/context";
import { branch, remote } from "../../types"; import { branch, remote } from "../../types";
import { gitPluginContext } from "../gitui"; import { gitPluginContext } from "../gitui";
@ -14,6 +15,8 @@ interface RemotesDetailsNavigationProps {
export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) => { export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) => {
const { eventKey, activePanel, callback, remote } = props; const { eventKey, activePanel, callback, remote } = props;
const context = React.useContext(gitPluginContext) const context = React.useContext(gitPluginContext)
const actions = React.useContext(gitActionsContext)
const handleClick = () => { const handleClick = () => {
if (!callback) return if (!callback) return
if (activePanel === eventKey) { if (activePanel === eventKey) {
@ -27,6 +30,10 @@ export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) =
window.open(`${remote.url}`, '_blank'); window.open(`${remote.url}`, '_blank');
} }
const setAsDefault = () => {
actions.setDefaultRemote(remote)
}
return ( return (
<> <>
<div className="d-flex flex-row w-100 mb-2 mt-2"> <div className="d-flex flex-row w-100 mb-2 mt-2">
@ -39,6 +46,11 @@ export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) =
</div> </div>
</div> </div>
{context.defaultRemote && context.defaultRemote?.url === remote.url ?
<FontAwesomeIcon className='ml-auto mr-1 pointer text-success' icon={faToggleOff} ></FontAwesomeIcon>
:
<FontAwesomeIcon className='ml-auto mr-1 pointer' icon={faToggleOn} onClick={setAsDefault} ></FontAwesomeIcon>
}
{remote?.url && <FontAwesomeIcon className='ml-2 pointer' icon={faGlobe} onClick={() => openRemote()}></FontAwesomeIcon>} {remote?.url && <FontAwesomeIcon className='ml-2 pointer' icon={faGlobe} onClick={() => openRemote()}></FontAwesomeIcon>}
</div> </div>
</> </>

@ -1,8 +1,8 @@
import { ViewPlugin } from "@remixproject/engine-web"; import { ViewPlugin } from "@remixproject/engine-web";
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git"; import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
import React from "react"; import React from "react";
import { fileStatus, fileStatusMerge, setRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences } from "../state/gitpayload"; import { fileStatus, fileStatusMerge, setRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault } from "../state/gitpayload";
import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference } from '../types'; import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote } from '../types';
import { removeSlash } from "../utils"; import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners"; import { disableCallBacks, enableCallBacks } from "./listeners";
import { AlertModal, ModalTypes } from "@remix-ui/app"; import { AlertModal, ModalTypes } from "@remix-ui/app";
@ -797,3 +797,7 @@ export const getBranchCommits = async (branch: branch, page: number) => {
await fetchBranch(branch, page) await fetchBranch(branch, page)
} }
} }
export const setDefaultRemote = async (remote: remote) => {
dispatch(setRemoteAsDefault(remote))
}

@ -1,6 +1,6 @@
import { ReadCommitResult } from "isomorphic-git" import { ReadCommitResult } from "isomorphic-git"
import React from "react" import React from "react"
import { branch, commitChange } from "../types" import { branch, commitChange, remote } from "../types"
export interface gitActions { export interface gitActions {
clone(url: string, path: string, depth: number, singleBranch: boolean): Promise<void> clone(url: string, path: string, depth: number, singleBranch: boolean): Promise<void>
@ -24,6 +24,7 @@ export interface gitActions {
setUpstreamRemote(upstream: string): Promise<void> setUpstreamRemote(upstream: string): Promise<void>
getBranches: () => Promise<void> getBranches: () => Promise<void>
getRemotes: () => Promise<void> getRemotes: () => Promise<void>
setDefaultRemote: (remote: remote) => Promise<void>
} }
export const gitActionsContext = React.createContext<gitActions>(null) export const gitActionsContext = React.createContext<gitActions>(null)

@ -172,3 +172,10 @@ export const setGItHubToken = (token: string) => {
payload: token payload: token
} }
} }
export const setRemoteAsDefault = (remote: remote) => {
return {
type: 'SET_DEFAULT_REMOTE',
payload: remote
}
}

@ -1,6 +1,6 @@
import { ReadCommitResult } from "isomorphic-git" import { ReadCommitResult } from "isomorphic-git"
import { allChangedButNotStagedFiles, getFilesByStatus, getFilesWithNotModifiedStatus } from "../lib/fileHelpers" import { allChangedButNotStagedFiles, getFilesByStatus, getFilesWithNotModifiedStatus } from "../lib/fileHelpers"
import { branch, commitChange, defaultGitState, fileStatusResult, gitState, setRemoteBranchCommitsAction, setLocalBranchCommitsAction, setBranchDifferencesAction } from "../types" import { branch, commitChange, defaultGitState, fileStatusResult, gitState, setRemoteBranchCommitsAction, setLocalBranchCommitsAction, setBranchDifferencesAction, setDefaultRemoteAction } from "../types"
interface Action { interface Action {
type: string type: string
@ -168,5 +168,11 @@ export const gitReducer = (state: gitState = defaultGitState, action: Action): g
...state, ...state,
gitHubAccessToken: action.payload gitHubAccessToken: action.payload
} }
case 'SET_DEFAULT_REMOTE':
return {
...state,
defaultRemote: (action as setDefaultRemoteAction).payload
}
} }
} }

@ -12,6 +12,7 @@ export type gitState = {
canCommit: boolean canCommit: boolean
branches: branch[] branches: branch[]
remotes: remote[] remotes: remote[]
defaultRemote: remote
fileStatusResult: fileStatusResult[] fileStatusResult: fileStatusResult[]
canUseApp: boolean canUseApp: boolean
loading: boolean loading: boolean
@ -117,6 +118,7 @@ export const defaultGitState: gitState = {
canCommit: true, canCommit: true,
branches: [], branches: [],
remotes: [], remotes: [],
defaultRemote: null,
fileStatusResult: [], fileStatusResult: [],
staged: [], staged: [],
untracked: [], untracked: [],
@ -255,4 +257,9 @@ export interface setTokenAction {
payload: string payload: string
} }
export type gitActionDispatch = setTokenAction | setUpstreamAction | setRemoteBranchCommitsAction | setLocalBranchCommitsAction | setBranchDifferencesAction | setRemotesAction | setCurrentBranchAction | fileStatusAction | setLoadingAction | setCanUseAppAction | setRepoNameAction | setCommitsAction | setBranchesAction | setReposAction | setRemoteBranchesAction export interface setDefaultRemoteAction {
type: string,
payload: remote
}
export type gitActionDispatch = setDefaultRemoteAction | setTokenAction | setUpstreamAction | setRemoteBranchCommitsAction | setLocalBranchCommitsAction | setBranchDifferencesAction | setRemotesAction | setCurrentBranchAction | fileStatusAction | setLoadingAction | setCanUseAppAction | setRepoNameAction | setCommitsAction | setBranchesAction | setReposAction | setRemoteBranchesAction
Loading…
Cancel
Save