Skip to content

Commit d64f321

Browse files
authored
Merge pull request #13143 from gitbutlerapp/push-pnyuqkroppvo
Lite: add ability to drag and drop uncommitted changes onto a branch
2 parents fae9e59 + 5d6ae94 commit d64f321

3 files changed

Lines changed: 60 additions & 22 deletions

File tree

apps/lite/ui/src/Operation.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { Toast } from "@base-ui/react";
22
import { useMutation } from "@tanstack/react-query";
33
import { Match } from "effect";
4-
import { CommitMoveParams, MoveBranchParams, TearOffBranchParams } from "#electron/ipc.ts";
4+
import {
5+
CommitCreateParams,
6+
CommitMoveParams,
7+
MoveBranchParams,
8+
TearOffBranchParams,
9+
} from "#electron/ipc.ts";
510
import { rejectedChangesToastOptions } from "#ui/components/RejectedChanges.tsx";
611
import {
12+
commitCreateMutationOptions,
713
commitMoveMutationOptions,
814
moveBranchMutationOptions,
915
rubMutationOptions,
@@ -15,13 +21,15 @@ export type RubOperation = Omit<RubParams, "projectId">;
1521

1622
export type Operation =
1723
| ({ _tag: "Rub" } & RubOperation)
24+
| ({ _tag: "CommitCreate" } & Omit<CommitCreateParams, "projectId">)
1825
| ({ _tag: "CommitMove" } & Omit<CommitMoveParams, "projectId">)
1926
| ({ _tag: "MoveBranch" } & Omit<MoveBranchParams, "projectId">)
2027
| ({ _tag: "TearOffBranch" } & Omit<TearOffBranchParams, "projectId">);
2128

2229
export const useRunOperation = (projectId: string) => {
2330
const toastManager = Toast.useToastManager();
2431
const rubMutation = useMutation(rubMutationOptions);
32+
const commitCreate = useMutation(commitCreateMutationOptions);
2533
const commitMove = useMutation(commitMoveMutationOptions);
2634
const moveBranch = useMutation(moveBranchMutationOptions);
2735
const tearOffBranch = useMutation(tearOffBranchMutationOptions);
@@ -50,6 +58,28 @@ export const useRunOperation = (projectId: string) => {
5058
},
5159
);
5260
}),
61+
Match.tag("CommitCreate", (operation) => {
62+
commitCreate.mutate(
63+
{
64+
projectId,
65+
relativeTo: operation.relativeTo,
66+
side: operation.side,
67+
changes: operation.changes,
68+
message: operation.message,
69+
},
70+
{
71+
onSuccess: (response) => {
72+
if (response.rejectedChanges.length > 0)
73+
toastManager.add(
74+
rejectedChangesToastOptions({
75+
newCommit: response.newCommit,
76+
rejectedChanges: response.rejectedChanges,
77+
}),
78+
);
79+
},
80+
},
81+
);
82+
}),
5383
Match.tag("CommitMove", (operation) => {
5484
commitMove.mutate({
5585
projectId,

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
.unassignedChangesLane {
2-
display: flex;
1+
.unassignedChanges {
32
flex-shrink: 0;
4-
flex-direction: column;
53
width: 300px;
4+
border: 1px dotted var(--color-separator);
65
}
76

87
.stackLane {
@@ -26,11 +25,6 @@
2625
width: 300px;
2726
}
2827

29-
.unassignedChanges {
30-
flex-grow: 1;
31-
border: 1px dotted var(--color-separator);
32-
}
33-
3428
.assignedChanges {
3529
min-height: 80px;
3630
border: 1px dotted var(--color-separator);

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

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,21 @@ const BranchTarget: FC<
13511351
side: "below",
13521352
};
13531353
}),
1354+
Match.tag("TreeChanges", ({ source }): Operation | null => {
1355+
if (anchorRef === null || source.parent._tag !== "Changes") return null;
1356+
return {
1357+
_tag: "CommitCreate",
1358+
relativeTo: {
1359+
type: "referenceBytes",
1360+
subject: anchorRef,
1361+
},
1362+
side: "below",
1363+
changes: source.changes.map(({ change, hunkHeaders }) =>
1364+
createDiffSpec(change, hunkHeaders),
1365+
),
1366+
message: "",
1367+
};
1368+
}),
13541369
Match.orElse(() => null),
13551370
);
13561371

@@ -1371,6 +1386,7 @@ const BranchTarget: FC<
13711386
const tooltip = operation
13721387
? Match.value(operation).pipe(
13731388
Match.tag("MoveBranch", () => "Stack branch onto here"),
1389+
Match.tag("CommitCreate", () => "Commit changes here"),
13741390
Match.tag("CommitMove", () => "Move commit here"),
13751391
Match.orElse(() => null),
13761392
)
@@ -1860,18 +1876,16 @@ const ProjectPage: FC = () => {
18601876
}
18611877
>
18621878
<div className={sharedStyles.lanes}>
1863-
<div className={styles.unassignedChangesLane}>
1864-
<Changes
1865-
label="Unassigned changes"
1866-
projectId={project.id}
1867-
stackId={null}
1868-
onAbsorbChanges={requestAbsorptionPlan}
1869-
onDependencyHover={highlightCommits}
1870-
selection={selection}
1871-
select={select}
1872-
className={styles.unassignedChanges}
1873-
/>
1874-
</div>
1879+
<Changes
1880+
label="Unassigned changes"
1881+
projectId={project.id}
1882+
stackId={null}
1883+
onAbsorbChanges={requestAbsorptionPlan}
1884+
onDependencyHover={highlightCommits}
1885+
selection={selection}
1886+
select={select}
1887+
className={styles.unassignedChanges}
1888+
/>
18751889

18761890
<div className={styles.headInfo}>
18771891
<div className={styles.stackLanes}>
@@ -1904,7 +1918,7 @@ const ProjectPage: FC = () => {
19041918
>
19051919
<button
19061920
type="button"
1907-
className={classes(styles.commonBaseCommit)}
1921+
className={styles.commonBaseCommit}
19081922
onClick={() => {
19091923
select(baseCommitItem(commonBaseCommitId));
19101924
setEditing(null);

0 commit comments

Comments
 (0)