Skip to content

Commit

Permalink
added toggleresources command
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Twydell <[email protected]>
  • Loading branch information
AndrewTwydell committed Jan 29, 2025
1 parent 616e791 commit 7282897
Show file tree
Hide file tree
Showing 11 changed files with 1,499 additions and 275 deletions.
1,577 changes: 1,333 additions & 244 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
},
"repository": "https://github.com/zowe/cics-for-zowe-client",
"workspaces": [
"packages/*"
"packages/*",
"packages/vsce/src/webviews"
],
"scripts": {
"build": "turbo build",
Expand Down Expand Up @@ -63,5 +64,8 @@
"typedoc": "^0.25.9",
"typescript": "^5.3.3",
"uuid": "^9.0.0"
},
"dependencies": {
"@vscode/l10n": "^0.0.18"
}
}
24 changes: 22 additions & 2 deletions packages/vsce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
"dark": "resources/imgs/plus-light.svg"
}
},
{
"command": "cics-extension-for-zowe.toggleResources",
"title": "Toggle resources",
"category": "IBM CICS for Zowe Explorer",
"icon": {
"light": "resources/imgs/newcopy-dark.svg",
"dark": "resources/imgs/newcopy-light.svg"
}
},
{
"command": "cics-extension-for-zowe.refreshTree",
"title": "Refresh",
Expand Down Expand Up @@ -416,6 +425,11 @@
],
"menus": {
"view/title": [
{
"command": "cics-extension-for-zowe.toggleResources",
"when": "view == cics-view",
"group": "navigation"
},
{
"command": "cics-extension-for-zowe.refreshTree",
"when": "view == cics-view",
Expand Down Expand Up @@ -750,7 +764,12 @@
"programSearchHistory": [],
"transactionSearchHistory": [],
"localFileSearchHistory": [],
"loadedCICSProfile": []
"loadedCICSProfile": [],
"visibleResources": [
"CICSProgram",
"CICSLocalTransaction",
"CICSLocalFile"
]
},
"description": "Zowe CICS Extension History",
"scope": "window"
Expand Down Expand Up @@ -896,8 +915,9 @@
"@vscode/vsce": "^2.32.0"
},
"dependencies": {
"@vscode-elements/react-elements": "^0.8.0",
"@zowe/cics-for-zowe-sdk": "6.2.4",
"@zowe/core-for-zowe-sdk": "^8.0.0",
"@zowe/zowe-explorer-api": "^3.0.3"
}
}
}
7 changes: 5 additions & 2 deletions packages/vsce/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import * as disableCommands from './disableCommands';
import * as enableCommands from './enableCommands';

import { TreeView } from 'vscode';
import { ExtensionContext, TreeView } from 'vscode';
import { CICSTree } from '../trees/CICSTree';
import { getAddSessionCommand } from "./addSessionCommand";
import { getClearPlexFilterCommand } from "./clearPlexFilterCommand";
Expand All @@ -32,8 +32,9 @@ import { getRefreshCommand } from "./refreshCommand";
import * as showAttributesCommands from "./showAttributesCommand";
import { getShowRegionSITParametersCommand } from "./showParameterCommand";
import { viewMoreCommand } from "./viewMoreCommand";
import { getToggleResourcesCommand } from './toggleResourcesCommand';

export const getCommands = (treeDataProv: CICSTree, treeview: TreeView<any>) => {
export const getCommands = (treeDataProv: CICSTree, treeview: TreeView<any>, context: ExtensionContext) => {
return [
getAddSessionCommand(treeDataProv),
getManageSessionCommand(treeDataProv, treeview),
Expand Down Expand Up @@ -100,5 +101,7 @@ export const getCommands = (treeDataProv: CICSTree, treeview: TreeView<any>) =>

getInquireTransactionCommand(treeDataProv, treeview),
getInquireProgramCommand(treeDataProv, treeview),

getToggleResourcesCommand(context),
];
};
19 changes: 19 additions & 0 deletions packages/vsce/src/commands/toggleResourcesCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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, ExtensionContext } from "vscode";
import { ToggleResourceTreeWebView } from "../trees/ToggleResourceTreeWebView";

export function getToggleResourcesCommand(context: ExtensionContext) {
return commands.registerCommand("cics-extension-for-zowe.toggleResources", () => {
return new ToggleResourceTreeWebView(context);
});
}
4 changes: 2 additions & 2 deletions packages/vsce/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ export async function activate(context: ExtensionContext) {
treeDataProv._onDidChangeTreeData.fire(undefined);
});

context.subscriptions.concat(getCommands(treeDataProv, treeview));
}
context.subscriptions.concat(getCommands(treeDataProv, treeview, context));
}
29 changes: 16 additions & 13 deletions packages/vsce/src/trees/CICSRegionTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import { getIconFilePathFromName } from "../utils/iconUtils";
import { IRegion, IResource } from "@zowe/cics-for-zowe-sdk";
import { CICSLibraryTree } from "./CICSLibraryTree";
import { CICSResourceTree } from "./CICSResourceTree";
import { LocalFileMeta, PipelineMeta, ProgramMeta, TaskMeta, TransactionMeta, URIMapMeta } from "../doc";
import { TCPIPMeta } from "../doc/TCPIPMeta";
import { WebServiceMeta } from "../doc/WebServiceMeta";
import { getMetas } from "../doc";
import { CICSRegionsContainer } from "./CICSRegionsContainer";
import { RegionMeta } from "../doc/RegionMeta";
import { PersistentStorage } from "../utils/PersistentStorage";

export class CICSRegionTree extends TreeItem {
children: (CICSResourceTree<IResource> | CICSLibraryTree)[] | null;
Expand Down Expand Up @@ -52,18 +51,22 @@ export class CICSRegionTree extends TreeItem {
}
this.iconPath = getIconFilePathFromName(RegionMeta.getIconName(region));
if (this.isActive) {

const pers = new PersistentStorage("zowe.cics.persistent");

const visibles = pers.getVisibleResources();
const availableMetas = getMetas();

this.children = [
new CICSResourceTree(ProgramMeta, this),
new CICSResourceTree(TransactionMeta, this),
new CICSResourceTree(LocalFileMeta, this),
new CICSResourceTree(TaskMeta, this),
new CICSLibraryTree(this),
// new CICSWebTree(this),
new CICSResourceTree(TCPIPMeta, this),
new CICSResourceTree(URIMapMeta, this),
new CICSResourceTree(PipelineMeta, this),
new CICSResourceTree(WebServiceMeta, this),
...availableMetas.filter((meta) => visibles.includes(meta.resourceName)).map((meta) => {
if (meta.resourceName === "CICSLibrary") {
return new CICSLibraryTree(this);
}
// @ts-ignore
return new CICSResourceTree(meta, this);
}),
];

} else {
this.children = null;
this.collapsibleState = TreeItemCollapsibleState.None;
Expand Down
44 changes: 44 additions & 0 deletions packages/vsce/src/trees/ToggleResourceTreeWebView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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 { WebView } from '@zowe/zowe-explorer-api';
import { getMetas } from '../doc';
import { PersistentStorage } from '../utils/PersistentStorage';
import { commands, ExtensionContext } from 'vscode';

export class ToggleResourceTreeWebView extends WebView {

persistentStorage: PersistentStorage;

constructor(context: ExtensionContext) {
super('Toggle Resources', "toggle-resources", context, {
onDidReceiveMessage: (message: { command: string; metas?: any[]; }) => this.onDidReceiveMessage(message),
retainContext: true,
});
this.persistentStorage = new PersistentStorage("zowe.cics.persistent");
}

async onDidReceiveMessage(message: { command: string; metas?: any[]; }) {
if (message.command === "metas") {
await this.persistentStorage.init();
const visibles = this.persistentStorage.getVisibleResources();

await this.panel.webview.postMessage({
metas: getMetas().map((meta) => { return { ...meta, visible: visibles.includes(meta.resourceName) }; })
});
} else if (message.command === "save") {
const visibleResources = message.metas.filter((meta) => meta.visible).map((meta) => meta.resourceName);
await this.persistentStorage.setVisibleResources(visibleResources);
this.panel.dispose();
commands.executeCommand("cics-extension-for-zowe.refreshTree");
}
}
}
39 changes: 38 additions & 1 deletion packages/vsce/src/utils/PersistentStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class PersistentStorage {
private static readonly urimapsSearchHistory: string = "urimapsSearchHistory";
private static readonly pipelineSearchHistory: string = "pipelineSearchHistory";
private static readonly webserviceSearchHistory: string = "webserviceSearchHistory";
private static readonly visibleResources: string = "visibleResources";

private mProgramSearchHistory: string[] = [];
private mLibrarySearchHistory: string[] = [];
Expand All @@ -37,13 +38,18 @@ export class PersistentStorage {
private mURIMapsSearchHistory: string[] = [];
private mPipelineSearchHistory: string[] = [];
private mWebServiceSearchHistory: string[] = [];
private mVisibleResources: string[] = [
"CICSProgram",
"CICSLocalTransaction",
"CICSLocalFile"
];

constructor(schema: string) {
this.schema = schema;
this.init();
}

private async init(): Promise<void> {
public async init(): Promise<void> {
let programSearchHistoryLines: string[] | undefined;
let librarySearchHistoryLines: string[] | undefined;
let datasetSearchHistoryLines: string[] | undefined;
Expand All @@ -55,6 +61,7 @@ export class PersistentStorage {
let urimapsSearchHistoryLines: string[] | undefined;
let pipelineSearchHistoryLines: string[] | undefined;
let webserviceSearchHistoryLines: string[] | undefined;
let visibleResourcesLines: string[] | undefined;

if (workspace.getConfiguration(this.schema)) {
programSearchHistoryLines = workspace.getConfiguration(this.schema).get(PersistentStorage.programSearchHistory);
Expand All @@ -68,6 +75,7 @@ export class PersistentStorage {
urimapsSearchHistoryLines = workspace.getConfiguration(this.schema).get(PersistentStorage.urimapsSearchHistory);
pipelineSearchHistoryLines = workspace.getConfiguration(this.schema).get(PersistentStorage.pipelineSearchHistory);
webserviceSearchHistoryLines = workspace.getConfiguration(this.schema).get(PersistentStorage.webserviceSearchHistory);
visibleResourcesLines = workspace.getConfiguration(this.schema).get(PersistentStorage.visibleResources);
}
if (programSearchHistoryLines) {
this.mProgramSearchHistory = programSearchHistoryLines;
Expand Down Expand Up @@ -124,6 +132,11 @@ export class PersistentStorage {
} else {
await this.resetWebServiceSearchHistory();
}
if (visibleResourcesLines) {
this.mVisibleResources = visibleResourcesLines;
} else {
await this.resetVisibleResources();
}
}

public getProgramSearchHistory(): string[] {
Expand Down Expand Up @@ -159,6 +172,9 @@ export class PersistentStorage {
public getWebServiceSearchHistory(): string[] {
return this.mWebServiceSearchHistory;
}
public getVisibleResources(): string[] {
return this.mVisibleResources;
}

public async resetProgramSearchHistory(): Promise<void> {
this.mProgramSearchHistory = [];
Expand Down Expand Up @@ -204,6 +220,14 @@ export class PersistentStorage {
this.mWebServiceSearchHistory = [];
await this.updateWebServiceSearchHistory();
}
public async resetVisibleResources(): Promise<void> {
this.mVisibleResources = [
"CICSProgram",
"CICSLocalTransaction",
"CICSLocalFile"
];
await this.updateVisibleResources();
}

private async updateProgramSearchHistory(): Promise<void> {
const settings: any = { ...workspace.getConfiguration(this.schema) };
Expand Down Expand Up @@ -285,6 +309,14 @@ export class PersistentStorage {
}
}

private async updateVisibleResources(): Promise<void> {
const settings: any = { ...workspace.getConfiguration(this.schema) };
if (settings.persistence) {
settings[PersistentStorage.visibleResources] = this.mVisibleResources;
await workspace.getConfiguration().update(this.schema, settings, ConfigurationTarget.Global);
}
}

public async addProgramSearchHistory(criteria: string): Promise<void> {
if (criteria) {
this.mProgramSearchHistory = this.mProgramSearchHistory.filter((element) => {
Expand Down Expand Up @@ -446,6 +478,11 @@ export class PersistentStorage {
}
}

public async setVisibleResources(visibles: string[]): Promise<void> {
this.mVisibleResources = visibles;
await this.updateVisibleResources();
}

public async removeLoadedCICSProfile(name: string): Promise<void> {
if (name) {
this.mLoadedCICSProfile = this.mLoadedCICSProfile.filter((element) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/vsce/src/webviews/src/toggle-resources/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
*/
import { VscodeButton, VscodeCheckbox } from "@vscode-elements/react-elements";
import { useEffect, useState } from "preact/hooks";
import PersistentVSCodeAPI from "src/PersistentVSCodeAPI";

const vscodeApi = PersistentVSCodeAPI.getVSCodeAPI();
const vscodeApi = acquireVsCodeApi();

export function App() {

Expand Down
22 changes: 14 additions & 8 deletions packages/vsce/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"],
"outDir": "./lib"
},
"include": [
"./src/**/*.ts"
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": [
"node",
"jest"
],
}
"outDir": "./lib"
},
"include": [
"./src/**/*.ts"
],
"exclude": [
"src/webviews/**",
]
}

0 comments on commit 7282897

Please sign in to comment.