Skip to content

Commit 91b6624

Browse files
committed
feat: refactor CommandBarBackdrop and utils to enhance navigation and search functionality
1 parent 3336f0e commit 91b6624

File tree

2 files changed

+187
-148
lines changed

2 files changed

+187
-148
lines changed

src/Pages/Shared/CommandBar/CommandBarBackdrop.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useMemo, useRef, useState } from 'react'
1+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
22
import { useHistory } from 'react-router-dom'
33

44
import {
@@ -47,18 +47,8 @@ const CommandBarBackdrop = ({ handleClose, isLoadingResourceList, resourceList }
4747

4848
const navigationGroups = useMemo(() => getNavigationGroups(serverMode, isSuperAdmin), [serverMode, isSuperAdmin])
4949

50-
const { data: recentActionsGroup, isLoading } = useQuery({
51-
queryFn: ({ signal }) =>
52-
getUserPreferences(signal).then((response) => {
53-
const responseData: ResponseType<typeof response> = {
54-
code: API_STATUS_CODES.OK,
55-
status: 'OK',
56-
result: response,
57-
}
58-
return responseData
59-
}),
60-
queryKey: ['recentNavigationActions'],
61-
select: ({ result }) =>
50+
const parseRecentActionsGroup = useCallback(
51+
({ result }: ResponseType<Awaited<ReturnType<typeof getUserPreferences>>>) =>
6252
result.commandBar.recentNavigationActions.reduce<CommandBarGroupType>((acc, action) => {
6353
const allGroups = [
6454
...navigationGroups,
@@ -79,6 +69,22 @@ const CommandBarBackdrop = ({ handleClose, isLoadingResourceList, resourceList }
7969
}
8070
return acc
8171
}, structuredClone(RECENT_ACTIONS_GROUP)),
72+
[resourceList],
73+
)
74+
75+
const { data: recentActionsGroup, isLoading } = useQuery({
76+
queryFn: ({ signal }) =>
77+
getUserPreferences(signal).then((response) => {
78+
const responseData: ResponseType<typeof response> = {
79+
code: API_STATUS_CODES.OK,
80+
status: 'OK',
81+
result: response,
82+
}
83+
return responseData
84+
}),
85+
queryKey: ['recentNavigationActions', isLoadingResourceList],
86+
enabled: !isLoadingResourceList,
87+
select: parseRecentActionsGroup,
8288
})
8389

8490
const areFiltersApplied = !!searchText
@@ -159,7 +165,7 @@ const CommandBarBackdrop = ({ handleClose, isLoadingResourceList, resourceList }
159165
const item = itemFlatList[newIndex]
160166
const itemElement = itemRefMap.current[item.id]
161167
if (itemElement) {
162-
itemElement.scrollIntoView({ block: 'nearest', inline: 'nearest' })
168+
itemElement.scrollIntoView({ block: 'center', inline: 'nearest' })
163169
}
164170
return newIndex
165171
})

0 commit comments

Comments
 (0)