-
Notifications
You must be signed in to change notification settings - Fork 179
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(robot-server,app): add download deck calibration button #6453
Merged
+422
−28
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
643921a
feat(robot-server,app): add download deck calibration button
ahiuchingau 98b4464
fix check errors
ahiuchingau 1a69c51
made requested changes
ahiuchingau 19b1f38
fix type checks
ahiuchingau 6309b3d
fix type error
ahiuchingau 121d53a
fix lint error
ahiuchingau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
app/src/components/RobotSettings/DeckCalibrationDownload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import { | ||
Flex, | ||
Text, | ||
SPACING_1, | ||
SPACING_4, | ||
DIRECTION_COLUMN, | ||
} from '@opentrons/components' | ||
import { IconCta } from '../IconCta' | ||
import { saveAs } from 'file-saver' | ||
|
||
import type { | ||
DeckCalibrationData, | ||
DeckCalibrationStatus, | ||
} from '../../calibration/types' | ||
|
||
const LAST_CALIBRATED = 'Last calibrated:' | ||
const DOWNLOAD = 'Download deck calibration data' | ||
|
||
export const DOWNLOAD_NAME = 'download-deck-calibration' | ||
|
||
export type DeckCalibrationDownloadProps = {| | ||
deckCalibrationStatus: DeckCalibrationStatus | null, | ||
deckCalibrationData: DeckCalibrationData | null, | ||
robotName: string, | ||
...styleProps, | ||
|} | ||
|
||
export function DeckCalibrationDownload({ | ||
deckCalibrationData: deckCalData, | ||
deckCalibrationStatus: deckCalStatus, | ||
robotName: name, | ||
...styleProps | ||
}: DeckCalibrationDownloadProps): React.Node { | ||
if (deckCalStatus === null) { | ||
return null | ||
} | ||
|
||
const isAttitude = deckCalData?.type === 'attitude' | ||
const timestamp = deckCalData?.lastModified | ||
? new Date(deckCalData.lastModified).toLocaleString() | ||
: null | ||
|
||
const handleDownloadButtonClick = () => { | ||
const report = isAttitude | ||
? deckCalData | ||
: { | ||
type: deckCalData?.type, | ||
matrix: deckCalData?.matrix, | ||
} | ||
const data = new Blob([JSON.stringify(report)], { | ||
type: 'application/json', | ||
}) | ||
saveAs(data, `${name}-deck-calibration.json`) | ||
} | ||
|
||
return ( | ||
<> | ||
<Flex flexDirection={DIRECTION_COLUMN} {...styleProps}> | ||
{isAttitude && ( | ||
<Flex marginBottom={SPACING_1}> | ||
<Text marginRight={SPACING_4}>{LAST_CALIBRATED}</Text> | ||
<Text>{timestamp}</Text> | ||
</Flex> | ||
)} | ||
<Flex> | ||
<IconCta | ||
iconName="download" | ||
text={DOWNLOAD} | ||
name={DOWNLOAD_NAME} | ||
onClick={handleDownloadButtonClick} | ||
/> | ||
</Flex> | ||
</Flex> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
app/src/components/RobotSettings/__tests__/DeckCalibrationDownload.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import { mount } from 'enzyme' | ||
import { act } from 'react-dom/test-utils' | ||
import { saveAs } from 'file-saver' | ||
|
||
import * as Calibration from '../../../calibration' | ||
import { Text } from '@opentrons/components' | ||
import { DeckCalibrationDownload } from '../DeckCalibrationDownload' | ||
|
||
jest.mock('file-saver') | ||
|
||
const mockSaveAs: JestMockFn< | ||
[Blob, string], | ||
$Call<typeof saveAs, Blob, string> | ||
> = saveAs | ||
|
||
describe('Calibration Download Component', () => { | ||
let render | ||
|
||
const getDownloadButton = wrapper => wrapper.find('button') | ||
|
||
const getLastModifedText = wrapper => | ||
wrapper.find(Text).filter({ children: 'Last calibrated:' }) | ||
|
||
beforeEach(() => { | ||
render = (props = {}) => { | ||
const { | ||
calData = { | ||
type: 'attitude', | ||
matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], | ||
lastModified: '2020-08-25T14:14:30.422070+00:00', | ||
pipetteCalibratedWith: 'P20MV202020042206', | ||
tiprack: 'somehash', | ||
}, | ||
calStatus = Calibration.DECK_CAL_STATUS_OK, | ||
name = 'opentrons', | ||
} = props | ||
return mount( | ||
<DeckCalibrationDownload | ||
deckCalibrationData={calData} | ||
deckCalibrationStatus={calStatus} | ||
robotName={name} | ||
/> | ||
) | ||
} | ||
}) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('renders when deck calibration status is ok', () => { | ||
const wrapper = render() | ||
expect(wrapper.exists()).toEqual(true) | ||
}) | ||
|
||
it('renders when deck calibration status is IDENTITY', () => { | ||
const wrapper = render({ | ||
deckCalibrationStatus: Calibration.DECK_CAL_STATUS_IDENTITY, | ||
}) | ||
expect(wrapper.exists()).toEqual(true) | ||
}) | ||
|
||
it('renders when deck calibration status is SINGULARITY', () => { | ||
const wrapper = render({ | ||
deckCalibrationStatus: Calibration.DECK_CAL_STATUS_SINGULARITY, | ||
}) | ||
expect(wrapper.exists()).toEqual(true) | ||
}) | ||
|
||
it('renders when deck calibration status is BAD_CALIBRATION', () => { | ||
const wrapper = render({ | ||
deckCalibrationStatus: Calibration.DECK_CAL_STATUS_BAD_CALIBRATION, | ||
}) | ||
expect(wrapper.exists()).toEqual(true) | ||
}) | ||
|
||
it('renders nothing when deck calibration status is unknown', () => { | ||
const wrapper = render({ deckCalibrationStatus: null }) | ||
expect(wrapper).toEqual({}) | ||
}) | ||
|
||
it('saves the deck calibration data when the button is clicked', () => { | ||
const wrapper = render() | ||
|
||
act(() => getDownloadButton(wrapper).invoke('onClick')()) | ||
wrapper.update() | ||
expect(mockSaveAs).toHaveBeenCalled() | ||
}) | ||
|
||
it('renders last modified when deck calibration type is attitude', () => { | ||
const wrapper = render() | ||
|
||
expect(getLastModifedText(wrapper).exists()).toEqual(true) | ||
}) | ||
|
||
it('should not render last modified when deck calibration type is affine', () => { | ||
const wrapper = render({ | ||
deckCalibrationData: { | ||
type: 'random', | ||
matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], | ||
lastModified: null, | ||
pipetteCalibratedWith: null, | ||
tiprack: null, | ||
}, | ||
}) | ||
|
||
expect(getLastModifedText(wrapper)).toEqual({}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to keep the app compatible with the last version of the robot as well as the current one, we should probably handle it here. I think the general use of null coalescence makes it work, but maybe add a test based on the robot returning the old style of the affine matrix directly in
data
?