From 7f8f355d52d63838a7e6d3c5c7401819bb50be34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 6 Aug 2020 14:35:45 +0200 Subject: [PATCH 1/7] Update wording Use camelCase for all variables. --- gsa/src/web/entities/__tests__/filterprovider.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gsa/src/web/entities/__tests__/filterprovider.js b/gsa/src/web/entities/__tests__/filterprovider.js index 3f7a44128d..d2615e9dd8 100644 --- a/gsa/src/web/entities/__tests__/filterprovider.js +++ b/gsa/src/web/entities/__tests__/filterprovider.js @@ -33,7 +33,7 @@ describe('FilterProvider component tests', () => { const locationQuery = {filter: 'location=query'}; - const defaultSettingfilter = Filter.fromString('foo=bar'); + const defaultSettingFilter = Filter.fromString('foo=bar'); const getSetting = jest.fn().mockResolvedValue({}); const gmp = { @@ -50,7 +50,7 @@ describe('FilterProvider component tests', () => { store.dispatch(loadingActions.success({rowsperpage: {value: '42'}})); store.dispatch( - defaultFilterLoadingActions.success('task', defaultSettingfilter), + defaultFilterLoadingActions.success('task', defaultSettingFilter), ); const renderFunc = jest @@ -76,7 +76,7 @@ describe('FilterProvider component tests', () => { const emptyFilter = Filter.fromString('rows=42'); - const defaultSettingfilter = Filter.fromString('foo=bar'); + const defaultSettingFilter = Filter.fromString('foo=bar'); const getSetting = jest.fn().mockResolvedValue({}); const gmp = { @@ -93,7 +93,7 @@ describe('FilterProvider component tests', () => { store.dispatch(loadingActions.success({rowsperpage: {value: '42'}})); store.dispatch( - defaultFilterLoadingActions.success('task', defaultSettingfilter), + defaultFilterLoadingActions.success('task', defaultSettingFilter), ); store.dispatch(pageFilter('task', pFilter)); @@ -114,7 +114,7 @@ describe('FilterProvider component tests', () => { test('should use defaultSettingFilter', async () => { const resultingFilter = Filter.fromString('foo=bar rows=42'); - const defaultSettingfilter = Filter.fromString('foo=bar'); + const defaultSettingFilter = Filter.fromString('foo=bar'); const emptyFilter = Filter.fromString('rows=42'); @@ -133,7 +133,7 @@ describe('FilterProvider component tests', () => { store.dispatch(loadingActions.success({rowsperpage: {value: '42'}})); store.dispatch( - defaultFilterLoadingActions.success('task', defaultSettingfilter), + defaultFilterLoadingActions.success('task', defaultSettingFilter), ); const renderFunc = jest @@ -150,7 +150,7 @@ describe('FilterProvider component tests', () => { expect(renderFunc).not.toHaveBeenCalledWith({filter: emptyFilter}); }); - test('should use fallbackfilter if defaultSettingFilter could not be loaded', async () => { + test('should use fallbackFilter if defaultSettingFilter could not be loaded', async () => { const resultingFilter = Filter.fromString('fall=back rows=42'); const fallbackFilter = Filter.fromString('fall=back'); From a873e07678de684bee973e0e0a94092823f1458b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 6 Aug 2020 14:53:23 +0200 Subject: [PATCH 2/7] Don't change global filter object Filter model objects are mutable. Therefore a copy must be created to not influence other tests. --- gsa/src/web/entities/__tests__/filterprovider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsa/src/web/entities/__tests__/filterprovider.js b/gsa/src/web/entities/__tests__/filterprovider.js index d2615e9dd8..88aa0211ac 100644 --- a/gsa/src/web/entities/__tests__/filterprovider.js +++ b/gsa/src/web/entities/__tests__/filterprovider.js @@ -231,7 +231,7 @@ describe('FilterProvider component tests', () => { }); test('should use default fallbackFilter as last resort', async () => { - const resultingFilter = DEFAULT_FALLBACK_FILTER.set('rows', 42); + const resultingFilter = DEFAULT_FALLBACK_FILTER.copy().set('rows', 42); const getSetting = jest.fn().mockResolvedValue({}); const subscribe = jest.fn(); From d29fdbba30f7a088999519d3eb3d9d77046a7e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 6 Aug 2020 14:54:39 +0200 Subject: [PATCH 3/7] Allow to use a different name to load the page filter The FilterProvider is used to load and determine a filter (mostly) for list pages. In saved the current used filter at a list page in the redux store under the gmp name e.g. task. This change allows to use a different name for the filter saved in the redux store. --- .../web/entities/__tests__/filterprovider.js | 46 +++++++++++++++++++ gsa/src/web/entities/filterprovider.js | 8 +++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/gsa/src/web/entities/__tests__/filterprovider.js b/gsa/src/web/entities/__tests__/filterprovider.js index 88aa0211ac..bf7d978bd2 100644 --- a/gsa/src/web/entities/__tests__/filterprovider.js +++ b/gsa/src/web/entities/__tests__/filterprovider.js @@ -111,6 +111,52 @@ describe('FilterProvider component tests', () => { expect(renderFunc).not.toHaveBeenCalledWith({filter: emptyFilter}); }); + test('should allow to set a pageName for loading the pageFilter', async () => { + const gmpName = 'task'; + const pageName = 'foo-bar-baz'; + const resultingFilter = Filter.fromString('page=filter rows=42'); + + const pFilter = Filter.fromString('page=filter'); + + const emptyFilter = Filter.fromString('rows=42'); + + const defaultSettingFilter = Filter.fromString('foo=bar'); + + const getSetting = jest.fn().mockResolvedValue({}); + const gmp = { + user: { + getSetting, + }, + }; + + const {render, store} = rendererWith({ + gmp, + store: true, + router: true, + }); + + store.dispatch(loadingActions.success({rowsperpage: {value: '42'}})); + store.dispatch( + defaultFilterLoadingActions.success(gmpName, defaultSettingFilter), + ); + store.dispatch(pageFilter(pageName, pFilter)); + + const renderFunc = jest + .fn() + .mockReturnValue(); + + const {getByTestId} = render( + + {renderFunc} + , + ); + + await waitForElement(() => getByTestId('awaiting-span')); + + expect(renderFunc).toHaveBeenCalledWith({filter: resultingFilter}); + expect(renderFunc).not.toHaveBeenCalledWith({filter: emptyFilter}); + }); + test('should use defaultSettingFilter', async () => { const resultingFilter = Filter.fromString('foo=bar rows=42'); diff --git a/gsa/src/web/entities/filterprovider.js b/gsa/src/web/entities/filterprovider.js index e7f61dcc30..1f165faf77 100644 --- a/gsa/src/web/entities/filterprovider.js +++ b/gsa/src/web/entities/filterprovider.js @@ -45,6 +45,7 @@ const FilterProvider = ({ children, fallbackFilter, gmpname, + pageName = gmpname, locationQuery = {}, }) => { const gmp = useGmp(); @@ -96,12 +97,14 @@ const FilterProvider = ({ useEffect(() => { if (isDefined(locationQuery.filter)) { - dispatch(setPageFilter(gmpname, Filter.fromString(locationQuery.filter))); + dispatch( + setPageFilter(pageName, Filter.fromString(locationQuery.filter)), + ); } setLocationQueryFilter(undefined); }, []); // eslint-disable-line react-hooks/exhaustive-deps - const pageFilter = useSelector(state => getPage(state).getFilter(gmpname)); + const pageFilter = useSelector(state => getPage(state).getFilter(pageName)); if (isDefined(locationQueryFilter)) { returnedFilter = locationQueryFilter; @@ -146,6 +149,7 @@ FilterProvider.propTypes = { locationQuery: PropTypes.shape({ filter: PropTypes.string, }), + pageName: PropTypes.string, }; export default FilterProvider; From c9dbf993d056c4a106b98072d215a48a029fddf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 6 Aug 2020 14:57:33 +0200 Subject: [PATCH 4/7] Revert commit and use filter from FilterProvider again Revert 60ec7eb8f0d8d63811b680584e422a4d28eb2d08 and PR #2358 because it doesn't fix the cause of the original problem. --- gsa/src/web/pages/reports/detailspage.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gsa/src/web/pages/reports/detailspage.js b/gsa/src/web/pages/reports/detailspage.js index 197d9d9f41..d75b0a40dc 100644 --- a/gsa/src/web/pages/reports/detailspage.js +++ b/gsa/src/web/pages/reports/detailspage.js @@ -714,6 +714,11 @@ const load = ({ filter = reportFilter; } + if (!hasValue(filter)) { + // use filter from user setting + filter = defaultFilter; + } + if (!hasValue(filter)) { // use fallback filter filter = DEFAULT_FILTER; From 7ec8842bbcdeef6f670214140ce6d2a7d1f0ba1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 6 Aug 2020 15:00:22 +0200 Subject: [PATCH 5/7] During loading a report use the stored page filter The page filter is already passed via redux connect and should be used for loading the report with second highest priority. --- gsa/src/web/pages/reports/detailspage.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gsa/src/web/pages/reports/detailspage.js b/gsa/src/web/pages/reports/detailspage.js index d75b0a40dc..ae042927a4 100644 --- a/gsa/src/web/pages/reports/detailspage.js +++ b/gsa/src/web/pages/reports/detailspage.js @@ -706,6 +706,7 @@ const load = ({ reportId, // eslint-disable-next-line no-shadow loadReportWithThreshold, + pageFilter, reportFilter, updateFilter, }) => filter => { @@ -714,6 +715,11 @@ const load = ({ filter = reportFilter; } + if (!hasValue(filter)) { + // use filter from store + filter = pageFilter; + } + if (!hasValue(filter)) { // use filter from user setting filter = defaultFilter; From 9509dfa9e332bbc3d00b3774776138fe2e8a5151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 6 Aug 2020 15:02:49 +0200 Subject: [PATCH 6/7] Update loading of results filter for report details When determining the filter for loading a report and its results we need to ensure that the user settings are considered but not to use the stored filter of the results list page. Therefore use a different page name in the FilterProvider to load the report results filter. The resulting filter is passed as defaultFilter to the load function. --- gsa/src/web/pages/reports/detailspage.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gsa/src/web/pages/reports/detailspage.js b/gsa/src/web/pages/reports/detailspage.js index ae042927a4..21be7f4450 100644 --- a/gsa/src/web/pages/reports/detailspage.js +++ b/gsa/src/web/pages/reports/detailspage.js @@ -735,7 +735,11 @@ const load = ({ }; const ReportDetailsWrapper = ({reportFilter, ...props}) => ( - + {({filter}) => ( Date: Thu, 6 Aug 2020 15:09:11 +0200 Subject: [PATCH 7/7] Add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fe5d5aa53..da7865df91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Deleting a single entity now removes its ID from store [#1839](https://github.com/greenbone/gsa/pull/1839) ### Fixed +- Don't use stored result list page filter at report results tab [#2366](https://github.com/greenbone/gsa/pull/2366) - Fixed flickering reports [#2359](https://github.com/greenbone/gsa/pull/2359) - Fixed "Hosts scanned" in report details disappearing during page refresh [#2357](https://github.com/greenbone/gsa/pull/2357) - Fixed schedule_periods not forwarded if there is no schedule [#2331](https://github.com/greenbone/gsa/pull/2331)