Skip to content

Commit c9608d1

Browse files
Merge pull request #9441 from gitbutlerapp/remove-any-file-based-draggers
Remove old drophandler
2 parents b80db74 + 86699f6 commit c9608d1

File tree

5 files changed

+8
-174
lines changed

5 files changed

+8
-174
lines changed
Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { type BranchStack } from '$lib/branches/branch';
2-
import { filesToOwnership } from '$lib/branches/ownership';
3-
import { HunkDropData, FileDropData } from '$lib/dragging/draggables';
4-
import { LocalFile } from '$lib/files/file';
2+
import { HunkDropData } from '$lib/dragging/draggables';
53
import { StackService } from '$lib/stacks/stackService.svelte';
64
import type { DropzoneHandler } from '$lib/dragging/handler';
75
/** Handler that moves uncommitted hunks between stacks. */
@@ -30,31 +28,3 @@ export class BranchHunkDzHandler implements DropzoneHandler {
3028
});
3129
}
3230
}
33-
34-
/** Handler that moves uncommitted files between stacks. */
35-
export class BranchFileDzHandler implements DropzoneHandler {
36-
constructor(
37-
private stackService: StackService,
38-
private projectId: string,
39-
private stackId: string,
40-
private ownership: string
41-
) {}
42-
43-
accepts(data: unknown) {
44-
return (
45-
data instanceof FileDropData &&
46-
data.file instanceof LocalFile &&
47-
this.stackId !== data.stackId &&
48-
!data.files.some((f) => f.locked)
49-
);
50-
}
51-
52-
ondrop(data: FileDropData) {
53-
const newOwnership = filesToOwnership(data.files);
54-
this.stackService.legacyUpdateBranchOwnership({
55-
projectId: this.projectId,
56-
stackId: this.stackId,
57-
ownership: (newOwnership + '\n' + this.ownership).trim()
58-
});
59-
}
60-
}

apps/desktop/src/lib/commits/dropHandler.ts

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { changesToDiffSpec } from '$lib/commits/utils';
2-
import {
3-
ChangeDropData,
4-
FileDropData,
5-
HunkDropData,
6-
HunkDropDataV3
7-
} from '$lib/dragging/draggables';
8-
import { LocalFile, RemoteFile } from '$lib/files/file';
2+
import { ChangeDropData, HunkDropData, HunkDropDataV3 } from '$lib/dragging/draggables';
93
import { untrack } from 'svelte';
104
import type { DropzoneHandler } from '$lib/dragging/handler';
11-
import type { DiffSpec } from '$lib/hunks/hunk';
125
import type { StackService } from '$lib/stacks/stackService.svelte';
136
import type { UiState } from '$lib/state/uiState.svelte';
147

@@ -379,57 +372,6 @@ export class AmendCommitWithHunkDzHandler implements DropzoneHandler {
379372
}
380373
}
381374

382-
/**
383-
* Handler that is able to amend a commit using `AnyFile`.
384-
*/
385-
export class AmendCommitDzHandler implements DropzoneHandler {
386-
constructor(
387-
private args: {
388-
stackService: StackService;
389-
okWithForce: boolean;
390-
projectId: string;
391-
stackId: string;
392-
commit: DzCommitData;
393-
}
394-
) {}
395-
396-
accepts(dropData: unknown): boolean {
397-
const { stackId, commit, okWithForce } = this.args;
398-
if (!okWithForce && commit.isRemote) return false;
399-
if (commit.isIntegrated) return false;
400-
return (
401-
dropData instanceof FileDropData &&
402-
dropData.stackId === stackId &&
403-
dropData.commit?.id !== commit.id &&
404-
!commit.hasConflicts
405-
);
406-
}
407-
408-
ondrop(data: FileDropData): void {
409-
const { stackService, projectId, stackId, commit } = this.args;
410-
if (data.file instanceof LocalFile) {
411-
stackService.amendCommitMutation({
412-
projectId,
413-
stackId,
414-
commitId: commit.id,
415-
worktreeChanges: filesToDiffSpec(data)
416-
});
417-
} else if (data.file instanceof RemoteFile) {
418-
// this is a file from a commit, rather than an uncommitted file
419-
if (data.commit) {
420-
stackService.moveChangesBetweenCommits({
421-
projectId,
422-
destinationStackId: stackId,
423-
destinationCommitId: commit.id,
424-
sourceStackId: data.stackId,
425-
sourceCommitId: data.commit.id,
426-
changes: filesToDiffSpec(data)
427-
});
428-
}
429-
}
430-
}
431-
}
432-
433375
/**
434376
* Handler that is able to squash two commits using `DzCommitData`.
435377
*/
@@ -467,17 +409,6 @@ export class SquashCommitDzHandler implements DropzoneHandler {
467409
}
468410
}
469411

470-
/** Helper function that converts `FileDropData` to `DiffSpec`. */
471-
function filesToDiffSpec(data: FileDropData): DiffSpec[] {
472-
return data.files.map((file) => {
473-
return {
474-
previousPathBytes: null,
475-
pathBytes: file.path as any, // Rust type is BString.
476-
hunkHeaders: []
477-
};
478-
});
479-
}
480-
481412
function updateUiState(
482413
uiState: UiState,
483414
stackId: string,

apps/desktop/src/lib/dragging/draggable.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getColorFromCommitState } from '$components/lib';
22
import { type CommitStatusType } from '$lib/commits/commit';
3-
import { FileDropData, ChangeDropData, type DropData } from '$lib/dragging/draggables';
3+
import { ChangeDropData, type DropData } from '$lib/dragging/draggables';
44
import { getFileIcon } from '@gitbutler/ui/file/getFileIcon';
55
import { pxToRem } from '@gitbutler/ui/utils/pxToRem';
66
import type { DragStateService } from '$lib/dragging/dragStateService.svelte';
@@ -85,27 +85,6 @@ function setupDragHandlers(
8585
endDragging = opts.dragStateService.startDragging();
8686
}
8787

88-
// This should be deleted once V3 design has shipped.
89-
if (opts.data instanceof FileDropData) {
90-
selectedElements = [];
91-
for (const file of opts.data.files) {
92-
const element = parentNode.querySelector(`[data-file-id="${file.id}"]`);
93-
if (element) {
94-
if (file.locked) {
95-
element.classList.add('locked-file-animation');
96-
element.addEventListener(
97-
'animationend',
98-
() => {
99-
element.classList.remove('locked-file-animation');
100-
},
101-
{ once: true }
102-
);
103-
}
104-
selectedElements.push(element);
105-
}
106-
}
107-
}
108-
10988
if (opts.data instanceof ChangeDropData) {
11089
selectedElements = [];
11190
for (const path of opts.data.changedPaths(opts.data.selectionId)) {

apps/desktop/src/lib/dragging/draggables.ts

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { key, type SelectionId } from '$lib/selection/key';
2-
import { get, type Readable } from 'svelte/store';
3-
import type { AnyCommit } from '$lib/commits/commit';
42
import type { CommitDropData } from '$lib/commits/dropHandler';
5-
import type { AnyFile } from '$lib/files/file';
63
import type { TreeChange } from '$lib/hunks/change';
74
import type { Hunk, HunkAssignment, HunkHeader, HunkLock } from '$lib/hunks/hunk';
85
import type { IdSelection } from '$lib/selection/idSelection.svelte';
@@ -84,38 +81,4 @@ export class ChangeDropData {
8481
}
8582
}
8683

87-
export class FileDropData {
88-
constructor(
89-
readonly stackId: string,
90-
readonly file: AnyFile,
91-
readonly commit: AnyCommit | undefined,
92-
/**
93-
* When a a file is dragged we compare it to what is already selected,
94-
* if dragged item is part of the selection we consider that to be to
95-
* be dragging all of them. If it is not part of the selection, we
96-
* want to ignore what is selected and only drag the actual file being
97-
* dragged.
98-
*/
99-
private selection: Readable<AnyFile[]> | undefined
100-
) {}
101-
102-
get files(): AnyFile[] {
103-
const selectedFiles = this.selection ? get(this.selection) : undefined;
104-
if (selectedFiles?.some((selectedFile) => selectedFile.id === this.file.id)) {
105-
return selectedFiles;
106-
} else {
107-
return [this.file];
108-
}
109-
}
110-
111-
get isCommitted(): boolean {
112-
return !!this.commit;
113-
}
114-
}
115-
116-
export type DropData =
117-
| FileDropData
118-
| HunkDropData
119-
| CommitDropData
120-
| ChangeDropData
121-
| HunkDropDataV3;
84+
export type DropData = HunkDropData | CommitDropData | ChangeDropData | HunkDropDataV3;

apps/desktop/src/lib/stacks/dropHandler.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { filesToOwnership } from '$lib/branches/ownership';
21
import { changesToDiffSpec } from '$lib/commits/utils';
3-
import { ChangeDropData, FileDropData, HunkDropData } from '$lib/dragging/draggables';
2+
import { ChangeDropData, HunkDropData } from '$lib/dragging/draggables';
43
import StackMacros from '$lib/stacks/macros';
54
import type { DropzoneHandler } from '$lib/dragging/handler';
65
import type { DiffService } from '$lib/hunks/diffService.svelte';
@@ -16,23 +15,15 @@ export class NewStackDzHandler implements DropzoneHandler {
1615
) {}
1716

1817
accepts(data: unknown) {
19-
if (data instanceof FileDropData) {
20-
return !(data.isCommitted || data.files.some((f) => f.locked));
21-
}
2218
if (data instanceof HunkDropData) {
2319
return !(data.isCommitted || data.hunk.locked);
2420
}
2521
return false;
2622
}
2723

28-
ondrop(data: FileDropData | HunkDropData) {
29-
if (data instanceof HunkDropData) {
30-
const ownership = `${data.hunk.filePath}:${data.hunk.id}`;
31-
this.stackService.newStackMutation({ projectId: this.projectId, branch: { ownership } });
32-
} else if (data instanceof FileDropData) {
33-
const ownership = filesToOwnership(data.files);
34-
this.stackService.newStackMutation({ projectId: this.projectId, branch: { ownership } });
35-
}
24+
ondrop(data: HunkDropData) {
25+
const ownership = `${data.hunk.filePath}:${data.hunk.id}`;
26+
this.stackService.newStackMutation({ projectId: this.projectId, branch: { ownership } });
3627
}
3728
}
3829

0 commit comments

Comments
 (0)