import isEqual from 'lodash/isEqual' ; import uniqBy from 'lodash/uniqBy' ; import { IDENTITY_VECTOR } from '@opentrons/shared-data' ; import type { LabwareOffset } from '@opentrons/api-client' ; const TRASH_LOCATION = { slotName : '12' } ; export const getLatestLabwareOffsetCount = ( labwareOffsets ) : number => { const orderedLabwareOffsets = labwareOffsets . slice ( ) . sort ( ( a , b ) => new Date ( b . createdAt ) - new Date ( a . createdAt ) ) ; const filteredLabwareOffsets = uniqBy ( orderedLabwareOffsets , ( offset ) => { const location = offset . location ; const definitionUri = offset . definitionUri ; const locationKey = location . moduleModel != null ? `${ location . moduleModel }_${ location . slotName }` : location . slotName ; return `${ definitionUri }_${ locationKey }` ; } ) ; const uniqueOffsetCount = filteredLabwareOffsets . reduce < number > ( ( acc , offset ) => { const vector = offset . vector ; if ( ! isEqual ( location , TRASH_LOCATION ) && ! isEqual ( vector , IDENTITY_VECTOR ) ) { return acc + 1 ; } return acc ; } , 0 ) ; return uniqueOffsetCount ; } ;