Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Feb 27, 2024
1 parent 562003c commit 61db824
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
76 changes: 38 additions & 38 deletions app/src/organisms/ConfigurePipette/ConfigForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,44 +56,6 @@ export function ConfigForm(props: ConfigFormProps): JSX.Element {
groupLabels,
} = props

const getInitialValues: () => FormValues = () => {
const fields = getVisibleFields()
const initialFieldValues = mapValues<
PipetteSettingsFieldsMap,
string | boolean
>(fields, f => {
if (f.value === true || f.value === false) return f.value
// @ts-expect-error(sa, 2021-05-27): avoiding src code change, use optional chain to access f.value
return f.value !== f.default ? f.value.toString() : ''
})
const initialQuirkValues = settings[QUIRK_KEY]
const initialValues = Object.assign(
{},
initialFieldValues,
initialQuirkValues
)

return initialValues
}
const initialValues = getInitialValues()

const resolver: Resolver<FormValues> = values => {
let errors = {}
errors = validate(values, errors)
return { values, errors }
}

const {
handleSubmit,
reset,
getValues,
control,
formState: { errors },
} = useForm<FormValues>({
defaultValues: initialValues,
resolver: resolver,
})

const getFieldsByKey = (
keys: string[],
fields: PipetteSettingsFieldsMap
Expand Down Expand Up @@ -205,6 +167,26 @@ export function ConfigForm(props: ConfigFormProps): JSX.Element {
return errors
}

const getInitialValues: () => FormValues = () => {
const fields = getVisibleFields()
const initialFieldValues = mapValues<
PipetteSettingsFieldsMap,
string | boolean
>(fields, f => {
if (f.value === true || f.value === false) return f.value
// @ts-expect-error(sa, 2021-05-27): avoiding src code change, use optional chain to access f.value
return f.value !== f.default ? f.value.toString() : ''
})
const initialQuirkValues = settings[QUIRK_KEY]
const initialValues = Object.assign(
{},
initialFieldValues,
initialQuirkValues
)

return initialValues
}

const fields = getVisibleFields()
const UNKNOWN_KEYS = getUnknownKeys()
const plungerFields = getFieldsByKey(PLUNGER_KEYS, fields)
Expand All @@ -213,6 +195,24 @@ export function ConfigForm(props: ConfigFormProps): JSX.Element {
const quirkFields = getKnownQuirks()
const quirksPresent = quirkFields.length > 0
const unknownFields = getFieldsByKey(UNKNOWN_KEYS, fields)
const initialValues = getInitialValues()

const resolver: Resolver<FormValues> = values => {
let errors = {}
errors = validate(values, errors)
return { values, errors }
}

const {
handleSubmit,
reset,
getValues,
control,
formState: { errors },
} = useForm<FormValues>({
defaultValues: initialValues,
resolver: resolver,
})

const handleReset = (): void => {
const newValues = mapValues(getValues(), v => {

Check warning on line 218 in app/src/organisms/ConfigurePipette/ConfigForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/organisms/ConfigurePipette/ConfigForm.tsx#L218

Added line #L218 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { InputField } from '../../../../../atoms/InputField'
import { Banner } from '../../../../../atoms/Banner'
import { useIsFlex } from '../../../hooks'

import { Resolver, FieldError } from 'react-hook-form'
import type { Resolver, FieldError } from 'react-hook-form'
import type { UpdatedRobotName } from '@opentrons/api-client'
import type { State, Dispatch } from '../../../../../redux/types'
interface RenameRobotSlideoutProps {
Expand Down

0 comments on commit 61db824

Please sign in to comment.