From d244315247f8f03a3386f53d96271a0711b76788 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 18 Aug 2025 06:25:29 +0000 Subject: [PATCH 1/4] fix: avoid error when AI usage is zero Fixes a bug that prevents the managed AI agent usage from showing in the licenses page of the dashboard when the usage is zero. --- .../ManagedAgentsConsumption.stories.tsx | 17 +++++++++++++++++ .../ManagedAgentsConsumption.tsx | 13 ++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.stories.tsx b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.stories.tsx index 2073ff5bf2a7f..24b65093d384b 100644 --- a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.stories.tsx +++ b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.stories.tsx @@ -26,6 +26,23 @@ type Story = StoryObj; 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: { diff --git a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx index 08da49c96b710..7af23059c9523 100644 --- a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx +++ b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx @@ -38,17 +38,20 @@ export const ManagedAgentsConsumption: FC = ({ ); } - const usage = managedAgentFeature.actual; - const included = managedAgentFeature.soft_limit; - const limit = managedAgentFeature.limit; + const valueOrZero = (value: number | undefined | null) => + value === undefined || value === null ? 0 : value; + + const usage = valueOrZero(managedAgentFeature.actual); + const included = valueOrZero(managedAgentFeature.soft_limit); + const limit = valueOrZero(managedAgentFeature.limit); const startDate = managedAgentFeature.usage_period?.start; const endDate = managedAgentFeature.usage_period?.end; - if (!usage || usage < 0) { + if (usage < 0) { return ; } - if (!included || included < 0 || !limit || limit < 0) { + if (included < 0 || limit < 0) { return ; } From 13ffbe7ad0b5a6eb26f65e696979795b5212d6a0 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 18 Aug 2025 13:42:27 +0000 Subject: [PATCH 2/4] use double question mark --- .../LicensesSettingsPage/ManagedAgentsConsumption.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx index 7af23059c9523..b4fea5f491f32 100644 --- a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx +++ b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx @@ -38,12 +38,9 @@ export const ManagedAgentsConsumption: FC = ({ ); } - const valueOrZero = (value: number | undefined | null) => - value === undefined || value === null ? 0 : value; - - const usage = valueOrZero(managedAgentFeature.actual); - const included = valueOrZero(managedAgentFeature.soft_limit); - const limit = valueOrZero(managedAgentFeature.limit); + const usage = managedAgentFeature.actual ?? 0; + const included = managedAgentFeature.soft_limit ?? 0; + const limit = managedAgentFeature.limit ?? 0; const startDate = managedAgentFeature.usage_period?.start; const endDate = managedAgentFeature.usage_period?.end; From d3ca374ef4900a0693cb0235b09fe7c37f68d5d7 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Tue, 19 Aug 2025 16:53:33 +0000 Subject: [PATCH 3/4] pr comments --- .../LicensesSettingsPage/ManagedAgentsConsumption.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx index b4fea5f491f32..d143de44fb5a6 100644 --- a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx +++ b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx @@ -38,17 +38,17 @@ export const ManagedAgentsConsumption: FC = ({ ); } - const usage = managedAgentFeature.actual ?? 0; - const included = managedAgentFeature.soft_limit ?? 0; - const limit = managedAgentFeature.limit ?? 0; + const usage = managedAgentFeature.actual; + const included = managedAgentFeature.soft_limit; + const limit = managedAgentFeature.limit; const startDate = managedAgentFeature.usage_period?.start; const endDate = managedAgentFeature.usage_period?.end; - if (usage < 0) { + if (usage === undefined || usage < 0) { return ; } - if (included < 0 || limit < 0) { + if (included === undefined || included < 0 || limit === undefined || limit < 0) { return ; } From c90d74a1ba1e474fac23501dc15692b272710902 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Tue, 19 Aug 2025 16:55:49 +0000 Subject: [PATCH 4/4] fmt --- .../LicensesSettingsPage/ManagedAgentsConsumption.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx index d143de44fb5a6..022627c11dc02 100644 --- a/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx +++ b/site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/ManagedAgentsConsumption.tsx @@ -48,7 +48,12 @@ export const ManagedAgentsConsumption: FC = ({ return ; } - if (included === undefined || included < 0 || limit === undefined || limit < 0) { + if ( + included === undefined || + included < 0 || + limit === undefined || + limit < 0 + ) { return ; }