Skip to content

Commit

Permalink
chore(cherrypick): 16208 to chore_release-8.0.0 (#16232)
Browse files Browse the repository at this point in the history
## Cherrypick in #16208

Co-authored-by: Seth Foster <[email protected]>
  • Loading branch information
y3rsh and sfoster1 authored Sep 10, 2024
1 parent 8940797 commit 9c83c6d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
runCreatedAt: '2022-05-11T13:33:51.012179+00:00',
}
when(vi.mocked(useOffsetCandidatesForAnalysis))
.calledWith(storedProtocolDataFixture.mostRecentAnalysis, '127.0.0.1')
.calledWith(storedProtocolDataFixture.mostRecentAnalysis, null)
.thenReturn([mockOffsetCandidate])
vi.mocked(getConnectableRobots).mockReturnValue([
mockConnectableRobot,
Expand All @@ -333,7 +333,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
})
expect(vi.mocked(useCreateRunFromProtocol)).toHaveBeenCalledWith(
expect.any(Object),
{ hostname: '127.0.0.1' },
null,
[
{
vector: mockOffsetCandidate.vector,
Expand Down Expand Up @@ -369,11 +369,8 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
runCreatedAt: '2022-05-11T13:33:51.012179+00:00',
}
when(vi.mocked(useOffsetCandidatesForAnalysis))
.calledWith(storedProtocolDataFixture.mostRecentAnalysis, '127.0.0.1')
.calledWith(storedProtocolDataFixture.mostRecentAnalysis, null)
.thenReturn([mockOffsetCandidate])
when(vi.mocked(useOffsetCandidatesForAnalysis))
.calledWith(storedProtocolDataFixture.mostRecentAnalysis, 'otherIp')
.thenReturn([])
vi.mocked(getConnectableRobots).mockReturnValue([
mockConnectableRobot,
{ ...mockConnectableRobot, name: 'otherRobot', ip: 'otherIp' },
Expand All @@ -393,10 +390,9 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
})
fireEvent.click(proceedButton)
fireEvent.click(screen.getByRole('button', { name: 'Confirm values' }))
expect(vi.mocked(useCreateRunFromProtocol)).nthCalledWith(
3,
expect(vi.mocked(useCreateRunFromProtocol)).toHaveBeenLastCalledWith(
expect.any(Object),
{ hostname: '127.0.0.1' },
null,
[
{
vector: mockOffsetCandidate.vector,
Expand All @@ -405,11 +401,6 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
},
]
)
expect(vi.mocked(useCreateRunFromProtocol)).toHaveBeenLastCalledWith(
expect.any(Object),
{ hostname: 'otherIp' },
[]
)
})

it('disables proceed button if no available robots', () => {
Expand Down
58 changes: 35 additions & 23 deletions app/src/organisms/ChooseRobotToRunProtocolSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
SPACING,
useHoverTooltip,
} from '@opentrons/components'
import { useUploadCsvFileMutation } from '@opentrons/react-api-client'
import {
useUploadCsvFileMutation,
ApiHostProvider,
} from '@opentrons/react-api-client'

import { Tooltip } from '../../atoms/Tooltip'
import { getRobotUpdateDisplayInfo } from '../../redux/robot-update'
Expand Down Expand Up @@ -46,11 +49,23 @@ interface ChooseRobotToRunProtocolSlideoutProps extends StyleProps {
showSlideout: boolean
}

interface ChooseRobotToRunProtocolSlideoutComponentProps
extends ChooseRobotToRunProtocolSlideoutProps {
selectedRobot: Robot | null
setSelectedRobot: (robot: Robot | null) => void
}

export function ChooseRobotToRunProtocolSlideoutComponent(
props: ChooseRobotToRunProtocolSlideoutProps
props: ChooseRobotToRunProtocolSlideoutComponentProps
): JSX.Element | null {
const { t } = useTranslation(['protocol_details', 'shared', 'app_settings'])
const { storedProtocolData, showSlideout, onCloseClick } = props
const {
storedProtocolData,
showSlideout,
onCloseClick,
selectedRobot,
setSelectedRobot,
} = props
const navigate = useNavigate()
const [shouldApplyOffsets, setShouldApplyOffsets] = React.useState<boolean>(
true
Expand All @@ -62,7 +77,6 @@ export function ChooseRobotToRunProtocolSlideoutComponent(
mostRecentAnalysis,
} = storedProtocolData
const [currentPage, setCurrentPage] = React.useState<number>(1)
const [selectedRobot, setSelectedRobot] = React.useState<Robot | null>(null)
const { trackCreateProtocolRunEvent } = useTrackCreateProtocolRunEvent(
storedProtocolData,
selectedRobot?.name ?? ''
Expand All @@ -83,19 +97,10 @@ export function ChooseRobotToRunProtocolSlideoutComponent(

const offsetCandidates = useOffsetCandidatesForAnalysis(
mostRecentAnalysis,
selectedRobot?.ip ?? null
null
)

const { uploadCsvFile } = useUploadCsvFileMutation(
{},
selectedRobot != null
? {
hostname: selectedRobot.ip,
requestor:
selectedRobot?.ip === OPENTRONS_USB ? appShellRequestor : undefined,
}
: null
)
const { uploadCsvFile } = useUploadCsvFileMutation()

const {
createRunFromProtocolSource,
Expand All @@ -121,13 +126,7 @@ export function ChooseRobotToRunProtocolSlideoutComponent(
})
},
},
selectedRobot != null
? {
hostname: selectedRobot.ip,
requestor:
selectedRobot?.ip === OPENTRONS_USB ? appShellRequestor : undefined,
}
: null,
null,
shouldApplyOffsets
? offsetCandidates.map(({ vector, location, definitionUri }) => ({
vector,
Expand Down Expand Up @@ -360,5 +359,18 @@ export function ChooseRobotToRunProtocolSlideoutComponent(
export function ChooseRobotToRunProtocolSlideout(
props: ChooseRobotToRunProtocolSlideoutProps
): JSX.Element | null {
return <ChooseRobotToRunProtocolSlideoutComponent {...props} />
const [selectedRobot, setSelectedRobot] = React.useState<Robot | null>(null)
return (
<ApiHostProvider
hostname={selectedRobot?.ip ?? null}
port={selectedRobot?.port ?? null}
requestor={
selectedRobot?.ip === OPENTRONS_USB ? appShellRequestor : undefined
}
>
<ChooseRobotToRunProtocolSlideoutComponent
{...{ ...props, selectedRobot, setSelectedRobot }}
/>
</ApiHostProvider>
)
}

0 comments on commit 9c83c6d

Please sign in to comment.