From 0b2490c689d23ebe0c1d4d86cb1c203e2d9ab8c7 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Mon, 31 Aug 2015 11:39:00 -0400 Subject: Reformatted access_history_modal.jsx to meet style guide requirements. --- web/react/components/access_history_modal.jsx | 99 ++++++++++++++++++--------- 1 file changed, 66 insertions(+), 33 deletions(-) (limited to 'web/react') diff --git a/web/react/components/access_history_modal.jsx b/web/react/components/access_history_modal.jsx index a19e5c16e..217b96d0b 100644 --- a/web/react/components/access_history_modal.jsx +++ b/web/react/components/access_history_modal.jsx @@ -6,46 +6,48 @@ var AsyncClient = require('../utils/async_client.jsx'); var LoadingScreen = require('./loading_screen.jsx'); var utils = require('../utils/utils.jsx'); -function getStateFromStoresForAudits() { - return { - audits: UserStore.getAudits() - }; -} +export default class AccessHistoryModal extends React.Component { + constructor(props) { + super(props); + + this.onAuditChange = this.onAuditChange.bind(this); + this.handleMoreInfo = this.handleMoreInfo.bind(this); -module.exports = React.createClass({ - displayName: 'AccessHistoryModal', - componentDidMount: function() { - UserStore.addAuditsChangeListener(this.onListenerChange); - $(this.refs.modal.getDOMNode()).on('shown.bs.modal', function() { + this.state = this.getStateFromStoresForAudits(); + this.state.moreInfo = []; + } + getStateFromStoresForAudits() { + return { + audits: UserStore.getAudits() + }; + } + componentDidMount() { + UserStore.addAuditsChangeListener(this.onAuditChange); + $(this.refs.modal.getDOMNode()).on('shown.bs.modal', function show() { AsyncClient.getAudits(); }); var self = this; - $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function() { + $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function hide() { $('#user_settings').modal('show'); self.setState({moreInfo: []}); }); - }, - componentWillUnmount: function() { - UserStore.removeAuditsChangeListener(this.onListenerChange); - }, - onListenerChange: function() { - var newState = getStateFromStoresForAudits(); + } + componentWillUnmount() { + UserStore.removeAuditsChangeListener(this.onAuditChange); + } + onAuditChange() { + var newState = this.getStateFromStoresForAudits(); if (!utils.areStatesEqual(newState.audits, this.state.audits)) { this.setState(newState); } - }, - handleMoreInfo: function(index) { + } + handleMoreInfo(index) { var newMoreInfo = this.state.moreInfo; newMoreInfo[index] = true; this.setState({moreInfo: newMoreInfo}); - }, - getInitialState: function() { - var initialState = getStateFromStoresForAudits(); - initialState.moreInfo = []; - return initialState; - }, - render: function() { + } + render() { var accessList = []; var currentHistoryDate = null; @@ -63,7 +65,16 @@ module.exports = React.createClass({ currentAudit.session_id = 'N/A (Login attempt)'; } - var moreInfo = (More info); + var moreInfo = ( + + More info + + ); + if (this.state.moreInfo[i]) { moreInfo = (
@@ -75,7 +86,7 @@ module.exports = React.createClass({ var divider = null; if (i < this.state.audits.length - 1) { - divider = (
) + divider = (
); } accessList[i] = ( @@ -102,14 +113,36 @@ module.exports = React.createClass({ return (
-