Skip to content

Commit 2f75c95

Browse files
committed
refactor: HelpButton - update typings
1 parent 69a01bb commit 2f75c95

5 files changed

Lines changed: 23 additions & 29 deletions

File tree

src/Shared/Components/Header/HelpButton.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { URLS } from '@Common/Constants'
66
import { ComponentSizeType } from '@Shared/constants'
77
import { useMainContext } from '@Shared/Providers'
88

9-
import { ActionMenu, ActionMenuItemType, ActionMenuProps } from '../ActionMenu'
9+
import { ActionMenu, ActionMenuItemType } from '../ActionMenu'
1010
import { Button, ButtonComponentType, ButtonVariantType } from '../Button'
1111
import { Icon } from '../Icon'
12-
import { HelpButtonProps, HelpMenuItems, InstallationType } from './types'
12+
import { HelpButtonActionMenuProps, HelpButtonProps, HelpMenuItems, InstallationType } from './types'
1313
import { getHelpActionMenuOptions } from './utils'
1414

1515
const CheckForUpdates = ({
@@ -35,12 +35,12 @@ const CheckForUpdates = ({
3535
</div>
3636
)
3737

38-
export const HelpButton = ({ serverInfo, fetchingServerInfo, handleGettingStartedClick, onClick }: HelpButtonProps) => {
38+
export const HelpButton = ({ serverInfo, fetchingServerInfo, onClick }: HelpButtonProps) => {
3939
// STATES
4040
const [isActionMenuOpen, setIsActionMenuOpen] = useState(false)
4141

4242
// HOOKS
43-
const { currentServerInfo, handleOpenLicenseInfoDialog, licenseData } = useMainContext()
43+
const { currentServerInfo, handleOpenLicenseInfoDialog, licenseData, setGettingStartedClicked } = useMainContext()
4444

4545
// REFS
4646
const typeFormSliderButtonRef = useRef(null)
@@ -69,7 +69,11 @@ export const HelpButton = ({ serverInfo, fetchingServerInfo, handleGettingStarte
6969
typeFormSliderButtonRef.current?.open()
7070
}
7171

72-
const handleActionMenuClick: ActionMenuProps['onClick'] = (item) => {
72+
const handleGettingStartedClick = () => {
73+
setGettingStartedClicked(true)
74+
}
75+
76+
const handleActionMenuClick: HelpButtonActionMenuProps['onClick'] = (item) => {
7377
switch (item.id) {
7478
case HelpMenuItems.GETTING_STARTED:
7579
handleGettingStartedClick()
@@ -94,7 +98,7 @@ export const HelpButton = ({ serverInfo, fetchingServerInfo, handleGettingStarte
9498

9599
return (
96100
<>
97-
<ActionMenu
101+
<ActionMenu<HelpMenuItems>
98102
id="page-header-help-action-menu"
99103
alignment="end"
100104
width={220}

src/Shared/Components/Header/PageHeader.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,8 @@ const PageHeader = ({
4949
markAsBeta,
5050
tippyProps,
5151
}: PageHeaderType) => {
52-
const {
53-
loginCount,
54-
setLoginCount,
55-
showGettingStartedCard,
56-
setShowGettingStartedCard,
57-
setGettingStartedClicked,
58-
licenseData,
59-
} = useMainContext()
52+
const { loginCount, setLoginCount, showGettingStartedCard, setShowGettingStartedCard, licenseData } =
53+
useMainContext()
6054
const { showSwitchThemeLocationTippy, handleShowSwitchThemeLocationTippyChange } = useTheme()
6155

6256
const { isTippyCustomized, tippyRedirectLink, TippyIcon, tippyMessage, onClickTippyButton, additionalContent } =
@@ -92,10 +86,6 @@ const PageHeader = ({
9286
setExpiryDate(+localStorage.getItem('clickedOkay'))
9387
}, [])
9488

95-
const handleGettingStartedClick = () => {
96-
setGettingStartedClicked(true)
97-
}
98-
9989
const hideGettingStartedCard = (count?: string) => {
10090
setShowGettingStartedCard(false)
10191
if (count) {
@@ -147,7 +137,6 @@ const PageHeader = ({
147137
<HelpButton
148138
serverInfo={currentServerInfo.serverInfo}
149139
fetchingServerInfo={currentServerInfo.fetchingServerInfo}
150-
handleGettingStartedClick={handleGettingStartedClick}
151140
onClick={onHelpButtonClick}
152141
/>
153142
{!window._env_.K8S_CLIENT && (

src/Shared/Components/Header/constants.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import { DISCORD_LINK, DOCUMENTATION_HOME_PAGE, URLS } from '@Common/Constants'
1818
import { CONTACT_SUPPORT_LINK, OPEN_NEW_TICKET, RAISE_ISSUE, VIEW_ALL_TICKETS } from '@Shared/constants'
1919

20-
import { ActionMenuItemType } from '../ActionMenu'
21-
import { HelpMenuItems } from './types'
20+
import { HelpButtonActionMenuProps, HelpMenuItems } from './types'
2221

23-
export const COMMON_HELP_ACTION_MENU_ITEMS: ActionMenuItemType[] = [
22+
export const COMMON_HELP_ACTION_MENU_ITEMS: HelpButtonActionMenuProps['options'][number]['items'] = [
2423
...((!window._env_?.K8S_CLIENT
2524
? [
2625
{
@@ -31,7 +30,7 @@ export const COMMON_HELP_ACTION_MENU_ITEMS: ActionMenuItemType[] = [
3130
to: `/${URLS.GETTING_STARTED}`,
3231
},
3332
]
34-
: []) satisfies ActionMenuItemType[]),
33+
: []) satisfies HelpButtonActionMenuProps['options'][number]['items']),
3534
{
3635
id: HelpMenuItems.VIEW_DOCUMENTATION,
3736
label: 'View documentation',
@@ -53,7 +52,7 @@ export const COMMON_HELP_ACTION_MENU_ITEMS: ActionMenuItemType[] = [
5352
},
5453
]
5554

56-
export const OSS_HELP_ACTION_MENU_ITEMS: ActionMenuItemType[] = [
55+
export const OSS_HELP_ACTION_MENU_ITEMS: HelpButtonActionMenuProps['options'][number]['items'] = [
5756
{
5857
id: HelpMenuItems.CHAT_WITH_SUPPORT,
5958
label: 'Chat with support',
@@ -70,7 +69,7 @@ export const OSS_HELP_ACTION_MENU_ITEMS: ActionMenuItemType[] = [
7069
},
7170
]
7271

73-
export const ENTERPRISE_TRIAL_HELP_ACTION_MENU_ITEMS: ActionMenuItemType[] = [
72+
export const ENTERPRISE_TRIAL_HELP_ACTION_MENU_ITEMS: HelpButtonActionMenuProps['options'][number]['items'] = [
7473
{
7574
id: HelpMenuItems.REQUEST_SUPPORT,
7675
label: 'Request Support',
@@ -80,7 +79,7 @@ export const ENTERPRISE_TRIAL_HELP_ACTION_MENU_ITEMS: ActionMenuItemType[] = [
8079
},
8180
]
8281

83-
export const ENTERPRISE_HELP_ACTION_MENU_ITEMS: ActionMenuItemType[] = [
82+
export const ENTERPRISE_HELP_ACTION_MENU_ITEMS: HelpButtonActionMenuProps['options'][number]['items'] = [
8483
{
8584
id: HelpMenuItems.OPEN_NEW_TICKET,
8685
label: 'Open new ticket',

src/Shared/Components/Header/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { ModuleStatus } from '@Shared/types'
1818

1919
import { ResponseType, TippyCustomizedProps } from '../../../Common'
20+
import { ActionMenuProps } from '../ActionMenu'
2021

2122
export enum InstallationType {
2223
OSS_KUBECTL = 'oss_kubectl',
@@ -58,7 +59,6 @@ export interface ServerInfoResponse extends ResponseType {
5859
export interface HelpButtonProps {
5960
serverInfo: ServerInfo
6061
fetchingServerInfo: boolean
61-
handleGettingStartedClick: () => void
6262
onClick: () => void
6363
}
6464

@@ -74,3 +74,5 @@ export enum HelpMenuItems {
7474
CHAT_WITH_SUPPORT = 'chat-with-support',
7575
RAISE_ISSUE_REQUEST = 'raise-issue-request',
7676
}
77+
78+
export type HelpButtonActionMenuProps = ActionMenuProps<HelpMenuItems>

src/Shared/Components/Header/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import { LOGIN_COUNT } from '@Common/Constants'
1818

19-
import { ActionMenuProps } from '../ActionMenu'
2019
import { DevtronLicenseInfo, LicenseStatus } from '../License'
2120
import {
2221
COMMON_HELP_ACTION_MENU_ITEMS,
@@ -25,6 +24,7 @@ import {
2524
OSS_HELP_ACTION_MENU_ITEMS,
2625
} from './constants'
2726
import { updatePostHogEvent } from './service'
27+
import { HelpButtonActionMenuProps } from './types'
2828

2929
const millisecondsInDay = 86400000
3030
export const getDateInMilliseconds = (days) => 1 + new Date().valueOf() + (days ?? 0) * millisecondsInDay
@@ -52,7 +52,7 @@ export const getHelpActionMenuOptions = ({
5252
}: {
5353
isEnterprise: boolean
5454
isTrial: boolean
55-
}): ActionMenuProps['options'] => [
55+
}): HelpButtonActionMenuProps['options'] => [
5656
{
5757
items: COMMON_HELP_ACTION_MENU_ITEMS,
5858
},

0 commit comments

Comments
 (0)