-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): Add deck map to module review modal (#1910)
Closes #1737
- Loading branch information
Showing
15 changed files
with
285 additions
and
125 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
53 changes: 53 additions & 0 deletions
53
app/src/components/ConnectModulesModal/ReviewModuleItem.js
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import {connect} from 'react-redux' | ||
import countBy from 'lodash/countBy' | ||
|
||
import {makeGetRobotModules} from '../../http-api-client' | ||
import {selectors as robotSelectors} from '../../robot' | ||
import {ModuleItem} from '../DeckMap' | ||
|
||
import type {LabwareComponentProps} from '@opentrons/components' | ||
import type {State} from '../../types' | ||
import type {SessionModule} from '../../robot' | ||
|
||
type OP = LabwareComponentProps | ||
|
||
type Props = { | ||
module: ?SessionModule, | ||
present: boolean | ||
} | ||
|
||
export default connect(makeMapStateToProps)(ReviewModuleItem) | ||
|
||
function ReviewModuleItem (props: Props) { | ||
if (!props.module) return null | ||
|
||
return ( | ||
<ModuleItem module={props.module} present={props.present} review /> | ||
) | ||
} | ||
|
||
function makeMapStateToProps (): (state: State, ownProps: OP) => Props { | ||
// TODO(mc, 2018-07-23): this logic is duplicated because can only get props | ||
// into Deck.props.LabwareComponent via redux | ||
const getRobotModules = makeGetRobotModules() | ||
|
||
return (state, ownProps) => { | ||
const robot = robotSelectors.getConnectedRobot(state) | ||
const module = robotSelectors.getModulesBySlot(state)[ownProps.slot] | ||
const sessionModules = robotSelectors.getModules(state) | ||
const actualModulesCall = robot && getRobotModules(state, robot) | ||
const actualModules = | ||
actualModulesCall && | ||
actualModulesCall.response && | ||
actualModulesCall.response.modules | ||
|
||
const requiredNames = countBy(sessionModules, 'name') | ||
const actualNames = countBy(actualModules || [], 'name') | ||
const present = | ||
!module || requiredNames[module.name] === actualNames[module.name] | ||
|
||
return {present, module} | ||
} | ||
} |
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,17 +1,89 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import {connect} from 'react-redux' | ||
import countBy from 'lodash/countBy' | ||
|
||
import {makeGetRobotModules, fetchModules} from '../../http-api-client' | ||
import {selectors as robotSelectors, actions as robotActions} from '../../robot' | ||
|
||
import {Deck} from '@opentrons/components' | ||
import {RefreshWrapper} from '../Page' | ||
import {Modal} from '../modals' | ||
import Prompt from './Prompt' | ||
import ReviewModuleItem from './ReviewModuleItem' | ||
|
||
import type {State} from '../../types' | ||
import type {RobotService, SessionModule} from '../../robot' | ||
import type {Module} from '../../http-api-client' | ||
|
||
type Props = { | ||
modulesMissing: boolean, | ||
onClick: () => mixed, | ||
type OP = { | ||
robot: RobotService | ||
} | ||
|
||
export default function ConnectModulesModal (props: Props) { | ||
type SP = { | ||
modulesRequired: boolean, | ||
modulesMissing: boolean | ||
} | ||
|
||
type DP = { | ||
setReviewed: () => mixed, | ||
fetchModules: () => mixed | ||
} | ||
|
||
type Props = OP & SP & DP | ||
|
||
export default connect( | ||
makeMapStateToProps, | ||
mapDispatchToProps | ||
)(ConnectModulesModal) | ||
|
||
function ConnectModulesModal (props: Props) { | ||
if (!props.modulesRequired) return null | ||
|
||
const {modulesMissing, setReviewed, fetchModules} = props | ||
const onPromptClick = modulesMissing ? fetchModules : setReviewed | ||
|
||
return ( | ||
<Modal> | ||
<Prompt {...props}/> | ||
</Modal> | ||
<RefreshWrapper refresh={fetchModules}> | ||
<Modal> | ||
<Prompt modulesMissing={modulesMissing} onClick={onPromptClick} /> | ||
<Deck LabwareComponent={ReviewModuleItem} /> | ||
</Modal> | ||
</RefreshWrapper> | ||
) | ||
} | ||
|
||
function makeMapStateToProps (): (state: State, ownProps: OP) => SP { | ||
const getRobotModules = makeGetRobotModules() | ||
|
||
return (state, ownProps) => { | ||
const sessionModules = robotSelectors.getModules(state) | ||
const actualModulesCall = getRobotModules(state, ownProps.robot) | ||
const actualModules = | ||
actualModulesCall.response && actualModulesCall.response.modules | ||
|
||
return { | ||
modulesRequired: sessionModules.length !== 0, | ||
modulesMissing: checkModulesMissing(sessionModules, actualModules) | ||
} | ||
} | ||
} | ||
|
||
function mapDispatchToProps (dispatch: Dispatch, ownProps: OP): DP { | ||
return { | ||
setReviewed: () => dispatch(robotActions.setModulesReviewed(true)), | ||
fetchModules: () => dispatch(fetchModules(ownProps.robot)) | ||
} | ||
} | ||
|
||
function checkModulesMissing ( | ||
required: Array<SessionModule>, | ||
actual: ?Array<Module> | ||
): boolean { | ||
const requiredNames = countBy(required, 'name') | ||
const actualNames = countBy(actual, 'name') | ||
|
||
return Object.keys(requiredNames).some( | ||
n => requiredNames[n] !== actualNames[n] | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,7 @@ function getModuleImg (name: string) { | |
return MODULE_IMGS[name] | ||
} | ||
|
||
// TODO (ka 2018-7-10): replace with design assets onces available | ||
const MODULE_IMGS = { | ||
'temp_deck': require('./images/[email protected]'), | ||
'mag_deck': require('./images/[email protected]') | ||
tempdeck: require('./images/[email protected]'), | ||
magdeck: require('./images/[email protected]') | ||
} |
Oops, something went wrong.