Skip to content

Commit b445699

Browse files
committed
chore: update ttl to humanize function
1 parent dc058fb commit b445699

File tree

9 files changed

+21
-60
lines changed

9 files changed

+21
-60
lines changed

src/Assets/IconV2/ic-devtron.svg

Lines changed: 0 additions & 1 deletion
Loading

src/Assets/IconV2/ic-timer.svg

Lines changed: 3 additions & 3 deletions
Loading

src/Shared/Components/DevtronLicenseCard/DevtronLicenseCard.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ClipboardButton } from '@Common/index'
22
import { ReactComponent as ICChatSupport } from '@IconsV2/ic-chat-circle-dots.svg'
3-
import { DevtronLicenseCardProps, LicenseStatus } from '@Shared/index'
3+
import { DevtronLicenseCardProps, ENTERPRISE_SUPPORT_LINK, LicenseStatus } from '@Shared/index'
44
import { Button, ButtonVariantType } from '../Button'
55
import { Icon } from '../Icon'
66
import { getLicenseColorsAccordingToStatus, getTTLInHumanReadableFormat } from './utils'
@@ -16,22 +16,22 @@ export const DevtronLicenseCard = ({
1616
ttl,
1717
}: DevtronLicenseCardProps) => {
1818
const { bgColor, textColor } = getLicenseColorsAccordingToStatus(licenseStatus)
19-
const remainingTime = getTTLInHumanReadableFormat(Math.abs(ttl))
19+
const remainingTime = getTTLInHumanReadableFormat(ttl)
2020
const remainingTimeString = ttl < 0 ? `Expired ${remainingTime} ago` : `${remainingTime} remaining`
2121

2222
return (
2323
<div className="flexbox-col p-8 br-16" style={{ backgroundColor: bgColor }}>
2424
<div className="license-card flexbox-col br-12 h-200 bg__tertiary">
2525
<div className="p-20 flexbox-col dc__content-space flex-grow-1">
2626
<div className="flexbox dc__align-items-center dc__content-space">
27-
<span className="font-merriweather cn-9 fs-16 fw-7 lh-1-5">{enterpriseName}</span>
27+
<span className="font-merriweather cn-9 fs-16 fw-7 lh-1-5 dc__truncate">{enterpriseName}</span>
2828
<Icon name="ic-devtron" color="N900" size={24} />
2929
</div>
3030
<div className="flexbox-col dc__gap-4">
3131
<div className="flexbox dc__align-items-center dc__gap-6">
3232
<Icon name="ic-key" color={null} size={20} />
3333
<div className="flex dc__gap-4 cn-7 fs-16 fw-5 lh-1-5 font-ibm-plex-mono">
34-
<span>••••</span>
34+
<span>&bull;&bull;&bull;&bull;</span>
3535
<span>{licenseSuffix || licenseKey?.slice(-8)}</span>
3636
</div>
3737
{licenseKey && <ClipboardButton content={licenseKey} />}
@@ -53,12 +53,13 @@ export const DevtronLicenseCard = ({
5353
<div className="p-16 flexbox-col dc__gap-8">
5454
<div className="flexbox dc__gap-8">
5555
<span>
56-
{/* TODO: Confirm with product team */}
57-
To renew your license mail us at enterprise@devtron.ai or contact your Devtron
58-
representative.
56+
To renew your license mail us at&nbsp;
57+
<a href={`mailto:${ENTERPRISE_SUPPORT_LINK}`}>{ENTERPRISE_SUPPORT_LINK}</a> or contact your
58+
Devtron representative.
5959
</span>
60-
<Icon name="ic-timer" color="Y500" size={16} />
60+
<Icon name={ttl < 0 ? 'ic-timer' : 'ic-error'} color={ttl < 0 ? 'Y500' : 'R500'} size={16} />
6161
</div>
62+
{/* TODO: Add onClick, and common out the button */}
6263
<Button
6364
dataTestId="contact-support"
6465
startIcon={<ICChatSupport />}

src/Shared/Components/DevtronLicenseCard/utils.tsx

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,5 @@ export const getLicenseColorsAccordingToStatus = (
1414
}
1515
}
1616

17-
export const getTTLInHumanReadableFormat = (ttl: number): string => {
18-
const duration = moment.duration(ttl, 'seconds')
19-
20-
if (duration.asYears() >= 1) {
21-
const years = Math.floor(duration.asYears())
22-
const months = duration.months()
23-
if (months > 0) {
24-
return `${years} ${years > 1 ? 'years' : 'year'}, ${months} ${months > 1 ? 'months' : 'month'}`
25-
}
26-
return `${years} ${years > 1 ? 'years' : 'year'}`
27-
}
28-
29-
if (duration.asMonths() >= 1) {
30-
const months = Math.floor(duration.asMonths())
31-
return `${months} ${months > 1 ? 'months' : 'month'}`
32-
}
33-
34-
if (duration.asDays() >= 1) {
35-
const days = Math.floor(duration.asDays())
36-
return `${days} ${days > 1 ? 'days' : 'day'}`
37-
}
38-
39-
if (duration.asHours() >= 1) {
40-
const hours = Math.floor(duration.asHours())
41-
return `${hours} ${hours > 1 ? 'hours' : 'hour'}`
42-
}
43-
44-
const minutes = Math.floor(duration.asMinutes())
45-
return `${minutes} ${minutes > 1 ? 'minutes' : 'minute'}`
46-
}
17+
export const getTTLInHumanReadableFormat = (ttl: number): string =>
18+
moment.duration(Math.abs(ttl), 'seconds').humanize(true)

src/Shared/Components/Header/HelpNav.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ const HelpNav = ({
3535
fetchingServerInfo,
3636
setGettingStartedClicked,
3737
showHelpCard,
38-
openAboutDevtronDialog,
3938
}: HelpNavType) => {
40-
const { currentServerInfo } = useMainContext()
39+
const { currentServerInfo, handleOpenLicenseInfoDialog } = useMainContext()
4140
const isEnterprise = currentServerInfo?.serverInfo?.installationType === InstallationType.ENTERPRISE
4241
const FEEDBACK_FORM_ID = `UheGN3KJ#source=${window.location.hostname}`
4342

@@ -112,7 +111,7 @@ const HelpNav = ({
112111
role="button"
113112
tabIndex={0}
114113
className="help-card__option flexbox dc__align-items-center cn-9 dc__gap-12 fs-14"
115-
onClick={openAboutDevtronDialog}
114+
onClick={handleOpenLicenseInfoDialog}
116115
>
117116
<Icon name="ic-devtron" color="N600" size={20} />
118117
About Devtron

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
showAnnouncementHeader,
5050
tippyProps,
5151
}: PageHeaderType) => {
52-
const {
53-
loginCount,
54-
setLoginCount,
55-
showGettingStartedCard,
56-
setShowGettingStartedCard,
57-
setGettingStartedClicked,
58-
setIsLicenseInfoDialogOpen,
59-
} = useMainContext()
52+
const { loginCount, setLoginCount, showGettingStartedCard, setShowGettingStartedCard, setGettingStartedClicked } =
53+
useMainContext()
6054
const { showSwitchThemeLocationTippy, handleShowSwitchThemeLocationTippyChange } = useTheme()
6155

6256
const { isTippyCustomized, tippyRedirectLink, TippyIcon, tippyMessage, onClickTippyButton, additionalContent } =
@@ -72,10 +66,6 @@ const PageHeader = ({
7266
)
7367
const [expiryDate, setExpiryDate] = useState(0)
7468

75-
const handleOpenLicenseInfoDialog = () => {
76-
setIsLicenseInfoDialogOpen(true)
77-
}
78-
7969
const getCurrentServerInfo = async () => {
8070
try {
8171
const { result } = await getServerInfo(true, true)
@@ -283,7 +273,6 @@ const PageHeader = ({
283273
fetchingServerInfo={currentServerInfo.fetchingServerInfo}
284274
setGettingStartedClicked={setGettingStartedClicked}
285275
showHelpCard={showHelpCard}
286-
openAboutDevtronDialog={handleOpenLicenseInfoDialog}
287276
/>
288277
)}
289278
{!window._env_.K8S_CLIENT &&

src/Shared/Components/Header/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export interface HelpNavType {
6262
fetchingServerInfo: boolean
6363
setGettingStartedClicked: (isClicked: boolean) => void
6464
showHelpCard: boolean
65-
openAboutDevtronDialog: () => void
6665
}
6766

6867
export interface HelpOptionType {

src/Shared/Providers/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface MainContext {
5656
isManifestScanningEnabled: boolean
5757
canOnlyViewPermittedEnvOrgLevel: boolean
5858
viewIsPipelineRBACConfiguredNode: ReactNode
59-
setIsLicenseInfoDialogOpen: (isLicenseInfoDialogOpen: boolean) => void
59+
handleOpenLicenseInfoDialog: () => void
6060
}
6161

6262
export interface MainContextProviderProps {

src/Shared/constants.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,5 @@ export const Routes = {
533533
CI_PIPELINE_PATCH: 'app/ci-pipeline/patch',
534534
WORKFLOW: 'app/app-wf',
535535
}
536+
537+
export const ENTERPRISE_SUPPORT_LINK = 'enterprise@devtron.ai'

0 commit comments

Comments
 (0)