From 55ae30f62fe4152bdf752812d54b4428b170ec5f Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Fri, 5 Jan 2024 12:06:15 +0100 Subject: [PATCH 1/2] Fix duplicate list_remote_branches call - give head and fetches streams an initial value --- gitbutler-ui/src/lib/stores/fetches.ts | 9 ++++++--- gitbutler-ui/src/lib/stores/head.ts | 4 ++-- gitbutler-ui/src/lib/stores/remoteBranches.ts | 6 ++---- gitbutler-ui/src/lib/vbranches/branchStoresCache.ts | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/gitbutler-ui/src/lib/stores/fetches.ts b/gitbutler-ui/src/lib/stores/fetches.ts index 0942495bf..ed261e040 100644 --- a/gitbutler-ui/src/lib/stores/fetches.ts +++ b/gitbutler-ui/src/lib/stores/fetches.ts @@ -1,6 +1,9 @@ import { subscribeToFetches } from '$lib/backend/fetches'; -import { Observable } from 'rxjs'; +import { Observable, shareReplay, startWith } from 'rxjs'; -export function getFetchNotifications(projectId: string): Observable { - return new Observable((observer) => subscribeToFetches(projectId, () => observer.next())); +export function getFetchNotifications(projectId: string): Observable { + return new Observable((observer) => subscribeToFetches(projectId, () => observer.next())).pipe( + startWith(undefined), + shareReplay(1) + ); } diff --git a/gitbutler-ui/src/lib/stores/head.ts b/gitbutler-ui/src/lib/stores/head.ts index fb745f1c9..bdfe0a3c1 100644 --- a/gitbutler-ui/src/lib/stores/head.ts +++ b/gitbutler-ui/src/lib/stores/head.ts @@ -1,10 +1,10 @@ import { getHead, subscribeToHead } from '$lib/backend/heads'; -import { Observable, concat, from } from 'rxjs'; +import { Observable, concat, from, shareReplay } from 'rxjs'; export function getHeads(projectId: string): Observable { const head$ = from(getHead(projectId)); const stream$ = new Observable((subscriber) => subscribeToHead(projectId, (head) => subscriber.next(head)) ); - return concat(head$, stream$); + return concat(head$, stream$).pipe(shareReplay(1)); } diff --git a/gitbutler-ui/src/lib/stores/remoteBranches.ts b/gitbutler-ui/src/lib/stores/remoteBranches.ts index 973ae6cda..6675fe305 100644 --- a/gitbutler-ui/src/lib/stores/remoteBranches.ts +++ b/gitbutler-ui/src/lib/stores/remoteBranches.ts @@ -5,9 +5,8 @@ import { BehaviorSubject, Observable, catchError, - combineLatestWith, + combineLatest, map, - merge, of, shareReplay, switchMap @@ -24,8 +23,7 @@ export class RemoteBranchService { head$: Observable, baseBranch$: Observable ) { - this.branches$ = merge(fetches$, head$, baseBranch$).pipe( - combineLatestWith(this.reload$), + this.branches$ = combineLatest([baseBranch$, this.reload$, head$, fetches$]).pipe( switchMap(() => getRemoteBranchesData({ projectId })), map((branches) => branches.filter((b) => b.ahead != 0)), shareReplay(1), diff --git a/gitbutler-ui/src/lib/vbranches/branchStoresCache.ts b/gitbutler-ui/src/lib/vbranches/branchStoresCache.ts index 4c1c43912..becc271a9 100644 --- a/gitbutler-ui/src/lib/vbranches/branchStoresCache.ts +++ b/gitbutler-ui/src/lib/vbranches/branchStoresCache.ts @@ -2,7 +2,6 @@ import { BaseBranch, Branch } from './types'; import { plainToInstance } from 'class-transformer'; import { UserError, invoke, listen } from '$lib/backend/ipc'; import { - merge, switchMap, Observable, shareReplay, @@ -14,7 +13,8 @@ import { tap, map, firstValueFrom, - timeout + timeout, + combineLatest } from 'rxjs'; export class VirtualBranchService { @@ -83,8 +83,8 @@ export class BaseBranchService { error$ = new BehaviorSubject(undefined); private reload$ = new BehaviorSubject(undefined); - constructor(projectId: string, fetches$: Observable, head$: Observable) { - this.base$ = merge(fetches$, head$, this.reload$).pipe( + constructor(projectId: string, fetches$: Observable, head$: Observable) { + this.base$ = combineLatest([fetches$, head$, this.reload$]).pipe( debounceTime(100), switchMap(() => getBaseBranch({ projectId })), catchError((e) => { From f09563061e20b68ce5b031b0df0d6937fcd8fbbe Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Fri, 5 Jan 2024 13:12:28 +0100 Subject: [PATCH 2/2] Add branch and pr links to header --- .../[projectId]/components/BranchCard.svelte | 2 + .../components/BranchHeader.svelte | 86 +++++++++++++++---- .../[projectId]/components/CommitList.svelte | 5 +- .../components/CommitListHeader.svelte | 39 +-------- .../[projectId]/components/commitList.ts | 7 +- gitbutler-ui/src/styles/card.postcss | 1 - 6 files changed, 80 insertions(+), 60 deletions(-) diff --git a/gitbutler-ui/src/routes/[projectId]/components/BranchCard.svelte b/gitbutler-ui/src/routes/[projectId]/components/BranchCard.svelte index 2ffa35eb2..0caf800bc 100644 --- a/gitbutler-ui/src/routes/[projectId]/components/BranchCard.svelte +++ b/gitbutler-ui/src/routes/[projectId]/components/BranchCard.svelte @@ -143,6 +143,8 @@ {readonly} {branchController} {branch} + {base} + {githubService} projectId={project.id} on:action={(e) => { if (e.detail == 'generate-branch-name') { diff --git a/gitbutler-ui/src/routes/[projectId]/components/BranchHeader.svelte b/gitbutler-ui/src/routes/[projectId]/components/BranchHeader.svelte index 8ad3b9bf2..8e3cca888 100644 --- a/gitbutler-ui/src/routes/[projectId]/components/BranchHeader.svelte +++ b/gitbutler-ui/src/routes/[projectId]/components/BranchHeader.svelte @@ -2,17 +2,27 @@ import IconButton from '$lib/components/IconButton.svelte'; import Icon from '$lib/icons/Icon.svelte'; import type { BranchController } from '$lib/vbranches/branchController'; - import type { Branch } from '$lib/vbranches/types'; + import type { BaseBranch, Branch } from '$lib/vbranches/types'; import { fade } from 'svelte/transition'; import BranchLabel from './BranchLabel.svelte'; import BranchLanePopupMenu from './BranchLanePopupMenu.svelte'; import { clickOutside } from '$lib/clickOutside'; + import Tag from './Tag.svelte'; + import { branchUrl } from './commitList'; + import type { GitHubService } from '$lib/github/service'; + import BranchIcon from '../navigation/BranchIcon.svelte'; + import { open } from '@tauri-apps/api/shell'; export let readonly = false; export let branch: Branch; + export let base: BaseBranch | undefined | null; export let branchController: BranchController; export let projectId: string; + export let githubService: GitHubService; + $: pr$ = githubService.get(branch.upstreamName); + // $: prStatus$ = githubService.getStatus($pr$?.targetBranch); + let meatballButton: HTMLDivElement; let visible = false; @@ -24,7 +34,7 @@
-
+
{#if !readonly}
@@ -48,17 +58,51 @@
{#if branch.upstreamName} -
-
- {#if !branch.upstream} - {#if hasIntegratedCommits} -
deleted
- {:else} -
pending
- {/if} +
+ {#if !branch.upstream} + {#if hasIntegratedCommits} +
deleted
+ {:else} +
pending
{/if} -
origin/{branch.upstreamName}
-
+ {/if} +
origin/{branch.upstreamName}
+
+ {/if} + {#if branch.upstream} + {/if}
@@ -72,12 +116,11 @@ .card__header:hover .draggable { color: var(--clr-theme-scale-ntrl-40); } - .card__row { + .header__row { width: 100%; display: flex; justify-content: space-between; gap: var(--space-8); - align-items: center; overflow-x: hidden; } .header__left { @@ -89,6 +132,15 @@ gap: var(--space-4); } + .header__links { + display: flex; + gap: var(--space-6); + align-items: center; + padding-left: var(--space-28); + margin-top: var(--space-10); + fill: var(--clr-core-ntrl-50); + } + .draggable { display: flex; cursor: grab; @@ -103,14 +155,14 @@ z-index: 10; } - .card__remote { + .header__remote-branch { + color: var(--clr-theme-scale-ntrl-50); padding-left: var(--space-28); display: flex; gap: var(--space-4); text-overflow: ellipsis; overflow-x: hidden; white-space: nowrap; - color: var(--clr-theme-scale-ntrl-50); align-items: center; } @@ -118,10 +170,12 @@ padding: var(--space-2) var(--space-4); border-radius: var(--radius-s); } + .pending { color: var(--clr-theme-scale-ntrl-40); background: var(--clr-theme-container-sub); } + .deleted { color: var(--clr-theme-scale-warn-30); background: var(--clr-theme-warn-container-dim); diff --git a/gitbutler-ui/src/routes/[projectId]/components/CommitList.svelte b/gitbutler-ui/src/routes/[projectId]/components/CommitList.svelte index 245776990..9604350df 100644 --- a/gitbutler-ui/src/routes/[projectId]/components/CommitList.svelte +++ b/gitbutler-ui/src/routes/[projectId]/components/CommitList.svelte @@ -29,15 +29,12 @@ return c.isIntegrated; } }); - $: pr$ = githubService.get(branch.upstreamName); - // $: prStatus$ = githubService.getStatus($pr$?.targetBranch); - let expanded = true; {#if commits.length > 0}
- + {#if expanded}
diff --git a/gitbutler-ui/src/routes/[projectId]/components/CommitListHeader.svelte b/gitbutler-ui/src/routes/[projectId]/components/CommitListHeader.svelte index 83f7d19e0..6a61fe40d 100644 --- a/gitbutler-ui/src/routes/[projectId]/components/CommitListHeader.svelte +++ b/gitbutler-ui/src/routes/[projectId]/components/CommitListHeader.svelte @@ -1,20 +1,10 @@