1- import { useEffect , useMemo , useRef , useState } from 'react'
1+ import { useCallback , useEffect , useMemo , useRef , useState } from 'react'
22import { useHistory } from 'react-router-dom'
33
44import {
@@ -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