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

refactor(js): Fix a variety of type definitions that will break in future Flow versions #4749

Merged
merged 3 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
"url": "https://github.com/Opentrons/opentrons/issues"
},
"homepage": "https://github.com/Opentrons/opentrons",
"devDependencies": {
"flow-bin": "^0.110.1",
"flow-typed": "^2.6.2"
},
"dependencies": {
"@opentrons/components": "3.15.2",
"@opentrons/shared-data": "3.15.2",
Expand Down
8 changes: 4 additions & 4 deletions app/src/analytics/make-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export function makeEvent(
return getProtocolAnalyticsData(state).then(data => ({
name: 'protocolUploadRequest',
properties: {
...data,
...getRobotAnalyticsData(state),
...data,
},
}))
}
Expand All @@ -63,8 +63,8 @@ export function makeEvent(
return getProtocolAnalyticsData(state).then(data => ({
name: 'protocolUploadResponse',
properties: {
...data,
...getRobotAnalyticsData(state),
...data,
success: actionType === 'robot:SESSION_RESPONSE',
error: (actionPayload.error && actionPayload.error.message) || '',
},
Expand All @@ -76,8 +76,8 @@ export function makeEvent(
return getProtocolAnalyticsData(state).then(data => ({
name: 'runStart',
properties: {
...data,
...getRobotAnalyticsData(state),
...data,
},
}))
}
Expand All @@ -94,8 +94,8 @@ export function makeEvent(
return getProtocolAnalyticsData(state).then(data => ({
name: 'runFinish',
properties: {
...data,
...getRobotAnalyticsData(state),
...data,
runTime,
success,
error,
Expand Down
3 changes: 2 additions & 1 deletion app/src/buildroot/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ export function buildrootReducer(

case Constants.BR_STATUS: {
const { stage, progress, message } = action.payload
const currentError = state.session?.error || null

return {
...state,
session: {
...state.session,
stage,
progress: typeof progress === 'number' ? progress : null,
error: stage === Constants.ERROR ? message : state.session?.error,
error: stage === Constants.ERROR ? message : currentError,
},
}
}
Expand Down
13 changes: 4 additions & 9 deletions app/src/components/CalibrateDeck/AttachTip.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
// @flow
import * as React from 'react'
import type { PipetteModelSpecs } from '@opentrons/shared-data'
import type { CalibrateDeckStartedProps, CalibrationStep } from './types'
import { PrimaryButton } from '@opentrons/components'

import styles from './styles.css'

type Props = CalibrateDeckStartedProps & {
type Props = {|
...CalibrateDeckStartedProps,
proceed: () => mixed,
}

type DiagramProps = {
calibrationStep: CalibrationStep,
pipette: PipetteModelSpecs,
}
|}

type Channels = 'single' | 'multi'

Expand Down Expand Up @@ -72,7 +67,7 @@ export default function AttachTipModal(props: Props) {
)
}

function getDiagramSrc(props: DiagramProps): string {
function getDiagramSrc(props: Props): string {
const { calibrationStep, pipette } = props
const channelsKey = pipette.channels === 8 ? 'multi' : 'single'

Expand Down
2 changes: 1 addition & 1 deletion app/src/components/CalibrateDeck/ClearDeckAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ClearDeckAlertModal from '../ClearDeckAlertModal'
import type { Dispatch } from '../../types'
import type { CalibrateDeckProps } from './types'

type OP = $Exact<CalibrateDeckProps>
type OP = CalibrateDeckProps

type DP = {|
onContinue: () => mixed,
Expand Down
5 changes: 3 additions & 2 deletions app/src/components/CalibrateDeck/ConfirmPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { PrimaryButton } from '@opentrons/components'
import JogControls from '../JogControls'
import Instructions from './Instructions'

type Props = CalibrateDeckStartedProps & {
type Props = {|
...CalibrateDeckStartedProps,
proceed: () => mixed,
}
|}

export default function ConfirmPosition(props: Props) {
return (
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/CalibrateDeck/InstructionsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import ConfirmPosition from './ConfirmPosition'
import type { Dispatch } from '../../types'
import type { CalibrateDeckStartedProps } from './types'

type OP = $Exact<CalibrateDeckStartedProps>
type OP = CalibrateDeckStartedProps

type DP = {| proceed: () => mixed |}

type Props = { ...OP, ...DP }
type Props = {| ...OP, ...DP |}

const TITLE = 'Deck Calibration'

Expand Down
8 changes: 4 additions & 4 deletions app/src/components/CalibrateDeck/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export type DP = {|
back: () => mixed,
|}

export type CalibrateDeckProps = { ...OP, ...SP, ...DP }
export type CalibrateDeckProps = {| ...OP, ...SP, ...DP |}

export type CalibrateDeckStartedProps = {
...$Exact<CalibrateDeckProps>,
export type CalibrateDeckStartedProps = {|
...CalibrateDeckProps,
exitUrl: string,
mount: Mount,
pipette: PipetteModelSpecs,
calibrationStep: CalibrationStep,
}
|}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DP = {|
jog: Jog,
|}

type Props = { ...OP, ...DP }
type Props = {| ...OP, ...DP |}

export default connect<Props, OP, _, _, _, _>(
null,
Expand All @@ -32,6 +32,7 @@ export default connect<Props, OP, _, _, _, _>(

function ConfirmPositionContents(props: Props) {
const {
jog,
onConfirmClick,
labware,
calibrator,
Expand All @@ -49,7 +50,7 @@ function ConfirmPositionContents(props: Props) {
{...{ labware, calibrator, calibrateToBottom, useCenteredTroughs }}
buttonText={confirmButtonText}
/>
<JogControls {...props} />
<JogControls jog={jog} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

<JogControls> only takes the one prop, so this code change is safe

<PrimaryButton title="confirm" onClick={onConfirmClick}>
{confirmButtonText}
</PrimaryButton>
Expand Down
1 change: 0 additions & 1 deletion app/src/components/CalibrateLabware/ProceedToRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function ProceedToRun(props: Props) {
}, [sessionModules])

const handleClick = () => {
// $FlowFixMe: robotActions.returnTip is not typed
returnTip()
if (mustPrepForRun) {
setRunPrepModalOpen(true)
Expand Down
5 changes: 2 additions & 3 deletions app/src/components/CalibratePanel/LabwareList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ type SP = {|

type DP = {| dispatch: Dispatch |}

type Props = {
type Props = {|
labware: Array<Labware>,
modulesBySlot: { [Slot]: SessionModule },
disabled: boolean,
setLabware: (labware: Labware) => mixed,
}
|}

export default withRouter<{||}, _>(
connect<Props, _, SP, {||}, State, Dispatch>(
Expand All @@ -54,7 +54,6 @@ function LabwareList(props: Props) {
modulesBySlot[lw.slot].name
}
isDisabled={disabled}
confirmed={lw.confirmed}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lw was already being spread in, so this line was unnecessary

onClick={() => setLabware(lw)}
/>
))}
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/CalibratePanel/LabwareListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { Labware } from '../../robot'
import { THERMOCYCLER } from '../../modules'

type LabwareListItemProps = {|
...$Exact<Labware>,
...Labware,
moduleName?: ModuleType,
isDisabled: boolean,
onClick: () => mixed,
Expand Down
6 changes: 1 addition & 5 deletions app/src/components/ConnectPanel/UnreachableRobotItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ export default function UnreachableRobotItem(props: UnreachableRobot) {
disabled
hoverTooltipHandlers={hoverTooltipHandlers}
>
<Icon
name={'alert-circle'}
className={styles.robot_item_icon}
disabled
Copy link
Contributor Author

Choose a reason for hiding this comment

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

<Icon> has no prop named disabled

/>
<Icon name={'alert-circle'} className={styles.robot_item_icon} />
<p className={styles.link_text}>{displayName}</p>
</RobotLink>
)}
Expand Down
7 changes: 4 additions & 3 deletions app/src/components/ReviewDeck/Prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { selectors as robotSelectors, type Labware } from '../../robot'
import styles from './styles.css'

type Props = {|
...$Exact<Labware>,
...Labware,
onClick: () => void,
|}

export default function Prompt(props: Props) {
const { name, definition, slot, onClick } = props
const labwareType = robotSelectors.labwareType(props)
const { onClick, ...labware } = props
const { name, definition, slot } = labware
const labwareType = robotSelectors.labwareType(labware)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change was driven by switching Labware to an exact object type. This minor code change keeps that all behaving

const labwareTitle = definition ? getLabwareDisplayName(definition) : name

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export default class SelectKey extends React.Component<Props> {
event.target.value = ''
// $FlowFixMe: see TODO and HACK in app/src/http-api-client/networking.js
this.props.addKey(file).then(success => {
// $FlowFixMe: ditto
this.props.onValueChange(this.props.name, success.payload.response.id)
})
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/components/RobotSettings/SelectNetwork/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ type PasswordFieldProps = {
toggleShowPassword: (name: string) => mixed,
}

type SelectOptionFieldProps = {
type SelectOptionFieldProps = {|
...BaseFieldProps,
options: Array<SelectOption>,
placeholder?: string,
onValueChange?: (name: string, value: ?string) => mixed,
onValueChange: (name: string, value: ?string) => mixed,
onLoseFocus?: (name: string) => mixed,
}
|}

const SHOW_PASSWORD_LABEL = 'Show password'
const FIELD_ID_PREFIX = '__ConnectForm__'
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/TipProbe/types.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import type { Pipette } from '../../robot'

export type TipProbeProps = $Exact<Pipette>
export type TipProbeProps = Pipette

export type TipProbeState =
| 'unprobed'
Expand Down
8 changes: 7 additions & 1 deletion app/src/components/calibrate-pipettes/Pipettes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PIPETTE_MOUNTS } from '../../pipettes'
import { InstrumentGroup } from '@opentrons/components'
import styles from './styles.css'

import type { InstrumentInfoProps } from '@opentrons/components'
import type { Pipette, TiprackByMountMap } from '../../robot/types'
import type { Mount } from '../../pipettes/types'

Expand All @@ -19,7 +20,12 @@ type Props = {|
export default function Pipettes(props: Props) {
const { currentMount, pipettes, tipracksByMount } = props

const infoByMount = PIPETTE_MOUNTS.reduce((result, mount) => {
const infoByMount = PIPETTE_MOUNTS.reduce<
$Shape<{|
left?: InstrumentInfoProps,
right?: InstrumentInfoProps,
|}>
>((result, mount) => {
const pipette = pipettes.find(p => p.mount === mount)
const tiprack = tipracksByMount[mount]
const pipetteConfig = pipette?.modelSpecs
Expand Down
16 changes: 8 additions & 8 deletions app/src/discovery/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,37 @@ export type ReachableStatus = 'reachable'
export type UnreachableStatus = 'unreachable'

// service with a known IP address
export type ResolvedRobot = {
export type ResolvedRobot = {|
...$Exact<Service>,
ip: $NonMaybeType<$PropertyType<Service, 'ip'>>,
local: $NonMaybeType<$PropertyType<Service, 'local'>>,
ok: $NonMaybeType<$PropertyType<Service, 'ok'>>,
serverOk: $NonMaybeType<$PropertyType<Service, 'serverOk'>>,
displayName: string,
}
|}

// fully connectable robot
export type Robot = {
export type Robot = {|
...$Exact<ResolvedRobot>,
ok: true,
health: $NonMaybeType<$PropertyType<Service, 'health'>>,
status: ConnectableStatus,
connected: boolean,
}
|}

// robot with a known IP (i.e. advertising over mDNS) but unconnectable
export type ReachableRobot = {
export type ReachableRobot = {|
...$Exact<ResolvedRobot>,
ok: false,
status: ReachableStatus,
}
|}

// robot with an unknown IP
export type UnreachableRobot = {
export type UnreachableRobot = {|
...$Exact<Service>,
displayName: string,
status: UnreachableStatus,
}
|}

export type ViewableRobot = Robot | ReachableRobot

Expand Down
8 changes: 4 additions & 4 deletions app/src/http-api-client/calibration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
// http api client module for /calibration/**
// DEPRECATED(mc, 2020-01-13)
import { createSelector } from 'reselect'

import type { OutputSelector } from 'reselect'
Expand Down Expand Up @@ -68,8 +69,7 @@ export type DeckCalStartState = ApiCall<DeckStartRequest, DeckStartResponse>
export type DeckCalCommandState = ApiCall<DeckCalRequest, DeckCalResponse>

type RobotCalState = {
'calibration/deck/start'?: DeckCalStartState,
'calibration/deck'?: DeckCalCommandState,
[string]: any,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The typing on this state was an illusion and this file is super deprecated, so this just makes the danger more explicit. Unit tests are already in place for this state

}

type CalState = {
Expand All @@ -82,7 +82,7 @@ const DECK_START: 'calibration/deck/start' = 'calibration/deck/start'
// TODO(mc, 2018-07-05): flow helper until we have one reducer, since
// p === 'constant' checks but p === CONSTANT does not, even if
// CONSTANT is defined as `const CONSTANT: 'constant' = 'constant'`
function getCalPath(p: string): ?CalPath {
function getCalPath(p: string): string | null {
if (p === 'calibration/deck/start' || p === 'calibration/deck') return p

return null
Expand Down Expand Up @@ -158,7 +158,7 @@ export function calibrationReducer(state: ?CalState, action: Action): CalState {
}

if (path === DECK_START) {
stateByName[DECK] = {
stateByName[(DECK: string)] = {
request: null,
response: null,
error: null,
Expand Down
Loading