Skip to content

Commit

Permalink
Use RobotFlotillaStatus in the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Jul 25, 2024
1 parent 4a6576c commit 652c2f0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Icon, Typography } from '@equinor/eds-core-react'
import { RobotStatus } from 'models/Robot'
import { RobotFlotillaStatus, RobotStatus } from 'models/Robot'
import { tokens } from '@equinor/eds-tokens'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { useSafeZoneContext } from 'components/Contexts/SafeZoneContext'
import { Icons } from 'utils/icons'
import { styled } from 'styled-components'

interface StatusProps {
status?: RobotStatus
isarConnected: boolean
flotillaStatus?: RobotFlotillaStatus
}

const StyledStatus = styled.div`
Expand All @@ -23,9 +23,8 @@ const StyledIcon = styled(Icon)`
height: 24px;
`

export const RobotStatusChip = ({ status, isarConnected }: StatusProps) => {
export const RobotStatusChip = ({ status, flotillaStatus, isarConnected }: StatusProps) => {
const { TranslateText } = useLanguageContext()
const { safeZoneStatus } = useSafeZoneContext()

var iconColor = tokens.colors.text.static_icons__default.hex
var statusIcon = Icons.CloudOff
Expand Down Expand Up @@ -57,10 +56,14 @@ export const RobotStatusChip = ({ status, isarConnected }: StatusProps) => {
iconColor = tokens.colors.interactive.disabled__text.hex
statusIcon = Icons.Info
status = RobotStatus.ConnectionIssues
} else if (safeZoneStatus) {
} else if (flotillaStatus && flotillaStatus === RobotFlotillaStatus.SafeZone) {
iconColor = tokens.colors.interactive.danger__resting.hex
statusIcon = Icons.Warning
status = RobotStatus.SafeZone
} else if (flotillaStatus && flotillaStatus === RobotFlotillaStatus.Recharging) {
iconColor = '#FFC300'
statusIcon = Icons.BatteryCharging
status = RobotStatus.Recharging
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { tokens } from '@equinor/eds-tokens'
import { useMissionControlContext } from 'components/Contexts/MissionControlContext'
import { BackendAPICaller } from 'api/ApiCaller'
import { useInstallationContext } from 'components/Contexts/InstallationContext'
import { useSafeZoneContext } from 'components/Contexts/SafeZoneContext'
import { TaskType } from 'models/Task'
import { AlertType, useAlertContext } from 'components/Contexts/AlertContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
import { AlertCategory } from 'components/Alerts/AlertsBanner'
import { useRobotContext } from 'components/Contexts/RobotContext'
import { RobotFlotillaStatus } from 'models/Robot'

const StyledDisplayButtons = styled.div`
display: flex;
Expand Down Expand Up @@ -135,11 +136,18 @@ export const StopMissionDialog = ({ missionName, robotId, missionTaskType }: Mis

export const StopRobotDialog = (): JSX.Element => {
const [isStopRobotDialogOpen, setIsStopRobotDialogOpen] = useState<boolean>(false)
const { safeZoneStatus } = useSafeZoneContext()
const { enabledRobots } = useRobotContext()
const { TranslateText } = useLanguageContext()
const { installationCode } = useInstallationContext()
const { setAlert } = useAlertContext()

const safeZoneActivated =
enabledRobots.find(
(r) =>
r.currentInstallation.installationCode === installationCode &&
r.flotillaStatus === RobotFlotillaStatus.SafeZone
) !== undefined

const openDialog = async () => {
setIsStopRobotDialogOpen(true)
}
Expand Down Expand Up @@ -176,7 +184,7 @@ export const StopRobotDialog = (): JSX.Element => {
return (
<>
<StyledButton color="danger" variant="outlined" onClick={openDialog}>
{!safeZoneStatus ? (
{!safeZoneActivated ? (
<>{TranslateText('Send robots to safe zone')}</>
) : (
<>{TranslateText('Dismiss robots from safe zone')}</>
Expand All @@ -186,7 +194,7 @@ export const StopRobotDialog = (): JSX.Element => {
<Dialog.Header>
<Dialog.Title>
<Typography variant="h5">
{!safeZoneStatus
{!safeZoneActivated
? TranslateText('Send robots to safe zone') + '?'
: TranslateText('Dismiss robots from safe zone') + '?'}
</Typography>
Expand All @@ -195,12 +203,12 @@ export const StopRobotDialog = (): JSX.Element => {
<Dialog.CustomContent>
<StyledText>
<Typography variant="body_long">
{!safeZoneStatus
{!safeZoneActivated
? TranslateText('Send robots to safe zone long text')
: TranslateText('Dismiss robots from safe zone long text')}
</Typography>
<Typography variant="body_long">
{!safeZoneStatus
{!safeZoneActivated
? TranslateText('Send robots to safe confirmation text')
: TranslateText('Dismiss robots from safe confirmation text')}
</Typography>
Expand All @@ -217,7 +225,7 @@ export const StopRobotDialog = (): JSX.Element => {
>
{TranslateText('Cancel')}
</Button>
{!safeZoneStatus ? (
{!safeZoneActivated ? (
<Button variant="contained" color="danger" onClick={stopAll}>
{TranslateText('Send robots to safe zone')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ export const RobotStatusCard = ({ robot }: RobotProps) => {
<HorizontalContent>
<VerticalContent>
<Typography variant="meta">{TranslateText('Status')}</Typography>
<RobotStatusChip status={robot.status} isarConnected={robot.isarConnected} />
<RobotStatusChip
status={robot.status}
flotillaStatus={robot.flotillaStatus}
isarConnected={robot.isarConnected}
/>
</VerticalContent>

{robot.status !== RobotStatus.Offline ? (
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Pages/RobotPage/RobotPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const RobotPage = () => {
<StatusContent $alignItems="start">
<RobotStatusChip
status={selectedRobot.status}
flotillaStatus={selectedRobot.flotillaStatus}
isarConnected={selectedRobot.isarConnected}
/>

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,6 @@
"Failed to release robots from safe zone": "Failed to release robots from safe zone",
"Failed to send robot {0} home": "Failed to send robot {0} to starting position",
"Failed to update inspection": "Failed to update inspection",
"Battery": "Battery"
"Battery": "Battery",
"Recharging": "Recharging"
}
3 changes: 2 additions & 1 deletion frontend/src/language/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,6 @@
"Failed to release robots from safe zone": "Kunne ikke slippe roboter ut av trygg sone",
"Failed to send robot {0} home": "Kunne ikke sende robot {0} til startposisjon",
"Failed to update inspection": "Kunne ikke oppdatere inspeksjon",
"Battery": "Batteri"
"Battery": "Batteri",
"Recharging": "Lader"
}
1 change: 1 addition & 0 deletions frontend/src/models/Robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum RobotStatus {
Offline = 'Offline',
Blocked = 'Blocked',
SafeZone = 'Safe Zone',
Recharging = 'Recharging',
ConnectionIssues = 'Connection Issues',
}

Expand Down

0 comments on commit 652c2f0

Please sign in to comment.