Skip to content

Commit

Permalink
chore(flow): Upgrade flow / most npm typedefs and fix type failures (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Oct 5, 2018
1 parent 4934c47 commit b165b17
Show file tree
Hide file tree
Showing 48 changed files with 2,638 additions and 872 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"homepage": "https://github.com/Opentrons/opentrons",
"devDependencies": {
"flow-bin": "^0.76.0",
"flow-bin": "^0.82.0",
"flow-typed": "^2.5.1"
},
"dependencies": {
Expand Down
3 changes: 1 addition & 2 deletions app/src/components/CalibrateDeck/ConfirmPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ type Props = CalibrateDeckStartedProps & {
export default function ConfirmPosition (props: Props) {
return (
<div>
{/* $FlowFixMe: `...props` type doesn't include necessary keys */}
<Instructions {...props} />
<Instructions calibrationStep={props.calibrationStep} />
<JogControls jog={props.jog} />
<PrimaryButton onClick={props.proceed}>
Save Calibration and Continue
Expand Down
4 changes: 3 additions & 1 deletion app/src/components/CalibrateDeck/Instructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export default function Instructions (props: Props) {
const diagram = getDiagramSrc(calibrationStep)
const instructions = getInstructionsByStep(calibrationStep)

return diagram && instructions && (
if (!diagram || !instructions) return null

return (
<div className={styles.instructions}>
<InstructionStep
step={'one'}
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/controls/LabeledButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import styles from './styles.css'
type Props = {
label: string,
buttonProps: ButtonProps,
children?: React.Node,
children: React.Node,
}

export default function LabeledButton (props: Props) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/controls/LabeledControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styles from './styles.css'
type Props = {
label: string,
control: React.Node,
children?: React.Node,
children: React.Node,
}

export default function LabeledControl (props: Props) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/controls/LabeledToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import styles from './styles.css'
type Props = {
label: string,
toggledOn: boolean,
children?: React.Node,
children: React.Node,
onClick: () => mixed,
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/components/portal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export function getPortalElem () {
return document.getElementById(PORTAL_ROOT_ID)
}

type Props = {children?: React.Node}
type Props = {children: React.Node}

/** The children of Portal are rendered into the
* PortalRoot, if the PortalRoot exists in the DOM */
export function Portal (props: Props): React.Node {
Expand Down
8 changes: 5 additions & 3 deletions app/src/http-api-client/calibration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow
// http api client module for /calibration/**
import {createSelector, type Selector} from 'reselect'
import {createSelector} from 'reselect'

import type {OutputSelector} from 'reselect'
import type {State, Action, ThunkPromiseAction} from '../types'
import type {BaseRobot, RobotService, Mount} from '../robot'
import type {ApiCall, ApiRequestError} from './types'
Expand Down Expand Up @@ -200,7 +202,7 @@ export function calibrationReducer (
}

export function makeGetDeckCalibrationStartState () {
const sel: Selector<State, BaseRobot, DeckCalStartState> = createSelector(
const sel: OutputSelector<State, BaseRobot, DeckCalStartState> = createSelector(
getRobotCalState,
getStartStateFromCalState
)
Expand All @@ -209,7 +211,7 @@ export function makeGetDeckCalibrationStartState () {
}

export function makeGetDeckCalibrationCommandState () {
const sel: Selector<State, BaseRobot, DeckCalCommandState> = createSelector(
const sel: OutputSelector<State, BaseRobot, DeckCalCommandState> = createSelector(
getRobotCalState,
getDeckStateFromCalState
)
Expand Down
5 changes: 3 additions & 2 deletions app/src/http-api-client/health.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @flow
// health http api module
import {createSelector, type Selector} from 'reselect'
import {createSelector} from 'reselect'

import type {OutputSelector} from 'reselect'
import type {State} from '../types'
import type {BaseRobot} from '../robot'
import type {ApiCall} from './types'
Expand Down Expand Up @@ -30,7 +31,7 @@ const HEALTH: 'health' = 'health'
export const fetchHealth = buildRequestMaker('GET', HEALTH)

export const makeGetRobotHealth = () => {
const selector: Selector<State, BaseRobot, FetchHealthCall> = createSelector(
const selector: OutputSelector<State, BaseRobot, FetchHealthCall> = createSelector(
getRobotApiState,
state => state[HEALTH] || {inProgress: false}
)
Expand Down
7 changes: 4 additions & 3 deletions app/src/http-api-client/modules.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @flow
// API client for modules (the robot kind)
import {createSelector, type Selector} from 'reselect'
import {createSelector} from 'reselect'

import type {OutputSelector} from 'reselect'
import type {State, ThunkPromiseAction} from '../types'
import type {BaseRobot, RobotService} from '../robot'
import type {ApiCall, ApiRequestError} from './types'
Expand Down Expand Up @@ -95,7 +96,7 @@ export function fetchModuleData (robot: RobotService, serial: string): ThunkProm
}

export function makeGetRobotModules () {
const selector: Selector<State, BaseRobot, FetchModulesCall> = createSelector(
const selector: OutputSelector<State, BaseRobot, FetchModulesCall> = createSelector(
getRobotApiState,
(state) => state[MODULES] || {inProgress: false}
)
Expand All @@ -104,7 +105,7 @@ export function makeGetRobotModules () {
}

export function makeGetRobotModuleData () {
const selector: Selector<State, BaseRobot, FetchModuleDataCall> = createSelector(
const selector: OutputSelector<State, BaseRobot, FetchModuleDataCall> = createSelector(
(state, robot, _serial) => (getRobotApiState(state, robot)),
(_state, _robot, serial) => serial,
(state, serial) => {
Expand Down
16 changes: 8 additions & 8 deletions app/src/http-api-client/pipettes.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// @flow
// pipette state from api
import {createSelector, type Selector} from 'reselect'

import type {State, ThunkPromiseAction} from '../types'
import type {BaseRobot, RobotService} from '../robot'
import {createSelector} from 'reselect'

import {apiRequest, apiSuccess, apiFailure} from './actions'
import type {ApiCall} from './types'
import type {ApiAction} from './actions'
import {getRobotApiState} from './reducer'
import client from './client'

import type {OutputSelector} from 'reselect'
import type {State, ThunkPromiseAction} from '../types'
import type {BaseRobot, RobotService} from '../robot'
import type {ApiCall, ApiRequestError} from './types'
import type {ApiAction} from './actions'
import type {MotorAxis} from './motors'
import client, {type ApiRequestError} from './client'

// TODO(mc, 2018-03-30): mount, volume, and channels should come from the API
export type Pipette = {
Expand Down Expand Up @@ -57,7 +57,7 @@ export function fetchPipettes (
}

export const makeGetRobotPipettes = () => {
const selector: Selector<State, BaseRobot, RobotPipettes> = createSelector(
const selector: OutputSelector<State, BaseRobot, RobotPipettes> = createSelector(
getRobotApiState,
(state) => state[PIPETTES] || {inProgress: false}
)
Expand Down
7 changes: 4 additions & 3 deletions app/src/http-api-client/reset.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @flow
// API client for getting reset options and resetting robot config files
import {createSelector, type Selector} from 'reselect'
import {createSelector} from 'reselect'

import type {OutputSelector} from 'reselect'
import type {State, ThunkPromiseAction} from '../types'
import type {BaseRobot, RobotService} from '../robot'
import type {ApiCall, ApiRequestError} from './types'
Expand Down Expand Up @@ -70,7 +71,7 @@ export function resetRobotData (robot: RobotService, options: ResetRobotRequest)
}

export function makeGetRobotResetOptions () {
const selector: Selector<State, BaseRobot, FetchResetOptionsCall> = createSelector(
const selector: OutputSelector<State, BaseRobot, FetchResetOptionsCall> = createSelector(
getRobotApiState,
(state) => state[OPTIONS_PATH] || {inProgress: false}
)
Expand All @@ -79,7 +80,7 @@ export function makeGetRobotResetOptions () {
}

export function makeGetRobotResetRequest () {
const selector: Selector<State, BaseRobot, ResetRobotRequest> = createSelector(
const selector: OutputSelector<State, BaseRobot, ResetRobotRequest> = createSelector(
getRobotApiState,
(state) => state[RESET_PATH] || {inProgress: false}
)
Expand Down
9 changes: 5 additions & 4 deletions app/src/http-api-client/robot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @flow
// HTTP API client module for /robot/**
import {createSelector, type Selector} from 'reselect'
import {createSelector} from 'reselect'

import type {OutputSelector} from 'reselect'
import type {PipetteConfig} from '@opentrons/shared-data'
import type {State, ThunkPromiseAction, Action} from '../types'
import type {Mount, BaseRobot, RobotService} from '../robot'
Expand Down Expand Up @@ -282,7 +283,7 @@ export function robotReducer (state: ?RobotState, action: Action): RobotState {
}

export const makeGetRobotMove = () => {
const selector: Selector<State, BaseRobot, RobotMove> = createSelector(
const selector: OutputSelector<State, BaseRobot, RobotMove> = createSelector(
selectRobotState,
(state) => state[MOVE] || {inProgress: false}
)
Expand All @@ -291,7 +292,7 @@ export const makeGetRobotMove = () => {
}

export const makeGetRobotHome = () => {
const selector: Selector<State, BaseRobot, RobotHome> = createSelector(
const selector: OutputSelector<State, BaseRobot, RobotHome> = createSelector(
selectRobotState,
(state) => state[HOME] || {inProgress: false}
)
Expand All @@ -300,7 +301,7 @@ export const makeGetRobotHome = () => {
}

export const makeGetRobotLights = () => {
const selector: Selector<State, BaseRobot, RobotLights> = createSelector(
const selector: OutputSelector<State, BaseRobot, RobotLights> = createSelector(
selectRobotState,
(state) => state[LIGHTS] || {inProgress: false}
)
Expand Down
24 changes: 13 additions & 11 deletions app/src/http-api-client/server.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// @flow
// server endpoints http api module
import {createSelector, type Selector} from 'reselect'
import {createSelector} from 'reselect'
import semver from 'semver'
import {chainActions} from '../util'
import type {State, ThunkPromiseAction, Action} from '../types'
import type {RobotService} from '../robot'

import type {ApiCall} from './types'
import client, {FetchError, type ApiRequestError} from './client'
import {chainActions} from '../util'
import client, {FetchError} from './client'
import {fetchHealth, makeGetRobotHealth} from './health'
import {
getApiUpdateVersion,
getApiUpdateFilename,
getApiUpdateContents,
} from '../shell'

import type {OutputSelector} from 'reselect'
import type {State, ThunkPromiseAction, Action} from '../types'
import type {RobotService} from '../robot'
import type {ApiCall, ApiRequestError} from './types'

type RequestPath = 'update' | 'restart' | 'update/ignore'

export type ServerUpdateResponse = {
Expand Down Expand Up @@ -246,7 +248,7 @@ export type RobotUpdateType = 'upgrade' | 'downgrade' | null
export type RobotUpdateInfo = {version: string, type: RobotUpdateType}

export const makeGetRobotUpdateInfo = () => {
const selector: Selector<State, RobotService, RobotUpdateInfo> = createSelector(
const selector: OutputSelector<State, RobotService, RobotUpdateInfo> = createSelector(
makeGetRobotHealth(),
getApiUpdateVersion,
(health, updateVersion) => {
Expand All @@ -271,7 +273,7 @@ export const makeGetRobotUpdateInfo = () => {
// TODO(mc, 2018-09-25): this is broken until some planned discovery work is
// done for https://github.com/Opentrons/opentrons/milestone/68
export const makeGetRobotUpdateRequest = () => {
const selector: Selector<State,
const selector: OutputSelector<State,
RobotService,
RobotServerUpdate> = createSelector(
selectRobotServerState,
Expand All @@ -282,7 +284,7 @@ export const makeGetRobotUpdateRequest = () => {
}

export const makeGetRobotRestartRequest = () => {
const selector: Selector<State,
const selector: OutputSelector<State,
RobotService,
RobotServerRestart> = createSelector(
selectRobotServerState,
Expand All @@ -293,7 +295,7 @@ export const makeGetRobotRestartRequest = () => {
}

export const makeGetRobotIgnoredUpdateRequest = () => {
const selector: Selector<State,
const selector: OutputSelector<State,
RobotService,
RobotServerUpdateIgnore> = createSelector(
selectRobotServerState,
Expand All @@ -303,7 +305,7 @@ export const makeGetRobotIgnoredUpdateRequest = () => {
return selector
}

export const getAnyRobotUpdateAvailable: Selector<State,
export const getAnyRobotUpdateAvailable: OutputSelector<State,
void,
boolean> = createSelector(selectServerState, state =>
Object.keys(state).some(name => state[name].availableUpdate)
Expand Down
5 changes: 3 additions & 2 deletions app/src/http-api-client/settings.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @flow
// robot settings endpoints
import {createSelector, type Selector} from 'reselect'
import {createSelector} from 'reselect'

import {buildRequestMaker} from './actions'
import {getRobotApiState} from './reducer'

import type {OutputSelector} from 'reselect'
import type {State} from '../types'
import type {BaseRobot} from '../robot'
import type {ApiCall} from './types'
Expand Down Expand Up @@ -45,7 +46,7 @@ export const setSettings: SettingsRequestMaker =
buildRequestMaker('POST', SETTINGS)

export function makeGetRobotSettings () {
const selector: Selector<State, BaseRobot, RobotSettingsCall> =
const selector: OutputSelector<State, BaseRobot, RobotSettingsCall> =
createSelector(getRobotApiState, getSettingsRequest)

return selector
Expand Down
6 changes: 3 additions & 3 deletions app/src/protocol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
filenameToType,
} from './protocol-data'

import type {Selector} from 'reselect'
import type {OutputSelector} from 'reselect'
import type {State, Action, ThunkAction} from '../types'
import type {ProtocolState, ProtocolFile, ProtocolData} from './types'

Expand Down Expand Up @@ -92,8 +92,8 @@ export function protocolReducer (

type StringGetter = (?ProtocolData) => ?string
type NumberGetter = (?ProtocolData) => ?number
type StringSelector = Selector<State, void, ?string>
type NumberSelector = Selector<State, void, ?number>
type StringSelector = OutputSelector<State, void, ?string>
type NumberSelector = OutputSelector<State, void, ?number>

const getName: StringGetter = getter('metadata.protocol-name')
const getAuthor: StringGetter = getter('metadata.author')
Expand Down
Loading

0 comments on commit b165b17

Please sign in to comment.