Skip to content

Commit

Permalink
fix(app,components): fix module controls no module connected case
Browse files Browse the repository at this point in the history
Connect modules to see controls doesn't align with the design. This PR fixes. The component is the
same as NoParameters component so I rename and add a new prop to use only one component.

close AUTH-264
  • Loading branch information
koji committed Apr 2, 2024
1 parent 5efb48d commit 53f5913
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { useInstrumentsQuery } from '@opentrons/react-api-client'
import {
COLORS,
DIRECTION_COLUMN,
Flex,
JUSTIFY_CENTER,
ProtocolRunEmptyState,
SPACING,
StyledText,
} from '@opentrons/components'
import { ModuleCard } from '../../ModuleCard'
import { useModuleRenderInfoForProtocolById } from '../hooks'
Expand Down Expand Up @@ -73,8 +72,6 @@ export const ProtocolRunModuleControls = ({
robotName,
runId,
}: ProtocolRunModuleControlsProps): JSX.Element => {
const { t } = useTranslation('protocol_details')

const {
attachPipetteRequired,
calibratePipetteRequired,
Expand All @@ -97,18 +94,15 @@ export const ProtocolRunModuleControls = ({
const rightColumnModules = attachedModules?.slice(halfAttachedModulesSize)

return attachedModules.length === 0 ? (
<Flex justifyContent={JUSTIFY_CENTER}>
<StyledText as="p" color={COLORS.grey50} marginY={SPACING.spacing16}>
{t('connect_modules_to_see_controls')}
</StyledText>
</Flex>
) : (
<Flex
gridGap={SPACING.spacing8}
paddingTop={SPACING.spacing16}
paddingBottom={SPACING.spacing8}
paddingX={SPACING.spacing16}
justifyContent={JUSTIFY_CENTER}
padding={SPACING.spacing16}
backgroundColor={COLORS.white}
>
<ProtocolRunEmptyState contentType="moduleControls" />
</Flex>
) : (
<Flex gridGap={SPACING.spacing8} padding={SPACING.spacing16}>
<Flex
flexDirection={DIRECTION_COLUMN}
flex="50%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SPACING,
StyledText,
TYPOGRAPHY,
NoParameters,
ProtocolRunEmptyState,
useHoverTooltip,
Icon,
} from '@opentrons/components'
Expand Down Expand Up @@ -78,7 +78,7 @@ export function ProtocolRunRuntimeParameters({
</Flex>
{!hasParameter ? (
<Flex padding={SPACING.spacing16}>
<NoParameters />
<ProtocolRunEmptyState />
</Flex>
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, vi, beforeEach, afterEach, expect } from 'vitest'
import { screen } from '@testing-library/react'
import { when } from 'vitest-when'

import { NoParameters } from '@opentrons/components'
import { ProtocolRunEmptyState } from '@opentrons/components'
import { renderWithProviders } from '../../../../__testing-utils__'
import { i18n } from '../../../../i18n'
import { useMostRecentCompletedAnalysis } from '../../../LabwarePositionCheck/useMostRecentCompletedAnalysis'
Expand All @@ -16,7 +16,7 @@ import type {
} from '@opentrons/shared-data'

vi.mock('@opentrons/components', async importOriginal => {
const actual = await importOriginal<typeof NoParameters>()
const actual = await importOriginal<typeof ProtocolRunEmptyState>()
return {
...actual,
NoParameters: vi.fn(),
Expand Down Expand Up @@ -94,7 +94,9 @@ describe('ProtocolRunRuntimeParameters', () => {
props = {
runId: RUN_ID,
}
vi.mocked(NoParameters).mockReturnValue(<div>mock NoParameter</div>)
vi.mocked(ProtocolRunEmptyState).mockReturnValue(
<div>mock ProtocolRunEmptyState</div>
)
when(vi.mocked(useMostRecentCompletedAnalysis))
.calledWith(RUN_ID)
.thenReturn({
Expand Down Expand Up @@ -151,7 +153,7 @@ describe('ProtocolRunRuntimeParameters', () => {
screen.getByText('No offsets')
})

it('should render mock NoParameter component when RunTimeParameters are empty', () => {
it('should render mock ProtocolRunEmptyState component when RunTimeParameters are empty', () => {
when(vi.mocked(useMostRecentCompletedAnalysis))
.calledWith(RUN_ID)
.thenReturn({
Expand All @@ -160,7 +162,7 @@ describe('ProtocolRunRuntimeParameters', () => {
render(props)
screen.getByText('Parameters')
expect(screen.queryByText('Default values')).not.toBeInTheDocument()
screen.getByText('mock NoParameter')
screen.getByText('mock ProtocolRunEmptyState')
})

// ToDo Additional test will be implemented when chip component is added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { useTranslation } from 'react-i18next'
import {
DIRECTION_COLUMN,
Flex,
ParametersTable,
ProtocolRunEmptyState,
SPACING,
StyledText,
TYPOGRAPHY,
ParametersTable,
NoParameters,
} from '@opentrons/components'
import { Banner } from '../../../atoms/Banner'

Expand Down Expand Up @@ -48,7 +48,7 @@ export function ProtocolParameters({
<ParametersTable runTimeParameters={runTimeParameters} t={t} />
</Flex>
) : (
<NoParameters />
<ProtocolRunEmptyState />
)}
</Flex>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ import { Icon } from '../../icons'
import { Flex } from '../../primitives'
import { ALIGN_CENTER, DIRECTION_COLUMN } from '../../styles'

export function NoParameters(): JSX.Element {
interface ProtocolRunEmptyStateProps {
contentType?: 'parameters' | 'moduleControls'
}

export function ProtocolRunEmptyState({
contentType = 'parameters',
}: ProtocolRunEmptyStateProps): JSX.Element {
const bodyText =
contentType === 'parameters'
? 'No parameters specified in this protocol'
: 'Connect modules to see controls'
return (
<Flex
alignItems={ALIGN_CENTER}
Expand All @@ -26,7 +36,7 @@ export function NoParameters(): JSX.Element {
aria-label="alert"
/>
<StyledText as="p" fontWeight={TYPOGRAPHY.fontWeightSemiBold}>
No parameters specified in this protocol
{bodyText}
</StyledText>
</Flex>
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react'
import { screen } from '@testing-library/react'
import { describe, it, expect, beforeEach } from 'vitest'

import { renderWithProviders } from '../../../testing/utils'
import { BORDERS, COLORS } from '../../../helix-design-system'
import { ProtocolRunEmptyState } from '../ProtocolRunEmptyState'

const render = (props: React.ComponentProps<typeof ProtocolRunEmptyState>) => {
return renderWithProviders(<ProtocolRunEmptyState {...props} />)
}

describe('NoParameters', () => {
let props: React.ComponentProps<typeof ProtocolRunEmptyState>

beforeEach(() => {
props = {
contentType: 'parameters',
}
})
it('should render text and icon with proper color - parameters', () => {
render(props)
screen.getByLabelText('alert')
screen.getByText('No parameters specified in this protocol')
})

it('should render text and icon with proper color - module controls', () => {
props = {
contentType: 'moduleControls',
}
render(props)
screen.getByLabelText('alert')
screen.getByText('Connect modules to see controls')
})

it('should have proper styles', () => {
render(props)
expect(screen.getByTestId('NoRunTimeParameter')).toHaveStyle(
`background-color: ${COLORS.grey30}`
)
expect(screen.getByTestId('NoRunTimeParameter')).toHaveStyle(
`border-radius: ${BORDERS.borderRadius8}`
)
expect(screen.getByLabelText('alert')).toHaveStyle(
`color: ${COLORS.grey60}`
)
})
})
2 changes: 1 addition & 1 deletion components/src/molecules/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './LocationIcon'
export * from './RoundTab'
export * from './ParametersTable'
export * from './ParametersTable/NoParameters'
export * from './ParametersTable/ProtocolRunEmptyState'

0 comments on commit 53f5913

Please sign in to comment.