Skip to content

Commit 565184f

Browse files
authored
Merge pull request #628 from devtron-labs/feat/license-manager-dto
feat: license manager DTO
2 parents 3a9ad03 + dad29d1 commit 565184f

File tree

8 files changed

+83
-18
lines changed

8 files changed

+83
-18
lines changed
Lines changed: 4 additions & 0 deletions
Loading

src/Assets/IconV2/ic-devtron.svg

Lines changed: 3 additions & 18 deletions
Loading

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/Components/Icon/Icon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ReactComponent as ICCode } from '@IconsV2/ic-code.svg'
1919
import { ReactComponent as ICContainer } from '@IconsV2/ic-container.svg'
2020
import { ReactComponent as ICCrown } from '@IconsV2/ic-crown.svg'
2121
import { ReactComponent as ICCube } from '@IconsV2/ic-cube.svg'
22+
import { ReactComponent as ICDevtronHeaderLogo } from '@IconsV2/ic-devtron-header-logo.svg'
2223
import { ReactComponent as ICDevtron } from '@IconsV2/ic-devtron.svg'
2324
import { ReactComponent as ICDockerhub } from '@IconsV2/ic-dockerhub.svg'
2425
import { ReactComponent as ICEcr } from '@IconsV2/ic-ecr.svg'
@@ -94,6 +95,7 @@ export const iconMap = {
9495
'ic-container': ICContainer,
9596
'ic-crown': ICCrown,
9697
'ic-cube': ICCube,
98+
'ic-devtron-header-logo': ICDevtronHeaderLogo,
9799
'ic-devtron': ICDevtron,
98100
'ic-dockerhub': ICDockerhub,
99101
'ic-ecr': ICEcr,

src/Shared/Components/LicenseInfoDialog/LicenseInfoDialog.components.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const DevtronLicenseCard = ({
4646
expiryDate,
4747
licenseStatus,
4848
isTrial,
49+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4950
ttl,
5051
}: DevtronLicenseCardProps) => {
5152
const colorValue = getColorAccordingToStatus(licenseStatus)

src/Shared/Helpers.tsx

Lines changed: 34 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,35 @@ 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 * 24 * 60 * 60) {
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 { isTrial, expiry, ttl, reminderThreshold, organisationMetadata, license, claimedByUserDetails } =
1091+
licenseDTO || {}
1092+
1093+
return {
1094+
enterpriseName: organisationMetadata?.name || '',
1095+
expiryDate: expiry ? moment(expiry).format(DATE_TIME_FORMATS['DD/MM/YYYY']) : '',
1096+
ttl,
1097+
licenseStatus: getDevtronLicenseStatus({ ttl, reminderThreshold }),
1098+
isTrial,
1099+
...(currentUserEmail === claimedByUserDetails?.email ? { licenseKey: license } : { licenseSuffix: license }),
1100+
}
1101+
}

src/Shared/constants.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,5 @@ export const DC_DELETE_SUBTITLES = {
515515
DELETE_ENVIRONMENT_SUBTITLE: 'Are you sure you want to delete this environment?',
516516
DELETE_CLUSTER_SUBTITLES: 'Are you sure you want to delete this cluster?',
517517
}
518+
519+
export const EULA_LINK = 'https://devtron.ai/end-user-license-agreement-eula'

src/Shared/types.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,3 +1031,39 @@ export interface AppEnvIdType {
10311031
appId: number
10321032
envId: number
10331033
}
1034+
1035+
export interface DevtronLicenseBaseDTO {
1036+
fingerprint: string | null
1037+
isTrial: boolean | null
1038+
/**
1039+
* In timestamp format
1040+
*/
1041+
expiry: string | null
1042+
/**
1043+
* Can be negative, depicts time left in seconds for license to expire
1044+
*/
1045+
ttl: number | null
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 | null
1051+
organisationMetadata: {
1052+
name: string | null
1053+
domain: string | null
1054+
} | null
1055+
license: string | null
1056+
}
1057+
1058+
export type DevtronLicenseDTO<isCentralDashboard extends boolean = false> = DevtronLicenseBaseDTO &
1059+
(isCentralDashboard extends true
1060+
? {
1061+
claimedByUserDetails: {
1062+
firstName: string | null
1063+
lastName: string | null
1064+
email: string | null
1065+
} | null
1066+
}
1067+
: {
1068+
claimedByUserDetails?: never
1069+
})

0 commit comments

Comments
 (0)