import React from 'react'; import {Component} from 'react'; import './AddMount.css'; import {connect} from 'react-redux'; import Button from '../../components/UI/Button/Button'; import Box from '../../components/UI/Box/Box'; import Text from '../../components/UI/Text/Text'; import {notifyError} from '../../redux/actions/error_actions'; import {addRemoteMount, addS3Mount} from '../../redux/actions/mount_actions'; import {createModalConditionally} from '../../utils'; import DropDown from '../../components/UI/DropDown/DropDown'; import * as Constants from '../../constants'; const mapStateToProps = state => { return { RemoteMounts: state.mounts.RemoteMounts, S3Mounts: state.mounts.S3Mounts, }; }; const mapDispatchToProps = dispatch => { return { addRemoteMount: (hostNameOrIp, port, token) => dispatch(addRemoteMount(hostNameOrIp, port, token)), addS3Mount: (name, accessKey, secretKey, region, bucketName, url) => dispatch(addS3Mount(name, accessKey, secretKey, region, bucketName, url)), notifyError: (msg, critical, callback) => dispatch(notifyError(msg, critical, callback)), } }; const default_state = { AccessKey: '', BucketName: '', DisplayRemote: false, DisplayS3: false, HostNameOrIp: '', Name: '', Port: 20000, Provider: Constants.S3_PROVIDER_LIST[0], Region: 'any', SecretKey: '', Token: '', }; export default connect(mapStateToProps, mapDispatchToProps)(class extends Component { state = { ...default_state, }; addRemoteMount = () => { if (this.state.HostNameOrIp.length === 0) { this.props.notifyError('Hostname or IP cannot be empty.'); } else { const provider = 'Remote' + this.state.HostNameOrIp + ':' + this.state.Port; if (this.props.RemoteMounts.includes(provider)) { this.props.notifyError('Remote host already exists'); } else { this.setState({ DisplayRemote: false }, () => { this.props.addRemoteMount(this.state.HostNameOrIp, this.state.Port, this.state.Token); this.setState({ ...default_state, }); }); } } }; addS3Mount = () => { if (this.state.Name.length === 0) { this.props.notifyError('Name cannot be empty.'); } else if (this.state.AccessKey.length === 0) { this.props.notifyError('AccessKey cannot be empty.'); } else if (this.state.SecretKey.length === 0) { this.props.notifyError('SecretKey cannot be empty.') } else { const provider = 'S3' + this.state.Name; if (this.props.S3Mounts.includes(provider)) { this.props.notifyError('Remote host already exists'); } else { this.setState({ DisplayS3: false }, () => { this.props.addS3Mount(this.state.Name, this.state.AccessKey, this.state.SecretKey, this.state.Region, this.state.BucketName, Constants.S3_PROVIDER_URL[this.state.Provider]); this.setState({ ...default_state, }); }); } } }; handleAddS3Mount = () => { this.setState({ DisplayRemote: false, DisplayS3: true, }); }; handleAddRemoteMount = () => { this.setState({ DisplayRemote: true, DisplayS3: false, }); }; render() { const displayAddRemote = createModalConditionally(this.state.DisplayRemote, (

Add Remote Mount

this.setState({HostNameOrIp: e.target.value.trim()})} className={'ConfigurationItemInput'} type={'text'} value={this.state.HostNameOrIp}/>
this.setState({Port: e.target.value})} className={'ConfigurationItemInput'} type={'number'} value={this.state.Port}/>
this.setState({Token: e.target.value})} className={'ConfigurationItemInput'} type={'text'} value={this.state.Token}/>
)); const displayAddS3 = createModalConditionally(this.state.DisplayS3, (

Add S3 Mount

this.setState({Name: e.target.value.trim()})} className={'ConfigurationItemInput'} style={{width: '100%'}} type={'text'} value={this.state.Name}/>
this.setState({Provider: e.target.value})} items={Constants.S3_PROVIDER_LIST} selected={this.state.Provider}/>
this.setState({BucketName: e.target.value})} className={'ConfigurationItemInput'} style={{width: '100%'}} type={'text'} value={this.state.BucketName}/>
this.setState({Region: e.target.value})} className={'ConfigurationItemInput'} type={'text'} value={this.state.Region}/>
this.setState({AccessKey: e.target.value})} className={'ConfigurationItemInput'} type={'text'} value={this.state.AccessKey}/>
this.setState({SecretKey: e.target.value})} className={'ConfigurationItemInput'} type={'text'} value={this.state.SecretKey}/>
)); return (
{displayAddRemote} {displayAddS3}
{this.props.remoteSupported ? : null} {this.props.remoteSupported && this.props.s3Supported ?
: null} {this.props.s3Supported ? : null}
); } });