Skip to content

Commit

Permalink
Fix pressure display
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Jan 15, 2024
1 parent a9946b7 commit 1bc3601
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const StyledTypography = styled(Typography)<{ $fontSize?: 24 | 16 | 18 | 32 | 40
font-size: ${(props) => props.$fontSize};
`
interface PressureStatusDisplayProps {
pressureInBar?: number
pressureInMilliBar?: number
pressureInBar: number
itemSize?: 24 | 16 | 18 | 32 | 40 | 48 | undefined
upperPressureWarningThreshold?: number
lowerPressureWarningThreshold?: number
Expand All @@ -28,27 +27,19 @@ export const PressureStatusDisplay = ({
lowerPressureWarningThreshold,
}: PressureStatusDisplayProps): JSX.Element => {
const barToMillibar = 1000
const pressureInMilliBar = `${Math.round(pressureInBar * barToMillibar)}mBar`
let icon_color: string = tokens.colors.interactive.primary__resting.hex
let pressureStatus: PressureStatus
let pressureInMilliBar: string = ''

if (!pressureInBar) {
pressureInMilliBar = ''
pressureStatus = PressureStatus.Default
return <></>
} else if (!upperPressureWarningThreshold || !lowerPressureWarningThreshold) {
if (!upperPressureWarningThreshold || !lowerPressureWarningThreshold) {
pressureStatus = PressureStatus.Normal
} else if (
pressureInBar * barToMillibar > upperPressureWarningThreshold ||
pressureInBar * barToMillibar < lowerPressureWarningThreshold
) {
pressureStatus = PressureStatus.Critical
} else {
if (
pressureInBar * barToMillibar > upperPressureWarningThreshold ||
pressureInBar * barToMillibar < lowerPressureWarningThreshold
) {
pressureStatus = PressureStatus.Critical
pressureInMilliBar = `${Math.round(pressureInBar * barToMillibar)}mBar`
} else {
pressureStatus = PressureStatus.Normal
pressureInMilliBar = `${Math.round(pressureInBar * barToMillibar)}mBar`
}
pressureStatus = PressureStatus.Normal
}

switch (pressureStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ export const RobotStatusCard = ({ robot }: RobotProps) => {
<VerticalContent $alignItems="end">
{robot.status !== RobotStatus.Offline ? (
<>
<PressureStatusDisplay
pressureInBar={robot.pressureLevel}
upperPressureWarningThreshold={robot.model.upperPressureWarningThreshold}
lowerPressureWarningThreshold={robot.model.lowerPressureWarningThreshold}
/>
{robot.pressureLevel && (
<PressureStatusDisplay
pressureInBar={robot.pressureLevel}
upperPressureWarningThreshold={robot.model.upperPressureWarningThreshold}
lowerPressureWarningThreshold={robot.model.lowerPressureWarningThreshold}
/>
)}
<BatteryStatusDisplay batteryLevel={robot.batteryLevel} />
</>
) : (
Expand Down
22 changes: 12 additions & 10 deletions frontend/src/components/Pages/RobotPage/RobotPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ export const RobotPage = () => {
{selectedRobot.status !== RobotStatus.Offline && (
<>
<BatteryStatusDisplay itemSize={48} batteryLevel={selectedRobot.batteryLevel} />
<PressureStatusDisplay
itemSize={48}
pressureInBar={selectedRobot.pressureLevel}
upperPressureWarningThreshold={
selectedRobot.model.upperPressureWarningThreshold
}
lowerPressureWarningThreshold={
selectedRobot.model.lowerPressureWarningThreshold
}
/>
{selectedRobot.pressureLevel && (
<PressureStatusDisplay
itemSize={48}
pressureInBar={selectedRobot.pressureLevel}
upperPressureWarningThreshold={
selectedRobot.model.upperPressureWarningThreshold
}
lowerPressureWarningThreshold={
selectedRobot.model.lowerPressureWarningThreshold
}
/>
)}
</>
)}
<RobotStatusChip status={selectedRobot.status} />
Expand Down

0 comments on commit 1bc3601

Please sign in to comment.