From 89207c2496059fd0939461e239077a3e44f14bb1 Mon Sep 17 00:00:00 2001 From: Jan Vorcak Date: Tue, 29 Oct 2024 11:17:29 +0100 Subject: [PATCH] Modify soonToExpire license notification --- .../components/license/LicenseNotification.tsx | 6 +++--- frontend/src/components/license/licenseUtils.ts | 17 ++++++++++++++--- .../src/components/pages/admin/AdminPage.tsx | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/license/LicenseNotification.tsx b/frontend/src/components/license/LicenseNotification.tsx index e12dc0554..34333b4ef 100644 --- a/frontend/src/components/license/LicenseNotification.tsx +++ b/frontend/src/components/license/LicenseNotification.tsx @@ -7,10 +7,10 @@ import { License_Type } from '../../protogen/redpanda/api/console/v1alpha1/licen export const LicenseNotification = observer(() => { const location = useLocation(); - const visibleExpiredLicenses = api.licenses.filter(licenseIsExpired).filter(license => license.type !== License_Type.TRIAL) ?? []; + const visibleExpiredLicenses = api.licenses.filter(licenseIsExpired).filter(license => license.type === License_Type.ENTERPRISE) ?? []; const soonToExpireLicenses = api.licenses - .filter(licenseSoonToExpire) - .filter(licenseCanExpire) + .filter(license => licenseSoonToExpire(license)) + .filter(license => licenseCanExpire(license)) ?? []; const showSomeLicenseExpirationInfo = visibleExpiredLicenses.length || soonToExpireLicenses.length; diff --git a/frontend/src/components/license/licenseUtils.ts b/frontend/src/components/license/licenseUtils.ts index 11e702f67..7ed3fb71d 100644 --- a/frontend/src/components/license/licenseUtils.ts +++ b/frontend/src/components/license/licenseUtils.ts @@ -17,12 +17,23 @@ export const licenseIsExpired = (license: License): boolean => license.type !== * The function returns `true` if the license is set to expire within the offset period from the current date. * * @param {License} license - The license object to check. - * @param {number} [offsetInDays=30] - The number of days to check before the license expires. Defaults to 30 days. + * @param {Partial>} [offsetInDays] - An optional mapping of license types + * to the number of days before expiration to consider for each license type. Defaults to 15 days + * for `TRIAL` licenses and 30 days for `ENTERPRISE` licenses. * @returns {boolean} - Returns `true` if the license will expire within the specified number of days, otherwise `false`. */ -export const licenseSoonToExpire = (license: License, offsetInDays: number = 30): boolean => { +export const licenseSoonToExpire = (license: License, offsetInDays: Partial> = { + [License_Type.TRIAL]: 15, + [License_Type.ENTERPRISE]: 30, +}): boolean => { + const daysToExpire: number | undefined = offsetInDays[license.type] + + if(daysToExpire === undefined) { + return false + } + const millisecondsInADay = 24 * 60 * 60 * 1000; // Number of milliseconds in a day - const offsetInMilliseconds = offsetInDays * millisecondsInADay; + const offsetInMilliseconds = daysToExpire * millisecondsInADay; const timeToExpiration = getTimeToExpiration(license); diff --git a/frontend/src/components/pages/admin/AdminPage.tsx b/frontend/src/components/pages/admin/AdminPage.tsx index f01294a15..b13ad1dd2 100644 --- a/frontend/src/components/pages/admin/AdminPage.tsx +++ b/frontend/src/components/pages/admin/AdminPage.tsx @@ -74,7 +74,7 @@ export default class AdminPage extends PageComponent { :
- You do not have the neccesary permissions to view this page. + You do not have the necessary permissions to view this page.
}