Skip to content

Commit

Permalink
feat(protocol-designer): implement "metadata.created" in JSON file (#…
Browse files Browse the repository at this point in the history
…2403)

Closes #2189
  • Loading branch information
IanLondon authored Oct 4, 2018
1 parent c19d57c commit a9c3d07
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
5 changes: 2 additions & 3 deletions protocol-designer/src/components/FilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import {
OutlineButton,
PrimaryButton,
} from '@opentrons/components'
import type {FileMetadataFields} from '../file-data'
import type {FormConnector} from '../utils'
import styles from './FilePage.css'
import formStyles from '../components/forms.css'

export type FilePageProps = {
formConnector: FormConnector<FileMetadataFields>,
formConnector: FormConnector<any>,
isFormAltered: boolean,
instruments: React.ElementProps<typeof InstrumentGroup>,
goToDesignPage: () => mixed,
Expand All @@ -35,7 +34,7 @@ const FilePage = ({formConnector, isFormAltered, instruments, saveFileMetadata,
<form onSubmit={handleSubmit} className={styles.card_content}>
<div className={formStyles.row_wrapper}>
<FormGroup label='Protocol Name:' className={formStyles.column_1_2}>
<InputField placeholder='Untitled' {...formConnector('name')} />
<InputField placeholder='Untitled' {...formConnector('protocol-name')} />
</FormGroup>

<FormGroup label='Organization/Author:' className={formStyles.column_1_2}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type MP = {
export default connect(mapStateToProps, null, mergeProps)(FileSidebar)

function mapStateToProps (state: BaseState): SP & MP {
const protocolName = fileDataSelectors.fileMetadata(state).name || 'untitled'
const protocolName = fileDataSelectors.getFileMetadata(state)['protocol-name'] || 'untitled'
const fileData = fileDataSelectors.createFile(state)
const canDownload = selectors.currentPage(state) !== 'file-splash'

Expand Down
6 changes: 3 additions & 3 deletions protocol-designer/src/containers/ConnectedFilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {formConnectorFactory, type FormConnector} from '../utils'
type SP = {
instruments: $PropertyType<FilePageProps, 'instruments'>,
isFormAltered: $PropertyType<FilePageProps, 'isFormAltered'>,
_values: {[accessor: FileMetadataFieldAccessors]: string},
_values: {[accessor: FileMetadataFieldAccessors]: any},
}

type DP = {
_updateFileMetadataFields: typeof actions.updateFileMetadataFields,
_saveFileMetadata: ({[accessor: FileMetadataFieldAccessors]: string}) => mixed,
_saveFileMetadata: ({[accessor: FileMetadataFieldAccessors]: mixed}) => mixed,
goToDesignPage: $PropertyType<FilePageProps, 'goToDesignPage'>,
swapPipettes: $PropertyType<FilePageProps, 'swapPipettes'>,
}
Expand Down Expand Up @@ -46,7 +46,7 @@ const mergeProps = (
{_updateFileMetadataFields, _saveFileMetadata, goToDesignPage, swapPipettes}: DP
): FilePageProps => {
const onChange = (accessor) => (e: SyntheticInputEvent<*>) => {
if (accessor === 'name' || accessor === 'description' || accessor === 'author') {
if (accessor === 'protocol-name' || accessor === 'description' || accessor === 'author') {
_updateFileMetadataFields({[accessor]: e.target.value})
} else {
console.warn('Invalid accessor in ConnectedFilePage:', accessor)
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/file-data/actions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @flow
import type {FileMetadataFieldAccessors} from './types'

export const updateFileMetadataFields = (payload: {[accessor: FileMetadataFieldAccessors]: string}) => ({
export const updateFileMetadataFields = (payload: {[accessor: FileMetadataFieldAccessors]: mixed}) => ({
type: 'UPDATE_FILE_METADATA_FIELDS',
payload,
})

export const saveFileMetadata = (payload: {[accessor: FileMetadataFieldAccessors]: string}) => ({
export const saveFileMetadata = (payload: {[accessor: FileMetadataFieldAccessors]: mixed}) => ({
type: 'SAVE_FILE_METADATA',
payload,
})
15 changes: 8 additions & 7 deletions protocol-designer/src/file-data/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {FileMetadataFields} from '../types'
import type {LoadFileAction, NewProtocolFields} from '../../load-file'

const defaultFields = {
name: '',
'protocol-name': '',
author: '',
description: '',
}
Expand All @@ -20,11 +20,7 @@ const updateMetadataFields = (
action: LoadFileAction
): FileMetadataFields => {
const {metadata} = action.payload
return {
author: metadata.author,
description: metadata.description,
name: metadata['protocol-name'],
}
return metadata
}

function newProtocolMetadata (
Expand All @@ -33,7 +29,8 @@ function newProtocolMetadata (
): FileMetadataFields {
return {
...defaultFields,
name: action.payload.name || '',
'protocol-name': action.payload.name || '',
created: Date.now(),
}
}

Expand All @@ -57,6 +54,10 @@ const fileMetadata = handleActions({
...state,
...action.payload,
}),
SAVE_PROTOCOL_FILE: (state: FileMetadataFields): FileMetadataFields => {
// NOTE: 'last-modified' is updated "on-demand", in response to user clicking "save/export"
return {...state, 'last-modified': Date.now()}
},
}, defaultFields)

export type RootState = {
Expand Down
15 changes: 9 additions & 6 deletions protocol-designer/src/file-data/selectors/fileCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {createSelector} from 'reselect'
import mapValues from 'lodash/mapValues'
import {getPropertyAllPipettes} from '@opentrons/shared-data'
import {fileMetadata} from './fileFields'
import {getFileMetadata} from './fileFields'
import {getInitialRobotState, robotStateTimeline} from './commands'
import {selectors as dismissSelectors} from '../../dismiss'
import {selectors as ingredSelectors} from '../../labware-ingred/reducers'
Expand Down Expand Up @@ -32,7 +32,7 @@ const executionDefaults = {
}

export const createFile: BaseState => ProtocolFile = createSelector(
fileMetadata,
getFileMetadata,
getInitialRobotState,
robotStateTimeline,
dismissSelectors.getAllDismissedWarnings,
Expand All @@ -50,8 +50,9 @@ export const createFile: BaseState => ProtocolFile = createSelector(
savedStepForms,
orderedSteps
) => {
const {author, description} = fileMetadata
const name = fileMetadata.name || 'untitled'
const {author, description, created} = fileMetadata
const name = fileMetadata['protocol-name'] || 'untitled'
const lastModified = fileMetadata['last-modified']

const instruments = mapValues(
initialRobotState.instruments,
Expand Down Expand Up @@ -83,8 +84,10 @@ export const createFile: BaseState => ProtocolFile = createSelector(
'protocol-name': name,
author,
description,
created: Date.now(),
'last-modified': null,
created,
'last-modified': lastModified,

// TODO LATER
category: null,
subcategory: null,
tags: [],
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/file-data/selectors/fileFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const isUnsavedMetadatFormAltered = createSelector(
state => !isEqual(state.unsavedMetadataForm, state.fileMetadata)
)

export const protocolName = createSelector(rootSelector, state => state.fileMetadata.name)
export const fileMetadata = createSelector(
export const protocolName = createSelector(rootSelector, state => state.fileMetadata['protocol-name'])
export const getFileMetadata = createSelector(
rootSelector,
state => state.fileMetadata
)
7 changes: 2 additions & 5 deletions protocol-designer/src/file-data/types.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// @flow
export type FileMetadataFields = {
name: string,
author: string,
description: string,
}
import type {ProtocolFile} from '../file-types'
export type FileMetadataFields = $PropertyType<ProtocolFile, 'metadata'>

export type FileMetadataFieldAccessors = $Keys<FileMetadataFields>
10 changes: 5 additions & 5 deletions protocol-designer/src/file-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export type ProtocolFile = {
'protocol-name': string,
author: string,
description: string,
created: MsSinceEpoch,
'last-modified': MsSinceEpoch | null,
created?: MsSinceEpoch,
'last-modified'?: MsSinceEpoch | null,
// TODO LATER string enums for category/subcategory? Or just strings?
category: string | null,
subcategory: string | null,
tags: Array<string>,
category?: string | null,
subcategory?: string | null,
tags?: Array<string>,
},

'default-values': {
Expand Down

0 comments on commit a9c3d07

Please sign in to comment.