<commit_before>// @flow
// nav button container
import {connect} from 'react-redux'
import {withRouter} from 'react-router'

import type {State} from '../../types'

import {
  selectors as robotSelectors,
  constants as robotConstants
} from '../../robot'

import type {IconName} from '@opentrons/components'
import {NavButton, FILE, CALIBRATE, CONNECT, RUN, MORE} from '@opentrons/components'

type OwnProps = {
  name: string
}

type StateProps = {
  iconName: IconName,
  title: string,
  url: string
}

export default withRouter(connect(mapStateToProps)(NavButton))

function mapStateToProps (state: State, ownProps: OwnProps): StateProps {
  const {name} = ownProps
  const isSessionLoaded = robotSelectors.getSessionIsLoaded(state)
  const nextInstrument = robotSelectors.getNextInstrument(state)
  const labware = robotSelectors.getNotTipracks(state)
  const nextLabware = robotSelectors.getNextLabware(state)
  const isTipsProbed = robotSelectors.getInstrumentsCalibrated(state)
  const isRunning = robotSelectors.getIsRunning(state)
  const isConnected = (
    robotSelectors.getConnectionStatus(state) === robotConstants.CONNECTED
  )

  // TODO(mc, 2018-03-08): move this logic to the Calibrate page
  let calibrateUrl
  if (isSessionLoaded) {
    calibrateUrl = '/calibrate/instruments'

    if (!isTipsProbed && nextInstrument) {
      calibrateUrl = `/calibrate/instruments/${nextInstrument.mount}`
    } else if (nextLabware) {
      calibrateUrl = `/calibrate/labware/${nextLabware.slot}`
    } else if (labware[0]) {
      calibrateUrl = `/calibrate/labware/${labware[0].slot}`
    }
  }

  const NAV_ITEM_BY_NAME = {
    connect: {
      iconName: CONNECT,
      title: 'robot',
      url: '/robots'
    },
    upload: {
      disabled: !isConnected || isRunning,
      iconName: FILE,
      title: 'protocol',
      url: '/upload'
    },
    setup: {
      disabled: !isSessionLoaded || isRunning,
      iconName: CALIBRATE,
      title: 'calibrate',
      url: calibrateUrl
    },
    run: {
      disabled: !isTipsProbed,
      iconName: RUN,
      title: 'run',
      url: '/run'
    },
    more: {
      iconName: MORE,
      isBottom: true,
      title: 'more',
      url: '/menu/app'
    }
  }

  return NAV_ITEM_BY_NAME[name]
}<commit_msg>feat(app): Display notification in navbar if robot update available<commit_after>// @flow
// nav button container
import * as React from 'react'
import {connect} from 'react-redux'
import {withRouter} from 'react-router'

import type {State} from '../../types'

import {
  selectors as robotSelectors,
  constants as robotConstants
} from '../../robot'
import {getAnyRobotUpdateAvailable} from '../../http-api-client'

import type {IconName} from '@opentrons/components'
import {NavButton, FILE, CALIBRATE, CONNECT, RUN, MORE} from '@opentrons/components'

type OwnProps = {
  name: string
}

type StateProps = {
  iconName: IconName,
  title?: string,
  url?: string
}

export default withRouter(connect(mapStateToProps)(NavButton))

function mapStateToProps (state: State, ownProps: OwnProps): StateProps {
  const {name} = ownProps
  const isSessionLoaded = robotSelectors.getSessionIsLoaded(state)
  const nextInstrument = robotSelectors.getNextInstrument(state)
  const labware = robotSelectors.getNotTipracks(state)
  const nextLabware = robotSelectors.getNextLabware(state)
  const isTipsProbed = robotSelectors.getInstrumentsCalibrated(state)
  const isRunning = robotSelectors.getIsRunning(state)
  const isConnected = (
    robotSelectors.getConnectionStatus(state) === robotConstants.CONNECTED
  )
  const robotNotification = getAnyRobotUpdateAvailable(state)

  // TODO(mc, 2018-03-08): move this logic to the Calibrate page
  let calibrateUrl
  if (isSessionLoaded) {
    calibrateUrl = '/calibrate/instruments'

    if (!isTipsProbed && nextInstrument) {
      calibrateUrl = `/calibrate/instruments/${nextInstrument.mount}`
    } else if (nextLabware) {
      calibrateUrl = `/calibrate/labware/${nextLabware.slot}`
    } else if (labware[0]) {
      calibrateUrl = `/calibrate/labware/${labware[0].slot}`
    }
  }

  const NAV_ITEM_BY_NAME: {[string]: React.ElementProps<typeof NavButton>} = {
    connect: {
      iconName: CONNECT,
      title: 'robot',
      url: '/robots',
      notification: robotNotification
    },
    upload: {
      disabled: !isConnected || isRunning,
      iconName: FILE,
      title: 'protocol',
      url: '/upload'
    },
    setup: {
      disabled: !isSessionLoaded || isRunning,
      iconName: CALIBRATE,
      title: 'calibrate',
      url: calibrateUrl
    },
    run: {
      disabled: !isTipsProbed,
      iconName: RUN,
      title: 'run',
      url: '/run'
    },
    more: {
      iconName: MORE,
      isBottom: true,
      title: 'more',
      url: '/menu/app'
    }
  }

  return NAV_ITEM_BY_NAME[name]
}
{'fraction_non_alphanumeric': 0.11959445478998551, 'fraction_numerical': 0.004138216428719222, 'mean_word_length': 3.463527239150508, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '961389', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1569, 'n_words': 359}