From ec95aafa8190bfac04b4dc259f9a4f396f7a32b1 Mon Sep 17 00:00:00 2001 From: Gordon Smith Date: Fri, 8 Dec 2023 15:37:05 +0000 Subject: [PATCH] HPCC-30983 Honour direct URLs to ECL Watch Bypass the user nominated selection when direct URLs are provided. Signed-off-by: Gordon Smith --- esp/src/eclwatch/stub.js | 27 ++------------ esp/src/src-react/index.tsx | 74 +++++++++++++++++++------------------ esp/src/src/Session.ts | 57 ++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 60 deletions(-) diff --git a/esp/src/eclwatch/stub.js b/esp/src/eclwatch/stub.js index f56fe35a010..6b3e0fd4fd9 100644 --- a/esp/src/eclwatch/stub.js +++ b/esp/src/eclwatch/stub.js @@ -10,8 +10,6 @@ define([ "src/Utility", "src/Session", - "src/KeyValStore", - "src/BuildInfo", "hpcc/LockDialogWidget", "dojox/html/entities", @@ -22,7 +20,7 @@ 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(); @@ -30,27 +28,8 @@ define([ 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(); } }); diff --git a/esp/src/src-react/index.tsx b/esp/src/src-react/index.tsx index d9ffe2cb05b..b1ecffcc918 100644 --- a/esp/src/src-react/index.tsx +++ b/esp/src/src-react/index.tsx @@ -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"; @@ -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); - } - }); - } + }); } -}); +} diff --git a/esp/src/src/Session.ts b/esp/src/src/Session.ts index 26e48278a93..94a30108e11 100644 --- a/esp/src/src/Session.ts +++ b/esp/src/src/Session.ts @@ -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"; @@ -34,6 +35,62 @@ export async function fetchModernMode(): Promise { }); } +const isV5DirectURL = () => !!parseSearch(window.location.search)?.["Widget"]; +const isV9DirectURL = () => window.location.hash && window.location.hash.indexOf("#/stub/") !== 0; + +export async function needsRedirectV5(): Promise { + 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 { + 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 };