Skip to content

Commit

Permalink
fix: harmonize commitStatus types and ensure correct color commitCard…
Browse files Browse the repository at this point in the history
… and branchHeader are rendered

fix: eslint
  • Loading branch information
ndom91 committed Oct 9, 2024
1 parent 215c375 commit 99f0b7f
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 35 deletions.
12 changes: 11 additions & 1 deletion apps/desktop/src/lib/branch/StackingBranchHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@
let meatballButtonEl = $state<HTMLDivElement>();
const currentSeries = $derived(branch.series?.find((series) => series.name === upstreamName));
const branchColorType = $derived<CommitStatus>(currentSeries?.patches[0]?.status ?? 'local');
const topPatch = $derived(currentSeries?.patches[0]);
const hasShadow = $derived.by(() => {
if (!topPatch || !topPatch.remoteCommitId) return false;
if (topPatch.remoteCommitId !== topPatch.id) return true;
return false;
});
const branchColorType = $derived<CommitStatus | 'localAndShadow'>(
hasShadow ? 'localAndShadow' : (topPatch?.status ?? 'local')
);
const lineColor = $derived(getColorFromBranchType(branchColorType));
// Pretty cumbersome way of getting the PR number, would be great if we can
Expand Down
5 changes: 2 additions & 3 deletions apps/desktop/src/lib/branch/stackingUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { CommitStatus } from '$lib/vbranches/types';

const colorMap = {
local: 'var(--clr-commit-local)',
localAndRemote: 'var(--clr-commit-remote)',
localAndShadow: 'var(--clr-commit-local)',
remote: 'var(--clr-commit-remote)',
integrated: 'var(--clr-commit-integrated)'
};

export function getColorFromBranchType(type: CommitStatus) {
export function getColorFromBranchType(type: keyof typeof colorMap): string {
return colorMap[type];
}
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/commit/StackingCommitList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
const lineManager = $derived(
lineManagerFactory.build({
remoteCommits: remoteOnlyPatches,
localCommits: patches.filter((patch) => !patch.isRemote),
localCommits: patches.filter((patch) => !patch.remoteCommitId),
localAndRemoteCommits: patches.filter((patch) => patch.remoteCommitId),
integratedCommits: patches.filter((patch) => patch.isIntegrated)
})
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/lib/stack/Stack.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
async function push() {
isPushingCommits = true;
try {
// TODO: Ensure requiresForce is bubbled up from each series to the stack here
await branchController.pushBranch(branch.id, branch.requiresForce, true);
$listingService?.refresh();
$prMonitor?.refresh();
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/src/lib/commitLinesStacking/Cell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

<div
class="commit-line stacked"
class:local={cell.type === 'Local'}
class:remote={cell.type === 'LocalRemote'}
class:local-shadow={cell.type === 'LocalShadow'}
class:upstream={cell.type === 'Upstream'}
class:integrated={cell.type === 'Integrated'}
class:local={cell.type === 'local'}
class:remote={cell.type === 'localAndRemote'}
class:local-shadow={cell.type === 'localAndShadow'}
class:upstream={cell.type === 'remote'}
class:integrated={cell.type === 'integrated'}
class:dashed={cell.style === 'dashed' || isBottom}
></div>

Expand Down
12 changes: 6 additions & 6 deletions packages/ui/src/lib/commitLinesStacking/CommitNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
);
const hoverTextShadow = $derived.by(() => {
return commitNode.type === 'LocalShadow'
return commitNode.type === 'localAndShadow'
? [
commitNode.commit?.relatedRemoteCommit?.author?.name,
commitNode.commit?.relatedRemoteCommit?.title,
Expand All @@ -34,7 +34,7 @@
</script>

<div class="container">
{#if type === 'Local'}
{#if type === 'local'}
<Tooltip text={hoverText}>
<svg
class="local-commit-dot"
Expand All @@ -47,7 +47,7 @@
<rect width="10" height="10" rx="5" />
</svg>
</Tooltip>
{:else if type === 'LocalShadow'}
{:else if type === 'localAndShadow'}
<div class="local-shadow-commit-dot">
<Tooltip text={hoverTextShadow}>
<svg
Expand Down Expand Up @@ -82,9 +82,9 @@
<Tooltip text={hoverText}>
<svg
class="generic-commit-dot"
class:remote={type === 'LocalRemote'}
class:upstream={type === 'Upstream'}
class:integrated={type === 'Integrated'}
class:remote={type === 'localAndRemote'}
class:upstream={type === 'remote'}
class:integrated={type === 'integrated'}
width="11"
height="12"
viewBox="0 0 11 12"
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/lib/commitLinesStacking/Line.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Cell cell={line.top} />
</div>
{#if line.commitNode}
<CommitNode commitNode={line.commitNode} type={line.commitNode.type ?? 'Local'} />
<CommitNode commitNode={line.commitNode} type={line.commitNode.type ?? 'local'} />
{/if}
<div class="line-bottom">
<Cell cell={line.bottom} {isBottom} />
Expand Down
40 changes: 23 additions & 17 deletions packages/ui/src/lib/commitLinesStacking/lineManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,33 @@ function generateLineData({
const integratedBranchGroups = mapToCommitLineGroupPair(integratedCommits);

remoteBranchGroups.forEach(({ commit, line }) => {
line.top.type = 'Upstream';
line.bottom.type = 'Upstream';
line.commitNode = { type: 'Upstream', commit };
line.top.type = 'remote';
line.bottom.type = 'remote';
line.commitNode = { type: 'remote', commit };
});

localBranchGroups.forEach(({ commit, line }) => {
line.top.type = 'Local';
line.bottom.type = 'Local';
line.commitNode = { type: 'Local', commit };
line.top.type = 'local';
line.bottom.type = 'local';
line.commitNode = { type: 'local', commit };
});

localAndRemoteBranchGroups.forEach(({ commit, line }) => {
line.top.type = 'LocalRemote';
line.bottom.type = 'LocalRemote';
line.commitNode = { type: 'LocalRemote', commit };
if (line.commitNode.commit.remoteCommitId !== line.commitNode.commit.id) {
line.commitNode = { type: 'localAndShadow', commit };
line.top.type = 'localAndShadow';
line.bottom.type = 'localAndShadow';
} else {
line.commitNode = { type: 'localAndRemote', commit };
line.top.type = 'localAndRemote';
line.bottom.type = 'localAndRemote';
}
});

integratedBranchGroups.forEach(({ commit, line }) => {
line.top.type = 'Integrated';
line.bottom.type = 'Integrated';
line.commitNode = { type: 'Integrated', commit };
line.top.type = 'integrated';
line.bottom.type = 'integrated';
line.commitNode = { type: 'integrated', commit };
});

const data = new Map<string, LineData>([
Expand Down Expand Up @@ -71,9 +77,9 @@ function mapToCommitLineGroupPair(commits: CommitData[]) {
const groupings = commits.map((commit) => ({
commit,
line: {
top: { type: 'Local' as CellType, style: 'solid' as Style },
bottom: { type: 'Local' as CellType, style: 'solid' as Style },
commitNode: { type: 'Local' as CellType, commit }
top: { type: 'local' as CellType, style: 'solid' as Style },
bottom: { type: 'local' as CellType, style: 'solid' as Style },
commitNode: { type: 'local' as CellType, commit }
}
}));

Expand All @@ -83,8 +89,8 @@ function mapToCommitLineGroupPair(commits: CommitData[]) {
/**
* The Line Manager assumes that the groups of commits will be in the following order:
* 1. Remote Commits (Commits you don't have in your branch)
* 2. Local Commits (Commits that you have changed locally)
* 3. LocalAndRemote Commits (Commits that exist locally and on the remote and have the same hash)
* 2. local Commits (Commits that you have changed locally)
* 3. localAndRemote Commits (Commits that exist locally and on the remote and have the same hash)
* 4. Integrated Commits (Commits that exist locally and perhaps on the remote that are in the trunk)
*/
export class LineManager {
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/lib/commitLinesStacking/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface CommitData {
// If an author is not provided, a commit node will not be drawn
author?: Author;
relatedRemoteCommit?: CommitData;
remoteCommitId?: string;
}

export type CellType = 'Local' | 'LocalRemote' | 'Integrated' | 'Upstream' | 'LocalShadow';
export type CellType = 'local' | 'localAndRemote' | 'integrated' | 'remote' | 'localAndShadow';

0 comments on commit 99f0b7f

Please sign in to comment.