-
Notifications
You must be signed in to change notification settings - Fork 175
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(app): Add connnect to unsecured on select to ConnectionCard #2504
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
711c80f
refactor(app): Add connnect to unsecured on select to ConnectionCard
mcous df12761
fixup: Add config in progress modal and fix async list result
mcous 87e5583
fixup: Don't display connect spinner if call has errored
mcous 18d0011
fixup: be less clever
mcous File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,30 +6,19 @@ import {getIn} from '@thi.ng/paths' | |||||
import find from 'lodash/find' | ||||||
|
||||||
import {getConfig} from '../../config' | ||||||
import { | ||||||
makeGetRobotNetworkingStatus, | ||||||
makeGetRobotWifiList, | ||||||
} from '../../http-api-client' | ||||||
import {RefreshCard} from '@opentrons/components' | ||||||
import { | ||||||
ConnectionStatusMessage, | ||||||
ConnectionInfo, | ||||||
AvailableNetworks, | ||||||
} from './connection' | ||||||
import {makeGetRobotNetworkingStatus} from '../../http-api-client' | ||||||
import {Card} from '@opentrons/components' | ||||||
import SelectNetwork from './SelectNetwork' | ||||||
import {ConnectionStatusMessage, ConnectionInfo} from './connection' | ||||||
|
||||||
import type {State} from '../../types' | ||||||
import type {ViewableRobot} from '../../discovery' | ||||||
import type { | ||||||
WifiNetworkList, | ||||||
InternetStatus, | ||||||
NetworkInterface, | ||||||
} from '../../http-api-client' | ||||||
import type {InternetStatus, NetworkInterface} from '../../http-api-client' | ||||||
|
||||||
type OP = {robot: ViewableRobot} | ||||||
|
||||||
type SP = {| | ||||||
__featureEnabled: boolean, | ||||||
wifiList: ?WifiNetworkList, | ||||||
internetStatus: ?InternetStatus, | ||||||
wifiNetwork: ?NetworkInterface, | ||||||
ethernetNetwork: ?NetworkInterface, | ||||||
|
@@ -39,46 +28,40 @@ type Props = {...$Exact<OP>, ...SP} | |||||
|
||||||
const __FEATURE_FLAG = 'devInternal.manageRobotConnection.newCard' | ||||||
|
||||||
export default connect( | ||||||
makeMapStateToProps | ||||||
/* mapDispatchToProps */ | ||||||
)(ConnectionCard) | ||||||
export default connect(makeSTP)(ConnectionCard) | ||||||
|
||||||
const TITLE = 'Connectivity' | ||||||
function ConnectionCard (props: Props) { | ||||||
// TODO(mc, 2018-10-15): remove feature flag | ||||||
if (!props.__featureEnabled) return null | ||||||
|
||||||
const {robot, wifiList, internetStatus, wifiNetwork, ethernetNetwork} = props | ||||||
const {robot, internetStatus, wifiNetwork, ethernetNetwork} = props | ||||||
|
||||||
return ( | ||||||
<RefreshCard title={TITLE} refresh={() => console.log('placeholder')}> | ||||||
<Card title={TITLE}> | ||||||
<ConnectionStatusMessage | ||||||
type={robot.local ? 'USB' : 'Wi-Fi'} | ||||||
status={internetStatus} | ||||||
/> | ||||||
<ConnectionInfo connection={wifiNetwork} title="Wi-Fi"> | ||||||
<AvailableNetworks list={wifiList} /> | ||||||
<SelectNetwork key={robot.name} robot={robot} /> | ||||||
</ConnectionInfo> | ||||||
<ConnectionInfo connection={ethernetNetwork} title="USB" wired /> | ||||||
</RefreshCard> | ||||||
</Card> | ||||||
) | ||||||
} | ||||||
|
||||||
function makeMapStateToProps (): (State, OP) => SP { | ||||||
function makeSTP (): (State, OP) => SP { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const getNetworkingStatusCall = makeGetRobotNetworkingStatus() | ||||||
const getWifiListCall = makeGetRobotWifiList() | ||||||
|
||||||
return (state, ownProps) => { | ||||||
const {robot} = ownProps | ||||||
const {response: statusResponse} = getNetworkingStatusCall(state, robot) | ||||||
const {response: listResponse} = getWifiListCall(state, robot) | ||||||
const internetStatus = statusResponse && statusResponse.status | ||||||
const interfaces = statusResponse && statusResponse.interfaces | ||||||
|
||||||
return { | ||||||
internetStatus, | ||||||
wifiList: listResponse && listResponse.list, | ||||||
wifiNetwork: find(interfaces, {type: 'wifi'}), | ||||||
ethernetNetwork: find(interfaces, {type: 'ethernet'}), | ||||||
__featureEnabled: !!getIn(getConfig(state), __FEATURE_FLAG), | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import {connect} from 'react-redux' | ||
import find from 'lodash/find' | ||
|
||
import { | ||
NO_SECURITY, | ||
fetchWifiList, | ||
configureWifi, | ||
makeGetRobotWifiList, | ||
makeGetRobotWifiConfigure, | ||
} from '../../http-api-client' | ||
import {NetworkDropdown} from './connection' | ||
import {Portal} from '../portal' | ||
import {IntervalWrapper, SpinnerModal} from '@opentrons/components' | ||
|
||
import type {State, Dispatch} from '../../types' | ||
import type {ViewableRobot} from '../../discovery' | ||
import type {WifiNetwork, WifiNetworkList} from '../../http-api-client' | ||
|
||
type OP = {robot: ViewableRobot} | ||
|
||
type SP = {|list: ?WifiNetworkList, connectingTo: ?string|} | ||
|
||
type DP = {| | ||
getList: () => mixed, | ||
configure: (network: WifiNetwork) => mixed, | ||
|} | ||
|
||
type Props = {...$Exact<OP>, ...SP, ...DP} | ||
|
||
type SelectNetworkState = {value: ?string} | ||
|
||
const LIST_REFRESH_MS = 15000 | ||
|
||
class SelectNetwork extends React.Component<Props, SelectNetworkState> { | ||
constructor (props) { | ||
super(props) | ||
// prepopulate selected SSID with currently connected network, if any | ||
this.state = {value: this.getActiveSsid()} | ||
} | ||
|
||
onChange = (network: WifiNetwork) => { | ||
this.setState({value: network.ssid}) | ||
this.props.configure(network) | ||
} | ||
|
||
getActiveSsid (): ?string { | ||
const activeNetwork = find(this.props.list, 'active') | ||
return activeNetwork && activeNetwork.ssid | ||
} | ||
|
||
componentDidUpdate (prevProps) { | ||
// if we don't have a selected network in component state and the list has | ||
// updated, seed component state with active ssid from props | ||
if (!this.state.value && this.props.list !== prevProps.list) { | ||
this.setState({value: this.getActiveSsid()}) | ||
} | ||
} | ||
|
||
render () { | ||
const {list, connectingTo, getList} = this.props | ||
const {value} = this.state | ||
|
||
return ( | ||
<IntervalWrapper refresh={getList} interval={LIST_REFRESH_MS}> | ||
<NetworkDropdown | ||
list={list} | ||
value={value} | ||
disabled={connectingTo != null} | ||
onChange={this.onChange} | ||
/> | ||
{connectingTo && ( | ||
<Portal> | ||
<SpinnerModal | ||
message={`Attempting to connect to network ${connectingTo}`} | ||
/> | ||
</Portal> | ||
)} | ||
</IntervalWrapper> | ||
) | ||
} | ||
} | ||
|
||
function makeSTP (): (State, OP) => SP { | ||
const getWifiListCall = makeGetRobotWifiList() | ||
const getWifiConfigureCall = makeGetRobotWifiConfigure() | ||
|
||
return (state, ownProps) => { | ||
const {robot} = ownProps | ||
const {response: listResponse} = getWifiListCall(state, robot) | ||
const { | ||
request: cfgRequest, | ||
inProgress: cfgInProgress, | ||
} = getWifiConfigureCall(state, robot) | ||
|
||
return { | ||
connectingTo: cfgInProgress && cfgRequest ? cfgRequest.ssid : null, | ||
list: listResponse && listResponse.list, | ||
} | ||
} | ||
} | ||
|
||
function DTP (dispatch: Dispatch, ownProps: OP): DP { | ||
const {robot} = ownProps | ||
|
||
return { | ||
getList: () => dispatch(fetchWifiList(robot)), | ||
configure: network => { | ||
if (network.securityType === NO_SECURITY) { | ||
return dispatch(configureWifi(robot, {ssid: network.ssid})) | ||
} | ||
}, | ||
} | ||
} | ||
|
||
export default connect( | ||
makeSTP, | ||
DTP | ||
)(SelectNetwork) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.