From 225d546b00cf544c871ebb1451e9fbc2e4ea2065 Mon Sep 17 00:00:00 2001 From: mrica-equinor Date: Wed, 26 Feb 2025 09:35:21 +0100 Subject: [PATCH] Redirect to asset page if no instalation selected --- frontend/src/components/Header/Header.tsx | 5 ++++- frontend/src/components/Pages/FrontPage/FrontPage.tsx | 3 +++ .../Pages/MissionHistoryPage/MissionHistoryPage.tsx | 3 +++ frontend/src/utils/RedirectIfNoInstallationSelected.tsx | 9 +++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 frontend/src/utils/RedirectIfNoInstallationSelected.tsx diff --git a/frontend/src/components/Header/Header.tsx b/frontend/src/components/Header/Header.tsx index 32e6c8fdc..f7fc9826d 100644 --- a/frontend/src/components/Header/Header.tsx +++ b/frontend/src/components/Header/Header.tsx @@ -68,6 +68,7 @@ const Circle = styled.div` height: 9px; border-radius: 50%; ` + export const Header = ({ page }: { page: string }) => { const { alerts, listAlerts } = useAlertContext() const { installationName } = useInstallationContext() @@ -90,7 +91,9 @@ export const Header = ({ page }: { page: string }) => { { - window.location.href = `${config.FRONTEND_BASE_ROUTE}/FrontPage` + window.location.href = installationName + ? `${config.FRONTEND_BASE_ROUTE}/FrontPage` + : `${config.FRONTEND_BASE_ROUTE}/` }} > diff --git a/frontend/src/components/Pages/FrontPage/FrontPage.tsx b/frontend/src/components/Pages/FrontPage/FrontPage.tsx index 1fba7bb79..3c5d2fc93 100644 --- a/frontend/src/components/Pages/FrontPage/FrontPage.tsx +++ b/frontend/src/components/Pages/FrontPage/FrontPage.tsx @@ -4,6 +4,7 @@ import { InspectionOverviewSection } from 'components/Pages/InspectionPage/Inspe import { StopRobotDialog } from './MissionOverview/StopDialogs' import { tokens } from '@equinor/eds-tokens' import { MissionControlSection } from './MissionOverview/MissionControlSection' +import { redirectIfNoInstallationSelected } from 'utils/RedirectIfNoInstallationSelected' const StyledFrontPage = styled.div` display: flex; @@ -15,6 +16,8 @@ const StyledFrontPage = styled.div` ` export const FrontPage = () => { + redirectIfNoInstallationSelected() + return ( <>
diff --git a/frontend/src/components/Pages/MissionHistoryPage/MissionHistoryPage.tsx b/frontend/src/components/Pages/MissionHistoryPage/MissionHistoryPage.tsx index d3a6b8540..25b0a663e 100644 --- a/frontend/src/components/Pages/MissionHistoryPage/MissionHistoryPage.tsx +++ b/frontend/src/components/Pages/MissionHistoryPage/MissionHistoryPage.tsx @@ -4,6 +4,7 @@ import { Header } from 'components/Header/Header' import { StyledPage } from 'components/Styles/StyledComponents' import { styled } from 'styled-components' import { tokens } from '@equinor/eds-tokens' +import { redirectIfNoInstallationSelected } from 'utils/RedirectIfNoInstallationSelected' export type RefreshProps = { refreshInterval: number @@ -15,6 +16,8 @@ const StyledMissionHistoryPage = styled(StyledPage)` export const MissionHistoryPage = () => { const refreshInterval = 1000 + redirectIfNoInstallationSelected() + return ( <>
diff --git a/frontend/src/utils/RedirectIfNoInstallationSelected.tsx b/frontend/src/utils/RedirectIfNoInstallationSelected.tsx new file mode 100644 index 000000000..2b1c9e279 --- /dev/null +++ b/frontend/src/utils/RedirectIfNoInstallationSelected.tsx @@ -0,0 +1,9 @@ +import { useInstallationContext } from 'components/Contexts/InstallationContext' +import { config } from 'config' + +export function redirectIfNoInstallationSelected() { + const { installationCode, installationName } = useInstallationContext() + if (installationCode === '' && installationName === '') { + window.location.href = `${config.FRONTEND_BASE_ROUTE}/` + } +}