From 8b1afb0a168e2edfdcb6a41ab60b281e79d7a1ae Mon Sep 17 00:00:00 2001 From: Mike Cousins Date: Tue, 4 Aug 2020 16:48:12 -0400 Subject: [PATCH] refactor(app): ensure proper API cal data is linked to protocol labware (#6280) --- .../labware/__tests__/selectors.test.js | 74 +++++++++++++++++++ app/src/calibration/labware/selectors.js | 37 ++++++---- 2 files changed, 95 insertions(+), 16 deletions(-) diff --git a/app/src/calibration/labware/__tests__/selectors.test.js b/app/src/calibration/labware/__tests__/selectors.test.js index 70624887cc4..5efb3f1787e 100644 --- a/app/src/calibration/labware/__tests__/selectors.test.js +++ b/app/src/calibration/labware/__tests__/selectors.test.js @@ -133,6 +133,7 @@ describe('labware calibration selectors', () => { it('grabs calibration data for labware if present, rounding to 1 decimal', () => { getModulesBySlot.mockReturnValue({}) + const lwCalibration = Fixtures.mockLabwareCalibration1 const { attributes } = lwCalibration const { calibrationData } = attributes @@ -151,6 +152,7 @@ describe('labware calibration selectors', () => { loadName: wellPlate96Def.parameters.loadName, namespace: wellPlate96Def.namespace, version: wellPlate96Def.version, + parent: '', calibrationData: { ...calibrationData, offset: { @@ -191,6 +193,7 @@ describe('labware calibration selectors', () => { ...lwCalibration, attributes: { ...attributes, + parent: '', loadName: wellPlate96Def.parameters.loadName, namespace: wellPlate96Def.namespace, version: wellPlate96Def.version, @@ -250,6 +253,77 @@ describe('labware calibration selectors', () => { ]) }) + it('grabs calibration data for labware not on module if on-module cal data is present', () => { + const lwCalibration = Fixtures.mockLabwareCalibration1 + const { attributes } = lwCalibration + const { calibrationData } = attributes + + const calNotOnModule = { + ...lwCalibration, + attributes: { + ...attributes, + parent: '', + loadName: wellPlate96Def.parameters.loadName, + namespace: wellPlate96Def.namespace, + version: wellPlate96Def.version, + calibrationData: { + ...calibrationData, + offset: { + ...calibrationData.offset, + value: [1.23, 4.56, 7.89], + }, + }, + }, + } + + const calOnModule = { + ...lwCalibration, + attributes: { + ...attributes, + parent: 'magneticModuleV1', + loadName: wellPlate96Def.parameters.loadName, + namespace: wellPlate96Def.namespace, + version: wellPlate96Def.version, + calibrationData: { + ...calibrationData, + offset: { + ...calibrationData.offset, + value: [0, 0, 0], + }, + }, + }, + } + + getModulesBySlot.mockReturnValue({}) + + state = ({ + calibration: { + robotName: { + calibrationStatus: null, + labwareCalibrations: { + meta: {}, + data: [calOnModule, calNotOnModule], + }, + }, + }, + }: $Shape) + + expect(Selectors.getProtocolLabwareList(state, robotName)).toEqual([ + { + displayName: wellPlate96Def.metadata.displayName, + parentDisplayName: null, + quantity: 1, + calibration: { x: 1.2, y: 4.6, z: 7.9 }, + }, + { + displayName: 'some_v1_labware', + parentDisplayName: null, + quantity: 1, + calibration: null, + }, + ]) + }) + it('flattens out duplicate labware using quantity field', () => { getLabware.mockReturnValue([ ({ diff --git a/app/src/calibration/labware/selectors.js b/app/src/calibration/labware/selectors.js index 28647360546..50ed708bd72 100644 --- a/app/src/calibration/labware/selectors.js +++ b/app/src/calibration/labware/selectors.js @@ -14,7 +14,7 @@ import { selectors as robotSelectors } from '../../robot' import type { LabwareDefinition2, ModuleModel } from '@opentrons/shared-data' import type { State } from '../../types' -import type { LabwareCalibrationModel } from './../types' +import type { LabwareCalibration, LabwareCalibrationModel } from './../types' import type { LabwareSummary } from './types' export const getLabwareCalibrations = ( @@ -70,25 +70,30 @@ export const getProtocolLabwareList: ( const { definition: def, loadName, namespace, version, parent } = lw const displayName = def ? getLabwareDisplayName(def) : loadName const parentDisplayName = parent ? getModuleDisplayName(parent) : null - const matchesLabwareIdentityForQuantity = target => - target.loadName === loadName && - target.namespace === namespace && - target.version === version && - target.parent === parent + const matchesLabwareIdentity = ( + compare: LabwareCalibration | BaseProtocolLabware + ) => { + // target may be an internal protocol labware or API calibration data + // internal protocol labware model uses null for no parent + // API calibration model uses empty string for no parent + // normalize to null to do the comparison + const compareParent = + compare.parent === '' || compare.parent === null + ? null + : compare.parent - const quantity = baseLabwareList.filter(matchesLabwareIdentityForQuantity) - .length + return ( + loadName === compare.loadName && + namespace === compare.namespace && + version === compare.version && + parent === compareParent + ) + } - const matchesLabwareIdentityForCalibration = target => - target.loadName === loadName && - target.namespace === namespace && - target.version === version && - (parent === null || target.parent === parent) + const quantity = baseLabwareList.filter(matchesLabwareIdentity).length const calData = calibrations - .filter(({ attributes }) => - matchesLabwareIdentityForCalibration(attributes) - ) + .filter(({ attributes }) => matchesLabwareIdentity(attributes)) .map(({ attributes }) => { const calVector = attributes.calibrationData.offset.value.map(n => round(n, 1)