forked from equinor/flotilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix confirm pressure/battery dialogs
- Loading branch information
Showing
12 changed files
with
267 additions
and
308 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
frontend/src/components/Displays/ConfirmScheduleDialogs/ConfirmScheduleDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Robot } from 'models/Robot' | ||
import { useEffect, useState } from 'react' | ||
import { ScheduleMissionWithLocalizationVerificationDialog } from 'components/Displays/ConfirmScheduleDialogs/LocalizationVerification/ScheduleMissionWithLocalizationVerification' | ||
import { useRobotContext } from 'components/Contexts/RobotContext' | ||
import { | ||
InsufficientBatteryDialog, | ||
InsufficientPressureDialog, | ||
} from 'components/Displays/ConfirmScheduleDialogs/InsufficientValueDialogs' | ||
|
||
interface ConfirmScheduleDialogProps { | ||
scheduleMissions: () => void | ||
closeDialog: () => void | ||
robotId: string | ||
missionDeckNames: string[] | ||
} | ||
|
||
export const ScheduleMissionWithConfirmDialogs = ({ | ||
robotId, | ||
missionDeckNames, | ||
scheduleMissions, | ||
closeDialog, | ||
}: ConfirmScheduleDialogProps) => { | ||
const { enabledRobots } = useRobotContext() | ||
const [robot, setRobot] = useState<Robot>() | ||
|
||
const isBatteryInsufficient = (currentRobot: Robot) => | ||
currentRobot.batteryLevel && | ||
currentRobot.model.batteryWarningThreshold && | ||
currentRobot.batteryLevel < currentRobot.model.batteryWarningThreshold | ||
|
||
const isPressureInsufficient = (currentRobot: Robot) => | ||
currentRobot.pressureLevel && | ||
((currentRobot.model.lowerPressureWarningThreshold && | ||
currentRobot.pressureLevel < currentRobot.model.lowerPressureWarningThreshold) || | ||
(currentRobot.model.upperPressureWarningThreshold && | ||
currentRobot.pressureLevel > currentRobot.model.upperPressureWarningThreshold)) | ||
|
||
useEffect(() => { | ||
setRobot(enabledRobots.find((robot) => robot.id === robotId)) | ||
}, [robotId, enabledRobots]) | ||
|
||
if (!robot) { | ||
return <></> | ||
} else if (isBatteryInsufficient(robot)) { | ||
return <InsufficientBatteryDialog robot={robot} cancel={closeDialog} /> | ||
} else if (isPressureInsufficient(robot)) { | ||
return <InsufficientPressureDialog robot={robot} cancel={closeDialog} /> | ||
} else { | ||
return ( | ||
<ScheduleMissionWithLocalizationVerificationDialog | ||
scheduleMissions={scheduleMissions} | ||
closeDialog={closeDialog} | ||
robotId={robot!.id} | ||
missionDeckNames={missionDeckNames} | ||
/> | ||
) | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
frontend/src/components/Displays/ConfirmScheduleDialogs/InsufficientValueDialogs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { Button, Dialog, Typography } from '@equinor/eds-core-react' | ||
import { useLanguageContext } from 'components/Contexts/LanguageContext' | ||
import { Robot } from 'models/Robot' | ||
import { | ||
StyledDialog, | ||
VerticalContent, | ||
} from 'components/Displays/ConfirmScheduleDialogs/LocalizationVerification/ScheduleMissionStyles' | ||
|
||
enum InsufficientDialogTypes { | ||
battery = 'battery', | ||
pressure = 'pressure', | ||
} | ||
|
||
interface SpecificInsufficientDialogProps { | ||
robot: Robot | ||
cancel: () => void | ||
} | ||
|
||
interface GenericInsufficientDialogProps { | ||
robot: Robot | ||
dialogType: InsufficientDialogTypes | ||
value: number | ||
lowerLimit?: number | ||
upperLimit?: number | ||
cancel: () => void | ||
} | ||
|
||
export const InsufficientBatteryDialog = ({ robot, cancel }: SpecificInsufficientDialogProps) => { | ||
return ( | ||
<InsufficientDialog | ||
robot={robot} | ||
dialogType={InsufficientDialogTypes.battery} | ||
value={robot.batteryLevel!} | ||
lowerLimit={robot.model.batteryWarningThreshold} | ||
cancel={cancel} | ||
/> | ||
) | ||
} | ||
|
||
export const InsufficientPressureDialog = ({ robot, cancel }: SpecificInsufficientDialogProps) => { | ||
return ( | ||
<InsufficientDialog | ||
robot={robot} | ||
dialogType={InsufficientDialogTypes.pressure} | ||
value={robot.pressureLevel!} | ||
lowerLimit={robot.model.lowerPressureWarningThreshold} | ||
upperLimit={robot.model.upperPressureWarningThreshold} | ||
cancel={cancel} | ||
/> | ||
) | ||
} | ||
|
||
const InsufficientDialog = ({ | ||
robot, | ||
dialogType, | ||
value, | ||
lowerLimit, | ||
upperLimit, | ||
cancel, | ||
}: GenericInsufficientDialogProps) => { | ||
const { TranslateText } = useLanguageContext() | ||
|
||
const getValueWithUnit = (value: number): string => { | ||
if (dialogType === InsufficientDialogTypes.battery) { | ||
return `${Math.round(value)}%` | ||
} else if (dialogType === InsufficientDialogTypes.pressure) { | ||
const barToMillibar = 1000 | ||
return `${Math.round(value * barToMillibar)}mBar` | ||
} else return value.toString() | ||
} | ||
|
||
const getAction = (): string => { | ||
if (dialogType === InsufficientDialogTypes.battery) return 'charge' | ||
else if (dialogType === InsufficientDialogTypes.pressure) | ||
return lowerLimit && value < lowerLimit ? 'pressurize' : 'de-pressurize' | ||
else return '' | ||
} | ||
|
||
let warningText = `${TranslateText(`Current ${dialogType} value for`)} ${robot.name} (${ | ||
robot.model.type | ||
}) ${TranslateText(`is`)} ${getValueWithUnit(value)}. ` | ||
|
||
if (lowerLimit && value < lowerLimit) { | ||
warningText += `${TranslateText('This is below recommended lower limit of')} ${getValueWithUnit(lowerLimit)}.` | ||
} else if (upperLimit && value > upperLimit) { | ||
warningText += `${TranslateText('This is above recommended upper limit of')} ${getValueWithUnit(upperLimit)}.` | ||
} | ||
|
||
const actionText = `${TranslateText(`Please ${getAction()} the robot`)}.` | ||
|
||
return ( | ||
<StyledDialog open={true} onClose={cancel}> | ||
<Dialog.Header> | ||
<Typography variant="h5">{TranslateText(`${dialogType} warning`)}</Typography> | ||
</Dialog.Header> | ||
<Dialog.Content> | ||
<VerticalContent> | ||
<Typography>{warningText}</Typography> | ||
<Typography>{actionText}</Typography> | ||
<Dialog.Actions> | ||
<Button variant="outlined" onClick={cancel}> | ||
{TranslateText('Close')} | ||
</Button> | ||
</Dialog.Actions> | ||
</VerticalContent> | ||
</Dialog.Content> | ||
</StyledDialog> | ||
) | ||
} |
71 changes: 71 additions & 0 deletions
71
...ts/Displays/ConfirmScheduleDialogs/LocalizationVerification/ConfirmLocalizationDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Button, Checkbox, Dialog, Typography } from '@equinor/eds-core-react' | ||
import { DeckMapView } from 'utils/DeckMapView' | ||
import { HorizontalContent, StyledDialog, VerticalContent } from './ScheduleMissionStyles' | ||
import { useLanguageContext } from 'components/Contexts/LanguageContext' | ||
import { Robot } from 'models/Robot' | ||
import { ChangeEvent, useState } from 'react' | ||
import { useInstallationContext } from 'components/Contexts/InstallationContext' | ||
|
||
interface ConfirmLocalizationDialogProps { | ||
closeDialog: () => void | ||
scheduleMissions: () => void | ||
robot: Robot | ||
newDeckName: string | ||
} | ||
|
||
export const ConfirmLocalizationDialog = ({ | ||
closeDialog, | ||
scheduleMissions, | ||
robot, | ||
newDeckName, | ||
}: ConfirmLocalizationDialogProps) => { | ||
const { TranslateText } = useLanguageContext() | ||
const { installationDecks } = useInstallationContext() | ||
const [isCheckboxClicked, setIsCheckboxClicked] = useState<boolean>(false) | ||
|
||
const newDeck = installationDecks.find((deck) => deck.deckName === newDeckName) | ||
|
||
return ( | ||
<StyledDialog open={true} onClose={closeDialog}> | ||
<Dialog.Header> | ||
<Typography variant="h5">{TranslateText('Confirm placement of robot')}</Typography> | ||
</Dialog.Header> | ||
<Dialog.Content> | ||
<VerticalContent> | ||
<Typography> | ||
{`${robot.name} (${robot.model.type}) ${TranslateText( | ||
'needs to be placed on marked position on' | ||
)} ${newDeckName} `} | ||
<b>{TranslateText('before')}</b> | ||
{` ${TranslateText('clicking confirm')}.`} | ||
</Typography> | ||
{newDeck && newDeck.defaultLocalizationPose && ( | ||
<DeckMapView deck={newDeck} markedRobotPosition={newDeck.defaultLocalizationPose}></DeckMapView> | ||
)} | ||
<HorizontalContent> | ||
<Checkbox | ||
crossOrigin={undefined} | ||
onChange={(e: ChangeEvent<HTMLInputElement>) => setIsCheckboxClicked(e.target.checked)} | ||
/> | ||
<Typography> | ||
{`${TranslateText('I confirm that')} ${robot.name} (${robot.model.type}) ${TranslateText( | ||
'has been placed on marked position on' | ||
)} `} | ||
<b>{newDeckName}</b> | ||
</Typography> | ||
</HorizontalContent> | ||
</VerticalContent> | ||
</Dialog.Content> | ||
<Dialog.Actions> | ||
<HorizontalContent> | ||
<Button variant="outlined" onClick={closeDialog}> | ||
{TranslateText('Cancel')} | ||
</Button> | ||
<Button onClick={scheduleMissions} disabled={!isCheckboxClicked}> | ||
{TranslateText('Confirm')} | ||
</Button> | ||
</HorizontalContent> | ||
</Dialog.Actions> | ||
</StyledDialog> | ||
) | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.