Skip to content
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(protocol-designer): liquid tooltips on well selection, popper and portal #2521

Merged
merged 11 commits into from
Oct 23, 2018
3 changes: 1 addition & 2 deletions components/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import startCase from 'lodash/startCase'
import {
swatchColors,
MIXED_WELL_COLOR,
AIR,
} from '@opentrons/components'

import {AIR} from './constants'

export const humanizeLabwareType = startCase

export const wellNameSplit = (wellName: string): [string, string] => {
Expand Down
2 changes: 2 additions & 0 deletions protocol-designer/src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HashRouter, Route } from 'react-router-dom'
import ConnectedDeckSetup from '../containers/ConnectedDeckSetup'
import About from './About'
import ProtocolEditor from './ProtocolEditor'
import {PortalRoot} from './portals/TopPortal'

import '../css/reset.css'

Expand All @@ -16,6 +17,7 @@ export default function App () {
{/* TODO: Ian 2018-06-08 remove these unused routes & their components */}
<Route exact path='/old-ingredient-selector' component={ConnectedDeckSetup} />
<Route path='/about' component={About} />
<PortalRoot />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go into ProtocolEditor.js? I think this App.js is just vestigal

</div>
</HashRouter>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import {selectors as pipetteSelectors} from '../../../pipettes'

import * as wellContentsSelectors from '../../../top-selectors/well-contents'
import {selectors} from '../../../labware-ingred/reducers'
import type {Wells, ContentsByWell} from '../../../labware-ingred/types'
import {selectors as steplistSelectors} from '../../../steplist'
import type {WellIngredientNames} from '../../../steplist/types'
import {changeFormInput} from '../../../steplist/actions'
import type {StepFieldName} from '../../../steplist/fieldLevel'
import type {PipetteData} from '../../../step-generation/types'
import type {Wells, ContentsByWell} from '../../../labware-ingred/types'

import {SelectableLabware} from '../../labware'
import SingleLabwareWrapper from '../../SingleLabware'
Expand All @@ -38,6 +39,7 @@ type SP = {
initialSelectedWells: Array<string>,
wellContents: ContentsByWell,
containerType: string,
ingredNames: WellIngredientNames,
}
type DP = {saveWellSelection: (Wells) => mixed}

Expand Down Expand Up @@ -101,7 +103,8 @@ class WellSelectionModal extends React.Component<Props, State> {
updateHighlightedWells={this.updateHighlightedWells}
wellContents={this.props.wellContents}
containerType={this.props.containerType}
pipetteChannels={pipette && pipette.channels} />
pipetteChannels={pipette && pipette.channels}
ingredNames={this.props.ingredNames} />
</SingleLabwareWrapper>

<WellSelectionInstructions />
Expand All @@ -123,12 +126,14 @@ function mapStateToProps (state: BaseState, ownProps: OP): SP {
const timelineIdx = orderedSteps.findIndex(id => id === stepId)
const allWellContentsForStep = allWellContentsForSteps[timelineIdx]
const formData = steplistSelectors.getUnsavedForm(state)
const ingredNames = selectors.getIngredientNames(state)

return {
initialSelectedWells: formData ? formData[ownProps.name] : [],
pipette: pipetteId ? pipetteSelectors.equippedPipettes(state)[pipetteId] : null,
wellContents: labware && allWellContentsForStep ? allWellContentsForStep[labware.id] : {},
containerType: labware ? labware.type : 'missing labware',
ingredNames,
}
}

Expand Down
30 changes: 0 additions & 30 deletions protocol-designer/src/components/WellToolTip.css

This file was deleted.

40 changes: 0 additions & 40 deletions protocol-designer/src/components/WellToolTip.js

This file was deleted.

114 changes: 33 additions & 81 deletions protocol-designer/src/components/labware/BrowseLabwareModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import {
import type {BaseState, ThunkDispatch} from '../../types'
import i18n from '../../localization'

import type {LocationLiquidState} from '../../step-generation'
import {PillTooltipContents} from '../steplist/SubstepRow'
import * as wellContentsSelectors from '../../top-selectors/well-contents'
import {selectors} from '../../labware-ingred/reducers'
import * as labwareIngredsActions from '../../labware-ingred/actions'
Expand All @@ -28,6 +26,7 @@ import SingleLabwareWrapper from '../SingleLabware'

import modalStyles from '../modals/modal.css'
import styles from './labware.css'
import WellTooltip from './WellTooltip'

type SP = {
wellContents: ContentsByWell,
Expand All @@ -40,44 +39,7 @@ type DP = {

type Props = SP & DP

type State = {
tooltipX: ?number,
tooltipY: ?number,
tooltipWellName: ?string,
tooltipWellIngreds: ?LocationLiquidState,
}
const initialState: State = {
tooltipX: null,
tooltipY: null,
tooltipWellName: null,
tooltipWellIngreds: null,
}

const MOUSE_TOOLTIP_OFFSET_PIXELS = 14

class BrowseLabwareModal extends React.Component<Props, State> {
state: State = initialState
wrapperRef: ?any

makeHandleWellMouseOver = (wellName: string, wellIngreds: LocationLiquidState) =>
(e) => {
const {clientX, clientY} = e
if (Object.keys(wellIngreds).length > 0 && clientX && clientY && this.wrapperRef) {
const wrapperLeft = this.wrapperRef ? this.wrapperRef.getBoundingClientRect().left : 0
const wrapperTop = this.wrapperRef ? this.wrapperRef.getBoundingClientRect().top : 0
this.setState({
tooltipX: clientX - wrapperLeft + MOUSE_TOOLTIP_OFFSET_PIXELS,
tooltipY: clientY - wrapperTop + MOUSE_TOOLTIP_OFFSET_PIXELS,
tooltipWellName: wellName,
tooltipWellIngreds: wellIngreds,
})
}
}

handleWellMouseLeave = (e) => {
this.setState(initialState)
}

class BrowseLabwareModal extends React.Component<Props> {
handleClose = () => {
this.props.drillUp()
}
Expand All @@ -87,50 +49,40 @@ class BrowseLabwareModal extends React.Component<Props, State> {

return (
<Modal
innerRef={ref => { this.wrapperRef = ref }}
className={modalStyles.modal}
contentsClassName={cx(modalStyles.modal_contents, modalStyles.transparent_content)}
onCloseClick={this.handleClose}>
<SingleLabwareWrapper showLabels>
<g>
<LabwareOutline />
{map(this.props.wellContents, (well, wellName) => {
const color = ingredIdsToColor(well.groupIds)
const mouseHandlers = color
? {
onMouseMove: this.makeHandleWellMouseOver(wellName, well.ingreds),
onMouseLeave: this.handleWellMouseLeave,
}
: {}
return (
<Well
{...mouseHandlers}
key={wellName}
wellName={wellName}
highlighted={this.state.tooltipWellName === wellName}
fillColor={color}
svgOffset={{x: 1, y: -3}}
wellDef={allWellDefsByName[wellName]} />
)
})}
</g>
<LabwareLabels labwareType={this.props.labwareType} inner={false} />
</SingleLabwareWrapper>
{this.state.tooltipWellName &&
<div
style={{
left: this.state.tooltipX,
top: this.state.tooltipY,
position: 'absolute',
}}>
<div className={styles.tooltip_box}>
<PillTooltipContents
well={this.state.tooltipWellName}
ingredNames={this.props.ingredNames}
ingreds={this.state.tooltipWellIngreds || {}} />
</div>
</div>
}
<WellTooltip ingredNames={this.props.ingredNames}>
{
({makeHandleMouseOverWell, handleMouseLeaveWell, tooltipWellName}) => (
<SingleLabwareWrapper showLabels>
<g>
<LabwareOutline />
{map(this.props.wellContents, (well, wellName) => {
const color = ingredIdsToColor(well.groupIds)
const mouseHandlers = color
? {
onMouseOver: makeHandleMouseOverWell(wellName, well.ingreds),
onMouseLeave: handleMouseLeaveWell,
}
: {}
return (
<Well
{...mouseHandlers}
key={wellName}
wellName={wellName}
highlighted={tooltipWellName === wellName}
fillColor={color}
svgOffset={{x: 1, y: -3}}
wellDef={allWellDefsByName[wellName]} />
)
})}
</g>
<LabwareLabels labwareType={this.props.labwareType} inner={false} />
</SingleLabwareWrapper>
)
}
</WellTooltip>
<div className={styles.modal_instructions}>{i18n.t('modal.browse_labware.instructions')}</div>
</Modal>
)
Expand Down
Loading