Skip to content

Commit

Permalink
Redirect to asset page if no instalation selected
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Feb 27, 2025
1 parent 8aab890 commit 225d546
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion frontend/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -90,7 +91,9 @@ export const Header = ({ page }: { page: string }) => {
<StyledWrapper>
<TopBar.Header
onClick={() => {
window.location.href = `${config.FRONTEND_BASE_ROUTE}/FrontPage`
window.location.href = installationName
? `${config.FRONTEND_BASE_ROUTE}/FrontPage`
: `${config.FRONTEND_BASE_ROUTE}/`
}}
>
<StyledTopBarHeader>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/Pages/FrontPage/FrontPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,8 @@ const StyledFrontPage = styled.div`
`

export const FrontPage = () => {
redirectIfNoInstallationSelected()

return (
<>
<Header page={'frontPage'} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +16,8 @@ const StyledMissionHistoryPage = styled(StyledPage)`
export const MissionHistoryPage = () => {
const refreshInterval = 1000

redirectIfNoInstallationSelected()

return (
<>
<Header page={'history'} />
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/utils/RedirectIfNoInstallationSelected.tsx
Original file line number Diff line number Diff line change
@@ -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}/`
}
}

0 comments on commit 225d546

Please sign in to comment.