From 4abe6520cca43cd6409df77d794e5ec7b4752226 Mon Sep 17 00:00:00 2001 From: Nick Diehl <47604184+ncdiehl11@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:06:15 -0400 Subject: [PATCH] fix(app): set default selected robot on slideout to first valid robot (#14925) closes RQA-2578 --- app/src/organisms/ChooseRobotSlideout/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/organisms/ChooseRobotSlideout/index.tsx b/app/src/organisms/ChooseRobotSlideout/index.tsx index 68b89afddad..066bd28eb61 100644 --- a/app/src/organisms/ChooseRobotSlideout/index.tsx +++ b/app/src/organisms/ChooseRobotSlideout/index.tsx @@ -193,12 +193,18 @@ export function ChooseRobotSlideout( // this useEffect sets the default selection to the first robot in the list. state is managed by the caller React.useEffect(() => { - if (selectedRobot == null && reducerAvailableRobots.length > 0) { + if ( + (selectedRobot == null || + !reducerAvailableRobots.some( + robot => robot.name === selectedRobot.name + )) && + reducerAvailableRobots.length > 0 + ) { setSelectedRobot(reducerAvailableRobots[0]) } else if (reducerAvailableRobots.length === 0) { setSelectedRobot(null) } - }, [healthyReachableRobots, selectedRobot, setSelectedRobot]) + }, [reducerAvailableRobots, selectedRobot, setSelectedRobot]) const unavailableCount = unhealthyReachableRobots.length + unreachableRobots.length