Skip to content

Commit 0c6a95d

Browse files
committed
Fix order of hooks error
1 parent 8c24d5d commit 0c6a95d

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

frontend/src/components/Pages/FrontPage/MissionOverview/MissionControlSection.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { MissionHistoryButton } from './MissionHistoryButton'
1010
import { Robot } from 'models/Robot'
1111
import { RobotMissionQueueView } from './MissionQueueView'
1212
import { FrontPageSectionId } from 'models/FrontPageSectionId'
13-
import { getNoMissionReason } from 'utils/IsRobotReadyToRunMissions'
1413

1514
const MissionControlStyle = styled.div`
1615
display: flex;
@@ -93,7 +92,7 @@ const MissionControlCard = ({ robot }: { robot: Robot }) => {
9392
{ongoingMission ? (
9493
<OngoingMissionCard mission={ongoingMission} />
9594
) : (
96-
<OngoingMissionPlaceholderCard noMissionReason={getNoMissionReason(robot)} />
95+
<OngoingMissionPlaceholderCard robot={robot} />
9796
)}
9897
</OngoingMissionControlCardStyle>
9998
<RobotMissionQueueView robot={robot} />

frontend/src/components/Pages/FrontPage/MissionOverview/OngoingMissionCard.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { TaskType } from 'models/Task'
1111
import { StyledButton } from 'components/Styles/StyledComponents'
1212
import { useLanguageContext } from 'components/Contexts/LanguageContext'
1313
import { Icons } from 'utils/icons'
14+
import { Robot } from 'models/Robot'
15+
import { NoMissionReason } from 'utils/IsRobotReadyToRunMissions'
1416

1517
interface MissionProps {
1618
mission: Mission
@@ -140,7 +142,7 @@ export const OngoingMissionCard = ({ mission }: MissionProps): JSX.Element => {
140142
)
141143
}
142144

143-
export const OngoingMissionPlaceholderCard = ({ noMissionReason }: { noMissionReason?: string }): JSX.Element => {
145+
export const OngoingMissionPlaceholderCard = ({ robot }: { robot?: Robot }): JSX.Element => {
144146
const { TranslateText } = useLanguageContext()
145147

146148
return (
@@ -149,11 +151,11 @@ export const OngoingMissionPlaceholderCard = ({ noMissionReason }: { noMissionRe
149151
style={{ backgroundColor: tokens.colors.ui.background__light.hex, gap: '8px' }}
150152
>
151153
<Typography variant="h5">{TranslateText('No ongoing missions')}</Typography>
152-
{noMissionReason && <Typography variant="body_short">{noMissionReason}</Typography>}
154+
{robot && <NoMissionReason robot={robot} />}
153155
</StyledSmallScreenMissionCard>
154156
<StyledLargeScreenMissionCard style={{ backgroundColor: tokens.colors.ui.background__light.hex }}>
155157
<Typography variant="h5">{TranslateText('No ongoing missions')}</Typography>
156-
{noMissionReason && <Typography variant="body_short">{noMissionReason}</Typography>}
158+
{robot && <NoMissionReason robot={robot} />}
157159
</StyledLargeScreenMissionCard>
158160
</>
159161
)

frontend/src/utils/IsRobotReadyToRunMissions.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Typography } from '@equinor/eds-core-react'
12
import { useLanguageContext } from 'components/Contexts/LanguageContext'
23
import { Robot, RobotFlotillaStatus } from 'models/Robot'
34

@@ -30,30 +31,33 @@ export const isRobotPressureTooLow = (robot: Robot): boolean => {
3031
return false
3132
}
3233

33-
export const getNoMissionReason = (robot: Robot): string | undefined => {
34+
export const NoMissionReason = ({ robot }: { robot: Robot }): JSX.Element => {
3435
const { TranslateText } = useLanguageContext()
35-
36+
let message = undefined
3637
if (isBatteryTooLow(robot)) {
37-
return robot.model.batteryMissionStartThreshold
38+
message = robot.model.batteryMissionStartThreshold
3839
? TranslateText(
3940
'Battery is too low to start a mission. Queued missions will start when the battery is over {0}%.',
4041
[robot.model.batteryMissionStartThreshold.toString()]
4142
)
4243
: TranslateText('Battery is too low to start a mission.')
4344
} else if (isRobotPressureTooHigh(robot)) {
44-
return robot.model.upperPressureWarningThreshold
45+
message = robot.model.upperPressureWarningThreshold
4546
? TranslateText(
4647
'Pressure is too high to start a mission. Queued missions will start when the pressure is under {0}mBar.',
4748
[(robot.model.upperPressureWarningThreshold * 1000).toString()]
4849
)
4950
: TranslateText('Pressure is too high to start a mission.')
5051
} else if (isRobotPressureTooLow(robot)) {
51-
return robot.model.lowerPressureWarningThreshold
52+
message = robot.model.lowerPressureWarningThreshold
5253
? TranslateText(
5354
'Pressure is too low to start a mission. Queued missions will start when the pressure is over {0}mBar.',
5455
[(robot.model.lowerPressureWarningThreshold * 1000).toString()]
5556
)
5657
: TranslateText('Pressure is too low to start a mission.')
5758
}
58-
return undefined
59+
if (!message) {
60+
return <></>
61+
}
62+
return <Typography variant="body_short">{message}</Typography>
5963
}

0 commit comments

Comments
 (0)