reduce use of ternaries in form code
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
import { AP_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { AP_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
import SectionContent from '../components/SectionContent';
|
||||
import APSettingsForm from '../forms/APSettingsForm';
|
||||
|
||||
@ -12,17 +13,20 @@ class APSettings extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, fetched, errorMessage } = this.props;
|
||||
const { fetched, errorMessage, data, saveData, loadData, handleValueChange } = this.props;
|
||||
return (
|
||||
<SectionContent title="AP Settings">
|
||||
<APSettingsForm
|
||||
apSettings={data}
|
||||
apSettingsFetched={fetched}
|
||||
errorMessage={errorMessage}
|
||||
onSubmit={this.props.saveData}
|
||||
onReset={this.props.loadData}
|
||||
handleValueChange={this.props.handleValueChange}
|
||||
/>
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
<APSettingsForm
|
||||
apSettings={data}
|
||||
onSubmit={saveData}
|
||||
onReset={loadData}
|
||||
handleValueChange={handleValueChange}
|
||||
/>
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ import React, { Component, Fragment } from 'react';
|
||||
|
||||
import { withStyles } from '@material-ui/core/styles';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import LinearProgress from '@material-ui/core/LinearProgress';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
import List from '@material-ui/core/List';
|
||||
import ListItem from '@material-ui/core/ListItem';
|
||||
import ListItemText from '@material-ui/core/ListItemText';
|
||||
@ -15,6 +13,7 @@ import DeviceHubIcon from '@material-ui/icons/DeviceHub';
|
||||
import ComputerIcon from '@material-ui/icons/Computer';
|
||||
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
import SectionContent from '../components/SectionContent'
|
||||
|
||||
import * as Highlight from '../constants/Highlight';
|
||||
@ -27,10 +26,6 @@ const styles = theme => ({
|
||||
["apStatus_" + Highlight.IDLE]: {
|
||||
backgroundColor: theme.palette.highlight_idle
|
||||
},
|
||||
fetching: {
|
||||
margin: theme.spacing(4),
|
||||
textAlign: "center"
|
||||
},
|
||||
button: {
|
||||
marginRight: theme.spacing(2),
|
||||
marginTop: theme.spacing(2),
|
||||
@ -106,30 +101,15 @@ class APStatus extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, fetched, errorMessage, classes } = this.props;
|
||||
|
||||
const { fetched, errorMessage, data, loadData, classes } = this.props;
|
||||
return (
|
||||
<SectionContent title="AP Status">
|
||||
{
|
||||
!fetched ?
|
||||
<div>
|
||||
<LinearProgress className={classes.fetching} />
|
||||
<Typography variant="h4" className={classes.fetching}>
|
||||
Loading...
|
||||
</Typography>
|
||||
</div>
|
||||
:
|
||||
data ? this.renderAPStatus(data, classes)
|
||||
:
|
||||
<div>
|
||||
<Typography variant="h4" className={classes.fetching}>
|
||||
{errorMessage}
|
||||
</Typography>
|
||||
<Button variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}>
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
{this.renderAPStatus(data, classes)}
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
}
|
||||
|
@ -2,8 +2,9 @@ import React, { Component } from 'react';
|
||||
|
||||
import { SECURITY_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import ManageUsersForm from '../forms/ManageUsersForm';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
import SectionContent from '../components/SectionContent';
|
||||
import ManageUsersForm from '../forms/ManageUsersForm';
|
||||
|
||||
class ManageUsers extends Component {
|
||||
|
||||
@ -12,18 +13,21 @@ class ManageUsers extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, fetched, errorMessage } = this.props;
|
||||
const { fetched, errorMessage, data, saveData, loadData, setData, handleValueChange } = this.props;
|
||||
return (
|
||||
<SectionContent title="Manage Users" titleGutter>
|
||||
<ManageUsersForm
|
||||
userData={data}
|
||||
userDataFetched={fetched}
|
||||
errorMessage={errorMessage}
|
||||
onSubmit={this.props.saveData}
|
||||
onReset={this.props.loadData}
|
||||
setData={this.props.setData}
|
||||
handleValueChange={this.props.handleValueChange}
|
||||
/>
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
<ManageUsersForm
|
||||
userData={data}
|
||||
onSubmit={saveData}
|
||||
onReset={loadData}
|
||||
setData={setData}
|
||||
handleValueChange={handleValueChange}
|
||||
/>
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
}
|
||||
|
@ -1,28 +1,32 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
import { NTP_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import {restComponent} from '../components/RestComponent';
|
||||
import { NTP_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
import SectionContent from '../components/SectionContent';
|
||||
import NTPSettingsForm from '../forms/NTPSettingsForm';
|
||||
|
||||
class NTPSettings extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
this.props.loadData();
|
||||
this.props.loadData();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, fetched, errorMessage } = this.props;
|
||||
const { fetched, errorMessage, data, saveData, loadData, handleValueChange } = this.props;
|
||||
return (
|
||||
<SectionContent title="NTP Settings">
|
||||
<NTPSettingsForm
|
||||
ntpSettings={data}
|
||||
ntpSettingsFetched={fetched}
|
||||
errorMessage={errorMessage}
|
||||
onSubmit={this.props.saveData}
|
||||
onReset={this.props.loadData}
|
||||
handleValueChange={this.props.handleValueChange}
|
||||
/>
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
<NTPSettingsForm
|
||||
ntpSettings={data}
|
||||
onSubmit={saveData}
|
||||
onReset={loadData}
|
||||
handleValueChange={handleValueChange}
|
||||
/>
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ import React, { Component, Fragment } from 'react';
|
||||
|
||||
import { withStyles } from '@material-ui/core/styles';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import LinearProgress from '@material-ui/core/LinearProgress';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
import List from '@material-ui/core/List';
|
||||
import ListItem from '@material-ui/core/ListItem';
|
||||
import ListItemAvatar from '@material-ui/core/ListItemAvatar';
|
||||
@ -22,6 +20,7 @@ import * as Highlight from '../constants/Highlight';
|
||||
import { unixTimeToTimeAndDate } from '../constants/TimeFormat';
|
||||
import { NTP_STATUS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
import SectionContent from '../components/SectionContent';
|
||||
|
||||
import moment from 'moment';
|
||||
@ -36,10 +35,6 @@ const styles = theme => ({
|
||||
["ntpStatus_" + Highlight.WARN]: {
|
||||
backgroundColor: theme.palette.highlight_warn
|
||||
},
|
||||
fetching: {
|
||||
margin: theme.spacing(4),
|
||||
textAlign: "center"
|
||||
},
|
||||
button: {
|
||||
marginRight: theme.spacing(2),
|
||||
marginTop: theme.spacing(2),
|
||||
@ -131,32 +126,17 @@ class NTPStatus extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, fetched, errorMessage, classes } = this.props;
|
||||
|
||||
const { data, fetched, errorMessage, loadData, classes } = this.props;
|
||||
return (
|
||||
<SectionContent title="NTP Status">
|
||||
{
|
||||
!fetched ?
|
||||
<div>
|
||||
<LinearProgress className={classes.fetching} />
|
||||
<Typography variant="h4" className={classes.fetching}>
|
||||
Loading...
|
||||
</Typography>
|
||||
</div>
|
||||
:
|
||||
data ? this.renderNTPStatus(data, classes)
|
||||
:
|
||||
<div>
|
||||
<Typography variant="h4" className={classes.fetching}>
|
||||
{errorMessage}
|
||||
</Typography>
|
||||
<Button variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}>
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
{this.renderNTPStatus(data, classes)}
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,29 +1,33 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
import { OTA_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import {restComponent} from '../components/RestComponent';
|
||||
import { OTA_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
import SectionContent from '../components/SectionContent';
|
||||
import OTASettingsForm from '../forms/OTASettingsForm';
|
||||
|
||||
class OTASettings extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
this.props.loadData();
|
||||
this.props.loadData();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, fetched, errorMessage } = this.props;
|
||||
const { fetched, errorMessage, data, saveData, loadData, handleValueChange, handleCheckboxChange } = this.props;
|
||||
return (
|
||||
<SectionContent title="OTA Settings">
|
||||
<OTASettingsForm
|
||||
otaSettings={data}
|
||||
otaSettingsFetched={fetched}
|
||||
errorMessage={errorMessage}
|
||||
onSubmit={this.props.saveData}
|
||||
onReset={this.props.loadData}
|
||||
handleValueChange={this.props.handleValueChange}
|
||||
handleCheckboxChange={this.props.handleCheckboxChange}
|
||||
/>
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
<OTASettingsForm
|
||||
otaSettings={data}
|
||||
onSubmit={saveData}
|
||||
onReset={loadData}
|
||||
handleValueChange={handleValueChange}
|
||||
handleCheckboxChange={handleCheckboxChange}
|
||||
/>
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import React, { Component } from 'react';
|
||||
|
||||
import { SECURITY_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
import SecuritySettingsForm from '../forms/SecuritySettingsForm';
|
||||
import SectionContent from '../components/SectionContent';
|
||||
|
||||
@ -15,14 +16,17 @@ class SecuritySettings extends Component {
|
||||
const { data, fetched, errorMessage, saveData, loadData, handleValueChange } = this.props;
|
||||
return (
|
||||
<SectionContent title="Security Settings">
|
||||
<SecuritySettingsForm
|
||||
securitySettings={data}
|
||||
securitySettingsFetched={fetched}
|
||||
errorMessage={errorMessage}
|
||||
onSubmit={saveData}
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
handleValueChange={handleValueChange}
|
||||
/>
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
<SecuritySettingsForm
|
||||
securitySettings={data}
|
||||
onSubmit={saveData}
|
||||
onReset={loadData}
|
||||
handleValueChange={handleValueChange}
|
||||
/>
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ import React, { Component, Fragment } from 'react';
|
||||
|
||||
import { withStyles } from '@material-ui/core/styles';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import LinearProgress from '@material-ui/core/LinearProgress';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
import List from '@material-ui/core/List';
|
||||
import ListItem from '@material-ui/core/ListItem';
|
||||
import ListItemAvatar from '@material-ui/core/ListItemAvatar';
|
||||
@ -16,16 +14,12 @@ import ShowChartIcon from '@material-ui/icons/ShowChart';
|
||||
import SdStorageIcon from '@material-ui/icons/SdStorage';
|
||||
import DataUsageIcon from '@material-ui/icons/DataUsage';
|
||||
|
||||
|
||||
import { SYSTEM_STATUS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
import SectionContent from '../components/SectionContent';
|
||||
|
||||
const styles = theme => ({
|
||||
fetching: {
|
||||
margin: theme.spacing(4),
|
||||
textAlign: "center"
|
||||
},
|
||||
button: {
|
||||
marginRight: theme.spacing(2),
|
||||
marginTop: theme.spacing(2),
|
||||
@ -85,7 +79,7 @@ class SystemStatus extends Component {
|
||||
</ListItemAvatar>
|
||||
<ListItemText primary="Flash Chip Size" secondary={data.flash_chip_size + ' bytes'} />
|
||||
</ListItem>
|
||||
<Divider variant="inset" component="li" />
|
||||
<Divider variant="inset" component="li" />
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
@ -104,29 +98,15 @@ class SystemStatus extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, fetched, errorMessage, classes } = this.props;
|
||||
const { data, fetched, errorMessage, loadData, classes } = this.props;
|
||||
return (
|
||||
<SectionContent title="System Status">
|
||||
{
|
||||
!fetched ?
|
||||
<div>
|
||||
<LinearProgress className={classes.fetching} />
|
||||
<Typography variant="h4" className={classes.fetching}>
|
||||
Loading...
|
||||
</Typography>
|
||||
</div>
|
||||
:
|
||||
data ? this.renderNTPStatus(data, classes)
|
||||
:
|
||||
<div>
|
||||
<Typography variant="h4" className={classes.fetching}>
|
||||
{errorMessage}
|
||||
</Typography>
|
||||
<Button variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}>
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
{this.renderNTPStatus(data, classes)}
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { withSnackbar } from 'notistack';
|
||||
|
||||
import { SCAN_NETWORKS_ENDPOINT, LIST_NETWORKS_ENDPOINT } from '../constants/Endpoints';
|
||||
import SectionContent from '../components/SectionContent';
|
||||
import WiFiNetworkSelector from '../forms/WiFiNetworkSelector';
|
||||
import { withSnackbar } from 'notistack';
|
||||
import { redirectingAuthorizedFetch } from '../authentication/Authentication';
|
||||
|
||||
const NUM_POLLS = 10
|
||||
|
@ -1,8 +1,9 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { WIFI_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { WIFI_SETTINGS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
import SectionContent from '../components/SectionContent';
|
||||
import WiFiSettingsForm from '../forms/WiFiSettingsForm';
|
||||
|
||||
@ -18,10 +19,10 @@ class WiFiSettings extends Component {
|
||||
const { selectedNetwork } = this.props;
|
||||
if (selectedNetwork) {
|
||||
var wifiSettings = {
|
||||
ssid:selectedNetwork.ssid,
|
||||
password:"",
|
||||
hostname:"esp8266-react",
|
||||
static_ip_config:false,
|
||||
ssid: selectedNetwork.ssid,
|
||||
password: "",
|
||||
hostname: "esp8266-react",
|
||||
static_ip_config: false,
|
||||
}
|
||||
this.props.setData(wifiSettings);
|
||||
} else {
|
||||
@ -35,20 +36,23 @@ class WiFiSettings extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, fetched, errorMessage, selectedNetwork } = this.props;
|
||||
const { data, fetched, errorMessage, saveData, loadData, handleValueChange, handleCheckboxChange, selectedNetwork, deselectNetwork } = this.props;
|
||||
return (
|
||||
<SectionContent title="WiFi Settings">
|
||||
<WiFiSettingsForm
|
||||
wifiSettings={data}
|
||||
wifiSettingsFetched={fetched}
|
||||
errorMessage={errorMessage}
|
||||
selectedNetwork={selectedNetwork}
|
||||
deselectNetwork={this.props.deselectNetwork}
|
||||
onSubmit={this.props.saveData}
|
||||
onReset={this.deselectNetworkAndLoadData}
|
||||
handleValueChange={this.props.handleValueChange}
|
||||
handleCheckboxChange={this.props.handleCheckboxChange}
|
||||
/>
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
<WiFiSettingsForm
|
||||
wifiSettings={data}
|
||||
selectedNetwork={selectedNetwork}
|
||||
deselectNetwork={deselectNetwork}
|
||||
onSubmit={saveData}
|
||||
onReset={this.deselectNetworkAndLoadData}
|
||||
handleValueChange={handleValueChange}
|
||||
handleCheckboxChange={handleCheckboxChange}
|
||||
/>
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
}
|
||||
|
@ -2,14 +2,10 @@ import React, { Component, Fragment } from 'react';
|
||||
|
||||
import { withStyles } from '@material-ui/core/styles';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import LinearProgress from '@material-ui/core/LinearProgress';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
|
||||
import List from '@material-ui/core/List';
|
||||
import ListItem from '@material-ui/core/ListItem';
|
||||
import ListItemText from '@material-ui/core/ListItemText';
|
||||
import ListItemAvatar from '@material-ui/core/ListItemAvatar';
|
||||
|
||||
import Avatar from '@material-ui/core/Avatar';
|
||||
import Divider from '@material-ui/core/Divider';
|
||||
import WifiIcon from '@material-ui/icons/Wifi';
|
||||
@ -23,6 +19,7 @@ import { WIFI_STATUS_ENDPOINT } from '../constants/Endpoints';
|
||||
import { isConnected, connectionStatus, connectionStatusHighlight } from '../constants/WiFiConnectionStatus';
|
||||
import * as Highlight from '../constants/Highlight';
|
||||
import { restComponent } from '../components/RestComponent';
|
||||
import LoadingNotification from '../components/LoadingNotification';
|
||||
|
||||
const styles = theme => ({
|
||||
["wifiStatus_" + Highlight.IDLE]: {
|
||||
@ -37,10 +34,6 @@ const styles = theme => ({
|
||||
["wifiStatus_" + Highlight.WARN]: {
|
||||
backgroundColor: theme.palette.highlight_warn
|
||||
},
|
||||
fetching: {
|
||||
margin: theme.spacing(4),
|
||||
textAlign: "center"
|
||||
},
|
||||
button: {
|
||||
marginRight: theme.spacing(2),
|
||||
marginTop: theme.spacing(2),
|
||||
@ -145,32 +138,19 @@ class WiFiStatus extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data, fetched, errorMessage, classes } = this.props;
|
||||
const { data, fetched, errorMessage, loadData, classes } = this.props;
|
||||
return (
|
||||
<SectionContent title="WiFi Status">
|
||||
{
|
||||
!fetched ?
|
||||
<div>
|
||||
<LinearProgress className={classes.fetching} />
|
||||
<Typography variant="h4" className={classes.fetching}>
|
||||
Loading...
|
||||
</Typography>
|
||||
</div>
|
||||
:
|
||||
data ? this.renderWiFiStatus(data, classes)
|
||||
:
|
||||
<div>
|
||||
<Typography variant="h4" className={classes.fetching}>
|
||||
{errorMessage}
|
||||
</Typography>
|
||||
<Button variant="contained" color="secondary" className={classes.button} onClick={this.props.loadData}>
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
<LoadingNotification
|
||||
onReset={loadData}
|
||||
fetched={fetched}
|
||||
errorMessage={errorMessage}>
|
||||
{this.renderWiFiStatus(data, classes)}
|
||||
</LoadingNotification>
|
||||
</SectionContent>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default restComponent(WIFI_STATUS_ENDPOINT, withStyles(styles)(WiFiStatus));
|
||||
|
Reference in New Issue
Block a user