From 195a07e00b7e7dbe08e0312ba714fe9eebdfa63b Mon Sep 17 00:00:00 2001 From: DingDongSoLong4 <99329275+DingDongSoLong4@users.noreply.github.com> Date: Mon, 8 Jan 2024 03:08:09 +0200 Subject: [PATCH] Fix settings tab links (#4430) --- ui/v2.5/src/components/Settings/Settings.tsx | 145 +++++++++++++------ 1 file changed, 98 insertions(+), 47 deletions(-) diff --git a/ui/v2.5/src/components/Settings/Settings.tsx b/ui/v2.5/src/components/Settings/Settings.tsx index fb1b95d2a17..324f8afd5e3 100644 --- a/ui/v2.5/src/components/Settings/Settings.tsx +++ b/ui/v2.5/src/components/Settings/Settings.tsx @@ -1,6 +1,7 @@ import React from "react"; import { Tab, Nav, Row, Col } from "react-bootstrap"; -import { useHistory, useLocation } from "react-router-dom"; +import { Redirect, RouteComponentProps } from "react-router-dom"; +import { LinkContainer } from "react-router-bootstrap"; import { FormattedMessage } from "react-intl"; import { Helmet } from "react-helmet"; import { useTitleProps } from "src/hooks/title"; @@ -18,83 +19,133 @@ import { SettingsLibraryPanel } from "./SettingsLibraryPanel"; import { SettingsSecurityPanel } from "./SettingsSecurityPanel"; import Changelog from "../Changelog/Changelog"; -export const Settings: React.FC = () => { - const location = useLocation(); - const history = useHistory(); - const defaultTab = new URLSearchParams(location.search).get("tab") ?? "tasks"; +const validTabs = [ + "tasks", + "library", + "interface", + "security", + "metadata-providers", + "services", + "system", + "plugins", + "logs", + "tools", + "changelog", + "about", +] as const; +type TabKey = (typeof validTabs)[number]; - const onSelect = (val: string) => history.push(`?tab=${val}`); +const defaultTab: TabKey = "tasks"; + +function isTabKey(tab: string | null): tab is TabKey { + return validTabs.includes(tab as TabKey); +} + +const Settings: React.FC = ({ location }) => { + const tab = new URLSearchParams(location.search).get("tab"); const titleProps = useTitleProps({ id: "settings" }); + + if (!isTabKey(tab)) { + return ( + + ); + } + return ( - tab && onSelect(tab)} - > +