git4refactor
filip mertens 7 months ago
parent 9ade399399
commit 36ec094dd4
  1. 15
      libs/remix-ui/git/src/components/buttons/commitmessage.tsx
  2. 8
      libs/remix-ui/git/src/components/panels/commits/commitdetails.tsx
  3. 12
      libs/remix-ui/git/src/components/panels/commits/commitdetailsitem.tsx

@ -37,6 +37,19 @@ export const CommitMessage = () => {
await actions.commit(message.value) await actions.commit(message.value)
} }
const getRemote = () => {
return context.upstream ? context.upstream : context.defaultRemote ? context.defaultRemote : null
}
const getRemoteName = () => {
return getRemote() ? getRemote().remote : ''
}
const sync = async() => {
await actions.pull(getRemoteName(), context.currentBranch.name)
await actions.push(getRemoteName(), context.currentBranch.name)
}
const commitNotAllowed = () => { const commitNotAllowed = () => {
return context.canCommit === false || message.value === "" || ( context.staged.length === 0 && context.allchangesnotstaged.length == 0 ) return context.canCommit === false || message.value === "" || ( context.staged.length === 0 && context.allchangesnotstaged.length == 0 )
} }
@ -110,7 +123,7 @@ export const CommitMessage = () => {
<FontAwesomeIcon icon={faCheck} className="mr-1" /> <FontAwesomeIcon icon={faCheck} className="mr-1" />
Commit Commit
</button> </button>
<button data-id='syncButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Sync ?'':'d-none'}`} disabled={!syncEnabled()} onClick={async () => await commit()} > <button data-id='syncButton' className={`btn btn-primary w-100 ${buttonState === buttonStateValues.Sync ?'':'d-none'}`} disabled={!syncEnabled()} onClick={async () => await sync()} >
<FontAwesomeIcon icon={faSync} className="mr-1" aria-hidden="true" /> <FontAwesomeIcon icon={faSync} className="mr-1" aria-hidden="true" />
Sync Changes {upDownArrows()} Sync Changes {upDownArrows()}
</button> </button>

@ -40,6 +40,12 @@ export const CommitDetails = (props: CommitDetailsProps) => {
return commitsAhead(getRemote()).findIndex((c) => c.oid === commit.oid) > -1 return commitsAhead(getRemote()).findIndex((c) => c.oid === commit.oid) > -1
} }
const openFileOnRemote = (file: string, hash: string) => {
console.log("open file on remote", file, hash, getRemote() ? `${getRemote().remote}/${branch.name}/commit/${hash}/${file}` : "")
if (!getRemote()) return
window.open(`${getRemote() ? `${getRemote().url}/blob/${hash}/${file}` : ""}`, "_blank")
}
return (<Accordion activeKey={activePanel} defaultActiveKey=""> return (<Accordion activeKey={activePanel} defaultActiveKey="">
<CommitDetailsNavigation isAheadOfRepo={isAheadOfRepo()} commit={commit} checkout={checkout} eventKey="0" activePanel={activePanel} callback={setActivePanel} /> <CommitDetailsNavigation isAheadOfRepo={isAheadOfRepo()} commit={commit} checkout={checkout} eventKey="0" activePanel={activePanel} callback={setActivePanel} />
<Accordion.Collapse className="pl-2 border-left ml-1" eventKey="0"> <Accordion.Collapse className="pl-2 border-left ml-1" eventKey="0">
@ -47,7 +53,7 @@ export const CommitDetails = (props: CommitDetailsProps) => {
{context.commitChanges && context.commitChanges.filter( {context.commitChanges && context.commitChanges.filter(
(change) => change.hashModified === commit.oid && change.hashOriginal === commit.commit.parent[0] (change) => change.hashModified === commit.oid && change.hashOriginal === commit.commit.parent[0]
).map((change, index) => { ).map((change, index) => {
return (<CommitDetailsItems isAheadOfRepo={isAheadOfRepo()} key={index} commitChange={change}></CommitDetailsItems>) return (<CommitDetailsItems openFileOnRemote={openFileOnRemote} isAheadOfRepo={isAheadOfRepo()} key={index} commitChange={change}></CommitDetailsItems>)
})} })}
</> </>

@ -1,4 +1,4 @@
import { commitChange } from "../../../types"; import { branch, commitChange } from "../../../types";
import React from "react"; import React from "react";
import path from "path"; import path from "path";
import { gitActionsContext, pluginActionsContext } from "../../../state/context"; import { gitActionsContext, pluginActionsContext } from "../../../state/context";
@ -8,10 +8,11 @@ import { faGlobe } from "@fortawesome/free-solid-svg-icons";
export interface CCommitDetailsItemsProps { export interface CCommitDetailsItemsProps {
commitChange: commitChange; commitChange: commitChange;
isAheadOfRepo: boolean; isAheadOfRepo: boolean;
openFileOnRemote: (file: string, hash: string) => void;
} }
export const CommitDetailsItems = (props: CCommitDetailsItemsProps) => { export const CommitDetailsItems = (props: CCommitDetailsItemsProps) => {
const { commitChange, isAheadOfRepo } = props; const { commitChange, isAheadOfRepo, openFileOnRemote } = props;
const actions = React.useContext(gitActionsContext) const actions = React.useContext(gitActionsContext)
const pluginActions = React.useContext(pluginActionsContext) const pluginActions = React.useContext(pluginActionsContext)
@ -22,6 +23,10 @@ export const CommitDetailsItems = (props: CCommitDetailsItemsProps) => {
await pluginActions.openDiff(change) await pluginActions.openDiff(change)
} }
const openRemote = () => {
openFileOnRemote(commitChange.path, commitChange.hashModified)
}
function FunctionStatusIcons() { function FunctionStatusIcons() {
const status = commitChange.type const status = commitChange.type
return (<> return (<>
@ -39,7 +44,8 @@ export const CommitDetailsItems = (props: CCommitDetailsItemsProps) => {
<div className='text-secondary long-and-truncated'> {commitChange.path}</div> <div className='text-secondary long-and-truncated'> {commitChange.path}</div>
</div> </div>
<div className="d-flex align-items-end"> <div className="d-flex align-items-end">
<FontAwesomeIcon icon={faGlobe} className="mr-1 align-self-center" /> {!isAheadOfRepo ?
<FontAwesomeIcon role={'button'} icon={faGlobe} onClick={() => openRemote()} className="pointer mr-1 align-self-center" /> : <></>}
<FunctionStatusIcons></FunctionStatusIcons> <FunctionStatusIcons></FunctionStatusIcons>
</div> </div>
</div> </div>

Loading…
Cancel
Save