Skip to content

Commit

Permalink
Merge pull request zowe#2586 from zowe/add-back-local-storage
Browse files Browse the repository at this point in the history
Add back lost local storage code
  • Loading branch information
JillieBeanSim authored Nov 20, 2023
2 parents 0903b33 + 373c897 commit 5f84872
Show file tree
Hide file tree
Showing 15 changed files with 672 additions and 688 deletions.
6 changes: 6 additions & 0 deletions packages/eslint-plugin-zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
All notable changes to the "eslint-plugin-zowe-explorer" package will be documented in this file.

## TBD Release

### New features and enhancements

### Bug fixes

## `3.0.0-next.202311171754`

## `3.0.0-next.202309121526`
Expand Down
6 changes: 6 additions & 0 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to the "zowe-explorer-api" extension will be documented in this file.

## TBD Release

### New features and enhancements

### Bug fixes

## `3.0.0-next.202311171754`

## Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@types/vscode": "^1.53.2",
"@zowe/cli": "^7.18.0",
"@zowe/cli": "7.18.0",
"@zowe/secrets-for-zowe-sdk": "7.18.4",
"handlebars": "^4.7.7",
"semver": "^7.5.3"
Expand Down
6 changes: 6 additions & 0 deletions packages/zowe-explorer-ftp-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
All notable changes to the "zowe-explorer-ftp-extension" extension will be documented in this file.

## TBD Release

### New features and enhancements

### Bug fixes

## `3.0.0-next.202311171754`

## `3.0.0-next.202311171523`
Expand Down
8 changes: 8 additions & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to the "vscode-extension-for-zowe" extension will be documented in this file.

## TBD Release

### New features and enhancements

- Added back local storage for Zowe Explorer persistent items

### Bug fixes

## `3.0.0-next.202311171754`

## `3.0.0-next.202311171523`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,27 @@ describe("PersistentFilters Unit Test", () => {
Object.defineProperty(ZoweLogger, "trace", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLocalStorage, "storage", {
value: {
get: () => ({ persistence: true, favorites: [], history: [], sessions: ["zosmf"], searchHistory: [], fileHistory: [] }),
get: () => ({
persistence: true,
favorites: [],
history: [],
sessions: ["zosmf"],
searchHistory: [],
fileHistory: [],
templates: [
{
MyMockTemplate: {
alcunit: "CYL",
blksize: 3130,
dirblk: 35,
dsorg: "PO",
lrecl: 40,
primary: 1,
recfm: "FB",
},
},
],
}),
update: jest.fn(),
keys: () => [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function createGlobalMocks() {

Object.defineProperty(ZoweLocalStorage, "storage", {
value: {
get: () => ({ persistence: true, favorites: [], history: [], sessions: ["zosmf"], searchHistory: [], fileHistory: [] }),
get: () => ({ persistence: true, favorites: [], history: [], sessions: ["zosmf"], searchHistory: [], fileHistory: [], templates: [] }),
update: jest.fn(),
keys: () => [],
},
Expand Down Expand Up @@ -3039,9 +3039,22 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {

describe("getDsTemplates", () => {
it("gets all the DS templates from persistent object", () => {
jest.spyOn(vscode.workspace, "getConfiguration").mockReturnValue({
get: () => ["test1", "test2", "test3"],
} as any);
Object.defineProperty(ZoweLocalStorage, "storage", {
value: {
get: () => ({
persistence: true,
favorites: [],
history: [],
sessions: ["zosmf"],
searchHistory: [],
fileHistory: [],
templates: ["test1", "test2", "test3"],
}),
update: jest.fn(),
keys: () => [],
},
configurable: true,
});
expect(tree.getDsTemplates()).toEqual(["test1", "test2", "test3"]);
});
});
Expand Down
53 changes: 26 additions & 27 deletions packages/zowe-explorer/src/PersistentFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
*
*/

import * as vscode from "vscode";
import * as api from "@zowe/zowe-explorer-api";
import * as globals from "./globals";
import * as api from "@zowe/zowe-explorer-api";
import { ZoweLogger } from "./utils/LoggerUtils";
import { SettingsConfig } from "./utils/SettingsConfig";
import { ZoweLocalStorage } from "./utils/ZoweLocalStorage";

export type PersistentFilter = {
Expand All @@ -23,6 +21,7 @@ export type PersistentFilter = {
sessions: string[];
searchHistory: string[];
fileHistory: string[];
templates: api.DataSetAllocTemplate[];
};

/**
Expand Down Expand Up @@ -120,14 +119,14 @@ export class PersistentFilters {
public addDsTemplateHistory(criteria: api.DataSetAllocTemplate): void {
if (criteria) {
let newTemplateName: string;
Object.entries(criteria).forEach(([key, value]) => {
Object.entries(criteria).forEach(([key]) => {
newTemplateName = key;
});
// Remove any entries that match
this.mDsTemplates = this.mDsTemplates.filter((template) => {
let historyName: string;
Object.entries(template).forEach(([key1, value]) => {
historyName = key1;
Object.entries(template).forEach(([key]) => {
historyName = key;
});
return historyName !== newTemplateName;
});
Expand Down Expand Up @@ -179,7 +178,7 @@ export class PersistentFilters {
}

public getDsTemplates(): api.DataSetAllocTemplate[] {
const dsTemplateLines: api.DataSetAllocTemplate[] = vscode.workspace.getConfiguration(this.schema).get(PersistentFilters.templates);
const dsTemplateLines: api.DataSetAllocTemplate[] = ZoweLocalStorage.getValue<PersistentFilter>(this.schema).templates;
if (dsTemplateLines.length !== this.mDsTemplates.length) {
this.mDsTemplates = dsTemplateLines;
}
Expand Down Expand Up @@ -211,7 +210,7 @@ export class PersistentFilters {
/**
* @param name - Should be in format "[session]: DATASET.QUALIFIERS" or "[session]: /file/path", as appropriate
*/
public removeFileHistory(name: string): Thenable<void> {
public removeFileHistory(name: string): void {
const index = this.mFileHistory.findIndex((fileHistoryItem) => {
return fileHistoryItem.includes(name.toUpperCase());
});
Expand All @@ -221,7 +220,7 @@ export class PersistentFilters {
return this.updateFileHistory();
}

public removeSearchHistory(name: string): Thenable<void> {
public removeSearchHistory(name: string): void {
const index = this.mSearchHistory.findIndex((searchHistoryItem) => {
return searchHistoryItem.includes(name);
});
Expand Down Expand Up @@ -262,48 +261,48 @@ export class PersistentFilters {
/* Update functions, for updating the settings.json file in VSCode
/*********************************************************************************************************************************************/

public updateFavorites(favorites: string[]): Thenable<void> {
// settings are read-only, so were cloned
const settings: any = { ...vscode.workspace.getConfiguration(this.schema) };
public updateFavorites(favorites: string[]): void {
ZoweLogger.trace("PersistentFilters.updateFavorites called.");
const settings = ZoweLocalStorage.getValue<PersistentFilter>(this.schema);
if (settings.persistence) {
settings.favorites = favorites;
return SettingsConfig.setDirectValue(this.schema, settings);
ZoweLocalStorage.setValue<PersistentFilter>(this.schema, settings);
}
}

private updateSearchHistory(): Thenable<void> {
// settings are read-only, so make a clone
const settings: any = { ...vscode.workspace.getConfiguration(this.schema) };
private updateSearchHistory(): void {
ZoweLogger.trace("PersistentFilters.updateSearchHistory called.");
const settings = { ...ZoweLocalStorage.getValue<PersistentFilter>(this.schema) };
if (settings.persistence) {
settings.searchHistory = this.mSearchHistory;
return SettingsConfig.setDirectValue(this.schema, settings);
ZoweLocalStorage.setValue<PersistentFilter>(this.schema, settings);
}
}

private updateSessions(): Thenable<void> {
// settings are read-only, so make a clone
const settings: any = { ...vscode.workspace.getConfiguration(this.schema) };
private updateSessions(): void {
ZoweLogger.trace("PersistentFilters.updateSessions called.");
const settings = { ...ZoweLocalStorage.getValue<PersistentFilter>(this.schema) };
if (settings.persistence) {
settings.sessions = this.mSessions;
return SettingsConfig.setDirectValue(this.schema, settings);
ZoweLocalStorage.setValue<PersistentFilter>(this.schema, settings);
}
}

private updateFileHistory(): Thenable<void> {
// settings are read-only, so make a clone
const settings: any = { ...vscode.workspace.getConfiguration(this.schema) };
private updateFileHistory(): void {
ZoweLogger.trace("PersistentFilters.updateFileHistory called.");
const settings = { ...ZoweLocalStorage.getValue<PersistentFilter>(this.schema) };
if (settings.persistence) {
settings.fileHistory = this.mFileHistory;
return SettingsConfig.setDirectValue(this.schema, settings);
ZoweLocalStorage.setValue<PersistentFilter>(this.schema, settings);
}
}

private updateDsTemplateHistory(): void {
// settings are read-only, so make a clone
const settings: any = { ...vscode.workspace.getConfiguration(this.schema) };
const settings: any = { ...ZoweLocalStorage.getValue<PersistentFilter>(this.schema) };
if (settings.persistence) {
settings.templates = this.mDsTemplates;
SettingsConfig.setDirectValue(this.schema, settings);
ZoweLocalStorage.setValue<PersistentFilter>(this.schema, settings);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/dataset/DatasetTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ export class DatasetTree extends ZoweTreeProvider implements IZoweTree<IZoweData
return this.mHistory.getFileHistory();
}

public removeFileHistory(name: string): Thenable<void> {
public removeFileHistory(name: string): void {
ZoweLogger.trace("DatasetTree.removeFileHistory called.");
return this.mHistory.removeFileHistory(name);
}
Expand Down
10 changes: 4 additions & 6 deletions packages/zowe-explorer/src/job/ZosJobsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export class ZosJobsProvider extends ZoweTreeProvider implements IZoweTree<IZowe
*
* @param {IZoweJobTreeNode} node
*/
public async addFavorite(node: IZoweJobTreeNode): Promise<void> {
public addFavorite(node: IZoweJobTreeNode): void {
ZoweLogger.trace("ZosJobsProvider.addFavorite called.");
let favJob: Job;
// Get node's profile node in favorites
Expand Down Expand Up @@ -533,7 +533,7 @@ export class ZosJobsProvider extends ZoweTreeProvider implements IZoweTree<IZowe
profileNodeInFavorites.children.push(favJob);
sortTreeItems(profileNodeInFavorites.children, globals.JOBS_SESSION_CONTEXT + globals.FAV_SUFFIX);
sortTreeItems(this.mFavorites, globals.FAV_PROFILE_CONTEXT);
await this.updateFavorites();
this.updateFavorites();
this.refreshElement(this.mFavoriteSession);
}
}
Expand All @@ -558,11 +558,10 @@ export class ZosJobsProvider extends ZoweTreeProvider implements IZoweTree<IZowe
return this.removeFavProfile(profileName, false);
}
if (startLength !== profileNodeInFavorites.children.length) {
await this.updateFavorites();
this.updateFavorites();
this.refreshElement(this.mFavoriteSession);
}
}
return;
}

public updateFavorites(): void {
Expand Down Expand Up @@ -624,8 +623,7 @@ export class ZosJobsProvider extends ZoweTreeProvider implements IZoweTree<IZowe
});

// Update the favorites in settings file
await this.updateFavorites();
return;
this.updateFavorites();
}

public removeSearchHistory(name: string): void {
Expand Down
8 changes: 3 additions & 5 deletions packages/zowe-explorer/src/uss/USSTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export class USSTree extends ZoweTreeProvider implements IZoweTree<IZoweUSSTreeN
profileNodeInFavorites.children.push(temp);
sortTreeItems(profileNodeInFavorites.children, globals.USS_SESSION_CONTEXT + globals.FAV_SUFFIX);
sortTreeItems(this.mFavorites, globals.FAV_PROFILE_CONTEXT);
await this.updateFavorites();
this.updateFavorites();
this.refreshElement(this.mFavoriteSession);
}
}
Expand Down Expand Up @@ -454,9 +454,8 @@ export class USSTree extends ZoweTreeProvider implements IZoweTree<IZoweUSSTreeN
return this.removeFavProfile(profileName, false);
}
}
await this.updateFavorites();
this.updateFavorites();
this.refreshElement(this.mFavoriteSession);
return;
}

public updateFavorites(): void {
Expand Down Expand Up @@ -511,8 +510,7 @@ export class USSTree extends ZoweTreeProvider implements IZoweTree<IZoweUSSTreeN
});

// Update the favorites in settings file
await this.updateFavorites();
return;
this.updateFavorites();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/zowe-explorer/src/utils/LoggerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as nls from "vscode-nls";
import { join as joinPath } from "path";
import { SettingsConfig } from "./SettingsConfig";
import * as loggerConfig from "../../log4jsconfig.json";
import { ZoweLocalStorage } from "./ZoweLocalStorage";

// Set up localization
nls.config({
Expand Down Expand Up @@ -157,8 +158,8 @@ export class ZoweLogger {
});
}

private static async setLogSetting(setting: string): Promise<void> {
await SettingsConfig.setDirectValue("zowe.logger", setting, vscode.ConfigurationTarget.Global);
private static setLogSetting(setting: string): void {
ZoweLocalStorage.setValue("zowe.logger", setting);
}

private static getZoweLogEnVar(): string {
Expand Down
Loading

0 comments on commit 5f84872

Please sign in to comment.