Skip to content

Commit 34db6ac

Browse files
committed
feat: Constants, ActionMenu, ProfileMenu - add LOGIN URL constant; update ActionMenuItem to use NumbersCount component; refactor useActionMenu hook for improved performance
1 parent 50a2ca6 commit 34db6ac

File tree

7 files changed

+13
-12
lines changed

7 files changed

+13
-12
lines changed

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const PATTERNS = {
4747
const GLOBAL_CONFIG_TEMPLATES_DEVTRON_APP = '/global-config/templates/devtron-apps'
4848

4949
export const URLS = {
50+
LOGIN: '/login',
5051
LOGIN_SSO: '/login/sso',
5152
PERMISSION_GROUPS: '/global-config/auth/groups',
5253
APP: '/app',

src/Shared/Components/ActionMenu/ActionMenuItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ComponentSizeType } from '@Shared/constants'
66

77
import { Button, ButtonProps, ButtonVariantType } from '../Button'
88
import { Icon } from '../Icon'
9+
import { NumbersCount } from '../NumbersCount'
910
import { getTooltipProps } from '../SelectPicker/common'
1011
import { DTSwitch, DTSwitchProps } from '../Switch'
1112
import { ActionMenuItemProps, ActionMenuItemType } from './types'
@@ -93,7 +94,7 @@ export const ActionMenuItem = <T extends string | number>({
9394
)
9495
}
9596
case 'counter':
96-
return <span className="icon-dim-20 flex px-6 bcn-1 cn-7 br-12 fs-13 lh-20 fw-6">{config.value}</span>
97+
return <NumbersCount count={config.value} />
9798
case 'switch':
9899
return (
99100
<DTSwitch

src/Shared/Components/ActionMenu/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { OmitNever } from '@Shared/types'
55

66
import { ButtonProps } from '../Button'
77
import { IconsProps } from '../Icon'
8+
import { NumbersCountProps } from '../NumbersCount'
89
import { PopoverProps, UsePopoverProps } from '../Popover'
910
import { SelectPickerOptionType, SelectPickerProps } from '../SelectPicker'
1011
import { DTSwitchProps } from '../Switch'
@@ -51,7 +52,7 @@ type TrailingItemType =
5152
| {
5253
type: 'counter'
5354
config: {
54-
value: string | number
55+
value: NumbersCountProps['count']
5556
}
5657
}
5758
| {

src/Shared/Components/ActionMenu/useActionMenu.hook.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeEvent, createRef, RefObject, useEffect, useMemo, useRef, useState } from 'react'
1+
import { ChangeEvent, createRef, RefObject, useEffect, useRef, useState } from 'react'
22

33
import { usePopover, UsePopoverProps } from '../Popover'
44
import { UseActionMenuProps } from './types'
@@ -17,13 +17,9 @@ export const useActionMenu = <T extends string | number>({
1717
const [focusedIndex, setFocusedIndex] = useState(-1)
1818
const [searchTerm, setSearchTerm] = useState('')
1919

20-
// MEMOIZED CONSTANTS
21-
const filteredOptions = useMemo(
22-
() => (isSearchable ? filterActionMenuOptions(options, searchTerm) : options),
23-
[isSearchable, options, searchTerm],
24-
)
25-
26-
const flatOptions = useMemo(() => getActionMenuFlatOptions(filteredOptions), [filteredOptions])
20+
// CONSTANTS
21+
const filteredOptions = isSearchable ? filterActionMenuOptions(options, searchTerm) : options
22+
const flatOptions = getActionMenuFlatOptions(filteredOptions)
2723

2824
// REFS
2925
const itemsRef = useRef<RefObject<HTMLAnchorElement | HTMLButtonElement>[]>(

src/Shared/Components/Header/ProfileMenu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useMemo } from 'react'
22
import { Link } from 'react-router-dom'
33

4+
import { URLS } from '@Common/Constants'
45
import { getAlphabetIcon } from '@Common/Helper'
56
import { clearCookieOnLogout } from '@Shared/Helpers'
67
import { useMainContext } from '@Shared/Providers'
@@ -66,7 +67,7 @@ export const ProfileMenu = ({ user, onClick }: ProfileMenuProps) => {
6667
{viewIsPipelineRBACConfiguredNode}
6768
</div>
6869
<div className="p-4">
69-
<Link to="/login" className="flex dc__gap-8 px-8 py-6 br-4 dc__hover-r50" onClick={onLogout}>
70+
<Link to={URLS.LOGIN} className="flex dc__gap-8 px-8 py-6 br-4 dc__hover-r50" onClick={onLogout}>
7071
<span className="flex-grow-1 fs-13 lh-1-5 fw-4 cr-5">Logout</span>
7172
<Icon name="ic-logout" color="R500" />
7273
</Link>

src/Shared/Components/NumbersCount/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
*/
1616

1717
export { default as NumbersCount } from './NumbersCount.component'
18+
export * from './types'

src/Shared/Components/Popover/usePopover.hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const usePopover = ({
5050
onTriggerKeyDown?.(e, open, closePopover)
5151
}
5252

53-
const handlePopoverKeyDown = (e: React.KeyboardEvent) => onPopoverKeyDown(e, open, closePopover)
53+
const handlePopoverKeyDown = (e: React.KeyboardEvent) => onPopoverKeyDown?.(e, open, closePopover)
5454

5555
const handleOverlayClick = (e: MouseEvent<HTMLDivElement>) => {
5656
if (!popover.current?.contains(e.target as Node)) {

0 commit comments

Comments
 (0)