Skip to content

Commit

Permalink
use new filename format for report download
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahd93 committed Jul 26, 2019
1 parent be4c473 commit 620e657
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions gsa/src/web/pages/audits/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ import {
import {loadUserSettingDefaults} from 'web/store/usersettings/defaults/actions';
import {getUserSettingsDefaults} from 'web/store/usersettings/defaults/selectors';

import {getUsername} from 'web/store/usersettings/selectors';

import compose from 'web/utils/compose';
import PropTypes from 'web/utils/proptypes';
import withCapabilities from 'web/utils/withCapabilities';
import withGmp from 'web/utils/withGmp';
import {UNSET_VALUE} from 'web/utils/render';
import {UNSET_VALUE, generateFilename} from 'web/utils/render';

import EntityComponent from 'web/entity/component';

Expand Down Expand Up @@ -387,8 +389,13 @@ class AuditComponent extends React.Component {
}

handleReportDownload(audit) {
// TODO: use generateFilename when it becomes available for master
const {gmp, reportFormats = [], onDownload} = this.props;
const {
gmp,
reportExportFileName,
username,
reportFormats = [],
onDownload,
} = this.props;

const [reportFormat] = reportFormats;

Expand All @@ -411,7 +418,15 @@ class AuditComponent extends React.Component {
)
.then(response => {
const {data} = response;
const filename = 'report-' + id + '.' + extension;
const filename = generateFilename({
extension,
fileNameFormat: reportExportFileName,
id: id,
reportFormat: reportFormat.name,
resourceName: audit.name,
resourceType: 'report',
username,
});
onDownload({filename, data});
}, this.handleError);
}
Expand Down Expand Up @@ -560,9 +575,11 @@ AuditComponent.propTypes = {
loadTargets: PropTypes.func.isRequired,
loadUserSettingsDefaults: PropTypes.func.isRequired,
policies: PropTypes.arrayOf(PropTypes.model),
reportExportFileName: PropTypes.object,
reportFormats: PropTypes.array,
schedules: PropTypes.arrayOf(PropTypes.model),
targets: PropTypes.arrayOf(PropTypes.model),
username: PropTypes.string,
onCloneError: PropTypes.func,
onCloned: PropTypes.func,
onCreateError: PropTypes.func,
Expand All @@ -589,6 +606,8 @@ const mapStateToProps = (rootState, {match}) => {
const policiesSel = policiesSelector(rootState);
const scheduleSel = scheduleSelector(rootState);
const targetSel = targetSelector(rootState);
const userDefaultsSelector = getUserSettingsDefaults(rootState);
const username = getUsername(rootState);

const reportFormatsSel = reportFormatsSelector(rootState);

Expand All @@ -597,10 +616,14 @@ const mapStateToProps = (rootState, {match}) => {
defaultAlertId: userDefaults.getValueByName('defaultalert'),
defaultScheduleId: userDefaults.getValueByName('defaultschedule'),
defaultTargetId: userDefaults.getValueByName('defaulttarget'),
reportExportFileName: userDefaultsSelector.getValueByName(
'reportexportfilename',
),
reportFormats: reportFormatsSel.getAllEntities(REPORT_FORMATS_FILTER),
policies: policiesSel.getEntities(ALL_FILTER),
schedules: scheduleSel.getEntities(ALL_FILTER),
targets: targetSel.getEntities(ALL_FILTER),
username,
};
};

Expand Down

0 comments on commit 620e657

Please sign in to comment.