Browse Source

feature(selectedPeers): allow selected peers to be added or removed

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
88e4f4313c
  1. 4
      app/components/GlobalError/GlobalError.scss
  2. 8
      app/components/Network/NetworkGraph.js
  3. 43
      app/components/Network/NetworkGraph.scss
  4. 6
      app/components/Network/PeersList.js
  5. 37
      app/reducers/network.js
  6. 12
      app/routes/network/components/Network.js
  7. 10
      app/routes/network/containers/NetworkContainer.js

4
app/components/GlobalError/GlobalError.scss

@ -13,6 +13,10 @@
&.closed { &.closed {
max-height: 0; max-height: 0;
padding: 0; padding: 0;
.content .close {
opacity: 0;
}
} }
.content { .content {

8
app/components/Network/NetworkGraph.js

@ -22,6 +22,7 @@ class NetworkGraph extends Component {
const { ready } = this.state const { ready } = this.state
const { const {
network: { nodes, edges, selectedChannel, networkLoading }, network: { nodes, edges, selectedChannel, networkLoading },
selectedPeerPubkeys,
identity_pubkey, identity_pubkey,
} = this.props } = this.props
@ -53,16 +54,17 @@ class NetworkGraph extends Component {
zoomOptions={{ minScale: 0.1, maxScale: 5, scale: 0.2 }} zoomOptions={{ minScale: 0.1, maxScale: 5, scale: 0.2 }}
zoom zoom
> >
<path d="M534.7054286266647, 460.3260926684966" fill="red" stroke="blue" />
{ {
nodes.map(node => { nodes.map(node => {
return ( return (
<ForceGraphNode <ForceGraphNode
r={15} r={25}
label={node.pub_key} label={node.pub_key}
key={node.pub_key} key={node.pub_key}
node={{ id: node.pub_key }} node={{ id: node.pub_key }}
fill={identity_pubkey === node.pub_key ? 'white' : 'black'} fill={selectedPeerPubkeys.includes(node.pub_key) ? '#5589F3' : '#353535'}
strokeWidth={2.5}
className={styles.node}
/> />
) )
}) })

43
app/components/Network/NetworkGraph.scss

@ -26,25 +26,30 @@
} }
} }
.container { // .container {
width: 100%; // width: 100%;
height: 100vh; // height: 100vh;
animation: fadein 0.5s; // animation: fadein 0.5s;
animation-timing-function:linear; // animation-timing-function:linear;
animation-fill-mode:forwards; // animation-fill-mode:forwards;
animation-iteration-count: 1; // animation-iteration-count: 1;
line.active { // line.active {
opacity: 1; // opacity: 1;
stroke: green; // stroke: green;
stroke-width: 5; // stroke-width: 5;
stroke-dasharray: 100; // stroke-dasharray: 100;
animation: dash 2.5s infinite linear; // animation: dash 2.5s infinite linear;
} // }
circle { // circle {
cursor: pointer; // cursor: pointer;
} // stroke-width: 2 !important;
// }
// }
.node {
stroke-width: 2 !important;
} }
.network { .network {

6
app/components/Network/PeersList.js

@ -2,12 +2,12 @@ import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import styles from './PeersList.scss' import styles from './PeersList.scss'
const PeersList = ({ peers }) => ( const PeersList = ({ peers, updateSelectedPeers, selectedPeerPubkeys }) => (
<ul className={styles.peers}> <ul className={styles.peers}>
{ {
peers.map(peer => peers.map(peer =>
<li key={peer.peer_id} className={styles.peer}> <li key={peer.peer_id} className={styles.peer} onClick={() => updateSelectedPeers(peer)}>
<span className={styles.dot} /> <span className={`${styles.dot} ${selectedPeerPubkeys.includes(peer.pub_key) && styles.active}`} />
<h1>{peer.address}</h1> <h1>{peer.address}</h1>
<h4>{peer.pub_key}</h4> <h4>{peer.pub_key}</h4>
</li> </li>

37
app/reducers/network.js

@ -20,6 +20,8 @@ export const SET_CURRENT_PEER = 'SET_CURRENT_PEER'
export const UPDATE_PAY_REQ = 'UPDATE_PAY_REQ' export const UPDATE_PAY_REQ = 'UPDATE_PAY_REQ'
export const UPDATE_SELECTED_PEERS = 'UPDATE_SELECTED_PEERS'
// ------------------------------------ // ------------------------------------
// Actions // Actions
// ------------------------------------ // ------------------------------------
@ -71,6 +73,13 @@ export function updatePayReq(pay_req) {
} }
} }
export function updateSelectedPeers(peer) {
return {
type: UPDATE_SELECTED_PEERS,
peer
}
}
// Send IPC event for describeNetwork // Send IPC event for describeNetwork
export const fetchDescribeNetwork = () => (dispatch) => { export const fetchDescribeNetwork = () => (dispatch) => {
dispatch(getDescribeNetwork()) dispatch(getDescribeNetwork())
@ -116,7 +125,23 @@ const ACTION_HANDLERS = {
[SET_CURRENT_PEER]: (state, { currentPeer }) => ({ ...state, currentPeer }), [SET_CURRENT_PEER]: (state, { currentPeer }) => ({ ...state, currentPeer }),
[UPDATE_PAY_REQ]: (state, { pay_req }) => ({ ...state, pay_req }) [UPDATE_PAY_REQ]: (state, { pay_req }) => ({ ...state, pay_req }),
[UPDATE_SELECTED_PEERS]: (state, { peer }) => {
let selectedPeers
if (state.selectedPeers.includes(peer)) {
selectedPeers = state.selectedPeers.filter(selectedPeer => selectedPeer.pub_key !== peer.pub_key)
}
if (!state.selectedPeers.includes(peer)) {
selectedPeers = [...state.selectedPeers, peer]
}
return {
...state, selectedPeers
}
}
} }
// ------------------------------------ // ------------------------------------
@ -124,6 +149,7 @@ const ACTION_HANDLERS = {
// ------------------------------------ // ------------------------------------
const networkSelectors = {} const networkSelectors = {}
const currentRouteSelector = state => state.network.selectedNode.currentRoute const currentRouteSelector = state => state.network.selectedNode.currentRoute
const selectedPeers = state => state.network.selectedPeers
networkSelectors.currentRouteHopChanIds = createSelector( networkSelectors.currentRouteHopChanIds = createSelector(
currentRouteSelector, currentRouteSelector,
@ -134,6 +160,11 @@ networkSelectors.currentRouteHopChanIds = createSelector(
} }
) )
networkSelectors.selectedPeerPubkeys = createSelector(
selectedPeers,
peers => peers.map(peer => peer.pub_key)
)
export { networkSelectors } export { networkSelectors }
// ------------------------------------ // ------------------------------------
@ -154,7 +185,9 @@ const initialState = {
currentPeer: {}, currentPeer: {},
pay_req: '' pay_req: '',
selectedPeers: []
} }

12
app/routes/network/components/Network.js

@ -19,8 +19,11 @@ class Network extends Component {
render() { render() {
const { const {
setCurrentTab, setCurrentTab,
updateSelectedPeers,
network, network,
selectedPeerPubkeys,
peers: { peers }, peers: { peers },
identity_pubkey identity_pubkey
} = this.props } = this.props
@ -28,7 +31,7 @@ class Network extends Component {
const renderContent = () => { const renderContent = () => {
switch(network.currentTab) { switch(network.currentTab) {
case 1: case 1:
return <PeersList peers={peers} /> return <PeersList peers={peers} updateSelectedPeers={updateSelectedPeers} selectedPeerPubkeys={selectedPeerPubkeys} />
break break
case 2: case 2:
return <h1>channels</h1> return <h1>channels</h1>
@ -41,7 +44,12 @@ class Network extends Component {
return ( return (
<div className={styles.container}> <div className={styles.container}>
<NetworkGraph className={styles.network} network={network} identity_pubkey={identity_pubkey} /> <NetworkGraph
className={styles.network}
network={network}
identity_pubkey={identity_pubkey}
selectedPeerPubkeys={selectedPeerPubkeys}
/>
<section className={styles.toolbox}> <section className={styles.toolbox}>
<ul className={styles.tabs}> <ul className={styles.tabs}>

10
app/routes/network/containers/NetworkContainer.js

@ -4,7 +4,10 @@ import { connect } from 'react-redux'
import { import {
fetchDescribeNetwork, fetchDescribeNetwork,
setCurrentTab setCurrentTab,
updateSelectedPeers,
networkSelectors
} from '../../../reducers/network' } from '../../../reducers/network'
import { fetchPeers } from '../../../reducers/peers' import { fetchPeers } from '../../../reducers/peers'
@ -13,6 +16,7 @@ import Network from '../components/Network'
const mapDispatchToProps = { const mapDispatchToProps = {
fetchDescribeNetwork, fetchDescribeNetwork,
setCurrentTab, setCurrentTab,
updateSelectedPeers,
fetchPeers fetchPeers
} }
@ -20,7 +24,9 @@ const mapDispatchToProps = {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
network: state.network, network: state.network,
peers: state.peers, peers: state.peers,
identity_pubkey: state.info.data.identity_pubkey identity_pubkey: state.info.data.identity_pubkey,
selectedPeerPubkeys: networkSelectors.selectedPeerPubkeys(state)
}) })
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Network)) export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Network))

Loading…
Cancel
Save