From a802ec1990876a4f4aa5c6fed832c19f215c18e7 Mon Sep 17 00:00:00 2001 From: oysand Date: Wed, 12 Oct 2022 12:17:15 +0200 Subject: [PATCH] Select robot when scheduling missions --- frontend/src/api/ApiCaller.tsx | 4 +- .../MissionOverview/ScheduleMissionDialog.tsx | 20 +++++-- .../MissionOverview/UpcomingMissionView.tsx | 52 +++++++++++++++++-- frontend/src/utils/scheduleMission.tsx | 4 +- 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/frontend/src/api/ApiCaller.tsx b/frontend/src/api/ApiCaller.tsx index 6463bfe95..67c434c15 100644 --- a/frontend/src/api/ApiCaller.tsx +++ b/frontend/src/api/ApiCaller.tsx @@ -115,10 +115,10 @@ export class BackendAPICaller { }) return result.body } - async postMission(echoMissionId: number, startTime: Date) { + async postMission(echoMissionId: number, robotId: string, startTime: Date) { const path: string = 'missions' const robots: Robot[] = await this.getRobots() - const desiredRobot = filterRobots(robots, 'R2-D2') + const desiredRobot = filterRobots(robots, robotId) const body = { robotId: desiredRobot[0].id, echoMissionId: echoMissionId, startTime: startTime } const result = await this.POST(path, body).catch((e) => { throw new Error(`Failed to POST /${path}: ` + e) diff --git a/frontend/src/components/MissionOverview/ScheduleMissionDialog.tsx b/frontend/src/components/MissionOverview/ScheduleMissionDialog.tsx index 64dad0e33..1629e169d 100644 --- a/frontend/src/components/MissionOverview/ScheduleMissionDialog.tsx +++ b/frontend/src/components/MissionOverview/ScheduleMissionDialog.tsx @@ -4,9 +4,12 @@ import { useState } from 'react' import styled from 'styled-components' interface IProps { - options: Array + robotOptions: Array + echoMissionsOptions: Array onSelectedMissions: (missions: string[]) => void + onSelectedRobot: (robot: string) => void onScheduleButtonPress: () => void + scheduleButtonDisabled: boolean } const StyledMissionDialog = styled.div` @@ -26,9 +29,12 @@ const StyledMissionSection = styled.div` export const ScheduleMissionDialog = (props: IProps): JSX.Element => { const [isOpen, setIsOpen] = useState(false) - const onChange = (changes: AutocompleteChanges) => { + const onChangeEchoMissionSelections = (changes: AutocompleteChanges) => { props.onSelectedMissions(changes.selectedItems) } + const onChangeRobotSelection = (changes: AutocompleteChanges) => { + props.onSelectedRobot(changes.selectedItems[0]) + } return ( <> diff --git a/frontend/src/utils/scheduleMission.tsx b/frontend/src/utils/scheduleMission.tsx index 2a496e3be..934273119 100644 --- a/frontend/src/utils/scheduleMission.tsx +++ b/frontend/src/utils/scheduleMission.tsx @@ -1,6 +1,6 @@ import { Robot } from 'models/Robot' -export const filterRobots = (robots: Robot[], name: string): Robot[] => { - const desiredRobot = robots.filter((robot: Robot) => robot.name === name) +export const filterRobots = (robots: Robot[], id: string): Robot[] => { + const desiredRobot = robots.filter((robot: Robot) => robot.id === id) return desiredRobot }