Skip to content

Commit

Permalink
fix: ensure pullRequestCard still works in both stacking/non-stacking…
Browse files Browse the repository at this point in the history
… contexts
  • Loading branch information
ndom91 committed Oct 23, 2024
1 parent 41b8734 commit b939af8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 48 deletions.
37 changes: 29 additions & 8 deletions apps/desktop/src/lib/branch/BranchCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -42,6 +44,28 @@
commitBoxOpen
}: { isLaneCollapsed: Writable<boolean>; commitBoxOpen: Writable<boolean> } = $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);
Expand All @@ -61,7 +85,6 @@
let laneWidth: number | undefined = $state();
let commitDialog = $state<CommitDialog>();
let scrollViewport: HTMLElement | undefined = $state();
let rsViewport: HTMLElement | undefined = $state();
$effect(() => {
Expand Down Expand Up @@ -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;
}
Expand All @@ -139,7 +160,7 @@
<div class="collapsed-lane-divider" data-remove-from-draggable></div>
</div>
{:else}
<div class="resizer-wrapper" bind:this={scrollViewport}>
<div class="resizer-wrapper">
<div class="branch-card hide-native-scrollbar" class:target-branch={branch.selectedForChanges}>
<ScrollableContainer
wide
Expand Down
33 changes: 0 additions & 33 deletions apps/desktop/src/lib/branch/BranchLane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
import { projectLaneCollapsed } from '$lib/config/config';
import { stackingFeature } from '$lib/config/uiFeatureFlags';
import FileCard from '$lib/file/FileCard.svelte';
import { getGitHost } from '$lib/gitHost/interface/gitHost';
import { createGitHostChecksMonitorStore } from '$lib/gitHost/interface/gitHostChecksMonitor';
import { getGitHostListingService } from '$lib/gitHost/interface/gitHostListingService';
import { createGitHostPrMonitorStore } from '$lib/gitHost/interface/gitHostPrMonitor';
import { createGitHostPrServiceStore } from '$lib/gitHost/interface/gitHostPrService';
import { SETTINGS, type Settings } from '$lib/settings/userSettings';
import Resizer from '$lib/shared/Resizer.svelte';
import Stack from '$lib/stack/Stack.svelte';
Expand All @@ -35,34 +30,6 @@
const { branch }: { branch: VirtualBranch } = $props();
const gitHost = getGitHost();
// BRANCH SERVICE
const prService = createGitHostPrServiceStore(undefined);
$effect(() => 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(
Expand Down
10 changes: 6 additions & 4 deletions apps/desktop/src/lib/dragging/reorderDropzoneManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion apps/desktop/src/lib/pr/PullRequestCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@
tooltip="Open in browser"
onclick={() => {
openExternalUrl($pr.htmlUrl);
}}>View PR</Button
}}
>
View PR
</Button>
</div>

<!--
Expand Down
5 changes: 3 additions & 2 deletions apps/desktop/src/lib/stack/StackCurrentSeries.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createGitHostChecksMonitorStore } from '$lib/gitHost/interface/gitHostChecksMonitor';
import { getGitHostListingService } from '$lib/gitHost/interface/gitHostListingService';
import { createGitHostPrMonitorStore } from '$lib/gitHost/interface/gitHostPrMonitor';
import { getGitHostPrService } from '$lib/gitHost/interface/gitHostPrService';
import { createGitHostPrServiceStore } from '$lib/gitHost/interface/gitHostPrService';
import type { PatchSeries } from '$lib/vbranches/types';
import type { Snippet } from 'svelte';
Expand All @@ -16,7 +16,8 @@
// Setup PR Store and Monitor on a per-series basis
const gitHost = getGitHost();
const prService = getGitHostPrService();
const prService = createGitHostPrServiceStore(undefined);
$effect(() => prService.set($gitHost?.prService()));
// Pretty cumbersome way of getting the PR number, would be great if we can
// make it more concise somehow.
Expand Down

0 comments on commit b939af8

Please sign in to comment.