Skip to content

Commit

Permalink
Preselect robot if there is only one robot
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Nov 28, 2024
1 parent 8bbe1b1 commit c3cc233
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,27 @@ const SelectRobotComponent = memo(
}) => {
const { enabledRobots } = useRobotContext()
const { TranslateText } = useLanguageContext()
const filteredRobots = enabledRobots.filter(
(r) =>
(r.status === RobotStatus.Available ||
r.status === RobotStatus.Busy ||
r.status === RobotStatus.Recharging) &&
r.isarConnected
)

const defaultRobotSelections = (): Robot[] => {
if (filteredRobots.length === 1) {
return [filteredRobots[0]]
}
return []
}

return (
<Autocomplete
initialSelectedOptions={defaultRobotSelections()}
optionLabel={(r) => (r ? r.name + ' (' + r.model.type + ')' : '')}
options={enabledRobots.filter(
(r) =>
(r.status === RobotStatus.Available ||
r.status === RobotStatus.Busy ||
r.status === RobotStatus.Recharging) &&
r.isarConnected
)}
disabled={!enabledRobots}
options={filteredRobots}
disabled={!filteredRobots}
selectedOptions={[selectedRobot]}
label={TranslateText('Select robot')}
onOptionsChange={(changes) => setSelectedRobot(changes.selectedItems[0])}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ export const ScheduleMissionDialog = (props: IProps): JSX.Element => {
r.status === RobotStatus.Recharging) &&
r.isarConnected
)

const defaultRobotSelections = (): Robot[] => {
if (filteredRobots.length === 1) {
return [filteredRobots[0]]
}
return []
}

const onSelectedRobot = (selectedRobot: Robot) => {
if (filteredRobots) setSelectedRobot(selectedRobot)
}
Expand Down Expand Up @@ -151,6 +159,7 @@ export const ScheduleMissionDialog = (props: IProps): JSX.Element => {
)}
<StyledAutoComplete>
<Autocomplete
initialSelectedOptions={defaultRobotSelections()}
dropdownHeight={200}
optionLabel={(r) => r.name + ' (' + r.model.type + ')'}
options={filteredRobots}
Expand Down

0 comments on commit c3cc233

Please sign in to comment.