mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-20 08:01:46 +03:00
connect ui to move_commit
This commit is contained in:
parent
2a07acf46e
commit
658a1ab1be
@ -6,12 +6,14 @@
|
||||
import DropzoneOverlay from './DropzoneOverlay.svelte';
|
||||
import ImgThemed from '$lib/components/ImgThemed.svelte';
|
||||
import Resizer from '$lib/components/Resizer.svelte';
|
||||
import { projectAiGenEnabled } from '$lib/config/config';
|
||||
import { projectAiGenAutoBranchNamingEnabled } from '$lib/config/config';
|
||||
import { projectAiGenEnabled } from '$lib/config/config';
|
||||
import {
|
||||
isDraggableCommit,
|
||||
isDraggableFile,
|
||||
isDraggableHunk,
|
||||
isDraggableRemoteCommit,
|
||||
type DraggableCommit,
|
||||
type DraggableFile,
|
||||
type DraggableHunk,
|
||||
type DraggableRemoteCommit
|
||||
@ -95,6 +97,13 @@
|
||||
laneWidth = lscache.get(laneWidthKey + branch.id);
|
||||
});
|
||||
|
||||
function acceptMoveCommit(data: any) {
|
||||
return isDraggableCommit(data) && data.branchId != branch.id && data.isHeadCommit;
|
||||
}
|
||||
function onCommitDrop(data: DraggableCommit) {
|
||||
branchController.moveCommit(branch.id, data.commit.id);
|
||||
}
|
||||
|
||||
function acceptCherrypick(data: any) {
|
||||
return isDraggableRemoteCommit(data) && data.branchId == branch.id;
|
||||
}
|
||||
@ -181,10 +190,18 @@
|
||||
/>
|
||||
<!-- DROPZONES -->
|
||||
<DropzoneOverlay class="cherrypick-dz-marker" label="Apply here" />
|
||||
<DropzoneOverlay class="cherrypick-dz-marker" label="Apply here" />
|
||||
<DropzoneOverlay class="lane-dz-marker" label="Move here" />
|
||||
|
||||
<div
|
||||
class="branch-card__dropzone-wrapper"
|
||||
use:dropzone={{
|
||||
hover: 'move-commit-dz-hover',
|
||||
active: 'move-commit-dz-active',
|
||||
accepts: acceptMoveCommit,
|
||||
onDrop: onCommitDrop,
|
||||
disabled: isUnapplied
|
||||
}}
|
||||
use:dropzone={{
|
||||
hover: 'cherrypick-dz-hover',
|
||||
active: 'cherrypick-dz-active',
|
||||
@ -202,6 +219,8 @@
|
||||
>
|
||||
<DropzoneOverlay class="cherrypick-dz-marker" label="Apply here" />
|
||||
<DropzoneOverlay class="lane-dz-marker" label="Move here" />
|
||||
<DropzoneOverlay class="move-commit-dz-marker" label="Move here" />
|
||||
|
||||
{#if branch.files?.length > 0}
|
||||
<div class="card">
|
||||
{#if branch.active && branch.conflicted}
|
||||
@ -428,6 +447,11 @@
|
||||
@apply flex;
|
||||
}
|
||||
|
||||
/* move commit drop zone */
|
||||
:global(.move-commit-dz-active .move-commit-dz-marker) {
|
||||
@apply flex;
|
||||
}
|
||||
|
||||
/* squash drop zone */
|
||||
:global(.squash-dz-active .squash-dz-marker) {
|
||||
@apply flex;
|
||||
|
@ -43,7 +43,7 @@
|
||||
|
||||
<div
|
||||
use:draggable={commit instanceof Commit
|
||||
? draggableCommit(commit.branchId, commit)
|
||||
? draggableCommit(commit.branchId, commit, isHeadCommit)
|
||||
: nonDraggable()}
|
||||
class="commit"
|
||||
class:is-commit-open={showFiles}
|
||||
|
@ -38,14 +38,15 @@ export function isDraggableFile(obj: any): obj is DraggableFile {
|
||||
export type DraggableCommit = {
|
||||
branchId: string;
|
||||
commit: Commit;
|
||||
isHeadCommit: boolean;
|
||||
};
|
||||
|
||||
export function draggableCommit(branchId: string, commit: Commit) {
|
||||
return { data: { branchId, commit } };
|
||||
export function draggableCommit(branchId: string, commit: Commit, isHeadCommit: boolean) {
|
||||
return { data: { branchId, commit, isHeadCommit } };
|
||||
}
|
||||
|
||||
export function isDraggableCommit(obj: any): obj is DraggableCommit {
|
||||
return obj && obj.branchId && obj.commit;
|
||||
return obj && obj.branchId && obj.commit && obj.isHeadCommit;
|
||||
}
|
||||
|
||||
export type DraggableRemoteCommit = {
|
||||
|
@ -280,4 +280,16 @@ export class BranchController {
|
||||
toasts.error(`Failed to amend commit: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async moveCommit(targetBranchId: string, commitOid: string) {
|
||||
try {
|
||||
await invoke<void>('move_commit', {
|
||||
projectId: this.projectId,
|
||||
targetBranchId,
|
||||
commitOid
|
||||
});
|
||||
} catch (err: any) {
|
||||
toasts.error(`Failed to move commit: ${err.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user