Skip to content

Commit

Permalink
fix: Persist entire IOptions through results view
Browse files Browse the repository at this point in the history
Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Jul 19, 2023
1 parent cb762fe commit 1c57fba
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 77 deletions.
2 changes: 1 addition & 1 deletion ecl-sample/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"serverAddress": "play.hpccsystems.com",
"port": 18010,
"targetCluster": "thor",
"rejectUnauthorized": true,
"rejectUnauthorized": false,
"resultLimit": 100,
"timeoutSecs": 60,
"user": "vscode_user",
Expand Down
35 changes: 18 additions & 17 deletions src/ecl/eclWatchPanelView.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import * as vscode from "vscode";
import { send } from "@hpcc-js/comms";
import { hashSum } from "@hpcc-js/util";
import { LaunchProtocol } from "../debugger/launchRequestArguments";
import { LaunchRequestArguments } from "../debugger/launchRequestArguments";
import { wuDetailsUrl, wuResultUrl } from "../hpccplatform/launchConfig";
import { sessionManager } from "../hpccplatform/session";
import type { Messages } from "../eclwatch/messages";

interface PartialLaunchRequestArgumentss {
protocol: LaunchProtocol;
serverAddress: string;
port: number;
path: string;
user?: string;
password?: string;
rejectUnauthorized?: boolean;
}

interface NavigateParams extends PartialLaunchRequestArgumentss {
interface NavigateParams extends LaunchRequestArguments {
wuid: string;
result?: number;
show: boolean;
Expand Down Expand Up @@ -111,7 +101,7 @@ export class ECLWatchPanelView implements vscode.WebviewViewProvider {
command: "proxyResponse",
id: message.id,
response
});
} as Messages);
delete abortControllers[message.id];
});
break;
Expand All @@ -130,9 +120,9 @@ export class ECLWatchPanelView implements vscode.WebviewViewProvider {
}

private _prevHash: string;
navigateTo(launchRequestArgs: PartialLaunchRequestArgumentss, wuid: string, result?: number, show = true) {
const { protocol, serverAddress, port, path, user, password, rejectUnauthorized } = launchRequestArgs;
this._currParams = { protocol, serverAddress, port, path, user, password, rejectUnauthorized, wuid, result, show };
navigateTo(launchRequestArgs: LaunchRequestArguments, wuid: string, result?: number, show = true) {
const { protocol, serverAddress, port, path, user, password, rejectUnauthorized, name, type, targetCluster } = launchRequestArgs;
this._currParams = { protocol, serverAddress, port, path, user, password, rejectUnauthorized, name, type, targetCluster, wuid, result, show };
if (!this._webviewView) {
this._initialParams = this._currParams;
if (show) {
Expand All @@ -143,7 +133,18 @@ export class ECLWatchPanelView implements vscode.WebviewViewProvider {
if (this._prevHash !== hash) {
this._prevHash = hash;
this._webviewView.title = this._currParams?.wuid;
this._webviewView.webview.postMessage({ command: "navigate", data: this._currParams });
this._webviewView.webview.postMessage({
command: "navigate",
data: {
baseUrl: this._currParams.protocol + "://" + this._currParams.serverAddress + ":" + this._currParams.port + "/",
userID: this._currParams.user,
password: this._currParams.password,
rejectUnauthorized: this._currParams.rejectUnauthorized,
timeoutSecs: this._currParams.timeoutSecs,
wuid: this._currParams.wuid,
result: this._currParams.result
}
} as Messages);
if (show) {
this._webviewView.show(true);
}
Expand Down
16 changes: 4 additions & 12 deletions src/eclwatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import * as React from "react";
import * as ReactDOM from "react-dom";
import { WUDetails } from "./eclwatch/WUDetails";
import { ThemeProvider } from "./eclwatch/themeGenerator";
import { join } from "@hpcc-js/util";
import { LoadedMessage, Messages, ProxyCancelMessage, ProxySendMessage, State, vscode } from "./eclwatch/messages";
import { LoadedMessage, ProxyCancelMessage, ProxySendMessage, State, vscode } from "./eclwatch/messages";
import { hookSend } from "@hpcc-js/comms";

const bodyStyles = window.getComputedStyle(document.body);
Expand Down Expand Up @@ -75,11 +74,8 @@ function render(state: State) {
if (state) {
vscode.setState(state);
ReactDOM.render(<WUDetails
baseUrl={join(`${state.protocol}://${state.serverAddress}:${state.port}`, state.path)}
rejectUnauthorized={state.rejectUnauthorized}
opts={state}
wuid={state.wuid}
user={state.user}
password={state.password}
sequence={state.result}
/>, placeholder);
}
Expand All @@ -92,13 +88,9 @@ function rerender() {
// Local debugging without VS Code
if (document.location.protocol === "file:") {
render({
protocol: "https",
serverAddress: "play.hpccsystems.com",
port: "18010",
path: "",
user: "gosmith",
baseUrl: "https://play.hpccsystems.com:18010",
userID: "gosmith",
password: "",
rejectUnauthorized: false,
wuid: "W20210304-144316"
});
}
Expand Down
20 changes: 7 additions & 13 deletions src/eclwatch/WUDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { Pivot, PivotItem, IPivotStyles, Spinner, initializeIcons, MessageBar, MessageBarType, IStyleFunctionOrObject, IPivotStyleProps } from "@fluentui/react";
import { Workunit, WUInfo, Result } from "@hpcc-js/comms";
import { Workunit, WUInfo, Result, IOptions } from "@hpcc-js/comms";
import { WUIssues, WUResult } from "./WUResult";
import { HolyGrail } from "./HolyGrail";

Expand Down Expand Up @@ -30,21 +30,15 @@ const getTabId = (itemKey: string) => {
};

export interface WUDetailsProps {
baseUrl: string;
user: string;
password: string;
opts: IOptions;
wuid: string;
sequence?: number;
rejectUnauthorized: boolean;
}

export const WUDetails: React.FunctionComponent<WUDetailsProps> = ({
baseUrl,
user,
password,
opts,
wuid,
sequence,
rejectUnauthorized
}) => {

const pivotRef = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -80,7 +74,7 @@ export const WUDetails: React.FunctionComponent<WUDetailsProps> = ({
if (wuid) {
setSpinnerMessage("Loading...");
update(false, [], []);
const wu = Workunit.attach({ baseUrl, userID: user, password, rejectUnauthorized }, wuid);
const wu = Workunit.attach(opts, wuid);
wu.refresh().then(() => {
if (!canceled) {
if (wu.isComplete()) {
Expand All @@ -107,11 +101,11 @@ export const WUDetails: React.FunctionComponent<WUDetailsProps> = ({
return () => {
canceled = true;
};
}, [baseUrl, wuid]);
}, [opts.baseUrl, wuid]);

React.useEffect(() => {
setSelectedKey(sequence === undefined ? "" + 0 : "" + sequence);
}, [baseUrl, wuid, sequence]);
}, [opts.baseUrl, wuid, sequence]);

const hasIssues = exceptions.length > 0;
const hasResults = results.length > 0;
Expand Down Expand Up @@ -151,7 +145,7 @@ export const WUDetails: React.FunctionComponent<WUDetailsProps> = ({
main={selected === "issues" ?
<WUIssues exceptions={exceptions} />
: hasResults ?
<WUResult baseUrl={baseUrl} user={user} password={password} wuid={wuid} sequence={parseInt(selectedKey)} />
<WUResult opts={opts} wuid={wuid} sequence={parseInt(selectedKey)} />
: undefined
}
/>;
Expand Down
35 changes: 10 additions & 25 deletions src/eclwatch/WUResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,9 @@ export class WUResultTable extends Common {
this.renderHtml(false);
}

@publish(undefined, "string", "URL to WsWorkunits")
baseUrl: { (): string, (_: string): WUResultTable };
@publish(undefined, "string", "Workunit ID")
user: { (): string, (_: string): WUResultTable };
@publish(undefined, "string", "User ID")
password: { (): string, (_: string): WUResultTable };
@publish(undefined, "string", "Password")
@publish(undefined, "object", "IOptions")
opts: { (): IOptions, (_: IOptions): WUResultTable };
@publish(undefined, "string", "Wuid")
wuid: { (): string, (_: string): WUResultTable };
@publish(undefined, "string", "Result Name")
resultName: { (): string, (_: string): WUResultTable };
Expand All @@ -235,17 +231,12 @@ export class WUResultTable extends Common {
logicalFile: { (): string, (_: string): WUResultTable };

calcResult(): Result | null {
const opts: IOptions = {
baseUrl: this.baseUrl(),
userID: this.user(),
password: this.password()
};
if (this.wuid() && this.resultName()) {
return Result.attach(opts, this.wuid(), this.resultName());
return Result.attach(this.opts(), this.wuid(), this.resultName());
} else if (this.wuid() && this.sequence() !== undefined) {
return Result.attach(opts, this.wuid(), this.sequence());
return Result.attach(this.opts(), this.wuid(), this.sequence());
} else if (this.logicalFile()) {
return Result.attachLogicalFile(opts, this.cluster(), this.logicalFile());
return Result.attachLogicalFile(this.opts(), this.cluster(), this.logicalFile());
}
return null;
}
Expand Down Expand Up @@ -311,7 +302,7 @@ export class WUResultTable extends Common {
update(domNode, element) {
super.update(domNode, element);
const hash = hashSum({
wsWorkunitsUrl: this.baseUrl(),
opts: hashSum(this.opts()),
wuid: this.wuid(),
resultName: this.resultName(),
sequence: this.sequence(),
Expand Down Expand Up @@ -402,17 +393,13 @@ export class WUResultTable extends Common {
WUResultTable.prototype._class += " eclwatch_WUResultTable";

interface WUResultProps {
baseUrl: string;
user: string;
password: string;
opts: IOptions;
wuid: string;
sequence: number;
}

export const WUResult: React.FunctionComponent<WUResultProps> = ({
baseUrl,
user,
password,
opts,
wuid,
sequence,
}) => {
Expand All @@ -422,9 +409,7 @@ export const WUResult: React.FunctionComponent<WUResultProps> = ({
).current;

table
.baseUrl(baseUrl)
.user(user)
.password(password)
.opts(opts)
.wuid(wuid)
.sequence(sequence)
;
Expand Down
24 changes: 15 additions & 9 deletions src/eclwatch/messages.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
export interface State {
protocol: string;
serverAddress: string;
port: string;
path: string;
user: string;
password: string;
rejectUnauthorized: boolean;
import type { IOptions } from "@hpcc-js/comms";

export interface State extends IOptions {
wuid: string;
result?: number;
}
Expand All @@ -24,6 +19,11 @@ export interface Message {
callbackID?: string;
}

export interface NavigateMessage extends Message {
command: "navigate";
data: State;
}

export interface LoadedMessage extends Message {
command: "loaded";
}
Expand All @@ -41,9 +41,15 @@ export interface ProxySendMessage extends Message {
}
}

export interface ProxyResponseMessage extends Message {
command: "proxyResponse";
id: number;
response: any;
}

export interface ProxyCancelMessage extends Message {
command: "proxyCancel";
id: number;
}

export type Messages = LoadedMessage | ProxySendMessage | ProxyCancelMessage;
export type Messages = NavigateMessage | LoadedMessage | ProxySendMessage | ProxyResponseMessage | ProxyCancelMessage;

0 comments on commit 1c57fba

Please sign in to comment.