Skip to content

Commit

Permalink
HPCC-30983 Honour direct URLs to ECL Watch
Browse files Browse the repository at this point in the history
Bypass the user nominated selection when direct URLs are provided.

Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Dec 8, 2023
1 parent 1d4939e commit ec95aaf
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 60 deletions.
27 changes: 3 additions & 24 deletions esp/src/eclwatch/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ define([

"src/Utility",
"src/Session",
"src/KeyValStore",
"src/BuildInfo",
"hpcc/LockDialogWidget",

"dojox/html/entities",
Expand All @@ -22,35 +20,16 @@ define([
"css!hpcc/css/hpcc.css"

], function (fx, dom, domStyle, ioQuery, ready, lang, arrayUtil, topic,
Utility, Session, KeyValStore, BuildInfo, LockDialogWidget,
Utility, Session, LockDialogWidget,
entities, Toaster) {

Session.initSession();

const params = ioQuery.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search.substr(0, 1) === "?" ? 1 : 0)));
const hpccWidget = params.Widget ? params.Widget : "HPCCPlatformWidget";

Session.fetchModernMode().then(modernMode => {
if (modernMode === String(true) && hpccWidget !== "IFrameWidget") {
switch (hpccWidget) {
case "WUDetailsWidget":
window.location.replace(`/esp/files/index.html#/workunits/${params.Wuid}`);
break;
case "GraphsWUWidget":
window.location.replace(`/esp/files/index.html#/workunits/${params.Wuid}/metrics`);
break;
case "TopologyWidget":
case "DiskUsageWidget":
case "TargetClustersQueryWidget":
case "ClusterProcessesQueryWidget":
case "SystemServersQueryWidget":
case "LogWidget":
loadUI();
break;
default:
window.location.replace("/esp/files/index.html");
}
} else {
Session.needsRedirectV5().then(redirected => {
if (!redirected) {
loadUI();
}
});
Expand Down
74 changes: 38 additions & 36 deletions esp/src/src-react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ReactDOM from "react-dom";
import { initializeIcons } from "@fluentui/react";
import { scopedLogger } from "@hpcc-js/util";
import { cookieKeyValStore } from "src/KeyValStore";
import { fetchModernMode } from "src/Session";
import { needsRedirectV9 } from "src/Session";
import { ECLWatchLogger } from "./hooks/logging";
import { replaceUrl } from "./util/history";

Expand Down Expand Up @@ -32,41 +32,43 @@ dojoConfig.urlInfo = {
};
dojoConfig.disableLegacyHashing = true;

fetchModernMode().then(async modernMode => {
if (modernMode === String(false)) {
window.location.replace("/esp/files/stub.htm");
needsRedirectV9().then(async redirected => {
if (!redirected) {
loadUI();
}
});

async function loadUI() {
const authTypeResp = await fetch("/esp/getauthtype");
const authType = await authTypeResp?.text() ?? "None";
const userStore = cookieKeyValStore();
const userSession = await userStore.getAll();
if (authType.indexOf("None") < 0 && (userSession["ESPSessionState"] === "false" || userSession["ECLWatchUser"] === "false" || (!userSession["Status"] || userSession["Status"] === "Locked"))) {
if (window.location.hash.indexOf("login") < 0) {
replaceUrl("/login");
}
import("./components/forms/Login").then(_ => {
try {
ReactDOM.render(
<_.Login />,
document.getElementById("placeholder")
);
document.getElementById("loadingOverlay").remove();
} catch (e) {
logger.error(e);
}
});
} else {
const authTypeResp = await fetch("/esp/getauthtype");
const authType = await authTypeResp?.text() ?? "None";
const userStore = cookieKeyValStore();
const userSession = await userStore.getAll();
if (authType.indexOf("None") < 0 && (userSession["ESPSessionState"] === "false" || userSession["ECLWatchUser"] === "false" || (!userSession["Status"] || userSession["Status"] === "Locked"))) {
if (window.location.hash.indexOf("login") < 0) {
replaceUrl("/login");
import("./components/Frame").then(_ => {
try {
ReactDOM.render(
<_.Frame />,
document.getElementById("placeholder")
);
document.getElementById("loadingOverlay").remove();
} catch (e) {
logger.error(e);
}
import("./components/forms/Login").then(_ => {
try {
ReactDOM.render(
<_.Login />,
document.getElementById("placeholder")
);
document.getElementById("loadingOverlay").remove();
} catch (e) {
logger.error(e);
}
});
} else {
import("./components/Frame").then(_ => {
try {
ReactDOM.render(
<_.Frame />,
document.getElementById("placeholder")
);
document.getElementById("loadingOverlay").remove();
} catch (e) {
logger.error(e);
}
});
}
});
}
});
}
57 changes: 57 additions & 0 deletions esp/src/src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { format as d3Format } from "@hpcc-js/common";
import { SMCService } from "@hpcc-js/comms";
import { cookieKeyValStore, sessionKeyValStore, userKeyValStore } from "src/KeyValStore";
import { singletonDebounce } from "../src-react/util/throttle";
import { parseSearch } from "../src-react/util/history";
import { ModernMode } from "./BuildInfo";
import * as ESPUtil from "./ESPUtil";
import { scopedLogger } from "@hpcc-js/util";
Expand Down Expand Up @@ -34,6 +35,62 @@ export async function fetchModernMode(): Promise<string> {
});
}

const isV5DirectURL = () => !!parseSearch(window.location.search)?.["Widget"];
const isV9DirectURL = () => window.location.hash && window.location.hash.indexOf("#/stub/") !== 0;

export async function needsRedirectV5(): Promise<boolean> {
if (isV9DirectURL()) {
window.location.replace(`/esp/files/index.html${window.location.hash}`);
return true;
}
if (isV5DirectURL()) {
return false;
}

const v9Mode = await fetchModernMode() === String(true);
if (v9Mode) {
const params = parseSearch(window.location.search);
if (params?.["hpccWidget"] !== "IFrameWidget") {
switch (params?.["hpccWidget"]) {
case "WUDetailsWidget":
window.location.replace(`/esp/files/index.html#/workunits/${params.Wuid}`);
break;
case "GraphsWUWidget":
window.location.replace(`/esp/files/index.html#/workunits/${params.Wuid}/metrics`);
break;
case "TopologyWidget":
case "DiskUsageWidget":
case "TargetClustersQueryWidget":
case "ClusterProcessesQueryWidget":
case "SystemServersQueryWidget":
case "LogWidget":
return false;
default:
window.location.replace("/esp/files/index.html");
}
return true;
}
}
return false;
}

export async function needsRedirectV9(): Promise<boolean> {
if (isV5DirectURL()) {
window.location.replace(`/esp/files/stub.htm${window.location.search}`);
return true;
}
if (isV9DirectURL()) {
return false;
}

const v5Mode = await fetchModernMode() === String(false);
if (v5Mode) {
window.location.replace(`/esp/files/stub.htm${window.location.search}`);
return true;
}
return false;
}

const smc = new SMCService({ baseUrl: "" });

export type BuildInfo = { [key: string]: string };
Expand Down

0 comments on commit ec95aaf

Please sign in to comment.