Skip to content

Commit ac7e476

Browse files
fix(frontend): #2341 Keep selected option on top of dropdown list on test search screen (#2346)
1 parent 7cc0535 commit ac7e476

File tree

1 file changed

+19
-13
lines changed
  • frontend/src/views/CONSEP/TestingActivities/TestSearch

1 file changed

+19
-13
lines changed

frontend/src/views/CONSEP/TestingActivities/TestSearch/index.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,23 @@ const TestSearch = () => {
240240
}
241241
}, [testTypeQuery.error, activityIdQuery.error]);
242242

243+
const testTypeItems = React.useMemo(
244+
() => (
245+
testTypeQuery.data
246+
? testTypeQuery.data.map((type: string) => ({
247+
id: type,
248+
text: type
249+
}))
250+
: []
251+
),
252+
[testTypeQuery.data]
253+
);
254+
255+
const activityIdItems = React.useMemo(
256+
() => (activityIdQuery.data ? activityIdQuery.data.map((id) => ({ id, text: id })) : []),
257+
[activityIdQuery.data]
258+
);
259+
243260
const handlePageChange = (pageIndex: number, pageSize: number) => {
244261
const sort = sorting[0];
245262
searchMutation.mutate(
@@ -506,14 +523,7 @@ const TestSearch = () => {
506523
id="test-type-input"
507524
className="test-type-input"
508525
titleText="Test type"
509-
items={
510-
testTypeQuery.data
511-
? testTypeQuery.data.map((type: string) => ({
512-
id: type,
513-
text: type
514-
}))
515-
: []
516-
}
526+
items={testTypeItems}
517527
itemToString={(item: { id: string; text: string } | null) => (item ? item.text : '')}
518528
onChange={(event: { selectedItems: Array<{ id: string }> }) => {
519529
handleMultiSelectChanges('testTypes', event.selectedItems.map((it: { id: string }) => it.id));
@@ -524,11 +534,7 @@ const TestSearch = () => {
524534
id="activity-type-input"
525535
className="activity-type-input"
526536
titleText="Choose activity"
527-
items={
528-
activityIdQuery.data
529-
? activityIdQuery.data.map((id) => ({ id, text: id }))
530-
: []
531-
}
537+
items={activityIdItems}
532538
itemToString={(item: { id: string; text: string } | null) => (item ? item.text : '')}
533539
onChange={(event: { selectedItems: Array<{ id: string }> }) => {
534540
handleMultiSelectChanges('activityIds', event.selectedItems.map((it: { id: string }) => it.id));

0 commit comments

Comments
 (0)