From b939af8299b3edbf2ac211669bcca247a00803c9 Mon Sep 17 00:00:00 2001 From: ndom91 Date: Tue, 22 Oct 2024 17:43:03 +0200 Subject: [PATCH] fix: ensure pullRequestCard still works in both stacking/non-stacking contexts --- apps/desktop/src/lib/branch/BranchCard.svelte | 37 +++++++++++++++---- apps/desktop/src/lib/branch/BranchLane.svelte | 33 ----------------- .../lib/dragging/reorderDropzoneManager.ts | 10 +++-- .../desktop/src/lib/pr/PullRequestCard.svelte | 4 +- .../src/lib/stack/StackCurrentSeries.svelte | 5 ++- 5 files changed, 41 insertions(+), 48 deletions(-) diff --git a/apps/desktop/src/lib/branch/BranchCard.svelte b/apps/desktop/src/lib/branch/BranchCard.svelte index d82f0c971..fe206e0e4 100644 --- a/apps/desktop/src/lib/branch/BranchCard.svelte +++ b/apps/desktop/src/lib/branch/BranchCard.svelte @@ -12,9 +12,11 @@ import CommitList from '$lib/commit/CommitList.svelte'; import { projectAiGenEnabled } from '$lib/config/config'; import BranchFiles from '$lib/file/BranchFiles.svelte'; - import { getGitHostChecksMonitor } from '$lib/gitHost/interface/gitHostChecksMonitor'; + import { getGitHost } from '$lib/gitHost/interface/gitHost'; + import { createGitHostChecksMonitorStore } from '$lib/gitHost/interface/gitHostChecksMonitor'; import { getGitHostListingService } from '$lib/gitHost/interface/gitHostListingService'; - import { getGitHostPrMonitor } from '$lib/gitHost/interface/gitHostPrMonitor'; + import { createGitHostPrMonitorStore } from '$lib/gitHost/interface/gitHostPrMonitor'; + import { createGitHostPrServiceStore } from '$lib/gitHost/interface/gitHostPrService'; import { showError } from '$lib/notifications/toasts'; import { isFailure } from '$lib/result'; import ScrollableContainer from '$lib/scroll/ScrollableContainer.svelte'; @@ -42,6 +44,28 @@ commitBoxOpen }: { isLaneCollapsed: Writable; commitBoxOpen: Writable } = $props(); + const gitHost = getGitHost(); + + const prService = createGitHostPrServiceStore(undefined); + $effect(() => prService.set($gitHost?.prService())); + + const hostedListingServiceStore = getGitHostListingService(); + + const prStore = $derived($hostedListingServiceStore?.prs); + const prs = $derived(prStore ? $prStore : undefined); + + const listedPr = $derived(prs?.find((pr) => pr.sourceBranch === branch.upstream?.givenName)); + const sourceBranch = $derived(listedPr?.sourceBranch); + const prNumber = $derived(listedPr?.number); + + const gitHostPrMonitorStore = createGitHostPrMonitorStore(undefined); + const prMonitor = $derived(prNumber ? $prService?.prMonitor(prNumber) : undefined); + $effect(() => gitHostPrMonitorStore.set(prMonitor)); + + const gitHostChecksMonitorStore = createGitHostChecksMonitorStore(undefined); + const checksMonitor = $derived(sourceBranch ? $gitHost?.checksMonitor(sourceBranch) : undefined); + $effect(() => gitHostChecksMonitorStore.set(checksMonitor)); + const branchController = getContext(BranchController); const fileIdSelection = getContext(FileIdSelection); const branchStore = getContextStore(VirtualBranch); @@ -61,7 +85,6 @@ let laneWidth: number | undefined = $state(); let commitDialog = $state(); - let scrollViewport: HTMLElement | undefined = $state(); let rsViewport: HTMLElement | undefined = $state(); $effect(() => { @@ -112,16 +135,14 @@ ); const listingService = getGitHostListingService(); - const prMonitor = getGitHostPrMonitor(); - const checksMonitor = getGitHostChecksMonitor(); async function push() { isPushingCommits = true; try { await branchController.pushBranch(branch.id, branch.requiresForce); $listingService?.refresh(); - $prMonitor?.refresh(); - $checksMonitor?.update(); + prMonitor?.refresh(); + checksMonitor?.update(); } finally { isPushingCommits = false; } @@ -139,7 +160,7 @@
{:else} -
+
prService.set($gitHost?.prService())); - - // Pretty cumbersome way of getting the PR number, would be great if we can - // make it more concise somehow. - const hostedListingServiceStore = getGitHostListingService(); - const prStore = $derived($hostedListingServiceStore?.prs); - const prs = $derived(prStore ? $prStore : undefined); - - const listedPr = $derived(prs?.find((pr) => pr.sourceBranch === branch.upstream?.givenName)); - const sourceBranch = $derived(listedPr?.sourceBranch); - const prNumber = $derived(listedPr?.number); - - if (!$stackingFeature) { - const gitHostPrMonitorStore = createGitHostPrMonitorStore(undefined); - const prMonitor = $derived(prNumber ? $prService?.prMonitor(prNumber) : undefined); - $effect(() => gitHostPrMonitorStore.set(prMonitor)); - - const gitHostChecksMonitorStore = createGitHostChecksMonitorStore(undefined); - const checksMonitor = $derived( - sourceBranch ? $gitHost?.checksMonitor(sourceBranch) : undefined - ); - $effect(() => gitHostChecksMonitorStore.set(checksMonitor)); - } - // BRANCH const branchStore = createContextStore(VirtualBranch, branch); const selectedOwnershipStore = createContextStore( diff --git a/apps/desktop/src/lib/dragging/reorderDropzoneManager.ts b/apps/desktop/src/lib/dragging/reorderDropzoneManager.ts index eba223ce4..ac85af835 100644 --- a/apps/desktop/src/lib/dragging/reorderDropzoneManager.ts +++ b/apps/desktop/src/lib/dragging/reorderDropzoneManager.ts @@ -76,7 +76,7 @@ class Indexer { get(key: string) { const index = this.getIndex(key); - return new Entry(this.commitIndexes, index); + return new Entry(this.commitIndexes, index ?? 0); } private getIndex(key: string) { @@ -90,9 +90,11 @@ class Indexer { } else { const index = this.dropzoneIndexes.get(key); - if (index === undefined) { - throw new Error(`Commit ${key} not found in dropzoneIndexes`); - } + // TODO: Improve reactivity of dropzoneIndexes + // Handle integrated state and dont error + // if (index === undefined) { + // throw new Error(`Commit ${key} not found in dropzoneIndexes`); + // } return index; } diff --git a/apps/desktop/src/lib/pr/PullRequestCard.svelte b/apps/desktop/src/lib/pr/PullRequestCard.svelte index 1e6a6e20f..2ecb7c754 100644 --- a/apps/desktop/src/lib/pr/PullRequestCard.svelte +++ b/apps/desktop/src/lib/pr/PullRequestCard.svelte @@ -143,8 +143,10 @@ tooltip="Open in browser" onclick={() => { openExternalUrl($pr.htmlUrl); - }}>View PR + View PR +