-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(app): Enable pipette config modal and form #3202
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bd4fc69
feat(app): Enable pipette config modal and form
Kadee80 0c6c5a9
fixup: Cleanup unknown field logic and validation
Kadee80 362a9cd
fixup: Check max type
Kadee80 2f5716d
fixup: Consistent naming for unknown field consts and methods
Kadee80 bcbe0d7
fixup: Remove duplicate logic
Kadee80 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,11 @@ import {Formik, Form} from 'formik' | |
|
||
import startCase from 'lodash/startCase' | ||
import mapValues from 'lodash/mapValues' | ||
import forOwn from 'lodash/forOwn' | ||
import keys from 'lodash/keys' | ||
import pick from 'lodash/pick' | ||
import omit from 'lodash/omit' | ||
import set from 'lodash/set' | ||
import forOwn from 'lodash/forOwn' | ||
import isEmpty from 'lodash/isEmpty' | ||
|
||
import FormButtonBar from './FormButtonBar' | ||
|
@@ -33,6 +35,7 @@ type Props = { | |
pipette: Pipette, | ||
pipetteConfig: PipetteConfigResponse, | ||
updateConfig: (id: string, PipetteConfigRequest) => mixed, | ||
showHiddenFields: boolean, | ||
} | ||
|
||
const PLUNGER_KEYS = ['top', 'bottom', 'blowout', 'dropTip'] | ||
|
@@ -57,13 +60,24 @@ export default class ConfigForm extends React.Component<Props> { | |
} | ||
|
||
getVisibleFields = () => { | ||
if (this.props.showHiddenFields) return this.props.pipetteConfig.fields | ||
return pick(this.props.pipetteConfig.fields, [ | ||
...PLUNGER_KEYS, | ||
...POWER_KEYS, | ||
...TIP_KEYS, | ||
]) | ||
} | ||
|
||
getUnknownKeys = () => { | ||
return keys( | ||
omit(this.props.pipetteConfig.fields, [ | ||
...PLUNGER_KEYS, | ||
...POWER_KEYS, | ||
...TIP_KEYS, | ||
]) | ||
) | ||
} | ||
|
||
handleSubmit = (values: FormValues) => { | ||
const params = mapValues(values, v => { | ||
return v === '' ? null : {value: Number(v)} | ||
|
@@ -84,19 +98,24 @@ export default class ConfigForm extends React.Component<Props> { | |
|
||
validate = (values: FormValues) => { | ||
const errors = {} | ||
const fields = this.getVisibleFields() | ||
const fields = this.props.showHiddenFields | ||
? this.props.pipetteConfig.fields | ||
: this.getVisibleFields() | ||
const plungerFields = this.getFieldsByKey(PLUNGER_KEYS, fields) | ||
|
||
// validate all visible fields with min and max | ||
forOwn(fields, (field, name) => { | ||
const value = values[name] | ||
const value = values[name].trim() | ||
const {min, max} = field | ||
|
||
if (value !== '') { | ||
const parsed = Number(value) | ||
if (Number.isNaN(parsed)) { | ||
set(errors, name, `number required`) | ||
} else if (min && max && (parsed < min || value > max)) { | ||
} else if ( | ||
typeof min === 'number' && | ||
max && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should probably get the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
(parsed < min || value > max) | ||
) { | ||
set(errors, name, `Min ${min} / Max ${max}`) | ||
} | ||
} | ||
|
@@ -118,12 +137,14 @@ export default class ConfigForm extends React.Component<Props> { | |
render () { | ||
const {parentUrl} = this.props | ||
const fields = this.getVisibleFields() | ||
const HIDDEN_KEYS = this.getUnknownKeys() | ||
const initialValues = mapValues(fields, f => { | ||
return f.value !== f.default ? f.value.toString() : '' | ||
}) | ||
const plungerFields = this.getFieldsByKey(PLUNGER_KEYS, fields) | ||
const powerFields = this.getFieldsByKey(POWER_KEYS, fields) | ||
const tipFields = this.getFieldsByKey(TIP_KEYS, fields) | ||
const devFields = this.getFieldsByKey(HIDDEN_KEYS, fields) | ||
|
||
return ( | ||
<Formik | ||
|
@@ -154,6 +175,12 @@ export default class ConfigForm extends React.Component<Props> { | |
groupLabel="Tip Pickup / Drop " | ||
formFields={tipFields} | ||
/> | ||
{this.props.showHiddenFields && ( | ||
<ConfigFormGroup | ||
groupLabel="For Dev Use Only" | ||
formFields={devFields} | ||
/> | ||
)} | ||
</FormColumn> | ||
<FormButtonBar | ||
buttons={[ | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is duplicated here and in
render
and should probably be moved togetVisibleFields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line change should be reverted with the update to
getVisibleFields