diff --git a/packages/zowe-explorer-api/CHANGELOG.md b/packages/zowe-explorer-api/CHANGELOG.md index d1ae90f616..c6f0b8c760 100644 --- a/packages/zowe-explorer-api/CHANGELOG.md +++ b/packages/zowe-explorer-api/CHANGELOG.md @@ -39,6 +39,67 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t - Added the `onVaultUpdate` VSCode event to notify extenders when credentials are updated on the OS vault by other applications. [#2994](https://github.com/zowe/zowe-explorer-vscode/pull/2994) - Added the `onCredMgrsUpdate` VSCode event to notify extenders when the local PC's credential manager has been updated by other applications. [#2994](https://github.com/zowe/zowe-explorer-vscode/pull/2994) - **Breaking:** Updated most function signatures for exported programmatic interfaces. Changes make developing with the Zowe Explorer API more efficient for extenders by showing which properties they can expect when calling our APIs. [#2952](https://github.com/zowe/zowe-explorer-vscode/issues/2952) +- **LTS Breaking:** Updated most function signatures for exported programmatic interfaces. Changes make developing with the Zowe Explorer API more efficient for extenders by showing which properties they can expect when calling our APIs. [#2952](https://github.com/zowe/zowe-explorer-vscode/issues/2952) + + - Updated `IApiExplorerExtender.ts`, see changes below: + - Allowed `reloadProfiles` and `initForZowe` to be synchronous methods (non-breaking) + - Updated `MainframeInteraction.ts`, see changes below: + - Modified `getStatus` to add `string` type to the optional parameter `profileType` + - Updated `IZoweTree.ts`, see changes below: + + - Modified `checkCurrentProfile(node: IZoweTreeNode);` to return `Validation.IValidationProfile | Promise` + - Modified `getSearchHistory()` to return `string[]` + - Modified `getAllLoadedItems()` to return `IZoweTreeNode[] | Promise` + - Modified `getFileHistory()` to return `string[]` + - Modified `createFilterString?(newFilter: string, node: IZoweTreeNode);` to return `string` + - Allowed the following methods to be implemented synchronously: (non-breaking) + - `addSession` + - `addSingleSession` + - `editSession` + - `createZoweSession` + - `createZoweSchema` + - `ssoLogin` + - `ssoLogout` + - `addFavorite` + - `removeFavorite` + - `removeFavProfile` + - `onDidChangeConfiguration` + - `flipState` _synchronous - no `Promise` returned_ + - `rename` + - `open` + - `copy` + - `paste` + - `delete` + - `setItem` _synchronous - no `Promise` returned_ + - `saveSearch` + - `saveFile` + - `refreshPS` + - `uploadDialog` + - `filterPrompt` + - `addSearchHistory` _synchronous - no `Promise` returned_ + - `deleteSession` _synchronous - no `Promise` returned_ + - `updateFavorites` + - `renameFavorite` + - `addFileHistory` _synchronous - no `Promise` returned_ + - `removeFileHistory` _synchronous - no `Promise` returned_ + - `renameNode` + - `openItemFromPath` + - `addDsTemplate` + - `pollData` + - `openWithEncoding` + + **Note**: Developers should not expect a value to be returned from the methods above (breaking) + + - Updated `IZoweTreeNode.ts`, see changes below: + - Modified `rename?(newNamePath: string);` to return `Promise` + - Developers should not be expecting output from the following methods: + - `openUSS` + - `refreshUSS` + - `deleteUSSNode` + - `renameUSSNode` + - `reopen` + - `saveSearch` + - Enhanced the `ZoweVsCodeExtension.loginWithBaseProfile` and `ZoweVsCodeExtension.logoutWithBaseProfile` methods to store SSO token in parent profile when nested profiles are in use. [#2264](https://github.com/zowe/zowe-explorer-vscode/issues/2264) - **Next Breaking:** Changed return type of `ZoweVsCodeExtension.logoutWithBaseProfile` method from `void` to `boolean` to indicate whether logout was successful. diff --git a/packages/zowe-explorer-api/__mocks__/vscode.ts b/packages/zowe-explorer-api/__mocks__/vscode.ts index 009aa42aeb..7a86f4bb85 100644 --- a/packages/zowe-explorer-api/__mocks__/vscode.ts +++ b/packages/zowe-explorer-api/__mocks__/vscode.ts @@ -136,7 +136,7 @@ export class CancellationTokenSource { } export namespace extensions { - export function getExtension(identifier: string) { + export function getExtension(_identifier: string): { packageJSON: { version: string } } { return { packageJSON: { version: "2.0.0", @@ -289,32 +289,32 @@ export namespace window { * @param items A set of items that will be rendered as actions in the message. * @return A thenable that resolves to the selected item or `undefined` when being dismissed. */ - export function showInformationMessage(message: string, ...items: string[]): Thenable { + export function showInformationMessage(_message: string, ..._items: string[]): Thenable { return Promise.resolve(""); } - export function showErrorMessage(message: string, ...items: string[]): undefined { + export function showErrorMessage(_message: string, ..._items: string[]): undefined { return undefined; } - export function showWarningMessage(message: string, ...items: string[]): undefined { + export function showWarningMessage(_message: string, ..._items: string[]): undefined { return undefined; } - export function setStatusBarMessage(message: string, ...items: string[]): undefined { + export function setStatusBarMessage(_message: string, ..._items: string[]): undefined { return undefined; } - export function createQuickPick(): QuickPick { + export function createQuickPick(): QuickPick | undefined { return undefined; } export function showQuickPick( - items: readonly T[] | Thenable, - options?: QuickPickOptions & { canPickMany: true }, - token?: CancellationToken + _items: readonly T[] | Thenable, + _options?: QuickPickOptions & { canPickMany: true }, + _token?: CancellationToken ): Thenable { - return undefined; + return Promise.resolve(undefined); } /** @@ -360,11 +360,11 @@ export namespace commands { * @param thisArg The `this` context used when invoking the handler function. * @return Disposable which unregisters this command on disposal. */ - export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable { + export function registerCommand(_command: string, callback: (...args: any[]) => any, _thisArg?: any): Disposable | undefined { return undefined; } - export function executeCommand(command: string): undefined { + export function executeCommand(_command: string): undefined { return undefined; } } @@ -377,7 +377,7 @@ export class Disposable { constructor() {} } -export function RelativePattern(base: string, pattern: string) { +export function RelativePattern(_base: string, _pattern: string): {} { return {}; } @@ -430,7 +430,7 @@ export class Uri { public static file(path: string): Uri { return Uri.parse(path); } - public static parse(value: string, strict?: boolean): Uri { + public static parse(value: string, _strict?: boolean): Uri { const newUri = new Uri(); newUri.path = value; @@ -722,7 +722,7 @@ export class EventEmitter { * * @param data The event object. */ - fire(data?: T): void {} + fire(_data?: T): void {} /** * Dispose this object and free resources. @@ -827,7 +827,7 @@ export class FileSystemError extends Error { * Create an error to signal that a file or folder wasn't found. * @param messageOrUri Message or uri. */ - static FileNotFound(messageOrUri?: string | Uri): FileSystemError { + static FileNotFound(_messageOrUri?: string | Uri): FileSystemError { return new FileSystemError("file not found"); } @@ -836,7 +836,7 @@ export class FileSystemError extends Error { * creating but not overwriting a file. * @param messageOrUri Message or uri. */ - static FileExists(messageOrUri?: string | Uri): FileSystemError { + static FileExists(_messageOrUri?: string | Uri): FileSystemError { return new FileSystemError("file exists"); } @@ -844,7 +844,7 @@ export class FileSystemError extends Error { * Create an error to signal that a file is not a folder. * @param messageOrUri Message or uri. */ - static FileNotADirectory(messageOrUri?: string | Uri): FileSystemError { + static FileNotADirectory(_messageOrUri?: string | Uri): FileSystemError { return new FileSystemError("file not a directory"); } @@ -852,7 +852,7 @@ export class FileSystemError extends Error { * Create an error to signal that a file is a folder. * @param messageOrUri Message or uri. */ - static FileIsADirectory(messageOrUri?: string | Uri): FileSystemError { + static FileIsADirectory(_messageOrUri?: string | Uri): FileSystemError { return new FileSystemError("file is a directory"); } @@ -860,7 +860,7 @@ export class FileSystemError extends Error { * Create an error to signal that an operation lacks required permissions. * @param messageOrUri Message or uri. */ - static NoPermissions(messageOrUri?: string | Uri): FileSystemError { + static NoPermissions(_messageOrUri?: string | Uri): FileSystemError { return new FileSystemError("no permissions"); } @@ -869,7 +869,7 @@ export class FileSystemError extends Error { * complete a request. * @param messageOrUri Message or uri. */ - static Unavailable(messageOrUri?: string | Uri): FileSystemError { + static Unavailable(_messageOrUri?: string | Uri): FileSystemError { return new FileSystemError("unavailable"); } @@ -902,7 +902,7 @@ export class FileSystemError extends Error { */ export namespace workspace { export const textDocuments: TextDocument[] = []; - export function getConfiguration(configuration: string) { + export function getConfiguration(_configuration: string): { update: () => void; inspect: () => void } { return { update: () => { return; @@ -913,7 +913,7 @@ export namespace workspace { }; } - export function createFileSystemWatcher() { + export function createFileSystemWatcher(): { onDidCreate: () => void; onDidChange: () => void; onDidDelete: () => void } { return { onDidCreate: () => {}, onDidChange: () => {}, @@ -921,11 +921,11 @@ export namespace workspace { }; } - export function onDidCloseTextDocument(event) { + export function onDidCloseTextDocument(_event): Disposable { return Disposable; } - export function onWillSaveTextDocument(event) { + export function onWillSaveTextDocument(_event): Disposable { return Disposable; } @@ -966,7 +966,7 @@ export namespace workspace { * @returns The file metadata about the file. * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `uri` doesn't exist. */ - export function stat(uri: Uri): FileStat | Thenable { + export function stat(_uri: Uri): FileStat | Thenable { return {} as FileStat; } @@ -977,7 +977,7 @@ export namespace workspace { * @returns An array of name/type-tuples or a thenable that resolves to such. * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `uri` doesn't exist. */ - export function readDirectory(uri: Uri): Array<[string, FileType]> | Thenable> { + export function readDirectory(_uri: Uri): Array<[string, FileType]> | Thenable> { return []; } @@ -989,7 +989,7 @@ export namespace workspace { * @throws {@linkcode FileSystemError.FileExists FileExists} when `uri` already exists. * @throws {@linkcode FileSystemError.NoPermissions NoPermissions} when permissions aren't sufficient. */ - export function createDirectory(uri: Uri): void | Thenable { + export function createDirectory(_uri: Uri): void | Thenable { return; } @@ -1000,7 +1000,7 @@ export namespace workspace { * @returns An array of bytes or a thenable that resolves to such. * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `uri` doesn't exist. */ - export function readFile(uri: Uri): Uint8Array | Thenable { + export function readFile(_uri: Uri): Uint8Array | Thenable { return new Uint8Array(); } @@ -1016,9 +1016,9 @@ export namespace workspace { * @throws {@linkcode FileSystemError.NoPermissions NoPermissions} when permissions aren't sufficient. */ export function writeFile( - uri: Uri, - content: Uint8Array, - options: { + _uri: Uri, + _content: Uint8Array, + _options: { /** * Create the file if it does not exist already. */ @@ -1044,9 +1044,9 @@ export namespace workspace { * @throws {@linkcode FileSystemError.NoPermissions NoPermissions} when permissions aren't sufficient. */ export function rename( - oldUri: Uri, - newUri: Uri, - options: { + _oldUri: Uri, + _newUri: Uri, + _options: { /** * Overwrite the file if it does exist. */ @@ -1069,9 +1069,9 @@ export namespace workspace { * @throws {@linkcode FileSystemError.NoPermissions NoPermissions} when permissions aren't sufficient. */ export function copy( - source: Uri, - destination: Uri, - options: { + _source: Uri, + _destination: Uri, + _options: { /** * Overwrite the file if it does exist. */ @@ -1120,7 +1120,7 @@ export namespace env { * The system clipboard. */ export const clipboard: Clipboard = { - writeText() { + writeText(): Thenable { return Promise.resolve(); }, }; diff --git a/packages/zowe-explorer-api/src/extend/IApiExplorerExtender.ts b/packages/zowe-explorer-api/src/extend/IApiExplorerExtender.ts index 6270fb17f7..89e660262f 100644 --- a/packages/zowe-explorer-api/src/extend/IApiExplorerExtender.ts +++ b/packages/zowe-explorer-api/src/extend/IApiExplorerExtender.ts @@ -37,12 +37,12 @@ export interface IApiExplorerExtender { * to make them automatically appears in the Explorer drop- * down dialogs. */ - reloadProfiles(profileType?: string): Promise; + reloadProfiles(profileType?: string): void | Promise; /** * After an extenders registered all its API extensions it * might want to check for an existing profile folder with meta-file * or to create them automatically if it is non-existant. */ - initForZowe(type: string, profileTypeConfigurations: imperative.ICommandProfileTypeConfiguration[]): Promise; + initForZowe(type: string, profileTypeConfigurations: imperative.ICommandProfileTypeConfiguration[]): void | Promise; } diff --git a/packages/zowe-explorer-api/src/extend/MainframeInteraction.ts b/packages/zowe-explorer-api/src/extend/MainframeInteraction.ts index 1ad359e820..29677723f2 100644 --- a/packages/zowe-explorer-api/src/extend/MainframeInteraction.ts +++ b/packages/zowe-explorer-api/src/extend/MainframeInteraction.ts @@ -40,13 +40,13 @@ export namespace MainframeInteraction { getSession(profile?: imperative.IProfileLoaded): imperative.Session; /** - * Create a session for the specific profile type. + * Retrieve the status of a specific profile. * - * @param {imperative.IProfileLoaded} profile - * will use the profile the API was retrieved with by default - * @returns {IZosmfInfoResponse} z/OSMF Check Status response + * @param {imperative.IProfileLoaded} profile the profile for which we will retrieve the status + * @param {string} profileType the type of profile being requested + * @returns {Promise} The status of the profile (e.g. active, inactive, unverified) */ - getStatus?(profile: imperative.IProfileLoaded, profileType?): Promise; + getStatus?(profile: imperative.IProfileLoaded, profileType?: string): Promise; /** * Create a session for a set command arguments. The session will be created independent diff --git a/packages/zowe-explorer-api/src/fs/types/abstract.ts b/packages/zowe-explorer-api/src/fs/types/abstract.ts index e85cec8dcb..f29305bc6b 100644 --- a/packages/zowe-explorer-api/src/fs/types/abstract.ts +++ b/packages/zowe-explorer-api/src/fs/types/abstract.ts @@ -40,7 +40,7 @@ export class BufferBuilder extends Duplex { this.chunks = []; } - public _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error) => void): void { + public _write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error) => void): void { this.chunks.push(chunk); callback(); } diff --git a/packages/zowe-explorer-api/src/tree/IZoweTree.ts b/packages/zowe-explorer-api/src/tree/IZoweTree.ts index ca996d96f6..7ef69d107d 100644 --- a/packages/zowe-explorer-api/src/tree/IZoweTree.ts +++ b/packages/zowe-explorer-api/src/tree/IZoweTree.ts @@ -14,6 +14,7 @@ import * as imperative from "@zowe/imperative"; import { IZoweTreeNode, ZosEncoding } from "./IZoweTreeNode"; import { PersistenceSchemaEnum } from "../profiles/UserSettings"; import { Types } from "../Types"; +import { Validation } from "../profiles/Validation"; /** * The base interface for Zowe tree browsers that implement the @@ -29,10 +30,12 @@ export interface IZoweTree extends vscode.TreeDataProvider, Partial extends vscode.TreeDataProvider, Partial; + addSession(opts?: Types.AddSessionOpts): void | Promise; /** * Adds a single session to the tree * @param profile the profile to add to the tree */ - addSingleSession(profile: imperative.IProfileLoaded): Promise; + addSingleSession(profile: imperative.IProfileLoaded): void | Promise; /** * Edit a session to the container * @param node This parameter identifies the node that needs to be called */ - editSession(node: IZoweTreeNode): Promise; + editSession(node: IZoweTreeNode): void | Promise; /** * Get sessions from persistent object of provider @@ -83,149 +86,176 @@ export interface IZoweTree extends vscode.TreeDataProvider, Partial): Promise; + createZoweSession(zoweFileProvider: IZoweTree): void | Promise; /** * Create a brand new Schema * @param zoweFileProvider The tree from which the schema will be created */ - createZoweSchema(zoweFileProvider: IZoweTree): Promise; + createZoweSchema(zoweFileProvider: IZoweTree): void | Promise; /** - * Adds a favorite node - * @param favorite Adds a favorite node + * Validates the profile for the given node + * @param node Node to validate/check its current profile */ - checkCurrentProfile(node: IZoweTreeNode); + checkCurrentProfile(node: IZoweTreeNode): Validation.IValidationProfile | Promise; /** * Log in to authentication service * @param node This parameter identifies the node that needs to be called */ - ssoLogin(node: IZoweTreeNode): Promise; + ssoLogin(node: IZoweTreeNode): void | Promise; /** * Log out from authentication service * @param node This parameter identifies the node that needs to be called */ - ssoLogout(node: IZoweTreeNode): Promise; + ssoLogout(node: IZoweTreeNode): void | Promise; /** * Adds a favorite node * @param favorite Adds a favorite node */ - addFavorite(favorite: IZoweTreeNode): Promise; + addFavorite(favorite: IZoweTreeNode): void | Promise; + /** * Removes a favorite node * @param favorite Adds a favorite node */ - removeFavorite(node: IZoweTreeNode): Promise; + removeFavorite(node: IZoweTreeNode): void | Promise; + /** * Removes profile node from Favorites section * @param profileName */ - removeFavProfile(profileName: string, userSelected: boolean): Promise; + removeFavProfile(profileName: string, userSelected: boolean): void | Promise; + /** * Refreshes the tree */ refresh(): void; + /** * Refreshes an element of the tree * @param favorite Node to refresh */ refreshElement(node: IZoweTreeNode): void; + /** * Signals that node data has changed in the tree view * @param element to pass to event listener callback */ nodeDataChanged?(node: IZoweTreeNode): void; + /** * Event Emitters used to notify subscribers that the refresh event has fired */ - onDidChangeConfiguration(e: vscode.ConfigurationChangeEvent); + onDidChangeConfiguration(e: vscode.ConfigurationChangeEvent): void | Promise; + /** * Change the state of an expandable node * @param element the node being flipped * @param isOpen the intended state of the the tree view provider, true or false */ - flipState(element: IZoweTreeNode, isOpen: boolean); + flipState(element: IZoweTreeNode, isOpen: boolean): void; /** * Rename the node. Begins a dialog. * @param the node to be renamed */ - rename(node: IZoweTreeNode); + rename(node: IZoweTreeNode): void | Promise; + /** * Opens the node. Begins a dialog. * @param node: the node to be opened * @param preview: open in preview of edit mode */ - open(node: IZoweTreeNode, preview: boolean); + open(node: IZoweTreeNode, preview: boolean): void | Promise; + /** * Begins a copy operation on the node. * @param node: the node to be copied */ - copy(node: IZoweTreeNode); + copy(node: IZoweTreeNode): void | Promise; + /** * Concludes a copy/paste operation on the node. * @param node: the node to be pasted */ - paste(node: IZoweTreeNode); + paste(node: IZoweTreeNode): void | Promise; + /** * Deletes a node. * @param node: the node to be deleted */ - delete(node: IZoweTreeNode); + delete(node: IZoweTreeNode): void | Promise; + /** * Reveals and selects a node within the tree. * @param treeView: the vscode tree container * @param node: the node to be selected */ - setItem(treeView: vscode.TreeView, node: IZoweTreeNode); + setItem(treeView: vscode.TreeView, node: IZoweTreeNode): void; + /** * Saves the currently employed filter as a favorite. * @param node: A root node representing a session */ - saveSearch(node: IZoweTreeNode); + saveSearch(node: IZoweTreeNode): void | Promise; + /** * Saves an edited file. * @param node: the node to be saved */ - saveFile(document: vscode.TextDocument); + saveFile(document: vscode.TextDocument): void | Promise; - refreshPS(node: IZoweTreeNode); + /** + * Refresh the given node with current mainframe data. + * @param node: the node to be refreshed + */ + refreshPS(node: IZoweTreeNode): void | Promise; - uploadDialog(node: IZoweTreeNode); + /** + * Confirmation dialog to upload/save the given node. + * @param node: the node to be uploaded/saved + */ + uploadDialog(node: IZoweTreeNode): void | Promise; /** * Begins a filter/search operation on a node. * @param node: the root node to be searched from */ - filterPrompt(node: IZoweTreeNode); + filterPrompt(node: IZoweTreeNode): void | Promise; /** * Adds a search history element to persisted settings. * @param node: the root node representing the operation */ - addSearchHistory(element: string); + addSearchHistory(element: string): void; + /** * Retrieves search history elements from persisted settings. */ - getSearchHistory(); + getSearchHistory(): string[]; + /** * Returns the type of the tree provider. * @returns {PersistenceSchemaEnum} the type of tree: Dataset, USS, or Job */ getTreeType(): PersistenceSchemaEnum; + /** * Deletes a root node from the tree. * @param node: A root node representing a session * @param hideFromAllTrees: whether to hide from all trees or just the single tree */ - deleteSession(node: IZoweTreeNode, hideFromAllTrees?: boolean); + deleteSession(node: IZoweTreeNode, hideFromAllTrees?: boolean): void; + /** * Lets the user open a dataset by filtering the currently-loaded list */ - getAllLoadedItems?(): Promise; + getAllLoadedItems?(): IZoweTreeNode[] | Promise; + /** * Retrieves the vscode tree container */ @@ -237,91 +267,106 @@ export interface IZoweTree extends vscode.TreeDataProvider, Partial; + /** * Renames a node from the favorites list * * @param {IZoweTreeNode} node */ - renameFavorite(node: IZoweTreeNode, newLabel: string); + renameFavorite(node: IZoweTreeNode, newLabel: string): void | Promise; + /** * Renames a node based on the profile and it's label * * @param {string} criteria the member name to add */ - addFileHistory?(criteria: string); + addFileHistory?(criteria: string): void; + /** * Returns the array of recently-opened member names * * @returns {string[]} the array of recently-opened member names */ - getFileHistory?(); + getFileHistory?(): string[]; + /** * Removes a member name from the recently-opened members array * * @param {string} name the member to remove */ - removeFileHistory?(name: string); + removeFileHistory?(name: string): void; + /** * Removes session from the session array * @param {string} name the sessions to remove */ removeSession?(name: string): void; + /** * Returns a new dataset filter string, from an old filter and a new string * * @param {string} newFilter the new filter to add * @param {IZoweTreeNode} node the node with the old filter */ - createFilterString?(newFilter: string, node: IZoweTreeNode); + createFilterString?(newFilter: string, node: IZoweTreeNode): string; + /** * @param {string} profileLabel * @param {string} beforeLabel * @param {string} afterLabel */ - renameNode(profile: string, beforeDataSetName: string, afterDataSetName: string); + renameNode(profile: string, beforeDataSetName: string, afterDataSetName: string): void | Promise; + /** * Opens an item & reveals it in the tree * * @param {string} path the path of the item * @param {IZoweTreeNode} sessionNode the session to use */ - openItemFromPath?(path: string, sessionNode: IZoweTreeNode); + openItemFromPath?(path: string, sessionNode: IZoweTreeNode): void | Promise; + /** * Adds template for data set creation attributes * * @param {any} criteria the member name to add */ - addDsTemplate?(criteria: Types.DataSetAllocTemplate): Promise; + addDsTemplate?(criteria: Types.DataSetAllocTemplate): void | Promise; + /** * Returns the array of saved templates for data set creation attributes * * @returns {DataSetAllocTemplate[]} the array of recently-opened member names */ getDsTemplates?(): Types.DataSetAllocTemplate[]; + /* Initializes polling (refresh w/ configurable interval) for the provided node. * * @param {IZoweTreeNode} node the node to poll data for */ - pollData?(node: IZoweTreeNode): any; + pollData?(node: IZoweTreeNode): void | Promise; + /** * Opens resource for the provided node using encoding specified by user. * @param {IZoweTreeNode} node * @param {ZosEncoding} encoding File encoding, user will be prompted if undefined */ - openWithEncoding?(node: IZoweTreeNode, encoding?: ZosEncoding): Promise; + openWithEncoding?(node: IZoweTreeNode, encoding?: ZosEncoding): void | Promise; } diff --git a/packages/zowe-explorer-api/src/tree/IZoweTreeNode.ts b/packages/zowe-explorer-api/src/tree/IZoweTreeNode.ts index 6a0eca7d6c..e304d9e8ab 100644 --- a/packages/zowe-explorer-api/src/tree/IZoweTreeNode.ts +++ b/packages/zowe-explorer-api/src/tree/IZoweTreeNode.ts @@ -11,10 +11,11 @@ import * as vscode from "vscode"; import * as imperative from "@zowe/imperative"; -import * as zosjobs from "@zowe/zos-jobs-for-zowe-sdk"; import { Sorting } from "./sorting"; import { ZoweTreeNodeActions } from "./ZoweNodeActions"; import type { Types } from "../Types"; +import { IJob } from "@zowe/zos-jobs-for-zowe-sdk"; +import { IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk"; interface TextEncoding { kind: "text"; @@ -30,6 +31,7 @@ interface OtherEncoding { } export type ZosEncoding = TextEncoding | BinaryEncoding | OtherEncoding; + export type EncodingMap = Record; /** @@ -43,60 +45,74 @@ export interface IZoweTreeNode extends vscode.TreeItem { * Indicator that the child data may have become stale and requires refreshing. */ dirty: boolean; + /** * Describes the full path of a file */ fullPath?: string; + /** * Children nodes of this node */ children?: IZoweTreeNode[]; + /** * Any ongoing actions that must be awaited before continuing */ ongoingActions?: Record>; + /** * whether the node was double-clicked */ wasDoubleClicked?: boolean; + /** * Sorting method for this node's children */ sort?: Sorting.NodeSort; + /** * Retrieves the node label */ getLabel(): string | vscode.TreeItemLabel; + /** * Retrieves the nodes parent node */ getParent(): IZoweTreeNode; + /** * Retrieves the nodes children nodes */ getChildren(): Promise; + /** * Retrieves the profile name in use with this node */ getProfileName(): string; + /** * Retrieves the session node in use with this node */ getSessionNode(): IZoweTreeNode; + /** * Retrieves the session object in use with this node */ getSession(): imperative.Session; + /** * Retrieves the profile object in use with this node */ getProfile(): imperative.IProfileLoaded; + /** * Set the profile to use for this node to be the one chosen in the parameters * * @param profileObj The profile you will set the node to use */ setProfileToChoice(profileObj: imperative.IProfileLoaded): void; + /** * Set the session to use for this node to be the one chosen in the parameters * @@ -116,32 +132,38 @@ export interface IZoweDatasetTreeNode extends IZoweTreeNode { * Search criteria for a Dataset search */ pattern?: string; + /** * Search criteria for a Dataset member search */ memberPattern?: string; + /** * @deprecated Please use `setStats` and `getStats` instead. * * Additional statistics about this data set */ stats?: Partial; + /** * Filter method for this data set's children */ filter?: Sorting.DatasetFilter; + /** * @deprecated Please use `getEncodingInMap` and `updateEncodingInMap` instead. * * List of child nodes and user-selected encodings */ encodingMap?: Record; + /** * @deprecated Please use `setEncoding` and `getEncoding` instead. * * Binary indicator. Default false (text) */ binary?: boolean; + /** * @deprecated Please use `setEncoding` and `getEncoding` instead. * @@ -151,24 +173,28 @@ export interface IZoweDatasetTreeNode extends IZoweTreeNode { * * `undefined` = user did not specify */ encoding?: string; + /** * Retrieves child nodes of this IZoweDatasetTreeNode * * @returns {Promise} */ getChildren(): Promise; + /** * Retrieves the etag value for the file * * @returns {string} */ getEtag(): string | PromiseLike; + /** * Sets the etag value for the file * * @param {string} */ setEtag(etag: string): void | PromiseLike; + /** * Downloads and displays a file in a text editor view * @@ -177,12 +203,14 @@ export interface IZoweDatasetTreeNode extends IZoweTreeNode { * @param datasetFileProvider the tree provider */ openDs?(download: boolean, previewFile: boolean, datasetFileProvider: Types.IZoweDatasetTreeType): Promise; + /** * Gets the codepage value for the file * * @param {string} */ getEncoding(): ZosEncoding | PromiseLike; + /** * Sets the codepage value for the file * @@ -224,25 +252,38 @@ export interface IZoweUSSTreeNode extends IZoweTreeNode { * Retrieves an abridged for of the label */ shortLabel?: string; + + /** + * @deprecated Please use `setEncoding` and `getEncoding` instead. + * + * Remote encoding of the USS file + * + * * `null` = user selected z/OS default codepage + * * `undefined` = user did not specify + */ encoding?: string; + /** * @deprecated Please use `getEncodingInMap` and `updateEncodingInMap` instead. * * List of child nodes and user-selected encodings */ encodingMap?: Record; + /** * @deprecated Please use `getEncoding` and `setEncoding` instead. * * Binary indicator. Default false (text) */ binary?: boolean; + /** * @deprecated Please use `setAttributes` and `getAttributes` instead. * * File attributes */ attributes?: Types.FileAttributes; + /** * Event that fires whenever an existing node is updated. */ @@ -281,6 +322,7 @@ export interface IZoweUSSTreeNode extends IZoweTreeNode { * @returns {string} */ getEtag(): string | PromiseLike; + /** * Sets the etag value for the file * @@ -303,24 +345,28 @@ export interface IZoweUSSTreeNode extends IZoweTreeNode { * * @param {string} newNamePath */ - rename?(newNamePath: string); + rename?(newNamePath: string): Promise; + /** * Gets the codepage value for the file * * @param {string} */ getEncoding(): ZosEncoding | PromiseLike; + /** * Sets the codepage value for the file * * @param {string} */ setEncoding(encoding: ZosEncoding): void | PromiseLike; + // /** // * Opens the text document // * @return vscode.TextDocument // */ // getOpenedDocumentInstance?(): vscode.TextDocument; + /** * Downloads and displays a file in a text editor view * @@ -328,46 +374,53 @@ export interface IZoweUSSTreeNode extends IZoweTreeNode { * @param preview the file, true or false * @param ussFileProvider the tree provider */ - openUSS?(download: boolean, previewFile: boolean, ussFileProvider: Types.IZoweUSSTreeType): Promise; + openUSS?(download: boolean, previewFile: boolean, ussFileProvider: Types.IZoweUSSTreeType): void | Promise; + /** * Returns the local file path for the ZoweUSSNode * @deprecated Zowe Explorer no longer uses local file paths for uploading and downloading USS files. */ getUSSDocumentFilePath?(): string; + /** * Refreshes the node with current mainframe data * */ - refreshUSS?(); + refreshUSS?(): void | Promise; + /** * * @param ussFileProvider Deletes the USS tree node * @param filePath * @param cancelled optional */ - deleteUSSNode?(ussFileProvider: Types.IZoweUSSTreeType, filePath: string, cancelled?: boolean); + deleteUSSNode?(ussFileProvider: Types.IZoweUSSTreeType, filePath: string, cancelled?: boolean): void | Promise; + /** * Process for renaming a USS Node. This could be a Favorite Node * * @param {USSTree} ussFileProvider * @param {string} filePath */ - renameUSSNode?(ussFileProvider: Types.IZoweUSSTreeType, filePath: string); + renameUSSNode?(ussFileProvider: Types.IZoweUSSTreeType, filePath: string): void | Promise; + /** * Reopens a file if it was closed (e.g. while it was being renamed). * @param hasClosedInstance */ - reopen?(hasClosedInstance?: boolean); + reopen?(hasClosedInstance?: boolean): void | Promise; + /** * Adds a search node to the USS favorites list * * @param {USSTree} ussFileProvider */ - saveSearch?(ussFileProvider: Types.IZoweUSSTreeType); + saveSearch?(ussFileProvider: Types.IZoweUSSTreeType): void | Promise; + /** * Uploads a tree of USS file(s)/folder(s) to mainframe */ - pasteUssTree?(); + pasteUssTree?(): void | Promise; } /** @@ -381,43 +434,52 @@ export interface IZoweJobTreeNode extends IZoweTreeNode { * Use Job-specific tree node for children. */ children?: IZoweJobTreeNode[]; + /** * Standard job response document * Represents the attributes and status of a z/OS batch job * @interface IJob */ - job?: zosjobs.IJob; + job?: IJob; + /** * Search criteria for a Job search */ searchId?: string; + /** * Job Prefix i.e "MYJOB" * Attribute of Job query */ prefix?: string; + /** * Job Owner i.e "MYID" * Attribute of Job query */ owner?: string; + /** * Job Status i.e "ACTIVE" * Attribute of Job query */ status?: string; + /** * Returns whether the job node is a filtered search */ filtered?: boolean; + /** * Filter method for this job search */ filter?: string; + /** * Array of original filter search results job's children */ actualJobs?: IZoweTreeNode[]; + /** * Retrieves child nodes of this IZoweJobTreeNode * diff --git a/packages/zowe-explorer/CHANGELOG.md b/packages/zowe-explorer/CHANGELOG.md index cf283bdc69..35cbb7eb17 100644 --- a/packages/zowe-explorer/CHANGELOG.md +++ b/packages/zowe-explorer/CHANGELOG.md @@ -66,6 +66,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen - Fixed regression where `getProviderForNode` returned the wrong tree provider after performing an action on a Zowe tree node, causing some commands to fail silently. [#2967](https://github.com/zowe/zowe-explorer-vscode/issues/2967) - Fixed issue where creating a new team configuration file could cause Zowe Explorer to crash, resulting in all sessions disappearing from trees. [#2906](https://github.com/zowe/zowe-explorer-vscode/issues/2906) - Update Zowe SDKs to `8.0.0-next.202407232256` for technical currency. [#2994](https://github.com/zowe/zowe-explorer-vscode/pull/2994) +- Addressed breaking changes from the Zowe Explorer API package.[#2952](https://github.com/zowe/zowe-explorer-vscode/issues/2952) ## `3.0.0-next.202404242037` diff --git a/packages/zowe-explorer/__tests__/__mocks__/DatasetTree.ts b/packages/zowe-explorer/__tests__/__mocks__/DatasetTree.ts index 4a08b81d64..65b1879d5d 100644 --- a/packages/zowe-explorer/__tests__/__mocks__/DatasetTree.ts +++ b/packages/zowe-explorer/__tests__/__mocks__/DatasetTree.ts @@ -48,9 +48,7 @@ export class DatasetTree implements vscode.TreeDataProvider { */ @MockMethod() public getChildren(_element?: ZoweDatasetNode): Promise { - return new Promise((resolve) => { - return resolve([]); - }); + return Promise.resolve([]); } /** @@ -76,23 +74,15 @@ export class DatasetTree implements vscode.TreeDataProvider { } @MockMethod() - public async addSession(_sessionName?: string): Promise { - return new Promise((resolve) => { - return resolve(); - }); + public addSession(_sessionName?: string): void | Promise { + return Promise.resolve(); } @MockMethod() - public async deleteSession(_node?: ZoweDatasetNode): Promise { - return new Promise((resolve) => { - return resolve(); - }); - } + public deleteSession(_node?: ZoweDatasetNode): void {} @MockMethod() - public async removeFavorite(_node: ZoweDatasetNode) { - return new Promise((resolve) => { - return resolve(); - }); + public removeFavorite(_node: ZoweDatasetNode): void | Promise { + return Promise.resolve(); } } diff --git a/packages/zowe-explorer/__tests__/__mocks__/USSTree.ts b/packages/zowe-explorer/__tests__/__mocks__/USSTree.ts index 96aab92912..885baa612c 100644 --- a/packages/zowe-explorer/__tests__/__mocks__/USSTree.ts +++ b/packages/zowe-explorer/__tests__/__mocks__/USSTree.ts @@ -10,7 +10,7 @@ */ import * as vscode from "vscode"; -import { IZoweUSSTreeNode, IZoweDatasetTreeNode, IZoweTreeNode } from "@zowe/zowe-explorer-api"; +import { IZoweUSSTreeNode, IZoweDatasetTreeNode, IZoweTreeNode, Validation } from "@zowe/zowe-explorer-api"; import { ZoweUSSNode } from "../../src/trees/uss/ZoweUSSNode"; import { MockMethod } from "../__decorators__/MockMethod"; import { createTreeView } from "./mockCreators/shared"; @@ -36,7 +36,7 @@ export class USSTree implements vscode.TreeDataProvider { * @memberof USSTree */ @MockMethod() - public addFavorite(_node: IZoweUSSTreeNode) {} + public addFavorite(_node: IZoweUSSTreeNode): void | Promise {} /** * @param {string} itemPath @@ -44,14 +44,14 @@ export class USSTree implements vscode.TreeDataProvider { * @memberof USSTree */ @MockMethod() - public async openItemFromPath(_itemPath: string, _sessionNode: IZoweUSSTreeNode) {} + public openItemFromPath(_itemPath: string, _sessionNode: IZoweUSSTreeNode): void | Promise {} /** * @param {IZoweUSSTreeNode} node * @memberof USSTree */ @MockMethod() - public removeFavorite(_node: IZoweUSSTreeNode) {} + public removeFavorite(_node: IZoweUSSTreeNode): void | Promise {} /** * @returns {IZoweUSSTreeNode[]} @@ -77,42 +77,44 @@ export class USSTree implements vscode.TreeDataProvider { * @memberof USSTree */ @MockMethod() - public setItem(_treeView: vscode.TreeView, _item: IZoweTreeNode) {} + public setItem(_treeView: vscode.TreeView, _item: IZoweTreeNode): void {} /** * @param {string} criteria * @memberof USSTree */ @MockMethod() - public addSearchHistory(_criteria: string) {} + public addSearchHistory(_criteria: string): void {} /** * @param {IZoweDatasetTreeNode} element * @memberof USSTree */ @MockMethod() - public refreshElement(_element: IZoweDatasetTreeNode) {} + public refreshElement(_element: IZoweDatasetTreeNode): void {} /** * @param {IZoweUSSTreeNode} node * @memberof USSTree */ @MockMethod() - public checkCurrentProfile(_node: IZoweUSSTreeNode) {} + public checkCurrentProfile(_node: IZoweUSSTreeNode): Validation.IValidationProfile | Promise { + return { status: "unverified", name: "mock" }; + } /** * @param {string} name - The name to remove from the file history array * @memberof USSTree */ @MockMethod() - public removeFileHistory(_name: string) {} + public removeFileHistory(_name: string): void {} /** * @param {string} criteria - The name to add to the file history array * @memberof USSTree */ @MockMethod() - public addFileHistory(_criteria: string) {} + public addFileHistory(_criteria: string): void {} /** * @returns {string[]} @@ -144,9 +146,7 @@ export class USSTree implements vscode.TreeDataProvider { */ @MockMethod() public getChildren(_element?: ZoweUSSNode): Promise { - return new Promise((resolve) => { - return resolve([]); - }); + return Promise.resolve([]); } /** @@ -172,16 +172,10 @@ export class USSTree implements vscode.TreeDataProvider { } @MockMethod() - public async addSession(_sessionName?: string): Promise { - return new Promise((resolve) => { - return resolve(); - }); + public addSession(_sessionName?: string): void | Promise { + return Promise.resolve(); } @MockMethod() - public async deleteSession(_node?: ZoweUSSNode): Promise { - return new Promise((resolve) => { - return resolve(); - }); - } + public deleteSession(_node?: ZoweUSSNode): void {} } diff --git a/packages/zowe-explorer/__tests__/__unit__/commands/ZoweCommandProvider.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/commands/ZoweCommandProvider.unit.test.ts index 0b4f7ee156..77952117aa 100644 --- a/packages/zowe-explorer/__tests__/__unit__/commands/ZoweCommandProvider.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/commands/ZoweCommandProvider.unit.test.ts @@ -40,7 +40,7 @@ describe("ZoweCommandProvider Unit Tests", () => { }); describe("ZoweCommandProvide Unit Tests - function checkCurrentProfile", () => { - const testNode = new ZoweDatasetNode({ + const testNode: any = new ZoweDatasetNode({ label: "test", collapsibleState: vscode.TreeItemCollapsibleState.None, session: globalMocks.testSession, @@ -59,18 +59,16 @@ describe("ZoweCommandProvide Unit Tests - function checkCurrentProfile", () => { jest.spyOn(SharedContext, "isSessionNotFav").mockReturnValue(true); }); it("should check current profile and perform the case when status is 'active'", async () => { - jest.spyOn(Profiles.getInstance(), "checkCurrentProfile").mockResolvedValue({ - name: "test", - status: "active", - }); - await expect(ZoweCommandProvider.prototype.checkCurrentProfile(testNode)).resolves.toEqual(undefined); + const profileStatus = { name: "test", status: "active" }; + + jest.spyOn(Profiles.getInstance(), "checkCurrentProfile").mockResolvedValue(profileStatus); + await expect(ZoweCommandProvider.prototype.checkCurrentProfile(testNode)).resolves.toEqual(profileStatus); }); it("should check current profile and perform the case when status is 'unverified'", async () => { - jest.spyOn(Profiles.getInstance(), "checkCurrentProfile").mockResolvedValue({ - name: "test", - status: "unverified", - }); - await expect(ZoweCommandProvider.prototype.checkCurrentProfile(testNode)).resolves.toEqual(undefined); + const profileStatus = { name: "test", status: "unverified" }; + + jest.spyOn(Profiles.getInstance(), "checkCurrentProfile").mockResolvedValue(profileStatus); + await expect(ZoweCommandProvider.prototype.checkCurrentProfile(testNode)).resolves.toEqual(profileStatus); }); it("should check current profile and perform the case when status is 'inactive'", async () => { Object.defineProperty(ZoweCommandProvider, "mOnDidChangeTreeData", { @@ -79,12 +77,10 @@ describe("ZoweCommandProvide Unit Tests - function checkCurrentProfile", () => { }, configurable: true, }); - jest.spyOn(Profiles.getInstance(), "checkCurrentProfile").mockResolvedValue({ - name: "test", - status: "inactive", - }); + const profileStatus = { name: "test", status: "inactive" }; + jest.spyOn(Profiles.getInstance(), "checkCurrentProfile").mockResolvedValue(profileStatus); const errorHandlingSpy = jest.spyOn(AuthUtils, "errorHandling").mockImplementation(); - await expect(ZoweCommandProvider.prototype.checkCurrentProfile(testNode)).resolves.toEqual(undefined); + await expect(ZoweCommandProvider.prototype.checkCurrentProfile(testNode)).resolves.toEqual(profileStatus); expect(errorHandlingSpy).toHaveBeenCalledWith( "Profile Name " + globalMocks.testProfile.name + diff --git a/packages/zowe-explorer/__tests__/__unit__/configuration/Profiles.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/configuration/Profiles.unit.test.ts index fb65f0c6f9..c4b4430295 100644 --- a/packages/zowe-explorer/__tests__/__unit__/configuration/Profiles.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/configuration/Profiles.unit.test.ts @@ -28,7 +28,7 @@ import { } from "../../__mocks__/mockCreators/shared"; import { createDatasetSessionNode, createDatasetTree } from "../../__mocks__/mockCreators/datasets"; import { createProfileManager } from "../../__mocks__/mockCreators/profiles"; -import { imperative, Gui, ProfilesCache, ZoweTreeNode, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api"; +import { imperative, Gui, ProfilesCache, ZoweTreeNode, ZoweVsCodeExtension, IZoweTree, IZoweTreeNode } from "@zowe/zowe-explorer-api"; import { Profiles } from "../../../src/configuration/Profiles"; import { ZoweExplorerExtender } from "../../../src/extending/ZoweExplorerExtender"; import { ZoweExplorerApiRegister } from "../../../src/extending/ZoweExplorerApiRegister"; @@ -44,6 +44,8 @@ import { Constants } from "../../../src/configuration/Constants"; import { ProfilesUtils } from "../../../src/utils/ProfilesUtils"; import { AuthUtils } from "../../../src/utils/AuthUtils"; import { FilterDescriptor } from "../../../src/management/FilterManagement"; +import { ZoweDatasetNode } from "../../../src/trees/dataset/ZoweDatasetNode"; +import { USSTree } from "../../../src/trees/uss/USSTree"; jest.mock("child_process"); jest.mock("fs"); @@ -68,7 +70,7 @@ function createGlobalMocks(): { [key: string]: any } { testProfile: createValidIProfile(), testTeamConfigProfile: createTeamConfigMock(), testUnsecureTeamConfigProfile: createUnsecureTeamConfigMock(), - testUSSTree: null, + testUSSTree: null as any as USSTree, testNode: createMockNode("test", Constants.DS_SESSION_CONTEXT), testSession: createISession(), mockCliProfileManager: createProfileManager(), @@ -85,10 +87,10 @@ function createGlobalMocks(): { [key: string]: any } { host: "fake.com", port: 143, }, - mockProfileInstance: null, - mockProfilesCache: null, + mockProfileInstance: null as any as Profiles, + mockProfilesCache: null as any as ProfilesCache, mockConfigInstance: createConfigInstance(), - mockConfigLoad: null, + mockConfigLoad: null as any as typeof imperative.Config, FileSystemProvider: { createDirectory: jest.fn(), }, @@ -195,7 +197,7 @@ function createGlobalMocks(): { [key: string]: any } { configurable: true, }); - newMocks.testUSSTree = createUSSTree(undefined, [createUSSNode(newMocks.testSession, newMocks.testProfile)], createTreeView()); + newMocks.testUSSTree = createUSSTree(undefined as any, [createUSSNode(newMocks.testSession, newMocks.testProfile)], createTreeView()); return newMocks; } @@ -274,8 +276,8 @@ describe("Profiles Unit Tests - Function createZoweSession", () => { const newMocks = { session: createISessionWithoutCredentials(), treeView: createTreeView(), - testDatasetSessionNode: null, - testDatasetTree: null, + testDatasetSessionNode: null as any as ZoweDatasetNode, + testDatasetTree: null as any as IZoweTree, quickPickItem: createQuickPickItem(), qpPlaceholder: 'Choose "Create new..." to define a new profile or select an existing profile to add to the Data Set Explorer', }; @@ -406,8 +408,8 @@ describe("Profiles Unit Tests - Function createZoweSchema", () => { const newMocks = { session: createISessionWithoutCredentials(), treeView: createTreeView(), - testDatasetSessionNode: null, - testDatasetTree: null, + testDatasetSessionNode: null as any as ZoweDatasetNode, + testDatasetTree: null as any as IZoweTree, quickPickItem: createQuickPickItem(), mockWsFolder: null, qpPlaceholder: 'Choose "Create new..." to define a new profile or select an existing profile to add to the Data Set Explorer', @@ -553,7 +555,9 @@ describe("Profiles Unit Tests - Function createZoweSchema", () => { ? "file:\\globalPath\\.zowe\\zowe.config.json" : "file:/globalPath/.zowe/zowe.config.json".split(path.sep).join(path.posix.sep); - await expect(Profiles.getInstance().createZoweSchema(blockMocks.testDatasetTree)).resolves.toBe(expectedValue); + const spyConfig = jest.spyOn(Profiles.getInstance(), "openConfigFile").mockImplementation(); + await Profiles.getInstance().createZoweSchema(blockMocks.testDatasetTree); + expect(spyConfig).toHaveBeenCalledWith(expectedValue); }); it("Test that createZoweSchema will create global configuration", async () => { diff --git a/packages/zowe-explorer/__tests__/__unit__/trees/ZoweTreeProvider.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/trees/ZoweTreeProvider.unit.test.ts index 62da65583b..cd838c7550 100644 --- a/packages/zowe-explorer/__tests__/__unit__/trees/ZoweTreeProvider.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/trees/ZoweTreeProvider.unit.test.ts @@ -208,7 +208,7 @@ describe("ZoweJobNode unit tests - Function editSession", () => { blockMocks.jobNode.contextValue = Constants.JOBS_SESSION_CONTEXT; await blockMocks.testJobsProvider.editSession(blockMocks.jobNode); expect(globalMocks.mockEditSession).toHaveBeenCalled(); - expect(deleteSessionSpy).toHaveBeenCalledWith(blockMocks.jobNode); + expect(deleteSessionSpy).not.toHaveBeenCalled(); }); }); diff --git a/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts index ea807578a1..9505ff971f 100644 --- a/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts @@ -1705,7 +1705,7 @@ describe("Dataset Tree Unit Tests - Function editSession", () => { imperativeProfile: createIProfile(), mockDefaultProfile: jest.fn(), treeView: createTreeView(), - datasetSessionNode: null, + datasetSessionNode: null as any as ZoweDatasetNode, profile: null, mockGetProfileSetting: jest.fn(), mockEditSession: jest.fn(), @@ -1751,9 +1751,9 @@ describe("Dataset Tree Unit Tests - Function editSession", () => { parentNode: testTree.mSessionNodes[1], }); - await testTree.editSession(node, testTree); + await testTree.editSession(node); - expect(node.getProfile().profile).toBe("testProfile"); + expect(node.getProfile().profile).toEqual(blockMocks.imperativeProfile.profile); }); }); describe("Dataset Tree Unit Tests - Function getAllLoadedItems", () => { diff --git a/packages/zowe-explorer/src/commands/ZoweCommandProvider.ts b/packages/zowe-explorer/src/commands/ZoweCommandProvider.ts index b082042079..d2ac576dc8 100644 --- a/packages/zowe-explorer/src/commands/ZoweCommandProvider.ts +++ b/packages/zowe-explorer/src/commands/ZoweCommandProvider.ts @@ -10,7 +10,7 @@ */ import * as vscode from "vscode"; -import { IZoweTreeNode, PersistenceSchemaEnum } from "@zowe/zowe-explorer-api"; +import { IZoweTreeNode, PersistenceSchemaEnum, Validation } from "@zowe/zowe-explorer-api"; import { ZowePersistentFilters } from "../tools/ZowePersistentFilters"; import { ZoweLogger } from "../tools/ZoweLogger"; import { SharedContext } from "../trees/shared/SharedContext"; @@ -52,7 +52,7 @@ export class ZoweCommandProvider { this.mOnDidChangeTreeData.fire(); } - public async checkCurrentProfile(node: IZoweTreeNode): Promise { + public async checkCurrentProfile(node: IZoweTreeNode): Promise { ZoweLogger.trace("ZoweCommandProvider.checkCurrentProfile called."); const profile = node.getProfile(); const profileStatus = await Profiles.getInstance().checkCurrentProfile(profile); @@ -99,5 +99,6 @@ export class ZoweCommandProvider { } } this.refresh(); + return profileStatus; } } diff --git a/packages/zowe-explorer/src/configuration/Profiles.ts b/packages/zowe-explorer/src/configuration/Profiles.ts index dea18cc4b1..99ba497953 100644 --- a/packages/zowe-explorer/src/configuration/Profiles.ts +++ b/packages/zowe-explorer/src/configuration/Profiles.ts @@ -398,7 +398,7 @@ export class Profiles extends ProfilesCache { } } - public async editSession(profileLoaded: imperative.IProfileLoaded): Promise { + public async editSession(profileLoaded: imperative.IProfileLoaded): Promise { const currentProfile = await this.getProfileFromConfig(profileLoaded.name); const filePath = currentProfile.profLoc.osLoc[0]; await this.openConfigFile(filePath); @@ -422,7 +422,7 @@ export class Profiles extends ProfilesCache { return profileType; } - public async createZoweSchema(_zoweFileProvider: IZoweTree): Promise { + public async createZoweSchema(_zoweFileProvider: IZoweTree): Promise { ZoweLogger.trace("Profiles.createZoweSchema called."); try { let user = false; @@ -487,7 +487,6 @@ export class Profiles extends ProfilesCache { configName = config.configName; } await this.openConfigFile(path.join(rootPath, configName)); - return path.join(rootPath, configName); } catch (err) { ZoweLogger.error(err); ZoweExplorerExtender.showZoweConfigError(err.message); @@ -865,7 +864,6 @@ export class Profiles extends ProfilesCache { }); ZoweLogger.error(message); Gui.errorMessage(message); - return; } } diff --git a/packages/zowe-explorer/src/trees/ZoweTreeProvider.ts b/packages/zowe-explorer/src/trees/ZoweTreeProvider.ts index 040b9ee91c..ecf8139bab 100644 --- a/packages/zowe-explorer/src/trees/ZoweTreeProvider.ts +++ b/packages/zowe-explorer/src/trees/ZoweTreeProvider.ts @@ -19,7 +19,6 @@ import { Constants } from "../configuration/Constants"; import { IconGenerator } from "../icons/IconGenerator"; import { SettingsConfig } from "../configuration/SettingsConfig"; import { SharedTreeProviders } from "./shared/SharedTreeProviders"; -import { ProfilesUtils } from "../utils/ProfilesUtils"; import { SharedActions } from "./shared/SharedActions"; import { IconUtils } from "../icons/IconUtils"; import { AuthUtils } from "../utils/AuthUtils"; @@ -213,25 +212,10 @@ export class ZoweTreeProvider { public async editSession(node: IZoweTreeNode): Promise { ZoweLogger.trace("ZoweTreeProvider.editSession called."); const profile = node.getProfile(); - const EditSession = await Profiles.getInstance().editSession(profile); - if (EditSession) { - node.getProfile().profile = EditSession as imperative.IProfile; - ProfilesUtils.setProfile(node, EditSession as imperative.IProfile); - if (node.getSession()) { - ProfilesUtils.setSession(node, EditSession as imperative.ISession); - } else { - this.deleteSession(node.getSessionNode()); - this.mHistory.addSession(node.label as string); - await this.addSession({ sessionName: node.getProfileName() }); - } - this.refresh(); - // Remove the edited profile from profilesForValidation - // Revalidate updated profile and update the validation icon - await this.checkCurrentProfile(node); - } + await Profiles.getInstance().editSession(profile); } - public async checkCurrentProfile(node: IZoweTreeNode): Promise { + public async checkCurrentProfile(node: IZoweTreeNode): Promise { ZoweLogger.trace("ZoweTreeProvider.checkCurrentProfile called."); const profile = node.getProfile(); const profileStatus = await Profiles.getInstance().checkCurrentProfile(profile); @@ -281,6 +265,7 @@ export class ZoweTreeProvider { } } this.refresh(); + return profileStatus; } public async ssoLogin(node: IZoweTreeNode): Promise { diff --git a/packages/zowe-explorer/src/trees/dataset/DatasetActions.ts b/packages/zowe-explorer/src/trees/dataset/DatasetActions.ts index c8c589dadb..a5e0b8cf3f 100644 --- a/packages/zowe-explorer/src/trees/dataset/DatasetActions.ts +++ b/packages/zowe-explorer/src/trees/dataset/DatasetActions.ts @@ -746,7 +746,7 @@ export class DatasetActions { * @param datasetProvider - the tree which contains the nodes */ public static async createFile(node: IZoweDatasetTreeNode, datasetProvider: Types.IZoweDatasetTreeType): Promise { - datasetProvider.checkCurrentProfile(node); + await datasetProvider.checkCurrentProfile(node); if (Profiles.getInstance().validProfile === Validation.ValidationType.INVALID) { return; } diff --git a/packages/zowe-explorer/src/trees/dataset/DatasetTree.ts b/packages/zowe-explorer/src/trees/dataset/DatasetTree.ts index a3f0b23b15..8355ac45ef 100644 --- a/packages/zowe-explorer/src/trees/dataset/DatasetTree.ts +++ b/packages/zowe-explorer/src/trees/dataset/DatasetTree.ts @@ -114,9 +114,9 @@ export class DatasetTree extends ZoweTreeProvider implemen public delete(_node: IZoweDatasetTreeNode): void { throw new Error("Method not implemented."); } - public saveSearch(node: IZoweDatasetTreeNode): Promise { + public async saveSearch(node: IZoweDatasetTreeNode): Promise { ZoweLogger.trace("DatasetTree.saveSearch called."); - return this.addFavorite(node); + await this.addFavorite(node); } public saveFile(_document: vscode.TextDocument): void { throw new Error("Method not implemented."); @@ -654,7 +654,7 @@ export class DatasetTree extends ZoweTreeProvider implemen ); // Remove profile node from Favorites if it contains no more favorites. if (profileNodeInFavorites.children.length < 1) { - return this.removeFavProfile(profileName, false); + await this.removeFavProfile(profileName, false); } this.updateFavorites(); this.refreshElement(this.mFavoriteSession); @@ -692,14 +692,13 @@ export class DatasetTree extends ZoweTreeProvider implemen comment: ["Profile name"], }); const continueRemove = vscode.l10n.t("Continue"); - await Gui.warningMessage(checkConfirmation, { + const selection = await Gui.warningMessage(checkConfirmation, { items: [continueRemove], vsCodeOpts: { modal: true }, - }).then((selection) => { - if (!selection || selection === "Cancel") { - cancelled = true; - } }); + if (!selection || selection === "Cancel") { + cancelled = true; + } } if (cancelled) { @@ -708,7 +707,7 @@ export class DatasetTree extends ZoweTreeProvider implemen // Remove favorited profile from UI this.mFavorites.forEach((favProfileNode) => { - const favProfileLabel = favProfileNode.label as string; + const favProfileLabel = favProfileNode.label?.toString(); if (favProfileLabel === profileName) { this.mFavorites = this.mFavorites.filter((tempNode) => tempNode.label.toString() !== favProfileLabel); favProfileNode.dirty = true; @@ -720,7 +719,7 @@ export class DatasetTree extends ZoweTreeProvider implemen this.updateFavorites(); } - public async onDidChangeConfiguration(e): Promise { + public async onDidChangeConfiguration(e: vscode.ConfigurationChangeEvent): Promise { ZoweLogger.trace("DatasetTree.onDidChangeConfiguration called."); // Empties the persistent favorites & history arrays, if the user has set persistence to False if (e.affectsConfiguration(DatasetTree.persistenceSchema)) { diff --git a/packages/zowe-explorer/src/trees/job/JobTree.ts b/packages/zowe-explorer/src/trees/job/JobTree.ts index ebc2c06bd5..176447cb89 100644 --- a/packages/zowe-explorer/src/trees/job/JobTree.ts +++ b/packages/zowe-explorer/src/trees/job/JobTree.ts @@ -511,7 +511,7 @@ export class JobTree extends ZoweTreeProvider implements Types job: node.job, }); favJob.command = { command: "zowe.jobs.search", title: "", arguments: [favJob] }; - this.saveSearch(favJob); + await this.saveSearch(favJob); } else { // Favorite a job favJob = new ZoweJobNode({ @@ -555,7 +555,7 @@ export class JobTree extends ZoweTreeProvider implements Types ); // Remove profile node from Favorites if it contains no more favorites. if (profileNodeInFavorites.children.length < 1) { - return this.removeFavProfile(profileName, false); + await this.removeFavProfile(profileName, false); } if (startLength !== profileNodeInFavorites.children.length) { this.updateFavorites(); @@ -599,14 +599,13 @@ export class JobTree extends ZoweTreeProvider implements Types comment: ["Profile name"], }); const continueRemove = vscode.l10n.t("Continue"); - await Gui.warningMessage(checkConfirmation, { + const selection = await Gui.warningMessage(checkConfirmation, { items: [continueRemove], vsCodeOpts: { modal: true }, - }).then((selection) => { - if (!selection || selection === "Cancel") { - cancelled = true; - } }); + if (!selection || selection === "Cancel") { + cancelled = true; + } } if (cancelled) { return; @@ -614,7 +613,7 @@ export class JobTree extends ZoweTreeProvider implements Types // Remove favorited profile from UI this.mFavorites.forEach((favProfileNode) => { - const favProfileLabel = favProfileNode.label as string; + const favProfileLabel = favProfileNode.label?.toString(); if (favProfileLabel === profileName) { this.mFavorites = this.mFavorites.filter((tempNode) => tempNode.label.toString() !== favProfileLabel); favProfileNode.dirty = true; diff --git a/packages/zowe-explorer/src/trees/shared/SharedInit.ts b/packages/zowe-explorer/src/trees/shared/SharedInit.ts index bd47500f7c..77eac5c882 100644 --- a/packages/zowe-explorer/src/trees/shared/SharedInit.ts +++ b/packages/zowe-explorer/src/trees/shared/SharedInit.ts @@ -199,8 +199,8 @@ export class SharedInit { ) ); context.subscriptions.push( - vscode.commands.registerCommand("zowe.saveSearch", (node: IZoweTreeNode) => { - SharedTreeProviders.getProviderForNode(node).saveSearch(node); + vscode.commands.registerCommand("zowe.saveSearch", async (node: IZoweTreeNode) => { + await SharedTreeProviders.getProviderForNode(node).saveSearch(node); }) ); context.subscriptions.push( diff --git a/packages/zowe-explorer/src/trees/uss/USSTree.ts b/packages/zowe-explorer/src/trees/uss/USSTree.ts index a7d9d3e7ef..d668ba31b0 100644 --- a/packages/zowe-explorer/src/trees/uss/USSTree.ts +++ b/packages/zowe-explorer/src/trees/uss/USSTree.ts @@ -589,13 +589,12 @@ export class USSTree extends ZoweTreeProvider implements Types * * @param {IZoweUSSTreeNode} node */ - public async saveSearch(node: IZoweUSSTreeNode): Promise { + public async saveSearch(node: IZoweUSSTreeNode): Promise { ZoweLogger.trace("USSTree.saveSearch called."); const fullPathLabel = node.fullPath; node.label = node.tooltip = fullPathLabel; node.contextValue = Constants.USS_SESSION_CONTEXT + Constants.FAV_SUFFIX; await this.checkCurrentProfile(node); - return node; } /** @@ -614,7 +613,7 @@ export class USSTree extends ZoweTreeProvider implements Types ); // Remove profile node from Favorites if it contains no more favorites. if (profileNodeInFavorites.children?.length < 1) { - return this.removeFavProfile(profileName, false); + await this.removeFavProfile(profileName, false); } } this.updateFavorites(); @@ -649,14 +648,13 @@ export class USSTree extends ZoweTreeProvider implements Types comment: ["Profile name"], }); const continueRemove = vscode.l10n.t("Continue"); - await Gui.warningMessage(checkConfirmation, { + const selection = await Gui.warningMessage(checkConfirmation, { items: [continueRemove], vsCodeOpts: { modal: true }, - }).then((selection) => { - if (!selection || selection === "Cancel") { - cancelled = true; - } }); + if (!selection || selection === "Cancel") { + cancelled = true; + } } if (cancelled) { return; @@ -664,7 +662,7 @@ export class USSTree extends ZoweTreeProvider implements Types // Remove favorited profile from UI this.mFavorites.forEach((favProfileNode) => { - const favProfileLabel = favProfileNode.label as string; + const favProfileLabel = favProfileNode.label?.toString(); if (favProfileLabel === profileName) { this.mFavorites = this.mFavorites.filter((tempNode) => tempNode?.label.toString() !== favProfileLabel); favProfileNode.dirty = true; diff --git a/packages/zowe-explorer/src/trees/uss/ZoweUSSNode.ts b/packages/zowe-explorer/src/trees/uss/ZoweUSSNode.ts index 3cad845e36..85b0411a02 100644 --- a/packages/zowe-explorer/src/trees/uss/ZoweUSSNode.ts +++ b/packages/zowe-explorer/src/trees/uss/ZoweUSSNode.ts @@ -376,7 +376,7 @@ export class ZoweUSSNode extends ZoweTreeNode implements IZoweUSSTreeNode { * Helper method to change the UI node names in one go * @param newFullPath string */ - public async rename(newFullPath: string): Promise { + public async rename(newFullPath: string): Promise { ZoweLogger.trace("ZoweUSSNode.rename called."); const oldUri = vscode.Uri.from({ @@ -407,7 +407,10 @@ export class ZoweUSSNode extends ZoweTreeNode implements IZoweUSSTreeNode { } const providers = SharedTreeProviders.providers; providers.uss.refresh(); - return true; + return { + success: true, + commandResponse: null, + }; } /** diff --git a/samples/uss-profile-sample/src/SshUssApi.ts b/samples/uss-profile-sample/src/SshUssApi.ts index 1a885afd79..87ffea0e82 100644 --- a/samples/uss-profile-sample/src/SshUssApi.ts +++ b/samples/uss-profile-sample/src/SshUssApi.ts @@ -17,7 +17,7 @@ export class SshUssApi implements MainframeInteraction.IUss { return new imperative.Session(sessCfg); } - public async getStatus(profile: imperative.IProfileLoaded, profileType?: any): Promise { + public async getStatus(profile: imperative.IProfileLoaded, profileType?: string): Promise { if (profileType === ZosUssProfile.type) { try { return await this.withClient(this.getSession(profile), () => Promise.resolve("active"));