Skip to content

Commit bccd34a

Browse files
authored
Merge pull request #13149 from gitbutlerapp/push-poxxrrlzmssv
Lite: fix tooltip flicker and simplify branch handling
2 parents da9ebcc + 92e38f6 commit bccd34a

9 files changed

Lines changed: 65 additions & 93 deletions

File tree

apps/lite/ui/src/domain/RefInfo.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BranchReference, type RefInfo } from "@gitbutler/but-sdk";
1+
import { type RefInfo } from "@gitbutler/but-sdk";
22

33
export const getCommonBaseCommitId = (headInfo: RefInfo): string | undefined => {
44
const bases = headInfo.stacks
@@ -20,7 +20,3 @@ export const getBranchNameByCommitId = (headInfo: RefInfo): Map<string, string>
2020

2121
return byCommitId;
2222
};
23-
24-
// TODO: move?
25-
export const getSegmentBranchRef = (refName: BranchReference) =>
26-
`refs/heads/${refName.displayName}`;

apps/lite/ui/src/routes/project/$id/-shared.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,18 @@ export const ShowCommitWithQuery: FC<{
270270

271271
export const ShowBranch: FC<{
272272
projectId: string;
273-
branchRef: string;
274273
branchName: string;
275274
remote: string | null;
276275
renderHunk: (change: TreeChange, hunk: DiffHunk, patch: Patch) => ReactNode;
277-
}> = ({ projectId, branchRef, branchName, remote, renderHunk }) => {
276+
}> = ({ projectId, branchName, remote, renderHunk }) => {
278277
const { data: branchDetails } = useSuspenseQuery(
279278
branchDetailsQueryOptions({ projectId, branchName, remote }),
280279
);
281280
const { data: branchDiff } = useSuspenseQuery(
282-
branchDiffQueryOptions({ projectId, branch: branchRef }),
281+
branchDiffQueryOptions({
282+
projectId,
283+
branch: remote !== null ? `refs/remotes/${remote}/${branchName}` : `refs/heads/${branchName}`,
284+
}),
283285
);
284286

285287
return (

apps/lite/ui/src/routes/project/$id/branches/route.tsx

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ const getBranchRemote = (branch: BranchListing) => {
4343
return branch.remotes[0] ?? null;
4444
};
4545

46-
const getBranchRef = (branch: BranchListing): string | null => {
47-
if (branch.hasLocal) return `refs/heads/${branch.name}`;
48-
const remote = branch.remotes[0];
49-
if (remote === undefined) return null;
46+
const getBranchRef = (branch: BranchListing): string => {
47+
const remote = getBranchRemote(branch);
48+
if (remote === null) return `refs/heads/${branch.name}`;
5049
return `refs/remotes/${remote}/${branch.name}`;
5150
};
5251

@@ -81,20 +80,17 @@ const BranchMenuPopup: FC<{
8180
const { Popup, Item } = parts;
8281
const applyBranch = useMutation(applyBranchMutationOptions);
8382
const unapplyStack = useMutation(unapplyStackMutationOptions);
84-
const ref = getBranchRef(branch);
8583
const stackId = branch.stack?.id;
8684

8785
return (
8886
<Popup className={classes(uiStyles.popup, uiStyles.menuPopup)}>
8987
{!branch.stack?.inWorkspace ? (
9088
<Item
9189
className={uiStyles.menuItem}
92-
disabled={ref === null}
9390
onClick={() => {
94-
if (ref === null) return;
9591
applyBranch.mutate({
9692
projectId,
97-
existingBranch: ref,
93+
existingBranch: getBranchRef(branch),
9894
});
9995
}}
10096
>
@@ -122,7 +118,6 @@ const BranchApplyToggle: FC<{
122118
}> = ({ branch, projectId }) => {
123119
const applyBranch = useMutation(applyBranchMutationOptions);
124120
const unapplyStack = useMutation(unapplyStackMutationOptions);
125-
const ref = getBranchRef(branch);
126121
const stackId = branch.stack?.id;
127122
const isApplied = branch.stack?.inWorkspace ?? false;
128123

@@ -144,13 +139,11 @@ const BranchApplyToggle: FC<{
144139
<button
145140
type="button"
146141
className={classes(sharedStyles.itemAction, styles.branchApplyToggle)}
147-
disabled={ref === null}
148142
aria-label={`Apply branch ${branch.name}`}
149143
onClick={() => {
150-
if (ref === null) return;
151144
applyBranch.mutate({
152145
projectId,
153-
existingBranch: ref,
146+
existingBranch: getBranchRef(branch),
154147
});
155148
}}
156149
>
@@ -452,22 +445,16 @@ const Preview: FC<{
452445
projectId: string;
453446
selection: Selection;
454447
remote: string | null;
455-
branchRef: string | null;
456-
}> = ({ projectId, selection, remote, branchRef }) =>
448+
}> = ({ projectId, selection, remote }) =>
457449
Match.value(selection).pipe(
458-
Match.tag("Branch", ({ branchName }) =>
459-
branchRef !== null ? (
460-
<ShowBranch
461-
projectId={projectId}
462-
branchRef={branchRef}
463-
branchName={branchName}
464-
remote={remote}
465-
renderHunk={(change, hunk) => <Hunk change={change} hunk={hunk} />}
466-
/>
467-
) : (
468-
<div>No branch diff available.</div>
469-
),
470-
),
450+
Match.tag("Branch", ({ branchName }) => (
451+
<ShowBranch
452+
projectId={projectId}
453+
branchName={branchName}
454+
remote={remote}
455+
renderHunk={(change, hunk) => <Hunk change={change} hunk={hunk} />}
456+
/>
457+
)),
471458
Match.tag("Commit", ({ branchName, commitId, mode }) =>
472459
mode._tag === "Details" && mode.path !== undefined ? (
473460
<ShowBranchCommitFile
@@ -520,7 +507,6 @@ const ProjectBranchesPage: FC = () => {
520507
<Preview
521508
projectId={projectId}
522509
selection={selection}
523-
branchRef={getBranchRef(selectedBranch)}
524510
remote={getBranchRemote(selectedBranch)}
525511
/>
526512
</Suspense>

apps/lite/ui/src/routes/project/$id/workspace/-Editing.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export type EditingCommit = {
22
stackId: string;
33
segmentIndex: number;
44
branchName: string | null;
5-
branchRef: string | null;
65
commitId: string;
76
};
87

apps/lite/ui/src/routes/project/$id/workspace/-Item.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCommonBaseCommitId, getSegmentBranchRef } from "#ui/domain/RefInfo.ts";
1+
import { getCommonBaseCommitId } from "#ui/domain/RefInfo.ts";
22
import { WorktreeChanges, type RefInfo } from "@gitbutler/but-sdk";
33
import { Match } from "effect";
44

@@ -9,7 +9,6 @@ export type SegmentItem = {
99
stackId: string;
1010
segmentIndex: number;
1111
branchName: string | null;
12-
branchRef: string | null;
1312
};
1413

1514
type CommitMode = { _tag: "Summary" } | { _tag: "Details"; path?: string };
@@ -35,32 +34,24 @@ export const changesDetailsItem = (stackId: string | null, path?: string): Item
3534
mode: { _tag: "Details", path },
3635
});
3736

38-
export const segmentItem = ({
39-
stackId,
40-
segmentIndex,
41-
branchName,
42-
branchRef,
43-
}: SegmentItem): Item => ({
37+
export const segmentItem = ({ stackId, segmentIndex, branchName }: SegmentItem): Item => ({
4438
_tag: "Segment",
4539
stackId,
4640
segmentIndex,
4741
branchName,
48-
branchRef,
4942
});
5043

5144
export const commitItem = ({
5245
stackId,
5346
segmentIndex,
5447
branchName,
55-
branchRef,
5648
commitId,
5749
mode = { _tag: "Summary" },
5850
}: Omit<CommitItem, "mode"> & { mode?: CommitItem["mode"] }): Item => ({
5951
_tag: "Commit",
6052
stackId,
6153
segmentIndex,
6254
branchName,
63-
branchRef,
6455
commitId,
6556
mode,
6657
});
@@ -126,8 +117,7 @@ export const normalizeItem = (
126117
const segment = stack.segments[item.segmentIndex];
127118
if (!segment) return null;
128119
const branchName = segment.refName?.displayName ?? null;
129-
const branchRef = segment.refName ? getSegmentBranchRef(segment.refName) : null;
130-
if (branchName !== item.branchName || branchRef !== item.branchRef) return null;
120+
if (branchName !== item.branchName) return null;
131121
return item;
132122
}),
133123
Match.tag("Commit", (item) => {

apps/lite/ui/src/routes/project/$id/workspace/-Selection.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getSegmentBranchRef } from "#ui/domain/RefInfo.ts";
21
import { type HunkAssignment, type RefInfo, type TreeChange } from "@gitbutler/but-sdk";
32
import {
43
baseCommitItem,
@@ -72,12 +71,10 @@ export const buildNavigationModel = ({
7271

7372
for (const [segmentIndex, segment] of stack.segments.entries()) {
7473
const branchName = segment.refName?.displayName ?? null;
75-
const branchRef = segment.refName ? getSegmentBranchRef(segment.refName) : null;
7674
const section = segmentItem({
7775
stackId: stack.id,
7876
segmentIndex,
7977
branchName,
80-
branchRef,
8178
});
8279
const sectionIndex = sections.length;
8380
sections.push(section);
@@ -90,7 +87,6 @@ export const buildNavigationModel = ({
9087
stackId: stack.id,
9188
segmentIndex,
9289
branchName,
93-
branchRef,
9490
commitId: commit.id,
9591
});
9692
indexByKey.set(itemKey(commitItemV), items.length);

apps/lite/ui/src/routes/project/$id/workspace/-WorkspaceShortcuts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export const getScope = ({
367367
bindings: renameBranchBindings,
368368
context: selection,
369369
}
370-
: selection.branchName === null || selection.branchRef === null
370+
: selection.branchName === null
371371
? {
372372
_tag: "Segment",
373373
bindings: selectionBindings,

apps/lite/ui/src/routes/project/$id/workspace/route.module.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@
6262
white-space: nowrap;
6363
}
6464

65-
.segmentButtonPending {
66-
opacity: 0.5;
67-
}
68-
6965
.renameBranchInput {
7066
font-weight: bold;
7167
}

0 commit comments

Comments
 (0)