Skip to content

Commit 2401d29

Browse files
Scott DoverScott Dover
authored andcommitted
fix: fix move issue
Signed-off-by: Scott Dover <[email protected]>
1 parent 589a62b commit 2401d29

File tree

6 files changed

+55
-25
lines changed

6 files changed

+55
-25
lines changed

client/src/components/ContentNavigator/ContentDataProvider.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import {
1414
FileType,
1515
Position,
1616
ProviderResult,
17-
Tab,
18-
TabInputNotebook,
19-
TabInputText,
2017
TextDocument,
2118
TextDocumentContentProvider,
2219
ThemeIcon,
@@ -54,7 +51,11 @@ import {
5451
ContentNavigatorConfig,
5552
FileManipulationEvent,
5653
} from "./types";
57-
import { getFileStatement, isContainer as getIsContainer } from "./utils";
54+
import {
55+
getEditorTabForItem,
56+
getFileStatement,
57+
isContainer as getIsContainer,
58+
} from "./utils";
5859

5960
class ContentDataProvider
6061
implements
@@ -502,6 +503,27 @@ class ContentDataProvider
502503
return this.getChildren(selection);
503504
}
504505

506+
private async moveItem(
507+
item: ContentItem,
508+
targetUri: string,
509+
): Promise<boolean> {
510+
if (!targetUri) {
511+
return false;
512+
}
513+
514+
const closing = closeFileIfOpen(item);
515+
if (!(await closing)) {
516+
return false;
517+
}
518+
519+
const newUri = await this.model.moveTo(item, targetUri);
520+
if (closing !== true) {
521+
commands.executeCommand("vscode.open", newUri);
522+
}
523+
524+
return !!newUri;
525+
}
526+
505527
private async handleContentItemDrop(
506528
target: ContentItem,
507529
item: ContentItem,
@@ -518,10 +540,7 @@ class ContentDataProvider
518540
success = await this.addToMyFavorites(item);
519541
} else {
520542
const targetUri = target.resourceId;
521-
if (targetUri) {
522-
success = await this.model.moveTo(item, targetUri);
523-
}
524-
543+
success = await this.moveItem(item, targetUri);
525544
if (success) {
526545
this.refresh();
527546
}
@@ -676,14 +695,7 @@ class ContentDataProvider
676695
export default ContentDataProvider;
677696

678697
const closeFileIfOpen = (item: ContentItem) => {
679-
const fileUri = item.vscUri;
680-
const tabs: Tab[] = window.tabGroups.all.map((tg) => tg.tabs).flat();
681-
const tab = tabs.find(
682-
(tab) =>
683-
(tab.input instanceof TabInputText ||
684-
tab.input instanceof TabInputNotebook) &&
685-
tab.input.uri.query === fileUri.query, // compare the file id
686-
);
698+
const tab = getEditorTabForItem(item);
687699
if (tab) {
688700
return window.tabGroups.close(tab);
689701
}

client/src/components/ContentNavigator/ContentModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class ContentModel {
127127
public async moveTo(
128128
item: ContentItem,
129129
targetParentFolderUri: string,
130-
): Promise<boolean> {
130+
): Promise<boolean | Uri> {
131131
return await this.contentAdapter.moveItem(item, targetParentFolderUri);
132132
}
133133

client/src/components/ContentNavigator/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export interface ContentAdapter {
8989
moveItem: (
9090
item: ContentItem,
9191
targetParentFolderUri: string,
92-
) => Promise<boolean>;
92+
) => Promise<Uri | undefined>;
9393
recycleItem?: (item: ContentItem) => Promise<{ newUri?: Uri; oldUri?: Uri }>;
9494
removeItemFromFavorites: (item: ContentItem) => Promise<boolean>;
9595
renameItem: (

client/src/components/ContentNavigator/utils.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import { FileType, SnippetString } from "vscode";
3+
import {
4+
FileType,
5+
SnippetString,
6+
Tab,
7+
TabInputNotebook,
8+
TabInputText,
9+
window,
10+
} from "vscode";
411

512
import { DEFAULT_FILE_CONTENT_TYPE } from "./const";
613
import mimeTypes from "./mime-types";
@@ -76,3 +83,14 @@ export const createStaticFolder = (
7683
},
7784
],
7885
});
86+
87+
export const getEditorTabForItem = (item: ContentItem) => {
88+
const fileUri = item.vscUri;
89+
const tabs: Tab[] = window.tabGroups.all.map((tg) => tg.tabs).flat();
90+
return tabs.find(
91+
(tab) =>
92+
(tab.input instanceof TabInputText ||
93+
tab.input instanceof TabInputNotebook) &&
94+
tab.input.uri.query === fileUri.query, // compare the file id
95+
);
96+
};

client/src/connection/rest/RestSASServerAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class RestSASServerAdapter implements ContentAdapter {
325325
public async moveItem(
326326
item: ContentItem,
327327
targetParentFolderUri: string,
328-
): Promise<boolean> {
328+
): Promise<Uri | undefined> {
329329
const currentFilePath = this.trimComputePrefix(item.uri);
330330
const newFilePath = this.trimComputePrefix(targetParentFolderUri);
331331
const { etag } = await this.getFileInfo(currentFilePath, true);
@@ -344,7 +344,7 @@ class RestSASServerAdapter implements ContentAdapter {
344344
delete this.fileMetadataMap[currentFilePath];
345345
this.updateFileMetadata(newFilePath, response);
346346

347-
return !!this.filePropertiesToContentItem(response.data);
347+
return this.filePropertiesToContentItem(response.data).vscUri;
348348
}
349349

350350
public async renameItem(

client/src/connection/rest/SASContentAdapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,15 @@ class SASContentAdapter implements ContentAdapter {
187187
public async moveItem(
188188
item: ContentItem,
189189
parentFolderUri: string,
190-
): Promise<boolean> {
190+
): Promise<Uri | undefined> {
191191
const newItemData = { ...item, parentFolderUri };
192192
const updateLink = getLink(item.links, "PUT", "update");
193193
try {
194-
await this.connection.put(updateLink.uri, newItemData);
194+
const response = await this.connection.put(updateLink.uri, newItemData);
195+
return this.enrichWithDataProviderProperties(response.data).vscUri;
195196
} catch (error) {
196-
return false;
197+
return;
197198
}
198-
return true;
199199
}
200200

201201
private async generatedMembersUrlForParentItem(

0 commit comments

Comments
 (0)