Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save alert and RFP to report content composer defaults #1086

Merged
merged 3 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions gsa/src/web/pages/reports/alertactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class AlertActions extends React.Component {
filter,
gmp,
report,
reportComposerDefaults,
showErrorMessage,
showSuccessMessage,
} = this.props;
Expand All @@ -112,7 +113,9 @@ class AlertActions extends React.Component {

if (storeAsDefault) {
this.props.saveReportComposerDefaults({
...reportComposerDefaults,
applyOverrides,
defaultAlertId: alertId,
includeNotes,
includeOverrides,
});
Expand All @@ -124,7 +127,10 @@ class AlertActions extends React.Component {
filter: newFilter.simple(),
}).then(response => {
showSuccessMessage(_('Running the alert was successful'));
this.setState({showTriggerAlertDialog: false});
this.setState({
alertId: undefined,
showTriggerAlertDialog: false,
});
}, error => {
log.error('Failed running alert', error);
showErrorMessage(_('Failed to run alert.'));
Expand All @@ -136,7 +142,6 @@ class AlertActions extends React.Component {
handleOpenTriggerAlertDialog() {
this.props.loadAlerts();
this.setState({
...this.props.reportComposerDefaults,
showTriggerAlertDialog: true,
});
}
Expand All @@ -157,15 +162,13 @@ class AlertActions extends React.Component {
render() {
const {
alerts,
reportComposerDefaults,
filter,
showError,
onInteraction,
} = this.props;
const {
alertId,
applyOverrides,
includeNotes,
includeOverrides,
showTriggerAlertDialog,
storeAsDefault,
} = this.state;
Expand All @@ -188,10 +191,11 @@ class AlertActions extends React.Component {
<TriggerAlertDialog
alertId={alertId}
alerts={alerts}
applyOverrides={applyOverrides}
applyOverrides={reportComposerDefaults.applyOverrides}
defaultAlertId={reportComposerDefaults.defaultAlertId}
filter={filter}
includeNotes={includeNotes}
includeOverrides={includeOverrides}
includeNotes={reportComposerDefaults.includeNotes}
includeOverrides={reportComposerDefaults.includeOverrides}
storeAsDefault={storeAsDefault}
onAlertChange={this.handleAlertChange}
onClose={this.handleCloseTriggerAlertDialog}
Expand Down
16 changes: 7 additions & 9 deletions gsa/src/web/pages/reports/detailspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ class ReportDetails extends React.Component {

handleOpenDownloadReportDialog() {
this.setState({
...this.props.reportComposerDefaults,
showDownloadReportDialog: true,
});
}
Expand All @@ -376,6 +375,7 @@ class ReportDetails extends React.Component {
entity,
filter,
gmp,
reportComposerDefaults,
reportFormats = [],
onDownload,
} = this.props;
Expand All @@ -394,7 +394,9 @@ class ReportDetails extends React.Component {

if (storeAsDefault) {
const defaults = {
...reportComposerDefaults,
applyOverrides,
defaultReportFormatId: reportFormatId,
includeNotes,
includeOverrides,
};
Expand Down Expand Up @@ -520,16 +522,14 @@ class ReportDetails extends React.Component {
isLoading,
reportFormats,
onInteraction,
reportComposerDefaults,
showError,
showErrorMessage,
showSuccessMessage,
} = this.props;
const {
activeTab,
applyOverrides,
includeNotes,
includeOverrides,
reportFormatId,
showFilterDialog,
showDownloadReportDialog,
sorting,
Expand All @@ -550,8 +550,6 @@ class ReportDetails extends React.Component {
filter={filter}
filters={filters}
isLoading={isLoading}
reportFormatId={reportFormatId}
reportFormats={reportFormats}
sorting={sorting}
onActivateTab={this.handleActivateTab}
onAddToAssetsClick={this.handleAddToAssets}
Expand Down Expand Up @@ -589,10 +587,10 @@ class ReportDetails extends React.Component {
{showDownloadReportDialog &&
<DownloadReportDialog
applyOverrides={applyOverrides}
defaultReportFormatId={reportComposerDefaults.defaultReportFormatId}
filter={filter}
includeNotes={includeNotes}
includeOverrides={includeOverrides}
reportFormatId={reportFormatId}
includeNotes={reportComposerDefaults.includeNotes}
includeOverrides={reportComposerDefaults.includeOverrides}
reportFormats={reportFormats}
storeAsDefault={storeAsDefault}
onClose={this.handleCloseDownloadReportDialog}
Expand Down
6 changes: 6 additions & 0 deletions gsa/src/web/pages/reports/downloadreportdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +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 PropTypes from 'web/utils/proptypes';
import {renderSelectItems} from 'web/utils/render';
Expand All @@ -46,6 +47,7 @@ const StyledDiv = styled.div`

const DownloadReportDialog = ({
applyOverrides = COMPOSER_CONTENT_DEFAULTS.applyOverrides,
defaultReportFormatId,
filter = {},
includeNotes = COMPOSER_CONTENT_DEFAULTS.includeNotes,
includeOverrides = COMPOSER_CONTENT_DEFAULTS.includeOverrides,
Expand All @@ -58,6 +60,8 @@ const DownloadReportDialog = ({
const filterString = isString(filter) ?
filter : filter.toFilterCriteriaString();

reportFormatId = selectSaveId(reportFormats, defaultReportFormatId);

const unControlledValues = {
applyOverrides,
includeNotes,
Expand Down Expand Up @@ -92,6 +96,7 @@ const DownloadReportDialog = ({
name="reportFormatId"
value={values.reportFormatId}
items={renderSelectItems(reportFormats)}
width="auto"
onChange={onValueChange}
/>
</Divider>
Expand All @@ -114,6 +119,7 @@ const DownloadReportDialog = ({

DownloadReportDialog.propTypes = {
applyOverrides: PropTypes.numberOrNumberString,
defaultReportFormatId: PropTypes.id,
filter: PropTypes.filter.isRequired,
includeNotes: PropTypes.number,
includeOverrides: PropTypes.number,
Expand Down
9 changes: 7 additions & 2 deletions gsa/src/web/pages/reports/triggeralertdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import _ from 'gmp/locale';

import {NO_VALUE, YES_VALUE} from 'gmp/parser';

import {first} from 'gmp/utils/array';
import {selectSaveId} from 'gmp/utils/id';
import {isDefined, isString} from 'gmp/utils/identity';
import PropTypes from 'web/utils/proptypes';
import {renderSelectItems} from 'web/utils/render';
Expand All @@ -50,6 +50,7 @@ const TriggerAlertDialog = ({
alertId,
alerts = [],
applyOverrides = COMPOSER_CONTENT_DEFAULTS.applyOverrides,
defaultAlertId,
filter = {},
includeNotes = COMPOSER_CONTENT_DEFAULTS.includeNotes,
includeOverrides = COMPOSER_CONTENT_DEFAULTS.includeOverrides,
Expand All @@ -59,11 +60,14 @@ const TriggerAlertDialog = ({
onNewAlertClick,
onSave,
}) => {
alertId = isDefined(alertId) ? alertId : first(alerts).id;

const filterString = isString(filter) ?
filter : filter.toFilterCriteriaString();

if (!isDefined(alertId)) {
alertId = selectSaveId(alerts, defaultAlertId);
};

const unControlledValues = {
applyOverrides,
includeNotes,
Expand Down Expand Up @@ -129,6 +133,7 @@ TriggerAlertDialog.propTypes = {
alertId: PropTypes.id,
alerts: PropTypes.array,
applyOverrides: PropTypes.numberOrNumberString,
defaultAlertId: PropTypes.id,
filter: PropTypes.filter.isRequired,
includeNotes: PropTypes.number,
includeOverrides: PropTypes.number,
Expand Down
13 changes: 10 additions & 3 deletions gsa/src/web/store/usersettings/__tests__/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,17 @@ describe('settings reducers tests', () => {
expect(reportComposerDefaults(undefined, action)).toEqual({foo: 'bar'});
});

test('should override existing defaults', () => {
test('should merge existing defaults', () => {
const action = getReportComposerDefaultsAction({foo: 'bar'});
const state = {toBe: 'deleted'};
expect(reportComposerDefaults(state, action)).toEqual({foo: 'bar'});
const state = {
foo: 'ipsum',
toBe: 'preserved',
};
const res = {
foo: 'bar',
toBe: 'preserved',
};
expect(reportComposerDefaults(state, action)).toEqual(res);
});
});
});
5 changes: 4 additions & 1 deletion gsa/src/web/store/usersettings/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import {
export const reportComposerDefaults = (state = {}, action) => {
switch (action.type) {
case USER_SETTINGS_LOAD_REPORT_COMPOSER_DEFAULTS_SUCCESS:
return action.data;
return {
...state,
...action.data,
};
default:
return state;
}
Expand Down