Skip to content

Commit af03d8c

Browse files
committed
feat: add Devtron license DTO and related parsing logic
1 parent 48f47c7 commit af03d8c

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ export const DATE_TIME_FORMATS = {
400400
TWELVE_HOURS_EXPORT_FORMAT: 'DD-MMM-YYYY hh.mm A',
401401
DD_MMM_YYYY_HH_MM: 'DD MMM YYYY, hh:mm',
402402
DD_MMM_YYYY: 'DD MMM YYYY',
403+
'DD/MM/YYYY': 'DD/MM/YYYY',
403404
}
404405

405406
export const SEMANTIC_VERSION_DOCUMENTATION_LINK = 'https://semver.org/'

src/Shared/Helpers.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
import {
5151
AggregationKeys,
5252
BorderConfigType,
53+
DevtronLicenseDTO,
5354
GitTriggers,
5455
IntersectionChangeHandler,
5556
IntersectionOptions,
@@ -67,6 +68,7 @@ import {
6768
PodMetadatum,
6869
} from './Components'
6970
import { getAggregator } from '../Pages'
71+
import { DevtronLicenseCardProps, LicenseStatus } from './Components/LicenseInfoDialog/LicenseInfoDialog.components'
7072

7173
interface HighlightSearchTextProps {
7274
/**
@@ -1065,3 +1067,43 @@ export const deriveBorderRadiusAndBorderClassFromConfig = ({
10651067

10661068
export const getClassNameForStickyHeaderWithShadow = (isStuck: boolean, topClassName = 'dc__top-0') =>
10671069
`dc__position-sticky ${topClassName} dc__transition--box-shadow ${isStuck ? 'dc__box-shadow--header' : ''}`
1070+
1071+
const getDevtronLicenseStatus = ({
1072+
ttl,
1073+
reminderThreshold,
1074+
}: Pick<DevtronLicenseDTO, 'ttl' | 'reminderThreshold'>): DevtronLicenseCardProps['licenseStatus'] => {
1075+
if (ttl < 0) {
1076+
return LicenseStatus.EXPIRED
1077+
}
1078+
1079+
if (ttl < reminderThreshold) {
1080+
return LicenseStatus.REMINDER_THRESHOLD_REACHED
1081+
}
1082+
1083+
return LicenseStatus.ACTIVE
1084+
}
1085+
1086+
export const parseDevtronLicenseDTOIntoLicenseCardData = <isCentralDashboard extends boolean = false>(
1087+
licenseDTO: DevtronLicenseDTO<isCentralDashboard>,
1088+
currentUserEmail?: isCentralDashboard extends true ? string : never,
1089+
): DevtronLicenseCardProps => {
1090+
const {
1091+
isTrial,
1092+
expiry,
1093+
ttl,
1094+
reminderThreshold,
1095+
organisationMetadata,
1096+
license,
1097+
licenseSuffix,
1098+
claimedByUserDetails,
1099+
} = licenseDTO || {}
1100+
1101+
return {
1102+
enterpriseName: organisationMetadata?.name || '',
1103+
expiryDate: expiry ? moment(expiry).format(DATE_TIME_FORMATS['DD/MM/YYYY']) : '',
1104+
ttl,
1105+
licenseStatus: getDevtronLicenseStatus({ ttl, reminderThreshold }),
1106+
isTrial,
1107+
...(currentUserEmail === claimedByUserDetails?.email ? { licenseKey: license } : { licenseSuffix }),
1108+
}
1109+
}

src/Shared/types.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,3 +1031,42 @@ export interface AppEnvIdType {
10311031
appId: number
10321032
envId: number
10331033
}
1034+
1035+
export interface DevtronLicenseBaseDTO {
1036+
fingerprint: string
1037+
isTrial: boolean
1038+
/**
1039+
* In timestamp format
1040+
*/
1041+
expiry: string
1042+
/**
1043+
* Can be negative, depicts time left in seconds for license to expire
1044+
*/
1045+
ttl: number
1046+
/**
1047+
* Show a reminder after these many DAYS left for license to expire, i.e,
1048+
* Show if `ttl` is less than `reminderThreshold` [converted to seconds]
1049+
*/
1050+
reminderThreshold: number
1051+
organisationMetadata: {
1052+
name: string
1053+
domain: string
1054+
}
1055+
}
1056+
1057+
export type DevtronLicenseDTO<isCentralDashboard extends boolean = false> = DevtronLicenseBaseDTO &
1058+
(isCentralDashboard extends true
1059+
? {
1060+
claimedByUserDetails: {
1061+
firstName: string
1062+
lastName: string
1063+
email: string
1064+
}
1065+
license: string
1066+
licenseSuffix?: never
1067+
}
1068+
: {
1069+
claimedByUserDetails?: never
1070+
license?: never
1071+
licenseSuffix: string
1072+
})

0 commit comments

Comments
 (0)