-
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): clarify editing file details
feat(protocol-designer): clarify editing file details Make file metadata form clearer about when you're altering the saved information and when you can update it by submitting. Also added in key press handler render prop component to the component library (used here for handling submission on pressing the enter key). Closes #1504 and #1661
- Loading branch information
Showing
11 changed files
with
128 additions
and
68 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
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,55 +1,60 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import type {Dispatch} from 'redux' | ||
import {connect} from 'react-redux' | ||
import type {BaseState} from '../types' | ||
|
||
import FilePage from '../components/FilePage' | ||
|
||
import type {FilePageProps} from '../components/FilePage' | ||
import {actions, selectors} from '../file-data' | ||
import type {FilePageFields} from '../file-data' | ||
import type {FileMetadataFields} from '../file-data' | ||
import {formConnectorFactory, type FormConnector} from '../utils' | ||
|
||
export default connect(mapStateToProps, null, mergeProps)(FilePage) | ||
|
||
type Props = React.ElementProps<typeof FilePage> | ||
type StateProps = { | ||
instruments: $PropertyType<Props, 'instruments'>, | ||
type SP = { | ||
instruments: $PropertyType<FilePageProps, 'instruments'>, | ||
isFormAltered: boolean, | ||
_values: {[string]: string} | ||
} | ||
|
||
function mapStateToProps (state: BaseState): StateProps { | ||
const formValues = selectors.fileFormValues(state) | ||
const pipetteData = selectors.pipettesForInstrumentGroup(state) | ||
type DP = { | ||
_updateFileMetadataFields: typeof actions.updateFileMetadataFields, | ||
_saveFileMetadata: ({[string]: string}) => void | ||
} | ||
|
||
const mapStateToProps = (state: BaseState): SP => { | ||
const pipetteData = selectors.pipettesForInstrumentGroup(state) | ||
return { | ||
_values: formValues, | ||
_values: selectors.fileFormValues(state), | ||
isFormAltered: selectors.isUnsavedMetadatFormAltered(state), | ||
instruments: { | ||
left: pipetteData.find(i => i.mount === 'left'), | ||
right: pipetteData.find(i => i.mount === 'right') | ||
} | ||
} | ||
} | ||
|
||
function mergeProps ( | ||
stateProps: StateProps, | ||
dispatchProps: {dispatch: Dispatch<*>} | ||
): Props { | ||
const {instruments, _values} = stateProps | ||
const {dispatch} = dispatchProps | ||
const mapDispatchToProps = { | ||
_updateFileMetadataFields: actions.updateFileMetadataFields, | ||
_saveFileMetadata: actions.saveFileMetadata | ||
} | ||
|
||
const mergeProps = ( | ||
{instruments, isFormAltered, _values}: SP, | ||
{_updateFileMetadataFields, _saveFileMetadata}: DP | ||
): FilePageProps => { | ||
const onChange = (accessor) => (e: SyntheticInputEvent<*>) => { | ||
if (accessor === 'name' || accessor === 'description' || accessor === 'author') { | ||
dispatch(actions.updateFileFields({[accessor]: e.target.value})) | ||
_updateFileMetadataFields({[accessor]: e.target.value}) | ||
} else { | ||
console.warn('Invalid accessor in ConnectedFilePage:', accessor) | ||
} | ||
} | ||
|
||
const formConnector: FormConnector<FilePageFields> = formConnectorFactory(onChange, _values) | ||
const formConnector: FormConnector<FileMetadataFields> = formConnectorFactory(onChange, _values) | ||
|
||
return { | ||
formConnector, | ||
instruments | ||
isFormAltered, | ||
instruments, | ||
saveFileMetadata: () => _saveFileMetadata(_values) | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(FilePage) |
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
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