Skip to content

Commit a9a1012

Browse files
Merge pull request #2916 from devtron-labs/feat/cmd-bar-ux
chore: enhance CommandBarBackdrop with keyword search and icon mapping
2 parents 6aaa75a + 6efbffd commit a9a1012

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

src/Pages/Shared/CommandBar/CommandBarBackdrop.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ const CommandBarBackdrop = ({ handleClose, isLoadingAppList, appList }: CommandB
9797

9898
const additionalGroups = getAdditionalNavGroups(searchText, appList)
9999
const parsedGroups = navigationGroups.reduce<typeof navigationGroups>((acc, group) => {
100-
const filteredItems = group.items.filter((item) => item.title.toLowerCase().includes(lowerCaseSearchText))
100+
const filteredItems = group.items.filter(
101+
(item) =>
102+
item.title.toLowerCase().includes(lowerCaseSearchText) ||
103+
item.keywords?.some((keyword) => keyword.toLowerCase().includes(lowerCaseSearchText)),
104+
)
101105

102106
if (filteredItems.length > 0) {
103107
acc.push({
@@ -146,7 +150,7 @@ const CommandBarBackdrop = ({ handleClose, isLoadingAppList, appList }: CommandB
146150
const item = itemFlatList[newIndex]
147151
const itemElement = itemRefMap.current[item.id]
148152
if (itemElement) {
149-
itemElement.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior: 'smooth' })
153+
itemElement.scrollIntoView({ block: 'nearest', inline: 'nearest' })
150154
}
151155
return newIndex
152156
})
@@ -202,7 +206,7 @@ const CommandBarBackdrop = ({ handleClose, isLoadingAppList, appList }: CommandB
202206

203207
const itemElement = itemRefMap.current[itemFlatList[selectedIndex]?.id]
204208
if (itemElement) {
205-
itemElement.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior: 'smooth' })
209+
itemElement.scrollIntoView({ block: 'nearest', inline: 'nearest' })
206210
}
207211

208212
setSelectedItemIndex(selectedIndex)
@@ -295,7 +299,7 @@ const CommandBarBackdrop = ({ handleClose, isLoadingAppList, appList }: CommandB
295299
}
296300

297301
const renderKeyboardShortcuts = (keys: SupportedKeyboardKeysType[], label: string) => (
298-
<div className="flexbox dc__gap-8 dc__align-items-center">
302+
<div className="flexbox dc__gap-6 dc__align-items-center">
299303
{keys.map((key) => (
300304
<KeyboardShortcut key={key} keyboardKey={key} />
301305
))}
@@ -312,10 +316,10 @@ const CommandBarBackdrop = ({ handleClose, isLoadingAppList, appList }: CommandB
312316
>
313317
<div
314318
onClick={stopPropagation}
315-
className="dc__mxw-720 mxh-500 flexbox-col dc__overflow-hidden dc__content-space br-12 bg__modal--primary command-bar__container w-100 h-100"
319+
className="dc__mxw-720 mxh-500 flexbox-col dc__overflow-hidden dc__content-space br-12 bg__modal--primary command-bar__container border__secondary-translucent w-100 h-100"
316320
>
317321
<div className="flexbox-col dc__overflow-hidden flex-grow-1">
318-
<div className="px-16 py-12">
322+
<div className="px-16 py-12 bg__modal--secondary border__primary--bottom">
319323
<SearchBar
320324
inputProps={{
321325
autoFocus: true,
@@ -340,7 +344,7 @@ const CommandBarBackdrop = ({ handleClose, isLoadingAppList, appList }: CommandB
340344
/>
341345
) : (
342346
<div
343-
className="flexbox-col dc__overflow-auto border__primary--top"
347+
className="flexbox-col dc__overflow-auto"
344348
role="listbox"
345349
aria-label="Command Menu"
346350
aria-activedescendant={itemFlatList[selectedItemIndex]?.id}
@@ -364,7 +368,7 @@ const CommandBarBackdrop = ({ handleClose, isLoadingAppList, appList }: CommandB
364368
)}
365369
</div>
366370

367-
<div className="flexbox dc__content-space dc__align-items-center px-20 py-12 border__primary--top bg__secondary">
371+
<div className="flexbox dc__content-space dc__align-items-center px-20 py-12 border__secondary--top bg__secondary">
368372
<div
369373
className={`flexbox dc__gap-20 dc__align-items-center flex-grow-1 ${showEmptyState ? 'dc__content-center' : ''}`}
370374
>

src/Pages/Shared/CommandBar/constants.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SupportedKeyboardKeysType } from '@devtron-labs/devtron-fe-common-lib'
1+
import { IconName, NavigationItemID, SupportedKeyboardKeysType } from '@devtron-labs/devtron-fe-common-lib'
22

33
import { CommandBarGroupType } from './types'
44

@@ -31,3 +31,9 @@ export const SHORT_CUTS: Record<
3131
description: 'Select Item',
3232
},
3333
}
34+
35+
export const NAV_SUB_ITEMS_ICON_MAPPING: Partial<Record<NavigationItemID, IconName>> = {
36+
'application-management-configurations': 'ic-gear',
37+
'application-management-policies': 'ic-gavel',
38+
'global-configuration-authorization': 'ic-key',
39+
}

src/Pages/Shared/CommandBar/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export type CommandBarItemType = {
1313
id: CommandBarActionIdType | `${typeof RECENT_NAVIGATION_ITEM_ID_PREFIX}${CommandBarActionIdType}`
1414
title: string
1515
icon: IconsProps['name']
16-
iconColor?: IconBaseColorType | 'none'
16+
keywords: string[]
1717
href: NavigationItemType['href']
18+
iconColor?: IconBaseColorType | 'none'
1819
} & (
1920
| {
2021
onSelect?: never

src/Pages/Shared/CommandBar/utils.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { SERVER_MODE, URLS as COMMON_URLS } from '@devtron-labs/devtron-fe-commo
33
import { NAVIGATION_LIST } from '@Components/Navigation/constants'
44
import { URLS } from '@Config/routes'
55

6-
import { DEVTRON_APPLICATIONS_COMMAND_GROUP_ID, RECENT_NAVIGATION_ITEM_ID_PREFIX } from './constants'
6+
import {
7+
DEVTRON_APPLICATIONS_COMMAND_GROUP_ID,
8+
NAV_SUB_ITEMS_ICON_MAPPING,
9+
RECENT_NAVIGATION_ITEM_ID_PREFIX,
10+
} from './constants'
711
import { CommandBarActionIdType, CommandBarBackdropProps, CommandBarGroupType, CommandBarItemType } from './types'
812

913
export const sanitizeItemId = (item: CommandBarItemType) =>
@@ -30,6 +34,7 @@ const getAppManagementAdditionalNavItems = (
3034
icon: 'ic-devtron-app',
3135
iconColor: 'none',
3236
href: URLS.DEVTRON_APP_LIST,
37+
keywords: [],
3338
} satisfies CommandBarGroupType['items'][number],
3439
]
3540
: []),
@@ -39,6 +44,7 @@ const getAppManagementAdditionalNavItems = (
3944
icon: 'ic-helm-app',
4045
iconColor: 'none',
4146
href: URLS.HELM_APP_LIST,
47+
keywords: [],
4248
},
4349
...(window._env_?.ENABLE_EXTERNAL_ARGO_CD && isSuperAdmin
4450
? [
@@ -48,6 +54,7 @@ const getAppManagementAdditionalNavItems = (
4854
icon: 'ic-argocd-app',
4955
iconColor: 'none',
5056
href: URLS.ARGO_APP_LIST,
57+
keywords: [],
5158
} satisfies CommandBarGroupType['items'][number],
5259
]
5360
: []),
@@ -59,6 +66,7 @@ const getAppManagementAdditionalNavItems = (
5966
icon: 'ic-fluxcd-app',
6067
iconColor: 'none',
6168
href: URLS.FLUX_APP_LIST,
69+
keywords: [],
6270
} satisfies CommandBarGroupType['items'][number],
6371
]
6472
: []),
@@ -70,15 +78,16 @@ export const getNavigationGroups = (serverMode: SERVER_MODE, isSuperAdmin: boole
7078
const additionalItems = isAppManagementBlock ? getAppManagementAdditionalNavItems(serverMode, isSuperAdmin) : []
7179

7280
const parsedItems = group.items.flatMap<CommandBarGroupType['items'][number]>(
73-
({ hasSubMenu, subItems, title, href, id, icon }) => {
81+
({ hasSubMenu, subItems, title, href, id, icon, keywords }) => {
7482
if (hasSubMenu && subItems?.length) {
7583
return subItems.map<CommandBarGroupType['items'][number]>((subItem) => ({
7684
title: `${title} / ${subItem.title}`,
7785
id: subItem.id,
7886
// Since icon is not present for some subItems, using from group
79-
icon: group.icon,
87+
icon: NAV_SUB_ITEMS_ICON_MAPPING[id] || group.icon,
8088
// TODO: No href present for some subItems
8189
href: subItem.href ?? null,
90+
keywords: subItem.keywords || [],
8291
}))
8392
}
8493

@@ -88,6 +97,7 @@ export const getNavigationGroups = (serverMode: SERVER_MODE, isSuperAdmin: boole
8897
icon: icon || 'ic-arrow-right',
8998
// TODO: No href present for some items
9099
href: href ?? null,
100+
keywords: keywords || [],
91101
}
92102
},
93103
)
@@ -114,6 +124,7 @@ export const parseAppListToNavItems = (appList: CommandBarBackdropProps['appList
114124
icon: 'ic-devtron-app',
115125
iconColor: 'none',
116126
href: `${COMMON_URLS.APPLICATION_MANAGEMENT_APP}/${app.id}/${URLS.APP_OVERVIEW}`,
127+
keywords: [],
117128
})),
118129
},
119130
]

0 commit comments

Comments
 (0)