Skip to content

Commit

Permalink
Filtering robots in ScheduleMissionDialogs.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
betaniat committed Aug 1, 2024
1 parent c64a0fc commit d1b8471
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ const SelectRobotComponent = memo(
<Autocomplete
optionLabel={(r) => (r ? r.name + ' (' + r.model.type + ')' : '')}
options={enabledRobots.filter(
(r) => (r.status === RobotStatus.Available || r.status === RobotStatus.Busy) && r.isarConnected
(r) =>
(r.status === RobotStatus.Available ||
r.status === RobotStatus.Busy ||
r.status === RobotStatus.Recharging) &&
r.isarConnected
)}
disabled={!enabledRobots}
selectedOptions={[selectedRobot]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Autocomplete, Dialog, Typography, Icon } from '@equinor/eds-core-react'
import styled from 'styled-components'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { useState } from 'react'
import { Robot } from 'models/Robot'
import { Robot, RobotStatus } from 'models/Robot'
import { CondensedMissionDefinition } from 'models/MissionDefinition'
import { BackendAPICaller } from 'api/ApiCaller'
import { Icons } from 'utils/icons'
Expand Down Expand Up @@ -58,9 +58,15 @@ export const ScheduleMissionDialog = (props: IProps): JSX.Element => {
const [isLocalizationVerificationDialogOpen, setIsLocalizationVerificationDialog] = useState<boolean>(false)
const [selectedRobot, setSelectedRobot] = useState<Robot>()
const [missionsToSchedule, setMissionsToSchedule] = useState<CondensedMissionDefinition[]>()

const filteredRobots = enabledRobots.filter(
(r) =>
(r.status === RobotStatus.Available ||
r.status === RobotStatus.Busy ||
r.status === RobotStatus.Recharging) &&
r.isarConnected
)
const onSelectedRobot = (selectedRobot: Robot) => {
if (enabledRobots) setSelectedRobot(selectedRobot)
if (filteredRobots) setSelectedRobot(selectedRobot)
}

const onScheduleButtonPress = (missions: CondensedMissionDefinition[]) => () => {
Expand Down Expand Up @@ -138,7 +144,7 @@ export const ScheduleMissionDialog = (props: IProps): JSX.Element => {
<Autocomplete
dropdownHeight={200}
optionLabel={(r) => r.name + ' (' + r.model.type + ')'}
options={enabledRobots}
options={filteredRobots}
label={TranslateText('Select robot')}
onOptionsChange={(changes) => onSelectedRobot(changes.selectedItems[0])}
autoWidth={true}
Expand Down

0 comments on commit d1b8471

Please sign in to comment.