From 71cd777833bdd7fd24c6af196e895b2fe81a3d5b Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:51:35 -0400 Subject: [PATCH] move enable, disable, and delete to quickpick Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- .../__tests__/__theia__/theia/Locators.ts | 2 + .../__theia__/theia/extension.theiaChrome.ts | 12 +- .../i18n/sample/src/Profiles.i18n.json | 2 +- .../src/utils/ProfileManagement.i18n.json | 6 + packages/zowe-explorer/package.json | 45 -------- .../src/utils/ProfileManagement.ts | 104 +++++++++++++++--- 6 files changed, 108 insertions(+), 63 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__theia__/theia/Locators.ts b/packages/zowe-explorer/__tests__/__theia__/theia/Locators.ts index 2b8793dba2..5e3eb996bc 100644 --- a/packages/zowe-explorer/__tests__/__theia__/theia/Locators.ts +++ b/packages/zowe-explorer/__tests__/__theia__/theia/Locators.ts @@ -44,6 +44,7 @@ export const UssLocators = { addToFavoriteOptionXpath: "//li[@data-command='zowe.uss.addFavorite']", removeFavoriteProfileFromUssOptionXpath: "//li[@data-command='zowe.uss.removeFavProfile']", hideProfileFromUssOptionXpath: "//li[@data-command='zowe.uss.removeSession']", + manageProfileFromUnixXpath: "(//li[@data-command='zowe.profileManagement'])", }; export const JobsLocators = { @@ -60,6 +61,7 @@ export const JobsLocators = { removeFavoriteProfileFromJobsOptionXpath: "//li[@data-command='zowe.jobs.removeFavProfile']", hideProfileFromJobsOptionXpath: "//li[@data-command='zowe.jobs.removeJobsSession']", secondJobsProfileBeforeHidingXpath: "(//div[contains(@id,'TestSeleniumProfile')])[2]", + manageProfileFromJobsXpath: "(//li[@data-command='zowe.profileManagement'])", }; export const TheiaNotificationMessages = { diff --git a/packages/zowe-explorer/__tests__/__theia__/theia/extension.theiaChrome.ts b/packages/zowe-explorer/__tests__/__theia__/theia/extension.theiaChrome.ts index 7d79c7eb9b..239aadb46a 100644 --- a/packages/zowe-explorer/__tests__/__theia__/theia/extension.theiaChrome.ts +++ b/packages/zowe-explorer/__tests__/__theia__/theia/extension.theiaChrome.ts @@ -138,13 +138,21 @@ export async function addProfileToFavoritesInJobs() { export async function hideProfileInUss() { const hideProfileFromUss = await driverChrome.wait(until.elementLocated(By.xpath(UssLocators.secondUssProfileXpath)), WAITTIME); await driverChrome.actions().click(hideProfileFromUss, Button.RIGHT).perform(); - await driverChrome.wait(until.elementLocated(By.xpath(UssLocators.hideProfileFromUssOptionXpath)), WAITTIME).click(); + driverChrome.wait(until.elementLocated(By.xpath(UssLocators.manageProfileFromUnixXpath)), WAITTIME).click(); + await driverChrome.sleep(SHORTSLEEPTIME); + const manageProfile = driverChrome.wait(until.elementLocated(By.xpath(UssLocators.emptyInputBoxXpath)), WAITTIME); + manageProfile.sendKeys("Hide Profile"); + manageProfile.sendKeys(Key.ENTER); } export async function hideProfileInJobs() { const hideProfileFromJobs = await driverChrome.wait(until.elementLocated(By.xpath(JobsLocators.secondJobsProfileBeforeHidingXpath)), WAITTIME); await driverChrome.actions().click(hideProfileFromJobs, Button.RIGHT).perform(); - await driverChrome.wait(until.elementLocated(By.xpath(JobsLocators.hideProfileFromJobsOptionXpath)), WAITTIME).click(); + driverChrome.wait(until.elementLocated(By.xpath(JobsLocators.manageProfileFromJobsXpath)), WAITTIME).click(); + await driverChrome.sleep(SHORTSLEEPTIME); + const manageProfile = driverChrome.wait(until.elementLocated(By.xpath(JobsLocators.emptyInputBoxXpath)), WAITTIME); + manageProfile.sendKeys("Hide Profile"); + manageProfile.sendKeys(Key.ENTER); } export async function verifyProfileIsHideInUss() { diff --git a/packages/zowe-explorer/i18n/sample/src/Profiles.i18n.json b/packages/zowe-explorer/i18n/sample/src/Profiles.i18n.json index 57a7772513..a7bdfe81e4 100644 --- a/packages/zowe-explorer/i18n/sample/src/Profiles.i18n.json +++ b/packages/zowe-explorer/i18n/sample/src/Profiles.i18n.json @@ -29,10 +29,10 @@ "validateProfiles.error": "Profile validation failed for {0}.", "ssoAuth.usingBasicAuth": "This profile is using basic authentication and does not support token authentication.", "ssoLogin.tokenType.error": "Error getting supported tokenType value for profile {0}", - "ssoLogin.successful": "Login to authentication service was successful.", "ssoLogin.error": "Unable to log in with {0}. {1}", "ssoLogout.successful": "Logout from authentication service was successful for {0}.", "ssoLogout.error": "Unable to log out with {0}. {1}", + "ssoLogin.successful": "Login to authentication service was successful.", "getConfigLocationPrompt.placeholder.create": "Select the location where the config file will be initialized", "getConfigLocationPrompt.placeholder.edit": "Select the location of the config file to edit", "getConfigLocationPrompt.showQuickPick.global": "Global: in the Zowe home directory", diff --git a/packages/zowe-explorer/i18n/sample/src/utils/ProfileManagement.i18n.json b/packages/zowe-explorer/i18n/sample/src/utils/ProfileManagement.i18n.json index 0b0107edb9..56776e1f3b 100644 --- a/packages/zowe-explorer/i18n/sample/src/utils/ProfileManagement.i18n.json +++ b/packages/zowe-explorer/i18n/sample/src/utils/ProfileManagement.i18n.json @@ -8,8 +8,14 @@ "updateBasicAuthQpItem.updateCredentials.qpLabel": "$(refresh) Update Credentials", "updateBasicAuthQpItem.updateCredentials.qpDetail": "Update stored username and password", "deleteProfileQpItem.delete.qpLabel": "$(trash) Delete Profile", + "disableProfileValildationQpItem.disableValidation.qpLabel": "$(workspace-untrusted) Disable Profile Validation", + "disableProfileValildationQpItem.disableValidation.qpDetail": "Disable validation of server check for profile.", + "enableProfileValildationQpItem.enableValidation.qpLabel": "$(workspace-trusted) Enable Profile Validation", + "enableProfileValildationQpItem.enableValidation.qpDetail": "Enable validation of server check for profile.", "editProfileQpItem.editProfile.qpLabel": "$(pencil) Edit Profile", "editProfileQpItem.editProfile.qpDetail": "Update profile connection information", + "hideProfileQpItems.hideProfile.qpLabel": "$(eye-closed) Hide Profile", + "hideProfileQpItems.hideProfile.qpDetail": "Hide profile name from tree view.", "loginQpItem.login.qpLabel": "$(arrow-right) Log in to authentication service", "loginQpItem.login.qpDetail": "Log in to obtain a new token value", "logoutQpItem.logout.qpLabel": "$(arrow-left) Log out of authentication service", diff --git a/packages/zowe-explorer/package.json b/packages/zowe-explorer/package.json index 398a82c58b..b50a2b6557 100644 --- a/packages/zowe-explorer/package.json +++ b/packages/zowe-explorer/package.json @@ -958,26 +958,11 @@ "command": "zowe.uss.deleteNode", "group": "099_zowe_ussModification:@4" }, - { - "when": "view == zowe.uss.explorer && viewItem =~ /_validate/ && !listMultiSelection", - "command": "zowe.uss.disableValidation", - "group": "099_zowe_ussProfileAuthentication@96" - }, - { - "when": "view == zowe.uss.explorer && viewItem =~ /_noValidate/ && !listMultiSelection", - "command": "zowe.uss.enableValidation", - "group": "099_zowe_ussProfileAuthentication@97" - }, { "when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection", "command": "zowe.profileManagement", "group": "099_zowe_ussProfileAuthentication@99" }, - { - "when": "viewItem =~ /^(?!.*_fav.*)ussSession.*/", - "command": "zowe.uss.removeSession", - "group": "099_zowe_ussProfileAuthentication@98" - }, { "when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection", "command": "zowe.ds.pattern", @@ -1153,26 +1138,11 @@ "command": "zowe.ds.deleteDataset", "group": "099_zowe_dsModification@5" }, - { - "when": "view == zowe.ds.explorer && viewItem =~ /_validate/ && !listMultiSelection", - "command": "zowe.ds.disableValidation", - "group": "099_zowe_dsProfileAuthentication@96" - }, - { - "when": "view == zowe.ds.explorer && viewItem =~ /_noValidate/ && !listMultiSelection", - "command": "zowe.ds.enableValidation", - "group": "099_zowe_dsProfileAuthentication@97" - }, { "when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection", "command": "zowe.profileManagement", "group": "099_zowe_dsProfileAuthentication@99" }, - { - "when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/", - "command": "zowe.ds.removeSession", - "group": "099_zowe_dsProfileAuthentication@98" - }, { "when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection", "command": "zowe.jobs.search", @@ -1298,26 +1268,11 @@ "command": "zowe.jobs.cancelJob", "group": "099_zowe_jobsModification" }, - { - "when": "view == zowe.jobs.explorer && viewItem =~ /_validate/ && !listMultiSelection", - "command": "zowe.jobs.disableValidation", - "group": "099_zowe_jobsProfileAuthentication@96" - }, - { - "when": "view == zowe.jobs.explorer && viewItem =~ /_noValidate/ && !listMultiSelection", - "command": "zowe.jobs.enableValidation", - "group": "099_zowe_jobsProfileAuthentication@97" - }, { "when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection", "command": "zowe.profileManagement", "group": "099_zowe_jobsProfileAuthentication@99" }, - { - "when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/", - "command": "zowe.jobs.removeJobsSession", - "group": "099_zowe_jobsProfileAuthentication@98" - }, { "when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection", "command": "zowe.jobs.sortbyid", diff --git a/packages/zowe-explorer/src/utils/ProfileManagement.ts b/packages/zowe-explorer/src/utils/ProfileManagement.ts index b72838721e..55a2f57eae 100644 --- a/packages/zowe-explorer/src/utils/ProfileManagement.ts +++ b/packages/zowe-explorer/src/utils/ProfileManagement.ts @@ -10,12 +10,14 @@ */ import * as vscode from "vscode"; +import * as globals from "../globals"; import { Gui, IZoweTreeNode, imperative } from "@zowe/zowe-explorer-api"; import { ZoweLogger } from "./LoggerUtils"; import { ProfilesUtils } from "./ProfilesUtils"; import * as nls from "vscode-nls"; import { Profiles } from "../Profiles"; import { ZoweExplorerApiRegister } from "../ZoweExplorerApiRegister"; +import { isZoweDatasetTreeNode, isZoweUSSTreeNode } from "../shared/utils"; // Set up localization nls.config({ @@ -31,18 +33,18 @@ export class ProfileManagement { switch (true) { case ProfilesUtils.isProfileUsingBasicAuth(profile): { ZoweLogger.debug(`Profile ${profile.name} is using basic authentication.`); - selected = await this.setupProfileManagementQp(imperative.SessConstants.AUTH_TYPE_BASIC, profile); + selected = await this.setupProfileManagementQp(imperative.SessConstants.AUTH_TYPE_BASIC, node); break; } case await ProfilesUtils.isUsingTokenAuth(profile.name): { ZoweLogger.debug(`Profile ${profile.name} is using token authentication.`); - selected = await this.setupProfileManagementQp("token", profile); + selected = await this.setupProfileManagementQp("token", node); break; } // will need a case for isUsingCertAuth default: { ZoweLogger.debug(`Profile ${profile.name} authentication method is unkown.`); - selected = await this.setupProfileManagementQp(null, profile); + selected = await this.setupProfileManagementQp(null, node); break; } } @@ -50,8 +52,11 @@ export class ProfileManagement { } public static AuthQpLabels = { add: "add-credentials", - delete: "delete", + delete: "delete-profile", + disable: "disable-validation", edit: "edit-profile", + enable: "enable-validation", + hide: "hide-profile", login: "obtain-token", logout: "invalidate-token", update: "update-credentials", @@ -73,12 +78,30 @@ export class ProfileManagement { label: localize("deleteProfileQpItem.delete.qpLabel", "$(trash) Delete Profile"), }, }; + public static disableProfileValildationQpItem: Record = { + [this.AuthQpLabels.disable]: { + label: localize("disableProfileValildationQpItem.disableValidation.qpLabel", "$(workspace-untrusted) Disable Profile Validation"), + description: localize("disableProfileValildationQpItem.disableValidation.qpDetail", "Disable validation of server check for profile."), + }, + }; + public static enableProfileValildationQpItem: Record = { + [this.AuthQpLabels.enable]: { + label: localize("enableProfileValildationQpItem.enableValidation.qpLabel", "$(workspace-trusted) Enable Profile Validation"), + description: localize("enableProfileValildationQpItem.enableValidation.qpDetail", "Enable validation of server check for profile."), + }, + }; public static editProfileQpItems: Record = { [this.AuthQpLabels.edit]: { label: localize("editProfileQpItem.editProfile.qpLabel", "$(pencil) Edit Profile"), description: localize("editProfileQpItem.editProfile.qpDetail", "Update profile connection information"), }, }; + public static hideProfileQpItems: Record = { + [this.AuthQpLabels.hide]: { + label: localize("hideProfileQpItems.hideProfile.qpLabel", "$(eye-closed) Hide Profile"), + description: localize("hideProfileQpItems.hideProfile.qpDetail", "Hide profile name from tree view."), + }, + }; public static tokenAuthLoginQpItem: Record = { [this.AuthQpLabels.login]: { label: localize("loginQpItem.login.qpLabel", "$(arrow-right) Log in to authentication service"), @@ -91,23 +114,24 @@ export class ProfileManagement { description: localize("logoutQpItem.logout.qpDetail", "Log out to invalidate and remove stored token value"), }, }; - private static async setupProfileManagementQp(managementType: string, profile: imperative.IProfileLoaded): Promise { + private static async setupProfileManagementQp(managementType: string, node: IZoweTreeNode): Promise { + const profile = node.getProfile(); const qp = Gui.createQuickPick(); let quickPickOptions: vscode.QuickPickItem[]; const placeholders = this.getQpPlaceholders(profile); switch (managementType) { case imperative.SessConstants.AUTH_TYPE_BASIC: { - quickPickOptions = this.basicAuthQp(); + quickPickOptions = this.basicAuthQp(node); qp.placeholder = placeholders.basicAuth; break; } case "token": { - quickPickOptions = this.tokenAuthQp(profile); + quickPickOptions = this.tokenAuthQp(node); qp.placeholder = placeholders.tokenAuth; break; } default: { - quickPickOptions = this.chooseAuthQp(profile); + quickPickOptions = this.chooseAuthQp(node); qp.placeholder = placeholders.chooseAuth; break; } @@ -142,10 +166,22 @@ export class ProfileManagement { await ProfilesUtils.promptCredentials(node); break; } + case this.hideProfileQpItems[this.AuthQpLabels.hide]: { + await this.handleHideProfiles(node); + break; + } case this.deleteProfileQpItem[this.AuthQpLabels.delete]: { await this.handleDeleteProfiles(node); break; } + case this.enableProfileValildationQpItem[this.AuthQpLabels.enable]: { + await this.handleEnableProfileValidation(node); + break; + } + case this.disableProfileValildationQpItem[this.AuthQpLabels.disable]: { + await this.handleDisableProfileValidation(node); + break; + } default: { Gui.infoMessage(localize("profiles.operation.cancelled", "Operation Cancelled")); break; @@ -165,18 +201,20 @@ export class ProfileManagement { }; } - private static basicAuthQp(): vscode.QuickPickItem[] { + private static basicAuthQp(node: IZoweTreeNode): vscode.QuickPickItem[] { const quickPickOptions: vscode.QuickPickItem[] = Object.values(this.basicAuthUpdateQpItems); - return this.addFinalQpOptions(quickPickOptions); + return this.addFinalQpOptions(node, quickPickOptions); } - private static tokenAuthQp(profile: imperative.IProfileLoaded): vscode.QuickPickItem[] { + private static tokenAuthQp(node: IZoweTreeNode): vscode.QuickPickItem[] { + const profile = node.getProfile(); const quickPickOptions: vscode.QuickPickItem[] = Object.values(this.tokenAuthLoginQpItem); if (profile.profile.tokenType) { quickPickOptions.push(this.tokenAuthLogoutQpItem[this.AuthQpLabels.logout]); } - return this.addFinalQpOptions(quickPickOptions); + return this.addFinalQpOptions(node, quickPickOptions); } - private static chooseAuthQp(profile: imperative.IProfileLoaded): vscode.QuickPickItem[] { + private static chooseAuthQp(node: IZoweTreeNode): vscode.QuickPickItem[] { + const profile = node.getProfile(); const quickPickOptions: vscode.QuickPickItem[] = Object.values(this.basicAuthAddQpItems); try { ZoweExplorerApiRegister.getInstance().getCommonApi(profile).getTokenTypeName(); @@ -184,10 +222,16 @@ export class ProfileManagement { } catch { ZoweLogger.debug(`Profile ${profile.name} doesn't support token authentication, will not provide option.`); } - return this.addFinalQpOptions(quickPickOptions); + return this.addFinalQpOptions(node, quickPickOptions); } - private static addFinalQpOptions(quickPickOptions: vscode.QuickPickItem[]): vscode.QuickPickItem[] { + private static addFinalQpOptions(node: IZoweTreeNode, quickPickOptions: vscode.QuickPickItem[]): vscode.QuickPickItem[] { + if (node.contextValue.includes(globals.NO_VALIDATE_SUFFIX)) { + quickPickOptions.push(this.enableProfileValildationQpItem[this.AuthQpLabels.enable]); + } else { + quickPickOptions.push(this.disableProfileValildationQpItem[this.AuthQpLabels.disable]); + } quickPickOptions.push(this.editProfileQpItems[this.AuthQpLabels.edit]); + quickPickOptions.push(this.hideProfileQpItems[this.AuthQpLabels.hide]); quickPickOptions.push(this.deleteProfileQpItem[this.AuthQpLabels.delete]); return quickPickOptions; } @@ -200,4 +244,34 @@ export class ProfileManagement { } await vscode.commands.executeCommand("zowe.ds.deleteProfile", node); } + + private static async handleHideProfiles(node: IZoweTreeNode): Promise { + if (isZoweDatasetTreeNode(node)) { + return vscode.commands.executeCommand("zowe.ds.removeSession", node); + } + if (isZoweUSSTreeNode(node)) { + return vscode.commands.executeCommand("zowe.uss.removeSession", node); + } + return vscode.commands.executeCommand("zowe.jobs.removeJobsSession", node); + } + + private static async handleEnableProfileValidation(node: IZoweTreeNode): Promise { + if (isZoweDatasetTreeNode(node)) { + return vscode.commands.executeCommand("zowe.ds.enableValidation", node); + } + if (isZoweUSSTreeNode(node)) { + return vscode.commands.executeCommand("zowe.uss.enableValidation", node); + } + return vscode.commands.executeCommand("zowe.jobs.enableValidation", node); + } + + private static async handleDisableProfileValidation(node: IZoweTreeNode): Promise { + if (isZoweDatasetTreeNode(node)) { + return vscode.commands.executeCommand("zowe.ds.disableValidation", node); + } + if (isZoweUSSTreeNode(node)) { + return vscode.commands.executeCommand("zowe.uss.disableValidation", node); + } + return vscode.commands.executeCommand("zowe.jobs.disableValidation", node); + } }