// 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}
); } }