Skip to content

Commit

Permalink
feat: 'Add to Workspace' context menu option
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
  • Loading branch information
traeok committed Oct 28, 2024
1 parent 0a627e0 commit 04f23d0
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen

- Update Zowe SDKs to `8.2.0` to get the latest enhancements from Imperative.
- Added expired JSON web token detection for profiles in each tree view (Data Sets, USS, Jobs). When a user performs a search on a profile, they are prompted to log in if their token expired. [#3175](https://github.com/zowe/zowe-explorer-vscode/issues/3175)
- Add Data Set or USS resources to a virtual workspace with the new "Add to Workspace" context menu option. [#3265](https://github.com/zowe/zowe-explorer-vscode/issues/3265)

### Bug fixes

Expand Down
17 changes: 17 additions & 0 deletions packages/zowe-explorer/__tests__/__mocks__/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,23 @@ export namespace workspace {
export function onDidOpenTextDocument<T>(listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]) {}
export function onDidSaveTextDocument<T>(listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]) {}

export function updateWorkspaceFolders(
start: number,
deleteCount: number | undefined | null,
...workspaceFoldersToAdd: {
/**
* The uri of a workspace folder that's to be added.
*/
readonly uri: Uri;
/**
* The name of a workspace folder that's to be added.
*/
readonly name?: string;
}[]
): boolean {
return false;
}

export function getConfiguration(configuration: string) {
return {
update: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { SharedUtils } from "../../../../src/trees/shared/SharedUtils";
import { ZoweUSSNode } from "../../../../src/trees/uss/ZoweUSSNode";
import { AuthUtils } from "../../../../src/utils/AuthUtils";
import { SharedTreeProviders } from "../../../../src/trees/shared/SharedTreeProviders";
import { MockedProperty } from "../../../__mocks__/mockUtils";

function createGlobalMocks() {
const newMocks = {
Expand Down Expand Up @@ -551,3 +552,44 @@ describe("Shared utils unit tests - function parseFavorites", () => {
expect(warnSpy).toHaveBeenCalledWith("Failed to parse a saved favorite. Attempted to parse: [testProfile]: ");
});
});

describe("Shared utils unit tests - function addToWorkspace", () => {
it("adds a Data Set resource to the workspace", () => {
const datasetNode = new ZoweDatasetNode({
label: "EXAMPLE.DS",
collapsibleState: vscode.TreeItemCollapsibleState.None,
contextOverride: Constants.DS_DS_CONTEXT,
profile: createIProfile(),
});
const updateWorkspaceFoldersMock = jest.spyOn(vscode.workspace, "updateWorkspaceFolders").mockImplementation();
SharedUtils.addToWorkspace(datasetNode, null as any);
expect(updateWorkspaceFoldersMock).toHaveBeenCalledWith(0, null, { uri: datasetNode.resourceUri, name: datasetNode.label as string });
});
it("adds a USS resource to the workspace", () => {
const ussNode = new ZoweUSSNode({
label: "textFile.txt",
collapsibleState: vscode.TreeItemCollapsibleState.None,
contextOverride: Constants.USS_TEXT_FILE_CONTEXT,
profile: createIProfile(),
});
const updateWorkspaceFoldersMock = jest.spyOn(vscode.workspace, "updateWorkspaceFolders").mockImplementation();
SharedUtils.addToWorkspace(ussNode, null as any);
expect(updateWorkspaceFoldersMock).toHaveBeenCalledWith(0, null, { uri: ussNode.resourceUri, name: ussNode.label as string });
});
it("skips adding a resource that's already in the workspace", () => {
const ussNode = new ZoweUSSNode({
label: "textFile.txt",
collapsibleState: vscode.TreeItemCollapsibleState.None,
contextOverride: Constants.USS_TEXT_FILE_CONTEXT,
profile: createIProfile(),
});
const workspaceFolders = new MockedProperty(vscode.workspace, "workspaceFolders", {
value: [{ uri: ussNode.resourceUri, name: ussNode.label }],
});
const updateWorkspaceFoldersMock = jest.spyOn(vscode.workspace, "updateWorkspaceFolders").mockImplementation();
updateWorkspaceFoldersMock.mockClear();
SharedUtils.addToWorkspace(ussNode, null as any);
expect(updateWorkspaceFoldersMock).not.toHaveBeenCalledWith(0, null, { uri: ussNode.resourceUri, name: ussNode.label as string });
workspaceFolders[Symbol.dispose]();
});
});
15 changes: 15 additions & 0 deletions packages/zowe-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@
"light": "./resources/light/favorites-open-light.svg"
}
},
{
"command": "zowe.addToWorkspace",
"title": "%addToWorkspace%",
"category": "Zowe Explorer"
},
{
"command": "zowe.ds.addSession",
"title": "%addSession%",
Expand Down Expand Up @@ -839,6 +844,11 @@
"command": "zowe.removeFavorite",
"group": "003_zowe_ussWorkspace@1"
},
{
"when": "view == zowe.uss.explorer && viewItem =~ /^(textFile.*|binaryFile.*|directory.*)/",
"command": "zowe.addToWorkspace",
"group": "003_zowe_ussWorkspace@2"
},
{
"when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection",
"command": "zowe.addFavorite",
Expand Down Expand Up @@ -1009,6 +1019,11 @@
"command": "zowe.removeFavorite",
"group": "002_zowe_dsWorkspace@1"
},
{
"when": "view == zowe.ds.explorer && viewItem =~ /^(pds|ds|migr|member).*/",
"command": "zowe.addToWorkspace",
"group": "003_zowe_dsWorkspace@2"
},
{
"when": "view == zowe.ds.explorer && viewItem == profile_fav && !listMultiSelection",
"command": "zowe.removeFavProfile",
Expand Down
1 change: 1 addition & 0 deletions packages/zowe-explorer/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"diff.overwrite": "Overwrite",
"diff.useRemote": "Use Remote",
"addFavorite": "Add to Favorites",
"addToWorkspace": "Add to Workspace",
"removeFavProfile": "Remove profile from Favorites",
"addSession": "Add Profile to Data Sets View",
"createDataset": "Create New Data Set",
Expand Down
1 change: 1 addition & 0 deletions packages/zowe-explorer/src/trees/shared/SharedInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export class SharedInit {
}
})
);
context.subscriptions.push(vscode.commands.registerCommand("zowe.addToWorkspace", SharedUtils.addToWorkspace));
context.subscriptions.push(
vscode.commands.registerCommand("zowe.removeFavProfile", (node: IZoweTreeNode) =>
SharedTreeProviders.getProviderForNode(node).removeFavProfile(node.label as string, true)
Expand Down
24 changes: 24 additions & 0 deletions packages/zowe-explorer/src/trees/shared/SharedUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,28 @@ export class SharedUtils {
public static getSessionLabel(node: IZoweTreeNode): string {
return (SharedContext.isSession(node) ? node : node.getSessionNode()).label as string;
}

/**
* Adds one or more Data Sets/USS nodes to a workspace.
* @param node Single node selection
* @param nodeList List of selected nodes
*/
public static addToWorkspace(
this: void,
node: IZoweUSSTreeNode | IZoweDatasetTreeNode,
nodeList: IZoweUSSTreeNode[] | IZoweDatasetTreeNode[]
): void {
const workspaceFolders = vscode.workspace.workspaceFolders;
const selectedNodes = SharedUtils.getSelectedNodeList(node, nodeList);
for (const item of selectedNodes) {
if (workspaceFolders?.some((folder) => folder.uri === item.resourceUri)) {
continue;
}

vscode.workspace.updateWorkspaceFolders(workspaceFolders?.length ?? 0, null, {
uri: item.resourceUri,
name: item.label as string,
});
}
}
}

0 comments on commit 04f23d0

Please # to comment.