Skip to content

Commit 5338c45

Browse files
Merge branch 'develop' into SWAP-4924-user-office-visit-questionary-review-page-error
2 parents 183ed7b + bbea11f commit 5338c45

1 file changed

Lines changed: 36 additions & 15 deletions

File tree

apps/frontend/src/components/proposal/ProposalTableOfficer.tsx

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from '@user-office-software/duo-localisation';
2727
import i18n from 'i18n';
2828
import { TFunction } from 'i18next';
29-
import React, { useContext, useEffect, useState } from 'react';
29+
import React, { useContext, useEffect, useRef, useState } from 'react';
3030
import isEqual from 'react-fast-compare';
3131
import { useTranslation } from 'react-i18next';
3232
import { useSearchParams } from 'react-router-dom';
@@ -380,16 +380,16 @@ const ProposalTableOfficer = ({
380380
<ReduceCapacityIcon data-cy="bulk-reassign-reviews" />
381381
);
382382

383+
const isFirstRender = useRef(true);
384+
383385
useEffect(() => {
384-
let isMounted = true;
386+
if (isFirstRender.current) {
387+
isFirstRender.current = false;
385388

386-
if (isMounted) {
387-
refreshTableData();
389+
return;
388390
}
389391

390-
return () => {
391-
isMounted = false;
392-
};
392+
refreshTableData();
393393
// eslint-disable-next-line react-hooks/exhaustive-deps
394394
}, [JSON.stringify(proposalFilter)]);
395395

@@ -1120,10 +1120,24 @@ const ProposalTableOfficer = ({
11201120
return searchParams;
11211121
});
11221122
}}
1123+
onRowsPerPageChange={(pageSize) => {
1124+
setSearchParams((searchParams) => {
1125+
searchParams.set('pageSize', pageSize.toString());
1126+
searchParams.set('page', '0');
1127+
1128+
return searchParams;
1129+
});
1130+
}}
11231131
onSearchChange={(searchText) => {
1124-
setSearchParams({
1125-
search: searchText ? searchText : '',
1126-
page: searchText ? '0' : page || '',
1132+
setSearchParams((searchParams) => {
1133+
if (searchText) {
1134+
searchParams.set('search', searchText);
1135+
searchParams.set('page', '0');
1136+
} else {
1137+
searchParams.delete('search');
1138+
}
1139+
1140+
return searchParams;
11271141
});
11281142
}}
11291143
onSelectionChange={(selectedItems) => {
@@ -1162,7 +1176,7 @@ const ProposalTableOfficer = ({
11621176
},
11631177
}),
11641178
pageSize: pageSize ? +pageSize : undefined,
1165-
initialPage: search ? 0 : page ? +page : 0,
1179+
initialPage: page ? +page : 0,
11661180
}}
11671181
actions={tableActions}
11681182
onChangeColumnHidden={(columnChange) => {
@@ -1182,11 +1196,18 @@ const ProposalTableOfficer = ({
11821196
const [orderBy] = orderByCollection;
11831197

11841198
if (!orderBy) {
1185-
setSearchParams({});
1199+
setSearchParams((searchParams) => {
1200+
searchParams.delete('sortField');
1201+
searchParams.delete('sortDirection');
1202+
1203+
return searchParams;
1204+
});
11861205
} else {
1187-
setSearchParams({
1188-
sortField: orderBy?.orderByField,
1189-
sortDirection: orderBy?.orderDirection,
1206+
setSearchParams((searchParams) => {
1207+
searchParams.set('sortField', orderBy.orderByField);
1208+
searchParams.set('sortDirection', orderBy.orderDirection);
1209+
1210+
return searchParams;
11901211
});
11911212
}
11921213
}}

0 commit comments

Comments
 (0)