Skip to content

Commit

Permalink
Add banner for blocked robot
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadUsama-afk-equinor authored and UsamaEquinorAFK committed Jan 2, 2024
1 parent b922d48 commit 2478001
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/Contexts/AlertContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum AlertType {
MissionFail,
RequestFail,
SafeZoneFail,
BlockedRobot,
}

const alertTypeEnumMap: { [key: string]: AlertType } = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Typography } from '@equinor/eds-core-react'
import { Robot } from 'models/Robot'
import { useEffect } from 'react'
import styled from 'styled-components'
import { BlockedRobotAlertContent } from 'components/Alerts/BlockedRobotAlert'
import { RobotStatusCard, RobotStatusCardPlaceholder } from './RobotStatusCard'
import { AlertType, useAlertContext } from 'components/Contexts/AlertContext'
import { useInstallationContext } from 'components/Contexts/InstallationContext'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { useSafeZoneContext } from 'components/Contexts/SafeZoneContext'
Expand All @@ -18,13 +20,16 @@ const RobotView = styled.div`
grid-column: 1/ -1;
gap: 1rem;
`
const isRobotBlocked = (robot: Robot): boolean => {
return robot.status === 'Blocked'
}

export const RobotStatusSection = () => {
const { TranslateText } = useLanguageContext()
const { installationCode } = useInstallationContext()
const { enabledRobots } = useRobotContext()
const { switchSafeZoneStatus } = useSafeZoneContext()

const { setAlert } = useAlertContext()
const relevantRobots = enabledRobots
.filter(
(robot) =>
Expand All @@ -35,7 +40,11 @@ export const RobotStatusSection = () => {
useEffect(() => {
const missionQueueFozenStatus = relevantRobots.some((robot: Robot) => robot.missionQueueFrozen)
switchSafeZoneStatus(missionQueueFozenStatus)
}, [enabledRobots, installationCode, switchSafeZoneStatus, relevantRobots])
const blockedRobots = relevantRobots.filter(isRobotBlocked)
if (blockedRobots.length > 0) {
setAlert(AlertType.BlockedRobot, <BlockedRobotAlertContent robot={blockedRobots[0]} />)
}
}, [enabledRobots, installationCode, switchSafeZoneStatus, relevantRobots, setAlert])

const robotDisplay = relevantRobots.map((robot) => <RobotStatusCard key={robot.id} robot={robot} />)

Expand Down

0 comments on commit 2478001

Please sign in to comment.