Skip to content

Commit

Permalink
add option to change tag of uss file
Browse files Browse the repository at this point in the history
Signed-off-by: Rudy Flores <[email protected]>
  • Loading branch information
rudyflores committed Sep 19, 2023
1 parent 5309909 commit 1dea648
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/zowe-explorer-api/src/profiles/ZoweExplorerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ export namespace ZoweExplorerApi {
* @returns {Promise<zowe.IZosFilesResponse>}
*/
rename(currentUssPath: string, newUssPath: string): Promise<zowe.IZosFilesResponse>;

/**
* Get the tag of a USS file
*
* @param {string} currentUssPath
* @returns {Promise<zowe.IZosFilesResponse>}
*/
getTag?(ussPath: string): Promise<string>;
}

/**
Expand Down
21 changes: 20 additions & 1 deletion packages/zowe-explorer-api/src/profiles/ZoweExplorerZosmfApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ export class ZosmfUssApi extends ZosmfApiCommon implements ZoweExplorerApi.IUss

public async updateAttributes(ussPath: string, attributes: Partial<FileAttributes>): Promise<zowe.IZosFilesResponse> {
try {
if (attributes.tag) {
await zowe.Utilities.putUSSPayload(this.getSession(), ussPath, {
request: "chtag",
action: "set",
type: "text",
codeset: attributes.tag !== null ? attributes.tag.toString() : attributes.tag,
});
}
if ((attributes.group || attributes.gid) && (attributes.owner || attributes.uid)) {
await zowe.Utilities.putUSSPayload(this.getSession(), ussPath, {
request: "chown",
Expand All @@ -161,7 +169,6 @@ export class ZosmfUssApi extends ZosmfApiCommon implements ZoweExplorerApi.IUss
recursive: true,
});
}

if (attributes.perms) {
await zowe.Utilities.putUSSPayload(this.getSession(), ussPath, {
request: "chmod",
Expand Down Expand Up @@ -205,6 +212,18 @@ export class ZosmfUssApi extends ZosmfApiCommon implements ZoweExplorerApi.IUss
apiResponse: result,
};
}

public async getTag(ussPath: string): Promise<string> {
const result = JSON.parse(
Buffer.from(
await zowe.Utilities.putUSSPayload(this.getSession(), ussPath, {
request: "chtag",
action: "list",
})
).toString()
);
return result.stdout[0].split(" ")[1] as string;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/zowe-explorer-api/src/utils/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type FileAttributes = {
owner: string;
uid: number;
perms: string;
tag?: string;
};

export function permStringToOctal(perms: string): number {
Expand Down
5 changes: 4 additions & 1 deletion packages/zowe-explorer/i18n/sample/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,8 @@
"createZoweSchema.reload.button": "Reload Window",
"createZoweSchema.reload.infoMessage": "Team Configuration file created. Location: {0}. \n Please reload your window.",
"copyFile": "Copy",
"pasteFile": "Paste"
"pasteFile": "Paste",
"jobs.sortbyreturncode": "Sort by ReturnCode",
"jobs.sortbyname": "Sort by Name",
"jobs.sortbyid": "Sort by ID"
}
13 changes: 13 additions & 0 deletions packages/zowe-explorer/src/uss/AttributeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { FileAttributes, Gui, IZoweTree, IZoweUSSTreeNode, WebView, ZoweExplorerApi } from "@zowe/zowe-explorer-api";
import { Disposable, ExtensionContext } from "vscode";
import { ZoweExplorerApiRegister } from "../ZoweExplorerApiRegister";
import * as contextually from "../shared/context";

export class AttributeView extends WebView {
private treeProvider: IZoweTree<IZoweUSSTreeNode>;
Expand All @@ -30,11 +31,18 @@ export class AttributeView extends WebView {
this.ussApi = ZoweExplorerApiRegister.getUssApi(this.ussNode.getProfile());
}

private async attachTag(node: IZoweUSSTreeNode): Promise<void> {
if (this.ussApi.getTag && !contextually.isUssDirectory(node)) {
node.attributes.tag = await this.ussApi.getTag(node.fullPath);
}
}

protected async onDidReceiveMessage(message: any): Promise<void> {
switch (message.command) {
case "refresh":
if (this.canUpdate) {
this.onUpdateDisposable = this.ussNode.onUpdate(async (node) => {
await this.attachTag(node);
await this.panel.webview.postMessage({
attributes: node.attributes,
name: node.fullPath,
Expand All @@ -51,6 +59,7 @@ export class AttributeView extends WebView {
}
break;
case "ready":
await this.attachTag(this.ussNode);
await this.panel.webview.postMessage({
attributes: this.ussNode.attributes,
name: this.ussNode.fullPath,
Expand Down Expand Up @@ -104,6 +113,10 @@ export class AttributeView extends WebView {
newAttrs.perms = attrs.perms;
}

if (this.ussNode.attributes.tag !== attrs.tag && this.ussApi.getTag) {
newAttrs.tag = attrs.tag;
}

await this.ussApi.updateAttributes(this.ussNode.fullPath, newAttrs);
this.ussNode.attributes = { ...(this.ussNode.attributes ?? {}), ...newAttrs } as FileAttributes;

Expand Down
13 changes: 13 additions & 0 deletions packages/zowe-explorer/webviews/edit-attributes/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import isEqual from "lodash.isequal";
const vscodeApi = acquireVsCodeApi();

export function App() {
const notSupported = "NOT SUPPORTED";
const [readonly, setReadonly] = useState(false);
const [allowUpdate, setAllowUpdate] = useState(false);
const [attributes, setAttributes] = useState<Record<"current" | "initial", FileAttributes | null>>({
Expand Down Expand Up @@ -111,6 +112,7 @@ export function App() {
};
return all;
}, {}),
tag: attributes.tag ?? notSupported,
};

setAttributes({
Expand Down Expand Up @@ -155,6 +157,17 @@ export function App() {
<pre style={{ fontSize: "1.25em" }}>{attributes.current.name}</pre>
</strong>
<VSCodeDivider />
{attributes.initial?.directory ?? false ? null : (
<div style={{ marginTop: "1em", display: "flex", marginLeft: "1em" }}>
<VSCodeTextField
readonly={attributes.current.tag === notSupported}
value={attributes.current.tag}
onInput={(e: any) => updateFileAttributes("tag", e.target.value)}
>
Tag
</VSCodeTextField>
</div>
)}
<div style={{ marginTop: "1em" }}>
<div style={{ maxWidth: "fit-content" }}>
<div style={{ display: "flex", marginLeft: "1em" }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export type FileAttributes = {
directory: boolean;
group: string;
perms: FilePermissions;
tag?: string;
};

0 comments on commit 1dea648

Please sign in to comment.