From 402a1c9130921281a21f6ec7243590ef79affc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Mon, 15 Apr 2019 10:42:47 +0200 Subject: [PATCH 1/6] Remove openContentComposerDialog binding The method is already called from a bind function. Therefore it doesn't need to be bind too. --- gsa/src/web/pages/alerts/component.js | 1 - 1 file changed, 1 deletion(-) diff --git a/gsa/src/web/pages/alerts/component.js b/gsa/src/web/pages/alerts/component.js index 0b77e3e428..6152e10506 100644 --- a/gsa/src/web/pages/alerts/component.js +++ b/gsa/src/web/pages/alerts/component.js @@ -140,7 +140,6 @@ class AlertComponent extends React.Component { this.handleOpenContentComposerDialog = this.handleOpenContentComposerDialog.bind( this, ); - this.openContentComposerDialog = this.openContentComposerDialog.bind(this); this.closeContentComposerDialog = this.closeContentComposerDialog.bind( this, ); From f36fdffc9f9dcba6ba32b7088b77822970928e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Mon, 15 Apr 2019 10:43:34 +0200 Subject: [PATCH 2/6] Always open content composer in alert dialog Regardless of whether the displayed filter could be loaded always open the content composer from the alert dialog. --- gsa/src/web/pages/alerts/component.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gsa/src/web/pages/alerts/component.js b/gsa/src/web/pages/alerts/component.js index 6152e10506..6a4c62493a 100644 --- a/gsa/src/web/pages/alerts/component.js +++ b/gsa/src/web/pages/alerts/component.js @@ -243,15 +243,17 @@ class AlertComponent extends React.Component { handleOpenContentComposerDialog() { const {gmp} = this.props; const {composerFilterId = NO_VALUE} = this.state; + gmp.filter.get({id: composerFilterId}).then(response => { this.setState({ composerFilterString: isDefined(response.data) ? response.data.toFilterCriteriaString() : undefined, }); - this.openContentComposerDialog(); - this.handleInteraction(); }); + + this.openContentComposerDialog(); + this.handleInteraction(); } closeContentComposerDialog() { From 141027ec72295f63d4bb193b3aac2dbbcf5ea747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Mon, 15 Apr 2019 11:30:57 +0200 Subject: [PATCH 3/6] Don't pass filter string to alert content composer This allows to remove loading of the filter from alerts component because we get the used filter from the already passed list of filters. --- gsa/src/web/pages/alerts/component.js | 29 +++---------------- .../web/pages/alerts/contentcomposerdialog.js | 14 ++++----- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/gsa/src/web/pages/alerts/component.js b/gsa/src/web/pages/alerts/component.js index 6a4c62493a..f93b464fa2 100644 --- a/gsa/src/web/pages/alerts/component.js +++ b/gsa/src/web/pages/alerts/component.js @@ -241,18 +241,8 @@ class AlertComponent extends React.Component { } handleOpenContentComposerDialog() { - const {gmp} = this.props; - const {composerFilterId = NO_VALUE} = this.state; - - gmp.filter.get({id: composerFilterId}).then(response => { - this.setState({ - composerFilterString: isDefined(response.data) - ? response.data.toFilterCriteriaString() - : undefined, - }); - }); - this.openContentComposerDialog(); + this.handleInteraction(); } @@ -261,13 +251,11 @@ class AlertComponent extends React.Component { method_data_composer_include_notes, method_data_composer_include_overrides, filter_id, - filter_string, } = this.state; this.setState({ composerIncludeNotes: method_data_composer_include_notes, composerIncludeOverrides: method_data_composer_include_overrides, composerFilterId: filter_id, - composerFilterString: filter_string, composerStoreAsDefault: NO_VALUE, contentComposerDialogVisible: false, }); @@ -292,7 +280,6 @@ class AlertComponent extends React.Component { } this.setState({ filter_id: filterId, - filter_string: filterString, method_data_composer_include_notes: includeNotes, method_data_composer_include_overrides: includeOverrides, composerStoreAsDefault: NO_VALUE, @@ -902,16 +889,10 @@ class AlertComponent extends React.Component { } handleFilterIdChange(value) { - const {gmp} = this.props; - gmp.filter.get({id: value}).then(response => { - const composerFilterString = isDefined(response.data) - ? response.data.toFilterCriteriaString() - : undefined; - this.setState({ - composerFilterId: value, - composerFilterString, - }); + this.setState({ + composerFilterId: value, }); + this.handleInteraction(); } @@ -947,7 +928,6 @@ class AlertComponent extends React.Component { filters, filter_id, composerFilterId, - composerFilterString, composerIncludeNotes, composerIncludeOverrides, credentials, @@ -1206,7 +1186,6 @@ class AlertComponent extends React.Component { includeOverrides={parseYesNo(composerIncludeOverrides)} filterId={composerFilterId} filters={result_filters} - filterString={composerFilterString} storeAsDefault={parseYesNo(composerStoreAsDefault)} title={_('Compose Content for Scan Report')} onChange={this.handleValueChange} diff --git a/gsa/src/web/pages/alerts/contentcomposerdialog.js b/gsa/src/web/pages/alerts/contentcomposerdialog.js index 505ff9efe7..6e469b9c32 100644 --- a/gsa/src/web/pages/alerts/contentcomposerdialog.js +++ b/gsa/src/web/pages/alerts/contentcomposerdialog.js @@ -46,9 +46,8 @@ const StyledDiv = styled.div` `; const ContentComposerDialog = ({ - filterId, - filters, - filterString = '', + filterId = UNSET_VALUE, + filters = [], includeNotes = COMPOSER_CONTENT_DEFAULTS.includeNotes, includeOverrides = COMPOSER_CONTENT_DEFAULTS.includeOverrides, storeAsDefault, @@ -57,12 +56,11 @@ const ContentComposerDialog = ({ onSave, onChange, }) => { - filterId = - filterId === NO_VALUE || !isDefined(filterId) ? UNSET_VALUE : filterId; + const filter = + filterId === UNSET_VALUE ? undefined : filters.find(f => f.id === filterId); const controlledValues = { filterId, - filterString, includeNotes, includeOverrides, storeAsDefault, @@ -81,7 +79,7 @@ const ContentComposerDialog = ({