connect ui to move_commit

This commit is contained in:
Nikita Galaiko 2024-02-19 14:43:20 +01:00
parent 2a07acf46e
commit 658a1ab1be
4 changed files with 42 additions and 5 deletions

View File

@ -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;

View File

@ -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}

View File

@ -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 = {

View File

@ -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}`);
}
}
}