Skip to content

Commit

Permalink
fix(app): set default selected robot on slideout to first valid robot (
Browse files Browse the repository at this point in the history
  • Loading branch information
ncdiehl11 authored Apr 16, 2024
1 parent 385d123 commit 4abe652
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/organisms/ChooseRobotSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4abe652

Please sign in to comment.