Skip to content

Commit 789d8a2

Browse files
authored
Merge pull request #9448 from gitbutlerapp/desktop-ui-excl-action-update
Update branch rename logic and add exclusiveAction branch helper
2 parents 6998f5d + 6db3893 commit 789d8a2

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

apps/desktop/src/components/MultiStackView.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,9 @@
146146
{#each mutableStacks as stack, i (stack.id)}
147147
{@const stackState = uiState.stack(stack.id)}
148148
{@const selection = stackState.selection}
149-
{@const laneWraperMinWidth = laneWidths[i] ?? 0}
150149
<div
151150
class="reorderable-stack"
152151
role="presentation"
153-
style:min-width="{laneWraperMinWidth}px"
154152
animate:flip={{ duration: 150 }}
155153
onmousedown={onReorderMouseDown}
156154
ondragstart={(e) => {

apps/desktop/src/lib/stacks/stackService.svelte.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
providesList,
1313
ReduxTag
1414
} from '$lib/state/tags';
15+
import { replaceBranchInExclusiveAction, type UiState } from '$lib/state/uiState.svelte';
1516
import { isDefined } from '@gitbutler/ui/utils/typeguards';
1617
import {
1718
createEntityAdapter,
@@ -28,7 +29,6 @@ import type { TreeChange, TreeChanges } from '$lib/hunks/change';
2829
import type { DiffSpec, Hunk } from '$lib/hunks/hunk';
2930
import type { BranchDetails, Stack, StackDetails } from '$lib/stacks/stack';
3031
import type { PropertiesFn } from '$lib/state/customHooks.svelte';
31-
import type { UiState } from '$lib/state/uiState.svelte';
3232
import type { User } from '$lib/user/user';
3333

3434
type BranchParams = {
@@ -622,15 +622,26 @@ export class StackService {
622622

623623
get updateBranchName() {
624624
return this.api.endpoints.updateBranchName.useMutation({
625-
preEffect: (args) => {
626-
const state = this.uiState.stack(args.stackId);
627-
state.selection.set(undefined);
628-
},
629625
sideEffect: (_, args) => {
630-
const state = this.uiState.stack(args.stackId);
631-
state.selection.set({
626+
// Immediately update the selection and the exclusive action.
627+
const stackState = this.uiState.stack(args.stackId);
628+
const projectState = this.uiState.project(args.projectId);
629+
const exclusiveAction = projectState.exclusiveAction.current;
630+
const previousSelection = stackState.selection.current ?? {};
631+
632+
stackState.selection.set({
633+
...previousSelection,
632634
branchName: args.newName
633635
});
636+
637+
if (exclusiveAction) {
638+
const updatedExclusiveAction = replaceBranchInExclusiveAction(
639+
exclusiveAction,
640+
args.branchName,
641+
args.newName
642+
);
643+
projectState.exclusiveAction.set(updatedExclusiveAction);
644+
}
634645
},
635646
onError: (_, args) => {
636647
const state = this.uiState.stack(args.stackId);

apps/desktop/src/lib/state/uiState.svelte.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,24 @@ export type GlobalProperty<T> = {
246246
type GlobalStore<T extends DefaultConfig> = {
247247
[K in keyof T]: GlobalProperty<T[K]>;
248248
};
249+
250+
export function replaceBranchInExclusiveAction(
251+
action: ExclusiveAction,
252+
oldBranchName: string,
253+
branchName: string
254+
): ExclusiveAction {
255+
switch (action.type) {
256+
case 'commit':
257+
if (action.branchName === oldBranchName) {
258+
return { ...action, branchName };
259+
}
260+
return action;
261+
case 'edit-commit-message':
262+
return action; // No change needed
263+
case 'create-pr':
264+
if (action.branchName === oldBranchName) {
265+
return { ...action, branchName };
266+
}
267+
return action;
268+
}
269+
}

0 commit comments

Comments
 (0)