Skip to content

feat(site): show license utilization in general settings #15683

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

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const meta: Meta<typeof GeneralSettingsPageView> = {
deploymentDAUs: MockDeploymentDAUResponse,
invalidExperiments: [],
safeExperiments: [],
entitlements: undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entitlements: undefined,

undefined is JavaScript's equivalent to a zero value, this doesn't do anything

},
};

Expand Down Expand Up @@ -136,3 +137,74 @@ export const invalidExperimentsEnabled: Story = {
invalidExperiments: ["invalid"],
},
};

export const WithLicenseUtilization: Story = {
args: {
entitlements: {
...MockEntitlementsWithUserLimit,
features: {
...MockEntitlementsWithUserLimit.features,
user_limit: {
...MockEntitlementsWithUserLimit.features.user_limit,
enabled: true,
actual: 75,
limit: 100,
entitlement: "entitled",
},
},
},
},
};

export const HighLicenseUtilization: Story = {
args: {
entitlements: {
...MockEntitlementsWithUserLimit,
features: {
...MockEntitlementsWithUserLimit.features,
user_limit: {
...MockEntitlementsWithUserLimit.features.user_limit,
enabled: true,
actual: 95,
limit: 100,
entitlement: "entitled",
},
},
},
},
};

export const ExceedsLicenseUtilization: Story = {
args: {
entitlements: {
...MockEntitlementsWithUserLimit,
features: {
...MockEntitlementsWithUserLimit.features,
user_limit: {
...MockEntitlementsWithUserLimit.features.user_limit,
enabled: true,
actual: 100,
limit: 95,
entitlement: "entitled",
},
},
},
},
};
export const NoLicenseLimit: Story = {
args: {
entitlements: {
...MockEntitlementsWithUserLimit,
features: {
...MockEntitlementsWithUserLimit.features,
user_limit: {
...MockEntitlementsWithUserLimit.features.user_limit,
enabled: false,
actual: 0,
limit: 0,
entitlement: "entitled",
},
},
},
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AlertTitle from "@mui/material/AlertTitle";
import LinearProgress from "@mui/material/LinearProgress";
import type {
DAUsResponse,
Entitlements,
Expand Down Expand Up @@ -36,6 +37,12 @@ export const GeneralSettingsPageView: FC<GeneralSettingsPageViewProps> = ({
safeExperiments,
invalidExperiments,
}) => {
const licenseUtilizationPercentage =
entitlements?.features?.user_limit?.actual &&
entitlements?.features?.user_limit?.limit
? entitlements.features.user_limit.actual /
entitlements.features.user_limit.limit
: undefined;
Copy link
Member

@mafredri mafredri Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Instead of just doing the percentage here, we could prepare the data format in a more convenient way to use in the template:

	const licenseInfo =
		entitlements?.features?.user_limit?.actual &&
		entitlements?.features?.user_limit?.limit
			? {
				valid: true,
				actual: entitlements.features.user_limit.actual,
				limit: entitlements.features.user_limit.limit
			} : {
				valid: false,
				actual: 0,
				limit: 0,
			};

Might not need to even init the actual/limit for the zero case but added it just in case.

return (
<>
<SettingsHeader
Expand All @@ -54,6 +61,37 @@ export const GeneralSettingsPageView: FC<GeneralSettingsPageViewProps> = ({
</ChartSection>
</div>
)}
{licenseUtilizationPercentage && (
<ChartSection title="License Utilization">
<LinearProgress
variant="determinate"
value={(licenseUtilizationPercentage % 1) * 100}
color={
licenseUtilizationPercentage < 0.9
? "primary"
: licenseUtilizationPercentage < 1
? "warning"
: "error"
}
css={{
height: 24,
borderRadius: 4,
marginBottom: 8,
}}
/>
<span
css={{
fontSize: "0.75rem",
display: "block",
textAlign: "right",
}}
>
{Math.round(licenseUtilizationPercentage * 100)}% used (
{entitlements!.features.user_limit.actual}/
{entitlements!.features.user_limit.limit} users)
</span>
</ChartSection>
)}
{invalidExperiments.length > 0 && (
<Alert severity="warning">
<AlertTitle>Invalid experiments in use:</AlertTitle>
Expand Down
Loading