-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2925 from crshnburn/zos-console-panel
Contribute z/OS console panel
- Loading branch information
Showing
16 changed files
with
406 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
*/ | ||
|
||
export * from "./WebView"; | ||
export * as HTMLTemplate from "./utils/HTMLTemplate"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/zowe-explorer/__mocks__/@zowe/zos-console-for-zowe-sdk.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* 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. | ||
* | ||
*/ | ||
|
||
export interface IIssueParms {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/zowe-explorer/__tests__/__unit__/zosconsole/ZosConsolePanel.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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 { createInstanceOfProfile, createIProfile } from "../../../__mocks__/mockCreators/shared"; | ||
import { ZosConsoleViewProvider } from "../../../src/zosconsole/ZosConsolePanel"; | ||
import { Profiles } from "../../../src/Profiles"; | ||
import * as vscode from "vscode"; | ||
|
||
describe("ZosConsoleViewProvider", () => { | ||
function createGlobalMocks(): any { | ||
const newMocks = { | ||
imperativeProfile: createIProfile(), | ||
profileInstance: null, | ||
testWebView: {}, | ||
}; | ||
newMocks.testWebView = { | ||
webview: { | ||
postMessage: jest.fn(), | ||
asWebviewUri: jest.fn(), | ||
onDidReceiveMessage: jest.fn(), | ||
}, | ||
}; | ||
newMocks.profileInstance = createInstanceOfProfile(newMocks.imperativeProfile); | ||
Object.defineProperty(Profiles, "getInstance", { | ||
value: jest.fn().mockReturnValue(newMocks.profileInstance), | ||
configurable: true, | ||
}); | ||
Object.defineProperty(vscode.Uri, "joinPath", { value: jest.fn(), configurable: true }); | ||
|
||
return newMocks; | ||
} | ||
describe("resolveWebviewView", () => { | ||
it("should submit command", () => { | ||
const globalMocks = createGlobalMocks(); | ||
const myconsole = new ZosConsoleViewProvider({} as any); | ||
myconsole.resolveWebviewView(globalMocks.testWebView, {} as any, { isCancellationRequested: false } as any); | ||
expect(globalMocks.testWebView.webview.onDidReceiveMessage).toBeCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/zowe-explorer/src/webviews/src/zos-console/App.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Dropdown, Option, TextArea, TextField } from "@vscode/webview-ui-toolkit"; | ||
import { VSCodeDropdown, VSCodeTextArea, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"; | ||
import { useEffect, useState } from "preact/hooks"; | ||
|
||
declare const vscode: any; | ||
|
||
export function App() { | ||
const [consoleContent, setConsoleContent] = useState(""); | ||
useEffect(() => { | ||
window.addEventListener("message", (event) => { | ||
// Prevent users from sending data into webview outside of extension/webview context | ||
const eventUrl = new URL(event.origin); | ||
const isWebUser = | ||
(eventUrl.protocol === document.location.protocol && eventUrl.hostname === document.location.hostname) || | ||
eventUrl.hostname.endsWith(".github.dev"); | ||
const isLocalVSCodeUser = eventUrl.protocol === "vscode-webview:"; | ||
|
||
if (!isWebUser && !isLocalVSCodeUser) { | ||
return; | ||
} | ||
|
||
const message = event.data; | ||
const profileList = document.getElementById("systems") as Option; | ||
|
||
switch (message.type) { | ||
case "commandResult": | ||
setConsoleContent(consoleContent + `> ${message.cmd} (${message.profile})\n${message.result}`); | ||
break; | ||
case "optionsList": | ||
for (const profile in message.profiles) { | ||
const option = document.createElement("vscode-option"); | ||
option.textContent = message.profiles[profile]; | ||
if (message.profiles[profile] === message.defaultProfile) { | ||
option.setAttribute("selected", "true"); | ||
} | ||
profileList.appendChild(option); | ||
} | ||
break; | ||
} | ||
}); | ||
const consoleResponse = document.getElementById("output") as TextArea; | ||
consoleResponse.control.scrollTop = consoleResponse.control.scrollHeight; | ||
}); | ||
|
||
const sendCommand = (e: KeyboardEvent) => { | ||
const consoleField = document.getElementById("command-input") as TextField; | ||
const profileList = document.getElementById("systems") as Dropdown; | ||
if (e.key === "Enter") { | ||
if (consoleField!.value === "clear") { | ||
setConsoleContent(""); | ||
} else { | ||
vscode.postMessage({ | ||
command: "opercmd", | ||
profile: profileList.options[profileList.selectedIndex].text, | ||
text: consoleField.value, | ||
}); | ||
} | ||
consoleField.value = ""; | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="box"> | ||
<div style="display: flex; align-items: center; gap: 10px;"> | ||
<VSCodeTextField | ||
id="command-input" | ||
name="command-input" | ||
type="text" | ||
placeholder="Enter command here..." | ||
onKeyDown={sendCommand} | ||
style={{ | ||
width: "100%", | ||
"font-family": "Consolas,monospace", | ||
}} | ||
> | ||
<span slot="start" className="codicon codicon-chevron-right"></span> | ||
</VSCodeTextField> | ||
<VSCodeDropdown id="systems"></VSCodeDropdown> | ||
</div> | ||
<VSCodeTextArea | ||
id="output" | ||
readonly | ||
resize="none" | ||
value={consoleContent} | ||
style={{ | ||
width: "100%", | ||
height: "100%", | ||
overflow: "auto", | ||
display: "flex", | ||
"font-family": "Consolas,monospace", | ||
}} | ||
></VSCodeTextArea> | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/zowe-explorer/src/webviews/src/zos-console/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>z/OS Console</title> | ||
</head> | ||
<body> | ||
<div id="webviewRoot"></div> | ||
<script type="module" src="./index.tsx"></script> | ||
</body> | ||
</html> |
4 changes: 4 additions & 0 deletions
4
packages/zowe-explorer/src/webviews/src/zos-console/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { render } from "preact"; | ||
import { App } from "./App"; | ||
|
||
render(<App />, document.getElementById("webviewRoot")!); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.