Skip to content

Commit 953a579

Browse files
authored
Merge pull request #10643 from gitbutlerapp/drag-branch-ui-fix
fix: Only the branch header is draggable
2 parents c0ac005 + f91a78b commit 953a579

File tree

2 files changed

+57
-24
lines changed

2 files changed

+57
-24
lines changed

apps/desktop/src/components/BranchCard.svelte

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { CodegenRuleDropData, CodegenRuleDropHandler } from '$lib/codegen/dropzone';
1717
import { useGoToCodegenPage } from '$lib/codegen/redirect.svelte';
1818
import { MoveCommitDzHandler } from '$lib/commits/dropHandler';
19-
import { draggableBranch, draggableChips } from '$lib/dragging/draggable';
19+
import { draggableChips } from '$lib/dragging/draggable';
2020
import { DROPZONE_REGISTRY } from '$lib/dragging/registry';
2121
import { ReorderCommitDzHandler } from '$lib/dragging/stackingReorderDropzoneManager';
2222
import { DEFAULT_FORGE_FACTORY } from '$lib/forge/forgeFactory.svelte';
@@ -154,25 +154,6 @@
154154
class:draft={args.type === 'draft-branch'}
155155
data-series-name={branchName}
156156
data-testid={TestId.BranchCard}
157-
data-remove-from-panning
158-
use:draggableBranch={{
159-
disabled: args.type !== 'stack-branch' || args.isConflicted,
160-
label: branchName,
161-
pushStatus: args.type === 'stack-branch' ? args.pushStatus : undefined,
162-
viewportId: 'board-viewport',
163-
data:
164-
args.type === 'stack-branch' && args.stackId
165-
? new BranchDropData(
166-
args.stackId,
167-
branchName,
168-
args.isConflicted,
169-
args.numberOfBranchesInStack,
170-
args.numberOfCommits
171-
)
172-
: undefined,
173-
dropzoneRegistry,
174-
dragStateService
175-
}}
176157
>
177158
{#if args.type === 'stack-branch'}
178159
{@const moveHandler = args.stackId
@@ -220,6 +201,22 @@
220201
onclick={args.onclick}
221202
menu={args.menu}
222203
conflicts={args.isConflicted}
204+
dragArgs={{
205+
disabled: args.isConflicted,
206+
label: branchName,
207+
pushStatus: args.pushStatus,
208+
viewportId: 'board-viewport',
209+
data:
210+
args.type === 'stack-branch' && args.stackId
211+
? new BranchDropData(
212+
args.stackId,
213+
branchName,
214+
args.isConflicted,
215+
args.numberOfBranchesInStack,
216+
args.numberOfCommits
217+
)
218+
: undefined
219+
}}
223220
>
224221
{#snippet buttons()}
225222
{#if args.buttons}

apps/desktop/src/components/BranchHeader.svelte

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
<!-- BRANCH HEADER PURE COMPONENT -->
2-
<!-- ONLY CONCERNED ABOUT STYLE 😎 -->
1+
<script lang="ts" module>
2+
export type DragableBranchData = {
3+
disabled: boolean;
4+
label: string;
5+
pushStatus: PushStatus | undefined;
6+
viewportId: string;
7+
data: BranchDropData | undefined;
8+
};
9+
</script>
10+
311
<script lang="ts">
412
import BranchHeaderIcon from '$components/BranchHeaderIcon.svelte';
513
import BranchLabel from '$components/BranchLabel.svelte';
14+
import { BranchDropData } from '$lib/branches/dropHandler';
15+
import { draggableBranch, type DraggableConfig } from '$lib/dragging/draggable';
16+
import { DROPZONE_REGISTRY } from '$lib/dragging/registry';
17+
import { inject } from '@gitbutler/core/context';
618
import { Badge } from '@gitbutler/ui';
719
import { TestId } from '@gitbutler/ui';
20+
import { DRAG_STATE_SERVICE } from '@gitbutler/ui/drag/dragStateService.svelte';
821
import { focusable } from '@gitbutler/ui/focus/focusable';
922
import { slide } from 'svelte/transition';
23+
import type { PushStatus } from '$lib/stacks/stack';
1024
import type iconsJson from '@gitbutler/ui/data/icons.json';
1125
import type { Snippet } from 'svelte';
1226
@@ -29,6 +43,7 @@
2943
content?: Snippet;
3044
menu?: Snippet<[{ rightClickTrigger: HTMLElement }]>;
3145
buttons?: Snippet;
46+
dragArgs?: DragableBranchData;
3247
};
3348
3449
const {
@@ -49,13 +64,32 @@
4964
emptyState,
5065
content,
5166
menu,
52-
buttons
67+
buttons,
68+
dragArgs
5369
}: Props = $props();
5470
71+
const dropzoneRegistry = inject(DROPZONE_REGISTRY);
72+
const dragStateService = inject(DRAG_STATE_SERVICE);
73+
5574
let rightClickTrigger = $state<HTMLDivElement>();
5675
let active = $state(false);
5776
5877
const actionsVisible = $derived(!draft && !isCommitting && (buttons || menu));
78+
79+
const draggableBranchConfig = $derived.by<DraggableConfig>(() => {
80+
if (!dragArgs) {
81+
return {
82+
disabled: true,
83+
dropzoneRegistry,
84+
dragStateService
85+
};
86+
}
87+
return {
88+
...dragArgs,
89+
dropzoneRegistry,
90+
dragStateService
91+
};
92+
});
5993
</script>
6094

6195
<div
@@ -79,6 +113,8 @@
79113
{onclick}
80114
onkeypress={onclick}
81115
tabindex="0"
116+
data-remove-from-panning
117+
use:draggableBranch={draggableBranchConfig}
82118
>
83119
{#if selected && !draft}
84120
<div
@@ -122,7 +158,7 @@
122158
</div>
123159

124160
{#if actionsVisible}
125-
<div class="branch-hedaer__actions-row" class:draft class:new-branch={isEmpty}>
161+
<div class="branch-hedaer__actions-row" class:draft class:new-branch={isEmpty} data-no-drag>
126162
{#if buttons}
127163
<div class="text-12 branch-header__actions">
128164
{@render buttons()}

0 commit comments

Comments
 (0)