Skip to content

Commit

Permalink
Merge pull request #2771 from zowe/fix/profcache-api-proposal
Browse files Browse the repository at this point in the history
fixes: Resolve TypeError in `ProfilesCache`; hide quick pick separators for old VS Code versions
  • Loading branch information
zFernand0 authored Mar 19, 2024
2 parents 682b6fa + 4c34d50 commit 67bfed5
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.16.0-SNAPSHOT",
"version": "2.15.1",
"command": {
"version": {
"forcePublish": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t

### Bug fixes

- Fixed TypeError encountered in the `ProfilesCache.checkMergingConfigAllProfiles` function when merging profiles. [#2771](https://github.com/zowe/vscode-extension-for-zowe/pull/2771)

## `2.15.0`

### Bug fixes
Expand Down
34 changes: 6 additions & 28 deletions packages/zowe-explorer-api/src/profiles/ProfilesCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,40 +481,18 @@ export class ProfilesCache {

// used by refresh to check correct merging of allProfiles
protected checkMergingConfigAllProfiles(): void {
const baseProfile = this.defaultProfileByType.get("base");
const allProfiles: zowe.imperative.IProfileLoaded[] = [];
this.allTypes.forEach((type) => {
try {
const allProfilesByType: zowe.imperative.IProfileLoaded[] = [];
const profByType = this.profilesByType.get(type);
profByType.forEach((profile) => {
if (this.shouldRemoveTokenFromProfile(profile, baseProfile)) {
profile.profile.tokenType = undefined;
profile.profile.tokenValue = undefined;
// update default profile of type if changed
if (profile.name === this.defaultProfileByType.get(type).name) {
this.defaultProfileByType.set(type, profile);
}
}
allProfiles.push(profile);
allProfilesByType.push(profile);
});
this.profilesByType.set(type, allProfilesByType);
} catch (error) {
// do nothing, skip if profile type is not included in config file
this.log.debug(error as string);
}
});
this.allProfiles = [];
this.allProfiles.push(...allProfiles);
for (const profs of this.profilesByType.values()) {
profs.forEach((profile) => {
this.checkMergingConfigSingleProfile(profile);
});
}
}

// check correct merging of a single profile
protected checkMergingConfigSingleProfile(profile: zowe.imperative.IProfileLoaded): zowe.imperative.IProfileLoaded {
const baseProfile = this.defaultProfileByType.get("base");
if (this.shouldRemoveTokenFromProfile(profile, baseProfile)) {
profile.profile.tokenType = undefined;
profile.profile.tokenValue = undefined;
profile.profile.tokenType = profile.profile.tokenValue = undefined;
}
return profile;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen

### Bug fixes

- Fixed issue where VS Code quick pick separators were used in environments that did not support the feature. [#2771](https://github.com/zowe/vscode-extension-for-zowe/pull/2771)

## `2.15.0`

### New features and enhancements
Expand Down
2 changes: 2 additions & 0 deletions packages/zowe-explorer/__mocks__/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,5 @@ export namespace env {
},
};
}

export const version = "1.53.2";
Original file line number Diff line number Diff line change
Expand Up @@ -778,19 +778,35 @@ describe("ZosJobsProvider unit tests - Function getUserJobsMenuChoice", () => {
jest.spyOn(globalMocks.testJobsProvider.mHistory, "getSearchHistory").mockReturnValue(["JobId:123"]);
});
it("should return undefined and warn if user did not select a menu", async () => {
jest.spyOn(Gui, "resolveQuickPick").mockReturnValue(undefined);
const resolveQuickPickMock = jest.spyOn(Gui, "resolveQuickPick").mockResolvedValueOnce(undefined);
const result = await globalMocks.testJobsProvider.getUserJobsMenuChoice();
expect(result).toEqual(undefined);
expect(showInformationMessage).toHaveBeenCalled();
expect(showInformationMessage).toHaveBeenCalledWith("No selection made. Operation cancelled.");
showInformationMessage.mockClear();
resolveQuickPickMock.mockRestore();
});

it("should return undefined and warn if user did not select a menu - Theia", async () => {
const oldIsTheia = globals.ISTHEIA;
Object.defineProperty(globals, "ISTHEIA", { value: true });
const showQuickPickMock = jest.spyOn(Gui, "showQuickPick").mockClear().mockResolvedValueOnce(undefined);
const result = await globalMocks.testJobsProvider.getUserJobsMenuChoice();
expect(result).toEqual(undefined);
expect(showInformationMessage).toHaveBeenCalledWith("No selection made. Operation cancelled.");
expect(showQuickPickMock).toHaveBeenCalled();
showInformationMessage.mockClear();
showQuickPickMock.mockRestore();
Object.defineProperty(globals, "ISTHEIA", { value: oldIsTheia, configurable: true });
});

it("should return user menu choice and not show vscode warning", async () => {
const menuItem = new utils.FilterItem({ text: "searchById" });
jest.spyOn(Gui, "resolveQuickPick").mockReturnValue(Promise.resolve(menuItem));
const resolveQuickPickMock = jest.spyOn(Gui, "resolveQuickPick").mockResolvedValueOnce(menuItem);
const result = await globalMocks.testJobsProvider.getUserJobsMenuChoice();
expect(result).toEqual(menuItem);
expect(showInformationMessage).not.toHaveBeenCalled();
showInformationMessage.mockClear();
resolveQuickPickMock.mockRestore();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,10 @@ describe("Shared utils unit tests - function promptForEncoding", () => {
node.setEncoding(otherEncoding);
const encodingHistory = ["IBM-123", "IBM-456", "IBM-789"];
blockMocks.localStorageGet.mockReturnValueOnce(encodingHistory);
blockMocks.showQuickPick.mockImplementationOnce(async (items) => items[4]);
blockMocks.showQuickPick.mockImplementationOnce(async (items) => items[3]);
const encoding = await sharedUtils.promptForEncoding(node);
expect(blockMocks.showQuickPick).toHaveBeenCalled();
expect((await blockMocks.showQuickPick.mock.calls[0][0]).slice(4)).toEqual(encodingHistory.map((x) => ({ label: x })));
expect((await blockMocks.showQuickPick.mock.calls[0][0]).slice(3)).toEqual(encodingHistory.map((x) => ({ label: x })));
expect(blockMocks.showQuickPick.mock.calls[0][1]).toEqual(expect.objectContaining({ placeHolder: "Current encoding is IBM-1047" }));
expect(encoding).toEqual({ ...otherEncoding, codepage: encodingHistory[0] });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ describe("Logger Utils Unit Tests - function initializeZoweLogger", () => {
expect(infoSpy).toHaveBeenCalled();
infoSpy.mockClear();
});

it("should call vscode.extensions.getExtension when package JSON is invalid in ExtensionContext", async () => {
const globalMocks = createGlobalMocks();
jest.spyOn(globals, "initLogger").mockReturnValueOnce();
globalMocks.mockGetConfiguration.mockReturnValue({
get: getSettingMock,
});
const infoSpy = jest.spyOn(logger.ZoweLogger, "info");
const getExtensionMock = jest.spyOn(vscode.extensions, "getExtension").mockReturnValueOnce({
packageJSON: {
displayName: "Zowe Explorer",
version: "2.15.0",
},
} as any);

expect(await logger.ZoweLogger.initializeZoweLogger({ extension: undefined } as any)).toBeUndefined();
expect(infoSpy).toHaveBeenCalled();
expect(getExtensionMock).toHaveBeenCalledWith("zowe.vscode-extension-for-zowe");
infoSpy.mockClear();
});

it("should initialize loggers successfully with not changing to cli logger setting", async () => {
const globalMocks = createGlobalMocks();
jest.spyOn(globals, "initLogger").mockReturnValueOnce();
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/Profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export class Profiles extends ProfilesCache {
const createPick = new FilterDescriptor(createNewProfile);
const configPick = new FilterDescriptor(createNewConfig);
const configEdit = new FilterDescriptor(editConfig);
const items: vscode.QuickPickItem[] = [globals.SEPARATORS.BLANK];
const items: vscode.QuickPickItem[] = [globals.SEPARATORS.BLANK].filter(Boolean);
let mProfileInfo: zowe.imperative.ProfileInfo;
try {
mProfileInfo = await this.getProfileInfo();
Expand Down
4 changes: 2 additions & 2 deletions packages/zowe-explorer/src/dataset/DatasetTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,15 +934,15 @@ export class DatasetTree extends ZoweTreeProvider implements IZoweTree<IZoweData
placeHolder: localize("searchHistory.options.prompt", "Select a filter"),
};
// get user selection
const choice = await Gui.showQuickPick([createPick, globals.SEPARATORS.RECENT_FILTERS, ...items], options1);
const choice = await Gui.showQuickPick([createPick, globals.SEPARATORS.RECENT_FILTERS, ...items].filter(Boolean), options1);
if (!choice) {
Gui.showMessage(localize("enterPattern.pattern", "No selection made. Operation cancelled."));
return;
}
pattern = choice === createPick ? "" : choice.label;
} else {
const quickpick = Gui.createQuickPick();
quickpick.items = [createPick, globals.SEPARATORS.RECENT_FILTERS, ...items];
quickpick.items = [createPick, globals.SEPARATORS.RECENT_FILTERS, ...items].filter(Boolean);
quickpick.placeholder = localize("searchHistory.options.prompt", "Select a filter");
quickpick.ignoreFocusOut = true;
quickpick.show();
Expand Down
23 changes: 17 additions & 6 deletions packages/zowe-explorer/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,23 @@ export enum JobPickerTypes {
History = "History",
}

export const SEPARATORS = {
BLANK: { kind: vscode.QuickPickItemKind.Separator, label: "" },
RECENT: { kind: vscode.QuickPickItemKind.Separator, label: localize("zowe.separator.recent", "Recent") },
RECENT_FILTERS: { kind: vscode.QuickPickItemKind.Separator, label: localize("zowe.separator.recentFilters", "Recent Filters") },
OPTIONS: { kind: vscode.QuickPickItemKind.Separator, label: localize("zowe.separator.options", "Options") },
};
// Engine version defined in package.json for v2
export const ZE_VSC_ENGINE = "1.53.2";
export const [VSC_MAJOR, VSC_MINOR, VSC_PATCH] = (vscode.version || ZE_VSC_ENGINE).split(".").map(parseInt);
export const SEPARATORS =
VSC_MAJOR > 1 || VSC_MINOR >= 64
? {
BLANK: { kind: vscode.QuickPickItemKind.Separator, label: "" },
RECENT: { kind: vscode.QuickPickItemKind.Separator, label: localize("zowe.separator.recent", "Recent") },
RECENT_FILTERS: { kind: vscode.QuickPickItemKind.Separator, label: localize("zowe.separator.recentFilters", "Recent Filters") },
OPTIONS: { kind: vscode.QuickPickItemKind.Separator, label: localize("zowe.separator.options", "Options") },
}
: {
BLANK: undefined,
RECENT: undefined,
RECENT_FILTERS: undefined,
OPTIONS: undefined,
};

/**
* Defines all global variables
Expand Down
9 changes: 6 additions & 3 deletions packages/zowe-explorer/src/job/ZosJobsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,10 @@ export class ZosJobsProvider extends ZoweTreeProvider implements IZoweTree<IZowe
placeHolder: localize("searchHistory.options.prompt", "Select a filter"),
};
// get user selection
const choice = await Gui.showQuickPick([this.searchByQuery, this.searchById, globals.SEPARATORS.RECENT_FILTERS, ...items], selectFilter);
const choice = await Gui.showQuickPick(
[this.searchByQuery, this.searchById, globals.SEPARATORS.RECENT_FILTERS, ...items].filter(Boolean),
selectFilter
);
if (!choice) {
Gui.showMessage(localize("enterPattern.pattern", "No selection made. Operation cancelled."));
return undefined;
Expand All @@ -691,7 +694,7 @@ export class ZosJobsProvider extends ZoweTreeProvider implements IZoweTree<IZowe

// VSCode route to create a QuickPick
const quickpick = Gui.createQuickPick();
quickpick.items = [this.searchByQuery, this.searchById, globals.SEPARATORS.RECENT_FILTERS, ...items];
quickpick.items = [this.searchByQuery, this.searchById, globals.SEPARATORS.RECENT_FILTERS, ...items].filter(Boolean);
quickpick.placeholder = localize("searchHistory.options.prompt", "Select a filter");
quickpick.ignoreFocusOut = true;
quickpick.show();
Expand Down Expand Up @@ -949,7 +952,7 @@ export class ZosJobsProvider extends ZoweTreeProvider implements IZoweTree<IZowe
const editableItems: vscode.QuickPickItem[] = [
new FilterItem({ text: ZosJobsProvider.submitJobQueryLabel, show: true }),
globals.SEPARATORS.BLANK,
];
].filter(Boolean);
jobProperties.forEach((prop) => {
if (prop.key === "owner" && !prop.value) {
const session = node.getSession();
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export async function promptForEncoding(node: IZoweDatasetTreeNode | IZoweUSSTre
label: localize("zowe.shared.utils.promptForEncoding.other.label", "Other"),
description: localize("zowe.shared.utils.promptForEncoding.other.description", "Specify another codepage"),
};
const items: vscode.QuickPickItem[] = [ebcdicItem, binaryItem, otherItem, globals.SEPARATORS.RECENT];
const items: vscode.QuickPickItem[] = [ebcdicItem, binaryItem, otherItem, globals.SEPARATORS.RECENT].filter(Boolean);
const profile = node.getProfile();
if (profile.profile?.encoding != null) {
items.splice(0, 0, {
Expand Down
4 changes: 2 additions & 2 deletions packages/zowe-explorer/src/uss/USSTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export class USSTree extends ZoweTreeProvider implements IZoweTree<IZoweUSSTreeN
const items: vscode.QuickPickItem[] = this.mHistory.getSearchHistory().map((element) => new FilterItem({ text: element }));
if (globals.ISTHEIA) {
// get user selection
const choice = await Gui.showQuickPick([createPick, globals.SEPARATORS.RECENT_FILTERS, ...items], {
const choice = await Gui.showQuickPick([createPick, globals.SEPARATORS.RECENT_FILTERS, ...items].filter(Boolean), {
placeHolder: localize("searchHistory.options.prompt", "Select a filter"),
});
if (!choice) {
Expand All @@ -588,7 +588,7 @@ export class USSTree extends ZoweTreeProvider implements IZoweTree<IZoweUSSTreeN
} else {
const quickpick = Gui.createQuickPick();
quickpick.placeholder = localize("searchHistory.options.prompt", "Select a filter");
quickpick.items = [createPick, globals.SEPARATORS.RECENT_FILTERS, ...items];
quickpick.items = [createPick, globals.SEPARATORS.RECENT_FILTERS, ...items].filter(Boolean);
quickpick.ignoreFocusOut = true;
quickpick.show();
const choice = await Gui.resolveQuickPick(quickpick);
Expand Down
16 changes: 11 additions & 5 deletions packages/zowe-explorer/src/utils/LoggerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ export class ZoweLogger {
public static zeOutputChannel: vscode.OutputChannel;
private static defaultLogLevel: "INFO";
private static zeLogLevel: string;
private static displayName: string;
private static zeVersion: string;

public static async initializeZoweLogger(context: vscode.ExtensionContext): Promise<void> {
try {
const logsPath: string = ZoweVsCodeExtension.customLoggingPath ?? context.extensionPath;
const extInfo = context.extension ?? vscode.extensions.getExtension("zowe.vscode-extension-for-zowe");
this.displayName = extInfo.packageJSON.displayName;
this.zeVersion = extInfo.packageJSON.version;
globals.initLogger(logsPath);
await this.initVscLogger(context, logsPath);
await this.initVscLogger(logsPath);
} catch (err) {
// Don't log error if logger failed to initialize
if (err instanceof Error) {
Expand Down Expand Up @@ -77,15 +82,16 @@ export class ZoweLogger {
return this.zeLogLevel ?? this.defaultLogLevel;
}

private static async initVscLogger(context: vscode.ExtensionContext, logFileLocation: string): Promise<void> {
private static async initVscLogger(logFileLocation: string): Promise<void> {
this.zeOutputChannel = Gui.createOutputChannel(localize("zoweExplorer.outputchannel.title", "Zowe Explorer"));
this.writeVscLoggerInfo(logFileLocation, context);
this.writeVscLoggerInfo(logFileLocation);
this.info(localize("initialize.log.info", "Initialized logger for Zowe Explorer"));
await this.compareCliLogSetting();
}

private static writeVscLoggerInfo(logFileLocation: string, context: vscode.ExtensionContext): void {
this.zeOutputChannel?.appendLine(`${context.extension.packageJSON.displayName as string} ${context.extension.packageJSON.version as string}`);
private static writeVscLoggerInfo(logFileLocation: string): void {
this.zeOutputChannel?.appendLine(`${this.displayName} ${this.zeVersion}`);
this.zeOutputChannel?.appendLine(`VS Code version: ${vscode.version}`);
this.zeOutputChannel?.appendLine(localize("initialize.log.location", "This log file can be found at {0}", logFileLocation));
this.zeOutputChannel?.appendLine(localize("initialize.log.level", "Zowe Explorer log level: {0}", this.getLogSetting()));
}
Expand Down

0 comments on commit 67bfed5

Please sign in to comment.