Skip to content

Commit

Permalink
refactor LabwareField to not be a connect fnt
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Nov 30, 2023
1 parent 74a9b1c commit ac29c85
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react'
import { useSelector } from 'react-redux'
import {
getDisposalOptions,
getLabwareOptions,
} from '../../../ui/labware/selectors'
import { StepFormDropdown } from './StepFormDropdownField'
import type { FieldProps } from '../types'

export const LabwareField = (props: FieldProps): JSX.Element => {
const disposalOptions = useSelector(getDisposalOptions)
const options = useSelector(getLabwareOptions)

Check warning on line 12 in protocol-designer/src/components/StepEditForm/fields/LabwareField.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/StepEditForm/fields/LabwareField.tsx#L11-L12

Added lines #L11 - L12 were not covered by tests

const allOptions =
props.name === 'dispense_labware'
? [...options, ...disposalOptions]
: [...options]

return <StepFormDropdown {...props} options={allOptions} />

Check warning on line 19 in protocol-designer/src/components/StepEditForm/fields/LabwareField.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/StepEditForm/fields/LabwareField.tsx#L19

Added line #L19 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as React from 'react'
import { useSelector } from 'react-redux'
import { DropdownField, Options } from '@opentrons/components'
import cx from 'classnames'
import { StepFieldName } from '../../../steplist/fieldLevel'
import { getDisposalOptions } from '../../../ui/labware/selectors'
import styles from '../StepEditForm.css'
import type { FieldProps } from '../types'

Expand All @@ -24,13 +22,9 @@ export const StepFormDropdown = (props: StepFormDropdownProps): JSX.Element => {
updateValue,
errorToShow,
} = props
const disposalOptions = useSelector(getDisposalOptions)
const fullOptions =
name === 'dispense_labware' ? [...options, ...disposalOptions] : options

// TODO: BC abstract e.currentTarget.value inside onChange with fn like onChangeValue of type (value: unknown) => {}
// blank out the dropdown if labware id does not exist
const availableOptionIds = fullOptions.map(opt => opt.value)
const availableOptionIds = options.map(opt => opt.value)

Check warning on line 27 in protocol-designer/src/components/StepEditForm/fields/StepFormDropdownField.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/StepEditForm/fields/StepFormDropdownField.tsx#L27

Added line #L27 was not covered by tests
// @ts-expect-error (ce, 2021-06-21) unknown not assignable to string
const fieldValue = availableOptionIds.includes(value) ? String(value) : null

Expand All @@ -39,7 +33,7 @@ export const StepFormDropdown = (props: StepFormDropdownProps): JSX.Element => {
name={name}
error={errorToShow}
className={cx(styles.large_field, className)}
options={fullOptions}
options={options}
onBlur={onFieldBlur}
onFocus={onFieldFocus}
value={fieldValue}
Expand Down

0 comments on commit ac29c85

Please sign in to comment.