Skip to content

Commit

Permalink
refactor(app): update factory reset slideout for OT-3 (#11683)
Browse files Browse the repository at this point in the history
localizes factory reset options and updates for ot-3

closes RCORE-229
  • Loading branch information
brenthagen committed Nov 7, 2022
1 parent 2434df9 commit 934c322
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 27 deletions.
11 changes: 9 additions & 2 deletions app/src/assets/localization/en/device_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
"choose_reset_settings": "Choose reset settings",
"choose": "Choose...",
"clear_data_and_restart_robot": "Clear data and restart robot",
"clear_option_boot_scripts": "Clear custom boot scripts",
"clear_option_deck_calibration": "Clear deck calibration",
"clear_option_gripper_calibration": "Clear gripper calibration",
"clear_option_pipette_calibrations": "Clear pipette calibration(s)",
"clear_option_pipette_offset_calibrations": "Clear pipette offset calibrations",
"clear_option_runs_history": "Clear protocol run history",
"clear_option_tip_length_calibrations": "Clear tip length calibrations",
"connect_to_wifi_network": "Connect to Wi-Fi network",
"connection_lost_description": "The Opentrons App is unable to communicate with this robot right now. Double check the USB or Wifi connection to the robot, then try to reconnect.",
"connection_to_robot_lost": "Connection to robot lost",
Expand All @@ -45,7 +52,7 @@
"factory_reset_slideout_description": "Select the robot data to clear.",
"factory_reset_slideout_title": "Factory Reset",
"factory_reset": "Factory reset",
"factory_resets_cannot_be_undone": "Factory resets cannot be undone",
"factory_resets_cannot_be_undone": "Factory resets cannot be undone.",
"feature_flags": "Feature Flags",
"firmware_version": "Firmware Version",
"fully_calibrate_before_checking_health": "Fully calibrate your robot before checking calibration health",
Expand Down Expand Up @@ -91,7 +98,7 @@
"rename_robot": "Rename robot",
"requires_restarting_the_robot": "Updating the robot’s software requires restarting the robot",
"reset_to_factory_settings": "Reset to factory settings?",
"robot_calibration_data": "Robot calibration data",
"robot_calibration_data": "Robot Calibration Data",
"robot_name_already_exists": "Robot name already exists",
"robot_name": "Robot Name",
"robot_rename_button": "Rename robot",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { useTranslation } from 'react-i18next'
import snakeCase from 'lodash/snakeCase'

import {
Flex,
Expand Down Expand Up @@ -31,6 +32,7 @@ import { useTrackEvent } from '../../../../../redux/analytics'
import { EVENT_CALIBRATION_DOWNLOADED } from '../../../../../redux/calibration'
import {
useDeckCalibrationData,
useIsOT3,
usePipetteOffsetCalibrations,
useTipLengthCalibrations,
useRobot,
Expand Down Expand Up @@ -59,6 +61,7 @@ export function FactoryResetSlideout({
const dispatch = useDispatch<Dispatch>()
const [resetOptions, setResetOptions] = React.useState<ResetConfigRequest>({})
const runsQueryResponse = useAllRunsQuery()
const isOT3 = useIsOT3(robotName)

// Calibration data
const deckCalibrationData = useDeckCalibrationData(robotName)
Expand All @@ -68,8 +71,23 @@ export function FactoryResetSlideout({
getResetConfigOptions(state, robotName)
)

const calibrationOptions =
const ot2CalibrationOptions =
// TODO(bh, 2022-11-07): update OT-2 filter when gripper calibration reset config option available
options != null ? options.filter(opt => opt.id.includes('Calibration')) : []
const ot3CalibrationOptions =
options != null
? options.filter(
opt =>
opt.id === 'pipetteOffsetCalibrations' ||
// TODO(bh, 2022-11-07): confirm or update when gripper calibration reset config option available
opt.id === 'gripperCalibration'
)
: []

const calibrationOptions = isOT3
? ot3CalibrationOptions
: ot2CalibrationOptions

const bootScriptOption =
options != null ? options.filter(opt => opt.id.includes('bootScript')) : []
const runHistoryOption =
Expand Down Expand Up @@ -161,22 +179,46 @@ export function FactoryResetSlideout({
{t('download')}
</Link>
</Flex>
<StyledText as="p" marginBottom={SPACING.spacing3}>
{t('calibration_description')}
</StyledText>
{calibrationOptions.map(opt => (
{isOT3 ? null : (
<StyledText as="p" marginBottom={SPACING.spacing3}>
{t('calibration_description')}
</StyledText>
)}
{calibrationOptions.map(opt => {
const calibrationName =
isOT3 && opt.id === 'pipetteOffsetCalibrations'
? t('clear_option_pipette_calibrations')
: t(`clear_option_${snakeCase(opt.id)}`)
return (
<CheckboxField
key={opt.id}
onChange={() =>
setResetOptions({
...resetOptions,
[opt.id]: !(resetOptions[opt.id] ?? false),
})
}
value={resetOptions[opt.id]}
label={calibrationName}
/>
)
})}
{/* TODO(bh, 2022-11-02): placeholder, remove when gripper calibration reset config option available */}
{isOT3 ? (
<CheckboxField
key={opt.id}
key="gripperCalibration"
onChange={() =>
setResetOptions({
...resetOptions,
[opt.id]: !(resetOptions[opt.id] ?? false),
gripperCalibration: !(
resetOptions.gripperCalibration ?? false
),
})
}
value={resetOptions[opt.id]}
label={`Clear ${opt.name}`}
value={resetOptions.gripperCalibration}
label={t('clear_option_gripper_calibration')}
/>
))}
) : null}
</Box>
<Box marginTop={SPACING.spacing5}>
<Flex
Expand Down Expand Up @@ -208,7 +250,7 @@ export function FactoryResetSlideout({
})
}
value={resetOptions[opt.id]}
label={`${opt.name}`}
label={t(`clear_option_${snakeCase(opt.id)}`)}
/>
))}
</Box>
Expand All @@ -230,7 +272,7 @@ export function FactoryResetSlideout({
})
}
value={resetOptions[opt.id]}
label={`Clear ${opt.name}`}
label={t(`clear_option_${snakeCase(opt.id)}`)}
/>
))}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fireEvent } from '@testing-library/react'
import { renderWithProviders } from '@opentrons/components'
import { i18n } from '../../../../../../i18n'
import { getResetConfigOptions } from '../../../../../../redux/robot-admin'
import { useIsOT3 } from '../../../../hooks'
import { FactoryResetSlideout } from '../FactoryResetSlideout'

jest.mock('../../../../../../redux/config')
Expand All @@ -18,23 +19,34 @@ const mockUpdateResetStatus = jest.fn()
const mockGetResetConfigOptions = getResetConfigOptions as jest.MockedFunction<
typeof getResetConfigOptions
>
const mockUseIsOT3 = useIsOT3 as jest.MockedFunction<typeof useIsOT3>

const mockResetConfigOptions = [
{
id: 'bootScriptFoo',
id: 'bootScripts',
name: 'BootScript Foo',
description: 'BootScript foo description',
},
{
id: 'CalibrationBar',
name: 'Calibration Bar',
description: 'Calibration bar description',
id: 'deckCalibration',
name: 'deck Calibration Bar',
description: 'deck Calibration bar description',
},
{
id: 'runsHistoryFooBar',
id: 'pipetteOffsetCalibrations',
name: 'pipette calibration FooBar',
description: 'pipette calibration fooBar description',
},
{
id: 'runsHistory',
name: 'RunsHistory FooBar',
description: 'runsHistory fooBar description',
},
{
id: 'tipLengthCalibrations',
name: 'tip length FooBar',
description: 'tip length fooBar description',
},
]

const render = () => {
Expand All @@ -54,6 +66,7 @@ const render = () => {
describe('RobotSettings FactoryResetSlideout', () => {
beforeEach(() => {
mockGetResetConfigOptions.mockReturnValue(mockResetConfigOptions)
mockUseIsOT3.mockReturnValue(false)
})

afterEach(() => {
Expand All @@ -64,27 +77,56 @@ describe('RobotSettings FactoryResetSlideout', () => {
const [{ getByText, getByRole, getAllByText, getByTestId }] = render()
getByText('Factory Reset')
getByText('Select the robot data to clear.')
getByText('Factory resets cannot be undone')
getByText('Robot calibration data')
getByText('Factory resets cannot be undone.')
getByText('Robot Calibration Data')
getByText(
'Resetting Deck and/or Tip Length Calibration data will also clear Pipette Offset Calibration data.'
)
getByText('Clear deck calibration')
getByText('Clear pipette offset calibrations')
getByText('Clear tip length calibrations')
getByText('Protocol Run History')
getByText('Resetting run history will also clear Labware Offset data.')
getByText('Clear BootScript Foo')
getByText('Clear Calibration Bar')
getByText('RunsHistory FooBar')
getByText('Clear protocol run history')
getByText('Boot Scripts')
getByText('Clear custom boot scripts')
const downloads = getAllByText('Download')
expect(downloads.length).toBe(2)
getByRole('checkbox', { name: 'Clear Calibration Bar' })
getByRole('checkbox', { name: 'Clear BootScript Foo' })
getByRole('checkbox', { name: 'Clear deck calibration' })
getByRole('checkbox', { name: 'Clear pipette offset calibrations' })
getByRole('checkbox', { name: 'Clear tip length calibrations' })
getByRole('checkbox', { name: 'Clear protocol run history' })
getByRole('checkbox', { name: 'Clear custom boot scripts' })
getByRole('button', { name: 'Clear data and restart robot' })
getByTestId('Slideout_icon_close_Factory Reset')
})

it('should change some options and text for the OT-3', () => {
mockUseIsOT3.mockReturnValue(true)
const [{ getByText, getByRole, queryByRole, queryByText }] = render()

expect(
queryByText(
'Resetting Deck and/or Tip Length Calibration data will also clear Pipette Offset Calibration data.'
)
).toBeNull()
expect(queryByText('Clear deck calibration')).toBeNull()
getByText('Clear pipette calibration(s)')
expect(queryByText('Clear tip length calibrations')).toBeNull()
getByText('Clear gripper calibration')
getByRole('checkbox', { name: 'Clear pipette calibration(s)' })
getByRole('checkbox', { name: 'Clear gripper calibration' })
expect(
queryByRole('checkbox', { name: 'Clear deck calibration' })
).toBeNull()
expect(
queryByRole('checkbox', { name: 'Clear tip length calibrations' })
).toBeNull()
})

it('should enable Clear data and restart robot button when checked one checkbox', () => {
const [{ getByRole }] = render()
const checkbox = getByRole('checkbox', { name: 'Clear Calibration Bar' })
const checkbox = getByRole('checkbox', { name: 'Clear deck calibration' })
fireEvent.click(checkbox)
const clearButton = getByRole('button', {
name: 'Clear data and restart robot',
Expand Down

0 comments on commit 934c322

Please sign in to comment.