Skip to content

Commit bd9ca15

Browse files
committed
chore: bump version to 1.21.1-beta-3; update LicenseCard component to include isFreeForever logic and enhance license status handling
1 parent a3aa6c5 commit bd9ca15

6 files changed

Lines changed: 73 additions & 32 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.21.1-beta-2",
3+
"version": "1.21.1-beta-3",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Shared/Components/License/DevtronLicenseCard.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { LicensingErrorCodes } from '@Shared/types'
2727

2828
import { Button, ButtonComponentType, ButtonVariantType } from '../Button'
2929
import { Icon } from '../Icon'
30-
import { DevtronLicenseCardProps, LicenseStatus } from './types'
30+
import { DevtronLicenseCardProps, LicenseCardSubTextProps, LicenseStatus } from './types'
3131
import { getLicenseColorsAccordingToStatus } from './utils'
3232

3333
import './licenseCard.scss'
@@ -49,10 +49,11 @@ const LicenseCardSubText = ({
4949
isFreemium,
5050
licenseStatus,
5151
licenseStatusError,
52-
}: Pick<DevtronLicenseCardProps, 'isFreemium' | 'licenseStatus' | 'licenseStatusError'>) => {
53-
if (isFreemium) {
54-
const freemiumLimitReached = licenseStatusError?.code === LicensingErrorCodes.ClusterLimitExceeded
52+
isFreeForever,
53+
}: LicenseCardSubTextProps) => {
54+
const freemiumLimitReached = isFreemium && licenseStatusError?.code === LicensingErrorCodes.ClusterLimitExceeded
5555

56+
if (isFreeForever || freemiumLimitReached) {
5657
return (
5758
<div className="p-16 fs-13 lh-1-5 flexbox-col dc__gap-8">
5859
<div className="flexbox dc__gap-8 dc__content-space fs-13 fw-4 lh-20 cn-9">
@@ -132,7 +133,15 @@ export const DevtronLicenseCard = ({
132133
licenseStatusError,
133134
isSaasInstance,
134135
}: DevtronLicenseCardProps) => {
135-
const { bgColor, textColor } = getLicenseColorsAccordingToStatus({ isFreemium, licenseStatus, licenseStatusError })
136+
const isFreeForever = isFreemium && !isSaasInstance
137+
138+
const { bgColor, textColor } = getLicenseColorsAccordingToStatus({
139+
isFreemium,
140+
licenseStatus,
141+
licenseStatusError,
142+
isSaasInstance,
143+
})
144+
136145
const isThemeDark = appTheme === AppThemeType.dark
137146

138147
const cardRef = useRef<HTMLDivElement>(null)
@@ -178,7 +187,7 @@ export const DevtronLicenseCard = ({
178187
: useMotionTemplate`linear-gradient(55deg, transparent, rgba(255, 255, 255, ${sheenOpacity}) ${sheenPosition}%, transparent)`
179188

180189
const getRemainingTimeString = () => {
181-
if (isFreemium) {
190+
if (isFreeForever) {
182191
return null
183192
}
184193

@@ -224,12 +233,10 @@ export const DevtronLicenseCard = ({
224233
)}
225234
</div>
226235
<div className="flexbox dc__align-items-center dc__gap-4 flex-wrap fs-12">
227-
{!isSaasInstance && (
228-
<span className="font-ibm-plex-mono cn-9">
229-
{isFreemium ? 'VALID FOREVER' : expiryDate}
230-
</span>
231-
)}
232-
{!isFreemium && (
236+
<span className="font-ibm-plex-mono cn-9">
237+
{isFreeForever ? 'VALID FOREVER' : expiryDate}
238+
</span>
239+
{!isFreeForever && (
233240
<>
234241
<span className="cn-9">·</span>
235242
<span style={{ color: textColor }}>{getRemainingTimeString()}</span>
@@ -249,6 +256,7 @@ export const DevtronLicenseCard = ({
249256
isFreemium={isFreemium}
250257
licenseStatusError={licenseStatusError}
251258
licenseStatus={licenseStatus}
259+
isFreeForever={isFreeForever}
252260
/>
253261
</div>
254262
)

src/Shared/Components/License/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export type DevtronLicenseCardProps = {
4646
}
4747
)
4848

49+
export interface LicenseCardSubTextProps
50+
extends Pick<DevtronLicenseCardProps, 'isFreemium' | 'licenseStatus' | 'licenseStatusError'> {
51+
isFreeForever: boolean
52+
}
53+
4954
export type DevtronLicenseInfo = Omit<DevtronLicenseCardProps, 'appTheme'> &
5055
Pick<DevtronLicenseDTO, 'fingerprint' | 'showLicenseData' | 'licenseStatusError' | 'moduleLimits'>
5156

src/Shared/Components/License/utils.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,22 @@ export const getLicenseColorsAccordingToStatus = ({
2727
isFreemium,
2828
licenseStatus,
2929
licenseStatusError,
30-
}: Pick<DevtronLicenseCardProps, 'licenseStatus' | 'isFreemium' | 'licenseStatusError'>): {
30+
isSaasInstance,
31+
}: Pick<DevtronLicenseCardProps, 'licenseStatus' | 'isFreemium' | 'licenseStatusError' | 'isSaasInstance'>): {
3132
bgColor: string
3233
textColor: string
3334
} => {
3435
if (isFreemium) {
3536
const freemiumLimitReached = licenseStatusError?.code === LicensingErrorCodes.ClusterLimitExceeded
36-
return freemiumLimitReached
37-
? { bgColor: 'var(--R100)', textColor: 'var(--R500)' }
38-
: { bgColor: 'var(--G100)', textColor: 'var(--G500)' }
37+
if (freemiumLimitReached) {
38+
return { bgColor: 'var(--R100)', textColor: 'var(--R500)' }
39+
}
40+
41+
if (!isSaasInstance) {
42+
return { bgColor: 'var(--G100)', textColor: 'var(--G500)' }
43+
}
3944
}
45+
4046
switch (licenseStatus) {
4147
case LicenseStatus.ACTIVE:
4248
return { bgColor: 'var(--G100)', textColor: 'var(--G500)' }
@@ -68,17 +74,24 @@ export const parseDevtronLicenseDTOIntoLicenseCardData = <isCentralDashboard ext
6874
): Omit<DevtronLicenseCardProps, 'appTheme'> => {
6975
const {
7076
isTrial,
71-
expiry,
72-
ttl,
77+
expiry: onPremExpiry,
78+
ttl: onPremTTL,
7379
reminderThreshold,
7480
organisationMetadata,
7581
license,
7682
claimedByUserDetails,
7783
isFreemium,
7884
licenseStatusError,
7985
isSaasInstance,
86+
timeElapsedSinceCreation,
87+
creationTime,
8088
} = licenseDTO || {}
8189

90+
// In case of Saas expiry date is 30 days from creation time
91+
const expiry = isSaasInstance && creationTime ? moment(creationTime).add(30, 'days').toISOString() : onPremExpiry
92+
// For TTL will use timeElapsedSinceCreation to calculate remaining time for Saas license with 30 days validity, since browser time may differ from server time
93+
const ttl = isSaasInstance && timeElapsedSinceCreation ? 30 * 24 * 60 * 60 - timeElapsedSinceCreation : onPremTTL
94+
8295
return {
8396
enterpriseName: organisationMetadata?.name || 'Devtron Enterprise',
8497
expiryDate: expiry ? moment(expiry).format(DATE_TIME_FORMATS['DD/MM/YYYY']) : '',

src/Shared/types.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,18 +1106,10 @@ export interface LicenseErrorStruct {
11061106
userMessage: string
11071107
}
11081108

1109-
export interface DevtronLicenseBaseDTO {
1109+
export type DevtronLicenseBaseDTO = {
11101110
fingerprint: string | null
11111111
isTrial: boolean | null
11121112
isFreemium: boolean | null
1113-
/**
1114-
* In timestamp format
1115-
*/
1116-
expiry: string | null
1117-
/**
1118-
* Can be negative, depicts time left in seconds for license to expire
1119-
*/
1120-
ttl: number | null
11211113
/**
11221114
* Show a reminder after these many DAYS left for license to expire, i.e,
11231115
* Show if `ttl` is less than `reminderThreshold` [converted to seconds]
@@ -1128,8 +1120,31 @@ export interface DevtronLicenseBaseDTO {
11281120
domain: string | null
11291121
} | null
11301122
license: string | null
1131-
isSaasInstance?: boolean
1132-
}
1123+
} & (
1124+
| {
1125+
isSaasInstance: true
1126+
/**
1127+
* In seconds
1128+
*/
1129+
timeElapsedSinceCreation: number
1130+
creationTime: number
1131+
ttl?: never
1132+
expiry?: never
1133+
}
1134+
| {
1135+
isSaasInstance?: false
1136+
timeElapsedSinceCreation?: never
1137+
creationTime?: never
1138+
/**
1139+
* Can be negative, depicts time left in seconds for license to expire
1140+
*/
1141+
ttl: number | null
1142+
/**
1143+
* In timestamp format
1144+
*/
1145+
expiry: string | null
1146+
}
1147+
)
11331148

11341149
export type DevtronLicenseDTO<isCentralDashboard extends boolean = false> = DevtronLicenseBaseDTO &
11351150
(isCentralDashboard extends true

0 commit comments

Comments
 (0)