-
Notifications
You must be signed in to change notification settings - Fork 16
show-bundle-in-uss-dir #473
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
fe8e7ae
9c11a4b
7be7362
b486bd5
00219e8
b8360ef
6ef23e8
572b1bc
2fde404
7d7863a
130c31c
01ea643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,89 @@ | ||||||
| /** | ||||||
| * This program and the accompanying materials are made available under the terms of the | ||||||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||||||
| * https://www.eclipse.org/legal/epl-v20.html | ||||||
| * | ||||||
| * SPDX-License-Identifier: EPL-2.0 | ||||||
| * | ||||||
| * Copyright Contributors to the Zowe Project. | ||||||
| * | ||||||
| */ | ||||||
|
|
||||||
| import { commands, TreeView, window } from "vscode"; | ||||||
| import { CICSLogger } from "../utils/CICSLogger"; | ||||||
| import { ProfileManagement } from "../utils/profileManagement"; | ||||||
| import { IProfileLoaded } from "@zowe/imperative"; | ||||||
| import * as vscode from "vscode"; | ||||||
| import type { IZoweUSSTreeNode } | ||||||
| from "@zowe/zowe-explorer-api"; | ||||||
| import { doesProfileSupportConnectionType, findRelatedZosProfiles, promptUserForProfile } from "../utils/commandUtils"; | ||||||
|
|
||||||
| /** | ||||||
| * Creates a minimal USS tree node compatible with IZoweUSSTreeNode interface | ||||||
| * | ||||||
| * @param path - The full path of the USS directory | ||||||
| * @param profileName - The name of the profile to use | ||||||
| * @param profile - The profile object | ||||||
| * @returns A minimal implementation of IZoweUSSTreeNode | ||||||
| */ | ||||||
| function createUSSTreeNode(path: string, profileName: string, profile: IProfileLoaded): IZoweUSSTreeNode { | ||||||
| const directoryName = path.split("/").pop() || path; | ||||||
| return { | ||||||
| label: directoryName, | ||||||
| fullPath: path, | ||||||
| collapsibleState: vscode.TreeItemCollapsibleState.Collapsed, | ||||||
| contextValue: "directory", | ||||||
| getLabel: () => directoryName, | ||||||
| getChildren: async () => [] as IZoweUSSTreeNode[], | ||||||
| getProfileName: () => profileName, | ||||||
| getProfile: () => profile, | ||||||
|
|
||||||
| } as any as IZoweUSSTreeNode; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| export function showBundleDirectory(treeview: TreeView<any>) { | ||||||
| return commands.registerCommand("cics-extension-for-zowe.showBundleDirectory", async (selectedBundle) => { | ||||||
| if (!selectedBundle) { | ||||||
| window.showErrorMessage(`No Bundle is selected from cics tree`); | ||||||
| return; | ||||||
| } | ||||||
| const bundleDir = selectedBundle.getContainedResource().resource.attributes?.bundledir; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contained Resource is optional, but attributes is not
Suggested change
|
||||||
| if (!bundleDir) { | ||||||
| window.showErrorMessage(`Could not find bundle directory for ${selectedBundle.getLabel() | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The label could have other info in that's not necessary here, status info for example |
||||||
| }.`); | ||||||
| return; | ||||||
| } | ||||||
| const allProfiles = await ProfileManagement.getProfilesCache().fetchAllProfiles(); | ||||||
| const zosProfiles = allProfiles.filter((element) => doesProfileSupportConnectionType(element, "uss")); | ||||||
| let chosenProfileName: string; | ||||||
|
|
||||||
| const matchingZosProfile = await findRelatedZosProfiles(selectedBundle.profile, zosProfiles); | ||||||
|
|
||||||
| if (matchingZosProfile) { | ||||||
| chosenProfileName = matchingZosProfile.name; | ||||||
| } else { // we couldn't find a matching profile - prompt the user with all zos profiles | ||||||
| chosenProfileName = await promptUserForProfile(zosProfiles); | ||||||
| CICSLogger.debug(`User picked z/OS profile: ${chosenProfileName}`); | ||||||
| if (chosenProfileName === null) { | ||||||
| window.showErrorMessage("Could not find any profiles that will access USS (for instance z/OSMF)."); | ||||||
| return; | ||||||
| } else if (chosenProfileName === undefined) { // the user cancelled the quick pick | ||||||
| return; | ||||||
| } | ||||||
| } | ||||||
| try { // Get the profile object from the name | ||||||
| const chosenProfile = zosProfiles.find(profile => profile.name === chosenProfileName); | ||||||
| if (!chosenProfile) { | ||||||
| window.showErrorMessage(`Could not find profile ${chosenProfileName}`); | ||||||
| return; | ||||||
| } | ||||||
| const ussNode = createUSSTreeNode(bundleDir, chosenProfileName, chosenProfile); | ||||||
| await commands.executeCommand("zowe.uss.filterBy", ussNode); | ||||||
|
|
||||||
| } catch (error) { | ||||||
| CICSLogger.error(`Failed to show bundle directory in USS view: ${error}`); | ||||||
| window.showErrorMessage(`Unable to open bundle directory in USS view.`); | ||||||
| } | ||||||
| }); | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we use this feature toggle anymore...