-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): add tiprack selection step to quick transfer flow (#14950)
fix PLAT-290
- Loading branch information
Showing
6 changed files
with
207 additions
and
14 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { Flex, SPACING, DIRECTION_COLUMN } from '@opentrons/components' | ||
import { getAllDefinitions } from '@opentrons/shared-data' | ||
import { SmallButton, LargeButton } from '../../atoms/buttons' | ||
import { ChildNavigation } from '../ChildNavigation' | ||
|
||
import type { LabwareDefinition2 } from '@opentrons/shared-data' | ||
import type { | ||
QuickTransferSetupState, | ||
QuickTransferWizardAction, | ||
} from './types' | ||
|
||
interface SelectTipRackProps { | ||
onNext: () => void | ||
onBack: () => void | ||
exitButtonProps: React.ComponentProps<typeof SmallButton> | ||
state: QuickTransferSetupState | ||
dispatch: React.Dispatch<QuickTransferWizardAction> | ||
} | ||
|
||
export function SelectTipRack(props: SelectTipRackProps): JSX.Element { | ||
const { onNext, onBack, exitButtonProps, state, dispatch } = props | ||
const { i18n, t } = useTranslation(['quick_transfer', 'shared']) | ||
|
||
const allLabwareDefinitionsByUri = getAllDefinitions() | ||
const selectedPipetteDefaultTipracks = | ||
state.pipette?.liquids.default.defaultTipracks ?? [] | ||
|
||
const [selectedTipRack, setSelectedTipRack] = React.useState< | ||
LabwareDefinition2 | undefined | ||
>(state.tipRack) | ||
|
||
const handleClickNext = (): void => { | ||
// the button will be disabled if this values is null | ||
if (selectedTipRack != null) { | ||
dispatch({ | ||
type: 'SELECT_TIP_RACK', | ||
tipRack: selectedTipRack, | ||
}) | ||
onNext() | ||
} | ||
} | ||
return ( | ||
<Flex> | ||
<ChildNavigation | ||
header={t('select_tip_rack')} | ||
buttonText={i18n.format(t('shared:continue'), 'capitalize')} | ||
onClickBack={onBack} | ||
onClickButton={handleClickNext} | ||
secondaryButtonProps={exitButtonProps} | ||
top={SPACING.spacing8} | ||
buttonIsDisabled={selectedTipRack == null} | ||
/> | ||
<Flex | ||
marginTop={SPACING.spacing120} | ||
flexDirection={DIRECTION_COLUMN} | ||
padding={`${SPACING.spacing16} ${SPACING.spacing60} ${SPACING.spacing40} ${SPACING.spacing60}`} | ||
gridGap={SPACING.spacing4} | ||
width="100%" | ||
> | ||
{selectedPipetteDefaultTipracks.map(tipRack => { | ||
const tipRackDef = allLabwareDefinitionsByUri[tipRack] | ||
|
||
return tipRackDef != null ? ( | ||
<LargeButton | ||
buttonType={ | ||
selectedTipRack === tipRackDef ? 'primary' : 'secondary' | ||
} | ||
onClick={() => { | ||
setSelectedTipRack(tipRackDef) | ||
}} | ||
buttonText={tipRackDef.metadata.displayName} | ||
/> | ||
) : null | ||
})} | ||
</Flex> | ||
</Flex> | ||
) | ||
} |
86 changes: 86 additions & 0 deletions
86
app/src/organisms/QuickTransferFlow/__tests__/SelectTipRack.test.tsx
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,86 @@ | ||
import * as React from 'react' | ||
import { fireEvent, screen } from '@testing-library/react' | ||
import { describe, it, expect, afterEach, vi, beforeEach } from 'vitest' | ||
|
||
import { renderWithProviders } from '../../../__testing-utils__' | ||
import { i18n } from '../../../i18n' | ||
import { SelectTipRack } from '../SelectTipRack' | ||
|
||
vi.mock('@opentrons/react-api-client') | ||
const render = (props: React.ComponentProps<typeof SelectTipRack>) => { | ||
return renderWithProviders(<SelectTipRack {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('SelectTipRack', () => { | ||
let props: React.ComponentProps<typeof SelectTipRack> | ||
|
||
beforeEach(() => { | ||
props = { | ||
onNext: vi.fn(), | ||
onBack: vi.fn(), | ||
exitButtonProps: { | ||
buttonType: 'tertiaryLowLight', | ||
buttonText: 'Exit', | ||
onClick: vi.fn(), | ||
}, | ||
state: { | ||
mount: 'left', | ||
pipette: { | ||
liquids: { | ||
default: { | ||
defaultTipracks: [ | ||
'opentrons/opentrons_flex_96_tiprack_1000ul/1', | ||
'opentrons/opentrons_flex_96_tiprack_200ul/1', | ||
'opentrons/opentrons_flex_96_tiprack_50ul/1', | ||
'opentrons/opentrons_flex_96_filtertiprack_1000ul/1', | ||
'opentrons/opentrons_flex_96_filtertiprack_200ul/1', | ||
'opentrons/opentrons_flex_96_filtertiprack_50ul/1', | ||
], | ||
}, | ||
}, | ||
} as any, | ||
}, | ||
dispatch: vi.fn(), | ||
} | ||
}) | ||
afterEach(() => { | ||
vi.resetAllMocks() | ||
}) | ||
|
||
it('renders the select tip rack screen, header, and exit button', () => { | ||
render(props) | ||
screen.getByText('Select tip rack') | ||
const exitBtn = screen.getByText('Exit') | ||
fireEvent.click(exitBtn) | ||
expect(props.exitButtonProps.onClick).toHaveBeenCalled() | ||
}) | ||
|
||
it('renders continue button and it is disabled if no tip rack is selected', () => { | ||
render(props) | ||
screen.getByText('Continue') | ||
const continueBtn = screen.getByTestId('ChildNavigation_Primary_Button') | ||
expect(continueBtn).toBeDisabled() | ||
}) | ||
|
||
it('selects tip rack by default if there is one in state, button will be enabled', () => { | ||
render({ ...props, state: { tipRack: { def: 'definition' } as any } }) | ||
const continueBtn = screen.getByTestId('ChildNavigation_Primary_Button') | ||
expect(continueBtn).toBeEnabled() | ||
fireEvent.click(continueBtn) | ||
expect(props.onNext).toHaveBeenCalled() | ||
}) | ||
|
||
it('enables continue button if you click a tip rack', () => { | ||
render(props) | ||
const continueBtn = screen.getByTestId('ChildNavigation_Primary_Button') | ||
expect(continueBtn).toBeDisabled() | ||
const tipRackButton = screen.getByText('Opentrons Flex 96 Tip Rack 200 µL') | ||
fireEvent.click(tipRackButton) | ||
expect(continueBtn).toBeEnabled() | ||
fireEvent.click(continueBtn) | ||
expect(props.dispatch).toHaveBeenCalled() | ||
expect(props.onNext).toHaveBeenCalled() | ||
}) | ||
}) |
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