From af7a010558038bc80c762391e6f4af32aa6fd886 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Wed, 10 Jul 2024 22:41:47 +0200 Subject: [PATCH] Fix agent-mode menu items, path prefix calculation, and homepage redirects Signed-off-by: Julius Volz --- web/ui/mantine-ui/src/App.tsx | 146 ++++++++++++++++++++-------------- web/web.go | 7 +- 2 files changed, 91 insertions(+), 62 deletions(-) diff --git a/web/ui/mantine-ui/src/App.tsx b/web/ui/mantine-ui/src/App.tsx index 60376ae92a..5592ece217 100644 --- a/web/ui/mantine-ui/src/App.tsx +++ b/web/ui/mantine-ui/src/App.tsx @@ -74,12 +74,14 @@ const mainNavPages = [ path: "/query", icon: , element: , + inAgentMode: false, }, { title: "Alerts", path: "/alerts", icon: , element: , + inAgentMode: false, }, ]; @@ -89,18 +91,21 @@ const monitoringStatusPages = [ path: "/targets", icon: , element: , + inAgentMode: true, }, { title: "Rule health", path: "/rules", icon: , element: , + inAgentMode: false, }, { title: "Service discovery", path: "/service-discovery", icon: , element: , + inAgentMode: true, }, ]; @@ -110,29 +115,32 @@ const serverStatusPages = [ path: "/status", icon: , element: , + inAgentMode: true, }, { title: "TSDB status", path: "/tsdb-status", icon: , element: , + inAgentMode: false, }, { title: "Command-line flags", path: "/flags", icon: , element: , + inAgentMode: true, }, { title: "Configuration", path: "/config", icon: , element: , + inAgentMode: true, }, ]; const allStatusPages = [...monitoringStatusPages, ...serverStatusPages]; -const allPages = [...mainNavPages, ...allStatusPages]; const theme = createTheme({ colors: { @@ -159,7 +167,13 @@ const getPathPrefix = (path: string) => { path = path.slice(0, -1); } - const pagePath = allPages.find((p) => path.endsWith(p.path))?.path; + const pagePaths = [ + ...mainNavPages, + ...allStatusPages, + { path: "/agent" }, + ].map((p) => p.path); + + const pagePath = pagePaths.find((p) => path.endsWith(p)); return path.slice(0, path.length - (pagePath || "").length); }; @@ -176,41 +190,45 @@ function App() { const navLinks = ( <> - {mainNavPages.map((p) => ( - - ))} + {mainNavPages + .filter((p) => !agentMode || p.inAgentMode) + .map((p) => ( + + ))} - {allStatusPages.map((p) => ( - - - - } - /> - ))} + {allStatusPages + .filter((p) => !agentMode || p.inAgentMode) + .map((p) => ( + + + + } + /> + ))} Monitoring status - {monitoringStatusPages.map((p) => ( - - {p.title} - - ))} + {monitoringStatusPages + .filter((p) => !agentMode || p.inAgentMode) + .map((p) => ( + + {p.title} + + ))} Server status - {serverStatusPages.map((p) => ( - - {p.title} - - ))} + {serverStatusPages + .filter((p) => !agentMode || p.inAgentMode) + .map((p) => ( + + {p.title} + + ))} @@ -350,12 +372,20 @@ function App() { + } /> - } /> - } /> - } /> + {agentMode ? ( + } /> + ) : ( + <> + } /> + } /> + + )} {allStatusPages.map((p) => ( ))} diff --git a/web/web.go b/web/web.go index d4d2198d5e..4f65cf39d7 100644 --- a/web/web.go +++ b/web/web.go @@ -70,7 +70,6 @@ var reactRouterPaths = []string{ "/service-discovery", "/status", "/targets", - "/starting", } // Paths that are handled by the React router when the Agent mode is set. @@ -367,12 +366,12 @@ func New(logger log.Logger, o *Options) *Handler { } homePage := "/graph" - if o.IsAgent { - homePage = "/agent" - } if o.UseNewUI { homePage = "/query" } + if o.IsAgent { + homePage = "/agent" + } readyf := h.testReady