Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(robot-server, app): Fix ODD routing back to previous screen #16021

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 50 additions & 18 deletions app/src/pages/RunSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useSelector } from 'react-redux'
import { useParams, useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import styled, { css } from 'styled-components'
import { useQueryClient } from 'react-query'

import {
ALIGN_CENTER,
Expand Down Expand Up @@ -144,6 +143,10 @@ export function RunSummary(): JSX.Element {
const [showRunAgainSpinner, setShowRunAgainSpinner] = React.useState<boolean>(
false
)
const [showReturnToSpinner, setShowReturnToSpinner] = React.useState<boolean>(
false
)

const robotSerialNumber =
localRobot?.health?.robot_serial ??
localRobot?.serverHealth?.serialNumber ??
Expand Down Expand Up @@ -195,15 +198,6 @@ export function RunSummary(): JSX.Element {
}
}, [isRunCurrent, enteredER])

// TODO(jh, 08-02-24): Revisit useCurrentRunRoute and top level redirects.
const queryClient = useQueryClient()
const returnToDash = (): void => {
// Eagerly clear the query caches to prevent top level redirecting back to this page.
queryClient.setQueryData([host, 'runs', 'details'], () => undefined)
queryClient.setQueryData([host, 'runs', runId, 'details'], () => undefined)
navigate('/')
}

const returnToQuickTransfer = (): void => {
if (!isRunCurrent) {
deleteRun(runId)
Expand Down Expand Up @@ -239,6 +233,7 @@ export function RunSummary(): JSX.Element {
}

const handleReturnToDash = (aPipetteWithTip: PipetteWithTip | null): void => {
setShowReturnToSpinner(true)
if (isRunCurrent && aPipetteWithTip != null) {
void handleTipsAttachedModal({
setTipStatusResolved: setTipStatusResolvedAndRoute(handleReturnToDash),
Expand All @@ -251,16 +246,19 @@ export function RunSummary(): JSX.Element {
onSkipAndHome: () => {
closeCurrentRun({
onSuccess: () => {
returnToDash()
navigate('/')
},
})
},
})
} else if (isQuickTransfer) {
returnToQuickTransfer()
} else {
closeCurrentRun()
returnToDash()
closeCurrentRun({
onSuccess: () => {
navigate('/')
},
})
}
}

Expand Down Expand Up @@ -297,7 +295,22 @@ export function RunSummary(): JSX.Element {
setShowSplash(false)
}

const RUN_AGAIN_SPINNER_TEXT = (
const buildReturnToCopy = (): string =>
isQuickTransfer ? t('return_to_quick_transfer') : t('return_to_dashboard')

const buildReturnToWithSpinnerText = (): JSX.Element => (
<Flex justifyContent={JUSTIFY_SPACE_BETWEEN} width="16rem">
{buildReturnToCopy()}
<Icon
name="ot-spinner"
aria-label="icon_ot-spinner"
spin={true}
size="3.5rem"
color={COLORS.white}
/>
</Flex>
)
const buildRunAgainWithSpinnerText = (): JSX.Element => (
<Flex justifyContent={JUSTIFY_SPACE_BETWEEN} width="16rem">
{t('run_again')}
<Icon
Expand Down Expand Up @@ -414,18 +427,21 @@ export function RunSummary(): JSX.Element {
handleReturnToDash(aPipetteWithTip)
}}
buttonText={
isQuickTransfer
? t('return_to_quick_transfer')
: t('return_to_dashboard')
showReturnToSpinner
? buildReturnToWithSpinnerText()
: buildReturnToCopy()
}
css={showReturnToSpinner ? RETURN_TO_CLICKED_STYLE : undefined}
/>
<EqualWidthButton
iconName="play-round-corners"
onClick={() => {
handleRunAgain(aPipetteWithTip)
}}
buttonText={
showRunAgainSpinner ? RUN_AGAIN_SPINNER_TEXT : t('run_again')
showRunAgainSpinner
? buildRunAgainWithSpinnerText()
: t('run_again')
}
css={showRunAgainSpinner ? RUN_AGAIN_CLICKED_STYLE : undefined}
/>
Expand Down Expand Up @@ -517,6 +533,22 @@ const DURATION_TEXT_STYLE = css`
font-weight: ${TYPOGRAPHY.fontWeightRegular};
`

const RETURN_TO_CLICKED_STYLE = css`
background-color: ${COLORS.blue40};
&:focus {
background-color: ${COLORS.blue40};
}
&:hover {
background-color: ${COLORS.blue40};
}
&:focus-visible {
background-color: ${COLORS.blue40};
}
&:active {
background-color: ${COLORS.blue40};
}
`

const RUN_AGAIN_CLICKED_STYLE = css`
background-color: ${COLORS.blue60};
&:focus {
Expand Down
2 changes: 2 additions & 0 deletions robot-server/robot_server/runs/run_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ async def update(self, run_id: str, current: Optional[bool]) -> Union[Run, BadRu
parameters = self._run_orchestrator_store.get_run_time_parameters()
run_resource = self._run_store.get(run_id=run_id)

await self._runs_publisher.publish_runs_advise_refetch_async(run_id)

return _build_run(
run_resource=run_resource,
state_summary=state_summary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,22 @@ async def start_publishing_for_run(
)
self._engine_state_slice = _EngineStateSlice()

await self._publish_runs_advise_refetch_async(run_id=run_id)
await self.publish_runs_advise_refetch_async(run_id=run_id)

async def clean_up_run(self, run_id: str) -> None:
"""Publish final refetch and unsubscribe flags for the given run."""
await self._publish_runs_advise_refetch_async(run_id=run_id)
await self.publish_runs_advise_refetch_async(run_id=run_id)
await self._publish_runs_advise_unsubscribe_async(run_id=run_id)

async def publish_runs_advise_refetch_async(self, run_id: str) -> None:
"""Publish a refetch flag for relevant runs topics."""
await self._client.publish_advise_refetch_async(topic=topics.RUNS)

if self._run_hooks is not None:
await self._client.publish_advise_refetch_async(
topic=topics.TopicName(f"{topics.RUNS}/{run_id}")
)

async def _publish_command_links(self) -> None:
"""Publish an update to the run's command links.

Expand All @@ -92,15 +101,6 @@ async def _publish_command_links(self) -> None:
topic=topics.RUNS_COMMANDS_LINKS
)

async def _publish_runs_advise_refetch_async(self, run_id: str) -> None:
"""Publish a refetch flag for relevant runs topics."""
await self._client.publish_advise_refetch_async(topic=topics.RUNS)

if self._run_hooks is not None:
await self._client.publish_advise_refetch_async(
topic=topics.TopicName(f"{topics.RUNS}/{run_id}")
)

async def _publish_runs_advise_unsubscribe_async(self, run_id: str) -> None:
"""Publish an unsubscribe flag for relevant runs topics."""
if self._run_hooks is not None:
Expand Down Expand Up @@ -161,7 +161,7 @@ async def _handle_engine_status_change(self) -> None:
and self._engine_state_slice.state_summary_status
!= new_state_summary.status
):
await self._publish_runs_advise_refetch_async(
await self.publish_runs_advise_refetch_async(
run_id=self._run_hooks.run_id
)
self._engine_state_slice.state_summary_status = new_state_summary.status
Expand Down
4 changes: 4 additions & 0 deletions robot-server/tests/runs/test_run_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@ async def test_update_current(
await mock_runs_publisher.publish_pre_serialized_commands_notification(run_id),
times=1,
)
decoy.verify(
await mock_runs_publisher.publish_runs_advise_refetch_async(run_id),
times=1,
)
assert result == Run(
current=False,
id=run_resource.run_id,
Expand Down
Loading