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(app): fix tooltip behavior for disabled Restore default value on RTP slideout #15071

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,28 @@ describe('ChooseProtocolSlideout', () => {
screen.getByText('Restore default values')
})

it('shows tooltip when disabled Restore default values link is clicked', () => {
const protocolDataWithoutRunTimeParameter = {
...storedProtocolDataFixture,
}
vi.mocked(getStoredProtocols).mockReturnValue([
protocolDataWithoutRunTimeParameter,
])

render({
robot: mockConnectableRobot,
onCloseClick: vi.fn(),
showSlideout: true,
})
const proceedButton = screen.getByRole('button', {
name: 'Continue to parameters',
})
fireEvent.click(proceedButton)
const restoreValuesLink = screen.getByText('Restore default values')
fireEvent.click(restoreValuesLink)
screen.getByText('No custom values specified')
})

// ToDo (kk:04/18/2024) I will update test for RTP
/*
it('renders error state when there is a run creation error', () => {
Expand Down
41 changes: 33 additions & 8 deletions app/src/organisms/ChooseProtocolSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
SecondaryButton,
StyledText,
TYPOGRAPHY,
useHoverTooltip,
useTooltip,
} from '@opentrons/components'
import { ApiHostProvider } from '@opentrons/react-api-client'

Expand Down Expand Up @@ -63,6 +63,8 @@ export const CARD_OUTLINE_BORDER_STYLE = css`
}
`

const TOOLTIP_DELAY_MS = 2000

const _getFileBaseName = (filePath: string): string => {
return filePath.split('/').reverse()[0]
}
Expand All @@ -78,7 +80,11 @@ export function ChooseProtocolSlideoutComponent(
const { t } = useTranslation(['device_details', 'shared'])
const history = useHistory()
const logger = useLogger(new URL('', import.meta.url).pathname)
const [targetProps, tooltipProps] = useHoverTooltip()
const [targetProps, tooltipProps] = useTooltip()
const [
showRestoreValuesTooltip,
setShowRestoreValuesTooltip,
] = React.useState<boolean>(false)

const { robot, showSlideout, onCloseClick } = props
const { name } = robot
Expand Down Expand Up @@ -351,16 +357,35 @@ export function ChooseProtocolSlideoutComponent(
css={
isRestoreDefaultsLinkEnabled ? ENABLED_LINK_CSS : DISABLED_LINK_CSS
}
onClick={resetRunTimeParameters}
onClick={() => {
if (isRestoreDefaultsLinkEnabled) {
resetRunTimeParameters?.()
} else {
setShowRestoreValuesTooltip(true)
setTimeout(
() => setShowRestoreValuesTooltip(false),
TOOLTIP_DELAY_MS
)
}
}}
paddingBottom={SPACING.spacing10}
{...targetProps}
>
{t('protocol_details:restore_defaults')}
</LinkComponent>
{!isRestoreDefaultsLinkEnabled && (
<Tooltip tooltipProps={tooltipProps}>
{t('protocol_details:no_custom_values')}
</Tooltip>
)}
<Tooltip
tooltipProps={{
...tooltipProps,
visible: showRestoreValuesTooltip,
}}
css={css`
&:hover {
cursor: auto;
}
`}
>
{t('protocol_details:no_custom_values')}
</Tooltip>{' '}
</Flex>
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing16}>
{runTimeParametersInputs}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,22 @@ describe('ChooseRobotSlideout', () => {
})
expect(mockSetSelectedRobot).toBeCalledWith(null)
})

it('shows tooltip when disabled Restore default values link is clicked', () => {
render({
onCloseClick: vi.fn(),
isExpanded: true,
isSelectedRobotOnDifferentSoftwareVersion: false,
selectedRobot: null,
setSelectedRobot: mockSetSelectedRobot,
title: 'choose robot slideout title',
robotType: OT2_ROBOT_TYPE,
multiSlideout: { currentPage: 2 },
runTimeParametersOverrides: mockRunTimeParameters,
})

const restoreValuesLink = screen.getByText('Restore default values')
fireEvent.click(restoreValuesLink)
screen.getByText('No custom values specified')
})
})
41 changes: 33 additions & 8 deletions app/src/organisms/ChooseRobotSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
SPACING,
StyledText,
TYPOGRAPHY,
useHoverTooltip,
useTooltip,
} from '@opentrons/components'

import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE } from '@opentrons/shared-data'
Expand Down Expand Up @@ -63,6 +63,8 @@ export const CARD_OUTLINE_BORDER_STYLE = css`
}
`

const TOOLTIP_DELAY_MS = 2000

interface RobotIsBusyAction {
type: 'robotIsBusy'
robotName: string
Expand Down Expand Up @@ -145,7 +147,11 @@ export function ChooseRobotSlideout(

const dispatch = useDispatch<Dispatch>()
const isScanning = useSelector((state: State) => getScanning(state))
const [targetProps, tooltipProps] = useHoverTooltip()
const [targetProps, tooltipProps] = useTooltip()
const [
showRestoreValuesTooltip,
setShowRestoreValuesTooltip,
] = React.useState<boolean>(false)
const [isInputFocused, setIsInputFocused] = React.useState<boolean>(false)

const unhealthyReachableRobots = useSelector((state: State) =>
Expand Down Expand Up @@ -512,16 +518,35 @@ export function ChooseRobotSlideout(
? ENABLED_LINK_CSS
: DISABLED_LINK_CSS
}
onClick={() => resetRunTimeParameters?.()}
onClick={() => {
if (isRestoreDefaultsLinkEnabled) {
resetRunTimeParameters?.()
} else {
setShowRestoreValuesTooltip(true)
setTimeout(
() => setShowRestoreValuesTooltip(false),
TOOLTIP_DELAY_MS
)
}
}}
paddingBottom={SPACING.spacing10}
{...targetProps}
>
{t('restore_defaults')}
</Link>
{!isRestoreDefaultsLinkEnabled && (
<Tooltip tooltipProps={tooltipProps}>
{t('no_custom_values')}
</Tooltip>
)}
<Tooltip
tooltipProps={{
...tooltipProps,
visible: showRestoreValuesTooltip,
}}
css={css`
&:hover {
cursor: auto;
}
`}
>
{t('no_custom_values')}
</Tooltip>
</Flex>
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing16}>
{runTimeParameters}
Expand Down
Loading