From 646ea36131163173c3f83957b25250c773c08848 Mon Sep 17 00:00:00 2001 From: Caleb Owens Date: Mon, 11 Nov 2024 15:53:15 +0100 Subject: [PATCH 1/2] Fix lost PRs --- .../desktop/src/lib/branches/branchListing.ts | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/apps/desktop/src/lib/branches/branchListing.ts b/apps/desktop/src/lib/branches/branchListing.ts index 8b31c630d..95961232e 100644 --- a/apps/desktop/src/lib/branches/branchListing.ts +++ b/apps/desktop/src/lib/branches/branchListing.ts @@ -122,8 +122,12 @@ export class CombinedBranchListingService { private pullRequests: Readable; selectedOption: Persisted<'all' | 'pullRequest' | 'local'>; + // Used when deriving the search results and for finding the total number + // of listings combinedSidebarEntries: Readable; + // Contains entries grouped by date for the unsearched sidebar entries groupedSidebarEntries: Readable; + // Whether or not to show the pull request tab in the sidebar pullRequestsListed: Readable; constructor( @@ -135,6 +139,8 @@ export class CombinedBranchListingService { 'all', `branches-selectedOption-${projectId}` ); + + // Get a readable store of pull requeests this.pullRequests = readable([] as PullRequest[], (set) => { const unsubscribeListingService = forgeListingService.subscribe((forgeListingService) => { if (!forgeListingService) return; @@ -149,6 +155,7 @@ export class CombinedBranchListingService { return unsubscribeListingService; }); + // Whether or not to show the pull request tab in the sidebar this.pullRequestsListed = derived( forgeListingService, (forgeListingService) => { @@ -157,23 +164,24 @@ export class CombinedBranchListingService { false ); - const branchListingsByName = derived(branchListingService.branchListings, (branchListings) => { - const set = new Set(branchListings.map((branchListing) => branchListing.name)); - return set; - }); - + // Derive the combined sidebar entries this.combinedSidebarEntries = debouncedDerive( - [ - branchListingsByName, - this.pullRequests, - branchListingService.branchListings, - this.selectedOption - ], - ([branchListingsByName, pullRequests, branchListings, selectedOption]) => { + [this.pullRequests, branchListingService.branchListings, this.selectedOption], + ([pullRequests, branchListings, selectedOption]) => { + // Find the pull requests that don't have cooresponding local branches, + // remote branches, virutal branches, or stack branch heads. + // Then map the pull requests into the SidebarEntrySubject type const pullRequestSubjects: SidebarEntrySubject[] = pullRequests - .filter((pullRequests) => !branchListingsByName.has(pullRequests.sourceBranch)) + .filter( + (pullRequests) => + !branchListings.some((branchListing) => + branchListing.containsPullRequestBranch(pullRequests.sourceBranch) + ) + ) .map((pullRequests) => ({ type: 'pullRequest', subject: pullRequests })); + // Map the raw branch listing classes into the + // SidebarEntrySubject type const branchListingSubjects: SidebarEntrySubject[] = branchListings.map( (branchListing) => ({ type: 'branchListing', @@ -181,6 +189,7 @@ export class CombinedBranchListingService { }) ); + // Sort the combined entries by when htey were last updated const output = [...pullRequestSubjects, ...branchListingSubjects]; output.sort((a, b) => { @@ -193,6 +202,7 @@ export class CombinedBranchListingService { return getEntryName(a).localeCompare(getEntryName(b)); }); + // Filter by the currently selected tab in the frontend const filtered = this.filterSidebarEntries(pullRequests, selectedOption, output); return filtered; @@ -201,6 +211,7 @@ export class CombinedBranchListingService { 50 ); + // Create the entries which are grouped date-wise this.groupedSidebarEntries = derived(this.combinedSidebarEntries, (combinedSidebarEntries) => { const groupings = this.groupBranches(combinedSidebarEntries); return groupings; @@ -349,6 +360,13 @@ export class BranchListing { lastCommiter!: Author; /** Whether or not there is a local branch as part of the grouping */ hasLocal!: boolean; + + containsPullRequestBranch(sourceBranch: string): boolean { + if (sourceBranch === this.name) return true; + if (this.virtualBranch?.stackBranches.includes(sourceBranch)) return true; + + return false; + } } /** Represents a reference to an associated virtual branch */ From 4f6cef393e30e19559de7392747dcb13adf0b7f8 Mon Sep 17 00:00:00 2001 From: Caleb Owens Date: Mon, 11 Nov 2024 16:03:15 +0100 Subject: [PATCH 2/2] Improve filtering of PR tab to consider stacks --- apps/desktop/src/lib/branches/branchListing.ts | 4 ++-- .../src/lib/navigation/BranchListingSidebarEntry.svelte | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/lib/branches/branchListing.ts b/apps/desktop/src/lib/branches/branchListing.ts index 95961232e..0873a078c 100644 --- a/apps/desktop/src/lib/branches/branchListing.ts +++ b/apps/desktop/src/lib/branches/branchListing.ts @@ -298,8 +298,8 @@ export class CombinedBranchListingService { return sidebarEntries.filter( (sidebarEntry) => sidebarEntry.type === 'pullRequest' || - pullRequests.some( - (pullRequest) => pullRequest.sourceBranch === sidebarEntry.subject.name + pullRequests.some((pullRequest) => + sidebarEntry.subject.containsPullRequestBranch(pullRequest.sourceBranch) ) ); } diff --git a/apps/desktop/src/lib/navigation/BranchListingSidebarEntry.svelte b/apps/desktop/src/lib/navigation/BranchListingSidebarEntry.svelte index 59a237002..4712cd304 100644 --- a/apps/desktop/src/lib/navigation/BranchListingSidebarEntry.svelte +++ b/apps/desktop/src/lib/navigation/BranchListingSidebarEntry.svelte @@ -30,7 +30,7 @@ const forgeListingService = getForgeListingService(); const prs = $derived($forgeListingService?.prs); - const pr = $derived($prs?.find((pr) => pr.sourceBranch === branchListing.name)); + const pr = $derived($prs?.find((pr) => branchListing.containsPullRequestBranch(pr.sourceBranch))); let branchListingDetails = $state>();