diff --git a/webui/src/ConfigTabs.js b/webui/src/ConfigTabs.js index 34662a9..ffbb22f 100644 --- a/webui/src/ConfigTabs.js +++ b/webui/src/ConfigTabs.js @@ -31,7 +31,7 @@ require('./styles.css'); class ConfigTabs extends Component { static propTypes = { - currentTab: PropTypes.func.isRequired + currentTab: PropTypes.string.isRequired }; render() { diff --git a/webui/src/PTP.js b/webui/src/PTP.js index 252848f..c538ede 100644 --- a/webui/src/PTP.js +++ b/webui/src/PTP.js @@ -19,6 +19,7 @@ // import React, {Component} from 'react'; +import PropTypes from 'prop-types'; import {toast} from 'react-toastify'; import RestAPI from './Services'; @@ -26,21 +27,112 @@ import Loader from './Loader'; require('./styles.css'); + +class PTPConfig extends Component { + static propTypes = { + domain: PropTypes.number.isRequired, + dscp: PropTypes.number.isRequired, + }; + + constructor(props) { + super(props); + this.state = { + domain: this.props.domain, + dscp: this.props.dscp, + domainErr: false, + }; + this.onSubmit = this.onSubmit.bind(this); + this.inputIsValid = this.inputIsValid.bind(this); + } + + inputIsValid() { + return !this.state.domainErr; + } + + onSubmit(event) { + event.preventDefault(); + RestAPI.setPTPConfig(this.state.domain, this.state.dscp) + .then(response => toast.success('PTP config updated')); + } + + render() { + return ( +
+

Config

+ + + + + + + + + + + + + + + + +
this.setState({domain: e.target.value, domainErr: !e.currentTarget.checkValidity()})} required/>
+ +
+
+ ) + } +} + +class PTPStatus extends Component { + static propTypes = { + status: PropTypes.string.isRequired, + gmid: PropTypes.string.isRequired, + jitter: PropTypes.number.isRequired, + }; + + render() { + return ( +
+

Status

+ + + + + + + + + + + + + + + + + +
+
+ ) + } +} + class PTP extends Component { constructor(props) { super(props); this.state = { - domain: '', + domain: 0, domainErr: false, - dscp: '', + dscp: 0, status: '', gmid: '', - jitter: '', + jitter: 0, isConfigLoading: false, isStatusLoading: false, }; - this.onSubmit = this.onSubmit.bind(this); - this.inputIsValid = this.inputIsValid.bind(this); } fetchStatus() { @@ -51,21 +143,28 @@ class PTP extends Component { data => this.setState({ status: data.status, gmid: data.gmid, - jitter: data.jitter, + jitter: parseInt(data.jitter, 10), isStatusLoading: false })) .catch(err => this.setState({isStatusLoading: false})); } - - componentDidMount() { + + fetchConfig() { this.setState({isConfigLoading: true}); RestAPI.getPTPConfig() .then(response => response.json()) - .then(data => - this.setState({domain: data.domain, dscp: data.dscp, isConfigLoading: false})) + .then( + data => this.setState({ + domain: parseInt(data.domain, 10), + dscp: parseInt(data.dscp, 10), + isConfigLoading: false + })) .catch(err => this.setState({isConfigLoading: false})); - + } + + componentDidMount() { this.fetchStatus(); + this.fetchConfig(); this.interval = setInterval(() => { this.fetchStatus() }, 10000) } @@ -73,63 +172,14 @@ class PTP extends Component { clearInterval(this.interval); } - inputIsValid() { - return !this.state.domainErr && - !this.state.isConfigLoading; - } - - onSubmit(event) { - event.preventDefault(); - RestAPI.setPTPConfig(this.state.domain, this.state.dscp) - .then(response => toast.success('PTP config updated')); - } - render() { return (
- {this.state.isConfigLoading ? :

Config

} - - - - - - - - - - - - - - - - -
this.setState({domain: e.target.value, domainErr: !e.currentTarget.checkValidity()})} required/>
- -
+ { this.state.isConfigLoading ? : + }
- { this.state.isStatusLoading ? :

Status

} - - - - - - - - - - - - - - - - - -
+ { this.state.isStatusLoading ? : + }
) }