From 5c1bead36ac59ed62aeab97fc49ad2e6a9df458b Mon Sep 17 00:00:00 2001 From: nickago Date: Fri, 14 Aug 2015 09:09:39 -0700 Subject: cosmetic refactoring --- web/react/components/access_history_modal.jsx | 26 +++--- web/react/components/activity_log_modal.jsx | 112 ++++++++++++++------------ 2 files changed, 74 insertions(+), 64 deletions(-) diff --git a/web/react/components/access_history_modal.jsx b/web/react/components/access_history_modal.jsx index 678113a47..59c3384df 100644 --- a/web/react/components/access_history_modal.jsx +++ b/web/react/components/access_history_modal.jsx @@ -73,6 +73,11 @@ module.exports = React.createClass({ ); } + var divider = null; + if (i < this.state.audits.length - 1) { + divider = (
) + } + accessList[i] = (
{newDate}
@@ -82,16 +87,19 @@ module.exports = React.createClass({
{'IP: ' + currentAudit.ip_address}
{moreInfo}
- {i < this.state.audits.length - 1 ? -
- : - null - } + {divider}
); } + var content; + if (this.state.audits.loading) { + content = (); + } else { + content = (
{accessList}
); + } + return (
- {!this.state.audits.loading ? -
- {accessList} -
- : - - } + {content}
diff --git a/web/react/components/activity_log_modal.jsx b/web/react/components/activity_log_modal.jsx index 64f93ca71..6d466f976 100644 --- a/web/react/components/activity_log_modal.jsx +++ b/web/react/components/activity_log_modal.jsx @@ -10,27 +10,27 @@ var utils = require('../utils/utils.jsx'); function getStateFromStoresForSessions() { return { sessions: UserStore.getSessions(), - server_error: null, - client_error: null + serverError: null, + clientError: null }; } module.exports = React.createClass({ + displayName: 'ActivityLogModal', submitRevoke: function(altId) { - var self = this; Client.revokeSession(altId, function(data) { AsyncClient.getSessions(); }.bind(this), function(err) { - state = getStateFromStoresForSessions(); - state.server_error = err; + var state = getStateFromStoresForSessions(); + state.serverError = err; this.setState(state); }.bind(this) ); }, componentDidMount: function() { - UserStore.addSessionsChangeListener(this._onChange); + UserStore.addSessionsChangeListener(this.onListenerChange); $(this.refs.modal.getDOMNode()).on('shown.bs.modal', function (e) { AsyncClient.getSessions(); }); @@ -38,13 +38,13 @@ module.exports = React.createClass({ var self = this; $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function(e) { $('#user_settings1').modal('show'); - self.setState({ moreInfo: [] }); + self.setState({moreInfo: []}); }); }, componentWillUnmount: function() { - UserStore.removeSessionsChangeListener(this._onChange); + UserStore.removeSessionsChangeListener(this.onListenerChange); }, - _onChange: function() { + onListenerChange: function() { var newState = getStateFromStoresForSessions(); if (!utils.areStatesEqual(newState.sessions, this.state.sessions)) { this.setState(newState); @@ -53,7 +53,7 @@ module.exports = React.createClass({ handleMoreInfo: function(index) { var newMoreInfo = this.state.moreInfo; newMoreInfo[index] = true; - this.setState({ moreInfo: newMoreInfo }); + this.setState({moreInfo: newMoreInfo}); }, getInitialState: function() { var initialState = getStateFromStoresForSessions(); @@ -62,68 +62,76 @@ module.exports = React.createClass({ }, render: function() { var activityList = []; - var server_error = this.state.server_error ? this.state.server_error : null; + var serverError = this.state.serverError; + + // Squash any false-y value for server error into null + if (!serverError) { + serverError = null; + } for (var i = 0; i < this.state.sessions.length; i++) { var currentSession = this.state.sessions[i]; var lastAccessTime = new Date(currentSession.last_activity_at); var firstAccessTime = new Date(currentSession.create_at); - var devicePicture = ""; + var devicePicture = ''; - if (currentSession.props.platform === "Windows") { - devicePicture = "fa fa-windows"; + if (currentSession.props.platform === 'Windows') { + devicePicture = 'fa fa-windows'; } - else if (currentSession.props.platform === "Macintosh" || currentSession.props.platform === "iPhone") { - devicePicture = "fa fa-apple"; + else if (currentSession.props.platform === 'Macintosh' || currentSession.props.platform === 'iPhone') { + devicePicture = 'fa fa-apple'; } - else if (currentSession.props.platform === "Linux") { - devicePicture = "fa fa-linux"; + else if (currentSession.props.platform === 'Linux') { + devicePicture = 'fa fa-linux'; + } + + var moreInfo; + if (this.state.moreInfo[i]) { + moreInfo = ( +
+
{'First time active: ' + firstAccessTime.toDateString() + ', ' + lastAccessTime.toLocaleTimeString()}
+
{'OS: ' + currentSession.props.os}
+
{'Browser: ' + currentSession.props.browser}
+
{'Session ID: ' + currentSession.alt_id}
+
+ ); + } else { + moreInfo = (More info); } activityList[i] = ( -
-
-
{currentSession.props.platform}
-
-
{"Last activity: " + lastAccessTime.toDateString() + ", " + lastAccessTime.toLocaleTimeString()}
- { this.state.moreInfo[i] ? -
-
{"First time active: " + firstAccessTime.toDateString() + ", " + lastAccessTime.toLocaleTimeString()}
-
{"OS: " + currentSession.props.os}
-
{"Browser: " + currentSession.props.browser}
-
{"Session ID: " + currentSession.alt_id}
-
- : - More info - } +
+
+
{currentSession.props.platform}
+
+
{'Last activity: ' + lastAccessTime.toDateString() + ', ' + lastAccessTime.toLocaleTimeString()}
+ {moreInfo}
-
+
); } + var content; + if (this.state.sessions.loading) { + content = (); + } else { + content = (
{activityList}
); + } + return (
-