mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
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:
+17
@@ -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: {
|
||||
|
||||
+7
-2
@@ -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" />;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user