diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-04-25 11:46:02 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-04-25 11:46:02 -0400 |
commit | 6c4c706313eb765eb00c639f381646be74f27b69 (patch) | |
tree | 6068feaa9668dcd74601730ac1a5abfb366402b1 /webapp/components/access_history_modal | |
parent | cc07c005074348de87854f1c953a549e8772fa03 (diff) | |
download | chat-6c4c706313eb765eb00c639f381646be74f27b69.tar.gz chat-6c4c706313eb765eb00c639f381646be74f27b69.tar.bz2 chat-6c4c706313eb765eb00c639f381646be74f27b69.zip |
Start moving webapp to Redux (#6140)
* Start moving webapp to Redux
* Fix localforage import
* Updates per feedback
* Feedback udpates and a few fixes
* Minor updates
* Fix statuses, config not loading properly, getMe sanitizing too much
* Fix preferences
* Fix user autocomplete
* Fix sessions and audits
* Fix error handling for all redux actions
* Use new directory structure for components and containers
* Refresh immediately on logout instead of after timeout
* Add fetch polyfill
Diffstat (limited to 'webapp/components/access_history_modal')
-rw-r--r-- | webapp/components/access_history_modal/access_history_modal.jsx | 108 | ||||
-rw-r--r-- | webapp/components/access_history_modal/index.js | 24 |
2 files changed, 132 insertions, 0 deletions
diff --git a/webapp/components/access_history_modal/access_history_modal.jsx b/webapp/components/access_history_modal/access_history_modal.jsx new file mode 100644 index 000000000..da03fdb5b --- /dev/null +++ b/webapp/components/access_history_modal/access_history_modal.jsx @@ -0,0 +1,108 @@ +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import LoadingScreen from 'components/loading_screen.jsx'; +import AuditTable from 'components/audit_table.jsx'; + +import UserStore from 'stores/user_store.jsx'; + +import * as Utils from 'utils/utils.jsx'; + +import $ from 'jquery'; +import React from 'react'; + +import {Modal} from 'react-bootstrap'; +import {FormattedMessage} from 'react-intl'; + +export default class AccessHistoryModal extends React.Component { + static propTypes = { + onHide: React.PropTypes.func.isRequired, + actions: React.PropTypes.shape({ + getUserAudits: React.PropTypes.func.isRequired + }).isRequired + } + + constructor(props) { + super(props); + + this.onAuditChange = this.onAuditChange.bind(this); + this.onShow = this.onShow.bind(this); + this.onHide = this.onHide.bind(this); + + const state = this.getStateFromStoresForAudits(); + state.moreInfo = []; + state.show = true; + + this.state = state; + } + + getStateFromStoresForAudits() { + return { + audits: UserStore.getAudits() + }; + } + + onShow() { + this.props.actions.getUserAudits(UserStore.getCurrentId(), 0, 200); + if (!Utils.isMobile()) { + $('.modal-body').perfectScrollbar(); + } + } + + onHide() { + this.setState({show: false}); + } + + componentDidMount() { + UserStore.addAuditsChangeListener(this.onAuditChange); + this.onShow(); + } + + componentWillUnmount() { + UserStore.removeAuditsChangeListener(this.onAuditChange); + } + + onAuditChange() { + const newState = this.getStateFromStoresForAudits(); + if (!Utils.areObjectsEqual(newState.audits, this.state.audits)) { + this.setState(newState); + } + } + + render() { + let content; + if (this.state.audits.length === 0) { + content = (<LoadingScreen/>); + } else { + content = ( + <AuditTable + audits={this.state.audits} + showIp={true} + showSession={true} + /> + ); + } + + return ( + <Modal + dialogClassName='modal--scroll' + show={this.state.show} + onHide={this.onHide} + onExited={this.props.onHide} + bsSize='large' + > + <Modal.Header closeButton={true}> + <Modal.Title> + <FormattedMessage + id='access_history.title' + defaultMessage='Access History' + /> + </Modal.Title> + </Modal.Header> + <Modal.Body ref='modalBody'> + {content} + </Modal.Body> + </Modal> + ); + } +} diff --git a/webapp/components/access_history_modal/index.js b/webapp/components/access_history_modal/index.js new file mode 100644 index 000000000..4842ca730 --- /dev/null +++ b/webapp/components/access_history_modal/index.js @@ -0,0 +1,24 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import {connect} from 'react-redux'; +import {bindActionCreators} from 'redux'; +import {getUserAudits} from 'mattermost-redux/actions/users'; + +import AccessHistoryModal from './access_history_modal.jsx'; + +function mapStateToProps(state, ownProps) { + return { + ...ownProps + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + getUserAudits + }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(AccessHistoryModal); |