From 5935347bab01114e6ecc73617bd92097e6f9d9ee Mon Sep 17 00:00:00 2001 From: Kadee80 Date: Fri, 29 Mar 2019 15:20:40 -0400 Subject: [PATCH] feat(app): Enable adding manual robot IP addresses in app settings closes #2741 --- .../AppSettings/AddManualIp/IpField.js | 2 +- .../AppSettings/AddManualIp/IpItem.js | 21 +++++++++++-- .../AppSettings/AddManualIp/IpList.js | 25 +++++++++++++--- .../AppSettings/AddManualIp/ManualIpForm.js | 6 +++- .../AppSettings/AddManualIp/styles.css | 27 +++++++++-------- .../AppSettings/AdvancedSettingsCard.js | 30 ++++++++----------- app/src/components/ConnectPanel/index.js | 8 +++-- 7 files changed, 78 insertions(+), 41 deletions(-) diff --git a/app/src/components/AppSettings/AddManualIp/IpField.js b/app/src/components/AppSettings/AddManualIp/IpField.js index 9a6eeafafbe..f9b7fbecb9b 100644 --- a/app/src/components/AppSettings/AddManualIp/IpField.js +++ b/app/src/components/AppSettings/AddManualIp/IpField.js @@ -24,7 +24,7 @@ export default function IpField (props: Props) { ref={inputRef} /> mixed, } export default class IpItem extends React.Component { remove = () => this.props.removeIp(this.props.candidate) render () { + const iconName = this.props.discovered ? 'check' : 'ot-spinner' return (
{this.props.candidate}
+ @@ -21,3 +26,15 @@ export default class IpItem extends React.Component { ) } } + +type DiscoveryIconProps = { + iconName: IconName, +} +function DiscoveryIcon (props: DiscoveryIconProps) { + const spin = props.iconName === 'ot-spinner' + return ( +
+ +
+ ) +} diff --git a/app/src/components/AppSettings/AddManualIp/IpList.js b/app/src/components/AppSettings/AddManualIp/IpList.js index 1f89307aba1..366b52f19a0 100644 --- a/app/src/components/AppSettings/AddManualIp/IpList.js +++ b/app/src/components/AppSettings/AddManualIp/IpList.js @@ -1,14 +1,19 @@ // @flow import * as React from 'react' import {connect} from 'react-redux' +import find from 'lodash/find' import {getConfig, removeManualIp} from '../../../config' +import {getConnectableRobots, getReachableRobots} from '../../../discovery' import type {State, Dispatch} from '../../../types' import type {DiscoveryCandidates} from '../../../config' +import type {Robot, ReachableRobot} from '../../../discovery' import IpItem from './IpItem' type SP = {| + connectableRobots: Array, + reachableRobots: Array, candidates: DiscoveryCandidates, |} @@ -19,13 +24,23 @@ type DP = {| type Props = {...SP, ...DP} function IpList (props: Props) { - const {candidates, removeManualIp} = props + const {candidates, removeManualIp, connectableRobots, reachableRobots} = props const candidateList = [].concat(candidates) + const robots = connectableRobots.concat(reachableRobots) + console.log(robots) return (
- {candidateList.map((c, index) => ( - - ))} + {candidateList.map((c, index) => { + const discovered = !!find(robots, r => r.ip === c) + return ( + + ) + })}
) } @@ -37,6 +52,8 @@ export default connect( function STP (state: State): SP { return { + connectableRobots: getConnectableRobots(state), + reachableRobots: getReachableRobots(state), candidates: getConfig(state).discovery.candidates, } } diff --git a/app/src/components/AppSettings/AddManualIp/ManualIpForm.js b/app/src/components/AppSettings/AddManualIp/ManualIpForm.js index efb3b87dc3f..86e899d88aa 100644 --- a/app/src/components/AppSettings/AddManualIp/ManualIpForm.js +++ b/app/src/components/AppSettings/AddManualIp/ManualIpForm.js @@ -2,6 +2,7 @@ import * as React from 'react' import {connect} from 'react-redux' import {getConfig, addManualIp} from '../../../config' +import {startDiscovery} from '../../../discovery' import {Formik, Form, Field} from 'formik' import IpField from './IpField' @@ -62,6 +63,9 @@ function STP (state: State): SP { function DTP (dispatch: Dispatch): DP { return { - addManualIp: ip => dispatch(addManualIp(ip)), + addManualIp: ip => { + dispatch(addManualIp(ip)) + dispatch(startDiscovery()) + }, } } diff --git a/app/src/components/AppSettings/AddManualIp/styles.css b/app/src/components/AppSettings/AddManualIp/styles.css index b625ea8381c..de5bb52310a 100644 --- a/app/src/components/AppSettings/AddManualIp/styles.css +++ b/app/src/components/AppSettings/AddManualIp/styles.css @@ -1,18 +1,6 @@ @import '@opentrons/components'; :root { - --ip-group: { - display: flex; - justify-content: flex-start; - border: 1px solid var(--c-med-gray); - height: 2rem; - - &:focus-within { - background-color: var(--c-white); - box-shadow: 0 0.125rem 0.25rem 0 color(var(--c-black) alpha(0.5)); - } - } - --ip-item: { flex: 1 0 100%; padding: 0 1rem; @@ -40,7 +28,7 @@ } } -.ip_button { +.add_ip_button { padding: 0.25rem; flex: 0 0 2rem; border-radius: 0; @@ -66,4 +54,17 @@ .ip_item { @apply --ip-item; + + flex: 1 1 calc(100% - 4rem); +} + +.remove_ip_button { + padding: 0.25rem; + flex: 0 0 2rem; + border-radius: 0; +} + +.discovery_icon { + padding: 0.5rem; + flex: 0 0 2rem; } diff --git a/app/src/components/AppSettings/AdvancedSettingsCard.js b/app/src/components/AppSettings/AdvancedSettingsCard.js index efb42483881..8e660625a1d 100644 --- a/app/src/components/AppSettings/AdvancedSettingsCard.js +++ b/app/src/components/AppSettings/AdvancedSettingsCard.js @@ -21,7 +21,6 @@ type OP = { type SP = {| devToolsOn: boolean, channel: UpdateChannel, - __ffShowManualIp: boolean, |} type DP = {| @@ -74,21 +73,19 @@ function AdvancedSettingsCard (props: Props) { logging.

- {props.__ffShowManualIp && ( - -

- If your app is unable to automatically discover your robot, you - can manually add its IP address or hostname here -

-
- )} + +

+ If your app is unable to automatically discover your robot, you can + manually add its IP address or hostname here +

+
- {props.robots.map(robot => )} + {props.robots.map(robot => ( + + ))} {props.reachableRobots.map(robot => ( ))}