fix: avoid error when AI usage is zero (#19388)

Fixes a bug that prevents the managed AI agent usage from showing in the
licenses page of the dashboard when the usage is zero. Adds a story with
this case as well.
This commit is contained in:
Dean Sheather
2025-08-20 07:22:42 +00:00
committed by GitHub
parent c310a3202b
commit 67da780ce4
2 changed files with 24 additions and 2 deletions
@@ -26,6 +26,23 @@ type Story = StoryObj<typeof ManagedAgentsConsumption>;
export const Default: Story = {};
export const ZeroUsage: Story = {
args: {
managedAgentFeature: {
enabled: true,
actual: 0,
soft_limit: 60000,
limit: 120000,
usage_period: {
start: "February 27, 2025",
end: "February 27, 2026",
issued_at: "February 27, 2025",
},
entitlement: "entitled",
},
},
};
export const NearLimit: Story = {
args: {
managedAgentFeature: {
@@ -44,11 +44,16 @@ export const ManagedAgentsConsumption: FC<ManagedAgentsConsumptionProps> = ({
const startDate = managedAgentFeature.usage_period?.start;
const endDate = managedAgentFeature.usage_period?.end;
if (!usage || usage < 0) {
if (usage === undefined || usage < 0) {
return <ErrorAlert error="Invalid usage data" />;
}
if (!included || included < 0 || !limit || limit < 0) {
if (
included === undefined ||
included < 0 ||
limit === undefined ||
limit < 0
) {
return <ErrorAlert error="Invalid license usage limits" />;
}