Skip to content

Commit 8c4e9d1

Browse files
authored
Add clear mission button to context menu (#603)
* Add clear mission button to context menu * Clear mission for all mission types * Fix no waypoints mission test * Fix test again
1 parent bffd8a5 commit 8c4e9d1

4 files changed

Lines changed: 37 additions & 8 deletions

File tree

gcs/src/components/missions/missionsMap.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function MapSectionNonMemo({
5454
markerDragEndCallback,
5555
addNewMissionItem,
5656
updateMissionHomePosition,
57+
clearMissionItems,
5758
mapId = "dashboard",
5859
}) {
5960
const [connected] = useSessionStorage({
@@ -347,6 +348,11 @@ function MapSectionNonMemo({
347348
<p>Set home position</p>
348349
</div>
349350
</ContextMenuItem>
351+
<ContextMenuItem onClick={clearMissionItems}>
352+
<div className="w-full flex justify-between gap-2">
353+
<p>Clear mission</p>
354+
</div>
355+
</ContextMenuItem>
350356
</div>
351357
)}
352358
</Map>

gcs/src/missions.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,24 @@ export default function Missions() {
528528
}
529529
}
530530

531+
function clearMissionItems() {
532+
if (activeTab === "mission") {
533+
// Clear all mission items except the first if the first is a home position
534+
if (
535+
missionItems.length > 0 &&
536+
isGlobalFrameHomeCommand(missionItems[0])
537+
) {
538+
setMissionItems([missionItems[0]])
539+
} else {
540+
setMissionItems([])
541+
}
542+
} else if (activeTab === "fence") {
543+
setFenceItems([])
544+
} else if (activeTab === "rally") {
545+
setRallyItems([])
546+
}
547+
}
548+
531549
return (
532550
<Layout currentPage="missions">
533551
{/* Banner to let people know that things are still under development */}
@@ -644,6 +662,7 @@ export default function Missions() {
644662
markerDragEndCallback={updateMissionItem}
645663
addNewMissionItem={addNewMissionItem}
646664
updateMissionHomePosition={updateMissionHomePosition}
665+
clearMissionItems={clearMissionItems}
647666
mapId="missions"
648667
/>
649668
</div>

radio/app/controllers/missionController.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,16 +498,20 @@ def uploadMission(self, mission_type: int, waypoints: List[dict]) -> Response:
498498

499499
new_loader = self._parseWaypointsListIntoLoader(waypoints, mission_type)
500500

501-
if new_loader.count() == 0:
502-
return {
503-
"success": False,
504-
"message": f"No waypoints loaded for the mission type of {mission_type}",
505-
}
506-
507501
clear_mission_response = self.clearMission(mission_type)
508502
if not clear_mission_response.get("success"):
509503
return clear_mission_response
510504

505+
# If the loader is empty, we don't need to upload anything.
506+
if new_loader.count() == 0:
507+
self.drone.logger.info(
508+
f"Cleared mission type {mission_type}, no waypoints to upload"
509+
)
510+
return {
511+
"success": True,
512+
"message": f"Cleared mission type {mission_type}, no waypoints to upload",
513+
}
514+
511515
self.drone.is_listening = False
512516

513517
self.drone.master.mav.mission_count_send(

radio/tests/test_mission.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,6 @@ def test_writeCurrentMission_correctState_noWaypoints(
409409

410410
assert socketio_result["name"] == "write_mission_result"
411411
assert socketio_result["args"][0] == {
412-
"success": False,
413-
"message": "No waypoints loaded for the mission type of 0",
412+
"success": True,
413+
"message": "Cleared mission type 0, no waypoints to upload",
414414
}

0 commit comments

Comments
 (0)