import React from 'react'; import classnames from 'classnames'; import { connect } from 'react-redux'; import translate from 'translations'; import CustomNodeModal from 'components/CustomNodeModal'; import { TChangeNodeIntent, TAddCustomNode, TRemoveCustomNode, changeNodeIntent, addCustomNode, removeCustomNode, AddCustomNodeAction } from 'actions/config'; import { isNodeChanging, getNodeId, CustomNodeOption, NodeOption, getNodeOptions } from 'selectors/config'; import { AppState } from 'reducers'; import './NodeSelect.scss'; interface OwnProps { closePanel(): void; } interface StateProps { nodeSelection: AppState['config']['nodes']['selectedNode']['nodeId']; isChangingNode: AppState['config']['nodes']['selectedNode']['pending']; nodeOptions: (CustomNodeOption | NodeOption)[]; } interface DispatchProps { changeNodeIntent: TChangeNodeIntent; addCustomNode: TAddCustomNode; removeCustomNode: TRemoveCustomNode; } type Props = OwnProps & StateProps & DispatchProps; interface State { isAddingCustomNode: boolean; } class NodeSelect extends React.Component { public state: State = { isAddingCustomNode: false }; public render() { const { nodeSelection, nodeOptions } = this.props; const { isAddingCustomNode } = this.state; return (
{nodeOptions.map(node => ( ))}
); } private handleNodeSelect = (node: string) => { this.props.changeNodeIntent(node); this.props.closePanel(); }; private renderNodeLabel(node: CustomNodeOption | NodeOption) { return node.isCustom ? ( {node.label.network} - {node.label.nodeName} (custom) ) : ( {node.label.network} - ({node.label.service}) ); } private openCustomNodeModal = () => { this.setState({ isAddingCustomNode: true }); }; private closeCustomNodeModal = () => { this.setState({ isAddingCustomNode: false }); }; private addCustomNode = (payload: AddCustomNodeAction['payload']) => { this.props.addCustomNode(payload); this.closeCustomNodeModal(); }; } export default connect( (state: AppState): StateProps => ({ isChangingNode: isNodeChanging(state), nodeSelection: getNodeId(state), nodeOptions: getNodeOptions(state) }), { changeNodeIntent, addCustomNode, removeCustomNode } )(NodeSelect);