Skip to content

Commit e0da414

Browse files
committed
fix: filtering error on first render for create display
1 parent bfbd85a commit e0da414

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gmp/models/filter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ export const VULNS_FILTER_FILTER = Filter.fromString('type=vuln');
806806

807807
export const DEFAULT_FALLBACK_FILTER = Filter.fromString('sort=name first=1');
808808

809+
export const NO_ROW_LIMIT = -1;
809810
export const RESET_FILTER = Filter.fromString('first=1');
810811

811812
export const DEFAULT_ROWS_PER_PAGE = 50;

src/web/entities/__tests__/filterprovider.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('FilterProvider component tests', () => {
5757
});
5858

5959
test('should prefer pageFilter over defaultSettingFilter', async () => {
60-
const resultingFilter = Filter.fromString('page=filter rows=42');
60+
const resultingFilter = Filter.fromString('page=filter');
6161

6262
const pFilter = Filter.fromString('page=filter');
6363

@@ -99,7 +99,7 @@ describe('FilterProvider component tests', () => {
9999
test('should allow to set a pageName for loading the pageFilter', async () => {
100100
const gmpName = 'task';
101101
const pageName = 'foo-bar-baz';
102-
const resultingFilter = Filter.fromString('page=filter rows=42');
102+
const resultingFilter = Filter.fromString('page=filter');
103103

104104
const pFilter = Filter.fromString('page=filter');
105105

@@ -143,7 +143,7 @@ describe('FilterProvider component tests', () => {
143143
});
144144

145145
test('should use defaultSettingFilter', async () => {
146-
const resultingFilter = Filter.fromString('foo=bar rows=42');
146+
const resultingFilter = Filter.fromString('foo=bar');
147147

148148
const defaultSettingFilter = Filter.fromString('foo=bar');
149149

@@ -180,7 +180,7 @@ describe('FilterProvider component tests', () => {
180180
});
181181

182182
test('should use fallbackFilter if defaultSettingFilter could not be loaded', async () => {
183-
const resultingFilter = Filter.fromString('fall=back rows=42');
183+
const resultingFilter = Filter.fromString('fall=back');
184184

185185
const fallbackFilter = Filter.fromString('fall=back');
186186

@@ -222,7 +222,7 @@ describe('FilterProvider component tests', () => {
222222

223223
test('should use fallbackFilter if given', async () => {
224224
// if no usersettings defaultFilter exists use the given fallbackFilter
225-
const resultingFilter = Filter.fromString('fall=back rows=42');
225+
const resultingFilter = Filter.fromString('fall=back');
226226

227227
const fallbackFilter = Filter.fromString('fall=back');
228228

@@ -260,7 +260,7 @@ describe('FilterProvider component tests', () => {
260260
});
261261

262262
test('should use default fallbackFilter as last resort', async () => {
263-
const resultingFilter = DEFAULT_FALLBACK_FILTER.copy().set('rows', 42);
263+
const resultingFilter = DEFAULT_FALLBACK_FILTER.copy();
264264

265265
const getSetting = testing.fn().mockResolvedValue({});
266266
const subscribe = testing.fn();
@@ -332,7 +332,7 @@ describe('FilterProvider component tests', () => {
332332
});
333333

334334
test('should use default rows per page if rows per page setting could not be loaded', async () => {
335-
const resultingFilter = Filter.fromString('fall=back rows=50');
335+
const resultingFilter = Filter.fromString('fall=back');
336336
const fallbackFilter = Filter.fromString('fall=back');
337337

338338
const getSetting = testing.fn().mockRejectedValue(new Error('an error'));

src/web/hooks/usePageFilter.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Filter, {
1515
DEFAULT_FALLBACK_FILTER,
1616
DEFAULT_ROWS_PER_PAGE,
1717
RESET_FILTER,
18+
NO_ROW_LIMIT,
1819
} from 'gmp/models/filter';
1920

2021
import {isDefined, hasValue} from 'gmp/utils/identity';
@@ -74,6 +75,7 @@ const usePageFilter = (
7475
userSettingDefaultSel.getError(),
7576
];
7677
});
78+
7779
const pageFilter = useShallowEqualSelector(state =>
7880
getPage(state).getFilter(pageName),
7981
);
@@ -113,12 +115,14 @@ const usePageFilter = (
113115

114116
useEffect(() => {
115117
if (hasValue(locationQueryFilterString)) {
116-
dispatch(
117-
setPageFilter(pageName, Filter.fromString(locationQueryFilterString)),
118-
);
118+
const filter = Filter.fromString(locationQueryFilterString);
119+
if (!filter.has('rows') && isDefined(rowsPerPage)) {
120+
filter.set('rows', rowsPerPage);
121+
}
122+
dispatch(setPageFilter(pageName, filter));
119123
}
120124
setLocationQueryFilter(undefined);
121-
}, []); // eslint-disable-line react-hooks/exhaustive-deps
125+
}, [locationQueryFilterString, rowsPerPage, dispatch, pageName]);
122126

123127
if (hasValue(locationQueryFilter)) {
124128
returnedFilter = locationQueryFilter;
@@ -140,7 +144,11 @@ const usePageFilter = (
140144
rowsPerPage = DEFAULT_ROWS_PER_PAGE;
141145
}
142146

143-
if (!returnedFilter.has('rows') && isDefined(rowsPerPage)) {
147+
if (
148+
!returnedFilter.has('rows') &&
149+
isDefined(rowsPerPage) &&
150+
rowsPerPage === NO_ROW_LIMIT
151+
) {
144152
returnedFilter = returnedFilter.set('rows', rowsPerPage);
145153
}
146154

0 commit comments

Comments
 (0)