From 1138dd67705829a6af0d6c610cf3dbe09082187c Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 14 Jun 2017 08:56:56 -0400 Subject: PLT-6657 Move system console to use v4 endpoints and redux (#6572) * Move system console to use v4 endpoints and redux * Rename logs dir to get past gitignore * Fix test email * Update brand unit test * Updates per feedback --- .../compliance_reports/compliance_reports.jsx | 394 +++++++++++++++++++++ .../admin_console/compliance_reports/index.js | 42 +++ 2 files changed, 436 insertions(+) create mode 100644 webapp/components/admin_console/compliance_reports/compliance_reports.jsx create mode 100644 webapp/components/admin_console/compliance_reports/index.js (limited to 'webapp/components/admin_console/compliance_reports') diff --git a/webapp/components/admin_console/compliance_reports/compliance_reports.jsx b/webapp/components/admin_console/compliance_reports/compliance_reports.jsx new file mode 100644 index 000000000..af361bace --- /dev/null +++ b/webapp/components/admin_console/compliance_reports/compliance_reports.jsx @@ -0,0 +1,394 @@ +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import LoadingScreen from 'components/loading_screen.jsx'; + +import * as Utils from 'utils/utils.jsx'; +import UserStore from 'stores/user_store.jsx'; +import {Client4} from 'mattermost-redux/client'; + +import React from 'react'; +import PropTypes from 'prop-types'; +import {FormattedMessage, FormattedDate, FormattedTime} from 'react-intl'; + +export default class ComplianceReports extends React.PureComponent { + static propTypes = { + + /* + * Set if compliance reports are enabled in the config + */ + enabled: PropTypes.bool.isRequired, + + /* + * Array of reports to render + */ + reports: PropTypes.arrayOf(PropTypes.object).isRequired, + + /* + * Error message to display + */ + serverError: PropTypes.string, + + actions: PropTypes.shape({ + + /* + * Function to get compliance reports + */ + getComplianceReports: PropTypes.func.isRequired, + + /* + * Function to save compliance reports + */ + createComplianceReport: PropTypes.func.isRequired + }).isRequired + } + + constructor(props) { + super(props); + + this.state = { + loadingReports: true + }; + } + + componentDidMount() { + if (global.window.mm_license.IsLicensed !== 'true' || !this.props.enabled) { + return; + } + + this.props.actions.getComplianceReports().then( + () => this.setState({loadingReports: false}) + ); + } + + reload = () => { + this.setState({loadingReports: true}); + + this.props.actions.getComplianceReports().then( + () => this.setState({loadingReports: false}) + ); + } + + runReport = (e) => { + e.preventDefault(); + + this.setState({runningReport: true}); + + const job = {}; + job.desc = this.refs.desc.value; + job.emails = this.refs.emails.value; + job.keywords = this.refs.keywords.value; + job.start_at = Date.parse(this.refs.from.value); + job.end_at = Date.parse(this.refs.to.value); + + this.props.actions.createComplianceReport(job).then( + (data) => { + if (data) { + this.refs.emails.value = ''; + this.refs.keywords.value = ''; + this.refs.desc.value = ''; + this.refs.from.value = ''; + this.refs.to.value = ''; + } + this.setState({runningReport: false}); + } + ); + } + + getDateTime(millis) { + const date = new Date(millis); + return ( + + + {' - '} + + + ); + } + + render() { + if (global.window.mm_license.IsLicensed !== 'true' || !this.props.enabled) { + return
; + } + + let content = null; + if (this.state.loadingReports) { + content = ; + } else { + var list = []; + + for (var i = 0; i < this.props.reports.length; i++) { + const report = this.props.reports[i]; + + let params = ''; + if (report.type === 'adhoc') { + params = ( + + {' '}{this.getDateTime(report.start_at)} +
+ {' '}{this.getDateTime(report.end_at)} +
+ {' '}{report.emails} +
+ {' '}{report.keywords} +
); + } + + let download = ''; + if (report.status === 'finished') { + download = ( + + + + ); + } + + let status = report.status; + if (report.status === 'finished') { + status = ( + {report.status} + ); + } + + if (report.status === 'failed') { + status = ( + {report.status} + ); + } + + let user = report.user_id; + const profile = UserStore.getProfile(report.user_id); + if (profile) { + user = profile.email; + } + + list[i] = ( + + {download} + {this.getDateTime(report.create_at)} + {status} + {report.count} + {report.type} + {report.desc} + {user} + {params} + + ); + } + + content = ( +
+ + + + + + + + + + + + + + {list} + +
+ + + + + + + + + + + + + + +
+
+ ); + } + + let serverError = ''; + if (this.props.serverError) { + serverError = ( +
+ +
+ ); + } + + return ( +
+

+ +

+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ +
+ {serverError} +
+ +
+
+ {content} +
+
+ ); + } +} diff --git a/webapp/components/admin_console/compliance_reports/index.js b/webapp/components/admin_console/compliance_reports/index.js new file mode 100644 index 000000000..8534c1fda --- /dev/null +++ b/webapp/components/admin_console/compliance_reports/index.js @@ -0,0 +1,42 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import {connect} from 'react-redux'; +import {bindActionCreators} from 'redux'; +import {getComplianceReports, createComplianceReport} from 'mattermost-redux/actions/admin'; + +import {getComplianceReports as selectComplianceReports, getConfig} from 'mattermost-redux/selectors/entities/admin'; + +import ComplianceReports from './compliance_reports.jsx'; + +function mapStateToProps(state, ownProps) { + let enabled = false; + const config = getConfig(state); + if (config && config.ComplianceSettings) { + enabled = config.ComplianceSettings.Enable; + } + + let serverError; + const error = state.requests.admin.createCompliance.error; + if (error) { + serverError = error.message; + } + + return { + ...ownProps, + enabled, + reports: Object.values(selectComplianceReports(state)), + serverError + }; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ + getComplianceReports, + createComplianceReport + }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(ComplianceReports); -- cgit v1.2.3-1-g7c22