Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add non-archived branch getter #5813

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions apps/desktop/src/lib/branch/BranchLaneContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
let isDeleting = $state(false);

const branch = $derived($branchStore);
const commits = $derived(branch.validSeries.flatMap((s) => s.patches));
const commits = $derived(branch.validBranches.flatMap((s) => s.patches));

$effect(() => {
allowRebasing = branch.allowRebasing;
});

const allPrIds = $derived(branch.validSeries.map((series) => series.prNumber).filter(isDefined));
const allPrIds = $derived(
branch.validBranches.map((series) => series.prNumber).filter(isDefined)
);

async function toggleAllowRebasing() {
branchController.updateBranchAllowRebasing(branch.id, !allowRebasing);
Expand Down Expand Up @@ -123,13 +125,15 @@
</ContextMenuSection>
{#if $user && $user.role?.includes('admin')}
<!-- TODO: Remove after iterating on the pull request footer. -->
<ContextMenuSection title="Admin only">
<ContextMenuSection>
<ContextMenuItem
label="Update PR footers"
disabled={allPrIds.length === 0}
onclick={() => {
if ($prService && branch) {
const allPrIds = branch.validSeries.map((series) => series.prNumber).filter(isDefined);
const allPrIds = branch.validBranches
.map((series) => series.prNumber)
.filter(isDefined);
updatePrDescriptionTables($prService, allPrIds);
}
contextMenuEl?.close();
Expand Down
13 changes: 4 additions & 9 deletions apps/desktop/src/lib/branch/SeriesHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@
const parent = $derived(
parentBranch(
branch,
stack.validSeries.filter((b) => b.archived)
)
);
const child = $derived(
childBranch(
branch,
stack.validSeries.filter((b) => !b.archived)
stack.validBranches.filter((b) => b.archived)
)
);
const child = $derived(childBranch(branch, stack.validNonArchivedBranches));

const aiGenEnabled = projectAiGenEnabled(project.id);
const branchController = getContext(BranchController);
Expand All @@ -77,7 +72,7 @@
const upstreamName = $derived(branch.upstreamReference ? branch.name : undefined);
const forgeBranch = $derived(upstreamName ? $forge?.branch(upstreamName) : undefined);
const previousSeriesHavePrNumber = $derived(
allPreviousSeriesHavePrNumber(branch.name, stack.validSeries)
allPreviousSeriesHavePrNumber(branch.name, stack.validBranches)
);

let stackingAddSeriesModal = $state<ReturnType<typeof AddSeriesModal>>();
Expand Down Expand Up @@ -279,7 +274,7 @@
leftClickTrigger={kebabContextMenuTrigger}
rightClickTrigger={seriesHeaderEl}
headName={branch.name}
seriesCount={stack.validSeries?.length ?? 0}
seriesCount={stack.validBranches?.length ?? 0}
{isTopBranch}
{toggleDescription}
description={branch.description ?? ''}
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/branch/SeriesHeaderContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
const branch = $derived($branchStore);

export function showSeriesRenameModal(seriesName: string) {
renameSeriesModal.show(branch.validSeries.find((s) => s.name === seriesName));
renameSeriesModal.show(branch.validBranches.find((s) => s.name === seriesName));
}

let isOpenedByMouse = $state(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class StackingReorderDropzoneManager {
private branch: VirtualBranch
) {
const seriesMap = new Map();
this.branch.validSeries.forEach((series) => {
this.branch.validBranches.forEach((series) => {
seriesMap.set(series.name, series);
});
this.series = seriesMap;
Expand All @@ -67,7 +67,7 @@ export class StackingReorderDropzoneManager {
this.branch.id,
this.branchController,
currentSeries,
this.branch.validSeries,
this.branch.validBranches,
'top'
);
}
Expand All @@ -82,7 +82,7 @@ export class StackingReorderDropzoneManager {
this.branch.id,
this.branchController,
currentSeries,
this.branch.validSeries,
this.branch.validBranches,
commitId
);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/lib/pr/PrDetailsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
}

// All ids that existed prior to creating a new one (including archived).
const prNumbers = branch.validSeries.map((series) => series.prNumber);
const prNumbers = branch.validBranches.map((series) => series.prNumber);

isLoading = true;
try {
Expand Down Expand Up @@ -189,7 +189,7 @@
}

// Find the index of the current branch so we know where we want to point the pr.
const branches = branch.validSeries;
const branches = branch.validBranches;
const currentIndex = branches.findIndex((b) => b.name === currentSeries.name);
if (currentIndex === -1) {
throw new Error('Branch index not found.');
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/stack/CollapsedLane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

const branchStore = getContextStore(VirtualBranch);
const branch = $derived($branchStore);
const nonArchivedSeries = $derived(branch.validSeries.filter((s) => !s.archived));
const nonArchivedSeries = $derived(branch.validNonArchivedBranches);

function expandLane() {
$isLaneCollapsed = false;
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/lib/stack/SeriesList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
);

// All non-errored non-archived series for consumption elsewhere
const nonArchivedValidSeries = $derived(branch.validSeries.filter((s) => !s.archived));
const validNonArchivedBranches = $derived(branch.validNonArchivedBranches);

const stackingReorderDropzoneManagerFactory = getContext(StackingReorderDropzoneManagerFactory);
const stackingReorderDropzoneManager = $derived(
Expand Down Expand Up @@ -77,7 +77,7 @@
<div>
<Dropzone
{accepts}
ondrop={(data) => onDrop(data, nonArchivedValidSeries, currentSeries)}
ondrop={(data) => onDrop(data, validNonArchivedBranches, currentSeries)}
>
{#snippet overlay({ hovered, activated })}
<CardOverlay {hovered} {activated} label="Move here" />
Expand Down
10 changes: 5 additions & 5 deletions apps/desktop/src/lib/stack/Stack.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
let rsViewport = $state<HTMLElement>();

const branchHasFiles = $derived(branch.files !== undefined && branch.files.length > 0);
const branchHasNoCommits = $derived(branch.validSeries.flatMap((s) => s.patches).length === 0);
const branchHasNoCommits = $derived(branch.validBranches.flatMap((s) => s.patches).length === 0);

$effect(() => {
if ($commitBoxOpen && branch.files.length === 0) {
Expand All @@ -78,7 +78,7 @@
const upstreamPatches: DetailedCommit[] = [];
const branchPatches: DetailedCommit[] = [];

branch.validSeries.map((series) => {
branch.validBranches.map((series) => {
upstreamPatches.push(...series.upstreamPatches);
branchPatches.push(...series.patches);
hasConflicts = branchPatches.some((patch) => patch.conflicted);
Expand Down Expand Up @@ -110,7 +110,7 @@
}

async function checkMergeable() {
const nonArchivedBranches = branch.validSeries.filter((s) => !s.archived);
const nonArchivedBranches = branch.validNonArchivedBranches;
if (nonArchivedBranches.length <= 1) return false;

const seriesMergeResponse = await Promise.allSettled(
Expand All @@ -135,7 +135,7 @@
async function mergeAll(method: MergeMethod) {
isMergingSeries = true;
try {
const topBranch = branch.validSeries[0];
const topBranch = branch.validBranches[0];

if (topBranch?.prNumber && $prService) {
const targetBase = $baseBranch.branchName.replace(`${$baseBranch.remoteName}/`, '');
Expand Down Expand Up @@ -250,7 +250,7 @@
>
{branch.requiresForce
? 'Force push'
: branch.validSeries.length > 1
: branch.validBranches.length > 1
? 'Push All'
: 'Push'}
</Button>
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/lib/stack/UncommittedChanges.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<BranchFiles
isUnapplied={false}
files={branch.files}
branches={branch.validSeries}
branches={branch.validBranches}
showCheckboxes={$commitBoxOpen}
allowMultiple
commitDialogExpanded={commitBoxOpen}
Expand All @@ -53,7 +53,7 @@
bind:this={commitDialog}
projectId={project.id}
expanded={commitBoxOpen}
hasSectionsAfter={branch.validSeries.flatMap((s) => s.patches).length > 0}
hasSectionsAfter={branch.validBranches.flatMap((s) => s.patches).length > 0}
/>
</div>

Expand Down
12 changes: 10 additions & 2 deletions apps/desktop/src/lib/vbranches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export function isPatchSeries(item: PatchSeries | Error): item is PatchSeries {
return item instanceof PatchSeries;
}

export function isNonArchivedPatchSeries(item: PatchSeries | Error): item is PatchSeries {
return item instanceof PatchSeries && !item.archived;
}

export class VirtualBranch {
id!: string;
name!: string;
Expand Down Expand Up @@ -167,15 +171,19 @@ export class VirtualBranch {

/**
* @desc Used in the stacking context where VirtualBranch === Stack
* @warning You probably want 'validSeries' instead
* @warning You probably want 'validBranches' instead
*/
@Transform(({ value }) => transformResultToType(PatchSeries, value))
series!: (PatchSeries | Error)[];

get validSeries(): PatchSeries[] {
get validBranches(): PatchSeries[] {
return this.series.filter(isPatchSeries);
}

get validNonArchivedBranches(): PatchSeries[] {
return this.series.filter(isNonArchivedPatchSeries);
}

get displayName() {
if (this.upstream?.displayName) return this.upstream?.displayName;

Expand Down
8 changes: 4 additions & 4 deletions apps/desktop/src/lib/vbranches/virtualBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type { ModeService } from '$lib/modes/service';

export function allPreviousSeriesHavePrNumber(
seriesName: string,
validSeries: PatchSeries[]
validBranches: PatchSeries[]
): boolean {
const unarchivedSeries = validSeries.filter((series) => !series.archived);
const unarchivedSeries = validBranches.filter((series) => !series.archived);
for (let i = unarchivedSeries.length - 1; i >= 0; i--) {
const series = unarchivedSeries[i]!;
if (series.name === seriesName) return true;
Expand Down Expand Up @@ -92,8 +92,8 @@ export class VirtualBranchService {
branches.forEach(async (branch) => {
const upstreamName = branch.upstream?.name;
if (upstreamName) {
const upstreamCommits = branch.validSeries.flatMap((series) => series.upstreamPatches);
const commits = branch.validSeries.flatMap((series) => series.patches);
const upstreamCommits = branch.validBranches.flatMap((series) => series.upstreamPatches);
const commits = branch.validBranches.flatMap((series) => series.patches);
commits.forEach((commit) => {
const upstreamMatch = upstreamCommits.find(
(upstreamCommit) => commit.remoteCommitId === upstreamCommit.id
Expand Down
Loading