diff --git a/src/gmp/commands/reports.js b/src/gmp/commands/reports.js index 0cdb4f9f8d..12b3cef8ee 100644 --- a/src/gmp/commands/reports.js +++ b/src/gmp/commands/reports.js @@ -86,13 +86,14 @@ export class ReportCommand extends EntityCommand { }); } - download({id}, {reportFormatId, deltaReportId, filter}) { + download({id}, {reportFormatId, reportConfigId, deltaReportId, filter}) { return this.httpGet( { cmd: 'get_report', delta_report_id: deltaReportId, details: 1, report_id: id, + report_config_id: reportConfigId, report_format_id: reportFormatId, filter: isDefined(filter) ? filter.all() : ALL_FILTER, }, diff --git a/src/web/pages/reports/detailspage.js b/src/web/pages/reports/detailspage.js index e519b2e7f8..fa3846794e 100644 --- a/src/web/pages/reports/detailspage.js +++ b/src/web/pages/reports/detailspage.js @@ -24,7 +24,11 @@ import _ from 'gmp/locale'; import logger from 'gmp/log'; -import Filter, {RESET_FILTER, RESULTS_FILTER_FILTER} from 'gmp/models/filter'; +import Filter, { + ALL_FILTER, + RESET_FILTER, + RESULTS_FILTER_FILTER, +} from 'gmp/models/filter'; import {isActive} from 'gmp/models/task'; import {first} from 'gmp/utils/array'; @@ -48,6 +52,11 @@ import { selector as filterSelector, } from 'web/store/entities/filters'; +import { + loadAllEntities as loadReportConfigs, + selector as reportConfigsSelector, +} from 'web/store/entities/reportconfigs'; + import { loadAllEntities as loadReportFormats, selector as reportFormatsSelector, @@ -162,31 +171,26 @@ class ReportDetails extends React.Component { this.handleError = this.handleError.bind(this); this.handleFilterAddLogLevel = this.handleFilterAddLogLevel.bind(this); this.handleFilterChange = this.handleFilterChange.bind(this); - this.handleFilterDecreaseMinQoD = this.handleFilterDecreaseMinQoD.bind( - this, - ); + this.handleFilterDecreaseMinQoD = + this.handleFilterDecreaseMinQoD.bind(this); this.handleFilterCreated = this.handleFilterCreated.bind(this); this.handleFilterEditClick = this.handleFilterEditClick.bind(this); - this.handleFilterRemoveSeverity = this.handleFilterRemoveSeverity.bind( - this, - ); + this.handleFilterRemoveSeverity = + this.handleFilterRemoveSeverity.bind(this); this.handleFilterRemoveClick = this.handleFilterRemoveClick.bind(this); this.handleFilterResetClick = this.handleFilterResetClick.bind(this); this.handleRemoveFromAssets = this.handleRemoveFromAssets.bind(this); this.handleReportDownload = this.handleReportDownload.bind(this); - this.handleTlsCertificateDownload = this.handleTlsCertificateDownload.bind( - this, - ); + this.handleTlsCertificateDownload = + this.handleTlsCertificateDownload.bind(this); this.handleFilterDialogClose = this.handleFilterDialogClose.bind(this); this.handleSortChange = this.handleSortChange.bind(this); this.loadTarget = this.loadTarget.bind(this); - this.handleOpenDownloadReportDialog = this.handleOpenDownloadReportDialog.bind( - this, - ); - this.handleCloseDownloadReportDialog = this.handleCloseDownloadReportDialog.bind( - this, - ); + this.handleOpenDownloadReportDialog = + this.handleOpenDownloadReportDialog.bind(this); + this.handleCloseDownloadReportDialog = + this.handleCloseDownloadReportDialog.bind(this); } static getDerivedStateFromProps(props, state) { @@ -243,6 +247,7 @@ class ReportDetails extends React.Component { componentDidMount() { this.props.loadSettings(); this.props.loadFilters(); + this.props.loadReportConfigs(); this.props.loadReportFormats(); this.props.loadReportComposerDefaults(); } @@ -401,6 +406,7 @@ class ReportDetails extends React.Component { const { includeNotes, includeOverrides, + reportConfigId, reportFormatId, storeAsDefault, } = state; @@ -412,6 +418,7 @@ class ReportDetails extends React.Component { if (storeAsDefault) { const defaults = { ...reportComposerDefaults, + defaultReportConfigId: reportConfigId, defaultReportFormatId: reportFormatId, includeNotes, includeOverrides, @@ -431,6 +438,7 @@ class ReportDetails extends React.Component { return gmp.report .download(entity, { + reportConfigId, reportFormatId, filter: newFilter, }) @@ -551,6 +559,7 @@ class ReportDetails extends React.Component { isLoading, isLoadingFilters, pageFilter, + reportConfigs, reportError, reportFormats, reportId, @@ -655,10 +664,12 @@ class ReportDetails extends React.Component { )} {showDownloadReportDialog && ( ? USE_DEFAULT_RELOAD_INTERVAL_ACTIVE : NO_RELOAD; // report doesn't change anymore. no need to reload -const load = ({ - defaultFilter, - reportId, - // eslint-disable-next-line no-shadow - loadReportWithThreshold, - pageFilter, - reportFilter, - updateFilter, -}) => filter => { - if (!hasValue(filter)) { - // use loaded filter after initial loading - filter = reportFilter; - } +const load = + ({ + defaultFilter, + reportId, + // eslint-disable-next-line no-shadow + loadReportWithThreshold, + pageFilter, + reportFilter, + updateFilter, + }) => + filter => { + if (!hasValue(filter)) { + // use loaded filter after initial loading + filter = reportFilter; + } - if (!hasValue(filter)) { - // use filter from store - filter = pageFilter; - } + if (!hasValue(filter)) { + // use filter from store + filter = pageFilter; + } - if (!hasValue(filter)) { - // use filter from user setting - filter = defaultFilter; - } + if (!hasValue(filter)) { + // use filter from user setting + filter = defaultFilter; + } - if (!hasValue(filter)) { - // use fallback filter - filter = DEFAULT_FILTER; - } + if (!hasValue(filter)) { + // use fallback filter + filter = DEFAULT_FILTER; + } - updateFilter(filter); - return loadReportWithThreshold(reportId, {filter}); -}; + updateFilter(filter); + return loadReportWithThreshold(reportId, {filter}); + }; const ReportDetailsWrapper = ({reportFilter, ...props}) => ( ({ loadFilters: () => dispatch(loadFilters(gmp)(RESULTS_FILTER_FILTER)), loadSettings: () => dispatch(loadUserSettingDefaults(gmp)()), loadTarget: targetId => gmp.target.get({id: targetId}), + loadReportConfigs: () => dispatch(loadReportConfigs(gmp)(ALL_FILTER)), loadReportFormats: () => dispatch(loadReportFormats(gmp)(REPORT_FORMATS_FILTER)), loadReportWithThreshold: (id, options) => @@ -798,6 +814,7 @@ const mapStateToProps = (rootState, {match}) => { const {id} = match.params; const filterSel = filterSelector(rootState); const reportSel = reportSelector(rootState); + const reportConfigsSel = reportConfigsSelector(rootState); const reportFormatsSel = reportFormatsSelector(rootState); const userDefaultsSelector = getUserSettingsDefaults(rootState); const userDefaultFilterSel = getUserSettingsDefaultFilter( @@ -829,6 +846,7 @@ const mapStateToProps = (rootState, {match}) => { 'reportexportfilename', ), reportFilter: getFilter(entity), + reportConfigs: reportConfigsSel.getAllEntities(ALL_FILTER), reportFormats: reportFormatsSel.getAllEntities(REPORT_FORMATS_FILTER), reportId: id, reportComposerDefaults: getReportComposerDefaults(rootState), diff --git a/src/web/pages/reports/downloadreportdialog.js b/src/web/pages/reports/downloadreportdialog.js index 81eda412d2..c04f747219 100644 --- a/src/web/pages/reports/downloadreportdialog.js +++ b/src/web/pages/reports/downloadreportdialog.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import React from 'react'; +import React, {useState} from 'react'; import styled from 'styled-components'; @@ -25,7 +25,7 @@ import _ from 'gmp/locale'; import {NO_VALUE, YES_VALUE} from 'gmp/parser'; import {selectSaveId} from 'gmp/utils/id'; -import {isString} from 'gmp/utils/identity'; +import {isDefined, isString} from 'gmp/utils/identity'; import PropTypes from 'web/utils/proptypes'; import {renderSelectItems} from 'web/utils/render'; @@ -48,10 +48,13 @@ const StyledDiv = styled.div` `; const DownloadReportDialog = ({ + defaultReportConfigId, defaultReportFormatId, filter = {}, includeNotes = COMPOSER_CONTENT_DEFAULTS.includeNotes, includeOverrides = COMPOSER_CONTENT_DEFAULTS.includeOverrides, + reportConfigId, + reportConfigs, reportFormatId, reportFormats, showThresholdMessage = false, @@ -62,67 +65,112 @@ const DownloadReportDialog = ({ }) => { const filterString = isString(filter) ? filter : filter.toFilterString(); - reportFormatId = selectSaveId(reportFormats, defaultReportFormatId); + if (defaultReportConfigId === '' || !isDefined(defaultReportConfigId)) { + reportConfigId = ''; + } else { + reportConfigId = selectSaveId(reportConfigs, defaultReportConfigId, ''); + } + + const [reportFormatIdInState, setReportFormatId] = useState( + selectSaveId(reportFormats, defaultReportFormatId), + ); + const [reportConfigIdInState, setReportConfigId] = useState(reportConfigId); const unControlledValues = { includeNotes, includeOverrides, - reportFormatId, storeAsDefault, }; + const handleReportFormatIdChange = value => { + setReportConfigId(''); + setReportFormatId(value); + }; + + const handleReportConfigIdChange = value => { + setReportConfigId(value); + }; + + const handleSave = values => { + onSave({ + ...values, + reportConfigId: reportConfigIdInState, + reportFormatId: reportFormatIdInState, + }); + }; + return ( - {({values, onValueChange}) => ( - - - - - + + + + +