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

feat(app): add module calibration data to download #13511

Merged
merged 2 commits into from
Sep 12, 2023
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 @@ -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