From 0caeae6b7c54f79cde0e6982619517916a6bab3d Mon Sep 17 00:00:00 2001 From: "Mariana R. Santos" Date: Mon, 25 Mar 2024 16:14:29 +0100 Subject: [PATCH] Change safe zone banner when robot is in safe zone --- backend/api.test/Mocks/SignalRServiceMock.cs | 5 ++++ .../api/EventHandlers/MissionEventHandler.cs | 10 ++++++++ backend/api/Services/SignalRService.cs | 9 +++++++ .../src/components/Alerts/AlertsBanner.tsx | 20 +++++++++------ .../components/Alerts/FailedAlertContent.tsx | 4 +-- .../components/Alerts/FailedRequestAlert.tsx | 2 +- .../src/components/Alerts/SafeZoneAlert.tsx | 25 ++++++++++++------- .../src/components/Contexts/AlertContext.tsx | 23 +++++++++++++---- .../components/Contexts/SafeZoneContext.tsx | 7 +++--- frontend/src/language/en.json | 4 ++- frontend/src/language/no.json | 4 ++- 11 files changed, 84 insertions(+), 29 deletions(-) diff --git a/backend/api.test/Mocks/SignalRServiceMock.cs b/backend/api.test/Mocks/SignalRServiceMock.cs index 984b20bab..d0629ca6d 100644 --- a/backend/api.test/Mocks/SignalRServiceMock.cs +++ b/backend/api.test/Mocks/SignalRServiceMock.cs @@ -27,5 +27,10 @@ public void ReportScheduleFailureToSignalR(Robot robot, string message) { return; } + + public void ReportSafeZoneSuccessToSignalR(Robot robot, string message) + { + return; + } } } diff --git a/backend/api/EventHandlers/MissionEventHandler.cs b/backend/api/EventHandlers/MissionEventHandler.cs index 6347ab7a8..b24635c32 100644 --- a/backend/api/EventHandlers/MissionEventHandler.cs +++ b/backend/api/EventHandlers/MissionEventHandler.cs @@ -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; } diff --git a/backend/api/Services/SignalRService.cs b/backend/api/Services/SignalRService.cs index ebd949a93..37f825932 100644 --- a/backend/api/Services/SignalRService.cs +++ b/backend/api/Services/SignalRService.cs @@ -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) : ISignalRService @@ -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)); + } + } } diff --git a/frontend/src/components/Alerts/AlertsBanner.tsx b/frontend/src/components/Alerts/AlertsBanner.tsx index 7e2153a07..cc22b3280 100644 --- a/frontend/src/components/Alerts/AlertsBanner.tsx +++ b/frontend/src/components/Alerts/AlertsBanner.tsx @@ -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` @@ -32,7 +32,7 @@ const Center = styled.div` export enum AlertCategory { ERROR, WARNING, - SUCCESS, + INFO, } interface AlertProps { @@ -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(bannerColor) return ( <> - +
{children}
-
diff --git a/frontend/src/components/Alerts/FailedAlertContent.tsx b/frontend/src/components/Alerts/FailedAlertContent.tsx index bd6b4d66d..eda90f9ce 100644 --- a/frontend/src/components/Alerts/FailedAlertContent.tsx +++ b/frontend/src/components/Alerts/FailedAlertContent.tsx @@ -27,11 +27,11 @@ export const FailedAlertContent = ({ title, message }: { title: string; message: return ( - + {TranslateText(title)} - + {TranslateText(message)} diff --git a/frontend/src/components/Alerts/FailedRequestAlert.tsx b/frontend/src/components/Alerts/FailedRequestAlert.tsx index 0685a29de..4a02c4fbc 100644 --- a/frontend/src/components/Alerts/FailedRequestAlert.tsx +++ b/frontend/src/components/Alerts/FailedRequestAlert.tsx @@ -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 }) => { diff --git a/frontend/src/components/Alerts/SafeZoneAlert.tsx b/frontend/src/components/Alerts/SafeZoneAlert.tsx index 357d64704..e9c5c631e 100644 --- a/frontend/src/components/Alerts/SafeZoneAlert.tsx +++ b/frontend/src/components/Alerts/SafeZoneAlert.tsx @@ -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' @@ -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 ( @@ -38,10 +41,14 @@ export const SafeZoneAlertContent = ({ alertCategory }: SafeZoneBannerProps): JS {alertCategory === AlertCategory.WARNING ? TranslateText('WARNING') : TranslateText('INFO')} - - {alertCategory === AlertCategory.WARNING - ? TranslateText('Safe zone banner text') - : TranslateText('Dismiss safe zone banner text')} + + {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')} ) diff --git a/frontend/src/components/Contexts/AlertContext.tsx b/frontend/src/components/Contexts/AlertContext.tsx index aca1f4947..7e8fb5018 100644 --- a/frontend/src/components/Contexts/AlertContext.tsx +++ b/frontend/src/components/Contexts/AlertContext.tsx @@ -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, @@ -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 = { @@ -163,11 +166,21 @@ export const AlertProvider: FC = ({ children }) => { // Here we could update the robot state manually, but this is best done on the backend } - setAlert( - alertType, - , - AlertCategory.ERROR - ) + + if (alertType === AlertType.SafeZoneSuccess) { + setAlert( + alertType, + , + AlertCategory.INFO + ) + clearAlert(AlertType.RequestSafeZone) + } else { + setAlert( + alertType, + , + AlertCategory.ERROR + ) + } }) } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/frontend/src/components/Contexts/SafeZoneContext.tsx b/frontend/src/components/Contexts/SafeZoneContext.tsx index 74153457a..3e67d76a3 100644 --- a/frontend/src/components/Contexts/SafeZoneContext.tsx +++ b/frontend/src/components/Contexts/SafeZoneContext.tsx @@ -40,16 +40,17 @@ export const SafeZoneProvider: FC = ({ children }) => { clearAlert(AlertType.DismissSafeZone) setAlert( AlertType.RequestSafeZone, - , + , AlertCategory.WARNING ) } else if (missionQueueFozenStatus.length === 0 && safeZoneStatus === true) { setSafeZoneStatus((oldStatus) => !oldStatus) clearAlert(AlertType.RequestSafeZone) + clearAlert(AlertType.SafeZoneSuccess) setAlert( AlertType.DismissSafeZone, - , - AlertCategory.SUCCESS + , + AlertCategory.INFO ) } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/frontend/src/language/en.json b/frontend/src/language/en.json index 6bdbdbd89..81ba5c30a 100644 --- a/frontend/src/language/en.json +++ b/frontend/src/language/en.json @@ -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." } diff --git a/frontend/src/language/no.json b/frontend/src/language/no.json index cb0ff4620..534fe7e96 100644 --- a/frontend/src/language/no.json +++ b/frontend/src/language/no.json @@ -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'." }