Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
TulshiDas39 committed Nov 11, 2024
2 parents 027a002 + dfd4852 commit f0c80df
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 25 deletions.
1 change: 1 addition & 0 deletions common_library/src/constants/RendererEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,6 @@ export class RendererEvents{
static readonly updateUserEmail = "updateUserEmail";
static readonly getGraphCommits = "getGraphCommits";
static readonly continueRebase = "continueRebase";
static readonly remote = "remote";
}

15 changes: 15 additions & 0 deletions src/businessClasses/GitManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class GitManager{
this.addMergeHandler();
this.addCleanhHandler();
this.addRemoteAddHandler();
this.addRemoteHandler();
this.addRemoteRemoveHandler();
this.addRemoteListHandler();
this.addRebaseHandler();
Expand Down Expand Up @@ -704,6 +705,14 @@ export class GitManager{
})
}

private addRemoteHandler(){
ipcMain.handle(RendererEvents.remote,async (e,repoPath:string,options:string[])=>{
const git = this.getGitRunner(repoPath);
const r = await git.remote(options);
return r;
})
}

private addRemoteRemoveHandler(){
ipcMain.handle(RendererEvents.gitRemoveRemote,async (e,repoInfo:RepositoryInfo,remoteName:string)=>{
await this.removeRemote(repoInfo, remoteName);
Expand All @@ -726,6 +735,12 @@ export class GitManager{
await git.addRemote(remote.name,remote.url);
}

private async updateRemote(repPath:string,name:string, url:string){
const git = this.getGitRunner(repPath);
const options = ["set-url",name,url];
await git.remote(options);
}

private async removeRemote(repoInfo:RepositoryInfo, remoteName:string){
const git = this.getGitRunner(repoInfo);
await git.removeRemote(remoteName);
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"scripts": {
"start": "set FAST_REFRESH=false && set NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
"start-mac": "export FAST_REFRESH=false && export NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
"start-mac": "export FAST_REFRESH=false && export NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,83 @@ import { useSelectorTyped } from "../../../../../store/rootReducer";
import { shallowEqual, useDispatch } from "react-redux";
import { AddRemote } from "./AddRemote";
import { ActionUI } from "../../../../../store/slices/UiSlice";
import { FaTrash } from "react-icons/fa";
import { FaPen, FaTrash } from "react-icons/fa";
import { IRemoteInfo } from "common_library";
import { IpcUtils } from "../../../../../lib/utils/IpcUtils";
import { ModalData } from "../../../../modals/ModalData";
import { ActionModals } from "../../../../../store";
import { EnumModals } from "../../../../../lib";
import { EnumModals, useMultiState } from "../../../../../lib";
import { Form } from "react-bootstrap";
import { AppButton } from "../../../../common";

interface ISingleRemoteProps{
url:string;
name:string;
handleRemove:()=>void;
onUpdate:(url:string)=>void;

}

interface ISingleRemoteState{
isEditing:boolean;
value:string;
}

function SingleRemote(props:ISingleRemoteProps){
const [state,setState] = useMultiState<ISingleRemoteState>({isEditing:false,value:props.url});
const dispatch = useDispatch();
const handleSave = ()=>{
setState({isEditing:false});
props.onUpdate(state.value);
}

const handleCancel = ()=>{
setState({isEditing:false,value:props.url});
}

const handleRemove=()=>{
const yesHandler = ()=>{
props.handleRemove();
}
ModalData.confirmationModal.YesHandler = yesHandler;
ModalData.confirmationModal.message = "Remove remote '"+props.name+"' ?";
dispatch(ActionModals.showModal(EnumModals.CONFIRMATION));
}

useEffect(()=>{
setState({value:props.url});
},[props.url]);

return <div className="d-flex border w-100 align-items-center">
<div className="flex-grow-1">
<div className="d-flex">
<b className="">{props.name}</b>
</div>
<div>
{!state.isEditing && <span>{props.url}</span>}
{state.isEditing &&
<div className="d-flex align-items-center pt-1">
<Form.Control type="text" value={state.value} onChange={e=> setState({value:e.target.value})} />

<div className="px-2 d-flex align-items-center">
<span className="pe-3">
<AppButton text="Save" className="text-primary" onClick={()=> handleSave()}/>
</span>
<AppButton text="Cancel" className="text-danger hover-brighter" title="Remove" onClick={_=> handleCancel()} />
</div>
</div>
}
</div>
</div>
{!state.isEditing && <div className="px-2">
<span className="pe-3">
<FaPen className="text-primary" onClick={()=> setState({isEditing:true})}/>
</span>
<FaTrash className="text-danger hover-brighter" title="Remove" onClick={_=> handleRemove()} />
</div>}

</div>
}

function RemoteListComponent(){
const store = useSelectorTyped(state=>({
Expand All @@ -22,15 +93,15 @@ function RemoteListComponent(){
},[])

const handleRemove = (remote:IRemoteInfo)=>{
const remoteHandler = ()=>{
IpcUtils.removeRemote(remote.name).then(_=>{
dispatch(ActionUI.increamentVersion("remoteList"));
})
}
ModalData.confirmationModal.YesHandler = remoteHandler;
ModalData.confirmationModal.message = "Remove remote '"+remote.name+"' ?";
dispatch(ActionModals.showModal(EnumModals.CONFIRMATION));
IpcUtils.removeRemote(remote.name).then(_=>{
dispatch(ActionUI.increamentVersion("remoteList"));
})
}

const handleUpdate = (remote:IRemoteInfo, url:string)=>{
IpcUtils.runRemote(["set-url",remote.name,url]).then(_=>{
dispatch(ActionUI.increamentVersion("remoteList"));
});
}

return <div className="w-100 p-1">
Expand All @@ -39,20 +110,8 @@ function RemoteListComponent(){
</div>
{
store.remotes.map(r=>(
<div key={r.url+r.name} className="d-flex border w-100 align-items-center">
<div className="flex-grow-1">
<div className="d-flex">
<b className="">{r.name}</b>
</div>
<div>
<span>{r.url}</span>
</div>
</div>
<div className="pe-2">
<FaTrash className="text-danger hover-brighter" title="Remove" onClick={_=> handleRemove(r)} />
</div>
</div>

<SingleRemote key={r.url+r.name} handleRemove={()=> handleRemove(r)} name={r.name} url={r.url}
onUpdate={(url)=> handleUpdate(r,url)} />
))
}
</div>
Expand Down
3 changes: 3 additions & 0 deletions ui/src/lib/utils/IpcUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { RepoUtils } from "./RepoUtils";
import { IpcResult } from "../interfaces/IpcResult";

export class IpcUtils{
static runRemote(options:string[]) {
return this.runGitCommand(RendererEvents.remote,[options]);
}

static abortRebase() {
const options = ["--abort"];
Expand Down

0 comments on commit f0c80df

Please sign in to comment.