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. 10
      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 { 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 { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntrackedDecorator, statusChanged } from '../lib/pluginActions'
import { gitActionsContext, pluginActionsContext } from '../state/context'
@ -110,7 +110,8 @@ export const GitUI = (props: IGitUi) => {
getRemotes,
fetch,
pull,
push
push,
setDefaultRemote
}
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 React, { useContext, useEffect } from "react";
import { gitActionsContext } from "../../state/context";
import { branch, remote } from "../../types";
import { gitPluginContext } from "../gitui";
@ -14,6 +15,8 @@ interface RemotesDetailsNavigationProps {
export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) => {
const { eventKey, activePanel, callback, remote } = props;
const context = React.useContext(gitPluginContext)
const actions = React.useContext(gitActionsContext)
const handleClick = () => {
if (!callback) return
if (activePanel === eventKey) {
@ -27,6 +30,10 @@ export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) =
window.open(`${remote.url}`, '_blank');
}
const setAsDefault = () => {
actions.setDefaultRemote(remote)
}
return (
<>
<div className="d-flex flex-row w-100 mb-2 mt-2">
@ -39,6 +46,11 @@ export const RemotesDetailsNavigation = (props: RemotesDetailsNavigationProps) =
</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>}
</div>
</>

@ -1,8 +1,8 @@
import { ViewPlugin } from "@remixproject/engine-web";
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
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 { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference } from '../types';
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, remote } from '../types';
import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners";
import { AlertModal, ModalTypes } from "@remix-ui/app";
@ -797,3 +797,7 @@ export const getBranchCommits = async (branch: branch, page: number) => {
await fetchBranch(branch, page)
}
}
export const setDefaultRemote = async (remote: remote) => {
dispatch(setRemoteAsDefault(remote))
}

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

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

@ -1,6 +1,6 @@
import { ReadCommitResult } from "isomorphic-git"
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 {
type: string
@ -139,7 +139,7 @@ export const gitReducer = (state: gitState = defaultGitState, action: Action): g
}
case 'SET_BRANCH_DIFFERENCES':
state.branchDifferences[`${(action as setBranchDifferencesAction).payload.remote.remote}/${(action as setBranchDifferencesAction).payload.branch.name}`] = (action as setBranchDifferencesAction).payload.branchDifference
@ -168,5 +168,11 @@ export const gitReducer = (state: gitState = defaultGitState, action: Action): g
...state,
gitHubAccessToken: action.payload
}
case 'SET_DEFAULT_REMOTE':
return {
...state,
defaultRemote: (action as setDefaultRemoteAction).payload
}
}
}

@ -12,6 +12,7 @@ export type gitState = {
canCommit: boolean
branches: branch[]
remotes: remote[]
defaultRemote: remote
fileStatusResult: fileStatusResult[]
canUseApp: boolean
loading: boolean
@ -117,6 +118,7 @@ export const defaultGitState: gitState = {
canCommit: true,
branches: [],
remotes: [],
defaultRemote: null,
fileStatusResult: [],
staged: [],
untracked: [],
@ -255,4 +257,9 @@ export interface setTokenAction {
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