Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: show license expiration alert in Db Console #120490

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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