From bbfeffcc59fd29cfa5c3fd01b1c36c44d21da329 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sun, 11 Aug 2024 23:25:23 +0600 Subject: [PATCH 01/21] add filter state --- frontend/src/lib/utils/GraphUtils.ts | 9 +++++++ .../branchGraphPublishers/PbCommitFilter.ts | 26 +++++++++++++++++++ src/config.ts | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index ec291578..ecd084a2 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -12,6 +12,7 @@ import { PbSvgContainerWidth, PbHorizontalScrollLeft, PbHorizontalScrollWidth, P import { Publisher } from "../publishers"; import { NumUtils } from "./NumUtils"; import { IpcUtils } from "./IpcUtils"; +import { PbCommitFilter } from "./branchGraphPublishers/PbCommitFilter"; interface IState{ @@ -32,6 +33,10 @@ interface IState{ viewBoxWidth:PbViewBoxWidth; viewBoxHeight:PbViewBoxHeight; verticalScrollHeight:PbVerticalScrollHeight; + fromDate:Publisher; + toDate:Publisher; + limit:Publisher; + filter:PbCommitFilter; } export class GraphUtils{ @@ -62,6 +67,9 @@ export class GraphUtils{ zoomLabel:new Publisher(1), horizontalScrollRatio:new Publisher(0), verticalScrollRatio:new Publisher(0), + fromDate: new Publisher(null), + toDate: new Publisher(new Date().toISOString()), + limit : new Publisher(400), } as IState; static resizeHandler = ()=>{ @@ -79,6 +87,7 @@ export class GraphUtils{ GraphUtils.state.viewBoxX = new PbViewBoxX(0); GraphUtils.state.viewBoxY = new PbViewBoxY(0); GraphUtils.state.viewBox = new PbViewBox({x:0,y:0,width:0,height:0}); + GraphUtils.state.filter = new PbCommitFilter(); } static createBranchPanel(){ diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts new file mode 100644 index 00000000..1cd4b143 --- /dev/null +++ b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts @@ -0,0 +1,26 @@ +import { DerivedPublisher } from "../../publishers"; +import { GraphUtils } from "../GraphUtils"; + +export interface ICommitFilter{ + fromDate?:string; + toDate:string; + limit:number; +} +export class PbCommitFilter extends DerivedPublisher{ + constructor(){ + super(); + GraphUtils.state.fromDate.subscribe(this.update.bind(this)); + GraphUtils.state.toDate.subscribe(this.update.bind(this)); + GraphUtils.state.limit.subscribe(this.update.bind(this)); + this.update(); + } + + protected getDerivedValue(): ICommitFilter { + const data = {} as ICommitFilter; + data.fromDate = GraphUtils.state.fromDate.value!; + data.toDate = GraphUtils.state.toDate.value; + data.limit = GraphUtils.state.limit.value; + return data; + } + +} \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index a2c1904d..5a76c24f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,4 +1,4 @@ export class Config{ - static readonly env:'development'|'production'='production'; + static readonly env:'development'|'production'='development'; static readonly FRONTEND_PORT = 57631; } \ No newline at end of file From f3f56e258932dd4dbed3ad1889f20c59aeb0a79c Mon Sep 17 00:00:00 2001 From: tulshi das Date: Thu, 15 Aug 2024 21:10:18 +0600 Subject: [PATCH 02/21] fix branch hidden issue --- frontend/src/lib/utils/ArrayUtils.ts | 4 ++++ frontend/src/lib/utils/RepoUtils.ts | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/utils/ArrayUtils.ts b/frontend/src/lib/utils/ArrayUtils.ts index e606ea97..707889be 100644 --- a/frontend/src/lib/utils/ArrayUtils.ts +++ b/frontend/src/lib/utils/ArrayUtils.ts @@ -12,4 +12,8 @@ export class ArrayUtils{ static findMax(array:number[]){ return array.reduce((acc,current) => Math.max(acc,current)) } + + static findMin(array:number[]){ + return array.reduce((acc,current) => Math.min(acc,current)) + } } \ No newline at end of file diff --git a/frontend/src/lib/utils/RepoUtils.ts b/frontend/src/lib/utils/RepoUtils.ts index 5af0c988..87c9a81c 100644 --- a/frontend/src/lib/utils/RepoUtils.ts +++ b/frontend/src/lib/utils/RepoUtils.ts @@ -57,6 +57,9 @@ export class RepoUtils{ } const setHeight = (branch:IBranchDetails)=>{ + if(branch.name == 'preproduction'){ + debugger; + } const upperOffset = branch.verticalOffset - 1; const upperBranches = repoDetails.resolvedBranches.filter(_=> _.verticalOffset === upperOffset); const upperBranchesWithoutHeight = upperBranches.filter(_=> !_.y); @@ -67,7 +70,10 @@ export class RepoUtils{ const branches = repoDetails.resolvedBranches.filter(_=> !!_.parentCommit); if(!!branches.length){ - for(let offset = branchesWithoutParent.length + 1; offset <= repoDetails.resolvedBranches.length ; offset++){ + debugger; + const startOffset = ArrayUtils.findMin(branches.map(_=>_.verticalOffset)); + for(let offset = startOffset; offset <= repoDetails.resolvedBranches.length ; offset++){ + debugger; const branchesOfThisOffset = branches.filter(_ => _.verticalOffset === offset); branchesOfThisOffset.forEach(_ => setHeight(_)); } @@ -135,6 +141,8 @@ export class RepoUtils{ private static sortBranches(repoDetails:IRepositoryDetails){ repoDetails.resolvedBranches.sort((x,y)=> x.serial > y.serial ?1:-1); + const br = repoDetails.resolvedBranches.find(_=> _.name === 'preproduction'); + console.log("preprod",br); } private static specifySerialsOfBranch(repoDetails:IRepositoryDetails){ From 1d275edd150fc59bce380fe017bcaa5cf21acba6 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sat, 17 Aug 2024 10:18:04 +0600 Subject: [PATCH 03/21] fix vertical position issue of branches --- frontend/src/lib/utils/ArrayUtils.ts | 4 +++ frontend/src/lib/utils/RepoUtils.ts | 38 +++++++--------------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/frontend/src/lib/utils/ArrayUtils.ts b/frontend/src/lib/utils/ArrayUtils.ts index 707889be..8029a9eb 100644 --- a/frontend/src/lib/utils/ArrayUtils.ts +++ b/frontend/src/lib/utils/ArrayUtils.ts @@ -10,10 +10,14 @@ export class ArrayUtils{ } static findMax(array:number[]){ + if(!array.length) + return 0; return array.reduce((acc,current) => Math.max(acc,current)) } static findMin(array:number[]){ + if(!array.length) + return 0; return array.reduce((acc,current) => Math.min(acc,current)) } } \ No newline at end of file diff --git a/frontend/src/lib/utils/RepoUtils.ts b/frontend/src/lib/utils/RepoUtils.ts index 87c9a81c..cf140a55 100644 --- a/frontend/src/lib/utils/RepoUtils.ts +++ b/frontend/src/lib/utils/RepoUtils.ts @@ -49,37 +49,19 @@ export class RepoUtils{ } private static setBranchHeights2(repoDetails:IRepositoryDetails){ - const branchesWithoutParent = repoDetails.resolvedBranches.filter(_=> !_.parentCommit); let y = 30; - for(let branch of branchesWithoutParent){ - branch.y = y + (branch.maxRefCount* RepoUtils.branchPanelFontSize); - y = branch.y + RepoUtils.distanceBetweenBranchLine; - } + const maxOffset = ArrayUtils.findMax(repoDetails.resolvedBranches.map(_=>_.verticalOffset)); - const setHeight = (branch:IBranchDetails)=>{ - if(branch.name == 'preproduction'){ - debugger; + for(let offset = 1;offset <= maxOffset;offset++){ + const branchesOfThisOffset = repoDetails.resolvedBranches.filter(_=> _.verticalOffset == offset); + for(let branch of branchesOfThisOffset){ + branch.y = y + (branch.maxRefCount* RepoUtils.branchPanelFontSize); } - const upperOffset = branch.verticalOffset - 1; - const upperBranches = repoDetails.resolvedBranches.filter(_=> _.verticalOffset === upperOffset); - const upperBranchesWithoutHeight = upperBranches.filter(_=> !_.y); - upperBranchesWithoutHeight.forEach(_ => setHeight(_)); - const y = ArrayUtils.findMax(upperBranches.map(_=>_.y)) + RepoUtils.distanceBetweenBranchLine; - branch.y = y + (branch.maxRefCount* RepoUtils.branchPanelFontSize); - } - const branches = repoDetails.resolvedBranches.filter(_=> !!_.parentCommit); - if(!!branches.length){ - debugger; - const startOffset = ArrayUtils.findMin(branches.map(_=>_.verticalOffset)); - for(let offset = startOffset; offset <= repoDetails.resolvedBranches.length ; offset++){ - debugger; - const branchesOfThisOffset = branches.filter(_ => _.verticalOffset === offset); - branchesOfThisOffset.forEach(_ => setHeight(_)); - } - } - - repoDetails.branchPanelHeight = ArrayUtils.findMax(repoDetails.resolvedBranches.map(_=>_.y)) + 50; + y = ArrayUtils.findMax(branchesOfThisOffset.map(_=>_.y)) + RepoUtils.distanceBetweenBranchLine; + } + + repoDetails.branchPanelHeight = y + 50; } private static isOverlappingBranches(branch1:IBranchDetails,branch2:IBranchDetails){ @@ -141,8 +123,6 @@ export class RepoUtils{ private static sortBranches(repoDetails:IRepositoryDetails){ repoDetails.resolvedBranches.sort((x,y)=> x.serial > y.serial ?1:-1); - const br = repoDetails.resolvedBranches.find(_=> _.name === 'preproduction'); - console.log("preprod",br); } private static specifySerialsOfBranch(repoDetails:IRepositoryDetails){ From 674877034124693554b886151c1caf32d1ede80f Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sat, 17 Aug 2024 10:56:41 +0600 Subject: [PATCH 04/21] keep master branch at top --- frontend/src/lib/utils/RepoUtils.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/lib/utils/RepoUtils.ts b/frontend/src/lib/utils/RepoUtils.ts index cf140a55..582f2177 100644 --- a/frontend/src/lib/utils/RepoUtils.ts +++ b/frontend/src/lib/utils/RepoUtils.ts @@ -84,6 +84,8 @@ export class RepoUtils{ private static setBranchVerticalOffset(repoDetails:IRepositoryDetails){ const branchesWithoutParent = repoDetails.resolvedBranches.filter(_=> !_.parentCommit); + const mainBranches = ["master","main"]; + branchesWithoutParent.sort((a,_) => !mainBranches.includes(a.name) ? 1:-1); for(let i = 0; i < branchesWithoutParent.length; i++){ const branch = branchesWithoutParent[i]; branch.verticalOffset = i + 1; From 8aa759dbb8d03c4efc3dfde1c467a85c17fe6900 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sat, 17 Aug 2024 11:50:29 +0600 Subject: [PATCH 05/21] refactoring --- common_library/src/models/IBranchDetails.ts | 6 ++--- common_library/src/models/ICommitInfo.ts | 1 - frontend/src/lib/utils/RepoUtils.ts | 28 ++++++++++----------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/common_library/src/models/IBranchDetails.ts b/common_library/src/models/IBranchDetails.ts index ec8e69f1..3c7807ce 100644 --- a/common_library/src/models/IBranchDetails.ts +++ b/common_library/src/models/IBranchDetails.ts @@ -8,13 +8,11 @@ export interface IBranchDetails{ LastCommitsByRemotes:ILastCommitByRemote[]; noDerivedCommits:boolean; parentCommit?:ICommitInfo; - serial:number; + drawOrder:number; y:number; - // commitWithMaxRefCount:ICommitInfo; maxRefCount:number; increasedHeightForDetached:number; verticalOffset:number; - // Group uiObj; } export function createBranchDetailsObj(){ @@ -24,7 +22,7 @@ export function createBranchDetailsObj(){ LastCommitsByRemotes:[], commits:[], noDerivedCommits:false, - serial:0, + drawOrder:0, y:0, maxRefCount:0, increasedHeightForDetached:0, diff --git a/common_library/src/models/ICommitInfo.ts b/common_library/src/models/ICommitInfo.ts index f9b486ce..b6f2c2f7 100644 --- a/common_library/src/models/ICommitInfo.ts +++ b/common_library/src/models/ICommitInfo.ts @@ -19,7 +19,6 @@ export interface ICommitInfo{ x:number; isHead:boolean; inMergingState?:boolean; - // SingleCommit UiObj; } export function CreateCommitInfoObj(){ diff --git a/frontend/src/lib/utils/RepoUtils.ts b/frontend/src/lib/utils/RepoUtils.ts index 582f2177..c8d29588 100644 --- a/frontend/src/lib/utils/RepoUtils.ts +++ b/frontend/src/lib/utils/RepoUtils.ts @@ -17,10 +17,10 @@ export class RepoUtils{ RepoUtils.getBranchDetails(repoDetails); RepoUtils.enListSourceCommits(repoDetails); RepoUtils.finaliseSourceCommits(repoDetails); - RepoUtils.specifySerialsOfBranch(repoDetails); + RepoUtils.specifyDrawOrdersOfBranch(repoDetails); RepoUtils.setBranchVerticalOffset(repoDetails); RepoUtils.sortBranches(repoDetails); - RepoUtils.setBranchHeights2(repoDetails); + RepoUtils.setBranchHeights(repoDetails); RepoUtils.reversBranches(repoDetails); RepoUtils.createMergeLines(repoDetails); @@ -48,7 +48,7 @@ export class RepoUtils{ repoDetails.resolvedBranches.reverse(); } - private static setBranchHeights2(repoDetails:IRepositoryDetails){ + private static setBranchHeights(repoDetails:IRepositoryDetails){ let y = 30; const maxOffset = ArrayUtils.findMax(repoDetails.resolvedBranches.map(_=>_.verticalOffset)); @@ -124,22 +124,22 @@ export class RepoUtils{ } private static sortBranches(repoDetails:IRepositoryDetails){ - repoDetails.resolvedBranches.sort((x,y)=> x.serial > y.serial ?1:-1); + repoDetails.resolvedBranches.sort((x,y)=> x.drawOrder > y.drawOrder ?1:-1); } - private static specifySerialsOfBranch(repoDetails:IRepositoryDetails){ - const getSerial=(branch:IBranchDetails):number=>{ - if(branch.serial != 0) return branch.serial; - let parentSerial = getSerial(branch.parentCommit?.ownerBranch!); + private static specifyDrawOrdersOfBranch(repoDetails:IRepositoryDetails){ + const getDrawOrder=(branch:IBranchDetails):number=>{ + if(branch.drawOrder != 0) return branch.drawOrder; + let parentDrawOrder = getDrawOrder(branch.parentCommit?.ownerBranch!); let commitInex=0; if(!!branch.name)commitInex = branch.parentCommit!.ownerBranch.commits.indexOf(branch.parentCommit!)+1; else commitInex = branch.parentCommit!.ownerBranch.commits.length+1; - let measuredSerial = parentSerial+ parentSerial * (1.0/(10.0*commitInex)); - return measuredSerial; + let measuredDrawOrder = parentDrawOrder+ parentDrawOrder * (1.0/(10.0*commitInex)); + return measuredDrawOrder; } repoDetails.resolvedBranches.forEach(br=>{ - br.serial = getSerial(br); + br.drawOrder = getDrawOrder(br); }); } @@ -185,8 +185,8 @@ export class RepoUtils{ realOwnerBranch.parentCommit = currentOwnerBranch.parentCommit; currentOwnerBranch.parentCommit = sourceCommit; - if(currentOwnerBranch.serial != 0.0) realOwnerBranch.serial = currentOwnerBranch.serial; - currentOwnerBranch.serial = 0.0; + if(currentOwnerBranch.drawOrder != 0.0) realOwnerBranch.drawOrder = currentOwnerBranch.drawOrder; + currentOwnerBranch.drawOrder = 0.0; let commitToMove = sourceCommit; while (commitToMove != realOwnerBranch.parentCommit) { @@ -211,7 +211,7 @@ export class RepoUtils{ newOwnerBranch.parentCommit = parentCommit; if(!parentCommit) { branchTree.push(newOwnerBranch); - newOwnerBranch.serial = branchTree.length; + newOwnerBranch.drawOrder = branchTree.length; } branchDetails.push(newOwnerBranch); return newOwnerBranch; From 8bcded1623aec9b7d0abb028f63aef38fb2adda0 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sat, 17 Aug 2024 12:26:27 +0600 Subject: [PATCH 06/21] fix filter initialisation --- frontend/src/lib/utils/GraphUtils.ts | 4 ++-- .../src/lib/utils/branchGraphPublishers/PbCommitFilter.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index ecd084a2..5d2b94a8 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -4,7 +4,7 @@ import * as ReactDOMServer from 'react-dom/server'; import { BranchPanel } from "../../components/selectedRepository/selectedRepoRight/branches/BranchPanel"; import { UiUtils } from "./UiUtils"; import { EnumHtmlIds, EnumIdPrefix } from "../enums"; -import { Constants, CreateCommitInfoObj, IBranchDetails, ICommitInfo, IRepositoryDetails, IStatus } from "common_library"; +import { Constants, CreateCommitInfoObj, IBranchDetails, ICommitInfo, IStatus } from "common_library"; import { ModalData } from "../../components/modals/ModalData"; import { CacheUtils } from "./CacheUtils"; import { ReduxUtils } from "./ReduxUtils"; @@ -87,7 +87,7 @@ export class GraphUtils{ GraphUtils.state.viewBoxX = new PbViewBoxX(0); GraphUtils.state.viewBoxY = new PbViewBoxY(0); GraphUtils.state.viewBox = new PbViewBox({x:0,y:0,width:0,height:0}); - GraphUtils.state.filter = new PbCommitFilter(); + GraphUtils.state.filter = new PbCommitFilter(); } static createBranchPanel(){ diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts index 1cd4b143..e1885f3c 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts @@ -12,7 +12,7 @@ export class PbCommitFilter extends DerivedPublisher{ GraphUtils.state.fromDate.subscribe(this.update.bind(this)); GraphUtils.state.toDate.subscribe(this.update.bind(this)); GraphUtils.state.limit.subscribe(this.update.bind(this)); - this.update(); + this._val = this.getDerivedValue(); } protected getDerivedValue(): ICommitFilter { From 6c23113e3444191bd38eaf38f229306ab18f25eb Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sat, 17 Aug 2024 15:27:30 +0600 Subject: [PATCH 07/21] apply date range filters in graph --- common_library/src/models/ICommitFilter.ts | 5 ++++ common_library/src/models/index.ts | 3 +- .../selectedRepository/SelectedRepository.tsx | 10 +++++-- frontend/src/lib/utils/IpcUtils.ts | 10 +++++-- .../branchGraphPublishers/PbCommitFilter.ts | 7 ++--- src/businessClasses/GitManager.ts | 28 ++++++++++++++----- 6 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 common_library/src/models/ICommitFilter.ts diff --git a/common_library/src/models/ICommitFilter.ts b/common_library/src/models/ICommitFilter.ts new file mode 100644 index 00000000..4e0ad5ac --- /dev/null +++ b/common_library/src/models/ICommitFilter.ts @@ -0,0 +1,5 @@ +export interface ICommitFilter{ + fromDate?:string; + toDate:string; + limit:number; +} \ No newline at end of file diff --git a/common_library/src/models/index.ts b/common_library/src/models/index.ts index 15f4167f..5c5699de 100644 --- a/common_library/src/models/index.ts +++ b/common_library/src/models/index.ts @@ -17,4 +17,5 @@ export * from './IActionTaken'; export * from './IStash'; export * from './IUserConfig'; export * from './ITypedConfig'; -export * from './IGitConfig'; \ No newline at end of file +export * from './IGitConfig'; +export * from './ICommitFilter'; \ No newline at end of file diff --git a/frontend/src/components/selectedRepository/SelectedRepository.tsx b/frontend/src/components/selectedRepository/SelectedRepository.tsx index 1f42a3dd..30f171b8 100644 --- a/frontend/src/components/selectedRepository/SelectedRepository.tsx +++ b/frontend/src/components/selectedRepository/SelectedRepository.tsx @@ -37,9 +37,13 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ const {currentMousePosition:position,elementRef:resizer} = useDrag(); const dispatch = useDispatch(); - const getRepoDetails = async ()=>{ - const res:IRepositoryDetails = await window.ipcRenderer.invoke(RendererEvents.getRepositoryDetails().channel,props.repo); - return res; + const getRepoDetails = async ()=>{ + const filter = GraphUtils.state.filter.value; + return IpcUtils.getRepoDetails(props.repo,filter).then(r=>{ + if(!r.error) + return r.result!; + throw "Can't load repo details"; + }); } const updateStatus = ()=>{ diff --git a/frontend/src/lib/utils/IpcUtils.ts b/frontend/src/lib/utils/IpcUtils.ts index e4600f6f..950562f1 100644 --- a/frontend/src/lib/utils/IpcUtils.ts +++ b/frontend/src/lib/utils/IpcUtils.ts @@ -1,4 +1,4 @@ -import { Annotation, IActionTaken, ICommitInfo, ILogFilterOptions, IPaginated, IRemoteInfo, IStash, IStatus, ITypedConfig, IUserConfig, RendererEvents, RepositoryInfo } from "common_library"; +import { Annotation, IActionTaken, ICommitFilter, ICommitInfo, ILogFilterOptions, IPaginated, IRemoteInfo, IRepositoryDetails, IStash, IStatus, ITypedConfig, IUserConfig, RendererEvents, RepositoryInfo } from "common_library"; import { RepoUtils } from "./RepoUtils"; import { IpcResult } from "../interfaces/IpcResult"; @@ -219,7 +219,7 @@ export class IpcUtils{ }; } - private static async runGitCommand(channel:string,args:any[],repositoryPath?:string){ + private static async runGitCommand(channel:string,args:any[],repositoryPath?:string|RepositoryInfo){ if(!repositoryPath) repositoryPath = RepoUtils.repositoryDetails.repoInfo.path; return IpcUtils.execute(channel,[repositoryPath, ...args]); @@ -250,4 +250,10 @@ export class IpcUtils{ const r = await this.execute(RendererEvents.addAnnotation,[annot]); return r; } + + static async getRepoDetails(repoInfo:RepositoryInfo,filter:ICommitFilter){ + const r = await IpcUtils.runGitCommand(RendererEvents.getRepositoryDetails().channel,[filter],repoInfo); + return r; + } + } \ No newline at end of file diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts index e1885f3c..2d1250f2 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts @@ -1,11 +1,8 @@ +import { ICommitFilter } from "common_library"; import { DerivedPublisher } from "../../publishers"; import { GraphUtils } from "../GraphUtils"; -export interface ICommitFilter{ - fromDate?:string; - toDate:string; - limit:number; -} + export class PbCommitFilter extends DerivedPublisher{ constructor(){ super(); diff --git a/src/businessClasses/GitManager.ts b/src/businessClasses/GitManager.ts index 5cc17f99..ec65c7cc 100644 --- a/src/businessClasses/GitManager.ts +++ b/src/businessClasses/GitManager.ts @@ -1,4 +1,4 @@ -import { RendererEvents, RepositoryInfo ,CreateRepositoryDetails, IRemoteInfo,IStatus, ICommitInfo, IRepositoryDetails, IChanges, IFile, EnumChangeType, EnumChangeGroup, ILogFilterOptions, IPaginated, IGitCommandInfo, IActionTaken, IStash, IGitConfig, IUserConfig, ITypedConfig} from "common_library"; +import { RendererEvents, RepositoryInfo ,CreateRepositoryDetails, IRemoteInfo,IStatus, ICommitInfo, IRepositoryDetails, IChanges, IFile, EnumChangeType, EnumChangeGroup, ILogFilterOptions, IPaginated, IGitCommandInfo, IActionTaken, IStash, IGitConfig, IUserConfig, ITypedConfig, ICommitFilter} from "common_library"; import { ipcMain, ipcRenderer } from "electron"; import { existsSync, readdirSync } from "fs-extra"; import simpleGit, { CleanOptions, FetchResult, PullResult, PushResult, SimpleGit, SimpleGitOptions, SimpleGitProgressEvent } from "simple-git"; @@ -279,8 +279,8 @@ export class GitManager{ } private addRepoDetailsHandler(){ - ipcMain.handle(RendererEvents.getRepositoryDetails().channel, async (e,repoInfo:RepositoryInfo)=>{ - const repoDetails = await this.repoDetails(repoInfo); + ipcMain.handle(RendererEvents.getRepositoryDetails().channel, async (e,repoInfo:RepositoryInfo,filter:ICommitFilter)=>{ + const repoDetails = await this.repoDetails(repoInfo,filter); return repoDetails; }); } @@ -346,11 +346,11 @@ export class GitManager{ repoDetails.headCommit = head; } - private async repoDetails(repoInfo:RepositoryInfo){ + private async repoDetails(repoInfo:RepositoryInfo,filter:ICommitFilter){ const repoDetails = CreateRepositoryDetails(); repoDetails.repoInfo = repoInfo; const git = this.getGitRunner(repoInfo); - const commits = await this.getCommits(git); + const commits = await this.getCommits(git,filter); repoDetails.allCommits = commits; repoDetails.branchList = await this.getAllBranches(git); repoDetails.status = await this.getStatus(repoInfo); @@ -454,11 +454,25 @@ export class GitManager{ } } - private async getCommits(git: SimpleGit){ + private getFilterOptions(filter:ICommitFilter){ + const options = [`--before=${filter.toDate}`]; + if(filter.fromDate){ + options.push(`--after=${filter.fromDate}`); + } + else{ + options.push(`--max-count=${filter.limit}`); + } + return options; + } + + private async getCommits(git: SimpleGit,filter:ICommitFilter){ const commitLimit=500; //const LogFormat = "--pretty="+logFields.Hash+":%H%n"+LogFields.Abbrev_Hash+":%h%n"+LogFields.Parent_Hashes+":%p%n"+LogFields.Author_Name+":%an%n"+LogFields.Author_Email+":%ae%n"+LogFields.Date+":%ad%n"+LogFields.Ref+":%D%n"+LogFields.Message+":%s%n"; try{ - let res = await git.raw(["log","--exclude=refs/stash", "--all",`--max-count=${commitLimit}`,`--skip=${0*commitLimit}`,"--date=iso-strict","--topo-order", this.LogFormat]); + //--`--skip=${0*commitLimit}` + const filterOptions = this.getFilterOptions(filter); + const options = ["log","--exclude=refs/stash", "--all",...filterOptions,"--date=iso-strict","--topo-order", this.LogFormat]; + let res = await git.raw(options); const commits = CommitParser.parse(res); return commits; }catch(e){ From c0d504b2c3e621e83064f7e562151f230643aaff Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sat, 17 Aug 2024 18:30:40 +0600 Subject: [PATCH 08/21] refactor head commit state --- frontend/src/lib/interfaces/INotifiable.ts | 4 ++ frontend/src/lib/interfaces/IPublisher.ts | 8 ++-- frontend/src/lib/interfaces/IUpdater.ts | 5 +++ frontend/src/lib/interfaces/index.ts | 3 +- .../src/lib/publishers/DerivedPublisher.ts | 3 +- frontend/src/lib/publishers/Notifier.ts | 35 +++++++++++++++++ frontend/src/lib/publishers/Publisher.ts | 29 +++----------- frontend/src/lib/utils/GraphUtils.ts | 38 ++++++++----------- .../branchGraphPublishers/PbHeadCommit.ts | 18 +++++++-- 9 files changed, 88 insertions(+), 55 deletions(-) create mode 100644 frontend/src/lib/interfaces/INotifiable.ts create mode 100644 frontend/src/lib/interfaces/IUpdater.ts create mode 100644 frontend/src/lib/publishers/Notifier.ts diff --git a/frontend/src/lib/interfaces/INotifiable.ts b/frontend/src/lib/interfaces/INotifiable.ts new file mode 100644 index 00000000..effb6790 --- /dev/null +++ b/frontend/src/lib/interfaces/INotifiable.ts @@ -0,0 +1,4 @@ +export interface INotifiable{ + subscribe:(callback:(val:T)=>void)=>void; + unSubscribe:(callback:(val:T)=>void)=>void; +} \ No newline at end of file diff --git a/frontend/src/lib/interfaces/IPublisher.ts b/frontend/src/lib/interfaces/IPublisher.ts index a15473ed..a1902ae4 100644 --- a/frontend/src/lib/interfaces/IPublisher.ts +++ b/frontend/src/lib/interfaces/IPublisher.ts @@ -1,5 +1,5 @@ -export interface IPublisher{ - subscribe:(callback:(val:T)=>void)=>void; - unSubscribe:(callback:(val:T)=>void)=>void; - publish:(val:T)=>void; +import { INotifiable } from "./INotifiable"; + +export interface IPublisher extends INotifiable{ + publish:(val:T)=>void; } \ No newline at end of file diff --git a/frontend/src/lib/interfaces/IUpdater.ts b/frontend/src/lib/interfaces/IUpdater.ts new file mode 100644 index 00000000..5bf8d3fd --- /dev/null +++ b/frontend/src/lib/interfaces/IUpdater.ts @@ -0,0 +1,5 @@ +import { INotifiable } from "./INotifiable"; + +export interface IUpdater extends INotifiable{ + update:()=>void; +} \ No newline at end of file diff --git a/frontend/src/lib/interfaces/index.ts b/frontend/src/lib/interfaces/index.ts index 6f98a060..2b741430 100644 --- a/frontend/src/lib/interfaces/index.ts +++ b/frontend/src/lib/interfaces/index.ts @@ -8,4 +8,5 @@ export * from './IPublisher'; export * from './IPositionDiff'; export * from './ICommitFlatInfo'; export * from './IpcParams'; -export * from './IScopedValue'; \ No newline at end of file +export * from './IScopedValue'; +export * from './INotifiable'; \ No newline at end of file diff --git a/frontend/src/lib/publishers/DerivedPublisher.ts b/frontend/src/lib/publishers/DerivedPublisher.ts index 8b64db32..486f2664 100644 --- a/frontend/src/lib/publishers/DerivedPublisher.ts +++ b/frontend/src/lib/publishers/DerivedPublisher.ts @@ -10,6 +10,7 @@ export abstract class DerivedPublisher extends Publisher{ protected abstract getDerivedValue():T; update(){ - this.publish(this.getDerivedValue()); + this.value = this.getDerivedValue(); + this.notifyAll(); } } \ No newline at end of file diff --git a/frontend/src/lib/publishers/Notifier.ts b/frontend/src/lib/publishers/Notifier.ts new file mode 100644 index 00000000..feba2408 --- /dev/null +++ b/frontend/src/lib/publishers/Notifier.ts @@ -0,0 +1,35 @@ +import { INotifiable } from "../interfaces"; + +export class Notifier implements INotifiable{ + protected _prevVal?:T; + protected _val:T; + protected events:((val: T) => void)[]=[]; + constructor(value:T){ + this._val = value; + } + get value(){ + return this._val; + } + + protected set value(v:T){ + this._prevVal = this._val; + this._val = v; + } + + get prevValue(){ + return this._prevVal; + } + + public notifyAll(){ + this.events.forEach(f => f(this._val)); + } + + subscribe(callback: (val: T) => void){ + if(!this.events.includes(callback)) + this.events.push(callback); + return this; + } + unSubscribe(callback: (val: T) => void) { + this.events = this.events.filter( v => v != callback); + } +} \ No newline at end of file diff --git a/frontend/src/lib/publishers/Publisher.ts b/frontend/src/lib/publishers/Publisher.ts index 0044623d..73de489c 100644 --- a/frontend/src/lib/publishers/Publisher.ts +++ b/frontend/src/lib/publishers/Publisher.ts @@ -1,32 +1,15 @@ import { IPublisher } from "../interfaces"; +import { Notifier } from "./Notifier"; -export class Publisher implements IPublisher{ - protected _prevVal?:T; - protected _val:T; - protected events:((val: T) => void)[]=[]; +export class Publisher extends Notifier implements IPublisher{ constructor(value:T){ - this._val = value; - } - get value(){ - return this._val; - } + super(value) + } - get prevValue(){ - return this._prevVal; - } - subscribe(callback: (val: T) => void){ - if(!this.events.includes(callback)) - this.events.push(callback); - return this; - } - unSubscribe(callback: (val: T) => void) { - this.events = this.events.filter( v => v != callback); - } publish(v:T){ if(this._val == v) return; - this._prevVal = this._val; - this._val = v; - this.events.forEach(f => f(this._val)); + this.value = v; + this.notifyAll(); } } \ No newline at end of file diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index 5d2b94a8..9abf47c9 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -373,17 +373,21 @@ export class GraphUtils{ try{ const newStatus = RepoUtils.repositoryDetails?.status; if(!newStatus?.headCommit) return false; - if(newStatus.headCommit.hash !== GraphUtils.state.headCommit.value?.hash) return true; - const uiRefs = GraphUtils.state.headCommit.value.refValues; - const newRefs = newStatus.headCommit.refValues; - if(newRefs.some(ref=> !uiRefs.includes(ref)) || newRefs.length !== uiRefs.length) return true; + + if(!!GraphUtils.state.headCommit.value){ + if(newStatus.headCommit.hash !== GraphUtils.state.headCommit.value.hash) return true; + const uiRefs = GraphUtils.state.headCommit.value.refValues; + const newRefs = newStatus.headCommit.refValues; + if(newRefs.some(ref=> !uiRefs.includes(ref)) || newRefs.length !== uiRefs.length) return true; + } + let commits = await IpcUtils.getCommitList({pageIndex:0,pageSize:50}); for(let c of commits.list){ - const existingCm = RepoUtils.repositoryDetails.allCommits.find(_=> _.hash === c.hash); - if(!existingCm) - return true; - if(existingCm.refValues.some(_=> !c.refValues.includes(_))) - return true; + // const existingCm = RepoUtils.repositoryDetails.allCommits.find(_=> _.hash === c.hash); + // if(!existingCm) + // return true; + // if(existingCm.refValues.some(_=> !c.refValues.includes(_))) + // return true; } return false; }catch(e){ @@ -499,20 +503,8 @@ export class GraphUtils{ GraphUtils.state.horizontalScrollWidth.update(); GraphUtils.state.verticalScrollHeight.update(); //GraphUtils.state.selectedCommit.publish(RepoUtils.repositoryDetails.headCommit); - GraphUtils.state.headCommit.publish(RepoUtils.repositoryDetails.headCommit); - } - - static updateHeadIdentifier(){ - const currentHead = GraphUtils.state.headCommit.value; - if(currentHead != null){ - const headElem = GraphUtils.svgContainer.querySelector(`#${EnumIdPrefix.COMMIT_TEXT}${currentHead.hash}`) - headElem?.classList.remove("d-none"); - } - if(!GraphUtils.state.headCommit.prevValue) - return; - const prevHeadElem = GraphUtils.svgContainer.querySelector(`#${EnumIdPrefix.COMMIT_TEXT}${GraphUtils.state.headCommit.prevValue!.hash}`); - prevHeadElem?.classList.add("d-none"); - } + GraphUtils.state.headCommit.update(); + } static checkForUiUpdate(newStatus:IStatus){ const existingStatus = RepoUtils.repositoryDetails?.status; diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts b/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts index 34f4f031..719ef540 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts @@ -1,10 +1,22 @@ import { ICommitInfo } from "common_library"; -import { UiState } from "../../publishers"; +import { DerivedState } from "../../publishers"; import { GraphUtils } from "../GraphUtils"; +import { RepoUtils } from "../RepoUtils"; +import { EnumIdPrefix } from "../../enums"; -export class PbHeadCommit extends UiState{ +export class PbHeadCommit extends DerivedState{ + protected getDerivedValue(): ICommitInfo | undefined { + return RepoUtils.repositoryDetails?.allCommits.find(_=>_.isHead); + } protected applyChange(): void { - GraphUtils.updateHeadIdentifier(); + if(this.value){ + const headElem = GraphUtils.svgContainer.querySelector(`#${EnumIdPrefix.COMMIT_TEXT}${this.value.hash}`) + headElem?.classList.remove("d-none"); + } + if(!this.prevValue) + return; + const prevHeadElem = GraphUtils.svgContainer.querySelector(`#${EnumIdPrefix.COMMIT_TEXT}${GraphUtils.state.headCommit.prevValue!.hash}`); + prevHeadElem?.classList.add("d-none"); } } \ No newline at end of file From 837a398075ad5c4ed524baea27745c42b0f3c6b2 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sat, 17 Aug 2024 18:32:35 +0600 Subject: [PATCH 09/21] keep previous changes --- frontend/src/lib/utils/GraphUtils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index 9abf47c9..5a5685ff 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -383,11 +383,11 @@ export class GraphUtils{ let commits = await IpcUtils.getCommitList({pageIndex:0,pageSize:50}); for(let c of commits.list){ - // const existingCm = RepoUtils.repositoryDetails.allCommits.find(_=> _.hash === c.hash); - // if(!existingCm) - // return true; - // if(existingCm.refValues.some(_=> !c.refValues.includes(_))) - // return true; + const existingCm = RepoUtils.repositoryDetails.allCommits.find(_=> _.hash === c.hash); + if(!existingCm) + return true; + if(existingCm.refValues.some(_=> !c.refValues.includes(_))) + return true; } return false; }catch(e){ From dba084a953198d342e28e45b23eda0f75a711480 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sun, 18 Aug 2024 01:10:31 +0600 Subject: [PATCH 10/21] implement graph refresh on filter change --- .../src/constants/RendererEvents.ts | 2 +- common_library/src/models/ICommitFilter.ts | 1 + .../components/modals/CommitContextModal.tsx | 391 ------------------ .../selectedRepository/SelectedRepository.tsx | 11 +- .../branches/BranchActions.tsx | 2 - frontend/src/lib/utils/GraphUtils.ts | 23 +- frontend/src/lib/utils/IpcUtils.ts | 7 + .../branchGraphPublishers/PbCommitFilter.ts | 32 +- .../branchGraphPublishers/PbHeadCommit.ts | 2 +- src/businessClasses/GitManager.ts | 9 + 10 files changed, 58 insertions(+), 422 deletions(-) delete mode 100644 frontend/src/components/modals/CommitContextModal.tsx diff --git a/common_library/src/constants/RendererEvents.ts b/common_library/src/constants/RendererEvents.ts index cc43cffa..bf9485f2 100644 --- a/common_library/src/constants/RendererEvents.ts +++ b/common_library/src/constants/RendererEvents.ts @@ -278,6 +278,6 @@ export class RendererEvents{ static readonly getUserConfig = "getUserConfig"; static readonly updateUserName = "updateUserName"; static readonly updateUserEmail = "updateUserEmail"; - + static readonly getGraphCommits = "getGraphCommits"; } diff --git a/common_library/src/models/ICommitFilter.ts b/common_library/src/models/ICommitFilter.ts index 4e0ad5ac..0e8dc9b4 100644 --- a/common_library/src/models/ICommitFilter.ts +++ b/common_library/src/models/ICommitFilter.ts @@ -2,4 +2,5 @@ export interface ICommitFilter{ fromDate?:string; toDate:string; limit:number; + userModified:boolean; } \ No newline at end of file diff --git a/frontend/src/components/modals/CommitContextModal.tsx b/frontend/src/components/modals/CommitContextModal.tsx deleted file mode 100644 index 9306e7d9..00000000 --- a/frontend/src/components/modals/CommitContextModal.tsx +++ /dev/null @@ -1,391 +0,0 @@ -import { EnumChangeGroup, IStatus, RendererEvents } from "common_library"; -import React, { Fragment, useEffect, useMemo, useRef } from "react"; -import { Modal } from "react-bootstrap"; -import { shallowEqual, useDispatch } from "react-redux"; -import { RepoUtils, EnumModals, EnumSelectedRepoTab, IPositition, ReduxUtils, UiUtils, useMultiState } from "../../lib"; -import { GraphUtils } from "../../lib/utils/GraphUtils"; -import { ActionChanges, ActionModals } from "../../store"; -import { useSelectorTyped } from "../../store/rootReducer"; -import { ActionUI } from "../../store/slices/UiSlice"; -import { InitialModalData, ModalData } from "./ModalData"; -import { IpcUtils } from "../../lib/utils/IpcUtils"; -import { FaCodeBranch, FaRegPaperPlane } from "react-icons/fa"; -import { GitUtils } from "../../lib/utils/GitUtils"; - -enum Option{ - Checkout, - Merge, - Rebase, - CherryPick, - MoreOptions, - SoftReset, - HardReset, - DeleteBranch, -} - -interface IState{ - mouseOver?:Option; - showMore:boolean; - position:IPositition; -} - -function CommitContextModalComponent(){ - const Data = ModalData.commitContextModal; - const dispatch = useDispatch(); - const store = useSelectorTyped((state)=>({ - show:state.modal.openedModals.includes(EnumModals.COMMIT_CONTEXT), - repo:state.savedData.recentRepositories.find(x=>x.isSelected), - }),shallowEqual); - - const [state, setState] = useMultiState({showMore:false} as IState); - - const refData = useRef({mergerCommitMessage:"",onHover:false,show:false}); - - useEffect(()=>{ - refData.current.show = store.show; - if(store.show){ - let elem = document.querySelector(".commitContext") as HTMLElement; - if(elem){ - elem.style.marginTop = state.position.y+"px"; - elem.style.marginLeft = state.position.x+"px"; - } - } - else{ - setState({showMore:false}); - } - },[store.show,state.position]) - - const hideModal=()=>{ - ModalData.commitContextModal = InitialModalData.commitContextModal; - dispatch(ActionModals.hideModal(EnumModals.COMMIT_CONTEXT)); - } - - const checkOutCommit=(destination:string)=>{ - const options:string[]=[destination]; - IpcUtils.checkout(options).then(()=>{ - IpcUtils.getRepoStatusSync().then(status=>{ - GraphUtils.handleCheckout(Data.selectedCommit,status); - }) - }); - hideModal(); - } - const handleCreateNewBranchClick=()=>{ - ModalData.createBranchModal.sourceCommit = Data.selectedCommit; - dispatch(ActionModals.hideModal(EnumModals.COMMIT_CONTEXT)); - dispatch(ActionModals.showModal(EnumModals.CREATE_BRANCH)); - } - - const mergeCommit=(hash:string)=>{ - dispatch(ActionModals.hideModal(EnumModals.COMMIT_CONTEXT)); - refData.current.mergerCommitMessage = RepoUtils.generateMergeCommitMessage(hash)!; - const options = [hash,"--no-commit","--no-ff"]; - IpcUtils.merge(options).then((r)=>{ - GitUtils.getStatus().then(r=>{ - dispatch(ActionUI.setSelectedRepoTab(EnumSelectedRepoTab.CHANGES)); - if(r.conflicted?.length){ - dispatch(ActionChanges.updateData({selectedTab:EnumChangeGroup.CONFLICTED})); - } - else if(r.staged?.length){ - dispatch(ActionChanges.updateData({selectedTab:EnumChangeGroup.STAGED})); - } - }); - }); - } - - const cherryPick=()=>{ - dispatch(ActionModals.hideModal(EnumModals.COMMIT_CONTEXT)); - const options = [Data.selectedCommit.hash]; - IpcUtils.cherryPick(options).then(r=>{ - GitUtils.getStatus().then(r=>{ - if(r.conflicted?.length){ - dispatch(ActionUI.setSelectedRepoTab(EnumSelectedRepoTab.CHANGES)); - dispatch(ActionChanges.updateData({selectedTab:EnumChangeGroup.CONFLICTED})); - } - }); - }).catch(e=>{ - const message = e?.toString() || "Failed to perform cherry-pick."; - ModalData.errorModal.message = message; - dispatch(ActionModals.showModal(EnumModals.ERROR)); - }); - } - - const mergeBranch=(branch:string)=>{ - dispatch(ActionModals.hideModal(EnumModals.COMMIT_CONTEXT)); - refData.current.mergerCommitMessage = RepoUtils.generateMergeBranchMessage(branch)!; - const options = [branch,"--no-commit","--no-ff"]; - IpcUtils.merge(options).then(()=>{ - GitUtils.getStatus().then((r)=>{ - dispatch(ActionUI.setSelectedRepoTab(EnumSelectedRepoTab.CHANGES)); - if(r.conflicted?.length){ - dispatch(ActionChanges.updateData({selectedTab:EnumChangeGroup.CONFLICTED})); - } - else if(r.staged?.length){ - dispatch(ActionChanges.updateData({selectedTab:EnumChangeGroup.STAGED})); - } - }); - }) - } - - const rebaseBranch=(branch:string)=>{ - dispatch(ActionModals.hideModal(EnumModals.COMMIT_CONTEXT)); - IpcUtils.rebaseBranch(branch).then(_=>{ - GitUtils.getStatus(); - }).catch(e=>{ - ModalData.errorModal.message = e?.toString() || "Failed to rebase."; - dispatch(ActionModals.showModal(EnumModals.ERROR)); - }) - } - - useEffect(()=>{ - const modalOpenEventListener = ()=>{ - setState({position:Data.position}); - dispatch(ActionModals.showModal(EnumModals.COMMIT_CONTEXT)); - } - - GraphUtils.openContextModal = modalOpenEventListener; - - const mergeListener = (e:any,status:IStatus)=>{ - dispatch(ActionUI.setLoader()) - dispatch(ActionUI.setMergerCommitMessage(refData.current.mergerCommitMessage)); - if(status) { - ReduxUtils.setStatus(status); - dispatch(ActionUI.setSelectedRepoTab(EnumSelectedRepoTab.CHANGES)); - } - } - - window.ipcRenderer.on(RendererEvents.gitMerge().replyChannel,mergeListener) - document.addEventListener("click",(e)=>{ - if(refData.current.show && !refData.current.onHover){ - hideModal(); - } - }) - return ()=>{ - UiUtils.removeIpcListeners([ - RendererEvents.gitMerge().replyChannel, - ],[mergeListener]); - } - - },[]) - - const referredLocalBranches = useMemo(()=>{ - if(!store.show || !Data.selectedCommit?.refValues.length) - return []; - const branchList = RepoUtils.repositoryDetails.branchList; - const referredBranches = Data.selectedCommit.refValues.filter(_=> branchList.includes(_)); - return referredBranches; - },[store.show,Data.selectedCommit]) - - const branchNamesForCheckout = useMemo(()=>{ - if(!store.show || !Data.selectedCommit?.refValues.length) - return []; - const branches = referredLocalBranches.slice(); - for(let ref of Data.selectedCommit.refValues){ - if(!RepoUtils.isOriginBranch(ref) || RepoUtils.hasLocalBranch(ref)) - continue; - const localBranch = RepoUtils.getLocalBranch(ref); - if(localBranch) - branches.push(localBranch); - } - return branches; - },[referredLocalBranches,store.show,Data.selectedCommit]) - - const branchNamesForDelete = useMemo(()=>{ - if(!store.show || !Data.selectedCommit?.refValues.length) - return []; - const branches = referredLocalBranches.slice(); - return branches; - },[referredLocalBranches,store.show,Data.selectedCommit]) - - const softReset=()=>{ - hideModal(); - const options:string[]=["--soft","HEAD~1"]; - IpcUtils.reset(options).then(r=>{ - GitUtils.getStatus(); - }) - } - - const hardReset=()=>{ - hideModal(); - const handler = ()=>{ - const options:string[]=["--hard","HEAD~1"]; - IpcUtils.reset(options).then(r=>{ - GitUtils.getStatus(); - }) - } - ModalData.confirmationModal.YesHandler = handler; - ModalData.confirmationModal.message = `Hard reset ${Data.selectedCommit.avrebHash}?`; - dispatch(ActionModals.showModal(EnumModals.CONFIRMATION)); - } - - const deleteBranch=(branchName:string)=>{ - hideModal(); - const handler = ()=>{ - IpcUtils.getRaw(["branch","-D",branchName]).then(r=>{ - if(r.result){ - dispatch(ActionUI.increamentVersion("branchPanelRefresh")); - } - }) - } - ModalData.confirmationModal.YesHandler = handler; - ModalData.confirmationModal.message = `Delete local branch '${branchName}'?`; - dispatch(ActionModals.showModal(EnumModals.CONFIRMATION)); - } - - const moreOptionList = useMemo(()=>{ - const options:Option[] = []; - if(!store.show) - return options; - if(!Data.selectedCommit?.nextCommit && Data.selectedCommit?.isHead){ - options.push(Option.HardReset,Option.SoftReset); - } - if(branchNamesForDelete.length){ - options.push(Option.DeleteBranch); - } - return options; - },[store.show,Data.selectedCommit]) - - const optionClasses = "border-bottom context-option"; - - return ( - hideModal()}> - {refData.current.onHover = true}} onMouseLeave={()=>{refData.current.onHover = false}}> -
setState({mouseOver:undefined})}> - { - branchNamesForCheckout.length > 0 &&
-
- { - branchNamesForCheckout.length > 1 ?
-
setState(({mouseOver:Option.Checkout}))}> - Checkout branch - > -
- - {(state.mouseOver === Option.Checkout) &&
- { - branchNamesForCheckout.map((br=>( -
- checkOutCommit(br)}>{br} -
- ))) - } -
} -
: -
checkOutCommit(branchNamesForCheckout[0])}>Checkout branch '{branchNamesForCheckout[0]}'
- } -
-
- } - -
setState(({mouseOver:null!}))}> -
checkOutCommit(Data.selectedCommit.hash)}>Checkout this commit
-
-
setState(({mouseOver:null!}))}> -
- Create branch from this commit -
-
- { - !Data.selectedCommit?.isHead && referredLocalBranches.length > 0 && -
- { - referredLocalBranches.length > 1 ?
-
setState(({mouseOver:Option.Merge}))}> - Merge branch - > -
- - {(state.mouseOver === Option.Merge) &&
- { - referredLocalBranches.map((br=>( -
- mergeBranch(br)}>{br} -
- ))) - } -
} -
: -
mergeBranch(referredLocalBranches[0])}>Merge branch '{referredLocalBranches[0]}'
- } -
- } - {!Data.selectedCommit?.isHead &&
setState(({mouseOver:null!}))}> -
mergeCommit(Data.selectedCommit?.hash)}>Merge this commit
-
} - - { - !Data.selectedCommit?.isHead && referredLocalBranches.length > 0 && -
- { - referredLocalBranches.length > 1 ?
-
setState(({mouseOver:Option.Merge}))}> - Rebase branch - > -
- - {(state.mouseOver === Option.Rebase) &&
- { - referredLocalBranches.map((br=>( -
- rebaseBranch(br)}>{br} -
- ))) - } -
} -
: -
rebaseBranch(referredLocalBranches[0])}>Rebase branch '{referredLocalBranches[0]}'
- } -
- } - - {!Data.selectedCommit?.isHead &&
setState(({mouseOver:null!}))}> -
- Cherry-Pick this commit -
-
} - {!!moreOptionList.length && !state.showMore &&
setState(({mouseOver:null!}))} - onClick={_=> setState({showMore:true})}> -
Show More
-
} - { - state.showMore && - {moreOptionList.includes(Option.SoftReset) &&
setState(({mouseOver:null!}))}> -
Soft reset this commit
-
} - {moreOptionList.includes(Option.HardReset) &&
setState(({mouseOver:null!}))}> -
Hard reset this commit
-
} - { - moreOptionList.includes(Option.DeleteBranch) && -
- { - branchNamesForDelete.length > 1 ?
-
setState(({mouseOver:Option.DeleteBranch}))}> - Delete branch - > -
- - {(state.mouseOver === Option.DeleteBranch) &&
- { - branchNamesForDelete.map((br=>( -
- deleteBranch(br)}>{br} -
- ))) - } -
} -
: -
deleteBranch(branchNamesForDelete[0])}>Delete branch '{branchNamesForDelete[0]}'
- } -
- } - -
- } - -
-
-
- ) -} - -export const CommitContextModal = React.memo(CommitContextModalComponent); \ No newline at end of file diff --git a/frontend/src/components/selectedRepository/SelectedRepository.tsx b/frontend/src/components/selectedRepository/SelectedRepository.tsx index 30f171b8..b2eab563 100644 --- a/frontend/src/components/selectedRepository/SelectedRepository.tsx +++ b/frontend/src/components/selectedRepository/SelectedRepository.tsx @@ -65,7 +65,7 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ RepoUtils.repositoryDetails.status = status; } CacheUtils.setRepoDetails(RepoUtils.repositoryDetails); - } + } useEffect(()=>{ ReduxUtils.setStatus = (status:IStatus)=>{ @@ -78,6 +78,12 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ window.ipcRenderer.on(RendererEvents.getStatus().replyChannel,(e,res:IStatus)=>{ ReduxUtils.setStatus(res); }) + + const handleGraphFilterChange=()=>{ + dispatch(ActionUI.increamentVersion("branchPanelRefresh")); + } + + GraphUtils.state.filter.subscribe(handleGraphFilterChange); return ()=>{ ReduxUtils.setStatus = ()=>{}; @@ -85,6 +91,7 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ RendererEvents.getStatus().replyChannel, ]); dispatch(ActionUI.setStatus(undefined!)); + GraphUtils.state.filter.unSubscribe(handleGraphFilterChange); } },[]); @@ -92,7 +99,7 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ if(!store.status || !RepoUtils.repositoryDetails) return; GraphUtils.isRequiredReload().then(requiredReload => { - if(requiredReload) dispatch(ActionUI.increamentVersion("branchPanelRefresh")); + if(requiredReload) GraphUtils.refreshGraph(); else GraphUtils.checkForUiUpdate(store.status!); }); diff --git a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx index 4c5df0d0..939a32e5 100644 --- a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx +++ b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx @@ -3,8 +3,6 @@ import { FaHome, FaMinus, FaPlus, FaSyncAlt } from "react-icons/fa"; import { useDispatch } from "react-redux"; import { GraphUtils } from "../../../../lib/utils/GraphUtils"; import { ActionUI } from "../../../../store/slices/UiSlice"; -import { RepoUtils } from "../../../../lib"; -import { Messages } from "../../../../lib/constants"; function BranchActionsComponent(){ const dispatch = useDispatch(); diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index 5a5685ff..6061191f 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -33,9 +33,6 @@ interface IState{ viewBoxWidth:PbViewBoxWidth; viewBoxHeight:PbViewBoxHeight; verticalScrollHeight:PbVerticalScrollHeight; - fromDate:Publisher; - toDate:Publisher; - limit:Publisher; filter:PbCommitFilter; } @@ -67,9 +64,7 @@ export class GraphUtils{ zoomLabel:new Publisher(1), horizontalScrollRatio:new Publisher(0), verticalScrollRatio:new Publisher(0), - fromDate: new Publisher(null), - toDate: new Publisher(new Date().toISOString()), - limit : new Publisher(400), + filter : new PbCommitFilter({limit:400,toDate: new Date().toISOString(),userModified:false}), } as IState; static resizeHandler = ()=>{ @@ -87,7 +82,6 @@ export class GraphUtils{ GraphUtils.state.viewBoxX = new PbViewBoxX(0); GraphUtils.state.viewBoxY = new PbViewBoxY(0); GraphUtils.state.viewBox = new PbViewBox({x:0,y:0,width:0,height:0}); - GraphUtils.state.filter = new PbCommitFilter(); } static createBranchPanel(){ @@ -378,11 +372,14 @@ export class GraphUtils{ if(newStatus.headCommit.hash !== GraphUtils.state.headCommit.value.hash) return true; const uiRefs = GraphUtils.state.headCommit.value.refValues; const newRefs = newStatus.headCommit.refValues; - if(newRefs.some(ref=> !uiRefs.includes(ref)) || newRefs.length !== uiRefs.length) return true; + if(newRefs.some(ref => !uiRefs.includes(ref)) || newRefs.length !== uiRefs.length) return true; } - - let commits = await IpcUtils.getCommitList({pageIndex:0,pageSize:50}); - for(let c of commits.list){ + let filter = GraphUtils.state.filter.value; + if(!filter.userModified){ + filter = {...filter,toDate:new Date().toISOString()}; + } + let commits = await IpcUtils.getGraphCommitList(filter); + for(let c of commits){ const existingCm = RepoUtils.repositoryDetails.allCommits.find(_=> _.hash === c.hash); if(!existingCm) return true; @@ -506,6 +503,10 @@ export class GraphUtils{ GraphUtils.state.headCommit.update(); } + static refreshGraph(){ + GraphUtils.state.filter.resetFilter(); + } + static checkForUiUpdate(newStatus:IStatus){ const existingStatus = RepoUtils.repositoryDetails?.status; if(newStatus.mergingCommitHash !== GraphUtils.state.mergingCommit.value?.parentHashes[1]){ diff --git a/frontend/src/lib/utils/IpcUtils.ts b/frontend/src/lib/utils/IpcUtils.ts index 950562f1..63a71160 100644 --- a/frontend/src/lib/utils/IpcUtils.ts +++ b/frontend/src/lib/utils/IpcUtils.ts @@ -1,8 +1,15 @@ import { Annotation, IActionTaken, ICommitFilter, ICommitInfo, ILogFilterOptions, IPaginated, IRemoteInfo, IRepositoryDetails, IStash, IStatus, ITypedConfig, IUserConfig, RendererEvents, RepositoryInfo } from "common_library"; import { RepoUtils } from "./RepoUtils"; import { IpcResult } from "../interfaces/IpcResult"; +import { PbCommitFilter } from "./branchGraphPublishers/PbCommitFilter"; export class IpcUtils{ + static async getGraphCommitList(filter: ICommitFilter) { + const r = await IpcUtils.runGitCommand(RendererEvents.getGraphCommits,[filter]); + if(!r.error) + return r.result!; + return []; + } static updateUserEmail(value: string, isGlobal?:boolean) { return IpcUtils.runGitCommand(RendererEvents.updateUserEmail,[value,isGlobal]); } diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts index 2d1250f2..8afebfa9 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts @@ -1,23 +1,27 @@ import { ICommitFilter } from "common_library"; -import { DerivedPublisher } from "../../publishers"; +import { UiState } from "../../publishers"; import { GraphUtils } from "../GraphUtils"; -export class PbCommitFilter extends DerivedPublisher{ - constructor(){ - super(); - GraphUtils.state.fromDate.subscribe(this.update.bind(this)); - GraphUtils.state.toDate.subscribe(this.update.bind(this)); - GraphUtils.state.limit.subscribe(this.update.bind(this)); - this._val = this.getDerivedValue(); +export class PbCommitFilter extends UiState{ + constructor(filter:ICommitFilter){ + super(filter); } - protected getDerivedValue(): ICommitFilter { - const data = {} as ICommitFilter; - data.fromDate = GraphUtils.state.fromDate.value!; - data.toDate = GraphUtils.state.toDate.value; - data.limit = GraphUtils.state.limit.value; - return data; + protected applyChange(): void { + throw new Error("Method not implemented."); } + publishFilter(filter:Partial){ + this.publish({...this.value,...filter}); + } + + resetFilter(){ + const filter = {...this.value}; + if(!filter.userModified){ + filter.toDate = new Date().toISOString(); + } + + this.publishFilter(filter); + } } \ No newline at end of file diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts b/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts index 719ef540..b93971a8 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts @@ -15,7 +15,7 @@ export class PbHeadCommit extends DerivedState{ } if(!this.prevValue) return; - const prevHeadElem = GraphUtils.svgContainer.querySelector(`#${EnumIdPrefix.COMMIT_TEXT}${GraphUtils.state.headCommit.prevValue!.hash}`); + const prevHeadElem = GraphUtils.svgContainer.querySelector(`#${EnumIdPrefix.COMMIT_TEXT}${this.prevValue!.hash}`); prevHeadElem?.classList.add("d-none"); } diff --git a/src/businessClasses/GitManager.ts b/src/businessClasses/GitManager.ts index ec65c7cc..d0075b70 100644 --- a/src/businessClasses/GitManager.ts +++ b/src/businessClasses/GitManager.ts @@ -51,6 +51,7 @@ export class GitManager{ this.addGitUserConfigHandler(); this.addUserNameUpdateHandler(); this.addUserEmailUpdateHandler(); + this.addGraphCommitListHandler(); } @@ -285,6 +286,14 @@ export class GitManager{ }); } + private addGraphCommitListHandler(){ + ipcMain.handle(RendererEvents.getGraphCommits, async (e,repoPath:string,filter:ICommitFilter)=>{ + const git = this.getGitRunner(repoPath); + const list = await this.getCommits(git,filter); + return list; + }); + } + private addLogHandler(){ ipcMain.handle(RendererEvents.gitLog, async (e,repoInfo:RepositoryInfo,filterOptions:ILogFilterOptions)=>{ const repoDetails = await this.getFilteredCommits(repoInfo,filterOptions); From f5e7751941d3696ecd6cd6b8927ac9139e13e31e Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sun, 18 Aug 2024 01:16:43 +0600 Subject: [PATCH 11/21] implement method --- .../selectedRepository/SelectedRepository.tsx | 11 +++++------ frontend/src/lib/utils/ReduxUtils.ts | 1 + .../lib/utils/branchGraphPublishers/PbCommitFilter.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/selectedRepository/SelectedRepository.tsx b/frontend/src/components/selectedRepository/SelectedRepository.tsx index b2eab563..6915cfac 100644 --- a/frontend/src/components/selectedRepository/SelectedRepository.tsx +++ b/frontend/src/components/selectedRepository/SelectedRepository.tsx @@ -37,6 +37,10 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ const {currentMousePosition:position,elementRef:resizer} = useDrag(); const dispatch = useDispatch(); + ReduxUtils.refreshGraph = ()=>{ + dispatch(ActionUI.increamentVersion("branchPanelRefresh")); + } + const getRepoDetails = async ()=>{ const filter = GraphUtils.state.filter.value; return IpcUtils.getRepoDetails(props.repo,filter).then(r=>{ @@ -79,11 +83,7 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ ReduxUtils.setStatus(res); }) - const handleGraphFilterChange=()=>{ - dispatch(ActionUI.increamentVersion("branchPanelRefresh")); - } - - GraphUtils.state.filter.subscribe(handleGraphFilterChange); + return ()=>{ ReduxUtils.setStatus = ()=>{}; @@ -91,7 +91,6 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ RendererEvents.getStatus().replyChannel, ]); dispatch(ActionUI.setStatus(undefined!)); - GraphUtils.state.filter.unSubscribe(handleGraphFilterChange); } },[]); diff --git a/frontend/src/lib/utils/ReduxUtils.ts b/frontend/src/lib/utils/ReduxUtils.ts index 22a4bcc0..3d40eefc 100644 --- a/frontend/src/lib/utils/ReduxUtils.ts +++ b/frontend/src/lib/utils/ReduxUtils.ts @@ -5,4 +5,5 @@ export class ReduxUtils{ static setStatus=(status:IStatus)=>{}; static setLoader=(payload:ILoaderInfo|undefined)=>{}; static dispatch:any = null; + static refreshGraph=() => {}; } \ No newline at end of file diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts index 8afebfa9..5cce1856 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts @@ -1,6 +1,6 @@ import { ICommitFilter } from "common_library"; import { UiState } from "../../publishers"; -import { GraphUtils } from "../GraphUtils"; +import { ReduxUtils } from "../ReduxUtils"; export class PbCommitFilter extends UiState{ @@ -9,7 +9,7 @@ export class PbCommitFilter extends UiState{ } protected applyChange(): void { - throw new Error("Method not implemented."); + ReduxUtils.refreshGraph(); } publishFilter(filter:Partial){ From 31ac946ae0d7e96bb3648aefc18878991b580e9e Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sun, 18 Aug 2024 02:32:23 +0600 Subject: [PATCH 12/21] refactor graph refresh process --- frontend/src/components/main/Main.tsx | 4 ++-- frontend/src/components/modals/CheckoutBranchModal.tsx | 4 ++-- frontend/src/components/modals/commitContext/MoreOptions.tsx | 4 ++-- .../selectedRepoRight/branches/BranchActions.tsx | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/main/Main.tsx b/frontend/src/components/main/Main.tsx index e02f16bd..a6a12efa 100644 --- a/frontend/src/components/main/Main.tsx +++ b/frontend/src/components/main/Main.tsx @@ -2,7 +2,7 @@ import { ISavedData, RendererEvents } from "common_library"; import React from "react"; import { useEffect } from "react"; import {useDispatch,shallowEqual, batch} from "react-redux"; -import { DataUtils, EnumModals, FetchState, ReduxUtils, UiUtils, useMultiState } from "../../lib"; +import { DataUtils, EnumModals, FetchState, GraphUtils, ReduxUtils, UiUtils, useMultiState } from "../../lib"; import { useSelectorTyped } from "../../store/rootReducer"; import { ActionModals, ActionSavedData } from "../../store/slices"; import { ActionUI, EnumHomePageTab, ILoaderInfo } from "../../store/slices/UiSlice"; @@ -71,7 +71,7 @@ function MainComponent(){ window.ipcRenderer.on(RendererEvents.refreshBranchPanel().channel,()=>{ dispatch(ActionUI.setSync({text:"Refreshing..."})); - dispatch(ActionUI.increamentVersion("branchPanelRefresh")); + GraphUtils.state.filter.resetFilter(); }) window.ipcRenderer.on(RendererEvents.cloneProgress,(_e,progress:number,stage:FetchState)=>{ diff --git a/frontend/src/components/modals/CheckoutBranchModal.tsx b/frontend/src/components/modals/CheckoutBranchModal.tsx index ac7ae336..f7ecf061 100644 --- a/frontend/src/components/modals/CheckoutBranchModal.tsx +++ b/frontend/src/components/modals/CheckoutBranchModal.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useRef } from "react" import { Form, Modal } from "react-bootstrap"; import { useDispatch, shallowEqual } from "react-redux"; -import { EnumModals, RepoUtils, useMultiState } from "../../lib"; +import { EnumModals, GraphUtils, RepoUtils, useMultiState } from "../../lib"; import { ActionModals } from "../../store"; import { useSelectorTyped } from "../../store/rootReducer"; import { AppButton } from "../common"; @@ -85,7 +85,7 @@ function CheckoutBranchModalComponent(){ return; const options = [state.searchText]; IpcUtils.checkout(options).then(()=>{ - dispatch(ActionUI.increamentVersion("branchPanelRefresh")) + GraphUtils.state.filter.resetFilter(); }); hideModal(); } diff --git a/frontend/src/components/modals/commitContext/MoreOptions.tsx b/frontend/src/components/modals/commitContext/MoreOptions.tsx index bdb6ab94..841a8807 100644 --- a/frontend/src/components/modals/commitContext/MoreOptions.tsx +++ b/frontend/src/components/modals/commitContext/MoreOptions.tsx @@ -5,7 +5,7 @@ import { GitUtils } from "../../../lib/utils/GitUtils"; import { ModalData } from "../ModalData"; import { useSelectorTyped } from "../../../store/rootReducer"; import { shallowEqual, useDispatch } from "react-redux"; -import { EnumModals } from "../../../lib"; +import { EnumModals, GraphUtils } from "../../../lib"; import { ActionModals } from "../../../store"; import { ActionUI } from "../../../store/slices/UiSlice"; interface IProps extends IBaseProps{ @@ -54,7 +54,7 @@ function MoreOptionsComponent(props:IProps){ const handler = ()=>{ IpcUtils.getRaw(["branch","-D",branchName]).then(r=>{ if(r.result){ - dispatch(ActionUI.increamentVersion("branchPanelRefresh")); + GraphUtils.state.filter.resetFilter(); } }) } diff --git a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx index 939a32e5..0ce0c052 100644 --- a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx +++ b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx @@ -9,7 +9,7 @@ function BranchActionsComponent(){ const handleRefresh = ()=>{ dispatch(ActionUI.setGraphRefresh(true)); - dispatch(ActionUI.increamentVersion("branchPanelRefresh")); + GraphUtils.state.filter.resetFilter(); } return
From f73671e4999177b9bb328dce3d5bb18c84ddf791 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sun, 18 Aug 2024 03:30:04 +0600 Subject: [PATCH 13/21] refactor refresh logic. --- frontend/src/components/main/Main.tsx | 2 +- .../src/components/modals/CheckoutBranchModal.tsx | 2 +- .../components/modals/commitContext/MoreOptions.tsx | 2 +- .../selectedRepository/SelectedRepository.tsx | 13 +++++-------- .../selectedRepoRight/branches/BranchActions.tsx | 2 +- frontend/src/lib/utils/GraphUtils.ts | 6 +++++- .../utils/branchGraphPublishers/PbCommitFilter.ts | 10 +--------- 7 files changed, 15 insertions(+), 22 deletions(-) diff --git a/frontend/src/components/main/Main.tsx b/frontend/src/components/main/Main.tsx index a6a12efa..6ffed407 100644 --- a/frontend/src/components/main/Main.tsx +++ b/frontend/src/components/main/Main.tsx @@ -71,7 +71,7 @@ function MainComponent(){ window.ipcRenderer.on(RendererEvents.refreshBranchPanel().channel,()=>{ dispatch(ActionUI.setSync({text:"Refreshing..."})); - GraphUtils.state.filter.resetFilter(); + GraphUtils.refreshGraph(); }) window.ipcRenderer.on(RendererEvents.cloneProgress,(_e,progress:number,stage:FetchState)=>{ diff --git a/frontend/src/components/modals/CheckoutBranchModal.tsx b/frontend/src/components/modals/CheckoutBranchModal.tsx index f7ecf061..69af42ab 100644 --- a/frontend/src/components/modals/CheckoutBranchModal.tsx +++ b/frontend/src/components/modals/CheckoutBranchModal.tsx @@ -85,7 +85,7 @@ function CheckoutBranchModalComponent(){ return; const options = [state.searchText]; IpcUtils.checkout(options).then(()=>{ - GraphUtils.state.filter.resetFilter(); + GraphUtils.refreshGraph(); }); hideModal(); } diff --git a/frontend/src/components/modals/commitContext/MoreOptions.tsx b/frontend/src/components/modals/commitContext/MoreOptions.tsx index 841a8807..c51e6c2a 100644 --- a/frontend/src/components/modals/commitContext/MoreOptions.tsx +++ b/frontend/src/components/modals/commitContext/MoreOptions.tsx @@ -54,7 +54,7 @@ function MoreOptionsComponent(props:IProps){ const handler = ()=>{ IpcUtils.getRaw(["branch","-D",branchName]).then(r=>{ if(r.result){ - GraphUtils.state.filter.resetFilter(); + GraphUtils.refreshGraph(); } }) } diff --git a/frontend/src/components/selectedRepository/SelectedRepository.tsx b/frontend/src/components/selectedRepository/SelectedRepository.tsx index 6915cfac..0bd7a640 100644 --- a/frontend/src/components/selectedRepository/SelectedRepository.tsx +++ b/frontend/src/components/selectedRepository/SelectedRepository.tsx @@ -3,14 +3,12 @@ import { RepoUtils, CacheUtils, ObjectUtils, ReduxUtils, UiUtils, useDrag, useMu import { SelectedRepoLeft } from "./SelectedRepoLeft"; import { SelectedRepoRight } from "./selectedRepoRight/SelectedRepoRight"; import './SelectedRepository.scss'; -import { IRepositoryDetails, IStatus, RendererEvents, RepositoryInfo } from "common_library"; +import { IStatus, RendererEvents, RepositoryInfo } from "common_library"; import { useSelectorTyped } from "../../store/rootReducer"; import { shallowEqual, useDispatch } from "react-redux"; import { GraphUtils } from "../../lib/utils/GraphUtils"; import { ActionUI } from "../../store/slices/UiSlice"; import { IpcUtils } from "../../lib/utils/IpcUtils"; -import { ChangeUtils } from "../../lib/utils/ChangeUtils"; -import { ActionSavedData } from "../../store"; import { Messages } from "../../lib/constants"; import { GitUtils } from "../../lib/utils/GitUtils"; @@ -168,11 +166,10 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ useEffect(()=>{ refData.current.repo = props.repo; - updateRepoData().then(_=>{ - GraphUtils.createBranchPanel(); - ReduxUtils.setStatus(RepoUtils.repositoryDetails.status); - dispatch(ActionUI.setRemotes(new ObjectUtils().deepClone(RepoUtils.repositoryDetails.remotes))); - dispatch(ActionUI.setBranchList(RepoUtils.repositoryDetails.branchList.slice())); + GraphUtils.state.filter.publishFilter({ + userModified:false, + toDate:new Date().toISOString(), + limit:GraphUtils.state.filter.defaultLimit, }); },[props.repo]); diff --git a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx index 0ce0c052..2d2917d5 100644 --- a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx +++ b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchActions.tsx @@ -9,7 +9,7 @@ function BranchActionsComponent(){ const handleRefresh = ()=>{ dispatch(ActionUI.setGraphRefresh(true)); - GraphUtils.state.filter.resetFilter(); + GraphUtils.refreshGraph(); } return
diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index 6061191f..672baa93 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -504,7 +504,11 @@ export class GraphUtils{ } static refreshGraph(){ - GraphUtils.state.filter.resetFilter(); + const filter = {...GraphUtils.state.filter.value}; + if(!filter.userModified){ + filter.toDate = new Date().toISOString(); + } + GraphUtils.state.filter.publishFilter(filter); } static checkForUiUpdate(newStatus:IStatus){ diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts index 5cce1856..938f5d65 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts @@ -4,6 +4,7 @@ import { ReduxUtils } from "../ReduxUtils"; export class PbCommitFilter extends UiState{ + readonly defaultLimit = 400; constructor(filter:ICommitFilter){ super(filter); } @@ -15,13 +16,4 @@ export class PbCommitFilter extends UiState{ publishFilter(filter:Partial){ this.publish({...this.value,...filter}); } - - resetFilter(){ - const filter = {...this.value}; - if(!filter.userModified){ - filter.toDate = new Date().toISOString(); - } - - this.publishFilter(filter); - } } \ No newline at end of file From bc582134a440ff6da58058c87c870e30245f9ef5 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Mon, 19 Aug 2024 21:49:28 +0600 Subject: [PATCH 14/21] prevent load data on repo switch --- .../selectedRepository/SelectedRepository.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/selectedRepository/SelectedRepository.tsx b/frontend/src/components/selectedRepository/SelectedRepository.tsx index 0bd7a640..25e8c205 100644 --- a/frontend/src/components/selectedRepository/SelectedRepository.tsx +++ b/frontend/src/components/selectedRepository/SelectedRepository.tsx @@ -40,6 +40,7 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ } const getRepoDetails = async ()=>{ + console.log("Getting repository details."); const filter = GraphUtils.state.filter.value; return IpcUtils.getRepoDetails(props.repo,filter).then(r=>{ if(!r.error) @@ -102,10 +103,8 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ },[store.status]); - useEffect(()=>{ - if(!store.branchPanelRefreshVersion) return; - dispatch(ActionUI.setSync({text:Messages.refreshing})); - updateRepoData(true).then(()=>{ + const updateGraph=(reloadData = false)=>{ + return updateRepoData(reloadData).then(()=>{ GraphUtils.createBranchPanel(); dispatch(ActionUI.setLoader(undefined)); dispatch(ActionUI.setSync(undefined)); @@ -114,6 +113,12 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ dispatch(ActionUI.setBranchList(RepoUtils.repositoryDetails.branchList.slice())); dispatch(ActionUI.setGraphRefresh(false)); }); + } + + useEffect(()=>{ + if(!store.branchPanelRefreshVersion) return; + dispatch(ActionUI.setSync({text:Messages.refreshing})); + updateGraph(true); },[store.branchPanelRefreshVersion]); useEffect(()=>{ @@ -166,11 +171,7 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ useEffect(()=>{ refData.current.repo = props.repo; - GraphUtils.state.filter.publishFilter({ - userModified:false, - toDate:new Date().toISOString(), - limit:GraphUtils.state.filter.defaultLimit, - }); + updateGraph(); },[props.repo]); return
From b0b3d94f4f2a519854e773357e540fc792b2856c Mon Sep 17 00:00:00 2001 From: tulshi das Date: Mon, 19 Aug 2024 23:41:07 +0600 Subject: [PATCH 15/21] handle null head. --- .../src/models/IRepositoryDetails.ts | 2 +- .../branches/BranchesView.tsx | 2 +- .../selectedRepoRight/changes/CommitBox.tsx | 4 +- frontend/src/lib/utils/GitUtils.ts | 6 +- frontend/src/lib/utils/GraphUtils.ts | 86 +++++++++++-------- frontend/src/lib/utils/IpcUtils.ts | 16 +++- frontend/src/lib/utils/RepoUtils.ts | 44 +++++----- .../branchGraphPublishers/PbMergeCommit.ts | 2 + .../branchGraphPublishers/PbSelectedCommit.ts | 4 +- 9 files changed, 98 insertions(+), 68 deletions(-) diff --git a/common_library/src/models/IRepositoryDetails.ts b/common_library/src/models/IRepositoryDetails.ts index 97b4d73c..8a26de87 100644 --- a/common_library/src/models/IRepositoryDetails.ts +++ b/common_library/src/models/IRepositoryDetails.ts @@ -10,7 +10,7 @@ export interface IRepositoryDetails{ remotes:IRemoteInfo[]; branchTree:IBranchDetails[]; resolvedBranches:IBranchDetails[]; - headCommit:ICommitInfo; + headCommit?:ICommitInfo; mergeCommitMessages:string[]; sourceCommits:ICommitInfo[]; repoInfo:RepositoryInfo; diff --git a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchesView.tsx b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchesView.tsx index 120ca27d..0c9fe0a9 100644 --- a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchesView.tsx +++ b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchesView.tsx @@ -45,7 +45,7 @@ function BranchesViewComponent() { },[position?.y]) useEffect(()=>{ - const selectListener = (commit:ICommitInfo)=>{ + const selectListener = (commit?:ICommitInfo)=>{ setState({selectedCommit:commit}); } GraphUtils.state.selectedCommit.subscribe(selectListener); diff --git a/frontend/src/components/selectedRepository/selectedRepoRight/changes/CommitBox.tsx b/frontend/src/components/selectedRepository/selectedRepoRight/changes/CommitBox.tsx index 79b3e334..cb114f94 100644 --- a/frontend/src/components/selectedRepository/selectedRepoRight/changes/CommitBox.tsx +++ b/frontend/src/components/selectedRepository/selectedRepoRight/changes/CommitBox.tsx @@ -81,7 +81,9 @@ function CommitBoxComponent(){ useEffect(()=>{ if(!state.amend || !!state.value) return; - const headCommit = RepoUtils.repositoryDetails.headCommit; + const headCommit = RepoUtils.repositoryDetails.status.headCommit; + if(!headCommit) + return ; let msg = headCommit.message; if(headCommit.body){ msg += `\n${headCommit.body}`; diff --git a/frontend/src/lib/utils/GitUtils.ts b/frontend/src/lib/utils/GitUtils.ts index 3cf90722..3029d643 100644 --- a/frontend/src/lib/utils/GitUtils.ts +++ b/frontend/src/lib/utils/GitUtils.ts @@ -165,7 +165,11 @@ export class GitUtils{ } else{ const origin = RepoUtils.activeOriginName; - options.push(origin, RepoUtils.repositoryDetails.headCommit.ownerBranch.name); + options.push(origin); + const brName = RepoUtils.repositoryDetails.status.headCommit?.ownerBranch.name; + if(brName){ + options.push(brName); + } } ReduxUtils.dispatch(ActionUI.setLoader({text:Messages.fetch})); return IpcUtils.fetch(options).then(r=>{ diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index 672baa93..39d8e5ff 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -263,6 +263,8 @@ export class GraphUtils{ static updateUiForCheckout(){ if(!this.svgElement) return; const headCommit = RepoUtils.repositoryDetails.headCommit; + if(!headCommit) + return; if(RepoUtils.repositoryDetails.status.isDetached){ const commitElem = this.svgElement.querySelector(`#${EnumIdPrefix.COMMIT_CIRCLE}${headCommit.hash}`); const headTextElem = this.CreateHeadTextElement(headCommit); @@ -279,6 +281,8 @@ export class GraphUtils{ static revertUiOfExistingCheckout(){ if(!this.svgElement) return; const headCommit = RepoUtils.repositoryDetails.headCommit; + if(!headCommit) + return; const headCommitTextElem = this.svgElement.querySelector(`#${EnumIdPrefix.COMMIT_TEXT}${headCommit.hash}`); if(!headCommitTextElem) return; headCommitTextElem.classList.add("d-none"); @@ -299,46 +303,52 @@ export class GraphUtils{ const repoDetails = RepoUtils.repositoryDetails; this.revertUiOfExistingCheckout(); const existingHead = repoDetails.headCommit; - existingHead.isHead = false; - const newHeadCommit = repoDetails.allCommits.find(x=>x.hash === commit.hash); - if(!newHeadCommit) throw "New checkout commit not found"; - repoDetails.headCommit = newHeadCommit; - newHeadCommit.isHead = true; - - const existingStatus = repoDetails.status; - repoDetails.status = newStatus; - if(existingStatus.isDetached){ - existingHead.refValues = existingHead.refValues.filter(x=> x !== Constants.detachedHeadIdentifier); - if(existingHead.ownerBranch.increasedHeightForDetached > 0){ - existingHead.ownerBranch.maxRefCount -= existingHead.ownerBranch.increasedHeightForDetached; - existingHead.ownerBranch.increasedHeightForDetached = 0; - } - } + const newHeadCommit = repoDetails.allCommits.find(x=>x.hash === commit.hash); - const existingMaxRefLength = newHeadCommit.ownerBranch.maxRefCount; - - if(newStatus.isDetached){ - newHeadCommit.refs += `,${Constants.detachedHeadIdentifier}`; - newHeadCommit.refValues.push(`${Constants.detachedHeadIdentifier}`); - } - else{ - if(!RepoUtils.repositoryDetails.branchList.includes(newHeadCommit.ownerBranch.name)){ - newHeadCommit.refs = `${Constants.headPrefix}${newHeadCommit.ownerBranch.name},${newHeadCommit.refs}`; - newHeadCommit.refValues.push(`${newHeadCommit.ownerBranch.name}`); - newHeadCommit.branchNameWithRemotes.push({branchName:newHeadCommit.ownerBranch.name,remote:""}); + const existingStatus = repoDetails.status; + repoDetails.status = newStatus; + + if(existingHead){ + existingHead.isHead = false; + if(existingStatus.isDetached){ + existingHead.refValues = existingHead.refValues.filter(x=> x !== Constants.detachedHeadIdentifier); + if(existingHead.ownerBranch.increasedHeightForDetached > 0){ + existingHead.ownerBranch.maxRefCount -= existingHead.ownerBranch.increasedHeightForDetached; + existingHead.ownerBranch.increasedHeightForDetached = 0; + } } } - if(newHeadCommit.refValues.length > existingMaxRefLength){ - newHeadCommit.ownerBranch.increasedHeightForDetached = newHeadCommit.refValues.length - existingMaxRefLength; - newHeadCommit.ownerBranch.maxRefCount = newHeadCommit.refValues.length; - CacheUtils.setRepoDetails(RepoUtils.repositoryDetails); - GraphUtils.refreshBranchPanelUi(); + repoDetails.headCommit = newHeadCommit!; + + if(newHeadCommit){ + repoDetails.headCommit = newHeadCommit; + newHeadCommit.isHead = true; + const existingMaxRefLength = newHeadCommit.ownerBranch.maxRefCount; + + if(newStatus.isDetached){ + newHeadCommit.refs += `,${Constants.detachedHeadIdentifier}`; + newHeadCommit.refValues.push(`${Constants.detachedHeadIdentifier}`); + } + else{ + if(!RepoUtils.repositoryDetails.branchList.includes(newHeadCommit.ownerBranch.name)){ + newHeadCommit.refs = `${Constants.headPrefix}${newHeadCommit.ownerBranch.name},${newHeadCommit.refs}`; + newHeadCommit.refValues.push(`${newHeadCommit.ownerBranch.name}`); + newHeadCommit.branchNameWithRemotes.push({branchName:newHeadCommit.ownerBranch.name,remote:""}); + } + } + if(newHeadCommit.refValues.length > existingMaxRefLength){ + newHeadCommit.ownerBranch.increasedHeightForDetached = newHeadCommit.refValues.length - existingMaxRefLength; + newHeadCommit.ownerBranch.maxRefCount = newHeadCommit.refValues.length; + CacheUtils.setRepoDetails(RepoUtils.repositoryDetails); + GraphUtils.refreshBranchPanelUi(); + } + else { + CacheUtils.setRepoDetails(RepoUtils.repositoryDetails); + this.updateUiForCheckout(); + } } - else { - CacheUtils.setRepoDetails(RepoUtils.repositoryDetails); - this.updateUiForCheckout(); - } + } static refreshBranchPanelUi(){ @@ -452,7 +462,7 @@ export class GraphUtils{ const clickListener = (_e:MouseEvent)=>{ let existingSelectedCommitElem:HTMLElement|null; - if(GraphUtils.state.selectedCommit.value.hash) { + if(GraphUtils.state.selectedCommit.value?.hash) { existingSelectedCommitElem = GraphUtils.svgContainer.querySelector(`#${EnumIdPrefix.COMMIT_CIRCLE}${GraphUtils.state.selectedCommit.value.hash}`); existingSelectedCommitElem?.setAttribute("fill",GraphUtils.commitColor); } @@ -513,10 +523,10 @@ export class GraphUtils{ static checkForUiUpdate(newStatus:IStatus){ const existingStatus = RepoUtils.repositoryDetails?.status; - if(newStatus.mergingCommitHash !== GraphUtils.state.mergingCommit.value?.parentHashes[1]){ + const head = RepoUtils.repositoryDetails.headCommit; + if(!!head && newStatus.mergingCommitHash !== GraphUtils.state.mergingCommit.value?.parentHashes[1]){ existingStatus.mergingCommitHash = newStatus.mergingCommitHash; if(newStatus.mergingCommitHash){ - const head = RepoUtils.repositoryDetails.headCommit; const dummyCommit = CreateCommitInfoObj(); dummyCommit.hash = null!; dummyCommit.date = new Date().toISOString(); diff --git a/frontend/src/lib/utils/IpcUtils.ts b/frontend/src/lib/utils/IpcUtils.ts index 63a71160..8b875f00 100644 --- a/frontend/src/lib/utils/IpcUtils.ts +++ b/frontend/src/lib/utils/IpcUtils.ts @@ -80,8 +80,12 @@ export class IpcUtils{ static trigerPush(options?:string[]){ if(!options){ options = [RepoUtils.activeOriginName]; - if(!RepoUtils.repositoryDetails.status.trackingBranch) - options.push("-u",RepoUtils.repositoryDetails.headCommit.ownerBranch.name); + if(!RepoUtils.repositoryDetails.status.trackingBranch){ + const br = RepoUtils.repositoryDetails.headCommit?.ownerBranch.name; + if(br){ + options.push("-u",br); + } + } } return IpcUtils.runGitCommand(RendererEvents.push().channel,[options]) } @@ -89,8 +93,12 @@ export class IpcUtils{ static trigerPull(options?:string[]){ if(!options){ options = [RepoUtils.activeOriginName]; - if(!RepoUtils.repositoryDetails.status.trackingBranch) - options.push(RepoUtils.repositoryDetails.headCommit.ownerBranch.name); + if(!RepoUtils.repositoryDetails.status.trackingBranch){ + const br = RepoUtils.repositoryDetails.headCommit?.ownerBranch.name; + if(br){ + options.push(br); + } + } } return IpcUtils.runGitCommand(RendererEvents.pull().channel,[options]) } diff --git a/frontend/src/lib/utils/RepoUtils.ts b/frontend/src/lib/utils/RepoUtils.ts index c8d29588..f5ce21c6 100644 --- a/frontend/src/lib/utils/RepoUtils.ts +++ b/frontend/src/lib/utils/RepoUtils.ts @@ -406,35 +406,37 @@ export class RepoUtils{ } static handleCheckout(commit:ICommitInfo,repoDetails:IRepositoryDetails,newStatus:IStatus){ - const existingHead = repoDetails.headCommit; - existingHead.isHead = false; - const newHeadCommit = repoDetails.allCommits.find(x=>x.hash === commit.hash); - if(!newHeadCommit) throw "New checkout commit not found"; - repoDetails.headCommit = newHeadCommit; - newHeadCommit.isHead = true; + + const newHeadCommit = repoDetails.allCommits.find(x=>x.hash === commit.hash); const existingStatus = repoDetails.status; repoDetails.status = newStatus; - if(existingStatus.isDetached){ - existingHead.refValues = existingHead.refValues.filter(x=> x !== Constants.detachedHeadIdentifier); - if(existingHead.ownerBranch.increasedHeightForDetached > 0){ - existingHead.ownerBranch.maxRefCount -= existingHead.ownerBranch.increasedHeightForDetached; - existingHead.ownerBranch.increasedHeightForDetached = 0; - } + const existingHead = repoDetails.headCommit; + + if(existingHead){ + existingHead.isHead = false; + if(existingStatus.isDetached){ + existingHead.refValues = existingHead.refValues.filter(x=> x !== Constants.detachedHeadIdentifier); + if(existingHead.ownerBranch.increasedHeightForDetached > 0){ + existingHead.ownerBranch.maxRefCount -= existingHead.ownerBranch.increasedHeightForDetached; + existingHead.ownerBranch.increasedHeightForDetached = 0; + } + } } - const existingMaxRefLength = newHeadCommit.ownerBranch.maxRefCount; - - if(newStatus.isDetached){ - newHeadCommit.refValues.push(Constants.detachedHeadIdentifier); - if(newHeadCommit.refValues.length > existingMaxRefLength){ - newHeadCommit.ownerBranch.increasedHeightForDetached = newHeadCommit.refValues.length - existingMaxRefLength; - newHeadCommit.ownerBranch.maxRefCount = newHeadCommit.refValues.length; + if(newHeadCommit){ + repoDetails.headCommit = newHeadCommit; + newHeadCommit.isHead = true; + const existingMaxRefLength = newHeadCommit.ownerBranch.maxRefCount; + if(newStatus.isDetached){ + newHeadCommit.refValues.push(Constants.detachedHeadIdentifier); + if(newHeadCommit.refValues.length > existingMaxRefLength){ + newHeadCommit.ownerBranch.increasedHeightForDetached = newHeadCommit.refValues.length - existingMaxRefLength; + newHeadCommit.ownerBranch.maxRefCount = newHeadCommit.refValues.length; + } } } - - } diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbMergeCommit.ts b/frontend/src/lib/utils/branchGraphPublishers/PbMergeCommit.ts index 7b132431..a322bdeb 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbMergeCommit.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbMergeCommit.ts @@ -29,6 +29,8 @@ export class PbMergeCommit extends DerivedState{ private createMerginStategUi(){ if(!GraphUtils.state.mergingCommit.value)return; const head = RepoUtils.repositoryDetails.headCommit; + if(!head) + return; const allCommits = RepoUtils.repositoryDetails.allCommits; const endX = this.value!.x; const y = this.value!.ownerBranch.y; diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbSelectedCommit.ts b/frontend/src/lib/utils/branchGraphPublishers/PbSelectedCommit.ts index 9396efa6..ee0c3a28 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbSelectedCommit.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbSelectedCommit.ts @@ -4,7 +4,7 @@ import { RepoUtils } from "../RepoUtils"; import { GraphUtils } from "../GraphUtils"; import { EnumIdPrefix } from "../../enums"; -export class PbSelectedCommit extends UiState{ +export class PbSelectedCommit extends UiState{ protected applyChange(): void { this.resetPrevious(); this.highlight(); @@ -35,6 +35,8 @@ export class PbSelectedCommit extends UiState{ } focus(){ + if(!this.value) + return; const horizontalRatio = this.value.x/RepoUtils.repositoryDetails.branchPanelWidth; const verticalRatio = this.value.ownerBranch.y/RepoUtils.repositoryDetails.branchPanelHeight; GraphUtils.state.horizontalScrollRatio.publish(horizontalRatio); From f364dbd91df69cb1ff238628aeac29dd6c8f13da Mon Sep 17 00:00:00 2001 From: tulshi das Date: Wed, 21 Aug 2024 00:54:14 +0600 Subject: [PATCH 16/21] load graph according to base date --- common_library/src/models/ICommitFilter.ts | 3 +- frontend/src/lib/utils/GraphUtils.ts | 14 ++-- .../branchGraphPublishers/PbCommitFilter.ts | 1 - src/businessClasses/GitManager.ts | 71 +++++++++++++++---- 4 files changed, 70 insertions(+), 19 deletions(-) diff --git a/common_library/src/models/ICommitFilter.ts b/common_library/src/models/ICommitFilter.ts index 0e8dc9b4..16ec7cf2 100644 --- a/common_library/src/models/ICommitFilter.ts +++ b/common_library/src/models/ICommitFilter.ts @@ -1,6 +1,7 @@ export interface ICommitFilter{ fromDate?:string; - toDate:string; + toDate?:string; + baseDate?:string; limit:number; userModified:boolean; } \ No newline at end of file diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index 39d8e5ff..cd882fea 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -52,6 +52,7 @@ export class GraphUtils{ static readonly svgLnk = "http://www.w3.org/2000/svg"; //static readonly scrollbarSize = 10; static readonly scrollBarSize = 10; + static readonly defaultLimit = 400; static openContextModal=()=>{}; @@ -385,9 +386,6 @@ export class GraphUtils{ if(newRefs.some(ref => !uiRefs.includes(ref)) || newRefs.length !== uiRefs.length) return true; } let filter = GraphUtils.state.filter.value; - if(!filter.userModified){ - filter = {...filter,toDate:new Date().toISOString()}; - } let commits = await IpcUtils.getGraphCommitList(filter); for(let c of commits){ const existingCm = RepoUtils.repositoryDetails.allCommits.find(_=> _.hash === c.hash); @@ -515,8 +513,14 @@ export class GraphUtils{ static refreshGraph(){ const filter = {...GraphUtils.state.filter.value}; - if(!filter.userModified){ - filter.toDate = new Date().toISOString(); + if(!filter.userModified){ + const head = RepoUtils.repositoryDetails.status.headCommit; + if(!head) + return; + filter.fromDate = undefined; + filter.toDate = undefined; + filter.baseDate = new Date(head.date).toISOString(); + filter.limit = GraphUtils.defaultLimit; } GraphUtils.state.filter.publishFilter(filter); } diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts index 938f5d65..41f38ecc 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbCommitFilter.ts @@ -4,7 +4,6 @@ import { ReduxUtils } from "../ReduxUtils"; export class PbCommitFilter extends UiState{ - readonly defaultLimit = 400; constructor(filter:ICommitFilter){ super(filter); } diff --git a/src/businessClasses/GitManager.ts b/src/businessClasses/GitManager.ts index d0075b70..cea1defb 100644 --- a/src/businessClasses/GitManager.ts +++ b/src/businessClasses/GitManager.ts @@ -289,7 +289,7 @@ export class GitManager{ private addGraphCommitListHandler(){ ipcMain.handle(RendererEvents.getGraphCommits, async (e,repoPath:string,filter:ICommitFilter)=>{ const git = this.getGitRunner(repoPath); - const list = await this.getCommits(git,filter); + const list = await this.getCommitsIteratively(git,filter); return list; }); } @@ -359,10 +359,10 @@ export class GitManager{ const repoDetails = CreateRepositoryDetails(); repoDetails.repoInfo = repoInfo; const git = this.getGitRunner(repoInfo); - const commits = await this.getCommits(git,filter); + repoDetails.status = await this.getStatus(repoInfo); + const commits = await this.getCommitsIteratively(git,filter); repoDetails.allCommits = commits; repoDetails.branchList = await this.getAllBranches(git); - repoDetails.status = await this.getStatus(repoInfo); this.setHead(repoDetails); const remotes = await git.getRemotes(true); remotes.forEach(r=>{ @@ -464,16 +464,70 @@ export class GitManager{ } private getFilterOptions(filter:ICommitFilter){ - const options = [`--before=${filter.toDate}`]; + const options = []; + if(filter.toDate){ + options.push(`--before=${filter.toDate}`); + } if(filter.fromDate){ options.push(`--after=${filter.fromDate}`); } - else{ + if(filter.limit){ options.push(`--max-count=${filter.limit}`); } return options; } + private async getCommitsIteratively(git: SimpleGit,filter:ICommitFilter){ + if(filter.fromDate || filter.toDate) + return await this.getCommits(git,filter); + + if(!filter.limit || !filter.baseDate) + throw "Limit or base date cannot be null."; + + const date = new Date(filter.baseDate!); + date.setSeconds(date.getSeconds()+1); + const toDateStr = date.toISOString(); + let newFilter:ICommitFilter = { + toDate:toDateStr, + limit:filter.limit, + userModified:false, + } + + let preCommits = await this.getCommits(git,newFilter); + let newLimit = filter.limit/2; + if(preCommits.length < filter.limit / 2){ + newLimit += (filter.limit / 2) - preCommits.length; + } + + newFilter = { + fromDate:filter.baseDate, + limit:newLimit, + userModified:false, + }; + + + let postCommits = await this.getCommits(git,newFilter); + const preLastCommitHash = preCommits[preCommits.length -1].hash; + const postStartIndex = postCommits.findIndex(_=> _.hash === preLastCommitHash) + 1; + postCommits = postCommits.slice(postStartIndex); + const total = preCommits.length + postCommits.length; + if(total > filter.limit){ + const extra = total - filter.limit; + if(preCommits.length > filter.limit / 2 ){ + preCommits = preCommits.slice(extra); + } + else if(postCommits.length > filter.limit / 2 ){ + postCommits = postCommits.slice(0, postCommits.length - extra); + } + } + + + const allCommits = [...preCommits,...postCommits.slice(postStartIndex)]; + + return allCommits; + + } + private async getCommits(git: SimpleGit,filter:ICommitFilter){ const commitLimit=500; //const LogFormat = "--pretty="+logFields.Hash+":%H%n"+LogFields.Abbrev_Hash+":%h%n"+LogFields.Parent_Hashes+":%p%n"+LogFields.Author_Name+":%an%n"+LogFields.Author_Email+":%ae%n"+LogFields.Date+":%ad%n"+LogFields.Ref+":%D%n"+LogFields.Message+":%s%n"; @@ -563,13 +617,6 @@ export class GitManager{ return result.all; } - private isDetachedCommit(commit:ICommitInfo,repoDetails:IRepositoryDetails){ - if(!commit.branchNameWithRemotes.length) return true; - if(commit.branchNameWithRemotes.some(br=>br.branchName === commit.ownerBranch.name && !br.remote)) return false; - if(repoDetails.branchList.includes(commit.ownerBranch.name)) return true; - return true; - } - private async checkoutCommit(repoPath:string,options:string[]){ const git = this.getGitRunner(repoPath); await git.checkout(options); From 70145d13f5ad08ece01ad7beab192a611d4ea7bf Mon Sep 17 00:00:00 2001 From: tulshi das Date: Thu, 22 Aug 2024 21:09:42 +0600 Subject: [PATCH 17/21] fix head state update issue --- frontend/src/lib/publishers/DerivedPublisher.ts | 5 ++++- frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/publishers/DerivedPublisher.ts b/frontend/src/lib/publishers/DerivedPublisher.ts index 486f2664..8bad5004 100644 --- a/frontend/src/lib/publishers/DerivedPublisher.ts +++ b/frontend/src/lib/publishers/DerivedPublisher.ts @@ -10,7 +10,10 @@ export abstract class DerivedPublisher extends Publisher{ protected abstract getDerivedValue():T; update(){ - this.value = this.getDerivedValue(); + const newValue = this.getDerivedValue(); + if(newValue == this.value) + return; + this.value = newValue; this.notifyAll(); } } \ No newline at end of file diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts b/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts index b93971a8..0652156d 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts @@ -5,8 +5,9 @@ import { RepoUtils } from "../RepoUtils"; import { EnumIdPrefix } from "../../enums"; export class PbHeadCommit extends DerivedState{ - protected getDerivedValue(): ICommitInfo | undefined { - return RepoUtils.repositoryDetails?.allCommits.find(_=>_.isHead); + protected getDerivedValue(): ICommitInfo | undefined { + const head = RepoUtils.repositoryDetails?.allCommits.find(_=>_.isHead); + return head; } protected applyChange(): void { if(this.value){ From cd470e8b532cdbb23a38df4cc3a000c581b11662 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sun, 1 Sep 2024 15:25:36 +0600 Subject: [PATCH 18/21] fix exception on checkout very old commit. --- common_library/src/models/ICommitFilter.ts | 3 +- .../branchGraphPublishers/PbHeadCommit.ts | 2 +- src/businessClasses/GitManager.ts | 31 ++++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/common_library/src/models/ICommitFilter.ts b/common_library/src/models/ICommitFilter.ts index 16ec7cf2..80015e20 100644 --- a/common_library/src/models/ICommitFilter.ts +++ b/common_library/src/models/ICommitFilter.ts @@ -2,6 +2,7 @@ export interface ICommitFilter{ fromDate?:string; toDate?:string; baseDate?:string; - limit:number; + limit?:number; userModified:boolean; + firstItems?:boolean; } \ No newline at end of file diff --git a/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts b/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts index 0652156d..9b2bbb95 100644 --- a/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts +++ b/frontend/src/lib/utils/branchGraphPublishers/PbHeadCommit.ts @@ -6,7 +6,7 @@ import { EnumIdPrefix } from "../../enums"; export class PbHeadCommit extends DerivedState{ protected getDerivedValue(): ICommitInfo | undefined { - const head = RepoUtils.repositoryDetails?.allCommits.find(_=>_.isHead); + const head = RepoUtils.repositoryDetails?.allCommits.find(_=>_.isHead); return head; } protected applyChange(): void { diff --git a/src/businessClasses/GitManager.ts b/src/businessClasses/GitManager.ts index cea1defb..3fdf39b6 100644 --- a/src/businessClasses/GitManager.ts +++ b/src/businessClasses/GitManager.ts @@ -1,15 +1,16 @@ -import { RendererEvents, RepositoryInfo ,CreateRepositoryDetails, IRemoteInfo,IStatus, ICommitInfo, IRepositoryDetails, IChanges, IFile, EnumChangeType, EnumChangeGroup, ILogFilterOptions, IPaginated, IGitCommandInfo, IActionTaken, IStash, IGitConfig, IUserConfig, ITypedConfig, ICommitFilter} from "common_library"; -import { ipcMain, ipcRenderer } from "electron"; +import { RendererEvents, RepositoryInfo ,CreateRepositoryDetails, IRemoteInfo,IStatus, ICommitInfo, IRepositoryDetails, IFile, EnumChangeType, EnumChangeGroup, ILogFilterOptions, IPaginated, IActionTaken, IStash, IUserConfig, ITypedConfig, ICommitFilter} from "common_library"; +import { ipcMain } from "electron"; import { existsSync, readdirSync } from "fs-extra"; -import simpleGit, { CleanOptions, FetchResult, PullResult, PushResult, SimpleGit, SimpleGitOptions, SimpleGitProgressEvent } from "simple-git"; -import { AppData, LogFields, SavedData } from "../dataClasses"; +import simpleGit, { CleanOptions, PullResult, PushResult, SimpleGit, SimpleGitOptions, SimpleGitProgressEvent } from "simple-git"; +import { AppData, LogFields } from "../dataClasses"; import { CommitParser } from "./CommitParser"; import * as path from 'path'; import { FileManager } from "./FileManager"; import { ConflictResolver } from "./ConflictResolver"; export class GitManager{ - private readonly logFields = LogFields.Fields(); + private readonly logFields = LogFields.Fields(); + private logLine = 10; private readonly LogFormat = "--pretty="+this.logFields.Hash+":%H%n"+this.logFields.Abbrev_Hash+":%h%n"+this.logFields.Parent_Hashes+":%p%n"+this.logFields.Author_Name+":%an%n"+this.logFields.Author_Email+":%ae%n"+this.logFields.Date+":%ad%n"+this.logFields.Message+":%s%n"+this.logFields.Body+":%b%n"+this.logFields.Ref+":%D%n"; start(){ this.addEventHandlers(); @@ -484,11 +485,8 @@ export class GitManager{ if(!filter.limit || !filter.baseDate) throw "Limit or base date cannot be null."; - const date = new Date(filter.baseDate!); - date.setSeconds(date.getSeconds()+1); - const toDateStr = date.toISOString(); let newFilter:ICommitFilter = { - toDate:toDateStr, + toDate:filter.baseDate!, limit:filter.limit, userModified:false, } @@ -499,16 +497,20 @@ export class GitManager{ newLimit += (filter.limit / 2) - preCommits.length; } + const toDate = new Date(filter.baseDate); + toDate.setMonth(toDate.getMonth()+5); + newFilter = { fromDate:filter.baseDate, - limit:newLimit, + toDate:toDate.toISOString(), userModified:false, + firstItems:true, }; let postCommits = await this.getCommits(git,newFilter); const preLastCommitHash = preCommits[preCommits.length -1].hash; - const postStartIndex = postCommits.findIndex(_=> _.hash === preLastCommitHash) + 1; + const postStartIndex = postCommits.findIndex(_ => _.hash === preLastCommitHash) + 1; postCommits = postCommits.slice(postStartIndex); const total = preCommits.length + postCommits.length; if(total > filter.limit){ @@ -522,22 +524,21 @@ export class GitManager{ } - const allCommits = [...preCommits,...postCommits.slice(postStartIndex)]; + const allCommits = [...preCommits,...postCommits]; return allCommits; } private async getCommits(git: SimpleGit,filter:ICommitFilter){ - const commitLimit=500; //const LogFormat = "--pretty="+logFields.Hash+":%H%n"+LogFields.Abbrev_Hash+":%h%n"+LogFields.Parent_Hashes+":%p%n"+LogFields.Author_Name+":%an%n"+LogFields.Author_Email+":%ae%n"+LogFields.Date+":%ad%n"+LogFields.Ref+":%D%n"+LogFields.Message+":%s%n"; try{ //--`--skip=${0*commitLimit}` const filterOptions = this.getFilterOptions(filter); - const options = ["log","--exclude=refs/stash", "--all",...filterOptions,"--date=iso-strict","--topo-order", this.LogFormat]; + const options = ["log","--exclude=refs/stash", "--all",...filterOptions,"--date=iso-strict","--topo-order", this.LogFormat]; let res = await git.raw(options); const commits = CommitParser.parse(res); - return commits; + return commits; }catch(e){ console.error("error on get logs:", e); } From 175ff9a25c8dcd23317e1a713e20dbcf2e7aa2d5 Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sun, 1 Sep 2024 17:41:22 +0600 Subject: [PATCH 19/21] fix reload checking issue. --- frontend/src/components/modals/CheckoutBranchModal.tsx | 6 +++--- .../components/selectedRepository/SelectedRepository.tsx | 2 +- frontend/src/lib/utils/GraphUtils.ts | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/modals/CheckoutBranchModal.tsx b/frontend/src/components/modals/CheckoutBranchModal.tsx index 69af42ab..f445e498 100644 --- a/frontend/src/components/modals/CheckoutBranchModal.tsx +++ b/frontend/src/components/modals/CheckoutBranchModal.tsx @@ -1,13 +1,13 @@ import React, { useEffect, useRef } from "react" import { Form, Modal } from "react-bootstrap"; import { useDispatch, shallowEqual } from "react-redux"; -import { EnumModals, GraphUtils, RepoUtils, useMultiState } from "../../lib"; +import { EnumModals, RepoUtils, useMultiState } from "../../lib"; import { ActionModals } from "../../store"; import { useSelectorTyped } from "../../store/rootReducer"; import { AppButton } from "../common"; import { IpcUtils } from "../../lib/utils/IpcUtils"; -import { ActionUI } from "../../store/slices/UiSlice"; import { FaTimes } from "react-icons/fa"; +import { GitUtils } from "../../lib/utils/GitUtils"; interface IState{ options:string[]; @@ -85,7 +85,7 @@ function CheckoutBranchModalComponent(){ return; const options = [state.searchText]; IpcUtils.checkout(options).then(()=>{ - GraphUtils.refreshGraph(); + GitUtils.getStatus(); }); hideModal(); } diff --git a/frontend/src/components/selectedRepository/SelectedRepository.tsx b/frontend/src/components/selectedRepository/SelectedRepository.tsx index 25e8c205..32bba14d 100644 --- a/frontend/src/components/selectedRepository/SelectedRepository.tsx +++ b/frontend/src/components/selectedRepository/SelectedRepository.tsx @@ -78,7 +78,7 @@ function SelectedRepositoryComponent(props:ISelectedRepositoryProps){ } dispatch(ActionUI.setStatus(new ObjectUtils().deepClone(status))); } - window.ipcRenderer.on(RendererEvents.getStatus().replyChannel,(e,res:IStatus)=>{ + window.ipcRenderer.on(RendererEvents.getStatus().replyChannel,(e,res:IStatus)=>{ ReduxUtils.setStatus(res); }) diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index cd882fea..55f42be3 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -378,14 +378,16 @@ export class GraphUtils{ try{ const newStatus = RepoUtils.repositoryDetails?.status; if(!newStatus?.headCommit) return false; + let filter = GraphUtils.state.filter.value; if(!!GraphUtils.state.headCommit.value){ if(newStatus.headCommit.hash !== GraphUtils.state.headCommit.value.hash) return true; const uiRefs = GraphUtils.state.headCommit.value.refValues; const newRefs = newStatus.headCommit.refValues; if(newRefs.some(ref => !uiRefs.includes(ref)) || newRefs.length !== uiRefs.length) return true; + }else if(!filter.userModified){ + return true; } - let filter = GraphUtils.state.filter.value; let commits = await IpcUtils.getGraphCommitList(filter); for(let c of commits){ const existingCm = RepoUtils.repositoryDetails.allCommits.find(_=> _.hash === c.hash); From 8b6af2096d7707f520812abefb05414f4565a90f Mon Sep 17 00:00:00 2001 From: tulshi das Date: Sun, 1 Sep 2024 21:46:39 +0600 Subject: [PATCH 20/21] load 100 commits on checking reload required. --- frontend/src/lib/utils/GraphUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/lib/utils/GraphUtils.ts b/frontend/src/lib/utils/GraphUtils.ts index 55f42be3..5fb48aa9 100644 --- a/frontend/src/lib/utils/GraphUtils.ts +++ b/frontend/src/lib/utils/GraphUtils.ts @@ -388,6 +388,7 @@ export class GraphUtils{ }else if(!filter.userModified){ return true; } + filter = {...filter,limit:100}; let commits = await IpcUtils.getGraphCommitList(filter); for(let c of commits){ const existingCm = RepoUtils.repositoryDetails.allCommits.find(_=> _.hash === c.hash); From b7f479a42f9ed98026fa0eddb79ab08ab01e222b Mon Sep 17 00:00:00 2001 From: tulshi das Date: Mon, 2 Sep 2024 23:53:22 +0600 Subject: [PATCH 21/21] set min height of branch panel view --- .../branches/BranchesView.tsx | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchesView.tsx b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchesView.tsx index 0c9fe0a9..ad8eb550 100644 --- a/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchesView.tsx +++ b/frontend/src/components/selectedRepository/selectedRepoRight/branches/BranchesView.tsx @@ -6,7 +6,6 @@ import { useSelectorTyped } from "../../../../store/rootReducer"; import { BranchActions } from "./BranchActions"; import { CommitProperty } from "./CommitProperty"; import { CommitChangeView } from "./CommitChangeView"; -import { ChangeUtils } from "../../../../lib/utils/ChangeUtils"; import { BiLoader } from "react-icons/bi"; import { ICommitInfo } from "common_library"; @@ -29,11 +28,15 @@ function BranchesViewComponent() { const bottomHeightRef = useRef(200); const positionRef = useRef(0); + const graphViewRef = useRef(); const {currentMousePosition:position,elementRef:resizer} = useDrag(); + const prevBottomHeightRef = useRef(0); + const bottomHeight = useMemo(()=>{ - const curHeight = bottomHeightRef.current - positionRef.current; - const height = Math.max(50, curHeight); + let curHeight = bottomHeightRef.current - positionRef.current; + let height = Math.max(50, curHeight); + if(!position){ bottomHeightRef.current = height; positionRef.current = 0; @@ -41,9 +44,19 @@ function BranchesViewComponent() { else{ positionRef.current = position.y; } + + const graphViewHeight = graphViewRef.current?.getBoundingClientRect().height; + if(!!graphViewHeight && graphViewHeight <= 100 && curHeight > prevBottomHeightRef.current){ + return prevBottomHeightRef.current; + } return height; },[position?.y]) + useEffect(()=>{ + prevBottomHeightRef.current = bottomHeight; + },[bottomHeight]); + + useEffect(()=>{ const selectListener = (commit?:ICommitInfo)=>{ setState({selectedCommit:commit}); @@ -63,7 +76,7 @@ function BranchesViewComponent() { },[bottomHeight]) return
-
+