@@ -11,6 +11,7 @@ import {
11
11
ResponseType ,
12
12
SearchBar ,
13
13
stopPropagation ,
14
+ SupportedKeyboardKeysType ,
14
15
updateUserPreferences ,
15
16
useQuery ,
16
17
useRegisterShortcut ,
@@ -97,7 +98,7 @@ const CommandBarBackdrop = ({ handleClose }: CommandBarBackdropProps) => {
97
98
98
99
return recentActionsGroup
99
100
? [ ...recentActionsGroup . items , ...NAVIGATION_GROUPS . flatMap ( ( group ) => group . items ) ]
100
- : [ ]
101
+ : [ ... NAVIGATION_GROUPS . flatMap ( ( group ) => group . items ) ]
101
102
} , [ areFiltersApplied , recentActionsGroup , filteredGroups ] )
102
103
103
104
const handleClearFilters = ( ) => {
@@ -159,7 +160,6 @@ const CommandBarBackdrop = ({ handleClose }: CommandBarBackdropProps) => {
159
160
160
161
const currentItemId = sanitizeItemId ( item )
161
162
162
- // const updatedRecentActions = recentActionsGroup?.items.filter((action) => action.id !== currentItemId)
163
163
// In this now we will put the id as first item in the list and keep first 5 items then
164
164
const updatedRecentActions : UserPreferencesType [ 'commandBar' ] [ 'recentNavigationActions' ] = [
165
165
{
@@ -187,6 +187,21 @@ const CommandBarBackdrop = ({ handleClose }: CommandBarBackdropProps) => {
187
187
}
188
188
}
189
189
190
+ useEffect ( ( ) => {
191
+ if ( ! isLoading && recentActionsGroup ?. items ?. length && ! areFiltersApplied ) {
192
+ if ( selectedItemIndex !== 0 ) {
193
+ const selectedIndex = selectedItemIndex + recentActionsGroup . items . length
194
+
195
+ const itemElement = itemRefMap . current [ itemFlatList [ selectedIndex ] ?. id ]
196
+ if ( itemElement ) {
197
+ itemElement . scrollIntoView ( { block : 'nearest' , inline : 'nearest' , behavior : 'smooth' } )
198
+ }
199
+
200
+ setSelectedItemIndex ( selectedIndex )
201
+ }
202
+ }
203
+ } , [ isLoading , recentActionsGroup ] )
204
+
190
205
useEffect ( ( ) => {
191
206
const { keys } = SHORT_CUTS . OPEN_COMMAND_BAR
192
207
@@ -261,6 +276,15 @@ const CommandBarBackdrop = ({ handleClose }: CommandBarBackdropProps) => {
261
276
}
262
277
}
263
278
279
+ const renderKeyboardShortcuts = ( keys : SupportedKeyboardKeysType [ ] , label : string ) => (
280
+ < div className = "flexbox dc__gap-8 dc__align-items-center" >
281
+ { keys . map ( ( key ) => (
282
+ < KeyboardShortcut key = { key } keyboardKey = { key } />
283
+ ) ) }
284
+ < span className = "cn-9 fs-12 fw-4 lh-20" > { label } </ span >
285
+ </ div >
286
+ )
287
+
264
288
return (
265
289
< Backdrop onEscape = { handleEscape } onClick = { handleClose } deactivateFocusOnEscape = { ! ! searchText } >
266
290
< div
@@ -294,6 +318,7 @@ const CommandBarBackdrop = ({ handleClose }: CommandBarBackdropProps) => {
294
318
>
295
319
{ ! areFiltersApplied && (
296
320
< CommandGroup
321
+ key = "recent-navigation"
297
322
{ ...( recentActionsGroup || RECENT_ACTIONS_GROUP ) }
298
323
isLoading = { isLoading }
299
324
baseIndex = { 0 }
@@ -310,27 +335,11 @@ const CommandBarBackdrop = ({ handleClose }: CommandBarBackdropProps) => {
310
335
311
336
< div className = "flexbox dc__content-space dc__align-items-center px-20 py-12 border__primary--top bg__secondary" >
312
337
< div className = "flexbox dc__gap-20 dc__align-items-center" >
313
- < div className = "flexbox dc__gap-8 dc__align-items-center" >
314
- < KeyboardShortcut keyboardKey = "ArrowUp" />
315
- < KeyboardShortcut keyboardKey = "ArrowDown" />
316
- < span className = "cn-9 fs-12 fw-4 lh-20" > to navigate</ span >
317
- </ div >
318
-
319
- < div className = "flexbox dc__gap-8 dc__align-items-center" >
320
- < KeyboardShortcut keyboardKey = "Enter" />
321
- < span className = "cn-9 fs-12 fw-4 lh-20" > to select</ span >
322
- </ div >
323
-
324
- < div className = "flexbox dc__gap-8 dc__align-items-center" >
325
- < KeyboardShortcut keyboardKey = "Escape" />
326
- < span className = "cn-9 fs-12 fw-4 lh-20" > to close</ span >
327
- </ div >
328
- </ div >
329
-
330
- < div className = "flexbox dc__gap-8 dc__align-items-center" >
331
- < KeyboardShortcut keyboardKey = ">" />
332
- < span className = "cn-9 fs-12 fw-4 lh-20" > to search actions</ span >
338
+ { renderKeyboardShortcuts ( [ 'ArrowUp' , 'ArrowDown' ] , 'to navigate' ) }
339
+ { renderKeyboardShortcuts ( [ 'Enter' ] , 'to select' ) }
340
+ { renderKeyboardShortcuts ( [ 'Escape' ] , 'to close' ) }
333
341
</ div >
342
+ { renderKeyboardShortcuts ( [ '>' ] , 'to search actions' ) }
334
343
</ div >
335
344
</ div >
336
345
</ Backdrop >
0 commit comments