From 75d2cd823e6aa13779d3863b14f6126b1e1fe688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Chirico=20Indreb=C3=B8?= Date: Fri, 1 Sep 2023 15:34:35 +0200 Subject: [PATCH] Only show rerun failed missions when applicable --- backend/api/Database/Context/InitDb.cs | 155 +++++++++++++++++- frontend/src/api/ApiCaller.tsx | 2 - .../MissionOverview/MissionRestartButton.tsx | 13 +- .../MissionHistoryPage/MissionHistoryView.tsx | 34 ++-- .../MissionPage/TaskOverview/TaskTable.tsx | 29 ++-- 5 files changed, 195 insertions(+), 38 deletions(-) diff --git a/backend/api/Database/Context/InitDb.cs b/backend/api/Database/Context/InitDb.cs index b53675d32..bf39f0ac3 100644 --- a/backend/api/Database/Context/InitDb.cs +++ b/backend/api/Database/Context/InitDb.cs @@ -1,4 +1,5 @@ -using Api.Database.Models; +using Api.Controllers.Models; +using Api.Database.Models; namespace Api.Database.Context; @@ -10,6 +11,7 @@ public static class InitDb private static readonly List decks = GetDecks(); private static readonly List areas = GetAreas(); private static readonly List sources = GetSources(); + private static readonly List tasks = GetMissionTasks(); private static readonly List missionDefinitions = GetMissionDefinitions(); private static readonly List missionRuns = GetMissionRuns(); @@ -215,6 +217,87 @@ private static List GetMissionDefinitions() return new List(new[] { missionDefinition1, missionDefinition2, missionDefinition3 }); } + private static List GetMissionTasks() + { + var task1 = new MissionTask( + new EchoTag + { + Id = 2, + TagId = "ABCD", + PoseId = 2, + PlanOrder = 0, + Pose = new Pose(300.0f, 50.0f, 200.0f, 0.0f, 0.0f, 0.0f, 1.0f), + URL = new Uri( + $"https://stid.equinor.com/jsv/tag?tagNo=ABCD" + ), + Inspections = new List + { + new() + } + }, new Position(1.0f, 1.0f, 1.0f)); + var task2 = new MissionTask( + new EchoTag + { + Id = 2, + TagId = "ABCD", + PoseId = 2, + PlanOrder = 0, + Pose = new Pose(300.0f, 50.0f, 200.0f, 0.0f, 0.0f, 0.0f, 1.0f), + URL = new Uri( + $"https://stid.equinor.com/jsv/tag?tagNo=ABCD" + ), + Inspections = new List + { + new() + } + }, new Position(1.0f, 1.0f, 1.0f)) + { + Status = Models.TaskStatus.Failed + }; + + var task3 = new MissionTask( + new EchoTag + { + Id = 2, + TagId = "ABCD", + PoseId = 2, + PlanOrder = 0, + Pose = new Pose(300.0f, 50.0f, 200.0f, 0.0f, 0.0f, 0.0f, 1.0f), + URL = new Uri( + $"https://stid.equinor.com/jsv/tag?tagNo=ABCD" + ), + Inspections = new List + { + new() + } + }, new Position(1.0f, 1.0f, 1.0f)) + { + Status = Models.TaskStatus.PartiallySuccessful + }; + + var task4 = new MissionTask( + new EchoTag + { + Id = 2, + TagId = "ABCD", + PoseId = 2, + PlanOrder = 0, + Pose = new Pose(300.0f, 50.0f, 200.0f, 0.0f, 0.0f, 0.0f, 1.0f), + URL = new Uri( + $"https://stid.equinor.com/jsv/tag?tagNo=ABCD" + ), + Inspections = new List + { + new() + } + }, new Position(1.0f, 1.0f, 1.0f)) + { + Status = Models.TaskStatus.Cancelled + }; + + return new List { task1, task2, task3, task4 }; + } + private static List GetMissionRuns() { var missionRun1 = new MissionRun @@ -257,9 +340,77 @@ private static List GetMissionRuns() Map = new MapMetadata() }; + var missionRun4 = new MissionRun + { + Name = "Placeholder Mission 4", + Robot = robots[2], + InstallationCode = areas[1].Installation.InstallationCode, + Area = areas[1], + MissionId = missionDefinitions[1].Id, + Status = MissionStatus.Failed, + DesiredStartTime = DateTimeOffset.UtcNow, + Tasks = new List + { + tasks[0], + tasks[1] + }, + Map = new MapMetadata() + }; + + var missionRun5 = new MissionRun + { + Name = "Placeholder Mission 5", + Robot = robots[2], + InstallationCode = areas[1].Installation.InstallationCode, + Area = areas[1], + MissionId = missionDefinitions[1].Id, + Status = MissionStatus.PartiallySuccessful, + DesiredStartTime = DateTimeOffset.UtcNow, + Tasks = new List + { + tasks[0], + tasks[2] + }, + Map = new MapMetadata() + }; + + var missionRun6 = new MissionRun + { + Name = "Placeholder Mission 6", + Robot = robots[2], + InstallationCode = areas[1].Installation.InstallationCode, + Area = areas[1], + MissionId = missionDefinitions[1].Id, + Status = MissionStatus.Cancelled, + DesiredStartTime = DateTimeOffset.UtcNow, + Tasks = new List + { + tasks[0], + tasks[3] + }, + Map = new MapMetadata() + }; + + var missionRun7 = new MissionRun + { + Name = "Says failed but all tasks succeeded", + Robot = robots[2], + InstallationCode = areas[1].Installation.InstallationCode, + Area = areas[1], + MissionId = missionDefinitions[1].Id, + Status = MissionStatus.Failed, + DesiredStartTime = DateTimeOffset.UtcNow, + Tasks = new List + { + tasks[0], + tasks[0] + }, + Map = new MapMetadata() + }; + missionDefinitions[1].LastRun = missionRun3; - return new List(new[] { missionRun1, missionRun2, missionRun3 }); + return new List(new[] { missionRun1, missionRun2, missionRun3, missionRun4, missionRun5, missionRun6, missionRun7 }); } public static void PopulateDb(FlotillaDbContext context) diff --git a/frontend/src/api/ApiCaller.tsx b/frontend/src/api/ApiCaller.tsx index beb32ee5e..f77aa9331 100644 --- a/frontend/src/api/ApiCaller.tsx +++ b/frontend/src/api/ApiCaller.tsx @@ -372,8 +372,6 @@ export class BackendAPICaller { static async reRunMission(missionId: string, failedTasksOnly: boolean = false): Promise { let mission = await this.getMissionRunById(missionId) - // TODO: utilise reschedule endpoint instead of copying - if (failedTasksOnly) { mission.tasks = mission.tasks.filter( (task) => task.status !== TaskStatus.PartiallySuccessful && task.status !== TaskStatus.Successful diff --git a/frontend/src/components/Pages/FrontPage/MissionOverview/MissionRestartButton.tsx b/frontend/src/components/Pages/FrontPage/MissionOverview/MissionRestartButton.tsx index 145142afa..05b8cc22a 100644 --- a/frontend/src/components/Pages/FrontPage/MissionOverview/MissionRestartButton.tsx +++ b/frontend/src/components/Pages/FrontPage/MissionOverview/MissionRestartButton.tsx @@ -1,4 +1,4 @@ -import { Mission } from 'models/Mission' +import { Mission, MissionStatus } from 'models/Mission' import { Button, EdsProvider, Icon, Menu, Tooltip } from '@equinor/eds-core-react' import { Icons } from 'utils/icons' import { tokens } from '@equinor/eds-tokens' @@ -8,6 +8,7 @@ import { useNavigate } from 'react-router-dom' import { useLanguageContext } from 'components/Contexts/LanguageContext' import styled from 'styled-components' import { useRef, useState } from 'react' +import { TaskStatus } from 'models/Task' const Centered = styled.div` display: flex; @@ -77,9 +78,13 @@ export function MissionRestartButton({ mission }: MissionProps) { startReRun(ReRunOptions.ReRun)}> {TranslateText('Re-run full mission')} - startReRun(ReRunOptions.ReRunFailed)}> - {TranslateText('Re-run failed and cancelled tasks in the mission')} - + {mission.tasks.some( + (t) => t.status !== TaskStatus.PartiallySuccessful && t.status !== TaskStatus.Successful + ) && ( + startReRun(ReRunOptions.ReRunFailed)}> + {TranslateText('Re-run failed and cancelled tasks in the mission')} + + )} diff --git a/frontend/src/components/Pages/MissionHistoryPage/MissionHistoryView.tsx b/frontend/src/components/Pages/MissionHistoryPage/MissionHistoryView.tsx index 3b1b52409..a0f92de43 100644 --- a/frontend/src/components/Pages/MissionHistoryPage/MissionHistoryView.tsx +++ b/frontend/src/components/Pages/MissionHistoryPage/MissionHistoryView.tsx @@ -123,24 +123,22 @@ export function MissionHistoryView({ refreshInterval }: RefreshProps) { {TranslateText('Mission History')} -
- - - {TranslateText('Status')} - {TranslateText('Name')} - {TranslateText('Robot')} - {TranslateText('Completion Time')} - - - {isLoading && ( - - - - - - )} - {!isLoading && {missionsDisplay}} -
+ + + {TranslateText('Status')} + {TranslateText('Name')} + {TranslateText('Robot')} + {TranslateText('Completion Time')} + + + {isLoading && ( + + + + + + )} + {!isLoading && {missionsDisplay}} {paginationDetails && paginationDetails.TotalPages > 1 && !isResettingPage && PaginationComponent()} diff --git a/frontend/src/components/Pages/MissionPage/TaskOverview/TaskTable.tsx b/frontend/src/components/Pages/MissionPage/TaskOverview/TaskTable.tsx index 36b81d5cc..1e07e20fc 100644 --- a/frontend/src/components/Pages/MissionPage/TaskOverview/TaskTable.tsx +++ b/frontend/src/components/Pages/MissionPage/TaskOverview/TaskTable.tsx @@ -39,16 +39,16 @@ export function TaskTable({ mission }: MissionProps) { } function renderTasks(tasks: Task[]) { - var rows = tasks?.map(function (task) { + var rows = tasks.map((task) => { // Workaround for current bug in echo - var order: number = task.taskOrder < 214748364 ? task.taskOrder + 1 : 1 + const order: number = task.taskOrder < 214748364 ? task.taskOrder + 1 : 1 const rowStyle = task.status === TaskStatus.InProgress || task.status === TaskStatus.Paused ? { background: tokens.colors.infographic.primary__mist_blue.hex } : {} const markerColors = GetColorsFromTaskStatus(task.status) return ( - + @@ -56,8 +56,8 @@ function renderTasks(tasks: Task[]) { - {renderTagId(task)} - {renderDescription(task)} + {renderTagId(task)} + {renderDescription(task)} {renderInspectionTypes(task)} @@ -69,30 +69,35 @@ function renderTasks(tasks: Task[]) { } function renderTagId(task: Task) { - if (!task.tagId) return {'N/A'} + if (!task.tagId) return {'N/A'} if (task.echoTagLink) return ( - + {task.tagId!} ) - else return {task.tagId!} + else return {task.tagId!} } function renderDescription(task: Task) { - if (!task.description) return {'N/A'} - return {task.description} + if (!task.description) return {'N/A'} + return {task.description} } function renderInspectionTypes(task: Task) { return task.inspections?.map(function (inspection) { if (inspection.inspectionUrl) return ( - + + {TranslateTextWithContext(inspection.inspectionType as string)} + + ) + else + return ( + {TranslateTextWithContext(inspection.inspectionType as string)} ) - else return {TranslateTextWithContext(inspection.inspectionType as string)} }) }