Skip to content

Commit

Permalink
ui: show license expiration alert in Db Console
Browse files Browse the repository at this point in the history
With this change, new alert message is shown in Db Console
when license is expired or less than 15 days left before
it will expire.
This change doesn't affect clusters that doesn't have
any license set.

Release note (ui change): show alert message in Db Console
when license is expired or less than 15 days left before
it expires.
  • Loading branch information
koorosh committed Mar 15, 2024
1 parent 8c8d633 commit 006838d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/util/dataFromServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface DataFromServer {
OIDCButtonText: string;
OIDCGenerateJWTAuthTokenEnabled: boolean;
FeatureFlags: FeatureFlags;
LicenseType: string;
SecondsUntilLicenseExpiry: number;
}

// Tell TypeScript about `window.dataFromServer`, which is set in a script
Expand Down
73 changes: 73 additions & 0 deletions pkg/ui/workspaces/db-console/src/redux/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,78 @@ export const dataFromServerAlertSelector = createSelector(
},
);

const licenseTypeNames = new Map<
string,
"Trial" | "Enterprise" | "Non-Commercial" | "None"
>([
["Evaluation", "Trial"],
["Enterprise", "Enterprise"],
["NonCommercial", "Non-Commercial"],
["OSS", "None"],
["BSD", "None"],
]);

// licenseTypeSelector returns user-friendly names of license types.
export const licenseTypeSelector = createSelector(
getDataFromServer,
data => licenseTypeNames.get(data.LicenseType) || "None",
);

// daysUntilLicenseExpiresSelector returns number of days remaining before license expires.
export const daysUntilLicenseExpiresSelector = createSelector(
getDataFromServer,
data => {
return Math.ceil(data.SecondsUntilLicenseExpiry / 86400); // seconds in 1 day
},
);

export const showLicenseTTLLocalSetting = new LocalSetting(
"show_license_ttl",
localSettingsSelector,
{ show: true },
);

export const showLicenseTTLAlertSelector = createSelector(
showLicenseTTLLocalSetting.selector,
daysUntilLicenseExpiresSelector,
licenseTypeSelector,
(showLicenseTTL, daysUntilLicenseExpired, licenseType): Alert => {
if (!showLicenseTTL.show) {
return;
}
if (licenseType === "None") {
return;
}
const daysToShowAlert = 14;
let title: string;
let level: AlertLevel;

if (daysUntilLicenseExpired > daysToShowAlert) {
return;
} else if (daysUntilLicenseExpired < 0) {
title = `License expired ${Math.abs(daysUntilLicenseExpired)} days ago`;
level = AlertLevel.CRITICAL;
} else if (daysUntilLicenseExpired === 0) {
title = `License expired`;
level = AlertLevel.CRITICAL;
} else if (daysUntilLicenseExpired <= daysToShowAlert) {
title = `License expires in ${daysUntilLicenseExpired} days`;
level = AlertLevel.WARNING;
}
return {
level: level,
title: title,
showAsAlert: true,
autoClose: false,
closable: true,
dismiss: (dispatch: Dispatch<Action>) => {
dispatch(showLicenseTTLLocalSetting.set({ show: false }));
return Promise.resolve();
},
};
},
);

/**
* Selector which returns an array of all active alerts which should be
* displayed as a banner, which appears at the top of the page and overlaps
Expand All @@ -698,6 +770,7 @@ export const bannerAlertsSelector = createSelector(
terminateSessionAlertSelector,
terminateQueryAlertSelector,
dataFromServerAlertSelector,
showLicenseTTLAlertSelector,
(...alerts: Alert[]): Alert[] => {
return _.without(alerts, null, undefined);
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/ui/workspaces/db-console/src/redux/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const emptyDataFromServer: DataFromServer = {
OIDCGenerateJWTAuthTokenEnabled: false,
Tag: "",
Version: "",
LicenseType: "OSS",
SecondsUntilLicenseExpiry: 0,
};

export const featureFlagSelector = createSelector(
Expand Down
2 changes: 2 additions & 0 deletions pkg/ui/workspaces/db-console/src/util/dataFromServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface DataFromServer {
OIDCButtonText: string;
OIDCGenerateJWTAuthTokenEnabled: boolean;
FeatureFlags: FeatureFlags;
LicenseType: string;
SecondsUntilLicenseExpiry: number;
}
// Tell TypeScript about `window.dataFromServer`, which is set in a script
// tag in index.html, the contents of which are generated in a Go template
Expand Down

0 comments on commit 006838d

Please sign in to comment.