Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove multi-select, simplify profile selection code #223

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vsce/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the "cics-extension-for-zowe" extension will be documente

## Recent Changes

- BugFix: Editing profile results in exception - removed ability to multi-select profiles. [#222](https://github.com/zowe/cics-for-zowe-client/issues/222)
- BugFix: Update documentation to reflect changes to fully support V3 profiles. [#209](https://github.com/zowe/cics-for-zowe-client/issues/209)

## `3.3.1`
Expand Down
2 changes: 1 addition & 1 deletion packages/vsce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@
"group": ""
},
{
"when": "view == cics-view && viewItem =~ /^cicssession.*/",
"when": "view == cics-view && viewItem =~ /^cicssession.*/ && !listMultiSelection",
"command": "cics-extension-for-zowe.manageSession",
"title": "Manage Session"
},
Expand Down
64 changes: 11 additions & 53 deletions packages/vsce/src/trees/CICSTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,27 @@ export class CICSTree implements TreeDataProvider<CICSSessionTree> {
* @param treeview CICSTree View
* *@param node current selected node
*/
async manageProfile(treeview: TreeView<any>, node: any) {
const allSelectedNodes = findSelectedNodes(treeview, CICSSessionTree, node);
if (!allSelectedNodes || !allSelectedNodes.length) {
window.showErrorMessage("No profile selected to manage");
return;
}
async manageProfile(treeview: TreeView<any>, node: CICSSessionTree) {
try {
const configInstance = await ProfileManagement.getConfigInstance();
if (configInstance.getTeamConfig().exists) {
const currentProfile = await ProfileManagement.getProfilesCache().getProfileFromConfig(allSelectedNodes[allSelectedNodes.length - 1].label);
const currentProfile = await ProfileManagement.getProfilesCache().getProfileFromConfig(String(node.label));

const deleteProfile: QuickPickItem = {
label: `$(trash) ${l10n.t(`Delete Profile${allSelectedNodes.length > 1 ? "s" : ""}`)}`,
description: l10n.t(`Delete the selected Profile${allSelectedNodes.length > 1 ? "s" : ""}`),
label: `$(trash) ${l10n.t(`Delete Profile`)}`,
description: l10n.t(`Delete the selected Profile`),
};
const hideProfile: QuickPickItem = {
label: `$(eye-closed) ${l10n.t(`Hide Profile${allSelectedNodes.length > 1 ? "s" : ""}`)}`,
description: l10n.t(`Hide the selected Profile${allSelectedNodes.length > 1 ? "s" : ""}`),
label: `$(eye-closed) ${l10n.t(`Hide Profile`)}`,
description: l10n.t(`Hide the selected Profile`),
};
const editProfile: QuickPickItem = {
label: `$(pencil) ${l10n.t(`Edit Profile${allSelectedNodes.length > 1 ? "s" : ""}`)}`,
description: l10n.t(`Update the selected Profile${allSelectedNodes.length > 1 ? "s" : ""}`),
label: `$(pencil) ${l10n.t(`Edit Profile`)}`,
description: l10n.t(`Update the selected Profile`),
};

const quickpick = Gui.createQuickPick();
const addProfilePlaceholder = "Choose user action for selected profiles";
const addProfilePlaceholder = "Choose user action for selected profile";
quickpick.items = [editProfile, hideProfile, deleteProfile];
quickpick.placeholder = addProfilePlaceholder;
quickpick.ignoreFocusOut = true;
Expand All @@ -122,13 +117,10 @@ export class CICSTree implements TreeDataProvider<CICSSessionTree> {
Gui.showMessage(debugMsg);
return;
} else if (choice === hideProfile) {
this.hideZoweConfigFile(allSelectedNodes);
await this.removeSession(node);
return;
} else if (choice === editProfile) {
for (const sessionTree of allSelectedNodes) {
await this.updateSession(sessionTree, configInstance);
}
} else {
// editProfile or deleteProfile
const filePath = currentProfile.profLoc.osLoc[0];
await openConfigFile(filePath);
return;
Expand Down Expand Up @@ -451,26 +443,6 @@ export class CICSTree implements TreeDataProvider<CICSSessionTree> {
this._onDidChangeTreeData.fire(undefined);
}

/**
* Method for profile configuration that provides UI for user to hide a selected profile.
* @param allSelectedNodes array of selected nodes
*/
async hideZoweConfigFile(allSelectedNodes: any[]) {
for (const index in allSelectedNodes) {
try {
const currentNode = allSelectedNodes[parseInt(index)];
await this.removeSession(currentNode);
} catch (error) {
window.showErrorMessage(
`Something went wrong when hiding the profile - ${JSON.stringify(error, Object.getOwnPropertyNames(error)).replace(
/(\\n\t|\\n|\\t)/gm,
" ",
)}`,
);
}
}
}

async removeSession(session: CICSSessionTree, profile?: imperative.IProfileLoaded, position?: number) {
const persistentStorage = new PersistentStorage("zowe.cics.persistent");
await persistentStorage.removeLoadedCICSProfile(session.label.toString());
Expand All @@ -481,20 +453,6 @@ export class CICSTree implements TreeDataProvider<CICSSessionTree> {
this._onDidChangeTreeData.fire(undefined);
}

/**
* Update profile functionality for profile configuration
* @param session CICSSessions Tree
*/
async updateSession(session: CICSSessionTree, configInstance: imperative.ProfileInfo) {
await ProfileManagement.profilesCacheRefresh();
const profileCache = await ProfileManagement.getProfilesCache();
const profileToUpdate = profileCache.loadNamedProfile(session.label?.toString()!, "cics");
const currentProfile = await profileCache.getProfileFromConfig(profileToUpdate.name);
const teamConfigFilePath = configInstance.getTeamConfig().opts.homeDir + "/zowe.config.json";
const filePath = currentProfile?.profLoc.osLoc?.[0] ?? teamConfigFilePath;
await openConfigFile(filePath);
}

/**
* Method for profile configuration that returns the context of a configuration file.
* @param action string create or edit
Expand Down
Loading