Skip to content

Commit

Permalink
Change safe zone banner when robot is in safe zone
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Mar 26, 2024
1 parent 02e5453 commit 0caeae6
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 29 deletions.
5 changes: 5 additions & 0 deletions backend/api.test/Mocks/SignalRServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ public void ReportScheduleFailureToSignalR(Robot robot, string message)
{
return;
}

public void ReportSafeZoneSuccessToSignalR(Robot robot, string message)
{
return;
}
}
}
10 changes: 10 additions & 0 deletions backend/api/EventHandlers/MissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ private async void OnMissionCompleted(object? sender, MissionCompletedEventArgs
return;
}

var lastMissionRun = await MissionService.ReadLastExecutedMissionRunByRobotWithoutTracking(robot.Id);
if (lastMissionRun != null)
{
if (lastMissionRun.MissionRunPriority == MissionRunPriority.Emergency & lastMissionRun.Status == MissionStatus.Successful)
{
_logger.LogInformation("Return to safe zone mission on robot {RobotName} was successful.", robot.Name);
SignalRService.ReportSafeZoneSuccessToSignalR(robot, $"Robot {robot.Name} is in the safe zone");
}
}

_startMissionSemaphore.WaitOne();
try { await MissionScheduling.StartNextMissionRunIfSystemIsAvailable(robot.Id); }
catch (MissionRunNotFoundException) { return; }
Expand Down
9 changes: 9 additions & 0 deletions backend/api/Services/SignalRService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface ISignalRService
public Task SendMessageAsync(string label, Installation? installation, string message);
public void ReportSafeZoneFailureToSignalR(Robot robot, string message);
public void ReportScheduleFailureToSignalR(Robot robot, string message);
public void ReportSafeZoneSuccessToSignalR(Robot robot, string message);
}

public class SignalRService(IHubContext<SignalRHub> signalRHub) : ISignalRService
Expand Down Expand Up @@ -64,5 +65,13 @@ public void ReportScheduleFailureToSignalR(Robot robot, string message)
new AlertResponse("scheduleFailure", "Failure to schedule", message, robot.CurrentInstallation.InstallationCode, robot.Id));
}

public void ReportSafeZoneSuccessToSignalR(Robot robot, string message)
{
_ = SendMessageAsync(
"Alert",
robot.CurrentInstallation,
new AlertResponse("safeZoneSuccess", "Successful drive to safe zone", message, robot.CurrentInstallation.InstallationCode, robot.Id));
}

}
}
20 changes: 13 additions & 7 deletions frontend/src/components/Alerts/AlertsBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const StyledCard = styled.div`
justify-content: space-between;
align-items: center;
@media(max-width:600px) {
@media (max-width: 600px) {
padding: 6px 8px 2px 10px;
}
}
`

const Horizontal = styled.div`
Expand All @@ -32,7 +32,7 @@ const Center = styled.div`
export enum AlertCategory {
ERROR,
WARNING,
SUCCESS,
INFO,
}

interface AlertProps {
Expand All @@ -46,18 +46,24 @@ export const AlertBanner = ({ children, dismissAlert, alertCategory }: AlertProp
let hoverColor = tokens.colors.ui.background__light.hex

if (alertCategory === AlertCategory.WARNING) bannerColor = tokens.colors.interactive.warning__highlight.hex
if (alertCategory === AlertCategory.SUCCESS) bannerColor = tokens.colors.infographic.primary__mist_blue.hex
if (alertCategory === AlertCategory.INFO) bannerColor = tokens.colors.infographic.primary__mist_blue.hex

const [buttonBackgroundColor, setButtonBackgroundColor] = useState<string>(bannerColor)

return (
<>
<StyledCard style={{backgroundColor: bannerColor}}>
<StyledCard style={{ backgroundColor: bannerColor }}>
<Horizontal>
<Center>{children}</Center>
</Horizontal>
<Button variant="ghost_icon" onClick={dismissAlert} style={{backgroundColor: buttonBackgroundColor}} onPointerEnter={() => setButtonBackgroundColor(hoverColor)} onPointerLeave={() =>setButtonBackgroundColor(bannerColor)}>
<Icon name={Icons.Clear} style={{ color: tokens.colors.text.static_icons__default.hex}}></Icon>
<Button
variant="ghost_icon"
onClick={dismissAlert}
style={{ backgroundColor: buttonBackgroundColor }}
onPointerEnter={() => setButtonBackgroundColor(hoverColor)}
onPointerLeave={() => setButtonBackgroundColor(bannerColor)}
>
<Icon name={Icons.Clear} style={{ color: tokens.colors.text.static_icons__default.hex }}></Icon>
</Button>
</StyledCard>
</>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Alerts/FailedAlertContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export const FailedAlertContent = ({ title, message }: { title: string; message:
return (
<StyledDiv>
<StyledAlertTitle>
<Icon name={Icons.Failed} style={{color: iconColor}} />
<Icon name={Icons.Failed} style={{ color: iconColor }} />
<Typography>{TranslateText(title)}</Typography>
</StyledAlertTitle>
<Indent>
<TextAlignedButton variant="ghost" color="secondary" style={{backgroundColor: bannerColor}}>
<TextAlignedButton variant="ghost" color="secondary" style={{ backgroundColor: bannerColor }}>
{TranslateText(message)}
</TextAlignedButton>
</Indent>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Alerts/FailedRequestAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const StyledButton = styled(Button)`
text-align: left;
height: auto;
padding: 5px 5px;
background-color: '${tokens.colors.ui.background__danger.hex}'
background-color: '${tokens.colors.ui.background__danger.hex}';
`

export const FailedRequestAlertContent = ({ translatedMessage }: { translatedMessage: string }) => {
Expand Down
25 changes: 16 additions & 9 deletions frontend/src/components/Alerts/SafeZoneAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button, Icon, Typography } from '@equinor/eds-core-react'
import { tokens } from '@equinor/eds-tokens'
import { AlertCategory } from 'components/Alerts/AlertsBanner'
import { AlertType } from 'components/Contexts/AlertContext'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import styled from 'styled-components'

Expand All @@ -21,15 +22,17 @@ const StyledButton = styled(Button)`
`

interface SafeZoneBannerProps {
alertType: AlertType
alertCategory: AlertCategory
}

export const SafeZoneAlertContent = ({ alertCategory }: SafeZoneBannerProps): JSX.Element => {
export const SafeZoneAlertContent = ({ alertType, alertCategory }: SafeZoneBannerProps): JSX.Element => {
const { TranslateText } = useLanguageContext()
const buttonBackgroundColor = alertCategory === AlertCategory.WARNING
? tokens.colors.interactive.warning__highlight.hex
: tokens.colors.infographic.primary__mist_blue.hex

const buttonBackgroundColor =
alertCategory === AlertCategory.WARNING
? tokens.colors.interactive.warning__highlight.hex
: tokens.colors.infographic.primary__mist_blue.hex

return (
<StyledDiv>
<StyledAlertTitle>
Expand All @@ -38,10 +41,14 @@ export const SafeZoneAlertContent = ({ alertCategory }: SafeZoneBannerProps): JS
{alertCategory === AlertCategory.WARNING ? TranslateText('WARNING') : TranslateText('INFO')}
</Typography>
</StyledAlertTitle>
<StyledButton variant="ghost" color="secondary" style={{backgroundColor: buttonBackgroundColor}}>
{alertCategory === AlertCategory.WARNING
? TranslateText('Safe zone banner text')
: TranslateText('Dismiss safe zone banner text')}
<StyledButton variant="ghost" color="secondary" style={{ backgroundColor: buttonBackgroundColor }}>
{alertCategory === AlertCategory.WARNING && TranslateText('Safe zone banner text')}
{alertCategory === AlertCategory.INFO &&
alertType === AlertType.SafeZoneSuccess &&
TranslateText('Safe Zone successful text')}
{alertCategory === AlertCategory.INFO &&
alertType === AlertType.DismissSafeZone &&
TranslateText('Dismiss safe zone banner text')}
</StyledButton>
</StyledDiv>
)
Expand Down
23 changes: 18 additions & 5 deletions frontend/src/components/Contexts/AlertContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RobotStatus } from 'models/Robot'
import { FailedAlertContent } from 'components/Alerts/FailedAlertContent'
import { convertUTCDateToLocalDate } from 'utils/StringFormatting'
import { AlertCategory } from 'components/Alerts/AlertsBanner'
import { SafeZoneAlertContent } from 'components/Alerts/SafeZoneAlert'

export enum AlertType {
MissionFail,
Expand All @@ -20,11 +21,13 @@ export enum AlertType {
BlockedRobot,
RequestSafeZone,
DismissSafeZone,
SafeZoneSuccess,
}

const alertTypeEnumMap: { [key: string]: AlertType } = {
safeZoneFailure: AlertType.SafeZoneFail,
scheduleFailure: AlertType.RequestFail,
safeZoneSuccess: AlertType.SafeZoneSuccess,
}

type AlertDictionaryType = {
Expand Down Expand Up @@ -163,11 +166,21 @@ export const AlertProvider: FC<Props> = ({ children }) => {

// Here we could update the robot state manually, but this is best done on the backend
}
setAlert(
alertType,
<FailedAlertContent title={backendAlert.alertTitle} message={backendAlert.alertMessage} />,
AlertCategory.ERROR
)

if (alertType === AlertType.SafeZoneSuccess) {
setAlert(
alertType,
<SafeZoneAlertContent alertType={alertType} alertCategory={AlertCategory.INFO} />,
AlertCategory.INFO
)
clearAlert(AlertType.RequestSafeZone)
} else {
setAlert(
alertType,
<FailedAlertContent title={backendAlert.alertTitle} message={backendAlert.alertMessage} />,
AlertCategory.ERROR
)
}
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/Contexts/SafeZoneContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ export const SafeZoneProvider: FC<Props> = ({ children }) => {
clearAlert(AlertType.DismissSafeZone)
setAlert(
AlertType.RequestSafeZone,
<SafeZoneAlertContent alertCategory={AlertCategory.WARNING} />,
<SafeZoneAlertContent alertType={AlertType.RequestSafeZone} alertCategory={AlertCategory.WARNING} />,
AlertCategory.WARNING
)
} else if (missionQueueFozenStatus.length === 0 && safeZoneStatus === true) {
setSafeZoneStatus((oldStatus) => !oldStatus)
clearAlert(AlertType.RequestSafeZone)
clearAlert(AlertType.SafeZoneSuccess)
setAlert(
AlertType.DismissSafeZone,
<SafeZoneAlertContent alertCategory={AlertCategory.SUCCESS} />,
AlertCategory.SUCCESS
<SafeZoneAlertContent alertType={AlertType.DismissSafeZone} alertCategory={AlertCategory.INFO} />,
AlertCategory.INFO
)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,7 @@
"Safe zone failure": "Safe zone failure",
"Failure to schedule": "Failure to schedule",
"WARNING": "WARNING",
"INFO": "INFO"
"INFO": "INFO",
"Safe Zone": "Safe Zone",
"Safe Zone successful text": "The robots are in the safe zone and will not run missions. To continue the mission press the 'Safe to continue mission' button."
}
4 changes: 3 additions & 1 deletion frontend/src/language/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,7 @@
"Safe zone failure": "Trygg sone feilet",
"Failure to schedule": "Kunne ikke planlegge oppdrag",
"WARNING": "ADVARSEL",
"INFO": "INFO"
"INFO": "INFO",
"Safe Zone": "Trygg sone",
"Safe Zone successful text": "Robotene er i sikker sone og vil ikke kjøre oppdrag. For å fortsette oppdrag trykk på knappen 'Trygt å fortsette oppdrag'."
}

0 comments on commit 0caeae6

Please sign in to comment.