Skip to content
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
@@ -1,6 +1,4 @@
import { css } from 'styled-components'
import { useTranslation } from 'react-i18next'
import { getLabwareDisplayName } from '@opentrons/shared-data'
import {
ALIGN_FLEX_START,
Box,
Expand All @@ -17,13 +15,10 @@ import {
LegacyStyledText,
TYPOGRAPHY,
} from '@opentrons/components'
import { LegacyOffsetVector } from '/app/molecules/LegacyOffsetVector'

import type { LabwareDefinition2 } from '@opentrons/shared-data'
import { useLabwareOffsetForLabware } from './useLabwareOffsetForLabware'
interface LabwareInfoProps {
displayName: string | null
definitionDisplayName: string
displayName: string
labwareId: string
runId: string
labwareHasLiquid?: boolean
Expand All @@ -40,9 +35,7 @@ const labwareDisplayNameStyle = css`
-webkit-box-orient: vertical;
`
const LabwareInfo = (props: LabwareInfoProps): JSX.Element | null => {
const { displayName, definitionDisplayName, labwareId, runId, hover } = props
const { t } = useTranslation('protocol_setup')
const vector = useLabwareOffsetForLabware(runId, labwareId)?.vector
const { displayName, labwareId, hover } = props

return (
<Box
Expand All @@ -62,42 +55,31 @@ const LabwareInfo = (props: LabwareInfoProps): JSX.Element | null => {
<LegacyStyledText
as="h6"
css={labwareDisplayNameStyle}
title={definitionDisplayName}
title={displayName}
>
{displayName ?? definitionDisplayName}
{displayName}
</LegacyStyledText>
{props.labwareHasLiquid && (
<Icon name="water" color={COLORS.white} width="0" minWidth="1rem" />
)}
</Flex>
{vector != null && (
<>
<LegacyStyledText
as="h6"
fontWeight={TYPOGRAPHY.fontWeightSemiBold}
textTransform="uppercase"
>
{t('offset_data')}
</LegacyStyledText>
<LegacyOffsetVector {...vector} />
</>
)}
</Box>
)
}

interface LabwareInfoOverlayProps {
definition: LabwareDefinition2
labwareId: string
displayName: string | null
displayName: string
runId: string
hover?: boolean
labwareHasLiquid?: boolean
hover?: boolean
}
export const LabwareInfoOverlay = (
props: LabwareInfoOverlayProps
): JSX.Element => {
const { definition, labwareId, displayName, runId } = props
const { definition, labwareId, displayName, runId, labwareHasLiquid } = props

const width = definition.dimensions.xDimension
const height = definition.dimensions.yDimension
return (
Expand All @@ -113,11 +95,10 @@ export const LabwareInfoOverlay = (
>
<LabwareInfo
displayName={displayName}
definitionDisplayName={getLabwareDisplayName(definition)}
labwareId={labwareId}
runId={runId}
hover={props.hover}
labwareHasLiquid={props.labwareHasLiquid}
labwareHasLiquid={labwareHasLiquid}
/>
</RobotCoordsForeignDiv>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function SetupLabwareMap({
labwareId={topLabwareId}
displayName={topLabwareDisplayName}
runId={runId}
labwareHasLiquid={Object.values(wellFill).length > 0}
/>
) : null}
</g>
Expand Down Expand Up @@ -195,12 +196,13 @@ export function SetupLabwareMap({
setHoverLabwareId(null)
}}
>
{topLabwareDefinition != null ? (
{topLabwareDisplayName != null ? (
<LabwareInfoOverlay
definition={topLabwareDefinition}
labwareId={topLabwareId}
displayName={topLabwareDisplayName ?? null}
displayName={topLabwareDisplayName}
runId={runId}
labwareHasLiquid={Object.values(wellFill).length > 0}
/>
) : null}
</g>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
import { when } from 'vitest-when'
import { screen } from '@testing-library/react'
import { describe, it, beforeEach, vi, afterEach, expect } from 'vitest'
import {
getLabwareDisplayName,
fixtureTiprack300ul,
} from '@opentrons/shared-data'
import { nestedTextMatcher, renderWithProviders } from '/app/__testing-utils__'
import { describe, it, beforeEach, vi, afterEach } from 'vitest'
import { fixtureTiprack300ul } from '@opentrons/shared-data'
import { renderWithProviders } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'
import { useCurrentRun } from '/app/resources/runs'
import { getLabwareLocation } from '/app/transformations/commands'
import { LabwareInfoOverlay } from '../LabwareInfoOverlay'
import { getLabwareDefinitionUri } from '/app/transformations/protocols'
import { useLabwareOffsetForLabware } from '../useLabwareOffsetForLabware'

import type { ComponentProps } from 'react'
import type {
LabwareDefinition2,
ProtocolFile,
LoadedLabware,
} from '@opentrons/shared-data'

vi.mock('/app/resources/runs')
vi.mock('/app/transformations/commands')
vi.mock('../../hooks')
vi.mock('/app/transformations/protocols')
vi.mock('../useLabwareOffsetForLabware')

vi.mock('@opentrons/shared-data', async importOriginal => {
const actual = await importOriginal<typeof getLabwareDisplayName>()
return {
...actual,
getLabwareDisplayName: vi.fn(),
}
})
import type { LabwareDefinition2 } from '@opentrons/shared-data'

const render = (props: ComponentProps<typeof LabwareInfoOverlay>) => {
return renderWithProviders(
Expand All @@ -46,56 +20,17 @@ const render = (props: ComponentProps<typeof LabwareInfoOverlay>) => {
}

const MOCK_LABWARE_ID = 'some_labware_id'
const MOCK_LABWARE_DEFINITION_URI = 'some_labware_definition_uri'
const MOCK_SLOT_NAME = '4'
const MOCK_LABWARE_VECTOR = { x: 1, y: 2, z: 3 }
const MOCK_RUN_ID = 'fake_run_id'

describe('LabwareInfoOverlay', () => {
let props: ComponentProps<typeof LabwareInfoOverlay>
let labware: LoadedLabware[]
let labwareDefinitions: ProtocolFile<{}>['labwareDefinitions']
beforeEach(() => {
props = {
definition: fixtureTiprack300ul as LabwareDefinition2,
displayName: 'fresh tips',
labwareId: MOCK_LABWARE_ID,
runId: MOCK_RUN_ID,
}
labware = [
{
id: MOCK_LABWARE_ID,
definitionUri: MOCK_LABWARE_DEFINITION_URI,
} as LoadedLabware,
]
labwareDefinitions = {
[MOCK_LABWARE_DEFINITION_URI]: fixtureTiprack300ul as LabwareDefinition2,
}
when(vi.mocked(getLabwareDisplayName))
.calledWith(props.definition)
.thenReturn('mock definition display name')

when(vi.mocked(useLabwareOffsetForLabware))
.calledWith(MOCK_RUN_ID, MOCK_LABWARE_ID)
.thenReturn({
id: 'fake_offset_id',
createdAt: 'fake_timestamp',
definitionUri: 'fake_def_uri',
location: { slotName: MOCK_SLOT_NAME },
vector: MOCK_LABWARE_VECTOR,
})

when(vi.mocked(useCurrentRun))
.calledWith()
.thenReturn({} as any)

when(vi.mocked(getLabwareLocation))
.calledWith(MOCK_LABWARE_ID, [])
.thenReturn({ slotName: MOCK_SLOT_NAME })

when(vi.mocked(getLabwareDefinitionUri))
.calledWith(MOCK_LABWARE_ID, labware, labwareDefinitions)
.thenReturn(MOCK_LABWARE_DEFINITION_URI)
})
afterEach(() => {
vi.restoreAllMocks()
Expand All @@ -105,39 +40,4 @@ describe('LabwareInfoOverlay', () => {
render(props)
screen.getByText('fresh tips')
})

it('should render the labware def display name if no user displayName present', () => {
render({
...props,
displayName: null,
})
screen.getByText('mock definition display name')
})

it('should render NOT render the offset data label when offset data does not exist', () => {
render(props)
expect(screen.queryByText('Labware Offsets')).toBeNull()
})

it('should render the offset data when offset data exists', () => {
when(vi.mocked(useCurrentRun))
.calledWith()
.thenReturn({
data: {
labwareOffsets: [
{
id: '1',
definitionUri: MOCK_LABWARE_DEFINITION_URI,
location: { slotName: MOCK_SLOT_NAME },
vector: MOCK_LABWARE_VECTOR,
},
],
},
} as any)
render(props)
screen.getByText('Offset Data')
screen.getByText(nestedTextMatcher('X1.0'))
screen.getByText(nestedTextMatcher('Y2.0'))
screen.getByText(nestedTextMatcher('Z3.0'))
})
})

This file was deleted.

Loading