Remove virtual flag from front end

This commit is contained in:
Caleb Owens 2024-07-03 17:18:11 +02:00
parent 2d0dc3a9ff
commit 5b42e6e9e6
13 changed files with 64 additions and 172 deletions

View File

@ -15,16 +15,7 @@
</script> </script>
{#if !remoteExists} {#if !remoteExists}
{#if !$branch.active} {#if hasIntegratedCommits}
<Button
clickable={false}
size="tag"
icon="virtual-branch-small"
style="neutral"
help="These changes are stashed away from your working directory."
reversedDirection>unapplied</Button
>
{:else if hasIntegratedCommits}
<Button <Button
clickable={false} clickable={false}
size="tag" size="tag"

View File

@ -110,7 +110,7 @@
<div <div
class="branch-card hide-native-scrollbar" class="branch-card hide-native-scrollbar"
data-tauri-drag-region data-tauri-drag-region
class:target-branch={branch.active && branch.selectedForChanges} class:target-branch={branch.selectedForChanges}
> >
<ScrollableContainer <ScrollableContainer
wide wide
@ -148,7 +148,7 @@
showCheckboxes={$commitBoxOpen} showCheckboxes={$commitBoxOpen}
allowMultiple allowMultiple
/> />
{#if branch.active && branch.conflicted} {#if branch.conflicted}
<div class="card-notifications"> <div class="card-notifications">
<InfoMessage filled outlined={false} style="error"> <InfoMessage filled outlined={false} style="error">
<svelte:fragment slot="title"> <svelte:fragment slot="title">
@ -164,18 +164,16 @@
{/if} {/if}
</Dropzones> </Dropzones>
{#if branch.active} <CommitDialog
<CommitDialog projectId={project.id}
projectId={project.id} expanded={commitBoxOpen}
expanded={commitBoxOpen} hasSectionsAfter={branch.commits.length > 0}
hasSectionsAfter={branch.commits.length > 0} on:action={(e) => {
on:action={(e) => { if (e.detail === 'generate-branch-name') {
if (e.detail === 'generate-branch-name') { generateBranchName();
generateBranchName(); }
} }}
}} />
/>
{/if}
</div> </div>
{:else if branch.commits.length === 0} {:else if branch.commits.length === 0}
<Dropzones> <Dropzones>

View File

@ -182,33 +182,31 @@
<div class="header__actions"> <div class="header__actions">
<div class="header__buttons"> <div class="header__buttons">
{#if branch.active} {#if branch.selectedForChanges}
{#if branch.selectedForChanges} <Button
<Button style="pop"
style="pop" kind="soft"
kind="soft" help="New changes will land here"
help="New changes will land here" icon="target"
icon="target" clickable={false}
clickable={false} disabled={isUnapplied}
disabled={isUnapplied} >
> Default branch
Default branch </Button>
</Button> {:else}
{:else} <Button
<Button style="ghost"
style="ghost" outline
outline help="When selected, new changes will land here"
help="When selected, new changes will land here" icon="target"
icon="target" disabled={isUnapplied}
disabled={isUnapplied} on:click={async () => {
on:click={async () => { isTargetBranchAnimated = true;
isTargetBranchAnimated = true; await branchController.setSelectedForChanges(branch.id);
await branchController.setSelectedForChanges(branch.id); }}
}} >
> Set as default
Set as default </Button>
</Button>
{/if}
{/if} {/if}
</div> </div>

View File

@ -191,8 +191,7 @@
}} }}
disabled={isUnapplied || disabled={isUnapplied ||
!($aiGenEnabled && aiConfigurationValid) || !($aiGenEnabled && aiConfigurationValid) ||
branch.files?.length === 0 || branch.files?.length === 0}
!branch.active}
/> />
</ContextMenuSection> </ContextMenuSection>

View File

@ -137,7 +137,7 @@ function mergeBranchesAndPrs(
// This should be everything considered a branch in one list // This should be everything considered a branch in one list
const filtered = contributions const filtered = contributions
.filter((b) => !b.vbranch || !b.vbranch.active) .filter((b) => !b.vbranch)
.sort((a, b) => { .sort((a, b) => {
return (a.modifiedAt || new Date(0)) < (b.modifiedAt || new Date(0)) ? 1 : -1; return (a.modifiedAt || new Date(0)) < (b.modifiedAt || new Date(0)) ? 1 : -1;
}); });

View File

@ -64,10 +64,9 @@ export class CombinedBranch {
} }
// GH colors reference https://github.blog/changelog/2021-06-08-new-issue-and-pull-request-state-icons // GH colors reference https://github.blog/changelog/2021-06-08-new-issue-and-pull-request-state-icons
get color(): 'neutral' | 'success' | 'pop' | 'purple' | undefined { get color(): 'neutral' | 'success' | 'purple' | undefined {
if (this.pr?.mergedAt) return 'purple'; // merged PR if (this.pr?.mergedAt) return 'purple'; // merged PR
if (this.pr) return 'success'; // open PR if (this.pr) return 'success'; // open PR
if (this.vbranch && this.vbranch.active === false) return 'pop'; // stashed virtual branches
// if (this.remoteBranch?.isMergeable) return 'success'; // remote branches // if (this.remoteBranch?.isMergeable) return 'success'; // remote branches
return 'neutral'; return 'neutral';
} }

View File

@ -74,7 +74,7 @@
branchController.undoCommit(branch.id, commit.id); branchController.undoCommit(branch.id, commit.id);
} }
let isUndoable = !!branch?.active && commit instanceof Commit; let isUndoable = commit instanceof Commit;
const hasCommitUrl = !commit.isLocal && commitUrl; const hasCommitUrl = !commit.isLocal && commitUrl;

View File

@ -70,20 +70,9 @@
`refs/remotes/${remoteName}/${pullrequest.sourceBranch}` `refs/remotes/${remoteName}/${pullrequest.sourceBranch}`
); );
await virtualBranchService.reload(); await virtualBranchService.reload();
const vbranch = await virtualBranchService.getByUpstreamSha(pullrequest.sha);
// This is a little absurd, but it makes it soundly typed // This is a little absurd, but it makes it soundly typed
if (!vbranch) { goto(`/${project.id}/board`);
goto(`/${project.id}/board`);
return;
}
// Active seems to be a more reliable metric to determine whether to go to the branch page
if (vbranch.active) {
goto(`/${project.id}/board`);
} else {
goto(`/${project.id}/stashed/${vbranch.id}`);
}
createRemoteModal?.close(); createRemoteModal?.close();
} finally { } finally {

View File

@ -9,8 +9,7 @@
export let branch: CombinedBranch; export let branch: CombinedBranch;
function getBranchLink(b: CombinedBranch): string | undefined { function getBranchLink(b: CombinedBranch): string | undefined {
if (b.vbranch?.active) return `/${projectId}/board/`; if (b.vbranch) return `/${projectId}/board/`;
if (b.vbranch) return `/${projectId}/stashed/${b.vbranch.id}`;
if (b.remoteBranch) return `/${projectId}/remote/${branch?.remoteBranch?.displayName}`; if (b.remoteBranch) return `/${projectId}/remote/${branch?.remoteBranch?.displayName}`;
if (b.pr) return `/${projectId}/pull/${b.pr.number}`; if (b.pr) return `/${projectId}/pull/${b.pr.number}`;
} }

View File

@ -156,7 +156,6 @@ export const file1 = {
}; };
export const virtualBranch = { export const virtualBranch = {
active: true,
baseCurrent: true, baseCurrent: true,
commits: [], commits: [],
conflicted: false, conflicted: false,

View File

@ -99,8 +99,6 @@ export class Branch {
id!: string; id!: string;
name!: string; name!: string;
notes!: string; notes!: string;
// Active means the branch has been applied to the workspace
active!: boolean;
@Type(() => LocalFile) @Type(() => LocalFile)
files!: LocalFile[]; files!: LocalFile[];
@Type(() => Commit) @Type(() => Commit)

View File

@ -24,7 +24,6 @@ import { writable, type Readable } from 'svelte/store';
export class VirtualBranchService { export class VirtualBranchService {
branches$: Observable<Branch[] | undefined>; branches$: Observable<Branch[] | undefined>;
stashedBranches$: Observable<Branch[] | undefined>;
activeBranches$: Observable<Branch[] | undefined>; activeBranches$: Observable<Branch[] | undefined>;
branchesError = writable<any>(); branchesError = writable<any>();
private reload$ = new BehaviorSubject<void>(undefined); private reload$ = new BehaviorSubject<void>(undefined);
@ -67,10 +66,6 @@ export class VirtualBranchService {
shareReplay(1) shareReplay(1)
); );
this.stashedBranches$ = this.branches$.pipe(
map((branches) => branches?.filter((b) => !b.active))
);
// We need upstream data to be part of the branch without delay since the way we render // We need upstream data to be part of the branch without delay since the way we render
// commits depends on it. // commits depends on it.
// TODO: Move this async behavior into the rust code. // TODO: Move this async behavior into the rust code.
@ -80,29 +75,27 @@ export class VirtualBranchService {
switchMap((branches) => { switchMap((branches) => {
if (!branches) return of(); if (!branches) return of();
return Promise.all( return Promise.all(
branches branches.map(async (b) => {
.filter((b) => b.active) const upstreamName = b.upstream?.name;
.map(async (b) => { if (upstreamName) {
const upstreamName = b.upstream?.name; try {
if (upstreamName) { const data = await getRemoteBranchData(projectId, upstreamName);
try { const commits = data.commits;
const data = await getRemoteBranchData(projectId, upstreamName); commits.forEach((uc) => {
const commits = data.commits; const match = b.commits.find((c) => commitCompare(uc, c));
commits.forEach((uc) => { if (match) {
const match = b.commits.find((c) => commitCompare(uc, c)); match.relatedTo = uc;
if (match) { uc.relatedTo = match;
match.relatedTo = uc; }
uc.relatedTo = match; });
} linkAsParentChildren(commits);
}); b.upstreamData = data;
linkAsParentChildren(commits); } catch (e: any) {
b.upstreamData = data; console.log(e);
} catch (e: any) {
console.log(e);
}
} }
return b; }
}) return b;
})
); );
}) })
); );

View File

@ -1,71 +0,0 @@
<script lang="ts">
// This page is displayed when:
// - A vbranch is found
// It may also display details about a cooresponding remote and/or pr if they exist
import BranchLane from '$lib/branch/BranchLane.svelte';
import FullviewLoading from '$lib/components/FullviewLoading.svelte';
import Button from '$lib/shared/Button.svelte';
import Modal from '$lib/shared/Modal.svelte';
import type { PageData } from './$types';
import { goto } from '$app/navigation';
import { page } from '$app/stores';
export let data: PageData;
let applyConflictedModal: Modal;
let deleteBranchModal: Modal;
$: ({ projectId, branchController, vbranchService } = data);
$: branches$ = vbranchService.branches$;
$: error = vbranchService.branchesError;
$: branch = $branches$?.find((b) => b.id === $page.params.branchId);
</script>
{#if $error}
<p>{JSON.stringify($error)}</p>
{:else if !$branches$}
<FullviewLoading />
{:else if branch}
<BranchLane {branch} isUnapplied={!branch.active} />
{:else}
<p>Branch no longer exists</p>
{/if}
<Modal width="small" title="Merge conflicts" bind:this={applyConflictedModal}>
<p>Applying this branch will introduce merge conflicts.</p>
{#snippet controls(close, item)}
<Button style="ghost" outline on:click={close}>Cancel</Button>
<Button
style="pop"
kind="solid"
on:click={() => {
branchController.applyBranch(item.id);
close();
goto(`/${projectId}/board`);
}}
>
Update
</Button>
{/snippet}
</Modal>
<Modal width="small" title="Delete branch" bind:this={deleteBranchModal}>
{#snippet children(item)}
Deleting <code class="code-string">{item.name}</code> cannot be undone.
{/snippet}
{#snippet controls(close, item)}
<Button style="ghost" outline on:mousedown={close}>Cancel</Button>
<Button
style="error"
kind="solid"
on:click={() => {
branchController.deleteBranch(item.id);
close();
goto(`/${projectId}/board`);
}}
>
Delete
</Button>
{/snippet}
</Modal>