-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol-designer): create container for all tipracks (#14848)
closes AUTH-313
- Loading branch information
Showing
7 changed files
with
134 additions
and
31 deletions.
There are no files selected for viewing
72 changes: 51 additions & 21 deletions
72
protocol-designer/src/components/StepEditForm/fields/TiprackField.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 |
---|---|---|
@@ -1,32 +1,62 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useSelector } from 'react-redux' | ||
import { FormGroup, DropdownField } from '@opentrons/components' | ||
import { | ||
FormGroup, | ||
DropdownField, | ||
useHoverTooltip, | ||
Tooltip, | ||
Box, | ||
} from '@opentrons/components' | ||
import { selectors as uiLabwareSelectors } from '../../../ui/labware' | ||
import styles from '../StepEditForm.module.css' | ||
|
||
import { getPipetteEntities } from '../../../step-forms/selectors' | ||
import type { FieldProps } from '../types' | ||
|
||
export function TiprackField(props: FieldProps): JSX.Element { | ||
const { name, value, onFieldBlur, onFieldFocus, updateValue } = props | ||
const { t } = useTranslation('form') | ||
import styles from '../StepEditForm.module.css' | ||
|
||
interface TiprackFieldProps extends FieldProps { | ||
pipetteId?: unknown | ||
} | ||
export function TiprackField(props: TiprackFieldProps): JSX.Element { | ||
const { | ||
name, | ||
value, | ||
onFieldBlur, | ||
onFieldFocus, | ||
updateValue, | ||
pipetteId, | ||
} = props | ||
const { t } = useTranslation(['form', 'tooltip']) | ||
const [targetProps, tooltipProps] = useHoverTooltip() | ||
const pipetteEntities = useSelector(getPipetteEntities) | ||
const options = useSelector(uiLabwareSelectors.getTiprackOptions) | ||
const defaultTipracks = | ||
pipetteId != null ? pipetteEntities[pipetteId as string].tiprackDefURI : [] | ||
const pipetteOptions = options.filter(option => | ||
defaultTipracks.includes(option.defURI) | ||
) | ||
const hasMissingTiprack = defaultTipracks.length > pipetteOptions.length | ||
|
||
return ( | ||
<FormGroup | ||
label={t('step_edit_form.tipRack')} | ||
className={styles.large_field} | ||
> | ||
<DropdownField | ||
options={options} | ||
name={name} | ||
value={String(value) != null ? String(value) : null} | ||
onBlur={onFieldBlur} | ||
onFocus={onFieldFocus} | ||
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => { | ||
updateValue(e.currentTarget.value) | ||
}} | ||
/> | ||
</FormGroup> | ||
<Box {...targetProps}> | ||
<FormGroup | ||
label={t('step_edit_form.tipRack')} | ||
className={styles.large_field} | ||
> | ||
<DropdownField | ||
options={pipetteOptions} | ||
name={name} | ||
value={String(value) != null ? String(value) : null} | ||
onBlur={onFieldBlur} | ||
onFocus={onFieldFocus} | ||
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => { | ||
updateValue(e.currentTarget.value) | ||
}} | ||
/> | ||
</FormGroup> | ||
{hasMissingTiprack ? ( | ||
<Tooltip {...tooltipProps}>{t('tooltip:missing_tiprack')}</Tooltip> | ||
) : null} | ||
</Box> | ||
) | ||
} |
60 changes: 60 additions & 0 deletions
60
protocol-designer/src/components/StepEditForm/fields/__tests__/TiprackField.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,60 @@ | ||
import * as React from 'react' | ||
import { describe, it, vi, beforeEach } from 'vitest' | ||
import { screen } from '@testing-library/react' | ||
import { i18n } from '../../../../localization' | ||
import { getPipetteEntities } from '../../../../step-forms/selectors' | ||
import { renderWithProviders } from '../../../../__testing-utils__' | ||
import { getTiprackOptions } from '../../../../ui/labware/selectors' | ||
import { TiprackField } from '../TiprackField' | ||
|
||
vi.mock('../../../../ui/labware/selectors') | ||
vi.mock('../../../../step-forms/selectors') | ||
|
||
const render = (props: React.ComponentProps<typeof TiprackField>) => { | ||
return renderWithProviders(<TiprackField {...props} />, { | ||
i18nInstance: i18n, | ||
})[0] | ||
} | ||
const mockMockId = 'mockId' | ||
describe('TiprackField', () => { | ||
let props: React.ComponentProps<typeof TiprackField> | ||
|
||
beforeEach(() => { | ||
props = { | ||
disabled: false, | ||
value: null, | ||
name: 'tipRackt', | ||
updateValue: vi.fn(), | ||
onFieldBlur: vi.fn(), | ||
onFieldFocus: vi.fn(), | ||
pipetteId: mockMockId, | ||
} | ||
vi.mocked(getPipetteEntities).mockReturnValue({ | ||
[mockMockId]: { | ||
name: 'p50_single_flex', | ||
spec: {} as any, | ||
id: mockMockId, | ||
tiprackLabwareDef: [], | ||
tiprackDefURI: ['mockDefURI1', 'mockDefURI2'], | ||
}, | ||
}) | ||
vi.mocked(getTiprackOptions).mockReturnValue([ | ||
{ | ||
value: 'mockValue', | ||
name: 'tiprack1', | ||
defURI: 'mockDefURI1', | ||
}, | ||
{ | ||
value: 'mockValue', | ||
name: 'tiprack2', | ||
defURI: 'mockDefURI2', | ||
}, | ||
]) | ||
}) | ||
it('renders the dropdown field and texts', () => { | ||
render(props) | ||
screen.getByText('tip rack') | ||
screen.getByText('tiprack1') | ||
screen.getByText('tiprack2') | ||
}) | ||
}) |
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
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