Skip to content

Commit

Permalink
feat(app): add module calibration data to download (#13511)
Browse files Browse the repository at this point in the history
* feat(app): add module calibration data to downloaded calibrationd ata

We need to add module calibration data to calibration data download from the robot settings page.
(for Flex only)

* update tests
  • Loading branch information
ncdiehl11 authored Sep 12, 2023
1 parent 4f87ee2 commit d0edba9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
TYPOGRAPHY,
DIRECTION_COLUMN,
} from '@opentrons/components'
import { useInstrumentsQuery } from '@opentrons/react-api-client'
import {
useInstrumentsQuery,
useModulesQuery,
} from '@opentrons/react-api-client'
import { TertiaryButton } from '../../atoms/buttons'
import { StyledText } from '../../atoms/text'
import {
Expand Down Expand Up @@ -55,21 +58,15 @@ export function CalibrationDataDownload({
const pipetteOffsetCalibrations = usePipetteOffsetCalibrations()
const tipLengthCalibrations = useTipLengthCalibrations()
const { data: attachedInstruments } = useInstrumentsQuery({ enabled: isOT3 })
const { data: attachedModules } = useModulesQuery({ enabled: isOT3 })

const downloadIsPossible =
const ot2DownloadIsPossible =
deckCalibrationData.isDeckCalibrated &&
pipetteOffsetCalibrations != null &&
pipetteOffsetCalibrations.length > 0 &&
tipLengthCalibrations != null &&
tipLengthCalibrations.length > 0

const ot3DownloadIsPossible =
isOT3 &&
attachedInstruments?.data.some(
instrument =>
instrument.ok && instrument.data.calibratedOffset?.last_modified != null
)

const onClickSaveAs: React.MouseEventHandler = e => {
e.preventDefault()
doTrackEvent({
Expand All @@ -81,6 +78,7 @@ export function CalibrationDataDownload({
isOT3
? JSON.stringify({
instrumentData: attachedInstruments,
moduleData: attachedModules,
})
: JSON.stringify({
deck: deckCalibrationData,
Expand Down Expand Up @@ -124,7 +122,7 @@ export function CalibrationDataDownload({
) : (
<StyledText as="p">
{t(
downloadIsPossible
ot2DownloadIsPossible
? 'robot_calibration:download_calibration_data_available'
: 'robot_calibration:download_calibration_data_unavailable'
)}
Expand All @@ -133,7 +131,7 @@ export function CalibrationDataDownload({
</Flex>
<TertiaryButton
onClick={onClickSaveAs}
disabled={isOT3 ? !ot3DownloadIsPossible : !downloadIsPossible}
disabled={isOT3 ? false : !ot2DownloadIsPossible} // always enable download on Flex
>
<Flex alignItems={ALIGN_CENTER}>
<Icon name="download" size="0.75rem" marginRight={SPACING.spacing8} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { saveAs } from 'file-saver'
import { when, resetAllWhenMocks } from 'jest-when'

import { renderWithProviders } from '@opentrons/components'
import { useInstrumentsQuery } from '@opentrons/react-api-client'
import {
useInstrumentsQuery,
useModulesQuery,
} from '@opentrons/react-api-client'
import { instrumentsResponseFixture } from '@opentrons/api-client'

import { i18n } from '../../../i18n'
Expand Down Expand Up @@ -55,6 +58,9 @@ const mockUseIsOT3 = useIsOT3 as jest.MockedFunction<typeof useIsOT3>
const mockUseInstrumentsQuery = useInstrumentsQuery as jest.MockedFunction<
typeof useInstrumentsQuery
>
const mockUseModulesQuery = useModulesQuery as jest.MockedFunction<
typeof useModulesQuery
>

let mockTrackEvent: jest.Mock
const mockSetShowHowCalibrationWorksModal = jest.fn()
Expand Down Expand Up @@ -113,6 +119,9 @@ describe('CalibrationDataDownload', () => {
mockUseInstrumentsQuery.mockReturnValue({
data: { data: [] },
} as any)
mockUseModulesQuery.mockReturnValue({
data: { data: [] },
} as any)
})

afterEach(() => {
Expand Down Expand Up @@ -221,7 +230,7 @@ describe('CalibrationDataDownload', () => {
const downloadButton = getByRole('button', {
name: 'Download calibration data',
})
expect(downloadButton).toBeDisabled()
expect(downloadButton).toBeEnabled() // allow download for empty cal data
})

it('renders disabled button when tip lengths are not calibrated', () => {
Expand Down

0 comments on commit d0edba9

Please sign in to comment.